Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 223 additions & 14 deletions bun.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"devDependencies": {
"@types/better-sqlite3": "^7.6.13",
"@types/bun": "latest",
"@types/oracledb": "^6.10.1",
"@types/papaparse": "^5.5.2",
"@types/pg": "^8.16.0",
"lefthook": "^2.1.1",
"oxlint": "latest",
"typescript": "^5",
Expand All @@ -38,9 +40,12 @@
"ink-spinner": "^5.0.0",
"ink-text-input": "^6.0.0",
"mongodb": "^7.1.0",
"mysql2": "^3.18.0",
"nanoid": "^5.1.6",
"openai": "^6.22.0",
"oracledb": "^6.10.0",
"papaparse": "^5.5.3",
"pg": "^8.18.0",
"react": "^19.2.4",
"string-width": "^8.2.0"
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/check-no-private.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* CI/lint script that ensures no TypeScript visibility modifiers (private,
* protected, public) or JavaScript private class fields (#) appear in the
* Explorer codebase.
* codebase.
*
* Usage: bun scripts/check-no-private.ts
* Exit code 0 = all good, non-zero = violations found.
Expand All @@ -12,8 +12,8 @@ import { join, relative } from "node:path";

const ROOT = join(import.meta.dir, "..");
const SCAN_DIRS = [
join(ROOT, "src", "explorer"),
join(ROOT, "tests", "explorer"),
join(ROOT, "src"),
join(ROOT, "tests"),
];

const EXTENSIONS = new Set([".ts", ".tsx"]);
Expand Down
8 changes: 4 additions & 4 deletions src/Accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import type { Record } from "./Record.ts";
* Analogous to App::RecordStream::Accumulator in Perl.
*/
export class Accumulator {
#records: Record[] = [];
records: Record[] = [];

acceptRecord(record: Record): void {
this.accumulateRecord(record);
}

accumulateRecord(record: Record): void {
this.#records.push(record);
this.records.push(record);
}

getRecords(): Record[] {
return this.#records;
return this.records;
}

clear(): void {
this.#records = [];
this.records = [];
}
}
20 changes: 10 additions & 10 deletions src/BaseRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface RegistryEntry<T> {
}

export class BaseRegistry<T> {
#implementations = new Map<string, RegistryEntry<T>>();
implementations = new Map<string, RegistryEntry<T>>();
readonly typeName: string;

constructor(typeName: string) {
Expand All @@ -31,10 +31,10 @@ export class BaseRegistry<T> {
* Register an implementation under a name.
*/
register(name: string, entry: RegistryEntry<T>): void {
this.#implementations.set(name, entry);
this.implementations.set(name, entry);
if (entry.aliases) {
for (const alias of entry.aliases) {
this.#implementations.set(alias, entry);
this.implementations.set(alias, entry);
}
}
}
Expand All @@ -51,7 +51,7 @@ export class BaseRegistry<T> {
const name = parts[0]!;
const args = parts.slice(1);

const entry = this.#implementations.get(name);
const entry = this.implementations.get(name);
if (!entry) {
throw new Error(`Bad ${this.typeName}: ${name}`);
}
Expand All @@ -71,14 +71,14 @@ export class BaseRegistry<T> {
* Check if a name is registered.
*/
has(name: string): boolean {
return this.#implementations.has(name);
return this.implementations.has(name);
}

/**
* Get an entry by name.
*/
get(name: string): RegistryEntry<T> | undefined {
return this.#implementations.get(name);
return this.implementations.get(name);
}

/**
Expand All @@ -89,9 +89,9 @@ export class BaseRegistry<T> {
const entryToNames = new Map<RegistryEntry<T>, string[]>();
const entries: RegistryEntry<T>[] = [];

const sortedNames = [...this.#implementations.keys()].sort();
const sortedNames = [...this.implementations.keys()].sort();
for (const name of sortedNames) {
const entry = this.#implementations.get(name)!;
const entry = this.implementations.get(name)!;
let names = entryToNames.get(entry);
if (!names) {
names = [];
Expand All @@ -113,7 +113,7 @@ export class BaseRegistry<T> {
* Get the detailed usage for a specific implementation.
*/
showImplementation(name: string): string {
const entry = this.#implementations.get(name);
const entry = this.implementations.get(name);
if (!entry) {
return `Bad ${this.typeName}: ${name}\n`;
}
Expand All @@ -124,6 +124,6 @@ export class BaseRegistry<T> {
* Get all registered names.
*/
names(): string[] {
return [...this.#implementations.keys()];
return [...this.implementations.keys()];
}
}
12 changes: 6 additions & 6 deletions src/DomainLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export interface Valuation {

/** A valuation that extracts a field value via KeySpec */
export class KeySpecValuation implements Valuation {
#field: string;
field: string;
constructor(field: string) {
this.#field = field;
this.field = field;
}
evaluateRecord(record: Record): JsonValue {
const v = findKey(record.dataRef(), this.#field, true);
const v = findKey(record.dataRef(), this.field, true);
return v === undefined ? null : v;
}
}
Expand All @@ -41,12 +41,12 @@ export class RecordValuation implements Valuation {

/** A valuation from a JS function */
export class FunctionValuation implements Valuation {
#fn: (r: Record) => JsonValue;
fn: (r: Record) => JsonValue;
constructor(fn: (r: Record) => JsonValue) {
this.#fn = fn;
this.fn = fn;
}
evaluateRecord(record: Record): JsonValue {
return this.#fn(record);
return this.fn(record);
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ export interface SnippetDef {
}

export class Executor {
#snippets: Map<string, CompiledSnippet>;
#lineCounter = 0;
#currentFilename = "NONE";
#state: Record<string, unknown> = {};
snippets: Map<string, CompiledSnippet>;
lineCounter = 0;
currentFilename = "NONE";
state: Record<string, unknown> = {};

constructor(codeOrSnippets: string | { [name: string]: SnippetDef }) {
this.#snippets = new Map();
this.snippets = new Map();

if (typeof codeOrSnippets === "string") {
this.#addSnippet("__DEFAULT", {
this.addSnippet("__DEFAULT", {
code: codeOrSnippets,
argNames: ["r"],
});
} else {
for (const [name, def] of Object.entries(codeOrSnippets)) {
this.#addSnippet(name, def);
this.addSnippet(name, def);
}
}
}

#addSnippet(name: string, def: SnippetDef): void {
addSnippet(name: string, def: SnippetDef): void {
const transformedCode = transformCode(def.code);
const argNames = def.argNames ?? ["r"];
const fn = compileSnippet(transformedCode, argNames, this.#state);
this.#snippets.set(name, { fn, argNames });
const fn = compileSnippet(transformedCode, argNames, this.state);
this.snippets.set(name, { fn, argNames });
}

/**
Expand All @@ -57,29 +57,29 @@ export class Executor {
* Execute a named snippet with the given arguments.
*/
executeMethod(name: string, ...args: unknown[]): unknown {
const snippet = this.#snippets.get(name);
const snippet = this.snippets.get(name);
if (!snippet) {
throw new Error(`No such snippet: ${name}`);
}

this.#lineCounter++;
return snippet.fn(...args, this.#lineCounter, this.#currentFilename);
this.lineCounter++;
return snippet.fn(...args, this.lineCounter, this.currentFilename);
}

setCurrentFilename(filename: string): void {
this.#currentFilename = filename;
this.currentFilename = filename;
}

getCurrentFilename(): string {
return this.#currentFilename;
return this.currentFilename;
}

getLine(): number {
return this.#lineCounter;
return this.lineCounter;
}

resetLine(): void {
this.#lineCounter = 0;
this.lineCounter = 0;
}
}

Expand Down
Loading