@toiroakr/lines-db 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/bin/cli.js +94 -28
- package/dist/index.cjs +109 -27
- package/dist/index.d.cts +30 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +30 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +104 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +3 -2
- package/src/database.test.ts +28 -0
- package/src/database.ts +64 -8
- package/src/index.ts +8 -0
- package/src/schema-extensions.test.ts +155 -0
- package/src/schema-extensions.ts +89 -0
- package/src/schema-loader.test.ts +90 -0
- package/src/schema-loader.ts +10 -18
- package/src/type-generator.ts +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @toiroakr/lines-db
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4597383: feat: support .mts and .cts schema file extensions
|
|
8
|
+
|
|
9
|
+
Schema files are now auto-detected with the following priority: `.schema.ts` > `.schema.mts` > `.schema.cts`. Mixed extensions within a single project are supported.
|
|
10
|
+
- Added `--output` option to `generate` command for specifying the output file path (e.g., `--output ./data/db.mts`)
|
|
11
|
+
- Import paths are correctly rewritten: `.ts`→`.js`, `.mts`→`.mjs`, `.cts`→`.cjs`
|
|
12
|
+
- New exported utilities: `findSchemaFile`, `isSchemaFile`, `extractTableNameFromSchemaFile`, `rewriteExtensionForImport`, `SCHEMA_EXTENSIONS`
|
|
13
|
+
|
|
14
|
+
## 0.6.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 9ae4075: fix: support foreign key constraints with unique indexes
|
|
19
|
+
|
|
3
20
|
## 0.6.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/bin/cli.js
CHANGED
|
@@ -10,6 +10,57 @@ import { runInNewContext } from "node:vm";
|
|
|
10
10
|
//#region rolldown:runtime
|
|
11
11
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
12
12
|
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/schema-extensions.ts
|
|
15
|
+
/**
|
|
16
|
+
* Supported schema file extensions, in priority order.
|
|
17
|
+
* The first match wins when discovering schema files.
|
|
18
|
+
*/
|
|
19
|
+
const SCHEMA_EXTENSIONS = [
|
|
20
|
+
".schema.ts",
|
|
21
|
+
".schema.mts",
|
|
22
|
+
".schema.cts"
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Map from schema extensions to their JavaScript import counterparts.
|
|
26
|
+
*/
|
|
27
|
+
const SCHEMA_TO_JS_IMPORT_MAP = {
|
|
28
|
+
".schema.ts": ".schema.js",
|
|
29
|
+
".schema.mts": ".schema.mjs",
|
|
30
|
+
".schema.cts": ".schema.cjs"
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Try each supported schema extension and return the full path of the first
|
|
34
|
+
* one that exists on disk. Returns undefined if none is found.
|
|
35
|
+
*/
|
|
36
|
+
async function findSchemaFile(dir, tableName) {
|
|
37
|
+
for (const ext of SCHEMA_EXTENSIONS) {
|
|
38
|
+
const candidate = join(dir, `${tableName}${ext}`);
|
|
39
|
+
try {
|
|
40
|
+
await access(candidate);
|
|
41
|
+
return candidate;
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Synchronously find a schema file among directory entries.
|
|
47
|
+
* Returns the full path of the first match, or undefined.
|
|
48
|
+
*/
|
|
49
|
+
function findSchemaFileInEntries(dataDirPath, tableName, entries) {
|
|
50
|
+
for (const ext of SCHEMA_EXTENSIONS) {
|
|
51
|
+
const candidateName = `${tableName}${ext}`;
|
|
52
|
+
if (entries.some((e) => e.isFile() && e.name === candidateName)) return join(dataDirPath, candidateName);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Rewrite a TypeScript path to its JavaScript counterpart for ESM imports.
|
|
57
|
+
* ".schema.ts" -> ".schema.js", ".schema.mts" -> ".schema.mjs", ".schema.cts" -> ".schema.cjs"
|
|
58
|
+
*/
|
|
59
|
+
function rewriteExtensionForImport(filePath) {
|
|
60
|
+
for (const [tsExt, jsExt] of Object.entries(SCHEMA_TO_JS_IMPORT_MAP)) if (filePath.endsWith(tsExt)) return filePath.slice(0, -tsExt.length) + jsExt;
|
|
61
|
+
return filePath;
|
|
62
|
+
}
|
|
63
|
+
|
|
13
64
|
//#endregion
|
|
14
65
|
//#region src/type-generator.ts
|
|
15
66
|
var TypeGenerator = class {
|
|
@@ -22,7 +73,7 @@ var TypeGenerator = class {
|
|
|
22
73
|
this.projectRoot = envProjectRoot !== void 0 ? envProjectRoot : options.projectRoot || process.cwd();
|
|
23
74
|
this.dataDir = options.dataDir;
|
|
24
75
|
this.dataDirPath = isAbsolute(this.dataDir) ? this.dataDir : join(this.projectRoot, this.dataDir);
|
|
25
|
-
this.outputFile = join(this.dataDirPath, "db.ts");
|
|
76
|
+
this.outputFile = options.output ? isAbsolute(options.output) ? options.output : join(this.projectRoot, options.output) : join(this.dataDirPath, "db.ts");
|
|
26
77
|
}
|
|
27
78
|
/**
|
|
28
79
|
* Generate types file from JSONL files and their optional schema files.
|
|
@@ -45,12 +96,10 @@ var TypeGenerator = class {
|
|
|
45
96
|
const tables = [];
|
|
46
97
|
for (const entry of entries) if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
47
98
|
const tableName = basename(entry.name, ".jsonl");
|
|
48
|
-
const
|
|
49
|
-
const schemaFilePath = join(this.dataDirPath, schemaFileName);
|
|
50
|
-
const hasSchema = entries.some((e) => e.isFile() && e.name === schemaFileName);
|
|
99
|
+
const schemaFilePath = findSchemaFileInEntries(this.dataDirPath, tableName, entries);
|
|
51
100
|
tables.push({
|
|
52
101
|
tableName,
|
|
53
|
-
schemaFile:
|
|
102
|
+
schemaFile: schemaFilePath
|
|
54
103
|
});
|
|
55
104
|
}
|
|
56
105
|
return tables;
|
|
@@ -71,7 +120,7 @@ var TypeGenerator = class {
|
|
|
71
120
|
if (table.schemaFile) {
|
|
72
121
|
const schemaIdentifier = this.createSchemaIdentifier(table.tableName, usedAliases);
|
|
73
122
|
usedAliases.add(schemaIdentifier);
|
|
74
|
-
let relativePath = relative(join(this.outputFile, ".."), table.schemaFile).replace(/\\/g, "/")
|
|
123
|
+
let relativePath = rewriteExtensionForImport(relative(join(this.outputFile, ".."), table.schemaFile).replace(/\\/g, "/"));
|
|
75
124
|
if (!relativePath.startsWith(".")) relativePath = "./" + relativePath;
|
|
76
125
|
imports.push(`import { schema as ${schemaIdentifier} } from '${relativePath}';`);
|
|
77
126
|
tableEntries.push(` ${tableKey}: InferOutput<typeof ${schemaIdentifier}>;`);
|
|
@@ -279,27 +328,17 @@ var SchemaLoader = class {
|
|
|
279
328
|
* Check if a schema file exists for a table
|
|
280
329
|
*/
|
|
281
330
|
static async hasSchema(jsonlPath) {
|
|
282
|
-
|
|
283
|
-
try {
|
|
284
|
-
await access(schemaPath);
|
|
285
|
-
return true;
|
|
286
|
-
} catch {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
331
|
+
return await findSchemaFile(dirname(jsonlPath), basename(jsonlPath, ".jsonl")) !== void 0;
|
|
289
332
|
}
|
|
290
333
|
/**
|
|
291
334
|
* Load a validation schema file for a table
|
|
292
|
-
* Requires ${tableName}.schema.ts to exist alongside the JSONL file
|
|
335
|
+
* Requires ${tableName}.schema.{ts,mts,cts} to exist alongside the JSONL file
|
|
293
336
|
*/
|
|
294
337
|
static async loadSchema(jsonlPath) {
|
|
295
338
|
const dir = dirname(jsonlPath);
|
|
296
339
|
const tableName = basename(jsonlPath, ".jsonl");
|
|
297
|
-
const schemaPath =
|
|
298
|
-
|
|
299
|
-
await access(schemaPath);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
throw new Error(`Schema file not found for table '${tableName}'. Expected: ${schemaPath}`, { cause: error instanceof Error ? error : void 0 });
|
|
302
|
-
}
|
|
340
|
+
const schemaPath = await findSchemaFile(dir, tableName);
|
|
341
|
+
if (!schemaPath) throw new Error(`Schema file not found for table '${tableName}'. Expected one of: ${SCHEMA_EXTENSIONS.map((ext) => `${tableName}${ext}`).join(", ")}`);
|
|
303
342
|
try {
|
|
304
343
|
const module = await import(`${pathToFileURL(schemaPath).href}?t=${Date.now()}`);
|
|
305
344
|
const schema = module.default || module.schema;
|
|
@@ -424,8 +463,11 @@ var LinesDB = class LinesDB {
|
|
|
424
463
|
let foreignKeys;
|
|
425
464
|
try {
|
|
426
465
|
const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
|
|
427
|
-
const
|
|
428
|
-
|
|
466
|
+
const schemaPath = await findSchemaFile(dirname(tableConfig.jsonlPath), basename(tableConfig.jsonlPath, ".jsonl"));
|
|
467
|
+
if (schemaPath) {
|
|
468
|
+
const schemaModule = await import(`${pathToFileURL$1(schemaPath).href}?t=${Date.now()}`);
|
|
469
|
+
foreignKeys = (schemaModule.schema || schemaModule.default)?.foreignKeys || schemaModule.foreignKeys;
|
|
470
|
+
}
|
|
429
471
|
} catch {}
|
|
430
472
|
if (foreignKeys && foreignKeys.length > 0) for (const fk of foreignKeys) {
|
|
431
473
|
const referencedTable = fk.references.table;
|
|
@@ -465,7 +507,9 @@ var LinesDB = class LinesDB {
|
|
|
465
507
|
} catch (_error) {}
|
|
466
508
|
if (!config.validationSchema) try {
|
|
467
509
|
const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
|
|
468
|
-
const
|
|
510
|
+
const schemaPath = await findSchemaFile(dirname(config.jsonlPath), basename(config.jsonlPath, ".jsonl"));
|
|
511
|
+
if (!schemaPath) throw new Error("Schema file not found");
|
|
512
|
+
const schemaModule = await import(`${pathToFileURL$1(schemaPath).href}?t=${Date.now()}`);
|
|
469
513
|
const schemaExport = schemaModule.schema || schemaModule.default;
|
|
470
514
|
if (schemaExport?.primaryKey) schemaMetadata.primaryKey = schemaExport.primaryKey;
|
|
471
515
|
else if (schemaModule.primaryKey) schemaMetadata.primaryKey = schemaModule.primaryKey;
|
|
@@ -473,7 +517,15 @@ var LinesDB = class LinesDB {
|
|
|
473
517
|
else if (schemaModule.foreignKeys) schemaMetadata.foreignKeys = schemaModule.foreignKeys;
|
|
474
518
|
if (schemaExport?.indexes) schemaMetadata.indexes = schemaExport.indexes;
|
|
475
519
|
else if (schemaModule.indexes) schemaMetadata.indexes = schemaModule.indexes;
|
|
476
|
-
|
|
520
|
+
if (process.env.DEBUG_LINES_DB) {
|
|
521
|
+
console.log(`[lines-db] Schema metadata for ${tableName}:`);
|
|
522
|
+
console.log(` primaryKey: ${schemaMetadata.primaryKey}`);
|
|
523
|
+
console.log(` foreignKeys: ${JSON.stringify(schemaMetadata.foreignKeys)}`);
|
|
524
|
+
console.log(` indexes: ${JSON.stringify(schemaMetadata.indexes)}`);
|
|
525
|
+
}
|
|
526
|
+
} catch (_error) {
|
|
527
|
+
if (process.env.DEBUG_LINES_DB) console.warn(`[lines-db] Failed to load schema metadata for ${tableName}:`, _error instanceof Error ? _error.message : String(_error));
|
|
528
|
+
}
|
|
477
529
|
this.validationSchemas.set(tableName, validationSchema);
|
|
478
530
|
const validationErrors = [];
|
|
479
531
|
const validatedData = [];
|
|
@@ -530,7 +582,13 @@ var LinesDB = class LinesDB {
|
|
|
530
582
|
if (idColumn) idColumn.primaryKey = true;
|
|
531
583
|
}
|
|
532
584
|
if (foreignKeys) schema.foreignKeys = foreignKeys;
|
|
533
|
-
if (indexes)
|
|
585
|
+
if (indexes) {
|
|
586
|
+
schema.indexes = indexes;
|
|
587
|
+
for (const index of indexes) if (index.unique && index.columns.length === 1) {
|
|
588
|
+
const col = schema.columns.find((c) => c.name === index.columns[0]);
|
|
589
|
+
if (col && !col.unique && !col.primaryKey) col.unique = true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
534
592
|
this.schemas.set(tableName, schema);
|
|
535
593
|
this.createTable(schema);
|
|
536
594
|
if (detailedValidate) {
|
|
@@ -550,12 +608,17 @@ var LinesDB = class LinesDB {
|
|
|
550
608
|
*/
|
|
551
609
|
createTable(schema) {
|
|
552
610
|
const quotedTableName = this.quoteTableName(schema.name);
|
|
611
|
+
const uniqueColumns = /* @__PURE__ */ new Set();
|
|
612
|
+
for (const col of schema.columns) if (col.unique) uniqueColumns.add(col.name);
|
|
613
|
+
if (schema.indexes) {
|
|
614
|
+
for (const index of schema.indexes) if (index.unique && index.columns.length === 1) uniqueColumns.add(index.columns[0]);
|
|
615
|
+
}
|
|
553
616
|
const columnDefs = schema.columns.map((col) => {
|
|
554
617
|
const sqlType = col.type === "JSON" ? "TEXT" : col.type;
|
|
555
618
|
const parts = [this.quoteIdentifier(col.name), sqlType];
|
|
556
619
|
if (col.primaryKey) parts.push("PRIMARY KEY");
|
|
557
620
|
if (col.notNull) parts.push("NOT NULL");
|
|
558
|
-
if (col.
|
|
621
|
+
if (uniqueColumns.has(col.name) && !col.primaryKey) parts.push("UNIQUE");
|
|
559
622
|
return parts.join(" ");
|
|
560
623
|
});
|
|
561
624
|
const foreignKeyDefs = [];
|
|
@@ -1258,9 +1321,12 @@ function runInSandbox(expression, context = {}) {
|
|
|
1258
1321
|
}
|
|
1259
1322
|
const program = new Command();
|
|
1260
1323
|
program.name("@toiroakr/lines-db").description("Database utilities for JSONL files").version("1.0.0");
|
|
1261
|
-
program.command("generate").description("Generate TypeScript type definitions from schema files").argument("<dataDir>", "Directory containing JSONL and schema files").action(async (dataDir) => {
|
|
1324
|
+
program.command("generate").description("Generate TypeScript type definitions from schema files").argument("<dataDir>", "Directory containing JSONL and schema files").option("-o, --output <path>", "Output file path (default: db.ts in dataDir)").action(async (dataDir, options) => {
|
|
1262
1325
|
try {
|
|
1263
|
-
await new TypeGenerator({
|
|
1326
|
+
await new TypeGenerator({
|
|
1327
|
+
dataDir,
|
|
1328
|
+
output: options.output
|
|
1329
|
+
}).generate();
|
|
1264
1330
|
console.log("Type generation completed successfully!");
|
|
1265
1331
|
} catch (error) {
|
|
1266
1332
|
console.error("Error:", error instanceof Error ? error.message : String(error));
|
package/dist/index.cjs
CHANGED
|
@@ -180,6 +180,71 @@ var JsonlWriter = class {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/schema-extensions.ts
|
|
185
|
+
/**
|
|
186
|
+
* Supported schema file extensions, in priority order.
|
|
187
|
+
* The first match wins when discovering schema files.
|
|
188
|
+
*/
|
|
189
|
+
const SCHEMA_EXTENSIONS = [
|
|
190
|
+
".schema.ts",
|
|
191
|
+
".schema.mts",
|
|
192
|
+
".schema.cts"
|
|
193
|
+
];
|
|
194
|
+
/**
|
|
195
|
+
* Map from schema extensions to their JavaScript import counterparts.
|
|
196
|
+
*/
|
|
197
|
+
const SCHEMA_TO_JS_IMPORT_MAP = {
|
|
198
|
+
".schema.ts": ".schema.js",
|
|
199
|
+
".schema.mts": ".schema.mjs",
|
|
200
|
+
".schema.cts": ".schema.cjs"
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Try each supported schema extension and return the full path of the first
|
|
204
|
+
* one that exists on disk. Returns undefined if none is found.
|
|
205
|
+
*/
|
|
206
|
+
async function findSchemaFile(dir, tableName) {
|
|
207
|
+
for (const ext of SCHEMA_EXTENSIONS) {
|
|
208
|
+
const candidate = (0, node_path.join)(dir, `${tableName}${ext}`);
|
|
209
|
+
try {
|
|
210
|
+
await (0, node_fs_promises.access)(candidate);
|
|
211
|
+
return candidate;
|
|
212
|
+
} catch {}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Synchronously find a schema file among directory entries.
|
|
217
|
+
* Returns the full path of the first match, or undefined.
|
|
218
|
+
*/
|
|
219
|
+
function findSchemaFileInEntries(dataDirPath, tableName, entries) {
|
|
220
|
+
for (const ext of SCHEMA_EXTENSIONS) {
|
|
221
|
+
const candidateName = `${tableName}${ext}`;
|
|
222
|
+
if (entries.some((e) => e.isFile() && e.name === candidateName)) return (0, node_path.join)(dataDirPath, candidateName);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Check if a filename matches any supported schema file pattern.
|
|
227
|
+
*/
|
|
228
|
+
function isSchemaFile(fileName) {
|
|
229
|
+
return SCHEMA_EXTENSIONS.some((ext) => fileName.endsWith(ext));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Extract table name from a schema filename.
|
|
233
|
+
* e.g., "users.schema.ts" -> "users", "users.schema.mts" -> "users"
|
|
234
|
+
*/
|
|
235
|
+
function extractTableNameFromSchemaFile(fileName) {
|
|
236
|
+
for (const ext of SCHEMA_EXTENSIONS) if (fileName.endsWith(ext)) return fileName.slice(0, -ext.length);
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Rewrite a TypeScript path to its JavaScript counterpart for ESM imports.
|
|
241
|
+
* ".schema.ts" -> ".schema.js", ".schema.mts" -> ".schema.mjs", ".schema.cts" -> ".schema.cjs"
|
|
242
|
+
*/
|
|
243
|
+
function rewriteExtensionForImport(filePath) {
|
|
244
|
+
for (const [tsExt, jsExt] of Object.entries(SCHEMA_TO_JS_IMPORT_MAP)) if (filePath.endsWith(tsExt)) return filePath.slice(0, -tsExt.length) + jsExt;
|
|
245
|
+
return filePath;
|
|
246
|
+
}
|
|
247
|
+
|
|
183
248
|
//#endregion
|
|
184
249
|
//#region src/schema-loader.ts
|
|
185
250
|
var SchemaLoader = class {
|
|
@@ -187,27 +252,17 @@ var SchemaLoader = class {
|
|
|
187
252
|
* Check if a schema file exists for a table
|
|
188
253
|
*/
|
|
189
254
|
static async hasSchema(jsonlPath) {
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
await (0, node_fs_promises.access)(schemaPath);
|
|
193
|
-
return true;
|
|
194
|
-
} catch {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
255
|
+
return await findSchemaFile((0, node_path.dirname)(jsonlPath), (0, node_path.basename)(jsonlPath, ".jsonl")) !== void 0;
|
|
197
256
|
}
|
|
198
257
|
/**
|
|
199
258
|
* Load a validation schema file for a table
|
|
200
|
-
* Requires ${tableName}.schema.ts to exist alongside the JSONL file
|
|
259
|
+
* Requires ${tableName}.schema.{ts,mts,cts} to exist alongside the JSONL file
|
|
201
260
|
*/
|
|
202
261
|
static async loadSchema(jsonlPath) {
|
|
203
262
|
const dir = (0, node_path.dirname)(jsonlPath);
|
|
204
263
|
const tableName = (0, node_path.basename)(jsonlPath, ".jsonl");
|
|
205
|
-
const schemaPath =
|
|
206
|
-
|
|
207
|
-
await (0, node_fs_promises.access)(schemaPath);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
throw new Error(`Schema file not found for table '${tableName}'. Expected: ${schemaPath}`, { cause: error instanceof Error ? error : void 0 });
|
|
210
|
-
}
|
|
264
|
+
const schemaPath = await findSchemaFile(dir, tableName);
|
|
265
|
+
if (!schemaPath) throw new Error(`Schema file not found for table '${tableName}'. Expected one of: ${SCHEMA_EXTENSIONS.map((ext) => `${tableName}${ext}`).join(", ")}`);
|
|
211
266
|
try {
|
|
212
267
|
const module$1 = await import(`${(0, node_url.pathToFileURL)(schemaPath).href}?t=${Date.now()}`);
|
|
213
268
|
const schema = module$1.default || module$1.schema;
|
|
@@ -381,8 +436,11 @@ var LinesDB = class LinesDB {
|
|
|
381
436
|
let foreignKeys;
|
|
382
437
|
try {
|
|
383
438
|
const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
|
|
384
|
-
const
|
|
385
|
-
|
|
439
|
+
const schemaPath = await findSchemaFile((0, node_path.dirname)(tableConfig.jsonlPath), (0, node_path.basename)(tableConfig.jsonlPath, ".jsonl"));
|
|
440
|
+
if (schemaPath) {
|
|
441
|
+
const schemaModule = await import(`${pathToFileURL$1(schemaPath).href}?t=${Date.now()}`);
|
|
442
|
+
foreignKeys = (schemaModule.schema || schemaModule.default)?.foreignKeys || schemaModule.foreignKeys;
|
|
443
|
+
}
|
|
386
444
|
} catch {}
|
|
387
445
|
if (foreignKeys && foreignKeys.length > 0) for (const fk of foreignKeys) {
|
|
388
446
|
const referencedTable = fk.references.table;
|
|
@@ -422,7 +480,9 @@ var LinesDB = class LinesDB {
|
|
|
422
480
|
} catch (_error) {}
|
|
423
481
|
if (!config.validationSchema) try {
|
|
424
482
|
const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
|
|
425
|
-
const
|
|
483
|
+
const schemaPath = await findSchemaFile((0, node_path.dirname)(config.jsonlPath), (0, node_path.basename)(config.jsonlPath, ".jsonl"));
|
|
484
|
+
if (!schemaPath) throw new Error("Schema file not found");
|
|
485
|
+
const schemaModule = await import(`${pathToFileURL$1(schemaPath).href}?t=${Date.now()}`);
|
|
426
486
|
const schemaExport = schemaModule.schema || schemaModule.default;
|
|
427
487
|
if (schemaExport?.primaryKey) schemaMetadata.primaryKey = schemaExport.primaryKey;
|
|
428
488
|
else if (schemaModule.primaryKey) schemaMetadata.primaryKey = schemaModule.primaryKey;
|
|
@@ -430,7 +490,15 @@ var LinesDB = class LinesDB {
|
|
|
430
490
|
else if (schemaModule.foreignKeys) schemaMetadata.foreignKeys = schemaModule.foreignKeys;
|
|
431
491
|
if (schemaExport?.indexes) schemaMetadata.indexes = schemaExport.indexes;
|
|
432
492
|
else if (schemaModule.indexes) schemaMetadata.indexes = schemaModule.indexes;
|
|
433
|
-
|
|
493
|
+
if (process.env.DEBUG_LINES_DB) {
|
|
494
|
+
console.log(`[lines-db] Schema metadata for ${tableName}:`);
|
|
495
|
+
console.log(` primaryKey: ${schemaMetadata.primaryKey}`);
|
|
496
|
+
console.log(` foreignKeys: ${JSON.stringify(schemaMetadata.foreignKeys)}`);
|
|
497
|
+
console.log(` indexes: ${JSON.stringify(schemaMetadata.indexes)}`);
|
|
498
|
+
}
|
|
499
|
+
} catch (_error) {
|
|
500
|
+
if (process.env.DEBUG_LINES_DB) console.warn(`[lines-db] Failed to load schema metadata for ${tableName}:`, _error instanceof Error ? _error.message : String(_error));
|
|
501
|
+
}
|
|
434
502
|
this.validationSchemas.set(tableName, validationSchema);
|
|
435
503
|
const validationErrors = [];
|
|
436
504
|
const validatedData = [];
|
|
@@ -487,7 +555,13 @@ var LinesDB = class LinesDB {
|
|
|
487
555
|
if (idColumn) idColumn.primaryKey = true;
|
|
488
556
|
}
|
|
489
557
|
if (foreignKeys) schema.foreignKeys = foreignKeys;
|
|
490
|
-
if (indexes)
|
|
558
|
+
if (indexes) {
|
|
559
|
+
schema.indexes = indexes;
|
|
560
|
+
for (const index of indexes) if (index.unique && index.columns.length === 1) {
|
|
561
|
+
const col = schema.columns.find((c) => c.name === index.columns[0]);
|
|
562
|
+
if (col && !col.unique && !col.primaryKey) col.unique = true;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
491
565
|
this.schemas.set(tableName, schema);
|
|
492
566
|
this.createTable(schema);
|
|
493
567
|
if (detailedValidate) {
|
|
@@ -507,12 +581,17 @@ var LinesDB = class LinesDB {
|
|
|
507
581
|
*/
|
|
508
582
|
createTable(schema) {
|
|
509
583
|
const quotedTableName = this.quoteTableName(schema.name);
|
|
584
|
+
const uniqueColumns = /* @__PURE__ */ new Set();
|
|
585
|
+
for (const col of schema.columns) if (col.unique) uniqueColumns.add(col.name);
|
|
586
|
+
if (schema.indexes) {
|
|
587
|
+
for (const index of schema.indexes) if (index.unique && index.columns.length === 1) uniqueColumns.add(index.columns[0]);
|
|
588
|
+
}
|
|
510
589
|
const columnDefs = schema.columns.map((col) => {
|
|
511
590
|
const sqlType = col.type === "JSON" ? "TEXT" : col.type;
|
|
512
591
|
const parts = [this.quoteIdentifier(col.name), sqlType];
|
|
513
592
|
if (col.primaryKey) parts.push("PRIMARY KEY");
|
|
514
593
|
if (col.notNull) parts.push("NOT NULL");
|
|
515
|
-
if (col.
|
|
594
|
+
if (uniqueColumns.has(col.name) && !col.primaryKey) parts.push("UNIQUE");
|
|
516
595
|
return parts.join(" ");
|
|
517
596
|
});
|
|
518
597
|
const foreignKeyDefs = [];
|
|
@@ -1091,7 +1170,7 @@ var TypeGenerator = class {
|
|
|
1091
1170
|
this.projectRoot = envProjectRoot !== void 0 ? envProjectRoot : options.projectRoot || process.cwd();
|
|
1092
1171
|
this.dataDir = options.dataDir;
|
|
1093
1172
|
this.dataDirPath = (0, node_path.isAbsolute)(this.dataDir) ? this.dataDir : (0, node_path.join)(this.projectRoot, this.dataDir);
|
|
1094
|
-
this.outputFile = (0, node_path.join)(this.dataDirPath, "db.ts");
|
|
1173
|
+
this.outputFile = options.output ? (0, node_path.isAbsolute)(options.output) ? options.output : (0, node_path.join)(this.projectRoot, options.output) : (0, node_path.join)(this.dataDirPath, "db.ts");
|
|
1095
1174
|
}
|
|
1096
1175
|
/**
|
|
1097
1176
|
* Generate types file from JSONL files and their optional schema files.
|
|
@@ -1114,12 +1193,10 @@ var TypeGenerator = class {
|
|
|
1114
1193
|
const tables = [];
|
|
1115
1194
|
for (const entry of entries) if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
1116
1195
|
const tableName = (0, node_path.basename)(entry.name, ".jsonl");
|
|
1117
|
-
const
|
|
1118
|
-
const schemaFilePath = (0, node_path.join)(this.dataDirPath, schemaFileName);
|
|
1119
|
-
const hasSchema = entries.some((e) => e.isFile() && e.name === schemaFileName);
|
|
1196
|
+
const schemaFilePath = findSchemaFileInEntries(this.dataDirPath, tableName, entries);
|
|
1120
1197
|
tables.push({
|
|
1121
1198
|
tableName,
|
|
1122
|
-
schemaFile:
|
|
1199
|
+
schemaFile: schemaFilePath
|
|
1123
1200
|
});
|
|
1124
1201
|
}
|
|
1125
1202
|
return tables;
|
|
@@ -1140,7 +1217,7 @@ var TypeGenerator = class {
|
|
|
1140
1217
|
if (table.schemaFile) {
|
|
1141
1218
|
const schemaIdentifier = this.createSchemaIdentifier(table.tableName, usedAliases);
|
|
1142
1219
|
usedAliases.add(schemaIdentifier);
|
|
1143
|
-
let relativePath = (0, node_path.relative)((0, node_path.join)(this.outputFile, ".."), table.schemaFile).replace(/\\/g, "/")
|
|
1220
|
+
let relativePath = rewriteExtensionForImport((0, node_path.relative)((0, node_path.join)(this.outputFile, ".."), table.schemaFile).replace(/\\/g, "/"));
|
|
1144
1221
|
if (!relativePath.startsWith(".")) relativePath = "./" + relativePath;
|
|
1145
1222
|
imports.push(`import { schema as ${schemaIdentifier} } from '${relativePath}';`);
|
|
1146
1223
|
tableEntries.push(` ${tableKey}: InferOutput<typeof ${schemaIdentifier}>;`);
|
|
@@ -1221,9 +1298,14 @@ exports.JsonlReader = JsonlReader;
|
|
|
1221
1298
|
exports.JsonlWriter = JsonlWriter;
|
|
1222
1299
|
exports.LinesDB = LinesDB;
|
|
1223
1300
|
exports.RUNTIME = RUNTIME;
|
|
1301
|
+
exports.SCHEMA_EXTENSIONS = SCHEMA_EXTENSIONS;
|
|
1224
1302
|
exports.SchemaLoader = SchemaLoader;
|
|
1225
1303
|
exports.TypeGenerator = TypeGenerator;
|
|
1226
1304
|
exports.defineSchema = defineSchema;
|
|
1227
1305
|
exports.detectRuntime = detectRuntime;
|
|
1228
1306
|
exports.ensureTableRowsValid = ensureTableRowsValid;
|
|
1229
|
-
exports.
|
|
1307
|
+
exports.extractTableNameFromSchemaFile = extractTableNameFromSchemaFile;
|
|
1308
|
+
exports.findSchemaFile = findSchemaFile;
|
|
1309
|
+
exports.hasBackward = hasBackward;
|
|
1310
|
+
exports.isSchemaFile = isSchemaFile;
|
|
1311
|
+
exports.rewriteExtensionForImport = rewriteExtensionForImport;
|
package/dist/index.d.cts
CHANGED
|
@@ -344,7 +344,7 @@ declare class SchemaLoader {
|
|
|
344
344
|
static hasSchema(jsonlPath: string): Promise<boolean>;
|
|
345
345
|
/**
|
|
346
346
|
* Load a validation schema file for a table
|
|
347
|
-
* Requires ${tableName}.schema.ts to exist alongside the JSONL file
|
|
347
|
+
* Requires ${tableName}.schema.{ts,mts,cts} to exist alongside the JSONL file
|
|
348
348
|
*/
|
|
349
349
|
static loadSchema(jsonlPath: string): Promise<StandardSchema>;
|
|
350
350
|
/**
|
|
@@ -456,6 +456,7 @@ declare function hasBackward<Input extends Table, Output extends Table>(schema:
|
|
|
456
456
|
interface TypeGeneratorOptions {
|
|
457
457
|
dataDir: string;
|
|
458
458
|
projectRoot?: string;
|
|
459
|
+
output?: string;
|
|
459
460
|
}
|
|
460
461
|
declare class TypeGenerator {
|
|
461
462
|
private dataDir;
|
|
@@ -491,6 +492,33 @@ interface TableValidationOptions {
|
|
|
491
492
|
*/
|
|
492
493
|
declare function ensureTableRowsValid(options: TableValidationOptions): Promise<void>;
|
|
493
494
|
//#endregion
|
|
495
|
+
//#region src/schema-extensions.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* Supported schema file extensions, in priority order.
|
|
498
|
+
* The first match wins when discovering schema files.
|
|
499
|
+
*/
|
|
500
|
+
declare const SCHEMA_EXTENSIONS: readonly [".schema.ts", ".schema.mts", ".schema.cts"];
|
|
501
|
+
type SchemaExtension = (typeof SCHEMA_EXTENSIONS)[number];
|
|
502
|
+
/**
|
|
503
|
+
* Try each supported schema extension and return the full path of the first
|
|
504
|
+
* one that exists on disk. Returns undefined if none is found.
|
|
505
|
+
*/
|
|
506
|
+
declare function findSchemaFile(dir: string, tableName: string): Promise<string | undefined>;
|
|
507
|
+
/**
|
|
508
|
+
* Check if a filename matches any supported schema file pattern.
|
|
509
|
+
*/
|
|
510
|
+
declare function isSchemaFile(fileName: string): boolean;
|
|
511
|
+
/**
|
|
512
|
+
* Extract table name from a schema filename.
|
|
513
|
+
* e.g., "users.schema.ts" -> "users", "users.schema.mts" -> "users"
|
|
514
|
+
*/
|
|
515
|
+
declare function extractTableNameFromSchemaFile(fileName: string): string | null;
|
|
516
|
+
/**
|
|
517
|
+
* Rewrite a TypeScript path to its JavaScript counterpart for ESM imports.
|
|
518
|
+
* ".schema.ts" -> ".schema.js", ".schema.mts" -> ".schema.mjs", ".schema.cts" -> ".schema.cjs"
|
|
519
|
+
*/
|
|
520
|
+
declare function rewriteExtensionForImport(filePath: string): string;
|
|
521
|
+
//#endregion
|
|
494
522
|
//#region src/runtime.d.ts
|
|
495
523
|
/**
|
|
496
524
|
* Runtime detection utilities
|
|
@@ -499,5 +527,5 @@ type RuntimeEnvironment = 'node' | 'unknown';
|
|
|
499
527
|
declare function detectRuntime(): RuntimeEnvironment;
|
|
500
528
|
declare const RUNTIME: RuntimeEnvironment;
|
|
501
529
|
//#endregion
|
|
502
|
-
export { type BiDirectionalSchema, type ColumnDefinition, type DatabaseConfig, DirectoryScanner, type ForeignKeyDefinition, type IndexDefinition, type InferInput, type InferOutput, type JsonArray, type JsonObject, type JsonValue, JsonlReader, JsonlWriter, LinesDB, RUNTIME, type RuntimeEnvironment, type SQLiteDatabase, type SQLiteStatement, SchemaLoader, type SchemaOptions, type StandardSchema, type StandardSchemaIssue, type StandardSchemaResult, type Table, type TableConfig, type TableDefs, type TableSchema, type TableValidationOptions, TypeGenerator, type TypeGeneratorOptions, type ValidationError, type ValidationErrorDetail, type ValidationResult, defineSchema, detectRuntime, ensureTableRowsValid, hasBackward };
|
|
530
|
+
export { type BiDirectionalSchema, type ColumnDefinition, type DatabaseConfig, DirectoryScanner, type ForeignKeyDefinition, type IndexDefinition, type InferInput, type InferOutput, type JsonArray, type JsonObject, type JsonValue, JsonlReader, JsonlWriter, LinesDB, RUNTIME, type RuntimeEnvironment, SCHEMA_EXTENSIONS, type SQLiteDatabase, type SQLiteStatement, type SchemaExtension, SchemaLoader, type SchemaOptions, type StandardSchema, type StandardSchemaIssue, type StandardSchemaResult, type Table, type TableConfig, type TableDefs, type TableSchema, type TableValidationOptions, TypeGenerator, type TypeGeneratorOptions, type ValidationError, type ValidationErrorDetail, type ValidationResult, defineSchema, detectRuntime, ensureTableRowsValid, extractTableNameFromSchemaFile, findSchemaFile, hasBackward, isSchemaFile, rewriteExtensionForImport };
|
|
503
531
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/sqlite-adapter.ts","../src/types.ts","../src/database.ts","../src/jsonl-reader.ts","../src/jsonl-writer.ts","../src/schema-loader.ts","../src/directory-scanner.ts","../src/schema.ts","../src/type-generator.ts","../src/jsonl-migration.ts","../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;AASA;AAMA;;UANiB,cAAA;wBACO;ECPZ,IAAA,CAAA,GAAK,EAAA,MAAA,CAAA,EAAA,IAAG;EACR,KAAA,EAAA,EAAA,IAAA;;AACY,UDUP,eAAA,CCVO;EACP,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA;IAAQ,OAAA,EAAA,MAAA;IACJ,eAAA,EAAA,MAAA,GAAA,MAAA;EAAO,CAAA;EAAxB,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA,GAAA;EAAgB,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA,GAAA,EAAA;AACpB;;;KALY,KAAA,GAAQ;KACR,6BACI,QAAQ,sBACP,QAAQ,SACrB,iBAAiB,OAAO;ADEX,KCDL,oBDCmB,CACP,MAAA,CAAA,GCFmB,gBAAA,CAAiB,MDErB,CCF4B,MDE5B,CAAA;AAKtB,KCNL,mBAAA,GAAsB,gBAAA,CAAiB,KDMnB;KCCpB,kBAAgB,YAAU,qCAAqC;KAC/D,mBAAiB,YAAU,qCAAqC;AAdhE,UAiBK,gBAAA,CAjBS;EACd,KAAA,EAAA,OAAA;EACI,MAAA,EAiBN,qBAjBM,EAAA;EAAQ,QAAA,EAAA,MAAA,EAAA;;AACC,UAoBR,qBAAA,CApBQ;EACJ,IAAA,EAAA,MAAA;EAAO,SAAA,EAAA,MAAA;EAAxB,QAAA,EAAA,MAAA;EAAgB,MAAA,EAuBV,aAvBU,CAuBI,mBAvBJ,CAA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YAAA,EAkCW,EAlCK,OAkCL;;AACJ,UAtBF,WAAA,CAsBE;EAAU,SAAA,EAAA,MAAA;EAGjB,MAAA,CAAA,EAvBD,WAuBe;EAAW,eAAA,CAAA,EAAA,OAAA;EACrB,gBAAA,CAAA,EAtBK,cAsBL;;AACQ,UApBP,eAAA,SAAwB,KAoBjB,CAAA;EAApB,IAAA,EAAA,iBAAA;EAAmB,MAAA,EAlBb,aAkBa,CAlBC,mBAkBD,CAAA;AAEvB;AAA0C,KAjB9B,SAAA,GAiB8B,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,IAAA,GAjBiB,UAiBjB,GAjB8B,SAiB9B;AAA2B,UAhBpD,UAAA,CAgBoD;EAAZ,CAAA,GAAA,EAAA,MAAA,CAAA,EAfxC,SAewC;;AAAiB,KAb9D,SAAA,GAAY,SAakD,EAAA;AAAvB,KAVvC,UAUuC,CAAA,GAAA,CAAA,GAVvB,GAUuB,GAAA,CAAA,CAAA,KAAA,EAVV,GAUU,EAAA,GAAA,OAAA,CAAA;AAAK,KAR5C,WAQ4C,CAAA,YARtB,KAQsB,CAAA,GAAA,cAP1C,OAAK,WAAW,IAAE;KAGpB,2BAAyB,SACjC,YAAY,OACZ,oBAAoB;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/sqlite-adapter.ts","../src/types.ts","../src/database.ts","../src/jsonl-reader.ts","../src/jsonl-writer.ts","../src/schema-loader.ts","../src/directory-scanner.ts","../src/schema.ts","../src/type-generator.ts","../src/jsonl-migration.ts","../src/schema-extensions.ts","../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;AASA;AAMA;;UANiB,cAAA;wBACO;ECPZ,IAAA,CAAA,GAAK,EAAA,MAAA,CAAA,EAAA,IAAG;EACR,KAAA,EAAA,EAAA,IAAA;;AACY,UDUP,eAAA,CCVO;EACP,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA;IAAQ,OAAA,EAAA,MAAA;IACJ,e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KUPpB,eAAA,WAA0B;;;ATLtC;AACA;AACgB,iBSkBM,cAAA,CTlBN,GAAA,EAAA,MAAA,EAAA,SAAA,EAAA,MAAA,CAAA,ESqBb,OTrBa,CAAA,MAAA,GAAA,SAAA,CAAA;AAIhB;AAOA;;AAAsC,iBS4CtB,YAAA,CT5CsB,QAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;AACtC;;AAAuC,iBSmDvB,8BAAA,CTnDuB,QAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,IAAA;;;AAGvC;AAMA;AAciB,iBSyCD,yBAAA,CTzCqB,QAAA,EAAA,MAAA,CAAA,EAAA,MAAA;;;;;;AD/BpB,KWLL,kBAAA,GXMY,MAAA,GAAA,SAAe;AAKtB,iBWTD,aAAA,CAAA,CXSgB,EWTC,kBXSD;cWAnB,SAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -344,7 +344,7 @@ declare class SchemaLoader {
|
|
|
344
344
|
static hasSchema(jsonlPath: string): Promise<boolean>;
|
|
345
345
|
/**
|
|
346
346
|
* Load a validation schema file for a table
|
|
347
|
-
* Requires ${tableName}.schema.ts to exist alongside the JSONL file
|
|
347
|
+
* Requires ${tableName}.schema.{ts,mts,cts} to exist alongside the JSONL file
|
|
348
348
|
*/
|
|
349
349
|
static loadSchema(jsonlPath: string): Promise<StandardSchema>;
|
|
350
350
|
/**
|
|
@@ -456,6 +456,7 @@ declare function hasBackward<Input extends Table, Output extends Table>(schema:
|
|
|
456
456
|
interface TypeGeneratorOptions {
|
|
457
457
|
dataDir: string;
|
|
458
458
|
projectRoot?: string;
|
|
459
|
+
output?: string;
|
|
459
460
|
}
|
|
460
461
|
declare class TypeGenerator {
|
|
461
462
|
private dataDir;
|
|
@@ -491,6 +492,33 @@ interface TableValidationOptions {
|
|
|
491
492
|
*/
|
|
492
493
|
declare function ensureTableRowsValid(options: TableValidationOptions): Promise<void>;
|
|
493
494
|
//#endregion
|
|
495
|
+
//#region src/schema-extensions.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* Supported schema file extensions, in priority order.
|
|
498
|
+
* The first match wins when discovering schema files.
|
|
499
|
+
*/
|
|
500
|
+
declare const SCHEMA_EXTENSIONS: readonly [".schema.ts", ".schema.mts", ".schema.cts"];
|
|
501
|
+
type SchemaExtension = (typeof SCHEMA_EXTENSIONS)[number];
|
|
502
|
+
/**
|
|
503
|
+
* Try each supported schema extension and return the full path of the first
|
|
504
|
+
* one that exists on disk. Returns undefined if none is found.
|
|
505
|
+
*/
|
|
506
|
+
declare function findSchemaFile(dir: string, tableName: string): Promise<string | undefined>;
|
|
507
|
+
/**
|
|
508
|
+
* Check if a filename matches any supported schema file pattern.
|
|
509
|
+
*/
|
|
510
|
+
declare function isSchemaFile(fileName: string): boolean;
|
|
511
|
+
/**
|
|
512
|
+
* Extract table name from a schema filename.
|
|
513
|
+
* e.g., "users.schema.ts" -> "users", "users.schema.mts" -> "users"
|
|
514
|
+
*/
|
|
515
|
+
declare function extractTableNameFromSchemaFile(fileName: string): string | null;
|
|
516
|
+
/**
|
|
517
|
+
* Rewrite a TypeScript path to its JavaScript counterpart for ESM imports.
|
|
518
|
+
* ".schema.ts" -> ".schema.js", ".schema.mts" -> ".schema.mjs", ".schema.cts" -> ".schema.cjs"
|
|
519
|
+
*/
|
|
520
|
+
declare function rewriteExtensionForImport(filePath: string): string;
|
|
521
|
+
//#endregion
|
|
494
522
|
//#region src/runtime.d.ts
|
|
495
523
|
/**
|
|
496
524
|
* Runtime detection utilities
|
|
@@ -499,5 +527,5 @@ type RuntimeEnvironment = 'node' | 'unknown';
|
|
|
499
527
|
declare function detectRuntime(): RuntimeEnvironment;
|
|
500
528
|
declare const RUNTIME: RuntimeEnvironment;
|
|
501
529
|
//#endregion
|
|
502
|
-
export { type BiDirectionalSchema, type ColumnDefinition, type DatabaseConfig, DirectoryScanner, type ForeignKeyDefinition, type IndexDefinition, type InferInput, type InferOutput, type JsonArray, type JsonObject, type JsonValue, JsonlReader, JsonlWriter, LinesDB, RUNTIME, type RuntimeEnvironment, type SQLiteDatabase, type SQLiteStatement, SchemaLoader, type SchemaOptions, type StandardSchema, type StandardSchemaIssue, type StandardSchemaResult, type Table, type TableConfig, type TableDefs, type TableSchema, type TableValidationOptions, TypeGenerator, type TypeGeneratorOptions, type ValidationError, type ValidationErrorDetail, type ValidationResult, defineSchema, detectRuntime, ensureTableRowsValid, hasBackward };
|
|
530
|
+
export { type BiDirectionalSchema, type ColumnDefinition, type DatabaseConfig, DirectoryScanner, type ForeignKeyDefinition, type IndexDefinition, type InferInput, type InferOutput, type JsonArray, type JsonObject, type JsonValue, JsonlReader, JsonlWriter, LinesDB, RUNTIME, type RuntimeEnvironment, SCHEMA_EXTENSIONS, type SQLiteDatabase, type SQLiteStatement, type SchemaExtension, SchemaLoader, type SchemaOptions, type StandardSchema, type StandardSchemaIssue, type StandardSchemaResult, type Table, type TableConfig, type TableDefs, type TableSchema, type TableValidationOptions, TypeGenerator, type TypeGeneratorOptions, type ValidationError, type ValidationErrorDetail, type ValidationResult, defineSchema, detectRuntime, ensureTableRowsValid, extractTableNameFromSchemaFile, findSchemaFile, hasBackward, isSchemaFile, rewriteExtensionForImport };
|
|
503
531
|
//# sourceMappingURL=index.d.ts.map
|