@feltdb/core 0.11.7 → 0.11.9

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 (65) hide show
  1. package/dist/cli/index.js +0 -0
  2. package/dist/composition.d.ts +697 -0
  3. package/dist/composition.d.ts.map +1 -0
  4. package/dist/composition.js +1218 -0
  5. package/dist/create/package-versions.js +1 -1
  6. package/dist/create/server-source/crates/feltdb/src/lib.rs +363 -2
  7. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +257 -0
  8. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +442 -73
  9. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +18 -4
  10. package/dist/create/server-source/crates/feltdb-server/src/backup.rs +290 -7
  11. package/dist/create/server-source/crates/feltdb-server/src/main.rs +500 -23
  12. package/dist/db.d.ts +12 -1
  13. package/dist/db.d.ts.map +1 -1
  14. package/dist/db.js +42 -3
  15. package/dist/embedded-query.d.ts.map +1 -1
  16. package/dist/embedded-query.js +20 -6
  17. package/dist/embedded-transaction.d.ts +21 -1
  18. package/dist/embedded-transaction.d.ts.map +1 -1
  19. package/dist/embedded-transaction.js +96 -0
  20. package/dist/feltdb.d.ts +8 -0
  21. package/dist/feltdb.d.ts.map +1 -1
  22. package/dist/file-db.d.ts +25 -1
  23. package/dist/file-db.d.ts.map +1 -1
  24. package/dist/file-db.js +54 -3
  25. package/dist/flowspec.d.ts +7 -0
  26. package/dist/flowspec.d.ts.map +1 -1
  27. package/dist/flowspec.js +13 -1
  28. package/dist/http-db.d.ts +7 -0
  29. package/dist/http-db.d.ts.map +1 -1
  30. package/dist/http-db.js +38 -6
  31. package/dist/index-core.d.ts +1 -0
  32. package/dist/index-core.d.ts.map +1 -1
  33. package/dist/index-core.js +1 -0
  34. package/dist/indexeddb-db.d.ts +3 -1
  35. package/dist/indexeddb-db.d.ts.map +1 -1
  36. package/dist/indexeddb-db.js +50 -2
  37. package/dist/intent.d.ts +4 -2
  38. package/dist/intent.d.ts.map +1 -1
  39. package/dist/memory-db.d.ts +2 -1
  40. package/dist/memory-db.d.ts.map +1 -1
  41. package/dist/memory-db.js +13 -1
  42. package/dist/proposal.d.ts +5 -0
  43. package/dist/proposal.d.ts.map +1 -1
  44. package/dist/proposal.js +6 -2
  45. package/dist/runtime-snapshot.d.ts +76 -2
  46. package/dist/runtime-snapshot.d.ts.map +1 -1
  47. package/dist/runtime-snapshot.js +68 -7
  48. package/dist/stable-hash.d.ts +17 -0
  49. package/dist/stable-hash.d.ts.map +1 -0
  50. package/dist/stable-hash.js +82 -0
  51. package/dist/state-impact.d.ts +245 -0
  52. package/dist/state-impact.d.ts.map +1 -0
  53. package/dist/state-impact.js +404 -0
  54. package/dist/studio-app/assets/{feltdb_wasm-D58hv7aa.js → feltdb_wasm-DGGqm9GK.js} +1 -1
  55. package/dist/studio-app/assets/feltdb_wasm_bg-BYJo87WY.wasm +0 -0
  56. package/dist/studio-app/assets/index-qLeZcPW_.js +30 -0
  57. package/dist/studio-app/index.html +1 -1
  58. package/dist/transaction.d.ts +61 -1
  59. package/dist/transaction.d.ts.map +1 -1
  60. package/dist/transaction.js +59 -0
  61. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  62. package/package.json +1 -1
  63. package/dist/create/server-source/crates/feltdb-wasm/test.db +0 -0
  64. package/dist/studio-app/assets/feltdb_wasm_bg-BgFXYOtc.wasm +0 -0
  65. package/dist/studio-app/assets/index-gR6d3Tys.js +0 -30
@@ -132,6 +132,44 @@ export interface SnapshotStaleness {
132
132
  /** Why currency could not be decided. */
133
133
  reason?: string;
134
134
  }
