@orkestrel/database 0.0.13 → 0.0.14
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 +10 -6
- package/dist/src/browser/index.d.ts +54 -51
- package/dist/src/browser/index.js +35 -30
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/core/index.cjs +109 -42
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +274 -61
- package/dist/src/core/index.d.ts +274 -61
- package/dist/src/core/index.js +109 -42
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +54 -34
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +93 -76
- package/dist/src/server/index.d.ts +93 -76
- package/dist/src/server/index.js +54 -34
- package/dist/src/server/index.js.map +1 -1
- package/package.json +15 -16
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ContractInterface } from '@orkestrel/contract';
|
|
2
|
-
import { ContractShape } from '@orkestrel/contract';
|
|
3
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
4
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
5
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
6
|
-
import { FieldPath } from '@orkestrel/contract';
|
|
7
|
-
import { Infer } from '@orkestrel/contract';
|
|
8
|
-
import { JSONSchema } from '@orkestrel/contract';
|
|
1
|
+
import type { ContractInterface } from '@orkestrel/contract';
|
|
2
|
+
import type { ContractShape } from '@orkestrel/contract';
|
|
3
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
4
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
5
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
6
|
+
import type { FieldPath } from '@orkestrel/contract';
|
|
7
|
+
import type { Infer } from '@orkestrel/contract';
|
|
8
|
+
import type { JSONSchema } from '@orkestrel/contract';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Represents the admission boundary a scoped operation enters before it runs.
|
|
@@ -31,6 +31,10 @@ import { JSONSchema } from '@orkestrel/contract';
|
|
|
31
31
|
*/
|
|
32
32
|
export declare interface AdmissionInterface {
|
|
33
33
|
readonly accepting: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Enters one operation into the boundary's ledger so whoever stops the boundary
|
|
36
|
+
* contains everything already accepted.
|
|
37
|
+
*/
|
|
34
38
|
track<R>(operation: () => Promise<R>): Promise<R>;
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -53,7 +57,7 @@ export declare type AggregateOperation = 'count' | 'sum' | 'average' | 'minimum'
|
|
|
53
57
|
export declare function applyQuery(rows: readonly Row[], input?: QueryInput): readonly Row[];
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
* Runs the
|
|
60
|
+
* Runs the full driver-conformance battery and collects every violation — the
|
|
57
61
|
* audit entry point for a driver author who wants a complete report rather
|
|
58
62
|
* than a single fail-fast throw.
|
|
59
63
|
*
|
|
@@ -115,6 +119,11 @@ export declare function checkAbort(signal: AbortSignal | undefined): void;
|
|
|
115
119
|
/**
|
|
116
120
|
* Clones unknown driver metadata into a distinct deeply frozen snapshot.
|
|
117
121
|
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* The clone is validated as {@link DriverMetadata} before it is returned, so a
|
|
124
|
+
* malformed or hostile value throws a `VALIDATION` {@link DatabaseError} at
|
|
125
|
+
* `context.path === 'metadata'` rather than surfacing a raw Contract or caller error.
|
|
126
|
+
*
|
|
118
127
|
* @param value - Unknown metadata
|
|
119
128
|
* @returns Owned driver metadata
|
|
120
129
|
*/
|
|
@@ -123,6 +132,11 @@ export declare function cloneDriverMetadata(value: unknown): DriverMetadata;
|
|
|
123
132
|
/**
|
|
124
133
|
* Clones unknown driver schema into a distinct deeply frozen snapshot.
|
|
125
134
|
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* The clone is validated as a table-schema collection before it is returned, so a
|
|
137
|
+
* malformed or hostile value throws a `VALIDATION` {@link DatabaseError} at
|
|
138
|
+
* `context.path === 'schema'` rather than surfacing a raw Contract or caller error.
|
|
139
|
+
*
|
|
126
140
|
* @param value - Unknown table schema collection
|
|
127
141
|
* @returns Owned driver schema
|
|
128
142
|
*/
|
|
@@ -131,6 +145,11 @@ export declare function cloneDriverSchema(value: unknown): readonly TableSchema[
|
|
|
131
145
|
/**
|
|
132
146
|
* Clones unknown migration input into a distinct deeply frozen snapshot.
|
|
133
147
|
*
|
|
148
|
+
* @remarks
|
|
149
|
+
* The clone is validated as a {@link MigrationInput} before it is returned, so a
|
|
150
|
+
* malformed or hostile value throws a `VALIDATION` {@link DatabaseError} at
|
|
151
|
+
* `context.path === 'migration'` rather than surfacing a raw Contract or caller error.
|
|
152
|
+
*
|
|
134
153
|
* @param value - Unknown migration input
|
|
135
154
|
* @returns Owned migration input
|
|
136
155
|
*/
|
|
@@ -208,7 +227,7 @@ export declare function computeAggregate(rows: readonly unknown[], operation: Ag
|
|
|
208
227
|
* `present`, one for most, two for `between`, a list for `any` / `none`.
|
|
209
228
|
* `connector` folds this condition into the accumulated result left-to-right;
|
|
210
229
|
* the first condition's connector seeds the fold and is otherwise ignored.
|
|
211
|
-
* `column` is a {@link FieldPath}: a single string is
|
|
230
|
+
* `column` is a {@link FieldPath}: a single string is one column (never split on
|
|
212
231
|
* `.`), an array descends into a nested (object/`json`) value.
|
|
213
232
|
*/
|
|
214
233
|
export declare interface Condition {
|
|
@@ -242,11 +261,13 @@ export declare type ConditionOperator = 'equals' | 'not' | 'above' | 'below' | '
|
|
|
242
261
|
export declare const CONFORMANCE_POSTS_SCHEMA: TableSchema;
|
|
243
262
|
|
|
244
263
|
/**
|
|
245
|
-
* Holds the fixed
|
|
264
|
+
* Holds the fixed `users` and `posts` schema every driver-conformance phase opens.
|
|
246
265
|
*
|
|
247
266
|
* @remarks
|
|
248
267
|
* Each phase mints a fresh driver and opens this exact schema, so a finding
|
|
249
|
-
* names a violated invariant rather than a setup difference between phases.
|
|
268
|
+
* names a violated invariant rather than a setup difference between phases. The
|
|
269
|
+
* array and each schema in it are frozen, so a consumer holding it cannot change
|
|
270
|
+
* what a later phase opens.
|
|
250
271
|
*/
|
|
251
272
|
export declare const CONFORMANCE_SCHEMA: readonly TableSchema[];
|
|
252
273
|
|
|
@@ -268,7 +289,8 @@ export declare const CONFORMANCE_USERS_SCHEMA: TableSchema;
|
|
|
268
289
|
* @remarks
|
|
269
290
|
* Mirrors the payload shape of a `DatabaseError` `CONFORMANCE` `context` —
|
|
270
291
|
* `check` names the invariant, `message` describes the violation, and
|
|
271
|
-
* `context` carries the offending table / key / value that failed it.
|
|
292
|
+
* `context` carries the offending table / key / value that failed it. Yielded one at a
|
|
293
|
+
* time by {@link scanDriver} and collected whole by {@link auditDriver}.
|
|
272
294
|
*/
|
|
273
295
|
export declare interface ConformanceFinding {
|
|
274
296
|
readonly check: string;
|
|
@@ -283,11 +305,13 @@ export declare interface ConformanceFinding {
|
|
|
283
305
|
*
|
|
284
306
|
* @remarks
|
|
285
307
|
* Consumes only the first value {@link scanDriver} yields: because that
|
|
286
|
-
* generator is lazy, every
|
|
308
|
+
* generator is lazy, every later phase never runs — true fail-fast, not
|
|
287
309
|
* merely "report only the first". The
|
|
288
310
|
* thrown error is byte-compatible with the historical shape: a
|
|
289
311
|
* `CONFORMANCE` {@link DatabaseError} whose `message` is the finding's
|
|
290
|
-
* `message` and whose `context` is `{ check, ...finding.context }`.
|
|
312
|
+
* `message` and whose `context` is `{ check, ...finding.context }`. The battery
|
|
313
|
+
* takes a driver factory and reports through a throw, so it binds no test
|
|
314
|
+
* framework and runs from any runner.
|
|
291
315
|
*
|
|
292
316
|
* @param factory - Mints a fresh, unopened driver instance (called once per phase)
|
|
293
317
|
* @returns Nothing — resolves once every phase has passed
|
|
@@ -317,20 +341,29 @@ export declare function conformDriver(factory: () => DriverInterface): Promise<v
|
|
|
317
341
|
* `name`, `generator`, `version`, and emitter hooks
|
|
318
342
|
* @returns A typed {@link DatabaseInterface}
|
|
319
343
|
*
|
|
320
|
-
* @example
|
|
344
|
+
* @example Create a database
|
|
321
345
|
* ```ts
|
|
322
346
|
* import { createDatabase, createMemoryDriver } from '@orkestrel/database'
|
|
323
347
|
* import { integerShape, stringShape } from '@orkestrel/contract'
|
|
324
348
|
*
|
|
325
349
|
* const db = createDatabase({
|
|
326
|
-
* driver: createMemoryDriver(),
|
|
350
|
+
* driver: createMemoryDriver(), // any DriverInterface — a persistent backend swaps in, same API
|
|
327
351
|
* tables: {
|
|
328
|
-
* users: { id: stringShape(), age: integerShape() },
|
|
352
|
+
* users: { id: stringShape(), name: stringShape(), age: integerShape() },
|
|
329
353
|
* posts: { slug: stringShape(), title: stringShape() },
|
|
330
354
|
* },
|
|
331
|
-
* primary: { posts: 'slug' },
|
|
355
|
+
* primary: { posts: 'slug' }, // non-`id` primary-key columns, per table
|
|
332
356
|
* })
|
|
333
|
-
*
|
|
357
|
+
*
|
|
358
|
+
* const users = db.table('users') // hold the handle; TableInterface<{ id; name; age }>
|
|
359
|
+
*
|
|
360
|
+
* await users.set({ id: 'u1', name: 'Ada', age: 36 }) // coerced + validated through the contract
|
|
361
|
+
* await users.get('u1') // typed { id; name; age } | undefined — narrowed, never `as`
|
|
362
|
+
* await users
|
|
363
|
+
* .query()
|
|
364
|
+
* .condition({ column: 'age', operator: 'from', values: [18], connector: 'and' })
|
|
365
|
+
* .order({ column: 'age', direction: 'descending' })
|
|
366
|
+
* .collect() // typed rows
|
|
334
367
|
* ```
|
|
335
368
|
*/
|
|
336
369
|
export declare function createDatabase<const T extends TableMap>(options: DatabaseOptions<T>): DatabaseInterface<T>;
|
|
@@ -362,9 +395,21 @@ export declare interface CursorInterface<T = Row> {
|
|
|
362
395
|
readonly value: T | undefined;
|
|
363
396
|
readonly index: number;
|
|
364
397
|
readonly done: boolean;
|
|
398
|
+
/**
|
|
399
|
+
* Advances to the next present row.
|
|
400
|
+
*/
|
|
365
401
|
next(): Promise<void>;
|
|
402
|
+
/**
|
|
403
|
+
* Merges changes into the row at the current position.
|
|
404
|
+
*/
|
|
366
405
|
update(changes: Partial<T>): Promise<void>;
|
|
406
|
+
/**
|
|
407
|
+
* Deletes the row at the current position.
|
|
408
|
+
*/
|
|
367
409
|
remove(): Promise<void>;
|
|
410
|
+
/**
|
|
411
|
+
* Closes the cursor terminally, so every later operation is a no-op.
|
|
412
|
+
*/
|
|
368
413
|
close(): void;
|
|
369
414
|
}
|
|
370
415
|
|
|
@@ -376,6 +421,10 @@ export declare interface CursorInterface<T = Row> {
|
|
|
376
421
|
* generator. Imported views register their physical schemas with the same
|
|
377
422
|
* internal context before opening begins, so every view observes one driver,
|
|
378
423
|
* merged schema, emitter, status, transaction boundary, and terminal close.
|
|
424
|
+
*
|
|
425
|
+
* The view owns the driver and its declared `tables`, connects that driver lazily on
|
|
426
|
+
* first use, `import`s further tables and `export`s their portable definitions, and
|
|
427
|
+
* runs `transaction` scopes over the shared context.
|
|
379
428
|
*/
|
|
380
429
|
export declare class Database<T extends TableMap = TableMap> implements DatabaseInterface<T> {
|
|
381
430
|
#private;
|
|
@@ -426,11 +475,11 @@ export declare type DatabaseErrorCode = 'CLOSED' | 'NOT_FOUND' | 'CONFLICT' | 'V
|
|
|
426
475
|
* Pure signals carrying no row data — these are the database-level (not per-row)
|
|
427
476
|
* moments, so a non-generic map stays lean (per-row writes are {@link TableEventMap}).
|
|
428
477
|
* Listener isolation is the emitter's: every event is emitted directly and a
|
|
429
|
-
* listener throw is routed to the emitter's
|
|
478
|
+
* listener throw is routed to the emitter's own `error` handler (the `error` option), never
|
|
430
479
|
* onto this domain map and never into the snapshot / commit / rollback flow — so a buggy
|
|
431
|
-
* observer can never reorder, throw into, or corrupt a transaction. Every emit sits
|
|
480
|
+
* observer can never reorder, throw into, or corrupt a transaction. Every emit sits after the
|
|
432
481
|
* relevant transition: `commit` only after the scope succeeds, `rollback` only after the
|
|
433
|
-
* rollback operation completes (it
|
|
482
|
+
* rollback operation completes (it observes the propagated scope error; that exact reason
|
|
434
483
|
* still propagates). A rollback failure propagates instead and emits no misleading
|
|
435
484
|
* `rollback` event. Subscribe through `database.emitter.on(...)`.
|
|
436
485
|
*
|
|
@@ -473,11 +522,35 @@ export declare interface DatabaseInterface<T extends TableMap = TableMap> {
|
|
|
473
522
|
readonly emitter: EmitterInterface<DatabaseEventMap>;
|
|
474
523
|
readonly name: string;
|
|
475
524
|
readonly status: DatabaseStatus;
|
|
525
|
+
/**
|
|
526
|
+
* Returns the typed handle for a declared table.
|
|
527
|
+
*/
|
|
476
528
|
table<K extends keyof T & string>(name: K): TableInterface<RowOf<T[K]>>;
|
|
529
|
+
/**
|
|
530
|
+
* Defines a further shape map of tables as a typed view over the same driver and storage.
|
|
531
|
+
*/
|
|
477
532
|
import<U extends TableMap>(tables: U, primary?: PrimaryMap): DatabaseInterface<U>;
|
|
533
|
+
/**
|
|
534
|
+
* Returns one portable {@link TableDefinition} per declared table.
|
|
535
|
+
*/
|
|
478
536
|
export(): Readonly<Record<string, TableDefinition>>;
|
|
537
|
+
/**
|
|
538
|
+
* Connects the driver eagerly, ahead of the lazy connect on first use.
|
|
539
|
+
*/
|
|
479
540
|
open(): Promise<void>;
|
|
541
|
+
/**
|
|
542
|
+
* Closes the database and releases its driver.
|
|
543
|
+
*/
|
|
480
544
|
close(): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* Runs a scope over a {@link DatabaseStorageInterface}, committing when the callback
|
|
547
|
+
* fulfills and rolling back when it rejects.
|
|
548
|
+
*
|
|
549
|
+
* @remarks
|
|
550
|
+
* A native driver transaction carries the scope where the driver offers one;
|
|
551
|
+
* otherwise the universal whole-store snapshot floor does. `options.signal` is
|
|
552
|
+
* checked once, at entry.
|
|
553
|
+
*/
|
|
481
554
|
transaction<R>(scope: (transaction: DatabaseStorageInterface<T>) => Promise<R>, options?: OperationOptions): Promise<R>;
|
|
482
555
|
/**
|
|
483
556
|
* Diffs a caller-supplied deployed schema against this database's declared
|
|
@@ -485,7 +558,7 @@ export declare interface DatabaseInterface<T extends TableMap = TableMap> {
|
|
|
485
558
|
* resulting plan through the driver's optional `migrate` hook, and returns
|
|
486
559
|
* the applied plan.
|
|
487
560
|
*
|
|
488
|
-
* @param deployed - The schema
|
|
561
|
+
* @param deployed - The deployed schema, as {@link TableSchema}s
|
|
489
562
|
* @param options - Optional abort signal, checked at entry
|
|
490
563
|
* @returns The applied {@link Migration} plan
|
|
491
564
|
*
|
|
@@ -554,7 +627,7 @@ export declare interface DatabaseOptions<T extends TableMap = TableMap> {
|
|
|
554
627
|
* Holds the declared schema version.
|
|
555
628
|
*
|
|
556
629
|
* @remarks
|
|
557
|
-
* Only meaningful when the driver implements
|
|
630
|
+
* Only meaningful when the driver implements both {@link DriverInterface.metadata}
|
|
558
631
|
* and {@link DriverInterface.stamp} (a versioning driver); unset, or a
|
|
559
632
|
* non-versioning driver, leaves `open()` unchanged from today's behavior.
|
|
560
633
|
* When set and the driver versions, `open()` reconciles against the driver's
|
|
@@ -596,11 +669,17 @@ export declare type DatabaseStatus = 'idle' | 'open' | 'closed';
|
|
|
596
669
|
* after the scope settles.
|
|
597
670
|
*/
|
|
598
671
|
export declare interface DatabaseStorageInterface<T extends TableMap = TableMap> {
|
|
672
|
+
/**
|
|
673
|
+
* Returns a table bound to the active transaction scope.
|
|
674
|
+
*
|
|
675
|
+
* @remarks
|
|
676
|
+
* The returned table throws `CONFLICT` for work started after the scope settles.
|
|
677
|
+
*/
|
|
599
678
|
table<K extends keyof T & string>(name: K): TableInterface<RowOf<T[K]>>;
|
|
600
679
|
}
|
|
601
680
|
|
|
602
681
|
/**
|
|
603
|
-
* Supplies the primary-key column assumed when {@link PrimaryMap} does not name one.
|
|
682
|
+
* Supplies the primary-key column, `'id'`, assumed when {@link PrimaryMap} does not name one.
|
|
604
683
|
*
|
|
605
684
|
* @remarks
|
|
606
685
|
* `id` is the convention IndexedDB (`keyPath: 'id'`) and SQL (`id` / rowid) both
|
|
@@ -612,7 +691,7 @@ export declare const DEFAULT_PRIMARY = "id";
|
|
|
612
691
|
* Declares the storage primitive every backend implements — the whole of the bridge.
|
|
613
692
|
*
|
|
614
693
|
* @remarks
|
|
615
|
-
* The
|
|
694
|
+
* The required surface is deliberately minimal: keyed read / write / atomic
|
|
616
695
|
* insert / delete, an ordered `scan`, a key listing, and a `snapshot` that
|
|
617
696
|
* backs transactions — the irreducible primitive. There is **no** required
|
|
618
697
|
* query, count, or aggregate here: all of that is one query engine in the core
|
|
@@ -632,7 +711,17 @@ export declare const DEFAULT_PRIMARY = "id";
|
|
|
632
711
|
* rewritten, or repaired automatically.
|
|
633
712
|
*/
|
|
634
713
|
export declare interface DriverInterface extends StorageInterface {
|
|
714
|
+
/**
|
|
715
|
+
* Readies the tables from a derived {@link TableSchema} list.
|
|
716
|
+
*
|
|
717
|
+
* @remarks
|
|
718
|
+
* A native backend builds real tables and indexes from the derived columns,
|
|
719
|
+
* types, primary, and index groups; a scan-only backend reads `name` alone.
|
|
720
|
+
*/
|
|
635
721
|
open(schema: readonly TableSchema[]): Promise<void>;
|
|
722
|
+
/**
|
|
723
|
+
* Releases the backend.
|
|
724
|
+
*/
|
|
636
725
|
close(): Promise<void>;
|
|
637
726
|
/**
|
|
638
727
|
* Captures table rows and returns a repeatable thunk that restores those rows —
|
|
@@ -723,9 +812,9 @@ export declare interface DriverMetadata {
|
|
|
723
812
|
* @remarks
|
|
724
813
|
* Primitives compare by SameValueZero (`NaN` equals itself; `+0` equals `-0`).
|
|
725
814
|
* Arrays compare by index (same length, every element `equalsValue`). Plain
|
|
726
|
-
* records (through `isRecord`) compare by their
|
|
727
|
-
*
|
|
728
|
-
* with a `equalsValue` value — so a key present with value `undefined` is
|
|
815
|
+
* records (through `isRecord`) compare by their own enumerable keys: same key
|
|
816
|
+
* count and, for every key in `left`, `right` has that key (`Object.hasOwn`)
|
|
817
|
+
* with a `equalsValue` value — so a key present with value `undefined` is not
|
|
729
818
|
* equal to that key being absent (both differ in `Object.keys` membership).
|
|
730
819
|
* Anything else (functions, class instances, mismatched shapes) falls through
|
|
731
820
|
* to `false`. Container pairs are tracked iteratively, so self-referential and
|
|
@@ -812,6 +901,10 @@ export declare type IndexMap = Readonly<Record<string, ReadonlyArray<readonly st
|
|
|
812
901
|
/**
|
|
813
902
|
* Checks whether a value is a portable column schema.
|
|
814
903
|
*
|
|
904
|
+
* @remarks
|
|
905
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
906
|
+
* contained as a non-match rather than a throw.
|
|
907
|
+
*
|
|
815
908
|
* @param value - The value to test
|
|
816
909
|
* @returns True if `value` is a complete {@link ColumnSchema}; false otherwise
|
|
817
910
|
*/
|
|
@@ -837,6 +930,12 @@ export declare function isDatabaseError(value: unknown): value is DatabaseError;
|
|
|
837
930
|
/**
|
|
838
931
|
* Checks whether a value is persisted driver metadata.
|
|
839
932
|
*
|
|
933
|
+
* @remarks
|
|
934
|
+
* The boundary check a versioning driver's `metadata()` narrows a stored or
|
|
935
|
+
* deserialized record through, so no call site needs an assertion. Total over any
|
|
936
|
+
* input: a hostile getter, a revoked proxy, or a cyclic value is contained as a
|
|
937
|
+
* non-match rather than a throw.
|
|
938
|
+
*
|
|
840
939
|
* @param value - The value to test
|
|
841
940
|
* @returns True if `value` is complete {@link DriverMetadata}; false otherwise
|
|
842
941
|
*/
|
|
@@ -845,6 +944,10 @@ export declare function isDriverMetadata(value: unknown): value is DriverMetadat
|
|
|
845
944
|
/**
|
|
846
945
|
* Checks whether a value is a complete portable driver schema.
|
|
847
946
|
*
|
|
947
|
+
* @remarks
|
|
948
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
949
|
+
* contained as a non-match rather than a throw.
|
|
950
|
+
*
|
|
848
951
|
* @param value - The value to test
|
|
849
952
|
* @returns True if `value` is a table-schema collection with unique table names; false otherwise
|
|
850
953
|
*/
|
|
@@ -861,6 +964,10 @@ export declare function isKey(value: unknown): value is Key;
|
|
|
861
964
|
/**
|
|
862
965
|
* Checks whether a value is an ordered migration plan.
|
|
863
966
|
*
|
|
967
|
+
* @remarks
|
|
968
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
969
|
+
* contained as a non-match rather than a throw.
|
|
970
|
+
*
|
|
864
971
|
* @param value - The value to test
|
|
865
972
|
* @returns True if `value` is a complete {@link Migration}; false otherwise
|
|
866
973
|
*/
|
|
@@ -869,6 +976,10 @@ export declare function isMigration(value: unknown): value is Migration;
|
|
|
869
976
|
/**
|
|
870
977
|
* Checks whether a value is one atomic migration request.
|
|
871
978
|
*
|
|
979
|
+
* @remarks
|
|
980
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
981
|
+
* contained as a non-match rather than a throw.
|
|
982
|
+
*
|
|
872
983
|
* @param value - The value to test
|
|
873
984
|
* @returns True if `value` is a complete {@link MigrationInput}; false otherwise
|
|
874
985
|
*/
|
|
@@ -877,6 +988,10 @@ export declare function isMigrationInput(value: unknown): value is MigrationInpu
|
|
|
877
988
|
/**
|
|
878
989
|
* Checks whether a value is one ordered migration step.
|
|
879
990
|
*
|
|
991
|
+
* @remarks
|
|
992
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
993
|
+
* contained as a non-match rather than a throw.
|
|
994
|
+
*
|
|
880
995
|
* @param value - The value to test
|
|
881
996
|
* @returns True if `value` is a complete {@link MigrationStep}; false otherwise
|
|
882
997
|
*/
|
|
@@ -885,6 +1000,10 @@ export declare function isMigrationStep(value: unknown): value is MigrationStep;
|
|
|
885
1000
|
/**
|
|
886
1001
|
* Checks whether a value is a portable table schema.
|
|
887
1002
|
*
|
|
1003
|
+
* @remarks
|
|
1004
|
+
* Total over any input: a hostile getter, a revoked proxy, or a cyclic value is
|
|
1005
|
+
* contained as a non-match rather than a throw.
|
|
1006
|
+
*
|
|
888
1007
|
* @param value - The value to test
|
|
889
1008
|
* @returns True if `value` is a complete {@link TableSchema}; false otherwise
|
|
890
1009
|
*/
|
|
@@ -919,7 +1038,7 @@ export declare type KeyFunction = () => Key;
|
|
|
919
1038
|
* string is one column; an array descends a nested value) — and applies the
|
|
920
1039
|
* operator. Range operators (`above` / `below` / `from` / `to` / `between`) use
|
|
921
1040
|
* {@link compareValues}, the total order; the equality family (`equals` / `not`
|
|
922
|
-
* / `any` / `none`) uses {@link equalsValue} —
|
|
1041
|
+
* / `any` / `none`) uses {@link equalsValue} — structural equality, not the total
|
|
923
1042
|
* order's rank-5-collapses-all-objects behavior, so `equals` on an object/array
|
|
924
1043
|
* operand only matches a structurally-equal value, never every row holding any
|
|
925
1044
|
* object. This is a semantics change from ranking: `equalsValue` is SameValueZero
|
|
@@ -940,7 +1059,7 @@ export declare function matchesCondition(row: Row, condition: Condition): boolea
|
|
|
940
1059
|
* @remarks
|
|
941
1060
|
* `*` matches any run of characters (including none) and `?` matches exactly one
|
|
942
1061
|
* character; every other pattern character matches itself literally, so a
|
|
943
|
-
* character class such as `[a-z]` is
|
|
1062
|
+
* character class such as `[a-z]` is not interpreted. Runs on
|
|
944
1063
|
* {@link matchesWildcardPattern}, so the match is linear in the value length and
|
|
945
1064
|
* the pattern is capped at {@link MAX_PATTERN_LENGTH}.
|
|
946
1065
|
*
|
|
@@ -995,16 +1114,16 @@ export declare function matchesLikePattern(value: string, pattern: string): bool
|
|
|
995
1114
|
export declare function matchesQuery(row: Row, conditions: readonly Condition[]): boolean;
|
|
996
1115
|
|
|
997
1116
|
/**
|
|
998
|
-
* Matches a value against a wildcard pattern in
|
|
1117
|
+
* Matches a value against a wildcard pattern in linear time — the shared, ReDoS-safe
|
|
999
1118
|
* engine behind {@link matchesLikePattern} and {@link matchesGlobPattern}.
|
|
1000
1119
|
*
|
|
1001
1120
|
* @remarks
|
|
1002
|
-
* A backtracking RegExp (`a%b%c` → `^a.*b.*c$`) is
|
|
1121
|
+
* A backtracking RegExp (`a%b%c` → `^a.*b.*c$`) is catastrophic on a hostile pattern:
|
|
1003
1122
|
* `.*` segments separated by literals, matched against a long non-matching input, blow
|
|
1004
1123
|
* up super-linearly — and JS has no atomic groups / possessive quantifiers to bound it,
|
|
1005
1124
|
* while a `LIKE` / `GLOB` pattern is a caller-supplied operand this package cannot
|
|
1006
|
-
* trust. So this builds
|
|
1007
|
-
* the `any` wildcard records its position and, on a later mismatch, backtracks
|
|
1125
|
+
* trust. So this builds no regex. It runs the classic greedy two-pointer wildcard match:
|
|
1126
|
+
* the `any` wildcard records its position and, on a later mismatch, backtracks only to
|
|
1008
1127
|
* that last `any` (letting it absorb one more char) — so the work is O(value × pattern),
|
|
1009
1128
|
* never the exponential / polynomial backtracking a regex would do. The pattern length
|
|
1010
1129
|
* is capped at {@link MAX_PATTERN_LENGTH} (a `VALIDATION` {@link DatabaseError} over it),
|
|
@@ -1012,28 +1131,29 @@ export declare function matchesQuery(row: Row, conditions: readonly Condition[])
|
|
|
1012
1131
|
* pattern.
|
|
1013
1132
|
*
|
|
1014
1133
|
* The `any` wildcard matches any run (including empty); `single` matches exactly one
|
|
1015
|
-
* char; every other pattern char matches itself
|
|
1134
|
+
* char; every other pattern char matches itself literally (a pattern `.` / `(` / `\` is
|
|
1016
1135
|
* a literal — the regex-metacharacter hazard is gone with the regex). `any` is tested
|
|
1017
|
-
*
|
|
1018
|
-
* shadows the wildcard. Case folding is applied to
|
|
1136
|
+
* before a literal match, so a value that literally contains the wildcard char never
|
|
1137
|
+
* shadows the wildcard. Case folding is applied to both sides when `fold` is set.
|
|
1019
1138
|
*
|
|
1020
1139
|
* @param value - The value to test
|
|
1021
1140
|
* @param pattern - The wildcard pattern
|
|
1022
1141
|
* @param any - The any-run wildcard char (`%` for `LIKE`, `*` for `GLOB`)
|
|
1023
1142
|
* @param single - The single-char wildcard char (`_` for `LIKE`, `?` for `GLOB`)
|
|
1024
|
-
* @param fold - Whether to match case-
|
|
1143
|
+
* @param fold - Whether to match case-insensitively (`LIKE` folds; `GLOB` does not)
|
|
1025
1144
|
* @returns True if `value` matches `pattern`; false otherwise
|
|
1026
1145
|
* @throws A `VALIDATION` {@link DatabaseError} when `pattern` exceeds {@link MAX_PATTERN_LENGTH}
|
|
1027
1146
|
*/
|
|
1028
1147
|
export declare function matchesWildcardPattern(value: string, pattern: string, any: string, single: string, fold: boolean): boolean;
|
|
1029
1148
|
|
|
1030
1149
|
/**
|
|
1031
|
-
* Sets the longest `LIKE` / `GLOB` pattern the wildcard matcher accepts
|
|
1150
|
+
* Sets the longest `LIKE` / `GLOB` pattern the wildcard matcher accepts, 1024 characters, before
|
|
1151
|
+
* rejecting it.
|
|
1032
1152
|
*
|
|
1033
1153
|
* @remarks
|
|
1034
1154
|
* A `LIKE` / `GLOB` pattern is a caller-supplied operand, so
|
|
1035
1155
|
* `matchesLikePattern` / `matchesGlobPattern` run patterns this package cannot
|
|
1036
|
-
* trust. The matcher is the
|
|
1156
|
+
* trust. The matcher is the linear greedy two-pointer wildcard match — never a
|
|
1037
1157
|
* backtracking regex (`.*`-segments-separated-by-literals against a long input is the
|
|
1038
1158
|
* catastrophic shape JS cannot bound without atomic groups), so it is O(value ×
|
|
1039
1159
|
* pattern). Capping the pattern length bounds that pattern factor, leaving a match
|
|
@@ -1048,7 +1168,7 @@ export declare const MAX_PATTERN_LENGTH = 1024;
|
|
|
1048
1168
|
* @remarks
|
|
1049
1169
|
* The in-between made concrete: it runs identically in a browser or on a server,
|
|
1050
1170
|
* so it is the storage behind tests, ephemeral caches, and any code that wants
|
|
1051
|
-
* the database API without a persistent backend. Rows are
|
|
1171
|
+
* the database API without a persistent backend. Rows are deep-copied (through
|
|
1052
1172
|
* `structuredClone`) in and out — at `write`, `read`, `scan`, `stream`, and both
|
|
1053
1173
|
* snapshot capture and restore — so a caller mutating a nested field of an input
|
|
1054
1174
|
* row, a returned row, or a row mutated in place between snapshot and rollback
|
|
@@ -1083,7 +1203,7 @@ export declare class MemoryDriver implements DriverInterface {
|
|
|
1083
1203
|
* toward `offset` / `limit`. Both are applied lazily as matches are found —
|
|
1084
1204
|
* `offset` matches are skipped without being yielded, and iteration stops the
|
|
1085
1205
|
* instant `limit` yields have been produced, so a large table is never fully
|
|
1086
|
-
* walked for a small page. `input.order` is
|
|
1206
|
+
* walked for a small page. `input.order` is ignored (the same contract as
|
|
1087
1207
|
* `TableInterface.scan` and `QueryInterface.stream`): streaming yields key
|
|
1088
1208
|
* order, sorted output is `records()`'s job. Rows yield copy-out, and an
|
|
1089
1209
|
* unknown table mirrors `scan`'s empty-yield behavior.
|
|
@@ -1252,7 +1372,8 @@ export declare function normalizeDriverSchema(value: unknown): readonly TableSch
|
|
|
1252
1372
|
* When `signal` aborts, the operation throws a {@link DatabaseError} with code
|
|
1253
1373
|
* `ABORTED` carrying `signal.reason` in `context`. Reads check at their
|
|
1254
1374
|
* documented boundaries; point mutations propagate the signal through the
|
|
1255
|
-
* driver to the backend commit point.
|
|
1375
|
+
* driver to the backend commit point. A streamed read — {@link TableInterface.scan}
|
|
1376
|
+
* or {@link QueryInterface.stream} — checks the signal before each yield.
|
|
1256
1377
|
*/
|
|
1257
1378
|
export declare interface OperationOptions {
|
|
1258
1379
|
readonly signal?: AbortSignal;
|
|
@@ -1283,16 +1404,16 @@ export declare type OrderDirection = 'ascending' | 'descending';
|
|
|
1283
1404
|
* plan labels only; versioning drivers persist and reconcile them through
|
|
1284
1405
|
* {@link DriverMetadata}.
|
|
1285
1406
|
*
|
|
1286
|
-
* A column present in
|
|
1407
|
+
* A column present in both schemas under the same name but with a different
|
|
1287
1408
|
* `storage`, `optional`, or `nullable` value throws a `MIGRATION`
|
|
1288
1409
|
* {@link DatabaseError} naming the table, the column, and the from→to
|
|
1289
|
-
* difference — a name-only diff would otherwise silently produce
|
|
1410
|
+
* difference — a name-only diff would otherwise silently produce no step for
|
|
1290
1411
|
* the drift, and versioned reconciliation would stamp over it. There is no
|
|
1291
1412
|
* automatic in-place type-change step: the manual path is to add a new column,
|
|
1292
1413
|
* copy/convert the data at the application layer, then remove the old column —
|
|
1293
1414
|
* two separate plans, never a single implicit "alter" step.
|
|
1294
1415
|
*
|
|
1295
|
-
* @param deployed - The table schemas
|
|
1416
|
+
* @param deployed - The already-applied table schemas
|
|
1296
1417
|
* @param declared - The table schemas the caller wants applied
|
|
1297
1418
|
* @param from - The plan's source version label (defaults to `0`)
|
|
1298
1419
|
* @param to - The plan's target version label (defaults to `1`)
|
|
@@ -1324,6 +1445,8 @@ export declare type PrimaryMap = Readonly<Record<string, string>>;
|
|
|
1324
1445
|
|
|
1325
1446
|
/**
|
|
1326
1447
|
* Projects migration steps sequentially over a canonical validated owned schema.
|
|
1448
|
+
*
|
|
1449
|
+
* @remarks
|
|
1327
1450
|
* Adding a required non-null column to an existing table rejects with
|
|
1328
1451
|
* `MIGRATION`; optional-only and nullable-only additions remain portable.
|
|
1329
1452
|
*
|
|
@@ -1362,25 +1485,52 @@ export declare interface QueryInput {
|
|
|
1362
1485
|
* {@link FieldPath} — a string is one column, an array descends a nested value.
|
|
1363
1486
|
*/
|
|
1364
1487
|
export declare interface QueryInterface<T = Row> {
|
|
1488
|
+
/**
|
|
1489
|
+
* Adds one portable condition, including its explicit connector.
|
|
1490
|
+
*/
|
|
1365
1491
|
condition(input: Condition): QueryInterface<T>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Adds one portable ordering term — a column and a direction.
|
|
1494
|
+
*/
|
|
1366
1495
|
order(input: Order): QueryInterface<T>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Adds a post-fetch JavaScript predicate.
|
|
1498
|
+
*/
|
|
1367
1499
|
filter(predicate: (row: T) => boolean): QueryInterface<T>;
|
|
1500
|
+
/**
|
|
1501
|
+
* Caps the result count.
|
|
1502
|
+
*/
|
|
1368
1503
|
limit(count: number): QueryInterface<T>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Skips the leading rows.
|
|
1506
|
+
*/
|
|
1369
1507
|
offset(count: number): QueryInterface<T>;
|
|
1508
|
+
/**
|
|
1509
|
+
* Executes the accumulated read and collects every matching row.
|
|
1510
|
+
*/
|
|
1370
1511
|
collect(): Promise<readonly T[]>;
|
|
1512
|
+
/**
|
|
1513
|
+
* Executes the accumulated read and returns the first match, or `undefined`.
|
|
1514
|
+
*/
|
|
1371
1515
|
find(): Promise<T | undefined>;
|
|
1516
|
+
/**
|
|
1517
|
+
* Executes the accumulated read and returns the match count.
|
|
1518
|
+
*/
|
|
1372
1519
|
count(): Promise<number>;
|
|
1373
1520
|
/**
|
|
1374
1521
|
* Evaluates this query's conditions / filters / offset / limit lazily, row
|
|
1375
1522
|
* by row.
|
|
1376
1523
|
*
|
|
1377
1524
|
* @remarks
|
|
1378
|
-
* `order` and its comparators are
|
|
1525
|
+
* `order` and its comparators are ignored (streaming yields unsorted, as
|
|
1379
1526
|
* rows are evaluated one at a time). Same abort semantics as
|
|
1380
1527
|
* {@link TableInterface.scan}: the signal (if any) is checked before each
|
|
1381
1528
|
* yield, and breaking out early closes the underlying source.
|
|
1382
1529
|
*/
|
|
1383
1530
|
stream(options?: OperationOptions): AsyncIterable<T>;
|
|
1531
|
+
/**
|
|
1532
|
+
* Executes a named aggregate over one column.
|
|
1533
|
+
*/
|
|
1384
1534
|
aggregate(operation: AggregateOperation, column: FieldPath): Promise<number | undefined>;
|
|
1385
1535
|
}
|
|
1386
1536
|
|
|
@@ -1461,14 +1611,14 @@ export declare type RowOf<C extends ColumnMap> = Infer<{
|
|
|
1461
1611
|
* default `id`, `posts` keyed by a non-id `slug`) and, calling `factory()`
|
|
1462
1612
|
* fresh for each phase so failures stay isolated, verifies: `open`/`close`;
|
|
1463
1613
|
* `read` of a missing key returns `undefined`; `write`/`read` round-trip
|
|
1464
|
-
* with
|
|
1465
|
-
* including a
|
|
1614
|
+
* with deep copy-in/copy-out isolation (mutating the caller's row —
|
|
1615
|
+
* including a nested field — after `write`, or a row `read` returns, never
|
|
1466
1616
|
* perturbs stored state) and upsert-overwrite; simultaneous same-key
|
|
1467
1617
|
* `insert` calls produce exactly one commit and one `CONFLICT`; pre-aborted
|
|
1468
1618
|
* `write`, `insert`, and `delete` calls leave storage unchanged; `delete`
|
|
1469
1619
|
* returns `true` then `false`; `keys`/`scan` yield in ascending key order;
|
|
1470
1620
|
* `clear` empties only its target table; `snapshot`'s rollback thunk
|
|
1471
|
-
* restores pre-snapshot state, including a
|
|
1621
|
+
* restores pre-snapshot state, including a nested field mutated in place on
|
|
1472
1622
|
* a read-back row between capture and restore; a scoped
|
|
1473
1623
|
* `snapshot(['users'])` rolls back only the named table, leaving a
|
|
1474
1624
|
* concurrent mutation to another table intact; a non-`id` primary key
|
|
@@ -1482,12 +1632,12 @@ export declare type RowOf<C extends ColumnMap> = Infer<{
|
|
|
1482
1632
|
* store's `metadata()` is `undefined`, and after
|
|
1483
1633
|
* `stamp({ version, schema })`, `metadata()` returns the exact stamped value.
|
|
1484
1634
|
*
|
|
1485
|
-
* Each phase runs within a `try`/`catch`: an
|
|
1486
|
-
* finding built from the assertion, while an
|
|
1635
|
+
* Each phase runs within a `try`/`catch`: an expected mismatch yields a
|
|
1636
|
+
* finding built from the assertion, while an unexpected throw (a driver
|
|
1487
1637
|
* crash mid-phase) is caught and yielded as a finding too, naming the phase
|
|
1488
1638
|
* as `check` and carrying the caught error in `context.error` — a broken
|
|
1489
1639
|
* driver can never escape the battery as an unhandled rejection. Within a
|
|
1490
|
-
* phase, the
|
|
1640
|
+
* phase, the first violated assertion yields and the phase stops (matching
|
|
1491
1641
|
* the historical fail-fast shape at phase granularity); the generator then
|
|
1492
1642
|
* moves on to the next phase regardless. Because this is a **generator**,
|
|
1493
1643
|
* consuming only the first yielded value reproduces true fail-fast (later
|
|
@@ -1566,18 +1716,57 @@ export declare function sortRows(rows: readonly Row[], order: readonly Order[]):
|
|
|
1566
1716
|
* callers fall back to `scan` when a native read hook is absent.
|
|
1567
1717
|
*/
|
|
1568
1718
|
export declare interface StorageInterface {
|
|
1719
|
+
/**
|
|
1720
|
+
* Reads one row by key.
|
|
1721
|
+
*/
|
|
1569
1722
|
read(table: string, key: Key): Promise<Row | undefined>;
|
|
1723
|
+
/**
|
|
1724
|
+
* Writes one row at a key.
|
|
1725
|
+
*/
|
|
1570
1726
|
write(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
|
|
1727
|
+
/**
|
|
1728
|
+
* Inserts one row atomically, rejecting `CONFLICT` when its key already exists.
|
|
1729
|
+
*/
|
|
1571
1730
|
insert(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Deletes one row by key.
|
|
1733
|
+
*/
|
|
1572
1734
|
delete(table: string, key: Key, options?: OperationOptions): Promise<boolean>;
|
|
1735
|
+
/**
|
|
1736
|
+
* Lists a table's keys.
|
|
1737
|
+
*/
|
|
1573
1738
|
keys(table: string): Promise<readonly Key[]>;
|
|
1739
|
+
/**
|
|
1740
|
+
* Iterates a table's rows in ascending key order.
|
|
1741
|
+
*/
|
|
1574
1742
|
scan(table: string): AsyncIterable<Row>;
|
|
1743
|
+
/**
|
|
1744
|
+
* Empties a table.
|
|
1745
|
+
*/
|
|
1575
1746
|
clear(table: string): Promise<void>;
|
|
1747
|
+
/**
|
|
1748
|
+
* Reads the rows matching a {@link QueryInput} natively — an optional hook.
|
|
1749
|
+
*/
|
|
1576
1750
|
records?(table: string, input: QueryInput): Promise<readonly Row[]>;
|
|
1751
|
+
/**
|
|
1752
|
+
* Computes an aggregate over a column natively — an optional hook.
|
|
1753
|
+
*/
|
|
1577
1754
|
aggregate?(table: string, operation: AggregateOperation, column: FieldPath, input: QueryInput): Promise<number | undefined>;
|
|
1755
|
+
/**
|
|
1756
|
+
* Iterates the natively filtered rows lazily — an optional hook.
|
|
1757
|
+
*/
|
|
1578
1758
|
stream?(table: string, input: QueryInput): AsyncIterable<Row>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Applies one atomic {@link MigrationInput} — an optional hook.
|
|
1761
|
+
*/
|
|
1579
1762
|
migrate?(input: MigrationInput): Promise<void>;
|
|
1763
|
+
/**
|
|
1764
|
+
* Reads the persisted {@link DriverMetadata} as a deeply frozen copy — an optional hook.
|
|
1765
|
+
*/
|
|
1580
1766
|
metadata?(): Promise<DriverMetadata | undefined>;
|
|
1767
|
+
/**
|
|
1768
|
+
* Writes the persisted {@link DriverMetadata}, snapshot at entry — an optional hook.
|
|
1769
|
+
*/
|
|
1581
1770
|
stamp?(metadata: DriverMetadata): Promise<void>;
|
|
1582
1771
|
}
|
|
1583
1772
|
|
|
@@ -1599,17 +1788,17 @@ export declare interface TableDefinition {
|
|
|
1599
1788
|
/**
|
|
1600
1789
|
* Describes the push observation surface of a {@link TableInterface} — the per-row
|
|
1601
1790
|
* mutation moments a fire-and-forget observer (cache invalidation, sync, an audit log)
|
|
1602
|
-
* subscribes to,
|
|
1791
|
+
* subscribes to, alongside the database-level {@link DatabaseEventMap}.
|
|
1603
1792
|
*
|
|
1604
1793
|
* @remarks
|
|
1605
|
-
* Events carry the affected
|
|
1794
|
+
* Events carry the affected key only — never the row value — to keep fan-out lean and
|
|
1606
1795
|
* avoid leaking row data through the observation channel; a consumer that needs the
|
|
1607
1796
|
* value re-reads it by key. Any row put — `set`, `add`, or `update` — emits a single
|
|
1608
1797
|
* `write` (the consumer re-reads if it needs to know what changed); a delete emits
|
|
1609
|
-
* `remove`; emptying the table emits `clear`. Reads / queries / counts are
|
|
1798
|
+
* `remove`; emptying the table emits `clear`. Reads / queries / counts are not emitted
|
|
1610
1799
|
* (too hot, and a reader does not mutate). Listener isolation is the emitter's:
|
|
1611
1800
|
* every event is emitted directly and a listener throw is routed to the emitter's `error`
|
|
1612
|
-
* handler (the `error` option), never onto this map, and sits
|
|
1801
|
+
* handler (the `error` option), never onto this map, and sits after the driver write / delete
|
|
1613
1802
|
* / clear has completed — so a throwing observer can never corrupt a write or perturb a
|
|
1614
1803
|
* transaction. Subscribe through `table.emitter.on(...)`. Declared as a `type` alias (
|
|
1615
1804
|
* `EventMap` is a `type` kind).
|
|
@@ -1644,13 +1833,28 @@ export declare interface TableInterface<T = Row> {
|
|
|
1644
1833
|
readonly name: string;
|
|
1645
1834
|
readonly primary: string;
|
|
1646
1835
|
readonly contract: ContractInterface<T>;
|
|
1836
|
+
/**
|
|
1837
|
+
* Reads one row by key, or one row per key for a list — `undefined` for each miss.
|
|
1838
|
+
*/
|
|
1647
1839
|
get(key: Key): Promise<T | undefined>;
|
|
1648
1840
|
get(keys: readonly Key[]): Promise<ReadonlyArray<T | undefined>>;
|
|
1841
|
+
/**
|
|
1842
|
+
* Reads one row by key, or one row per key for a list, throwing `NOT_FOUND` on a miss.
|
|
1843
|
+
*/
|
|
1649
1844
|
resolve(key: Key): Promise<T>;
|
|
1650
1845
|
resolve(keys: readonly Key[]): Promise<readonly T[]>;
|
|
1846
|
+
/**
|
|
1847
|
+
* Reports whether one key exists, or one result per key for a list.
|
|
1848
|
+
*/
|
|
1651
1849
|
has(key: Key): Promise<boolean>;
|
|
1652
1850
|
has(keys: readonly Key[]): Promise<readonly boolean[]>;
|
|
1851
|
+
/**
|
|
1852
|
+
* Lists every primary key in order.
|
|
1853
|
+
*/
|
|
1653
1854
|
keys(): Promise<readonly Key[]>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Reads the contract-valid rows matching an optional {@link QueryInput}.
|
|
1857
|
+
*/
|
|
1654
1858
|
records(input?: QueryInput, options?: OperationOptions): Promise<readonly T[]>;
|
|
1655
1859
|
/**
|
|
1656
1860
|
* Counts contract-valid rows matching `input`'s conditions.
|
|
@@ -1666,7 +1870,7 @@ export declare interface TableInterface<T = Row> {
|
|
|
1666
1870
|
* conditions.
|
|
1667
1871
|
*
|
|
1668
1872
|
* @remarks
|
|
1669
|
-
* Unlike {@link TableInterface.count}, `aggregate` operates on
|
|
1873
|
+
* Unlike {@link TableInterface.count}, `aggregate` operates on stored rows
|
|
1670
1874
|
* without the contract guard that `records()` / `scan()` apply — a
|
|
1671
1875
|
* non-conforming stored row still contributes to the aggregate (or to the
|
|
1672
1876
|
* `count` operation's tally) when it matches the conditions, even though
|
|
@@ -1678,7 +1882,7 @@ export declare interface TableInterface<T = Row> {
|
|
|
1678
1882
|
*
|
|
1679
1883
|
* @remarks
|
|
1680
1884
|
* `input`'s `conditions` / `offset` / `limit` are honored lazily as rows
|
|
1681
|
-
* stream; `order` is intentionally
|
|
1885
|
+
* stream; `order` is intentionally ignored — streaming yields driver
|
|
1682
1886
|
* key-order, sorted output is `records()`'s job. Breaking out of the
|
|
1683
1887
|
* iteration early closes the underlying source. The signal (if any) is
|
|
1684
1888
|
* checked before each yield.
|
|
@@ -1770,8 +1974,17 @@ export declare interface TableInterface<T = Row> {
|
|
|
1770
1974
|
* applied — there is no rollback. Wrap in `transaction()` for atomicity.
|
|
1771
1975
|
*/
|
|
1772
1976
|
remove(keys: readonly Key[], options?: OperationOptions): Promise<readonly boolean[]>;
|
|
1977
|
+
/**
|
|
1978
|
+
* Empties the table.
|
|
1979
|
+
*/
|
|
1773
1980
|
clear(): Promise<void>;
|
|
1981
|
+
/**
|
|
1982
|
+
* Opens a fluent query builder over the table.
|
|
1983
|
+
*/
|
|
1774
1984
|
query(): QueryInterface<T>;
|
|
1985
|
+
/**
|
|
1986
|
+
* Opens a forward row cursor for bulk mutation.
|
|
1987
|
+
*/
|
|
1775
1988
|
cursor(): Promise<CursorInterface<T>>;
|
|
1776
1989
|
}
|
|
1777
1990
|
|