@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
package/dist/cli/index.js CHANGED
File without changes
@@ -0,0 +1,697 @@
1
+ /**
2
+ * Authoritative composition: several applications over one `.flow`.
3
+ *
4
+ * authoritative .flow (contract identity + digest)
5
+ * │
6
+ * FeltDB ── the only authority for state
7
+ * │
8
+ * ┌───────────────────┼───────────────────┐
9
+ * consumer A consumer B consumer C
10
+ * (declared access, capabilities, projections, connections)
11
+ *
12
+ * A consumer is an application, service, or agent that composes over the
13
+ * contract. It declares which collections it observes, mutates, or owns, and
14
+ * through which capability; FeltDB records that declaration durably and uses
15
+ * it as a ceiling. The authorization gate remains the authority for every
16
+ * individual operation, and it fails closed.
17
+ *
18
+ * Nothing here stores a copy of application state. Records stay in their
19
+ * contract collections. The substrate writes only `_feltdb.*` attribution,
20
+ * declaration, topology, observation, proposal, and impact records, and it
21
+ * writes them in the same atomic transaction as the state they describe.
22
+ *
23
+ * State-level proposals ("understand before mutate"):
24
+ *
25
+ * intent (`_feltdb.Intent`, action=transition, target=state)
26
+ * → proposal (`_feltdb.StateProposal`, bound to base snapshot N)
27
+ * → impact (`_feltdb.StateImpact`, computed from snapshot N) ─ one transaction
28
+ * → preview / review (`_feltdb.ProposalEvent`, the shared lifecycle)
29
+ * → apply: CAS on base versions + topology fence + re-derived impact ─ one transaction
30
+ *
31
+ * FeltDB supplies facts, topology, authority, and provenance. What a change
32
+ * means is decided by the consumer, agent, or person reading them.
33
+ */
34
+ import type { CanonicalApplicationContract } from './canonical-application.js';
35
+ import type { AuthorizationDecision, AuthorizationRequest, AuthorizationSubject } from './authorization.js';
36
+ import type { AuthorityQueryPage, AuthorityQueryRequest } from './http-db.js';
37
+ import type { AtomicTransactionOptions, AtomicTransactionResult, AtomicTransactionScope, TransactionReadBasis, TransactionReadSet } from './transaction.js';
38
+ import type { RuntimeSnapshotHandle, SnapshotDefinition, SnapshotIdentity, SnapshotBasis } from './runtime-snapshot.js';
39
+ import type { IntentEvent, IntentStatus } from './intent.js';
40
+ import type { FeltDBProposalEvent, ProposalStatus } from './proposal.js';
41
+ import { type AuthoritativeContractIdentity, type CompositionAccess, type CompositionAccessMode, type CompositionProjection, type ImpactSurface, type ProposedOperation, type StateDependencyEdge, type StateRef } from './state-impact.js';
42
+ export * from './state-impact.js';
43
+ export declare const COMPOSITION_CONTRACT_VERSION = 1;
44
+ export declare const COMPOSITION_MAX_LIMIT = 1000;
45
+ /** Substrate capabilities, checked through the authorization gate. */
46
+ export declare const COMPOSITION_CAPABILITIES: {
47
+ /** Record or re-record the authoritative contract identity. */
48
+ readonly bind: "composition:bind";
49
+ /** Admit a consumer's composition declaration. */
50
+ readonly declare: "composition:declare";
51
+ /** Act as a declared consumer. */
52
+ readonly act: "composition:act";
53
+ /** Approve or reject a state proposal. */
54
+ readonly review: "composition:review";
55
+ };
56
+ /** Every operation a consumer may be authorized for on one collection. */
57
+ export declare const COMPOSITION_OPERATIONS: readonly ["read", "observe", "write", "delete"];
58
+ export type CompositionOperation = typeof COMPOSITION_OPERATIONS[number];
59
+ /**
60
+ * The state-proposal operations, as a transport would expose them.
61
+ *
62
+ * This is the programmatic contract a service layer maps to its routes: one
63
+ * operation, one call, JSON in and JSON out. The subject is always the
64
+ * authenticated caller bound to the handle — never a request field — and the
65
+ * gate is always the deployment's authorization boundary.
66
+ */
67
+ export declare const STATE_PROPOSAL_OPERATIONS: readonly [{
68
+ readonly operation: "intend";
69
+ readonly on: "consumer";
70
+ readonly method: "intend";
71
+ readonly authorization: readonly ["composition:act", "read on every proposed record"];
72
+ readonly writes: readonly ["_feltdb.Intent", "_feltdb.IntentEvent", "_feltdb.StateProposal", "_feltdb.StateImpact", "_feltdb.ProposalEvent"];
73
+ }, {
74
+ readonly operation: "preview";
75
+ readonly on: "consumer";
76
+ readonly method: "preview";
77
+ readonly authorization: readonly ["composition:act", "read on every proposed record"];
78
+ readonly writes: readonly [];
79
+ }, {
80
+ readonly operation: "history";
81
+ readonly on: "consumer";
82
+ readonly method: "history";
83
+ readonly authorization: readonly ["composition:act", "read on every proposed record"];
84
+ readonly writes: readonly [];
85
+ }, {
86
+ readonly operation: "inspect";
87
+ readonly on: "review";
88
+ readonly method: "inspect";
89
+ readonly authorization: readonly ["composition:review"];
90
+ readonly writes: readonly [];
91
+ }, {
92
+ readonly operation: "approve";
93
+ readonly on: "review";
94
+ readonly method: "approve";
95
+ readonly authorization: readonly ["composition:review"];
96
+ readonly writes: readonly ["_feltdb.StateProposal", "_feltdb.ProposalEvent"];
97
+ }, {
98
+ readonly operation: "reject";
99
+ readonly on: "review";
100
+ readonly method: "reject";
101
+ readonly authorization: readonly ["composition:review"];
102
+ readonly writes: readonly ["_feltdb.StateProposal", "_feltdb.ProposalEvent"];
103
+ }, {
104
+ readonly operation: "rebase";
105
+ readonly on: "consumer";
106
+ readonly method: "rebase";
107
+ readonly authorization: readonly ["composition:act", "read on every proposed record"];
108
+ readonly writes: readonly ["_feltdb.StateProposal", "_feltdb.StateImpact", "_feltdb.ProposalEvent", "_feltdb.Intent", "_feltdb.IntentEvent"];
109
+ }, {
110
+ readonly operation: "apply";
111
+ readonly on: "consumer";
112
+ readonly method: "apply";
113
+ readonly authorization: readonly ["composition:act", "write (or delete, as owner) on every proposed record"];
114
+ readonly writes: readonly ["contract collections", "_feltdb.StateChange", "_feltdb.StateAttribution", "_feltdb.StateProposal", "_feltdb.ProposalEvent", "_feltdb.Intent", "_feltdb.IntentEvent"];
115
+ }];
116
+ /** Identity of a compiled contract. The digest is the contract's own hash, not a new one. */
117
+ export declare function contractIdentity(contract: CanonicalApplicationContract): AuthoritativeContractIdentity;
118
+ export interface CompositionProvenance {
119
+ subject: AuthorizationSubject;
120
+ tenant_id: string;
121
+ contract_id: string;
122
+ source: string;
123
+ recorded_at: string;
124
+ authorization_decision_ids: string[];
125
+ }
126
+ export interface CompositionDeclarationInput {
127
+ consumer: string;
128
+ access: CompositionAccess[];
129
+ projections?: CompositionProjection[];
130
+ }
131
+ export interface Composition {
132
+ consumer: string;
133
+ uri: string;
134
+ tenant_id: string;
135
+ contract_id: string;
136
+ contract_digest: string;
137
+ version: number;
138
+ digest: string;
139
+ status: 'active';
140
+ access: CompositionAccess[];
141
+ projections: CompositionProjection[];
142
+ /** The capabilities this composition names. Derived from `access`. */
143
+ requires: string[];
144
+ declared_at: string;
145
+ provenance: CompositionProvenance;
146
+ }
147
+ export interface StateRecord<T = Record<string, unknown>> {
148
+ uri: string;
149
+ ref: StateRef;
150
+ exists: boolean;
151
+ version: number | null;
152
+ value: T | null;
153
+ }
154
+ /** Durable attribution of one committed change. Carries no value: it cannot replay state. */
155
+ export interface StateChange {
156
+ change_id: string;
157
+ tenant_id: string;
158
+ contract_id: string;
159
+ contract_digest: string;
160
+ subject: string;
161
+ collection: string;
162
+ record_id: string;
163
+ operation: 'insert' | 'update' | 'delete';
164
+ version_before: number | null;
165
+ version_after: number | null;
166
+ value_digest_before: string | null;
167
+ value_digest_after: string | null;
168
+ fields_changed: string[];
169
+ /** Version of the subject's attribution head this change produced. Authority-assigned. */
170
+ attribution_version: number;
171
+ transaction_id: string;
172
+ consumer: string;
173
+ capability: string;
174
+ causal_id?: string;
175
+ intent_id?: string;
176
+ proposal_id?: string;
177
+ impact_id?: string;
178
+ recorded_at: string;
179
+ provenance: CompositionProvenance;
180
+ }
181
+ export interface StateObservation {
182
+ observation_id: string;
183
+ tenant_id: string;
184
+ contract_id: string;
185
+ subject: string;
186
+ change_id?: string;
187
+ consumer: string;
188
+ observed_at: string;
189
+ recorded_at: string;
190
+ evidence: string[];
191
+ context: {
192
+ causal_id?: string;
193
+ parent_observation_id?: string;
194
+ correlation_id?: string;
195
+ };
196
+ provenance: CompositionProvenance;
197
+ }
198
+ export interface StateProposalOperation {
199
+ collection: string;
200
+ record_id: string;
201
+ subject: string;
202
+ operation: 'set' | 'delete';
203
+ value?: Record<string, unknown>;
204
+ base_version: number | null;
205
+ base_value_digest: string | null;
206
+ }
207
+ export interface StateSnapshotBinding {
208
+ id: string;
209
+ version: number | null;
210
+ scope?: string;
211
+ coherence: SnapshotBasis['coherence'];
212
+ derivation: SnapshotIdentity['derivation'];
213
+ /** Version of the contract's topology head in the snapshot; fences declarations and connections. */
214
+ topology_version: number | null;
215
+ }
216
+ /** A proposed state transition. Never authoritative until applied. */
217
+ export interface StateProposal {
218
+ proposal_id: string;
219
+ intent_id: string;
220
+ tenant_id: string;
221
+ contract_id: string;
222
+ contract_digest: string;
223
+ status: ProposalStatus;
224
+ proposed_by: string;
225
+ summary: string;
226
+ operations: StateProposalOperation[];
227
+ proposal_digest: string;
228
+ base_snapshot: StateSnapshotBinding;
229
+ impact_id: string;
230
+ impact_digest: string;
231
+ parent_proposal_id?: string;
232
+ superseded_by?: string;
233
+ approval?: {
234
+ impact_id: string;
235
+ impact_digest: string;
236
+ approved_by: AuthorizationSubject;
237
+ decision_id: string;
238
+ approved_at: string;
239
+ note?: string;
240
+ };
241
+ rejection?: {
242
+ rejected_by: AuthorizationSubject;
243
+ decision_id?: string;
244
+ rejected_at: string;
245
+ reason: string;
246
+ };
247
+ applied?: {
248
+ transaction_id: string;
249
+ change_ids: string[];
250
+ applied_by: string;
251
+ applied_at: string;
252
+ apply_snapshot: StateSnapshotBinding;
253
+ };
254
+ authoritative: false;
255
+ created_at: string;
256
+ provenance: CompositionProvenance;
257
+ }
258
+ /** The impact surface of one proposal against its base snapshot. Written with the proposal. */
259
+ export interface StateImpact {
260
+ impact_id: string;
261
+ proposal_id: string;
262
+ proposal_digest: string;
263
+ tenant_id: string;
264
+ contract_id: string;
265
+ contract_digest: string;
266
+ base_snapshot: StateSnapshotBinding;
267
+ surface: ImpactSurface;
268
+ surface_digest: string;
269
+ /**
270
+ * What the authority held, at the base snapshot, for exactly the state the
271
+ * surface was computed from. `apply` commits fenced by it: if any of that
272
+ * state has changed since — through any write path — the commit is refused.
273
+ */
274
+ read_basis: TransactionReadBasis;
275
+ computed_by: string;
276
+ computed_at: string;
277
+ /** An impact grants nothing: it describes, it never authorizes. */
278
+ grants_authority: false;
279
+ authoritative: false;
280
+ provenance: CompositionProvenance;
281
+ }
282
+ export type StateProposalBlocker = 'basis_changed' | 'contract_changed' | 'direct_state_changed' | 'impact_changed' | 'not_current_status';
283
+ export interface StateProposalReadiness {
284
+ proposal_id: string;
285
+ status: ProposalStatus;
286
+ readiness: 'ready' | 'blocked';
287
+ blockers: StateProposalBlocker[];
288
+ /** True when the recorded impact no longer describes current authoritative state. */
289
+ stale: boolean;
290
+ base_snapshot: StateSnapshotBinding;
291
+ current_snapshot: StateSnapshotBinding;
292
+ /** The base snapshot is no longer the current one. Informational: unrelated writes do not block. */
293
+ basis_advanced: boolean;
294
+ /**
295
+ * Some declaration or connection in the contract changed since the base.
296
+ * Informational: only changes to the ones the impact read block, through
297
+ * `basis_changed` and `impact_changed`.
298
+ */
299
+ topology_advanced: boolean;
300
+ changed_subjects: string[];
301
+ current_impact_digest: string;
302
+ }
303
+ /** What a reader gets when it asks "what would change if this were applied?". */
304
+ export interface StateProposalPreview {
305
+ proposal: StateProposal;
306
+ /**
307
+ * The impact, redacted to the reader. The read basis is withheld: it names
308
+ * every record the surface read, including ones this reader may not see, and
309
+ * it is the authority's fence, not the reader's information.
310
+ */
311
+ impact: Omit<StateImpact, 'surface' | 'read_basis'> & {
312
+ surface: ImpactSurface;
313
+ fenced: boolean;
314
+ };
315
+ readiness: StateProposalReadiness;
316
+ /** Evaluated for this reader, now. Not part of the durable impact. */
317
+ authorization: Array<{
318
+ node: string;
319
+ capability?: string;
320
+ operations: Record<'write' | 'delete', boolean>;
321
+ }>;
322
+ /** Nothing in this preview is authoritative state; only `apply` changes state. */
323
+ effect: {
324
+ authoritative: false;
325
+ state_changes_on: 'apply';
326
+ };
327
+ }
328
+ export interface CompositionAuthorizationGate {
329
+ check(request: AuthorizationRequest): Promise<AuthorizationDecision>;
330
+ }
331
+ /** The part of a FeltDB instance composition needs. Satisfied by `StateFirstDB`. */
332
+ export interface CompositionDatabase {
333
+ collection<T>(name: string): {
334
+ get(id: string | number): Promise<T | null>;
335
+ };
336
+ query<T = Record<string, unknown>>(request: AuthorityQueryRequest): Promise<AuthorityQueryPage<T>>;
337
+ transaction(build: (tx: AtomicTransactionScope) => void | Promise<void>, options?: AtomicTransactionOptions): Promise<AtomicTransactionResult>;
338
+ snapshot<D = undefined>(definition: SnapshotDefinition<D>): RuntimeSnapshotHandle<D>;
339
+ readBasis(reads: TransactionReadSet): Promise<TransactionReadBasis>;
340
+ }
341
+ export interface AuthoritativeCompositionOptions {
342
+ contract: CanonicalApplicationContract;
343
+ tenantId: string;
344
+ /** Who acts through this handle. Every write is attributed to it. */
345
+ subject: AuthorizationSubject;
346
+ /** FeltDB's authorization boundary. Required: composition fails closed. */
347
+ authorization: CompositionAuthorizationGate;
348
+ /** What produced writes through this handle, e.g. an application name. */
349
+ source: string;
350
+ environment?: string;
351
+ /** Explicitly record a different contract digest as authoritative. */
352
+ rebind?: boolean;
353
+ now?: () => Date;
354
+ }
355
+ /**
356
+ * Bind to the authoritative contract and return a composition handle.
357
+ *
358
+ * The first bind records the contract identity. A later bind with a different
359
+ * digest is refused unless `rebind` is explicit and authorized, so an
360
+ * application holding an old contract cannot quietly redefine the authority.
361
+ */
362
+ export declare function openAuthoritativeComposition(db: CompositionDatabase, options: AuthoritativeCompositionOptions): Promise<AuthoritativeComposition>;
363
+ export declare class AuthoritativeComposition {
364
+ private readonly db;
365
+ readonly contract: AuthoritativeContractIdentity;
366
+ readonly tenantId: string;
367
+ readonly subject: AuthorizationSubject;
368
+ readonly environment: string;
369
+ private readonly gate;
370
+ private readonly source;
371
+ private readonly clock;
372
+ private readonly flowHash;
373
+ constructor(db: CompositionDatabase, options: AuthoritativeCompositionOptions);
374
+ private resource;
375
+ now(): string;
376
+ private normalizeDeclaration;
377
+ readonly compositions: {
378
+ /**
379
+ * Admit a consumer's composition, or a new version of it.
380
+ *
381
+ * Declaration, version history, exclusive ownership claims, and the
382
+ * topology head commit in one transaction. Ownership is exclusive: a
383
+ * collection owned by another consumer refuses the whole declaration.
384
+ */
385
+ declare: (input: CompositionDeclarationInput) => Promise<Composition>;
386
+ get: (consumer: string) => Promise<Composition>;
387
+ /** Page declared compositions over this contract. */
388
+ list: (input?: {
389
+ limit?: number;
390
+ cursor?: string;
391
+ }) => Promise<{
392
+ exhausted: boolean;
393
+ nextCursor?: string | undefined;
394
+ items: Composition[];
395
+ }>;
396
+ };
397
+ /** Act as a declared consumer. The subject must be authorized to act as it. */
398
+ consumer(consumer: string): Promise<CompositionConsumer>;
399
+ readonly review: {
400
+ /**
401
+ * Approve a previewed proposal whose impact is still current.
402
+ *
403
+ * Approval binds to the exact impact record and digest. It grants nothing:
404
+ * `apply` still authorizes every write for the consumer that applies.
405
+ */
406
+ approve: (proposalId: string, input?: {
407
+ note?: string;
408
+ }) => Promise<StateProposal>;
409
+ reject: (proposalId: string, reason: string) => Promise<StateProposal>;
410
+ /** The full, unredacted proposal and impact, for an authorized reviewer. */
411
+ inspect: (proposalId: string) => Promise<{
412
+ proposal: StateProposal;
413
+ impact: StateImpact;
414
+ readiness: StateProposalReadiness;
415
+ }>;
416
+ };
417
+ }
418
+ export interface StateMutationBuilder {
419
+ set(collection: string, id: string, value: Record<string, unknown>): void;
420
+ delete(collection: string, id: string): void;
421
+ }
422
+ /**
423
+ * One application, service, or agent composing over the contract.
424
+ *
425
+ * Every operation checks the declaration (the ceiling) and then asks the gate
426
+ * (the authority). Reading does not imply writing, writing does not imply
427
+ * deleting, and referencing or observing implies neither.
428
+ */
429
+ export declare class CompositionConsumer {
430
+ private readonly service;
431
+ private readonly db;
432
+ readonly composition: Composition;
433
+ constructor(service: AuthoritativeComposition, db: CompositionDatabase, composition: Composition);
434
+ get id(): string;
435
+ private get contractId();
436
+ private ref;
437
+ /** Refuse to act on a declaration that has been superseded since this handle was opened. */
438
+ private current;
439
+ private entry;
440
+ /** Declaration ceiling, then the gate. Returns the capability and the decision id. */
441
+ private access;
442
+ /** What this consumer is authorized to do, per declared collection, evaluated now. */
443
+ authorizedOperations(): Promise<Array<{
444
+ collection: string;
445
+ uri: string;
446
+ mode: CompositionAccessMode;
447
+ capability: string;
448
+ operations: Record<CompositionOperation, boolean>;
449
+ }>>;
450
+ private readable;
451
+ read<T = Record<string, unknown>>(collection: string, id: string): Promise<StateRecord<T>>;
452
+ query<T = Record<string, unknown>>(request: AuthorityQueryRequest): Promise<{
453
+ exhausted: boolean;
454
+ nextCursor?: string | undefined;
455
+ items: {
456
+ uri: string;
457
+ ref: StateRef;
458
+ exists: true;
459
+ version: number | null;
460
+ value: T;
461
+ }[];
462
+ }>;
463
+ /**
464
+ * Stage attributed writes. A write to a collection this consumer only
465
+ * observes, or a delete of a collection it does not own, is refused before
466
+ * anything commits; so is anything the gate denies.
467
+ */
468
+ mutate(build: (tx: StateMutationBuilder) => void, options?: {
469
+ causalId?: string;
470
+ transactionId?: string;
471
+ }): Promise<{
472
+ transaction: AtomicTransactionResult;
473
+ changes: StateChange[];
474
+ }>;
475
+ private commit;
476
+ /** Attributed changes to one collection (optionally one record), oldest first per record. */
477
+ changes(input: {
478
+ collection: string;
479
+ record?: string;
480
+ limit?: number;
481
+ cursor?: string;
482
+ }): Promise<{
483
+ exhausted: boolean;
484
+ nextCursor?: string | undefined;
485
+ items: StateChange[];
486
+ }>;
487
+ private changeById;
488
+ /**
489
+ * Record that this consumer observed a subject, optionally a specific change.
490
+ *
491
+ * The schema is closed: there is no field for what the observation means.
492
+ */
493
+ observe(input: {
494
+ subject: string;
495
+ change?: string;
496
+ evidence?: string[];
497
+ context?: StateObservation['context'];
498
+ observedAt?: string;
499
+ observationId?: string;
500
+ }): Promise<StateObservation>;
501
+ observations(input: {
502
+ subject: string;
503
+ limit?: number;
504
+ cursor?: string;
505
+ }): Promise<{
506
+ exhausted: boolean;
507
+ nextCursor?: string | undefined;
508
+ items: StateObservation[];
509
+ }>;
510
+ /**
511
+ * Declare that a change to `from` may matter to each `to` record.
512
+ *
513
+ * A connection is a fact this consumer asserts, with evidence; FeltDB keeps
514
+ * it, attributes it, and follows it during impact traversal. The consumer
515
+ * must be able to read both ends; connecting grants nothing on either.
516
+ */
517
+ connect(input: {
518
+ from: string;
519
+ to: string[];
520
+ evidence: string[];
521
+ label?: string;
522
+ }): Promise<StateDependencyEdge[]>;
523
+ /**
524
+ * Materialize one of this consumer's declared projections.
525
+ *
526
+ * A projection is a runtime snapshot of authoritative state: frozen, with no
527
+ * write surface, and reporting its staleness. It never becomes authority.
528
+ */
529
+ projection(name: string): Promise<Readonly<{
530
+ uri: `projection://${string}/${string}/${string}`;
531
+ authoritative: false;
532
+ derived_from: string[];
533
+ identity: SnapshotIdentity;
534
+ get: <T = Record<string, unknown>>(collection: string, id: string) => T | undefined;
535
+ all: <T = Record<string, unknown>>(collection: string) => readonly T[];
536
+ staleness: () => Promise<import("./runtime-snapshot.js").SnapshotStaleness>;
537
+ }>>;
538
+ /**
539
+ * A consistent, authorized view of the collections this consumer reads,
540
+ * with the attribution boundary: a change is inside the view exactly when
541
+ * the view's attribution head for its subject has reached it.
542
+ */
543
+ snapshot(input: {
544
+ collections: string[];
545
+ }): Promise<Readonly<{
546
+ contract: AuthoritativeContractIdentity;
547
+ consumer: string;
548
+ composition_version: number;
549
+ authorization: {
550
+ subject: AuthorizationSubject;
551
+ entries: {
552
+ collection: string;
553
+ capability: string;
554
+ decision_id: string;
555
+ }[];
556
+ };
557
+ identity: SnapshotIdentity;
558
+ coherence: "proven" | "unproven";
559
+ authoritative: false;
560
+ get: <T = Record<string, unknown>>(collection: string, id: string) => StateRecord<T>;
561
+ includes: (change: StateChange) => boolean;
562
+ }>>;
563
+ /** Everything this consumer may learn about the composed contract, for an agent or a person. */
564
+ describe(): Promise<{
565
+ contract: AuthoritativeContractIdentity;
566
+ self: Composition;
567
+ compositions: {
568
+ consumer: string;
569
+ uri: string;
570
+ version: number;
571
+ access: CompositionAccess[];
572
+ projections: CompositionProjection[];
573
+ }[];
574
+ compositions_exhausted: boolean;
575
+ authorized_operations: {
576
+ collection: string;
577
+ uri: string;
578
+ mode: CompositionAccessMode;
579
+ capability: string;
580
+ operations: Record<CompositionOperation, boolean>;
581
+ }[];
582
+ }>;
583
+ /**
584
+ * The durable facts around one record: what changed, what is connected to
585
+ * it and why, what was observed, which projections derive from it, and what
586
+ * this consumer may do. No interpretation.
587
+ */
588
+ context(uri: string, input?: {
589
+ changes?: number;
590
+ observations?: number;
591
+ }): Promise<{
592
+ subject: StateRecord<Record<string, unknown>>;
593
+ basis: StateSnapshotBinding;
594
+ changes: StateChange[];
595
+ observations: StateObservation[];
596
+ connected: import("./state-impact.js").DependentImpact[];
597
+ unknown: import("./state-impact.js").UnknownImpact[];
598
+ authorized_operations: {
599
+ collection: string;
600
+ uri: string;
601
+ mode: CompositionAccessMode;
602
+ capability: string;
603
+ operations: Record<CompositionOperation, boolean>;
604
+ }[];
605
+ }>;
606
+ /** Validate the operations, read the basis, and compute the impact. Writes nothing. */
607
+ private prepareProposal;
608
+ /**
609
+ * "I propose this state transition."
610
+ *
611
+ * Records the intent, the proposal bound to the current basis snapshot, and
612
+ * the impact surface computed from that same snapshot, in one transaction.
613
+ * Authoritative state is not touched.
614
+ */
615
+ intend(input: {
616
+ request: string;
617
+ summary?: string;
618
+ operations: ProposedOperation[];
619
+ }): Promise<StateProposalPreview>;
620
+ /**
621
+ * "What would change if this were applied?"
622
+ *
623
+ * The recorded impact, redacted to what this reader may see, with its
624
+ * current readiness and this reader's authorization evaluated now.
625
+ */
626
+ preview(proposalId: string): Promise<StateProposalPreview>;
627
+ /**
628
+ * The durable record of one proposal: its lifecycle events, its intent and
629
+ * intent events, the changes its application produced, and its lineage.
630
+ * Bounded reads; redacted like `preview`.
631
+ */
632
+ history(proposalId: string, input?: {
633
+ limit?: number;
634
+ }): Promise<{
635
+ proposal: StateProposal;
636
+ impact: Omit<StateImpact, "read_basis" | "surface"> & {
637
+ surface: ImpactSurface;
638
+ fenced: boolean;
639
+ };
640
+ readiness: StateProposalReadiness;
641
+ events: FeltDBProposalEvent[];
642
+ intent: {
643
+ id: string;
644
+ application_id: string;
645
+ environment: string;
646
+ raw_request: string;
647
+ action: "implement" | "extend" | "transition" | "unknown";
648
+ target: "module" | "billing" | "state" | "unknown";
649
+ module?: string;
650
+ module_version?: string;
651
+ parent_intent_id?: string;
652
+ contract_hash: string;
653
+ flow_hash: string;
654
+ status: IntentStatus;
655
+ ambiguities: import("./intent.js").IntentAmbiguity[];
656
+ created_at: string;
657
+ understanding?: import("./application-understanding.js").ApplicationUnderstanding;
658
+ plan?: import("./intent.js").ImplementationPlan;
659
+ proposal_id?: string;
660
+ } | null;
661
+ intent_events: IntentEvent[];
662
+ changes: StateChange[];
663
+ lineage: {
664
+ superseded_by?: string | undefined;
665
+ parent_proposal_id?: string | undefined;
666
+ };
667
+ }>;
668
+ /**
669
+ * Re-propose the same operations against the current snapshot.
670
+ *
671
+ * The stale proposal is retired through the shared lifecycle, and the child
672
+ * proposal gets a fresh impact. Nothing carries over except lineage.
673
+ */
674
+ rebase(proposalId: string): Promise<StateProposalPreview>;
675
+ /**
676
+ * Make an approved proposal authoritative.
677
+ *
678
+ * The impact is re-derived from a current snapshot and must equal the
679
+ * approved one; every direct write is CAS-guarded on the proposal's base
680
+ * version; the topology head is fenced; the gate authorizes every write for
681
+ * this consumer. State, attribution, proposal, and intent commit together.
682
+ */
683
+ apply(proposalId: string, options?: {
684
+ causalId?: string;
685
+ }): Promise<{
686
+ transaction: AtomicTransactionResult;
687
+ changes: StateChange[];
688
+ }>;
689
+ /**
690
+ * Record a refused apply in the proposal's history, in its own transaction.
691
+ *
692
+ * The refused commit wrote nothing; this is the audit trail that it was
693
+ * attempted and why it was refused. The proposal record itself is unchanged.
694
+ */
695
+ private recordRefusal;
696
+ }
697
+ //# sourceMappingURL=composition.d.ts.map