@microdelta/history 0.0.0 → 0.2.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.
Files changed (79) hide show
  1. package/README.md +30 -4
  2. package/dist/api/history.alpha.d.ts +3 -0
  3. package/dist/api/history.beta.d.ts +3 -0
  4. package/dist/api/history.conformance.store.alpha.d.ts +3 -0
  5. package/dist/api/history.conformance.store.beta.d.ts +3 -0
  6. package/dist/api/history.conformance.store.public.d.ts +3 -0
  7. package/dist/api/history.conformance.store.raw.alpha.d.ts +215 -0
  8. package/dist/api/history.conformance.store.raw.beta.d.ts +215 -0
  9. package/dist/api/history.conformance.store.raw.public.d.ts +215 -0
  10. package/dist/api/history.conformance.store.raw.untrimmed.d.ts +215 -0
  11. package/dist/api/history.conformance.store.untrimmed.d.ts +3 -0
  12. package/dist/api/history.public.d.ts +3 -0
  13. package/dist/api/history.root.raw.alpha.d.ts +1371 -0
  14. package/dist/api/history.root.raw.beta.d.ts +425 -0
  15. package/dist/api/history.root.raw.public.d.ts +425 -0
  16. package/dist/api/history.root.raw.untrimmed.d.ts +1372 -0
  17. package/dist/api/history.shared.alpha.d.ts +1402 -0
  18. package/dist/api/history.shared.beta.d.ts +456 -0
  19. package/dist/api/history.shared.public.d.ts +456 -0
  20. package/dist/api/history.shared.untrimmed.d.ts +1403 -0
  21. package/dist/api/history.untrimmed.d.ts +3 -0
  22. package/dist/api/tsdoc-metadata.json +11 -0
  23. package/dist/src/completed-results.d.ts +99 -0
  24. package/dist/src/completed-results.d.ts.map +1 -0
  25. package/dist/src/completed-results.js +2 -0
  26. package/dist/src/completed-results.js.map +1 -0
  27. package/dist/src/durable/contracts.d.ts +612 -0
  28. package/dist/src/durable/contracts.d.ts.map +1 -0
  29. package/dist/src/durable/contracts.js +2 -0
  30. package/dist/src/durable/contracts.js.map +1 -0
  31. package/dist/src/durable/errors.d.ts +94 -0
  32. package/dist/src/durable/errors.d.ts.map +1 -0
  33. package/dist/src/durable/errors.js +118 -0
  34. package/dist/src/durable/errors.js.map +1 -0
  35. package/dist/src/durable/index.d.ts +9 -0
  36. package/dist/src/durable/index.d.ts.map +1 -0
  37. package/dist/src/durable/index.js +770 -0
  38. package/dist/src/durable/index.js.map +1 -0
  39. package/dist/src/durable/journal.d.ts +53 -0
  40. package/dist/src/durable/journal.d.ts.map +1 -0
  41. package/dist/src/durable/journal.js +174 -0
  42. package/dist/src/durable/journal.js.map +1 -0
  43. package/dist/src/durable/locator.d.ts +31 -0
  44. package/dist/src/durable/locator.d.ts.map +1 -0
  45. package/dist/src/durable/locator.js +50 -0
  46. package/dist/src/durable/locator.js.map +1 -0
  47. package/dist/src/durable/records.d.ts +40 -0
  48. package/dist/src/durable/records.d.ts.map +1 -0
  49. package/dist/src/durable/records.js +74 -0
  50. package/dist/src/durable/records.js.map +1 -0
  51. package/dist/src/durable/schema.d.ts +37 -0
  52. package/dist/src/durable/schema.d.ts.map +1 -0
  53. package/dist/src/durable/schema.js +335 -0
  54. package/dist/src/durable/schema.js.map +1 -0
  55. package/dist/src/durable/selected-index.d.ts +94 -0
  56. package/dist/src/durable/selected-index.d.ts.map +1 -0
  57. package/dist/src/durable/selected-index.js +594 -0
  58. package/dist/src/durable/selected-index.js.map +1 -0
  59. package/dist/src/index.d.ts +28 -0
  60. package/dist/src/index.d.ts.map +1 -0
  61. package/dist/src/index.js +15 -0
  62. package/dist/src/index.js.map +1 -0
  63. package/dist/src/store/index.d.ts +128 -0
  64. package/dist/src/store/index.d.ts.map +1 -0
  65. package/dist/src/store/index.js +33 -0
  66. package/dist/src/store/index.js.map +1 -0
  67. package/dist/src/store/memory/index.d.ts +24 -0
  68. package/dist/src/store/memory/index.d.ts.map +1 -0
  69. package/dist/src/store/memory/index.js +162 -0
  70. package/dist/src/store/memory/index.js.map +1 -0
  71. package/dist/src/types.d.ts +100 -0
  72. package/dist/src/types.d.ts.map +1 -0
  73. package/dist/src/types.js +2 -0
  74. package/dist/src/types.js.map +1 -0
  75. package/dist/test/conformance/store/index.d.ts +34 -0
  76. package/dist/test/conformance/store/index.d.ts.map +1 -0
  77. package/dist/test/conformance/store/index.js +368 -0
  78. package/dist/test/conformance/store/index.js.map +1 -0
  79. package/package.json +48 -8