135
+ /**
136
+ * Which authoritative state a published snapshot represents, stated explicitly.
137
+ *
138
+ * Two snapshots with the same `id` represent the same durable state, derived
139
+ * by the same definition, under the same authority. The identity is computed
140
+ * from what the snapshot already is — its revision, definition, and authority
141
+ * — rather than stored as parallel metadata that could disagree with it.
142
+ */
143
+ export interface SnapshotIdentity {
144
+ /** `snap_` + SHA-256 over the fields below. Deterministic across handles and processes. */
145
+ id: string;
146
+ name: string;
147
+ /**
148
+ * The authoritative revision value, when the runtime has one. `null` when it
149
+ * does not, in which case `contentDigest` identifies the state instead.
150
+ */
151
+ version: number | null;
152
+ /** The revision's consistency domain, when there is a revision. */
153
+ scope?: string;
154
+ /** Publication counter of the handle. Informational; not part of `id`. */
155
+ generation: number;
156
+ /** The source collections, sorted. */
157
+ sourceSet: readonly string[];
158
+ /** SHA-256 of the definition's sources, filters, and indexes. */
159
+ definitionDigest: string;
160
+ /** The authority the materialization read under (`tenant/…`, `platform`, or `unscoped`). */
161
+ authorityContext: string;
162
+ /**
163
+ * SHA-256 of the canonical materialized records. Present only when no
164
+ * authoritative revision exists, because then the content is the only honest
165
+ * identity there is.
166
+ */
167
+ contentDigest?: string;
168
+ /** How `id` was derived. */
169
+ derivation: 'revision' | 'content';
170
+ /** When materialization completed. Reporting only; not part of `id`. */
171
+ createdAt: number;
172
+ }
135
173
  export interface SnapshotIndexDescription {
136
174
  collection: string;
137
175
  name: string;
@@ -175,6 +213,14 @@ export interface SnapshotHandleExplanation extends SnapshotExplanation {
175
213
  * claim.
176
214
  */
177
215
  durableReads: number;
216
+ /**
217
+ * `refresh()` calls answered by the fast path: the active snapshot already
218
+ * represented the current authoritative revision, so nothing was read or
219
+ * rebuilt.
220
+ */
221
+ reused: number;
222
+ /** The authority the handle materializes under. */
223
+ authorityContext: string;
178
224
  }
179
225
  export declare class SnapshotDefinitionError extends Error {
180
226
  constructor(message: string);
@@ -209,6 +255,11 @@ export interface RuntimeSnapshot<D = undefined> {
209
255
  /** Materialized records, across every source. */
210
256
  readonly records: number;
211
257
  readonly collections: readonly string[];
258
+ /**
259
+ * Which authoritative state this snapshot represents. Computed on first
260
+ * access and memoized, so the hot read path never pays for it.
261
+ */
262
+ readonly identity: SnapshotIdentity;
212
263
  get<T = Record<string, unknown>>(collection: string, id: string | number): T | undefined;
213
264
  has(collection: string, id: string | number): boolean;
214
265
  /** Every materialized record of one collection, in materialization order. Frozen. */
@@ -231,6 +282,17 @@ export interface RuntimeSnapshot<D = undefined> {
231
282
  export interface SnapshotSourceRuntime {
232
283
  /** Read every authoritative record of one collection. */
233
284
  readRecords(collection: string): Promise<Array<Record<string, unknown>>>;
285
+ /**
286
+ * Read only the authoritative records that satisfy `where`, through the
287
+ * runtime's own bounded query (and its indexes, where it has them).
288
+ *
289
+ * Optional. When present it is the bounded source-selection fast path: a
290
+ * snapshot that selects ten records of a large collection reads ten records,
291
+ * not the collection. It must return exactly the records `readRecords` would
292
+ * after filtering by the same conditions — the build re-applies the filter
293
+ * regardless, so a runtime that over-returns cannot widen a snapshot.
294
+ */
295
+ readSelected?(collection: string, where: SnapshotCondition[]): Promise<Array<Record<string, unknown>>>;
234
296
  /** What freshness validation the underlying runtime can honestly support. */
235
297
  freshness(): Promise<FreshnessCapability>;
236
298
  /** The runtime's current revision. Called only when freshness advertises one. */
@@ -254,7 +316,10 @@ export declare class RuntimeSnapshotHandle<D = undefined> {
254
316
  private durableReads;
255
317
  private lastFailure?;
256
318
  private closed;
257
- constructor(definition: SnapshotDefinition<D>, source: SnapshotSourceRuntime);
319
+ private reused;
320
+ private readonly definitionDigest;
321
+ readonly authorityContext: string;
322
+ constructor(definition: SnapshotDefinition<D>, source: SnapshotSourceRuntime, options?: RuntimeSnapshotOptions);
258
323
  get name(): string;
259
324
  /**
260
325
  * The active snapshot, or `undefined` before the first successful build.
@@ -325,7 +390,16 @@ export declare function assertSnapshotDefinition(definition: SnapshotDefinition<
325
390
  * `StateFirstDB.snapshot()` is the application-facing form; this is the same
326
391
  * primitive for runtimes and tools that hold a source of their own.
327
392
  */
328
- export declare function createRuntimeSnapshot<D = undefined>(definition: SnapshotDefinition<D>, source: SnapshotSourceRuntime): RuntimeSnapshotHandle<D>;
393
+ export declare function createRuntimeSnapshot<D = undefined>(definition: SnapshotDefinition<D>, source: SnapshotSourceRuntime, options?: RuntimeSnapshotOptions): RuntimeSnapshotHandle<D>;
394
+ export interface RuntimeSnapshotOptions {
395
+ /**
396
+ * The authority the source reads under. `db.snapshot()` supplies the
397
+ * database's own authority scope; the source it hands the handle is already
398
+ * bound to that scope, so a snapshot can never read more than its database
399
+ * could. Recorded in every snapshot's identity.
400
+ */
401
+ authorityContext?: string;
402
+ }
329
403
  /**
330
404
  * Whether two definitions describe the same snapshot.
331
405
  *
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-snapshot.d.ts","sourceRoot":"","sources":["../src/runtime-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAyC,KAAK,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,4FAA4F;AAC5F,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,CAAC;AACzD,iEAAiE;AACjE,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC;AACnF,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpF,wFAAwF;AACxF,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC5B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,oEAAoE;AACpE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAA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';
32
32
  import { conditionMatches, EmbeddedQueryEngine } from './embedded-query.js';
33
+ import { canonicalJson, sha256Hex } from './stable-hash.js';
33
34
  export class SnapshotDefinitionError extends Error {
34
35
  constructor(message) { super(message); this.name = 'SnapshotDefinitionError'; }
35
36
  }
@@ -56,17 +57,57 @@ class PublishedSnapshot {
56
57
  generation;
57
58
  basis;
58
59
  materialization;
60
+ definitionDigest;
61
+ authorityContext;
59
62
  collections;
60
63
  records;
61
- constructor(name, generation, basis, materialization) {
64
+ // Memo cell, not snapshot state: identity is a pure function of what is
65
+ // already frozen, computed once on first access.
66
+ memo = {};
67
+ constructor(name, generation, basis, materialization, definitionDigest, authorityContext) {
62
68
  this.name = name;
63
69
  this.generation = generation;
64
70
  this.basis = basis;
65
71
  this.materialization = materialization;
72
+ this.definitionDigest = definitionDigest;
73
+ this.authorityContext = authorityContext;
66
74
  this.collections = Object.freeze([...materialization.byCollection.keys()]);
67
75
  this.records = materialization.records.size;
68
76
  Object.freeze(this);
69
77
  }
78
+ get identity() {
79
+ if (this.memo.identity)
80
+ return this.memo.identity;
81
+ const sourceSet = Object.freeze([...this.collections].sort());
82
+ const revision = this.basis.validation === 'revision' ? this.basis.revision : undefined;
83
+ const contentDigest = revision ? undefined : sha256Hex(canonicalJson(sourceSet.map(collection => [
84
+ collection,
85
+ [...(this.materialization.byCollection.get(collection) ?? EMPTY)]
86
+ .map(record => canonicalJson(record))
87
+ .sort(),
88
+ ])));
89
+ const id = `snap_${sha256Hex(canonicalJson([
90
+ 'feltdb.snapshot.v1',
91
+ this.name,
92
+ this.definitionDigest,
93
+ this.authorityContext,
94
+ revision ? ['revision', revision.scope, revision.value] : ['content', contentDigest],
95
+ ]))}`;
96
+ this.memo.identity = Object.freeze({
97
+ id,
98
+ name: this.name,
99
+ version: revision ? revision.value : null,
100
+ ...(revision ? { scope: revision.scope } : {}),
101
+ generation: this.generation,
102
+ sourceSet,
103
+ definitionDigest: this.definitionDigest,
104
+ authorityContext: this.authorityContext,
105
+ ...(contentDigest ? { contentDigest } : {}),
106
+ derivation: revision ? 'revision' : 'content',
107
+ createdAt: this.basis.materializedAt,
108
+ });
109
+ return this.memo.identity;
110
+ }
70
111
  get revision() { return this.basis.revision; }
71
112
  get materializedAt() { return this.basis.materializedAt; }
72
113
  get(collection, id) {
@@ -129,10 +170,15 @@ export class RuntimeSnapshotHandle {
129
170
  durableReads = 0;
130
171
  lastFailure;
131
172
  closed = false;
132
- constructor(definition, source) {
173
+ reused = 0;
174
+ definitionDigest;
175
+ authorityContext;
176
+ constructor(definition, source, options = {}) {
133
177
  this.definition = definition;
134
178
  this.source = source;
135
179
  assertSnapshotDefinition(definition);
180
+ this.definitionDigest = sha256Hex(definitionShape(definition));
181
+ this.authorityContext = options.authorityContext ?? 'unscoped';
136
182
  }
137
183
  get name() { return this.definition.name; }
138
184
  /**
@@ -162,8 +208,10 @@ export class RuntimeSnapshotHandle {
162
208
  this.assertOpen();
163
209
  if (!options.force && this.active) {
164
210
  const staleness = await this.staleness();
165
- if (staleness.state === 'current')
211
+ if (staleness.state === 'current') {
212
+ this.reused += 1;
166
213
  return this.active;
214
+ }
167
215
  }
168
216
  return this.build();
169
217
  }
@@ -240,6 +288,8 @@ export class RuntimeSnapshotHandle {
240
288
  failures: this.failures,
241
289
  ...(this.lastFailure ? { lastFailure: this.lastFailure } : {}),
242
290
  durableReads: this.durableReads,
291
+ reused: this.reused,
292
+ authorityContext: this.authorityContext,
243
293
  };
244
294
  }
245
295
  /**
@@ -322,7 +372,9 @@ export class RuntimeSnapshotHandle {
322
372
  const indexes = [];
323
373
  for (const source of this.definition.sources) {
324
374
  this.durableReads += 1;
325
- const durable = await this.source.readRecords(source.collection);
375
+ const durable = source.where?.length && this.source.readSelected
376
+ ? await this.source.readSelected(source.collection, source.where)
377
+ : await this.source.readRecords(source.collection);
326
378
  const kept = [];
327
379
  for (const record of durable) {
328
380
  if (!record || typeof record !== 'object' || Array.isArray(record))
@@ -389,7 +441,7 @@ export class RuntimeSnapshotHandle {
389
441
  * visible.
390
442
  */
391
443
  publish(materialization, basis) {
392
- const candidate = new PublishedSnapshot(this.name, this.generation + 1, Object.freeze(basis), materialization);
444
+ const candidate = new PublishedSnapshot(this.name, this.generation + 1, Object.freeze(basis), materialization, this.definitionDigest, this.authorityContext);
393
445
  this.definition.validate?.(candidate);
394
446
  this.active = candidate;
395
447
  this.generation = candidate.generation;
@@ -455,8 +507,17 @@ export function assertSnapshotDefinition(definition) {
455
507
  * `StateFirstDB.snapshot()` is the application-facing form; this is the same
456
508
  * primitive for runtimes and tools that hold a source of their own.
457
509
  */
458
- export function createRuntimeSnapshot(definition, source) {
459
- return new RuntimeSnapshotHandle(definition, source);
510
+ export function createRuntimeSnapshot(definition, source, options = {}) {
511
+ return new RuntimeSnapshotHandle(definition, source, options);
512
+ }
513
+ /** The identity-bearing shape of a definition: sources, filters, and indexes. */
514
+ function definitionShape(definition) {
515
+ return canonicalJson({
516
+ name: definition.name,
517
+ sources: [...definition.sources]
518
+ .map(source => ({ collection: source.collection, where: source.where ?? [], indexes: source.indexes ?? [] }))
519
+ .sort((left, right) => (left.collection < right.collection ? -1 : left.collection > right.collection ? 1 : 0)),
520
+ });
460
521
  }
461
522
  /**
462
523
  * Whether two definitions describe the same snapshot.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Synchronous, dependency-free SHA-256 and canonical JSON.
3
+ *
4
+ * Snapshot identity must be computable in every runtime `@feltdb/core` ships
5
+ * to — Node, browsers, workers — and synchronously, because a published
6
+ * snapshot answers without awaiting anything. WebCrypto is asynchronous and
7
+ * `node:crypto` is not available in a browser, so this is the small portable
8
+ * implementation both need. It is used for identity, not for security.
9
+ */
10
+ /** SHA-256 of a UTF-8 string, as lowercase hex. */
11
+ export declare function sha256Hex(input: string): string;
12
+ /**
13
+ * JSON with object keys sorted at every depth, so two structurally equal
14
+ * values serialize to the same bytes regardless of insertion order.
15
+ */
16
+ export declare function canonicalJson(value: unknown): string;
17
+ //# sourceMappingURL=stable-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-hash.d.ts","sourceRoot":"","sources":["../src/stable-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA+B/C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUpD"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Synchronous, dependency-free SHA-256 and canonical JSON.
3
+ *
4
+ * Snapshot identity must be computable in every runtime `@feltdb/core` ships
5
+ * to — Node, browsers, workers — and synchronously, because a published
6
+ * snapshot answers without awaiting anything. WebCrypto is asynchronous and
7
+ * `node:crypto` is not available in a browser, so this is the small portable
8
+ * implementation both need. It is used for identity, not for security.
9
+ */
10
+ const K = new Uint32Array([
11
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
12
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
13
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
14
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
15
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
16
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
17
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
18
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
19
+ ]);
20
+ /** SHA-256 of a UTF-8 string, as lowercase hex. */
21
+ export function sha256Hex(input) {
22
+ const bytes = new TextEncoder().encode(input);
23
+ const bitLength = bytes.length * 8;
24
+ const padded = new Uint8Array(((bytes.length + 9 + 63) >> 6) << 6);
25
+ padded.set(bytes);
26
+ padded[bytes.length] = 0x80;
27
+ const view = new DataView(padded.buffer);
28
+ view.setUint32(padded.length - 8, Math.floor(bitLength / 0x100000000));
29
+ view.setUint32(padded.length - 4, bitLength >>> 0);
30
+ const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
31
+ const w = new Uint32Array(64);
32
+ for (let offset = 0; offset < padded.length; offset += 64) {
33
+ for (let i = 0; i < 16; i += 1)
34
+ w[i] = view.getUint32(offset + i * 4);
35
+ for (let i = 16; i < 64; i += 1) {
36
+ const a = w[i - 15], b = w[i - 2];
37
+ const s0 = ((a >>> 7) | (a << 25)) ^ ((a >>> 18) | (a << 14)) ^ (a >>> 3);
38
+ const s1 = ((b >>> 17) | (b << 15)) ^ ((b >>> 19) | (b << 13)) ^ (b >>> 10);
39
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
40
+ }
41
+ let [a, b, c, d, e, f, g, hh] = h;
42
+ for (let i = 0; i < 64; i += 1) {
43
+ const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
44
+ const t1 = (hh + s1 + ((e & f) ^ (~e & g)) + K[i] + w[i]) >>> 0;
45
+ const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
46
+ const t2 = (s0 + ((a & b) ^ (a & c) ^ (b & c))) >>> 0;
47
+ hh = g;
48
+ g = f;
49
+ f = e;
50
+ e = (d + t1) >>> 0;
51
+ d = c;
52
+ c = b;
53
+ b = a;
54
+ a = (t1 + t2) >>> 0;
55
+ }
56
+ h[0] += a;
57
+ h[1] += b;
58
+ h[2] += c;
59
+ h[3] += d;
60
+ h[4] += e;
61
+ h[5] += f;
62
+ h[6] += g;
63
+ h[7] += hh;
64
+ }
65
+ return Array.from(h, word => word.toString(16).padStart(8, '0')).join('');
66
+ }
67
+ /**
68
+ * JSON with object keys sorted at every depth, so two structurally equal
69
+ * values serialize to the same bytes regardless of insertion order.
70
+ */
71
+ export function canonicalJson(value) {
72
+ if (value === null || typeof value !== 'object') {
73
+ return value === undefined ? 'null' : JSON.stringify(value);
74
+ }
75
+ if (Array.isArray(value))
76
+ return `[${value.map(canonicalJson).join(',')}]`;
77
+ const entries = Object.keys(value)
78
+ .filter(key => value[key] !== undefined)
79
+ .sort()
80
+ .map(key => `${JSON.stringify(key)}:${canonicalJson(value[key])}`);
81
+ return `{${entries.join(',')}}`;
82
+ }
@@ -0,0 +1,245 @@
1
+ /** Collections the composition substrate writes. Never contract state. */
2
+ export declare const FELTDB_COMPOSITION_CONTRACT_COLLECTION = "_feltdb.CompositionContract";
3
+ export declare const FELTDB_COMPOSITION_COLLECTION = "_feltdb.Composition";
4
+ export declare const FELTDB_COMPOSITION_VERSION_COLLECTION = "_feltdb.CompositionVersion";
5
+ export declare const FELTDB_COMPOSITION_TOPOLOGY_COLLECTION = "_feltdb.CompositionTopology";
6
+ export declare const FELTDB_STATE_OWNERSHIP_COLLECTION = "_feltdb.StateOwnership";
7
+ export declare const FELTDB_STATE_DEPENDENCY_COLLECTION = "_feltdb.StateDependency";
8
+ export declare const FELTDB_STATE_CHANGE_COLLECTION = "_feltdb.StateChange";
9
+ export declare const FELTDB_STATE_ATTRIBUTION_COLLECTION = "_feltdb.StateAttribution";
10
+ export declare const FELTDB_STATE_OBSERVATION_COLLECTION = "_feltdb.StateObservation";
11
+ export declare const FELTDB_STATE_PROPOSAL_COLLECTION = "_feltdb.StateProposal";
12
+ export declare const FELTDB_STATE_IMPACT_COLLECTION = "_feltdb.StateImpact";
13
+ /** Upper bound on `connects` hops followed from a directly changed record. */
14
+ export declare const IMPACT_MAX_DEPTH = 4;
15
+ /** Upper bound on items in any one section of a surface. */
16
+ export declare const IMPACT_MAX_ITEMS = 1000;
17
+ /**
18
+ * The identity of an authoritative `.flow` contract.
19
+ *
20
+ * State is addressed by contract, collection, and record — never by the
21
+ * application that happens to be looking at it — so the same record has the
22
+ * same identity for every consumer.
23
+ */
24
+ export interface AuthoritativeContractIdentity {
25
+ contract_id: string;
26
+ /** Digest of the whole compiled contract (`CanonicalApplicationContract.hashes.application`). */
27
+ contract_digest: string;
28
+ /** Digest of collections, indexes, and references (`hashes.model`). */
29
+ model_digest: string;
30
+ collections: string[];
31
+ capabilities: string[];
32
+ /** Declared field types, by collection. */
33
+ fields: Record<string, Array<{
34
+ name: string;
35
+ type: string;
36
+ reference?: string;
37
+ }>>;
38
+ /** Declared workflows and the capabilities their steps name. */
39
+ workflows: Array<{
40
+ name: string;
41
+ capabilities: string[];
42
+ }>;
43
+ /** Declared triggers: an event that starts a workflow. `workflow` is `''` when the trigger names none. */
44
+ triggers: Array<{
45
+ name: string;
46
+ event: string;
47
+ workflow: string;
48
+ }>;
49
+ }
50
+ /** Address of authoritative state. `record` absent means the whole collection. */
51
+ export interface StateRef {
52
+ contract: string;
53
+ collection: string;
54
+ record?: string;
55
+ }
56
+ export declare function stateUri(ref: StateRef): string;
57
+ export declare function parseStateUri(uri: string): StateRef;
58
+ export declare const consumerUri: (contract: string, consumer: string) => string;
59
+ export declare const capabilityUri: (contract: string, capability: string) => string;
60
+ export declare const projectionUri: (contract: string, consumer: string, name: string) => string;
61
+ export declare const workflowUri: (contract: string, workflow: string) => string;
62
+ /** `sha256:` over FeltDB's canonical encoding. */
63
+ export declare function canonicalDigest(value: unknown): Promise<string>;
64
+ /** Record fields the storage boundary owns. They are not part of a value. */
65
+ export declare function recordValue(row: Record<string, unknown> | null | undefined): Record<string, unknown> | null;
66
+ export declare function recordVersion(row: Record<string, unknown> | null | undefined): number | null;
67
+ export declare function changedFields(before: Record<string, unknown> | null, after: Record<string, unknown> | null): string[];
68
+ export type CompositionAccessMode = 'observe' | 'mutate' | 'own';
69
+ export interface CompositionAccess {
70
+ collection: string;
71
+ mode: CompositionAccessMode;
72
+ capability: string;
73
+ }
74
+ export interface CompositionProjection {
75
+ name: string;
76
+ sources: string[];
77
+ }
78
+ /** The part of a composition declaration the impact surface depends on. */
79
+ export interface CompositionTopologyEntry {
80
+ consumer: string;
81
+ version: number;
82
+ status: 'active';
83
+ access: CompositionAccess[];
84
+ projections: CompositionProjection[];
85
+ }
86
+ /** An explicit, consumer-declared connection between two records. */
87
+ export interface StateDependencyEdge {
88
+ edge_id: string;
89
+ from: string;
90
+ to: string;
91
+ relationship: 'connects';
92
+ declared_by: string;
93
+ label?: string;
94
+ evidence: string[];
95
+ }
96
+ export type ProposedOperation = {
97
+ collection: string;
98
+ id: string;
99
+ value: Record<string, unknown>;
100
+ } | {
101
+ collection: string;
102
+ id: string;
103
+ delete: true;
104
+ };
105
+ /** Why an item is in the surface. Every item carries one. */
106
+ export interface ImpactProvenance {
107
+ basis: 'proposal' | 'declared_dependency' | 'composition_declaration' | 'contract_reference' | 'contract_trigger' | 'contract_model';
108
+ /** The durable thing the item was derived from, as `scheme:reference`. */
109
+ source: string;
110
+ evidence: string[];
111
+ }
112
+ export interface DirectImpact {
113
+ node: string;
114
+ collection: string;
115
+ record_id: string;
116
+ operation: 'insert' | 'update' | 'delete';
117
+ base_version: number | null;
118
+ proposed_version: number | null;
119
+ base_value_digest: string | null;
120
+ proposed_value_digest: string | null;
121
+ fields_changed: string[];
122
+ provenance: ImpactProvenance;
123
+ }
124
+ export interface DependentImpact {
125
+ node: string;
126
+ kind: 'state' | 'consumer' | 'projection' | 'workflow';
127
+ /** The structural relationship, never an interpretation of it. */
128
+ relationship: string;
129
+ /** The node this one was reached from. */
130
+ from: string;
131
+ /** `connects` hops from the nearest directly changed record. */
132
+ depth: number;
133
+ capability?: string;
134
+ declared_by?: string;
135
+ label?: string;
136
+ /** For a workflow: the trigger and event that make it reachable, and the capabilities its steps name. */
137
+ trigger?: string;
138
+ event?: string;
139
+ capabilities?: string[];
140
+ provenance: ImpactProvenance;
141
+ }
142
+ export interface DerivedImpact {
143
+ node: string;
144
+ consequence: 'record_version_advances' | 'record_removed' | 'record_created' | 'reference_retargeted' | 'reference_target_absent' | 'reference_to_removed_record' | 'projection_source_changes';
145
+ field?: string;
146
+ before?: unknown;
147
+ after?: unknown;
148
+ provenance: ImpactProvenance;
149
+ }
150
+ export interface UnknownImpact {
151
+ kind: 'unregistered_consumers' | 'opaque_field' | 'workflow_effects' | 'unattributed_history' | 'traversal_bound' | 'external_reference' | 'unresolved_workflow' | 'unrecognized_trigger_event' | 'external_trigger_events' | 'not_authorized_to_inspect';
152
+ node?: string;
153
+ event?: string;
154
+ collection?: string;
155
+ field?: string;
156
+ count?: number;
157
+ /** Why this cannot be established from the authoritative model. */
158
+ reason: string;
159
+ }
160
+ export interface ImpactSurface {
161
+ direct: DirectImpact[];
162
+ dependent: DependentImpact[];
163
+ derived: DerivedImpact[];
164
+ /**
165
+ * Never empty. FeltDB cannot enumerate consumers that never declared a
166
+ * composition, so the surface is always open, and says so.
167
+ */
168
+ unknown: UnknownImpact[];
169
+ }
170
+ /** Read access to the materialized basis. Satisfied by `RuntimeSnapshot`. */
171
+ export interface ImpactBasis {
172
+ get<T = Record<string, unknown>>(collection: string, id: string | number): T | undefined;
173
+ all<T = Record<string, unknown>>(collection: string): readonly T[];
174
+ readonly collections: readonly string[];
175
+ }
176
+ /**
177
+ * What a surface computation read, as a transaction read set.
178
+ *
179
+ * `records` are point reads; `predicates` are equality reads ("every record of
180
+ * `collection` whose fields equal these values"). The surface is a function of
181
+ * exactly these reads, so a transaction fenced on them (`db.readBasis()` +
182
+ * `tx.fence()`) cannot commit against a state in which the surface differs.
183
+ */
184
+ export interface ImpactReads {
185
+ records: Map<string, {
186
+ collection: string;
187
+ id: string;
188
+ }>;
189
+ predicates: Map<string, {
190
+ collection: string;
191
+ where: Array<{
192
+ field: string;
193
+ eq: unknown;
194
+ }>;
195
+ }>;
196
+ }
197
+ export declare function emptyImpactReads(): ImpactReads;
198
+ /** The reads as a `TransactionReadSet`. */
199
+ export declare function impactReadSet(reads: ImpactReads): {
200
+ records: Array<{
201
+ collection: string;
202
+ id: string;
203
+ }>;
204
+ predicates: Array<{
205
+ collection: string;
206
+ where: Array<{
207
+ field: string;
208
+ eq: unknown;
209
+ }>;
210
+ }>;
211
+ };
212
+ export interface ImpactInput {
213
+ contract: AuthoritativeContractIdentity;
214
+ tenantId: string;
215
+ basis: ImpactBasis;
216
+ operations: readonly ProposedOperation[];
217
+ maxDepth?: number;
218
+ /** Filled with what the computation read. Does not affect the surface. */
219
+ reads?: ImpactReads;
220
+ }
221
+ /** The transition events a contract trigger can name for a collection. */
222
+ export declare const TRANSITION_EVENTS: {
223
+ readonly insert: "created";
224
+ readonly update: "updated";
225
+ readonly delete: "deleted";
226
+ };
227
+ /**
228
+ * Compute the impact surface of `operations` against `basis`.
229
+ *
230
+ * Pure and deterministic. The output is sorted so that its canonical digest is
231
+ * a function of the snapshot and the operations alone.
232
+ */
233
+ export declare function computeImpactSurface(input: ImpactInput): Promise<ImpactSurface>;
234
+ /** Canonical digest of a surface, for comparing an analysis with a re-derivation. */
235
+ export declare function impactSurfaceDigest(surface: ImpactSurface): Promise<string>;
236
+ /**
237
+ * The part of a surface a reader may see.
238
+ *
239
+ * The surface is computed by the authority over all state, so that its digest
240
+ * does not depend on who asked. A reader sees state nodes only in collections
241
+ * it may read; everything withheld is counted under `unknown` rather than
242
+ * silently dropped, because "you may not see it" is not "it is not there".
243
+ */
244
+ export declare function redactImpactSurface(surface: ImpactSurface, readable: (collection: string) => boolean): ImpactSurface;
245
+ //# sourceMappingURL=state-impact.d.ts.map
@@ -0,0 +1 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