@jarenjs/db 0.67.0 → 0.72.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/README.md +29 -0
- package/docs/JOBS-FORMAT.md +14 -1
- package/docs/MIGRATION-FORMAT.md +45 -26
- package/package.json +4 -4
- package/src/cli.js +89 -68
- package/src/dag-job.js +17 -12
- package/src/document-files.js +76 -20
- package/src/document-steps.js +94 -120
- package/src/documents.js +24 -6
- package/src/drivers/node.js +1 -1
- package/src/jobs.js +42 -0
- package/src/migrate.js +44 -5
- package/src/store.js +6 -0
- package/types/index.d.ts +32 -7
- package/types/node.d.ts +9 -3
package/types/index.d.ts
CHANGED
|
@@ -1274,6 +1274,23 @@ export declare function readSchema(connection: unknown, options?: {
|
|
|
1274
1274
|
tables?: readonly string[];
|
|
1275
1275
|
}): unknown;
|
|
1276
1276
|
|
|
1277
|
+
export interface AssertionBounds {
|
|
1278
|
+
maxRows?: number | null;
|
|
1279
|
+
maxBytes?: number | null;
|
|
1280
|
+
/** Opt into a distinct fold with at most this many unique items. */
|
|
1281
|
+
maxDistinct?: number;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
export interface AssertionPlan {
|
|
1285
|
+
migration: string;
|
|
1286
|
+
step: number;
|
|
1287
|
+
collection: string;
|
|
1288
|
+
strategy: 'provider' | 'perDocument' | 'fold' | 'materialize';
|
|
1289
|
+
shape: string | null;
|
|
1290
|
+
reason: string;
|
|
1291
|
+
bounds: AssertionBounds | null;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1277
1294
|
export interface MigrateOptions {
|
|
1278
1295
|
baseline: unknown;
|
|
1279
1296
|
model?: unknown;
|
|
@@ -1307,13 +1324,14 @@ export interface MigrateOptions {
|
|
|
1307
1324
|
/** An epoch-millisecond deadline on `runtime`'s clock (`JD2075`). */
|
|
1308
1325
|
deadline?: number;
|
|
1309
1326
|
/** What a MATERIALIZING assertion may hold. A per-document predicate
|
|
1310
|
-
* and a
|
|
1327
|
+
* and a supported ordered aggregate over independent rows are answered in
|
|
1311
1328
|
* batches and are never bounded by this; anything else must hold the
|
|
1312
1329
|
* collection at once and crosses these bounds before the excess is
|
|
1313
1330
|
* held (`JD2007` rows, `JD2076` bytes). Defaults to
|
|
1314
1331
|
* {@link ASSERTION_BOUNDS_DEFAULT}; `null` on either member removes
|
|
1315
1332
|
* that bound, deliberately. */
|
|
1316
|
-
assertionBounds?:
|
|
1333
|
+
assertionBounds?: AssertionBounds;
|
|
1334
|
+
onAssertionPlan?: (plan: AssertionPlan) => void;
|
|
1317
1335
|
}
|
|
1318
1336
|
|
|
1319
1337
|
/** The finite defaults a materializing assertion runs under when the
|
|
@@ -1324,9 +1342,8 @@ export declare const ASSERTION_BOUNDS_DEFAULT: {
|
|
|
1324
1342
|
};
|
|
1325
1343
|
|
|
1326
1344
|
/** How a host must run an assertion, and why. `perDocument` walks in
|
|
1327
|
-
* batches; `fold`
|
|
1328
|
-
|
|
1329
|
-
export declare function classifyAssertion(query: unknown): {
|
|
1345
|
+
* batches; `fold` accumulates query items in order; `materialize` needs every document at once and is bounded. */
|
|
1346
|
+
export declare function classifyAssertion(query: unknown, options?: { expect?: string; maxDistinct?: number }): {
|
|
1330
1347
|
strategy: 'perDocument' | 'fold' | 'materialize';
|
|
1331
1348
|
shape: string | null;
|
|
1332
1349
|
reason: string;
|
|
@@ -1402,7 +1419,8 @@ export interface DocumentMigrationOptions {
|
|
|
1402
1419
|
/** What a MATERIALIZING assertion may hold; the same bounds, and the
|
|
1403
1420
|
* same refusals, a Store applies. Defaults to
|
|
1404
1421
|
* {@link ASSERTION_BOUNDS_DEFAULT}. */
|
|
1405
|
-
assertionBounds?:
|
|
1422
|
+
assertionBounds?: AssertionBounds;
|
|
1423
|
+
onAssertionPlan?: (plan: AssertionPlan) => void;
|
|
1406
1424
|
/** Documents per assertion batch and per progress event (default 500). */
|
|
1407
1425
|
batchSize?: number;
|
|
1408
1426
|
onProgress?: (progress: MigrationProgress) => void;
|
|
@@ -1457,6 +1475,7 @@ export declare function compileDocumentStep(
|
|
|
1457
1475
|
compileJslt: (stylesheet: unknown) => (document: unknown) => unknown;
|
|
1458
1476
|
compileQuery: (query: unknown) => unknown;
|
|
1459
1477
|
keys?: readonly string[];
|
|
1478
|
+
assertionBounds?: { maxRows: number | null; maxBytes: number | null; maxDistinct?: number };
|
|
1460
1479
|
},
|
|
1461
1480
|
): unknown;
|
|
1462
1481
|
/** Structural validation of one migration document (`JD0023`/`JD0021`). */
|
|
@@ -1815,6 +1834,7 @@ export interface JobsApi {
|
|
|
1815
1834
|
* written up to it, and a settlement prunes no further, so a stale
|
|
1816
1835
|
* attempt cannot erase a live one's work. */
|
|
1817
1836
|
checkpointsFor(job: ClaimedJob): {
|
|
1837
|
+
inspect(runId: string, nodeId: string): unknown;
|
|
1818
1838
|
load(runId: string): unknown;
|
|
1819
1839
|
save(runId: string, nodeId: string, value: unknown): unknown;
|
|
1820
1840
|
complete(runId: string, result: unknown): unknown;
|
|
@@ -1840,6 +1860,11 @@ export interface JobPageOptions {
|
|
|
1840
1860
|
* schedule: WHEN to sweep or cancel is the host's call.
|
|
1841
1861
|
*/
|
|
1842
1862
|
export interface JobsAdminApi {
|
|
1863
|
+
/** Discard an inactive run's checkpoints and restart its attempts, atomically.
|
|
1864
|
+
* Requires its observed generation; refuses done jobs and live leases.
|
|
1865
|
+
* External effects are not undone. */
|
|
1866
|
+
reset(id: string, options: { expectedGeneration: number; signal?: AbortSignal; deadline?: number }):
|
|
1867
|
+
Promise<{ reset: true; discarded: number; generation: number }>;
|
|
1843
1868
|
/** A keyset cursor over the queue by id, admitted per pull under the
|
|
1844
1869
|
* store gate; each item is the record `get` answers. */
|
|
1845
1870
|
page(options?: JobPageOptions): QueryCursor<JobRecord>;
|
|
@@ -1876,7 +1901,7 @@ export interface JobsOptions {
|
|
|
1876
1901
|
export declare function createDagJobRunner(store: Store, options: {
|
|
1877
1902
|
compileDag: Function;
|
|
1878
1903
|
documents: Record<string, unknown>;
|
|
1879
|
-
tasks?: Record<string, Function>;
|
|
1904
|
+
tasks?: Record<string, Function | { run: Function; version?: string; taskVersions?: Record<string, string> }>;
|
|
1880
1905
|
concurrency?: number;
|
|
1881
1906
|
pollInterval?: number;
|
|
1882
1907
|
leaseMs?: number;
|
package/types/node.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export declare function readDocuments(
|
|
|
61
61
|
export interface DocumentTarget {
|
|
62
62
|
/** The sibling file being filled, or null for a sink with no file. */
|
|
63
63
|
readonly temporary: string | null;
|
|
64
|
-
write(document: unknown): Promise<void>;
|
|
64
|
+
write(document: unknown, collection?: string): Promise<void>;
|
|
65
65
|
/** Flush, rename over the target, and answer what was written. */
|
|
66
66
|
commit(): Promise<{ bytes: number; documents: number }>;
|
|
67
67
|
/** Remove the temporary; the target keeps the bytes it had. */
|
|
@@ -72,13 +72,19 @@ export interface DocumentTarget {
|
|
|
72
72
|
* on `commit`, and removed on `abort`, so a failed run leaves the
|
|
73
73
|
* original byte for byte. */
|
|
74
74
|
export declare function openAtomicTarget(
|
|
75
|
-
target: string, format: 'json' | 'jsonl',
|
|
75
|
+
target: string, format: 'json' | 'jsonl' | 'collections',
|
|
76
|
+
options?: { collections?: string[] },
|
|
76
77
|
): Promise<DocumentTarget>;
|
|
77
78
|
|
|
78
79
|
/** Write to an open stream; `abort` cannot take back what has left. */
|
|
79
80
|
export declare function openStreamTarget(
|
|
80
|
-
stream: DocumentByteSink, format: 'json' | 'jsonl',
|
|
81
|
+
stream: DocumentByteSink, format: 'json' | 'jsonl' | 'collections',
|
|
82
|
+
options?: { collections?: string[] },
|
|
81
83
|
): DocumentTarget;
|
|
82
84
|
|
|
83
85
|
/** Validate everything and write nothing. */
|
|
84
86
|
export declare function openNullTarget(): DocumentTarget;
|
|
87
|
+
|
|
88
|
+
/** Read an explicit collection bundle, materialized under the declared bounds. */
|
|
89
|
+
export declare function readCollectionBundle(source: DocumentByteSource,
|
|
90
|
+
bounds: { maxBytes: number | null; maxRows: number | null }): Promise<Record<string, unknown[]>>;
|