@toiroakr/lines-db 0.1.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/LICENSE +21 -0
- package/bin/cli.js +1373 -0
- package/dist/index.cjs +1212 -0
- package/dist/index.d.cts +486 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +486 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1181 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
- package/src/cli.ts +333 -0
- package/src/database.test.ts +493 -0
- package/src/database.ts +1025 -0
- package/src/directory-scanner.test.ts +91 -0
- package/src/directory-scanner.ts +38 -0
- package/src/error-formatter.ts +166 -0
- package/src/index.ts +35 -0
- package/src/jsonl-migration.ts +76 -0
- package/src/jsonl-reader.test.ts +168 -0
- package/src/jsonl-reader.ts +135 -0
- package/src/jsonl-writer.test.ts +101 -0
- package/src/jsonl-writer.ts +33 -0
- package/src/runtime.ts +34 -0
- package/src/schema-loader.test.ts +136 -0
- package/src/schema-loader.ts +64 -0
- package/src/schema.ts +135 -0
- package/src/sqlite-adapter.ts +99 -0
- package/src/type-generator.ts +201 -0
- package/src/types.ts +99 -0
- package/src/validator.test.ts +337 -0
- package/src/validator.ts +207 -0
- package/tsconfig.json +20 -0
- package/tsconfig.test.json +8 -0
- package/tsdown.config.ts +26 -0
- package/vitest.config.ts +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/sqlite-adapter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SQLite adapter that works across Node.js, Bun, and Deno
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Common interface for SQLite database
|
|
10
|
+
*/
|
|
11
|
+
interface SQLiteDatabase {
|
|
12
|
+
prepare(sql: string): SQLiteStatement;
|
|
13
|
+
exec(sql: string): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|
|
16
|
+
interface SQLiteStatement {
|
|
17
|
+
run(...params: any[]): {
|
|
18
|
+
changes: number;
|
|
19
|
+
lastInsertRowid: number | bigint;
|
|
20
|
+
};
|
|
21
|
+
get(...params: any[]): any;
|
|
22
|
+
all(...params: any[]): any[];
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/types.d.ts
|
|
26
|
+
type Table = Record<string, unknown>;
|
|
27
|
+
type StandardSchema<Input extends Table = Table, Output extends Table = Input> = StandardSchemaV1<Input, Output>;
|
|
28
|
+
type StandardSchemaResult<Output> = StandardSchemaV1.Result<Output>;
|
|
29
|
+
type StandardSchemaIssue = StandardSchemaV1.Issue;
|
|
30
|
+
type InferInput<T$1> = T$1 extends StandardSchemaV1<infer I, unknown> ? I : never;
|
|
31
|
+
type InferOutput<T$1> = T$1 extends StandardSchemaV1<unknown, infer O> ? O : never;
|
|
32
|
+
interface ForeignKeyDefinition {
|
|
33
|
+
columns: string[];
|
|
34
|
+
references: {
|
|
35
|
+
table: string;
|
|
36
|
+
columns: string[];
|
|
37
|
+
};
|
|
38
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
39
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
40
|
+
}
|
|
41
|
+
interface IndexDefinition {
|
|
42
|
+
name?: string;
|
|
43
|
+
columns: string[];
|
|
44
|
+
unique?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface TableSchema {
|
|
47
|
+
name: string;
|
|
48
|
+
columns: ColumnDefinition[];
|
|
49
|
+
foreignKeys?: ForeignKeyDefinition[];
|
|
50
|
+
indexes?: IndexDefinition[];
|
|
51
|
+
}
|
|
52
|
+
interface ColumnDefinition {
|
|
53
|
+
name: string;
|
|
54
|
+
type: 'TEXT' | 'INTEGER' | 'REAL' | 'BLOB' | 'NULL' | 'JSON';
|
|
55
|
+
primaryKey?: boolean;
|
|
56
|
+
notNull?: boolean;
|
|
57
|
+
unique?: boolean;
|
|
58
|
+
valueType?: 'boolean';
|
|
59
|
+
}
|
|
60
|
+
type TableDefs = Record<string, Table>;
|
|
61
|
+
declare const TABLES_BRAND: unique symbol;
|
|
62
|
+
interface DatabaseConfig<_Tables extends TableDefs = TableDefs> {
|
|
63
|
+
dataDir: string;
|
|
64
|
+
readonly [TABLES_BRAND]?: _Tables;
|
|
65
|
+
}
|
|
66
|
+
interface TableConfig {
|
|
67
|
+
jsonlPath: string;
|
|
68
|
+
schema?: TableSchema;
|
|
69
|
+
autoInferSchema?: boolean;
|
|
70
|
+
validationSchema?: StandardSchema;
|
|
71
|
+
}
|
|
72
|
+
interface ValidationError extends Error {
|
|
73
|
+
name: 'ValidationError';
|
|
74
|
+
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
75
|
+
}
|
|
76
|
+
type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
77
|
+
interface JsonObject {
|
|
78
|
+
[key: string]: JsonValue;
|
|
79
|
+
}
|
|
80
|
+
type JsonArray = JsonValue[];
|
|
81
|
+
type WhereValue<T$1> = T$1 | ((value: T$1) => boolean);
|
|
82
|
+
type WhereObject<T$1 extends Table> = { [K in keyof T$1]?: WhereValue<T$1[K]> };
|
|
83
|
+
type WhereCondition<T$1 extends Table> = WhereObject<T$1> | WhereConditionArray<T$1>;
|
|
84
|
+
type WhereConditionArray<T$1 extends Table> = Array<WhereObject<T$1> | WhereConditionArray<T$1>>;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/database.d.ts
|
|
87
|
+
declare class LinesDB<Tables extends TableDefs> {
|
|
88
|
+
private db;
|
|
89
|
+
private config;
|
|
90
|
+
private schemas;
|
|
91
|
+
private validationSchemas;
|
|
92
|
+
private tables;
|
|
93
|
+
private inTransaction;
|
|
94
|
+
private constructor();
|
|
95
|
+
static create<Tables extends TableDefs>(config: DatabaseConfig<Tables>, dbPath?: string): LinesDB<Tables>;
|
|
96
|
+
/**
|
|
97
|
+
* Initialize database by loading all JSONL files
|
|
98
|
+
*/
|
|
99
|
+
initialize(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Load a single table from JSONL file
|
|
102
|
+
*/
|
|
103
|
+
private loadTable;
|
|
104
|
+
/**
|
|
105
|
+
* Create table in SQLite with constraints and indexes
|
|
106
|
+
*/
|
|
107
|
+
private createTable;
|
|
108
|
+
/**
|
|
109
|
+
* Quote table name to handle special characters in SQL
|
|
110
|
+
*/
|
|
111
|
+
private quoteTableName;
|
|
112
|
+
/**
|
|
113
|
+
* Quote identifier for SQL statements, escaping embedded quotes
|
|
114
|
+
*/
|
|
115
|
+
private quoteIdentifier;
|
|
116
|
+
/**
|
|
117
|
+
* Insert data into table
|
|
118
|
+
*/
|
|
119
|
+
private insertData;
|
|
120
|
+
/**
|
|
121
|
+
* Execute a raw SQL query
|
|
122
|
+
*/
|
|
123
|
+
query<T$1 = unknown>(sql: string, params?: (string | number | bigint | null | Uint8Array)[]): T$1[];
|
|
124
|
+
/**
|
|
125
|
+
* Execute a SQL query that returns a single row
|
|
126
|
+
*/
|
|
127
|
+
queryOne<T$1 = unknown>(sql: string, params?: (string | number | bigint | null | Uint8Array)[]): T$1 | null;
|
|
128
|
+
/**
|
|
129
|
+
* Execute a SQL statement (INSERT, UPDATE, DELETE)
|
|
130
|
+
*/
|
|
131
|
+
execute(sql: string, params?: (string | number | bigint | null | Uint8Array)[]): {
|
|
132
|
+
changes: number | bigint;
|
|
133
|
+
lastInsertRowid: number | bigint;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Find rows by condition (supports OR/AND with arrays and function filters)
|
|
137
|
+
* If where is not provided, returns all rows
|
|
138
|
+
*/
|
|
139
|
+
find<K$1 extends keyof Tables & string>(tableName: K$1, where?: WhereCondition<Tables[K$1]>): Tables[K$1][];
|
|
140
|
+
/**
|
|
141
|
+
* Find a single row by condition (supports OR/AND with arrays and function filters)
|
|
142
|
+
*/
|
|
143
|
+
findOne<K$1 extends keyof Tables & string>(tableName: K$1, where: WhereCondition<Tables[K$1]>): Tables[K$1] | null;
|
|
144
|
+
/**
|
|
145
|
+
* Deserialize JSON columns in a row
|
|
146
|
+
*/
|
|
147
|
+
private deserializeRow;
|
|
148
|
+
/**
|
|
149
|
+
* Validate data using StandardSchema
|
|
150
|
+
* Note: Only synchronous validation is supported
|
|
151
|
+
*/
|
|
152
|
+
private validateData;
|
|
153
|
+
/**
|
|
154
|
+
* Insert a row into a table with validation
|
|
155
|
+
*/
|
|
156
|
+
insert<K$1 extends keyof Tables & string>(tableName: K$1, data: Tables[K$1]): {
|
|
157
|
+
changes: number | bigint;
|
|
158
|
+
lastInsertRowid: number | bigint;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Batch insert rows with validation per record.
|
|
162
|
+
*/
|
|
163
|
+
batchInsert<K$1 extends keyof Tables & string>(tableName: K$1, records: Tables[K$1][]): {
|
|
164
|
+
changes: number | bigint;
|
|
165
|
+
lastInsertRowid: number | bigint;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Update rows in a table with validation (supports OR/AND with arrays)
|
|
169
|
+
* Note: Function filters are not supported for update operations
|
|
170
|
+
* Note: By default, validation is enabled. For partial updates, existing data is fetched
|
|
171
|
+
* and merged before validation. Set options.validate = false to disable validation.
|
|
172
|
+
*/
|
|
173
|
+
update<K$1 extends keyof Tables & string>(tableName: K$1, data: Partial<Tables[K$1]>, where: WhereCondition<Tables[K$1]>, options?: {
|
|
174
|
+
validate?: boolean;
|
|
175
|
+
}): {
|
|
176
|
+
changes: number | bigint;
|
|
177
|
+
lastInsertRowid: number | bigint;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Batch update rows with record-specific values and validation.
|
|
181
|
+
* Each record must include the primary key to identify the target row.
|
|
182
|
+
* Validation runs once per merged record unless explicitly disabled.
|
|
183
|
+
*/
|
|
184
|
+
batchUpdate<K$1 extends keyof Tables & string>(tableName: K$1, records: Array<Partial<Tables[K$1]> & Record<string, unknown>>, options?: {
|
|
185
|
+
validate?: boolean;
|
|
186
|
+
}): {
|
|
187
|
+
changes: number | bigint;
|
|
188
|
+
lastInsertRowid: number | bigint;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Delete rows from a table (supports OR/AND with arrays)
|
|
192
|
+
* Note: Function filters are not supported for delete operations
|
|
193
|
+
*/
|
|
194
|
+
delete<K$1 extends keyof Tables & string>(tableName: K$1, where: WhereCondition<Tables[K$1]>): {
|
|
195
|
+
changes: number | bigint;
|
|
196
|
+
lastInsertRowid: number | bigint;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Batch delete rows by primary key.
|
|
200
|
+
*/
|
|
201
|
+
batchDelete<K$1 extends keyof Tables & string>(tableName: K$1, records: Array<Partial<Tables[K$1]> & Record<string, unknown>>): {
|
|
202
|
+
changes: number | bigint;
|
|
203
|
+
lastInsertRowid: number | bigint;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Normalize value for SQLite
|
|
207
|
+
*/
|
|
208
|
+
private normalizeValue;
|
|
209
|
+
/**
|
|
210
|
+
* Build WHERE clause from condition (supports OR/AND with arrays and functions)
|
|
211
|
+
*/
|
|
212
|
+
private buildWhereClause;
|
|
213
|
+
/**
|
|
214
|
+
* Apply OR condition with function filters by evaluating each row against the condition
|
|
215
|
+
*/
|
|
216
|
+
private applyOrConditionWithFilters;
|
|
217
|
+
/**
|
|
218
|
+
* Check if a row matches an OR/AND condition (recursively)
|
|
219
|
+
*/
|
|
220
|
+
private matchesOrCondition;
|
|
221
|
+
/**
|
|
222
|
+
* Apply function filters to rows
|
|
223
|
+
*/
|
|
224
|
+
private applyFunctionFilters;
|
|
225
|
+
/**
|
|
226
|
+
* Get table schema
|
|
227
|
+
*/
|
|
228
|
+
getSchema(tableName: string): TableSchema | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Get all table names
|
|
231
|
+
*/
|
|
232
|
+
getTableNames(): string[];
|
|
233
|
+
/**
|
|
234
|
+
* Sync a specific table back to its JSONL file
|
|
235
|
+
* Uses backward transformation when available
|
|
236
|
+
*/
|
|
237
|
+
private syncTable;
|
|
238
|
+
/**
|
|
239
|
+
* Sync database changes back to JSONL files
|
|
240
|
+
* Uses backward transformation when available
|
|
241
|
+
*/
|
|
242
|
+
sync(): Promise<void>;
|
|
243
|
+
/**
|
|
244
|
+
* Execute a function within a transaction
|
|
245
|
+
* Automatically commits on success or rolls back on error
|
|
246
|
+
*/
|
|
247
|
+
transaction<T$1>(fn: (tx: LinesDB<Tables>) => Promise<T$1> | T$1): Promise<T$1>;
|
|
248
|
+
/**
|
|
249
|
+
* Close the database connection
|
|
250
|
+
*/
|
|
251
|
+
close(): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Get the underlying SQLite database instance
|
|
254
|
+
*/
|
|
255
|
+
getDb(): SQLiteDatabase;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/jsonl-reader.d.ts
|
|
259
|
+
declare class JsonlReader {
|
|
260
|
+
private static overrides;
|
|
261
|
+
/**
|
|
262
|
+
* Temporarily override the data returned for specific JSONL files.
|
|
263
|
+
* Useful for scenarios like migration validation where in-memory data should be used.
|
|
264
|
+
*/
|
|
265
|
+
static withOverrides<T$1>(overrides: Map<string, JsonObject[]>, fn: () => Promise<T$1>): Promise<T$1>;
|
|
266
|
+
/**
|
|
267
|
+
* Read JSONL file and parse each line as JSON
|
|
268
|
+
*/
|
|
269
|
+
static read(filePath: string): Promise<JsonObject[]>;
|
|
270
|
+
/**
|
|
271
|
+
* Infer schema from JSONL data
|
|
272
|
+
*/
|
|
273
|
+
static inferSchema(tableName: string, data: JsonObject[]): TableSchema;
|
|
274
|
+
private static inferType;
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/jsonl-writer.d.ts
|
|
278
|
+
declare class JsonlWriter {
|
|
279
|
+
/**
|
|
280
|
+
* Write data to JSONL file
|
|
281
|
+
*/
|
|
282
|
+
static write(filePath: string, data: JsonObject[]): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Append data to JSONL file
|
|
285
|
+
*/
|
|
286
|
+
static append(filePath: string, data: JsonObject[]): Promise<void>;
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/schema-loader.d.ts
|
|
290
|
+
declare class SchemaLoader {
|
|
291
|
+
/**
|
|
292
|
+
* Load a validation schema file for a table
|
|
293
|
+
* Requires ${tableName}.schema.ts to exist alongside the JSONL file
|
|
294
|
+
*/
|
|
295
|
+
static loadSchema(jsonlPath: string): Promise<StandardSchema>;
|
|
296
|
+
/**
|
|
297
|
+
* Check if an object implements the StandardSchema interface
|
|
298
|
+
*/
|
|
299
|
+
private static isStandardSchema;
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/directory-scanner.d.ts
|
|
303
|
+
declare class DirectoryScanner {
|
|
304
|
+
/**
|
|
305
|
+
* Scan directory for JSONL files and create table configurations
|
|
306
|
+
*/
|
|
307
|
+
static scanDirectory(dataDir: string): Promise<Map<string, TableConfig>>;
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/schema.d.ts
|
|
311
|
+
/**
|
|
312
|
+
* Schema options for defining constraints and indexes
|
|
313
|
+
*/
|
|
314
|
+
interface SchemaOptions {
|
|
315
|
+
/**
|
|
316
|
+
* Primary key columns
|
|
317
|
+
*/
|
|
318
|
+
primaryKey?: string[];
|
|
319
|
+
/**
|
|
320
|
+
* Foreign key constraints
|
|
321
|
+
*/
|
|
322
|
+
foreignKeys?: ForeignKeyDefinition[];
|
|
323
|
+
/**
|
|
324
|
+
* Indexes to create
|
|
325
|
+
*/
|
|
326
|
+
indexes?: IndexDefinition[];
|
|
327
|
+
/**
|
|
328
|
+
* Backward transformation from Output to Input
|
|
329
|
+
* Required when Input and Output types differ (e.g., with transformations)
|
|
330
|
+
*/
|
|
331
|
+
backward?: (output: Table) => Table;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* BiDirectional Schema interface
|
|
335
|
+
* Extends StandardSchema with optional backward transformation and schema metadata
|
|
336
|
+
*/
|
|
337
|
+
interface BiDirectionalSchema<Input extends Table = Table, Output extends Table = Input> extends StandardSchema<Input, Output> {
|
|
338
|
+
/**
|
|
339
|
+
* Backward transformation from Output to Input
|
|
340
|
+
* Required when Input and Output types differ (e.g., with transformations)
|
|
341
|
+
*/
|
|
342
|
+
backward?: (output: Output) => Input;
|
|
343
|
+
/**
|
|
344
|
+
* Primary key columns
|
|
345
|
+
*/
|
|
346
|
+
primaryKey?: string[];
|
|
347
|
+
/**
|
|
348
|
+
* Foreign key constraints
|
|
349
|
+
*/
|
|
350
|
+
foreignKeys?: ForeignKeyDefinition[];
|
|
351
|
+
/**
|
|
352
|
+
* Indexes to create
|
|
353
|
+
*/
|
|
354
|
+
indexes?: IndexDefinition[];
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Define a bidirectional schema with optional backward transformation
|
|
358
|
+
*
|
|
359
|
+
* @param schema - Standard Schema for validation
|
|
360
|
+
* @param optionsOrBackward - Optional SchemaOptions object or backward transformation function (Output → Input)
|
|
361
|
+
* Required when schema performs transformations
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* // No transformation - backward not needed
|
|
365
|
+
* const schema = defineSchema(
|
|
366
|
+
* v.object({ id: v.number(), name: v.string() })
|
|
367
|
+
* );
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* // With transformation - backward recommended (legacy)
|
|
371
|
+
* const schema = defineSchema(
|
|
372
|
+
* v.pipe(v.string(), v.transform(Number)),
|
|
373
|
+
* (num) => String(num) // backward: number → string
|
|
374
|
+
* );
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* // With primary key and foreign key
|
|
378
|
+
* const schema = defineSchema(
|
|
379
|
+
* v.object({ id: v.number(), customerId: v.number() }),
|
|
380
|
+
* {
|
|
381
|
+
* primaryKey: ['id'],
|
|
382
|
+
* foreignKeys: [
|
|
383
|
+
* { columns: ['customerId'], references: { table: 'users', columns: ['id'] } }
|
|
384
|
+
* ]
|
|
385
|
+
* }
|
|
386
|
+
* );
|
|
387
|
+
*/
|
|
388
|
+
declare function defineSchema<Input extends Table, Output extends Table>(schema: StandardSchema<Input, Output>, optionsOrBackward?: SchemaOptions | ((output: Output) => Input)): BiDirectionalSchema<Input, Output>;
|
|
389
|
+
/**
|
|
390
|
+
* Check if a schema has backward transformation
|
|
391
|
+
*/
|
|
392
|
+
declare function hasBackward<Input extends Table, Output extends Table>(schema: StandardSchema<Input, Output>): schema is BiDirectionalSchema<Input, Output>;
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/type-generator.d.ts
|
|
395
|
+
interface TypeGeneratorOptions {
|
|
396
|
+
dataDir: string;
|
|
397
|
+
projectRoot?: string;
|
|
398
|
+
}
|
|
399
|
+
declare class TypeGenerator {
|
|
400
|
+
private dataDir;
|
|
401
|
+
private projectRoot;
|
|
402
|
+
private outputFile;
|
|
403
|
+
private dataDirPath;
|
|
404
|
+
constructor(options: TypeGeneratorOptions);
|
|
405
|
+
/**
|
|
406
|
+
* Generate types file from JSONL files and their optional schema files.
|
|
407
|
+
*/
|
|
408
|
+
generate(): Promise<string>;
|
|
409
|
+
/**
|
|
410
|
+
* Find all *.jsonl files and check if they have corresponding *.schema.ts files
|
|
411
|
+
*/
|
|
412
|
+
private findTables;
|
|
413
|
+
/**
|
|
414
|
+
* Generate type declaration content
|
|
415
|
+
*/
|
|
416
|
+
private generateTypeDeclarations;
|
|
417
|
+
private createSchemaIdentifier;
|
|
418
|
+
private formatTableKey;
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/validator.d.ts
|
|
422
|
+
interface ValidationResult {
|
|
423
|
+
valid: boolean;
|
|
424
|
+
errors: ValidationErrorDetail[];
|
|
425
|
+
}
|
|
426
|
+
interface ValidationErrorDetail {
|
|
427
|
+
file: string;
|
|
428
|
+
tableName: string;
|
|
429
|
+
rowIndex: number;
|
|
430
|
+
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
431
|
+
type?: 'schema' | 'foreignKey';
|
|
432
|
+
foreignKeyError?: {
|
|
433
|
+
column: string;
|
|
434
|
+
value: unknown;
|
|
435
|
+
referencedTable: string;
|
|
436
|
+
referencedColumn: string;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
interface ValidatorOptions {
|
|
440
|
+
path: string;
|
|
441
|
+
projectRoot?: string;
|
|
442
|
+
}
|
|
443
|
+
declare class Validator {
|
|
444
|
+
private path;
|
|
445
|
+
private projectRoot;
|
|
446
|
+
constructor(options: ValidatorOptions);
|
|
447
|
+
/**
|
|
448
|
+
* Validate JSONL file(s)
|
|
449
|
+
*/
|
|
450
|
+
validate(): Promise<ValidationResult>;
|
|
451
|
+
/**
|
|
452
|
+
* Validate all JSONL files in a directory
|
|
453
|
+
*/
|
|
454
|
+
private validateDirectory;
|
|
455
|
+
/**
|
|
456
|
+
* Validate foreign key constraints across all tables
|
|
457
|
+
*/
|
|
458
|
+
private validateForeignKeys;
|
|
459
|
+
/**
|
|
460
|
+
* Validate a single JSONL file
|
|
461
|
+
*/
|
|
462
|
+
private validateFile;
|
|
463
|
+
}
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/jsonl-migration.d.ts
|
|
466
|
+
interface TableValidationOptions {
|
|
467
|
+
dataDir: string;
|
|
468
|
+
tableName: string;
|
|
469
|
+
rows: JsonObject[];
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Validate a table by temporarily supplying in-memory rows while reusing the existing LinesDB validation pipeline.
|
|
473
|
+
* If validation fails, the underlying LinesDB error is rethrown so callers can inspect validation details.
|
|
474
|
+
*/
|
|
475
|
+
declare function ensureTableRowsValid(options: TableValidationOptions): Promise<void>;
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/runtime.d.ts
|
|
478
|
+
/**
|
|
479
|
+
* Runtime detection utilities
|
|
480
|
+
*/
|
|
481
|
+
type RuntimeEnvironment = 'node' | 'bun' | 'deno' | 'unknown';
|
|
482
|
+
declare function detectRuntime(): RuntimeEnvironment;
|
|
483
|
+
declare const RUNTIME: RuntimeEnvironment;
|
|
484
|
+
//#endregion
|
|
485
|
+
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, Validator, type ValidatorOptions, defineSchema, detectRuntime, ensureTableRowsValid, hasBackward };
|
|
486
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","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/validator.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,EAA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