lines-db 0.19.0 → 0.19.2
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 +26 -0
- package/README.ja.md +6 -4
- package/README.md +6 -4
- package/bin/cli.mjs +579 -78
- package/dist/index.d.mts +54 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +384 -79
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +2 -2
- package/dist/internal.mjs +1 -1
- package/dist/schema-module-D4j10w8_.mjs +396 -0
- package/dist/schema-module-D4j10w8_.mjs.map +1 -0
- package/dist/{jsonl-reader-aQqE1pe5.d.mts → schema-module-Tb40gPyF.d.mts} +16 -2
- package/dist/schema-module-Tb40gPyF.d.mts.map +1 -0
- package/package.json +4 -4
- package/dist/jsonl-reader-aQqE1pe5.d.mts.map +0 -1
- package/dist/replace-file-fStWc0ej.mjs +0 -200
- package/dist/replace-file-fStWc0ej.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as ValidationErrorDetail, C as StandardSchemaResult, D as TableSchema, E as TableDefs, M as WhereCondition, N as WriteFilledValues, O as TableValidationResult, S as StandardSchemaIssue, T as TableConfig, _ as JsonObject, b as JsonlParseError, c as ok, d as DatabaseConfig, f as ForeignKeyDefinition, g as JsonArray, h as InferOutput, i as JsonlSnapshot, j as ValidationResult, k as ValidationError, l as unwrap, m as InferInput, o as Result, p as IndexDefinition, r as JsonlReader, s as err, t as SchemaImports, u as ColumnDefinition, v as JsonValue, w as Table, x as StandardSchema, y as JsonlConflictError } from "./schema-module-Tb40gPyF.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* SQLite adapter for Node.js
|
|
4
4
|
*/
|
|
@@ -80,6 +80,18 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
80
80
|
* back, also once the row's primary key changed and its line can no longer be found by it
|
|
81
81
|
*/
|
|
82
82
|
private linesWithUnknownFields;
|
|
83
|
+
/**
|
|
84
|
+
* For a table without a primary key, where each row's line stands in its file: the rows cannot be
|
|
85
|
+
* matched to their lines by key, and by order only while none is added or removed
|
|
86
|
+
*/
|
|
87
|
+
private linePositionsByRowid;
|
|
88
|
+
/**
|
|
89
|
+
* What happened to the positions of a table's rows since its rows were read for its write-back, in order: the
|
|
90
|
+
* positions that write-back computes describe the rows as they were, and are brought up to date with these
|
|
91
|
+
*/
|
|
92
|
+
private positionEdits;
|
|
93
|
+
/** Whether the temporary table that triggers log the rowid changes of rows to exists */
|
|
94
|
+
private movedRowsLogReady;
|
|
83
95
|
/** Whether a transaction's callback has returned and its files are being written back */
|
|
84
96
|
private transactionClosing;
|
|
85
97
|
/** Whether a transaction() call is past its guard but has not begun yet */
|
|
@@ -105,6 +117,8 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
105
117
|
private tablesFromGivenColumns;
|
|
106
118
|
/** Each table's schema file and a hash of its content as the tables were loaded, or '' for none */
|
|
107
119
|
private schemaFileStates;
|
|
120
|
+
private schemaImports;
|
|
121
|
+
private schemaDependencyHashes;
|
|
108
122
|
private constructor();
|
|
109
123
|
static create<Tables extends TableDefs>(config: DatabaseConfig<Tables>, dbPath?: string): LinesDB<Tables>;
|
|
110
124
|
/**
|
|
@@ -123,6 +137,7 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
123
137
|
}): Promise<Result<ValidationResult, Error>>;
|
|
124
138
|
private initializeInternal;
|
|
125
139
|
private loadTables;
|
|
140
|
+
private importSchemaModule;
|
|
126
141
|
/**
|
|
127
142
|
* Load a table and its dependencies recursively
|
|
128
143
|
*/
|
|
@@ -382,6 +397,25 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
382
397
|
* since this database last read or wrote it
|
|
383
398
|
*/
|
|
384
399
|
private prepareWriteBack;
|
|
400
|
+
private forgetPosition;
|
|
401
|
+
/**
|
|
402
|
+
* The rowid of the row each line was loaded into, in the order of the lines. Not the rowid order: an INTEGER
|
|
403
|
+
* PRIMARY KEY is the rowid, so the line `{"id":3}` first in its file is the row with rowid 3
|
|
404
|
+
*/
|
|
405
|
+
private rowidsInLineOrder;
|
|
406
|
+
/**
|
|
407
|
+
* Log each change of a row's rowid in the table: a foreign-key action or raw SQL can change an INTEGER PRIMARY
|
|
408
|
+
* KEY, which is the rowid, without a write through this database telling it which row moved
|
|
409
|
+
*/
|
|
410
|
+
private logMovedRows;
|
|
411
|
+
/** Move what is kept by rowid to the rowid each logged row moved to, in the order the rows moved */
|
|
412
|
+
private applyMovedRows;
|
|
413
|
+
/**
|
|
414
|
+
* Whether the lines of a table are remembered by position, so a row whose key changed, or that has none, is
|
|
415
|
+
* found again by where its line stood. Several data directories have the origin of each row instead
|
|
416
|
+
*/
|
|
417
|
+
private tracksLinePositions;
|
|
418
|
+
private hasNoPrimaryKey;
|
|
385
419
|
private prepareFileWriteBack;
|
|
386
420
|
/**
|
|
387
421
|
* Every row of a table in rowid order - the order the file was read in - as stored and as its line
|
|
@@ -415,11 +449,13 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
415
449
|
private applyResets;
|
|
416
450
|
/**
|
|
417
451
|
* Every row of a table with the fields the schema filled in rather than the file: the ones its line
|
|
418
|
-
* does not hold and no write set, which a write-back leaves out of the file
|
|
452
|
+
* does not hold and no write set, which a write-back leaves out of the file. `input` is the row as
|
|
453
|
+
* its line holds it - the values before the schema transformed them, without the defaulted fields.
|
|
419
454
|
*/
|
|
420
455
|
findWithDefaults<K extends keyof Tables & string>(tableName: K): Promise<Result<Array<{
|
|
421
456
|
row: Tables[K];
|
|
422
457
|
defaulted: string[];
|
|
458
|
+
input: JsonObject;
|
|
423
459
|
}>, Error>>;
|
|
424
460
|
private writePrepared;
|
|
425
461
|
/**
|
|
@@ -464,6 +500,12 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
464
500
|
* rejects them instead, since there the caller named both the table and the fields.
|
|
465
501
|
*/
|
|
466
502
|
private mergeWithExistingLines;
|
|
503
|
+
/**
|
|
504
|
+
* The primary key the schema makes of a line, which is how the stored rows hold it. The line's own key
|
|
505
|
+
* when the rows are in the line's terms (a `backward` transformation maps them back), when there is no
|
|
506
|
+
* schema, or when the schema refuses the line
|
|
507
|
+
*/
|
|
508
|
+
private outputKeyOfLine;
|
|
467
509
|
/**
|
|
468
510
|
* Pair each row with the JSONL line it came from, indexed the same way as `rows`.
|
|
469
511
|
* Returns undefined when the rows cannot be matched and the caller can do without it.
|
|
@@ -484,12 +526,20 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
484
526
|
hasExternalChanges(): Promise<Result<boolean, Error>>;
|
|
485
527
|
/**
|
|
486
528
|
* The files that changed since this database last read or wrote them, as {@link hasExternalChanges}
|
|
487
|
-
* tells: each JSONL file edited, added or removed,
|
|
529
|
+
* tells: each JSONL file edited, added or removed, each schema file edited, added or removed, and each
|
|
530
|
+
* project file a schema imports edited, added or removed
|
|
488
531
|
*/
|
|
489
532
|
findExternalChanges(): Promise<Result<string[], Error>>;
|
|
490
533
|
private findExternalChangesInternal;
|
|
491
534
|
/** The state of the schema file a state names, for a table whose JSONL file is gone */
|
|
492
535
|
private stateOfKnownSchemaFile;
|
|
536
|
+
private recordSchemaDependencies;
|
|
537
|
+
/**
|
|
538
|
+
* The project files the schemas import, as paths: not the schema files, and not a package from
|
|
539
|
+
* node_modules. Those of one table when it is given. An edit to one of them is among
|
|
540
|
+
* {@link findExternalChanges}
|
|
541
|
+
*/
|
|
542
|
+
listSchemaDependencies(tableName?: string): string[];
|
|
493
543
|
private schemaFileState;
|
|
494
544
|
/**
|
|
495
545
|
* Sync database changes back to JSONL files
|
|
@@ -641,7 +691,7 @@ export declare class SchemaLoader {
|
|
|
641
691
|
* Load a validation schema file for a table
|
|
642
692
|
* Requires ${tableName}.schema.{ts,mts,cts} to exist in schemaDir, or alongside the JSONL file when omitted
|
|
643
693
|
*/
|
|
644
|
-
static loadSchema(jsonlPath: string, schemaDir?: string): Promise<StandardSchema>;
|
|
694
|
+
static loadSchema(jsonlPath: string, schemaDir?: string, imports?: SchemaImports): Promise<StandardSchema>;
|
|
645
695
|
/**
|
|
646
696
|
* Check if an object implements the StandardSchema interface
|
|
647
697
|
*/
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/sqlite-adapter.ts","../src/database.ts","../src/jsonl-writer.ts","../src/merge-fields.ts","../src/fill.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/error-formatter.ts","../src/runtime.ts","../src/dataset-config.ts"],"mappings":";;;;;;;UASiB;EACf,QAAQ,cAAc;EACtB,KAAK;EACL;;UAGe;EACf,OAAO;IAAkB;IAAiB;;EAC1C,OAAO;EACP,OAAO;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/sqlite-adapter.ts","../src/database.ts","../src/jsonl-writer.ts","../src/merge-fields.ts","../src/fill.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/error-formatter.ts","../src/runtime.ts","../src/dataset-config.ts"],"mappings":";;;;;;;UASiB;EACf,QAAQ,cAAc;EACtB,KAAK;EACL;;UAGe;EACf,OAAO;IAAkB;IAAiB;;EAC1C,OAAO;EACP,OAAO;;;;;UCoBQ;;EAEf;;;;;EAKA;;;;;UAMe;;;;;;;;;EASf;;;;;EAKA,oBAAoB;;qBAuLT,QAAQ,eAAe;UAC1B;mBACS;UACT;UACA;UACA;UACA;UACA;UACA;;UAEA;;UAEA;;;;;UAKA;UACA;;;;;UAKA;;UAEA;;;;;UAKA;;;;;UAKA;;;;;UAKA;;UAEA;;UAEA;;UAEA;;UAEA;;UAEA;;UAEA;;UAEA;;;;;UAKA;;UAEA;;UAEA;;UAEA;;UAEA;UAEA;U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