lines-db 0.19.2 → 0.19.3
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 +8 -0
- package/README.ja.md +16 -0
- package/README.md +16 -0
- package/bin/cli.mjs +73 -41
- package/dist/index.d.mts +17 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/internal.mjs +1 -1
- package/dist/{schema-module-Tb40gPyF.d.mts → schema-module-C_GKc1zV.d.mts} +3 -1
- package/dist/{schema-module-Tb40gPyF.d.mts.map → schema-module-C_GKc1zV.d.mts.map} +1 -1
- package/dist/{schema-module-D4j10w8_.mjs → schema-module-CdiS2Jq_.mjs} +41 -14
- package/dist/schema-module-CdiS2Jq_.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/schema-module-D4j10w8_.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @toiroakr/lines-db
|
|
2
2
|
|
|
3
|
+
## 0.19.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dbe99ef: `jsonlRecordLines(content)` is now exported. It applies the rule `JsonlReader` and `lines-db validate` read a JSONL file with (drop one leading byte order mark and each trailing carriage return, skip lines that are blank after trimming, count physical lines) and returns each row's trimmed `text` with its 1-based `line`, so a caller that reports errors by line no longer needs its own copy of the rule.
|
|
8
|
+
|
|
9
|
+
A row with a character around it that JSON does not allow as whitespace, such as a non-breaking space (`U+00A0`) or a second leading byte order mark, used to fail with `Failed to parse JSON line`. It is now trimmed and loaded, with a warning: `JsonlReader.readSnapshot` returns it in the new `warnings` of its result as `<file>:<line> has U+00A0 around its row, which JSON does not allow`, and `validate` and `initialize` add it to their `warnings` with the table name, which `lines-db validate` prints. Spaces and tabs around a row, which JSON allows, are still trimmed without a warning. A line that is only whitespace, including a non-breaking space, is still skipped without one. `fillFields` (`lines-db fill`) reads such a row the same way, instead of reporting it as a line that is not a JSON object: a row that gains a value is written back trimmed, and a row that gains nothing is left as it was.
|
|
10
|
+
|
|
3
11
|
## 0.19.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/README.ja.md
CHANGED
|
@@ -555,6 +555,22 @@ await JsonlWriter.write('./data/users.jsonl', filled);
|
|
|
555
555
|
|
|
556
556
|
対象外のフィールドは検証しません。その値がスキーマに違反していても、指定したフィールドを更新できます。計算後の行にないフィールドは元の値を残します。計算結果のキー順がスキーマと異なる場合は、`keyOrder`で新しいキーの位置を指定できます。
|
|
557
557
|
|
|
558
|
+
### 行の読み取り規則
|
|
559
|
+
|
|
560
|
+
`JsonlReader`と`lines-db validate`は、JSONLファイルを1つの規則で読みます。先頭のBOMを1つと各行末のCRを落とし、trimして空になる行は飛ばし、行番号は物理行番号です(飛ばした行も数えます)。各行の行番号を自分で使いたいとき(エラーを行番号つきで報告する場合など)は、`jsonlRecordLines`でファイルの内容にこの規則を適用できます。
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
import { jsonlRecordLines } from 'lines-db';
|
|
564
|
+
|
|
565
|
+
jsonlRecordLines('\n{"a":1}\n {"a":2}\n');
|
|
566
|
+
// [
|
|
567
|
+
// { text: '{"a":1}', line: 2 },
|
|
568
|
+
// { text: '{"a":2}', line: 3, warning: 'has U+00A0 around its row, which JSON does not allow' },
|
|
569
|
+
// ]
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
行の前後にある半角スペースとタブは、JSONが空白として許すので、警告なしでtrimします。NBSP(`U+00A0`)や2つ目のBOMのように、JSONが空白として許さない文字もtrimするので、その行は読み込めます。`JsonlReader.readSnapshot`は、そうした行の`warning`をファイルと行番号つきで`warnings`に返し、`validate`と`initialize`は、`Table 'users': ./data/users.jsonl:3 has U+00A0 around its row, which JSON does not allow`の形で`warnings`に加えます。
|
|
573
|
+
|
|
558
574
|
## 設定
|
|
559
575
|
|
|
560
576
|
```typescript
|
package/README.md
CHANGED
|
@@ -556,6 +556,22 @@ await JsonlWriter.write('./data/users.jsonl', filled);
|
|
|
556
556
|
|
|
557
557
|
Fields outside the selection are not validated. Even if their values would fail the schema, selected fields can still be updated. Fields absent from the computed row keep their original values. If computed key order differs from schema order, use `keyOrder` to set the position of new keys.
|
|
558
558
|
|
|
559
|
+
### Read the lines that hold rows
|
|
560
|
+
|
|
561
|
+
`JsonlReader` and `lines-db validate` read a JSONL file with one rule: one leading byte order mark and each line's trailing carriage return are dropped, lines that are blank after trimming are skipped, and a row's line is its physical line, so skipped lines still count. `jsonlRecordLines` applies that rule to a file's content when you need each row's line yourself, such as to report errors by line.
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
import { jsonlRecordLines } from 'lines-db';
|
|
565
|
+
|
|
566
|
+
jsonlRecordLines('\n{"a":1}\n {"a":2}\n');
|
|
567
|
+
// [
|
|
568
|
+
// { text: '{"a":1}', line: 2 },
|
|
569
|
+
// { text: '{"a":2}', line: 3, warning: 'has U+00A0 around its row, which JSON does not allow' },
|
|
570
|
+
// ]
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Spaces and tabs around a row are trimmed without a warning, as JSON allows them. A character JSON does not allow as whitespace, such as a non-breaking space (`U+00A0`) or a second byte order mark, is trimmed too, so the row still loads. `JsonlReader.readSnapshot` returns each such row's `warning` in `warnings` with its file and line, and `validate` and `initialize` add it to their `warnings` as `Table 'users': ./data/users.jsonl:3 has U+00A0 around its row, which JSON does not allow`.
|
|
574
|
+
|
|
559
575
|
## Configuration
|
|
560
576
|
|
|
561
577
|
```typescript
|
package/bin/cli.mjs
CHANGED
|
@@ -239,6 +239,32 @@ function unwrap(result) {
|
|
|
239
239
|
if (result.ok) return result.value;
|
|
240
240
|
throw result.error;
|
|
241
241
|
}
|
|
242
|
+
// src/jsonl-record-lines.ts
|
|
243
|
+
function strayWhitespace(raw, trimmed) {
|
|
244
|
+
const start = raw.indexOf(trimmed);
|
|
245
|
+
const around = raw.slice(0, start) + raw.slice(start + trimmed.length);
|
|
246
|
+
return [...new Set(around)].filter((char) => char !== " " && char !== " " && char !== "\r");
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Split JSONL content into the lines that hold a row: one leading byte order mark and each line's
|
|
250
|
+
* trailing carriage return are dropped, and lines that are blank after trimming are skipped.
|
|
251
|
+
* `line` is the 1-based physical line, so skipped lines still count. Whitespace around a row is
|
|
252
|
+
* trimmed; a character JSON does not allow as whitespace, such as a non-breaking space, is
|
|
253
|
+
* trimmed with a `warning`.
|
|
254
|
+
*/
|
|
255
|
+
function jsonlRecordLines(content) {
|
|
256
|
+
return (content.startsWith("") ? content.slice(1) : content).split("\n").flatMap((raw, index) => {
|
|
257
|
+
const text = raw.trim();
|
|
258
|
+
if (text.length === 0) return [];
|
|
259
|
+
const stray = strayWhitespace(raw, text);
|
|
260
|
+
const record = {
|
|
261
|
+
text,
|
|
262
|
+
line: index + 1
|
|
263
|
+
};
|
|
264
|
+
if (stray.length > 0) record.warning = `has ${stray.map((char) => `U+${char.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}`).join(", ")} around its row, which JSON does not allow`;
|
|
265
|
+
return [record];
|
|
266
|
+
});
|
|
267
|
+
}
|
|
242
268
|
// src/jsonl-reader.ts
|
|
243
269
|
/** Fingerprint of a JSONL file's content, to tell whether the file changed since it was read */
|
|
244
270
|
function hashJsonlContent(content) {
|
|
@@ -276,7 +302,8 @@ var JsonlReader = class {
|
|
|
276
302
|
const overrideRows = this.overrides?.get(normalize(filePath));
|
|
277
303
|
if (overrideRows) return ok({
|
|
278
304
|
rows: ok(overrideRows.map((row) => JSON.parse(JSON.stringify(row)))),
|
|
279
|
-
contentHash: void 0
|
|
305
|
+
contentHash: void 0,
|
|
306
|
+
warnings: []
|
|
280
307
|
});
|
|
281
308
|
let content;
|
|
282
309
|
try {
|
|
@@ -284,31 +311,31 @@ var JsonlReader = class {
|
|
|
284
311
|
} catch (error) {
|
|
285
312
|
return err(toError(error));
|
|
286
313
|
}
|
|
314
|
+
const records = jsonlRecordLines(content);
|
|
315
|
+
const warnings = records.flatMap(({ line, warning }) => warning ? [`${filePath}:${line} ${warning}`] : []);
|
|
287
316
|
return ok({
|
|
288
|
-
rows: this.parse(filePath,
|
|
289
|
-
contentHash: hashJsonlContent(content)
|
|
317
|
+
rows: this.parse(filePath, records),
|
|
318
|
+
contentHash: hashJsonlContent(content),
|
|
319
|
+
warnings
|
|
290
320
|
});
|
|
291
321
|
}
|
|
292
|
-
static parse(filePath,
|
|
293
|
-
const rawLines = (content.startsWith("") ? content.slice(1) : content).split("\n");
|
|
322
|
+
static parse(filePath, records) {
|
|
294
323
|
const rows = [];
|
|
295
|
-
for (
|
|
296
|
-
const line = rawLines[i].endsWith("\r") ? rawLines[i].slice(0, -1) : rawLines[i];
|
|
297
|
-
if (line.trim().length === 0) continue;
|
|
324
|
+
for (const { text, line } of records) {
|
|
298
325
|
const fail = (message, cause) => {
|
|
299
326
|
const parseError = new Error(message, { cause });
|
|
300
327
|
parseError.name = "JsonlParseError";
|
|
301
328
|
parseError.file = filePath;
|
|
302
|
-
parseError.line =
|
|
329
|
+
parseError.line = line;
|
|
303
330
|
return err(parseError);
|
|
304
331
|
};
|
|
305
332
|
let value;
|
|
306
333
|
try {
|
|
307
|
-
value = JSON.parse(
|
|
334
|
+
value = JSON.parse(text);
|
|
308
335
|
} catch (error) {
|
|
309
|
-
return fail(`Failed to parse JSON line: ${
|
|
336
|
+
return fail(`Failed to parse JSON line: ${text}`, error);
|
|
310
337
|
}
|
|
311
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return fail(`A JSONL line holds a row, which is a JSON object: ${
|
|
338
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return fail(`A JSONL line holds a row, which is a JSON object: ${text}`);
|
|
312
339
|
rows.push(value);
|
|
313
340
|
}
|
|
314
341
|
return ok(rows);
|
|
@@ -1090,7 +1117,7 @@ var LinesDB = class LinesDB {
|
|
|
1090
1117
|
const tableTransform = tableNameToLoad === tableName ? transform : void 0;
|
|
1091
1118
|
const { errors, warnings, rowCounts: tableRowCounts, deferredForeignKeys } = await this.loadTableWithDependencies(tableNameToLoad, loadedTables, loadingTables, attemptedTables, detailedValidate, tableTransform);
|
|
1092
1119
|
allErrors.push(...errors);
|
|
1093
|
-
allWarnings.push(
|
|
1120
|
+
for (const warning of warnings) allWarnings.push(warning);
|
|
1094
1121
|
allDeferredForeignKeys.push(...deferredForeignKeys);
|
|
1095
1122
|
for (const [k, v] of tableRowCounts) allRowCounts.set(k, v);
|
|
1096
1123
|
}
|
|
@@ -1159,7 +1186,7 @@ var LinesDB = class LinesDB {
|
|
|
1159
1186
|
if (this.tables.has(referencedTable)) {
|
|
1160
1187
|
const depResult = await this.loadTableWithDependencies(referencedTable, loadedTables, loadingTables, attemptedTables, detailedValidate, void 0);
|
|
1161
1188
|
errors.push(...depResult.errors);
|
|
1162
|
-
|
|
1189
|
+
for (const warning of depResult.warnings) warnings.push(warning);
|
|
1163
1190
|
deferredForeignKeys.push(...depResult.deferredForeignKeys);
|
|
1164
1191
|
for (const [k, v] of depResult.rowCounts) rowCounts.set(k, v);
|
|
1165
1192
|
} else throw new Error(`Foreign key reference to non-existent table '${referencedTable}' in table '${tableName}'`);
|
|
@@ -1182,7 +1209,7 @@ var LinesDB = class LinesDB {
|
|
|
1182
1209
|
}
|
|
1183
1210
|
}
|
|
1184
1211
|
const allSkippedDependencies = /* @__PURE__ */ new Set([...failedDependencies, ...circularDependencies]);
|
|
1185
|
-
const { loaded, rowCount, errors: loadErrors } = await this.loadTable(tableName, tableConfig, detailedValidate, transform, allSkippedDependencies);
|
|
1212
|
+
const { loaded, rowCount, errors: loadErrors } = await this.loadTable(tableName, tableConfig, detailedValidate, transform, allSkippedDependencies, warnings);
|
|
1186
1213
|
errors.push(...loadErrors);
|
|
1187
1214
|
rowCounts.set(tableName, rowCount);
|
|
1188
1215
|
if (loaded) {
|
|
@@ -1219,15 +1246,16 @@ var LinesDB = class LinesDB {
|
|
|
1219
1246
|
* Load a single table from JSONL file
|
|
1220
1247
|
* @returns Object with loaded status and validation errors
|
|
1221
1248
|
*/
|
|
1222
|
-
async loadTable(tableName, config, detailedValidate, transform, failedDependencies) {
|
|
1249
|
+
async loadTable(tableName, config, detailedValidate, transform, failedDependencies, warnings = []) {
|
|
1223
1250
|
let data = [];
|
|
1224
1251
|
const origins = [];
|
|
1225
1252
|
const contentHashes = /* @__PURE__ */ new Map();
|
|
1226
1253
|
for (const jsonlPath of config.jsonlPaths ?? [config.jsonlPath]) {
|
|
1227
1254
|
const readResult = await JsonlReader.readSnapshot(jsonlPath);
|
|
1228
1255
|
if (!readResult.ok) throw readResult.error;
|
|
1229
|
-
const { rows, contentHash } = readResult.value;
|
|
1256
|
+
const { rows, contentHash, warnings: readWarnings } = readResult.value;
|
|
1230
1257
|
if (!rows.ok) throw rows.error;
|
|
1258
|
+
for (const warning of readWarnings) warnings.push(`Table '${tableName}': ${warning}`);
|
|
1231
1259
|
if (contentHash !== void 0) {
|
|
1232
1260
|
contentHashes.set(jsonlPath, contentHash);
|
|
1233
1261
|
this.observedHashes.set(jsonlPath, contentHash);
|
|
@@ -3521,8 +3549,9 @@ function splitLines(content) {
|
|
|
3521
3549
|
const carriage = raw.endsWith("\r") ? "\r" : "";
|
|
3522
3550
|
const text = carriage ? raw.slice(0, -1) : raw;
|
|
3523
3551
|
let row;
|
|
3524
|
-
|
|
3525
|
-
|
|
3552
|
+
const trimmed = text.trim();
|
|
3553
|
+
if (trimmed !== "") try {
|
|
3554
|
+
const parsed = JSON.parse(trimmed);
|
|
3526
3555
|
row = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
|
|
3527
3556
|
} catch {
|
|
3528
3557
|
row = void 0;
|
|
@@ -3901,28 +3930,31 @@ const validateCommand = defineCommand({
|
|
|
3901
3930
|
}
|
|
3902
3931
|
if (!tableName) {
|
|
3903
3932
|
const formatter = new ErrorFormatter({ verbose: args.verbose });
|
|
3904
|
-
for (const tableResult of result.tableResults)
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3933
|
+
for (const tableResult of result.tableResults) {
|
|
3934
|
+
for (const warning of tableResult.warnings) console.warn(styleText("yellow", `⚠ ${warning}`));
|
|
3935
|
+
if (tableResult.valid) {
|
|
3936
|
+
if (tableResult.warnings.length === 0) console.log(styleText("green", `✓ ${tableResult.tableName} (${tableResult.rowCount} records)`));
|
|
3937
|
+
} else {
|
|
3938
|
+
const fileErrors = tableResult.errors;
|
|
3939
|
+
console.error(formatter.formatErrorHeader(fileErrors.length, fileErrors[0]?.file));
|
|
3940
|
+
console.error("");
|
|
3941
|
+
const validationErrors = fileErrors.filter((e) => e.type !== "foreignKey" || !e.foreignKeyError);
|
|
3942
|
+
const foreignKeyErrors = fileErrors.filter((e) => e.type === "foreignKey" && e.foreignKeyError);
|
|
3943
|
+
if (validationErrors.length > 0) console.error(formatter.formatValidationErrors(validationErrors.map((e) => ({
|
|
3944
|
+
file: e.file,
|
|
3945
|
+
rowIndex: e.rowIndex,
|
|
3946
|
+
issues: e.issues
|
|
3947
|
+
}))));
|
|
3948
|
+
for (const error of foreignKeyErrors) if (error.foreignKeyError) console.error(formatter.formatForeignKeyError({
|
|
3949
|
+
file: error.file,
|
|
3950
|
+
rowIndex: error.rowIndex,
|
|
3951
|
+
column: error.foreignKeyError.column,
|
|
3952
|
+
value: error.foreignKeyError.value,
|
|
3953
|
+
referencedTable: error.foreignKeyError.referencedTable,
|
|
3954
|
+
referencedColumn: error.foreignKeyError.referencedColumn
|
|
3955
|
+
}));
|
|
3956
|
+
console.error("");
|
|
3957
|
+
}
|
|
3926
3958
|
}
|
|
3927
3959
|
if (result.valid) {
|
|
3928
3960
|
console.log("");
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-C_GKc1zV.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* SQLite adapter for Node.js
|
|
4
4
|
*/
|
|
@@ -581,6 +581,22 @@ export declare class LinesDB<Tables extends TableDefs> {
|
|
|
581
581
|
*/
|
|
582
582
|
getDb(): SQLiteDatabase;
|
|
583
583
|
}
|
|
584
|
+
interface JsonlRecordLine {
|
|
585
|
+
/** The row's text, trimmed */
|
|
586
|
+
text: string;
|
|
587
|
+
/** 1-based physical line */
|
|
588
|
+
line: number;
|
|
589
|
+
/** Set when characters JSON does not allow as whitespace were trimmed from around the row */
|
|
590
|
+
warning?: string;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Split JSONL content into the lines that hold a row: one leading byte order mark and each line's
|
|
594
|
+
* trailing carriage return are dropped, and lines that are blank after trimming are skipped.
|
|
595
|
+
* `line` is the 1-based physical line, so skipped lines still count. Whitespace around a row is
|
|
596
|
+
* trimmed; a character JSON does not allow as whitespace, such as a non-breaking space, is
|
|
597
|
+
* trimmed with a `warning`.
|
|
598
|
+
*/
|
|
599
|
+
export declare function jsonlRecordLines(content: string): JsonlRecordLine[];
|
|
584
600
|
export declare class JsonlWriter {
|
|
585
601
|
/**
|
|
586
602
|
* Write data to JSONL file
|
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;;;;;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;UAEA;UAED;SAKA,OAAO,eAAe,WAAW,QAAQ,eAAe,SAAS,kBAAkB,QAAQ;;;;;;;;;;EAa5F,WAAW;IACf;IACA;IACA,aAAa,KAAK,eAAe;MAC/B,QAAQ,OAAO,kBAAkB;UAQvB;UAsBA;UAqHN;;;;UAOM;;;;UA8KA;;;;;UAQA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/sqlite-adapter.ts","../src/database.ts","../src/jsonl-record-lines.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;UAEA;UAED;SAKA,OAAO,eAAe,WAAW,QAAQ,eAAe,SAAS,kBAAkB,QAAQ;;;;;;;;;;EAa5F,WAAW;IACf;IACA;IACA,aAAa,KAAK,eAAe;MAC/B,QAAQ,OAAO,kBAAkB;UAQvB;UAsBA;UAqHN;;;;UAOM;;;;UA8KA;;;;;UAQA;;;;;;;;UA0SN;;;;;;UAkCA;;;;UAkBA;;;;UAsFA;;;;UAOA;;;;;;UASA;;;;;UAoCA;;;;UA6CA;;;;;UA+DA;;;;EAyCR,MAAM,aAAa,aAAa,4CAA2C,gBAAqB,OAAO,KAAK;UAUpG;;;;EAQR,SAAS,aACP,aACA,4CAA2C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;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;;qBAGW;UACH;EAEI,YAAA,UAAS;;;;EAOrB,uBAAuB,QAAQ;;;;EAU/B,sBAAsB,OAAO;;;;UAUrB;;;;UAiBA;;;;UAqCA;;;;UAOA;;;;UAoBA;;;;EAkBR,kBAAkB,eAAe;;;;EAQjC;;;;;KC9JU;wBAEI,iBAAiB;qBASpB,SAAO;UC2BH;EACf;;wBAGoB,kBACpB,eACA,UAAS,uBACR,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as JsonlReader, c as
|
|
1
|
+
import { a as JsonlReader, c as err, d as unwrap, i as replaceFile, l as ok, n as createSchemaImports, o as hashJsonlContent, r as hashContent, s as jsonlRecordLines, t as MISSING_HASH, u as toError } from "./schema-module-CdiS2Jq_.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { access, chmod, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
@@ -652,7 +652,7 @@ var LinesDB = class LinesDB {
|
|
|
652
652
|
const tableTransform = tableNameToLoad === tableName ? transform : void 0;
|
|
653
653
|
const { errors, warnings, rowCounts: tableRowCounts, deferredForeignKeys } = await this.loadTableWithDependencies(tableNameToLoad, loadedTables, loadingTables, attemptedTables, detailedValidate, tableTransform);
|
|
654
654
|
allErrors.push(...errors);
|
|
655
|
-
allWarnings.push(
|
|
655
|
+
for (const warning of warnings) allWarnings.push(warning);
|
|
656
656
|
allDeferredForeignKeys.push(...deferredForeignKeys);
|
|
657
657
|
for (const [k, v] of tableRowCounts) allRowCounts.set(k, v);
|
|
658
658
|
}
|
|
@@ -721,7 +721,7 @@ var LinesDB = class LinesDB {
|
|
|
721
721
|
if (this.tables.has(referencedTable)) {
|
|
722
722
|
const depResult = await this.loadTableWithDependencies(referencedTable, loadedTables, loadingTables, attemptedTables, detailedValidate, void 0);
|
|
723
723
|
errors.push(...depResult.errors);
|
|
724
|
-
|
|
724
|
+
for (const warning of depResult.warnings) warnings.push(warning);
|
|
725
725
|
deferredForeignKeys.push(...depResult.deferredForeignKeys);
|
|
726
726
|
for (const [k, v] of depResult.rowCounts) rowCounts.set(k, v);
|
|
727
727
|
} else throw new Error(`Foreign key reference to non-existent table '${referencedTable}' in table '${tableName}'`);
|
|
@@ -744,7 +744,7 @@ var LinesDB = class LinesDB {
|
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
const allSkippedDependencies = /* @__PURE__ */ new Set([...failedDependencies, ...circularDependencies]);
|
|
747
|
-
const { loaded, rowCount, errors: loadErrors } = await this.loadTable(tableName, tableConfig, detailedValidate, transform, allSkippedDependencies);
|
|
747
|
+
const { loaded, rowCount, errors: loadErrors } = await this.loadTable(tableName, tableConfig, detailedValidate, transform, allSkippedDependencies, warnings);
|
|
748
748
|
errors.push(...loadErrors);
|
|
749
749
|
rowCounts.set(tableName, rowCount);
|
|
750
750
|
if (loaded) {
|
|
@@ -781,15 +781,16 @@ var LinesDB = class LinesDB {
|
|
|
781
781
|
* Load a single table from JSONL file
|
|
782
782
|
* @returns Object with loaded status and validation errors
|
|
783
783
|
*/
|
|
784
|
-
async loadTable(tableName, config, detailedValidate, transform, failedDependencies) {
|
|
784
|
+
async loadTable(tableName, config, detailedValidate, transform, failedDependencies, warnings = []) {
|
|
785
785
|
let data = [];
|
|
786
786
|
const origins = [];
|
|
787
787
|
const contentHashes = /* @__PURE__ */ new Map();
|
|
788
788
|
for (const jsonlPath of config.jsonlPaths ?? [config.jsonlPath]) {
|
|
789
789
|
const readResult = await JsonlReader.readSnapshot(jsonlPath);
|
|
790
790
|
if (!readResult.ok) throw readResult.error;
|
|
791
|
-
const { rows, contentHash } = readResult.value;
|
|
791
|
+
const { rows, contentHash, warnings: readWarnings } = readResult.value;
|
|
792
792
|
if (!rows.ok) throw rows.error;
|
|
793
|
+
for (const warning of readWarnings) warnings.push(`Table '${tableName}': ${warning}`);
|
|
793
794
|
if (contentHash !== void 0) {
|
|
794
795
|
contentHashes.set(jsonlPath, contentHash);
|
|
795
796
|
this.observedHashes.set(jsonlPath, contentHash);
|
|
@@ -2981,8 +2982,9 @@ function splitLines(content) {
|
|
|
2981
2982
|
const carriage = raw.endsWith("\r") ? "\r" : "";
|
|
2982
2983
|
const text = carriage ? raw.slice(0, -1) : raw;
|
|
2983
2984
|
let row;
|
|
2984
|
-
|
|
2985
|
-
|
|
2985
|
+
const trimmed = text.trim();
|
|
2986
|
+
if (trimmed !== "") try {
|
|
2987
|
+
const parsed = JSON.parse(trimmed);
|
|
2986
2988
|
row = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
|
|
2987
2989
|
} catch {
|
|
2988
2990
|
row = void 0;
|
|
@@ -3268,6 +3270,6 @@ async function loadDatasetConfig(path = "lines-db.config.json", options = {}) {
|
|
|
3268
3270
|
schemaDir
|
|
3269
3271
|
};
|
|
3270
3272
|
}
|
|
3271
|
-
export { DirectoryScanner, ErrorFormatter, JsonlReader, JsonlWriter, LinesDB, RUNTIME, SCHEMA_EXTENSIONS, SchemaLoader, TypeGenerator, defineSchema, detectRuntime, ensureTableRowsValid, err, extractTableNameFromSchemaFile, fillFields, findSchemaFile, hasBackward, isSchemaFile, loadDatasetConfig, mergeFields, ok, rewriteExtensionForImport, unwrap };
|
|
3273
|
+
export { DirectoryScanner, ErrorFormatter, JsonlReader, JsonlWriter, LinesDB, RUNTIME, SCHEMA_EXTENSIONS, SchemaLoader, TypeGenerator, defineSchema, detectRuntime, ensureTableRowsValid, err, extractTableNameFromSchemaFile, fillFields, findSchemaFile, hasBackward, isSchemaFile, jsonlRecordLines, loadDatasetConfig, mergeFields, ok, rewriteExtensionForImport, unwrap };
|
|
3272
3274
|
|
|
3273
3275
|
//# sourceMappingURL=index.mjs.map
|