@@ -0,0 +1,456 @@
1
+ /**
2
+ * One declaration identity contains History's root and Store conformance APIs.
3
+ * This build-only entry does not define a runtime module or add conformance
4
+ * behavior to the public root export.
5
+ * @packageDocumentation
6
+ */
7
+
8
+ /* Excluded from this release type: AttemptConflictError */
9
+
10
+ /* Excluded from this release type: AttemptStateError */
11
+
12
+ /**
13
+ * Create a memory Store with linearizable CAS in a single JavaScript isolate.
14
+ * Each mutation snapshots its arguments before checking and changing the maps;
15
+ * the qualifying check and write have no await or caller callback between them.
16
+ * Values and fingerprints have separate indexes, so verification never touches
17
+ * payloads. The injected snapshot capability owns its supported value domain
18
+ * and failure behavior. This is a test backend, not durable or shared across
19
+ * processes.
20
+ *
21
+ * Only row storage is implemented here. Publication across multiple rows,
22
+ * generation allocation, lease ownership, and reclamation belong to higher layers.
23
+ * @public
24
+ */
25
+ export declare function createMemoryStore(capability: ISnapshotCapability, options?: MemoryStoreOptions): Store;
26
+
27
+ /** The first observed difference in a persisted read or a nested verification. @public */
28
+ export declare type Divergence = {
29
+ read: RecordedRead;
30
+ was: Fingerprint;
31
+ now: Fingerprint | 'missing';
32
+ } | {
33
+ read: Extract<RecordedRead, {
34
+ kind: 'memo';
35
+ }>;
36
+ nested: Divergence;
37
+ };
38
+
39
+ /** Insert-only storage encountered an existing complete tuple. @public */
40
+ export declare class DuplicateRowError extends Error {
41
+ /** Identify an insert conflict without modifying the retained row. @public */
42
+ constructor(message?: string);
43
+ }
44
+
45
+ /** An immutable value node and its caller-computed fingerprint. @public */
46
+ export declare interface FieldRow {
47
+ key: ResultKey;
48
+ generation: number;
49
+ path: Path;
50
+ fingerprint: Fingerprint;
51
+ value: unknown;
52
+ }
53
+
54
+ /**
55
+ * Compatibility shapes for the scaffold row Store. Their names and string paths
56
+ * describe that storage port, not the target Value Semantics or identity model.
57
+ */
58
+ /** Opaque, stable, hex-encoded content digest; equality is string equality. @public */
59
+ export declare type Fingerprint = string & {
60
+ readonly __fp: unique symbol;
61
+ };
62
+
63
+ /** Stored fingerprints cannot be compared with this runtime's algorithm. @public */
64
+ export declare class FingerprintAlgorithmMismatchError extends Error {
65
+ /** Name both identifiers so migrations are explicit rather than silent misses. @public */
66
+ constructor(storedAlgorithm: string, runtimeAlgorithm: string);
67
+ }
68
+
69
+ /** Writable generation columns; tuple identity cannot change after insertion. @public */
70
+ export declare type GenerationPatch = Partial<Omit<GenerationRow, 'key' | 'generation'>>;
71
+
72
+ /** A retained attempt, with lifecycle and numbering supplied by its caller. @public */
73
+ export declare interface GenerationRow {
74
+ key: ResultKey;
75
+ generation: number;
76
+ state: GenerationState;
77
+ reads: RecordedRead[];
78
+ identity: Identity | undefined;
79
+ startedAt: number;
80
+ endedAt: number | null;
81
+ cost: Record<string, number>;
82
+ arrival: string;
83
+ abandonReason?: 'error' | 'lease-expired' | 'refused';
84
+ error?: {
85
+ message: string;
86
+ stack?: string;
87
+ };
88
+ }
89
+
90
+ /** Retained lifecycle states interpreted by repository and claim, not by storage. @public */
91
+ export declare type GenerationState = 'claimed' | 'current' | 'superseded' | 'abandoned';
92
+
93
+ /* Excluded from this release type: HistoryClockError */
94
+
95
+ /* Excluded from this release type: HistoryIntegrityError */
96
+
97
+ /* Excluded from this release type: HistorySchemaError */
98
+
99
+ /* Excluded from this release type: IAbandonRequest */
100
+
101
+ /* Excluded from this release type: IAcceptanceRecord */
102
+
103
+ /* Excluded from this release type: IAcceptanceRequest */
104
+
105
+ /* Excluded from this release type: IAddressSegment */
106
+
107
+ /* Excluded from this release type: IAttemptRecord */
108
+
109
+ /* Excluded from this release type: IAttemptRequest */
110
+
111
+ /* Excluded from this release type: IAttemptState */
112
+
113
+ /* Excluded from this release type: IClockCapability */
114
+
115
+ /* Excluded from this release type: ICompletedEnvelope */
116
+
117
+ /* Excluded from this release type: ICompletedNavigationReader */
118
+
119
+ /* Excluded from this release type: ICompletedProjectionReader */
120
+
121
+ /* Excluded from this release type: ICompletedResultReader */
122
+
123
+ /* Excluded from this release type: ICompletedResultReference */
124
+
125
+ /**
126
+ * Compatibility identity shape stored in scaffold rows. It does not establish
127
+ * target subject identity, binding correspondence, or collection semantics.
128
+ * @public
129
+ */
130
+ export declare type Identity = {
131
+ kind: 'type';
132
+ type: string;
133
+ key: string;
134
+ } | {
135
+ kind: 'step';
136
+ name: string;
137
+ inputs: readonly Identity[];
138
+ } | {
139
+ kind: 'member';
140
+ of: Identity;
141
+ path: Path;
142
+ } | {
143
+ kind: 'collection';
144
+ step: string;
145
+ source: Identity;
146
+ };
147
+
148
+ /* Excluded from this release type: IDurableHistory */
149
+
150
+ /* Excluded from this release type: IDurableHistoryOptions */
151
+
152
+ /* Excluded from this release type: IHistoryScope */
153
+
154
+ /* Excluded from this release type: IJournalAddress */
155
+
156
+ /* Excluded from this release type: IJournalCommit */
157
+
158
+ /* Excluded from this release type: IJournalDeclaration */
159
+
160
+ /* Excluded from this release type: IJournalFormat */
161
+
162
+ /* Excluded from this release type: IJournalQuery */
163
+
164
+ /* Excluded from this release type: IJournalRecord */
165
+
166
+ /* Excluded from this release type: IJournalWrite */
167
+
168
+ /** A patch attempted to modify an immutable address or managed CAS version. @public */
169
+ export declare class InvalidStorePatchError extends Error {
170
+ /** Identify a structurally forbidden patch before any columns are changed. @public */
171
+ constructor(message?: string);
172
+ }
173
+
174
+ /* Excluded from this release type: IOperation */
175
+
176
+ /* Excluded from this release type: IOperationJournal */
177
+
178
+ /* Excluded from this release type: IPromotionQuery */
179
+
180
+ /* Excluded from this release type: IPromotionRecord */
181
+
182
+ /* Excluded from this release type: IPromotionRequest */
183
+
184
+ /* Excluded from this release type: IRecoveryOutcome */
185
+
186
+ /* Excluded from this release type: IResultVerification */
187
+
188
+ /* Excluded from this release type: IScopedSubject */
189
+
190
+ /* Excluded from this release type: ISelectedFact */
191
+
192
+ /* Excluded from this release type: ISelectedFingerprintRequest */
193
+
194
+ /* Excluded from this release type: ISelectedFingerprintResolution */
195
+
196
+ /* Excluded from this release type: ISelectedNode */
197
+
198
+ /* Excluded from this release type: ISelectedReadRequest */
199
+
200
+ /* Excluded from this release type: ISha256Capability */
201
+
202
+ /**
203
+ * Produces a synchronous detached copy of primitives, arrays, ordinary objects'
204
+ * enumerable string-keyed properties, Date, RegExp, Map, Set, ArrayBuffer, and
205
+ * typed-array/DataView contents. It preserves cycles and repeated references
206
+ * within one copy and isolates both input and returned snapshots. Functions,
207
+ * symbols, and raw SharedArrayBuffer values fail. Getters may run; nonenumerable
208
+ * and symbol-keyed properties and arbitrary class prototypes are not preserved.
209
+ * This contract defines neither durable encoding nor canonical identity. It is
210
+ * public because History's direct memory-store constructor requires injection.
211
+ * @public
212
+ */
213
+ declare interface ISnapshotCapability {
214
+ /** Return a detached copy or throw before a caller mutates owned state. */
215
+ snapshot<T>(value: T): T;
216
+ }
217
+
218
+ /* Excluded from this release type: ISqliteCapability */
219
+
220
+ /* Excluded from this release type: ISqliteConnection */
221
+
222
+ /* Excluded from this release type: ISqliteRow */
223
+
224
+ /* Excluded from this release type: ISqliteRunResult */
225
+
226
+ /* Excluded from this release type: ISqliteStatement */
227
+
228
+ /* Excluded from this release type: ISqliteSynchronousResult */
229
+
230
+ /* Excluded from this release type: ISqliteValue */
231
+
232
+ /* Excluded from this release type: IStageRequest */
233
+
234
+ /* Excluded from this release type: IValueProjectionDescriptor */
235
+
236
+ /* Excluded from this release type: IValueProjectionFact */
237
+
238
+ /* Excluded from this release type: IValueProjectionMember */
239
+
240
+ /* Excluded from this release type: IValueProjectionTraversal */
241
+
242
+ /* Excluded from this release type: IVersionedRecord */
243
+
244
+ /* Excluded from this release type: IVersionedSubject */
245
+
246
+ /* Excluded from this release type: IWriterAcquisition */
247
+
248
+ /* Excluded from this release type: IWriterAcquisitionRequest */
249
+
250
+ /* Excluded from this release type: IWriterContention */
251
+
252
+ /* Excluded from this release type: IWriterLease */
253
+
254
+ /* Excluded from this release type: IWriterRenewal */
255
+
256
+ /* Excluded from this release type: JournalConflictError */
257
+
258
+ /* Excluded from this release type: JournalVersionError */
259
+
260
+ /** Options for the isolated, non-durable test backend. @public */
261
+ export declare interface MemoryStoreOptions {
262
+ /** Metadata compatibility identifier; the initial store format uses sha256. */
263
+ fingerprintAlgorithm?: string;
264
+ /* Excluded from this release type: _onValueRead */
265
+ }
266
+
267
+ /** An update targeted a generation that has never been inserted. @public */
268
+ export declare class MissingRowError extends Error {
269
+ /** Identify an absent update target; updates never implicitly insert. @public */
270
+ constructor(message?: string);
271
+ }
272
+
273
+ /* Excluded from this release type: openDurableHistory */
274
+
275
+ /** Observable call outcomes; an unmemoized named execution has no storage key. @public */
276
+ export declare type Outcome = {
277
+ kind: 'served';
278
+ key: ResultKey;
279
+ generation: number;
280
+ } | {
281
+ kind: 'executed';
282
+ key: ResultKey;
283
+ generation: number;
284
+ } | {
285
+ kind: 'checked';
286
+ key: ResultKey;
287
+ wouldExecute: boolean;
288
+ divergence?: Divergence;
289
+ } | {
290
+ kind: 'refused';
291
+ key: ResultKey;
292
+ reason: unknown;
293
+ } | {
294
+ kind: 'failed';
295
+ key: ResultKey;
296
+ error: unknown;
297
+ } | {
298
+ kind: 'abandoned';
299
+ key: ResultKey;
300
+ reason: 'error' | 'lease-expired' | 'refused';
301
+ } | {
302
+ kind: 'ran';
303
+ };
304
+
305
+ /** A legacy row-storage address, not the future structured semantic path. @public */
306
+ export declare type Path = string;
307
+
308
+ /** Legacy persisted read rows; target observation encoding remains undecided. @public */
309
+ export declare type RecordedRead = {
310
+ kind: 'field';
311
+ arg: number;
312
+ path: Path;
313
+ fingerprint: Fingerprint;
314
+ } | {
315
+ kind: 'whole';
316
+ arg: number;
317
+ fingerprint: Fingerprint;
318
+ } | {
319
+ kind: 'memo';
320
+ key: ResultKey;
321
+ generation: number;
322
+ };
323
+
324
+ /** Complete storage tuple. Backends must preserve boundaries between all three parts. @public */
325
+ export declare type ResultKey = {
326
+ step: string;
327
+ revision: number;
328
+ subjectHash: string;
329
+ };
330
+
331
+ /* Excluded from this release type: StaleWriterError */
332
+
333
+ /**
334
+ * Storage mechanism for independent rows, with linearizable subject CAS.
335
+ * All inputs and returned rows are detached snapshots: caller mutation cannot
336
+ * alter persisted data. Values may only change by inserting another generation.
337
+ * There is no transaction spanning these methods; callers must not infer atomic
338
+ * claim/generation publication from the per-row CAS guarantee.
339
+ * @public
340
+ */
341
+ export declare interface Store {
342
+ /** Return detached format metadata; opening code must reject algorithm mismatches. */
343
+ meta(): Promise<StoreMetadata>;
344
+ /** Read a detached subject snapshot, or undefined for an absent tuple. */
345
+ getSubject(key: ResultKey): Promise<SubjectRow | undefined>;
346
+ /** Insert only; duplicate tuples reject, as do versions outside safe integers. */
347
+ putSubject(row: SubjectRow): Promise<void>;
348
+ /**
349
+ * Atomically apply a shallow column patch only when the stored version matches.
350
+ * Success increments that version once, even for an empty patch; a missing or
351
+ * stale row returns false without changes. Key/version properties reject at
352
+ * runtime, including extras passed from untyped JavaScript callers.
353
+ * An exhausted MAX_SAFE_INTEGER version rejects rather than reporting success
354
+ * without advancing the token. Neither rejection changes the stored row.
355
+ */
356
+ casSubject(key: ResultKey, expectedVersion: number, patch: SubjectPatch): Promise<boolean>;
357
+ /** Read a detached generation, or undefined for an absent tuple. */
358
+ getGeneration(key: ResultKey, generation: number): Promise<GenerationRow | undefined>;
359
+ /** Return detached rows for exactly this complete key; ordering is unspecified. */
360
+ listGenerations(key: ResultKey): Promise<GenerationRow[]>;
361
+ /** Insert only; generation numbers are supplied, never allocated by storage. */
362
+ putGeneration(row: GenerationRow): Promise<void>;
363
+ /** Patch an existing row; missing tuples and attempts to change its key reject. */
364
+ updateGeneration(key: ResultKey, generation: number, patch: GenerationPatch): Promise<void>;
365
+ /**
366
+ * Insert an atomic batch of immutable fields. Duplicate addresses, within the
367
+ * batch or already stored, reject the whole batch without inserting anything.
368
+ * This proposed storage refinement enforces retained-value immutability.
369
+ */
370
+ putFields(rows: FieldRow[]): Promise<void>;
371
+ /** Return requested field snapshots; absent paths are omitted. */
372
+ getFields(key: ResultKey, generation: number, paths: Path[]): Promise<FieldRow[]>;
373
+ /** Return requested fingerprints without reading/deserializing any field value. */
374
+ getFingerprints(key: ResultKey, generation: number, paths: Path[]): Promise<Map<Path, Fingerprint>>;
375
+ /**
376
+ * Query leases strictly less than now, oldest first, with at most limit rows.
377
+ * Zero limit returns no rows. This query never sweeps or changes a claim.
378
+ */
379
+ expiredClaims(now: number, limit: number): Promise<SubjectRow[]>;
380
+ /** Release resources owned by this store. */
381
+ close(): Promise<void>;
382
+ }
383
+
384
+ /**
385
+ * Register reusable backend qualification tests for SA-1 through SA-7.
386
+ * Register this from a Jest test module; the suite imports no concrete backend.
387
+ * Mutation tests enforce rev 9's retained-value isolation at the storage seam.
388
+ * This suite does not assert atomicity across subject, generation, and field rows:
389
+ * the supplied Store contract does not provide that operation.
390
+ * @public
391
+ */
392
+ export declare function storeConformance(name: string, options: StoreConformanceOptions): void;
393
+
394
+ /**
395
+ * Opens a fresh store for each test. The optional algorithm models persisted metadata
396
+ * at open time; factories must reject a mismatch with their runtime algorithm.
397
+ * Instrumentation is optional for third-party backends, but both shipped backends
398
+ * must provide it to qualify SA-3 without relying on wall-clock timing.
399
+ * @public
400
+ */
401
+ export declare interface StoreConformanceOptions {
402
+ create(options?: {
403
+ fingerprintAlgorithm?: string;
404
+ }): Store | Promise<Store>;
405
+ fingerprintAlgorithm: string;
406
+ probeValueReads?(store: Store): ValueReadProbe;
407
+ }
408
+
409
+ /** Persisted format identifiers, checked before using a store's fingerprints. @public */
410
+ export declare interface StoreMetadata {
411
+ schemaVersion: number;
412
+ fingerprintAlgorithm: string;
413
+ }
414
+
415
+ /** Legacy row subject shape; future author-supplied subject identity is separate. @public */
416
+ export declare type Subject = Extract<Identity, {
417
+ kind: 'step';
418
+ }>;
419
+
420
+ /** Writable subject columns; the complete key and CAS token cannot be patched. @public */
421
+ export declare type SubjectPatch = Partial<Omit<SubjectRow, 'key' | 'version'>>;
422
+
423
+ /**
424
+ * One compare-and-set row per complete result key. Repository owns generation
425
+ * meaning; claim owns lease meaning. Storage only preserves and patches columns.
426
+ * @public
427
+ */
428
+ export declare interface SubjectRow {
429
+ key: ResultKey;
430
+ subject: Subject;
431
+ /** Nonnegative safe-integer CAS token, incremented once per successful CAS. */
432
+ version: number;
433
+ currentGeneration: number | null;
434
+ claim: null | {
435
+ generation: number;
436
+ holder: string;
437
+ leaseUntil: number;
438
+ progress: {
439
+ fingerprint: Fingerprint;
440
+ value: unknown;
441
+ } | null;
442
+ };
443
+ durations: number[];
444
+ }
445
+
446
+ /**
447
+ * A backend's test-only counter at its actual value-read/deserialization boundary.
448
+ * The suite resets it after insertion and verifies a positive control with getFields.
449
+ * @public
450
+ */
451
+ export declare interface ValueReadProbe {
452
+ reset(): void;
453
+ count(): number;
454
+ }
455
+
456
+ export { }