@hops-ops/distributed 0.0.0 → 4.0.1

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 (78) hide show
  1. package/README.md +26 -13
  2. package/dist/auth-headers.js +3 -3
  3. package/dist/internal/cache-engine/engine.d.ts +3 -1
  4. package/dist/internal/cache-engine/engine.js +137 -22
  5. package/dist/internal/cache-engine/errors.d.ts +4 -0
  6. package/dist/internal/cache-engine/errors.js +8 -0
  7. package/dist/internal/cache-engine/index.d.ts +2 -2
  8. package/dist/internal/cache-engine/index.js +1 -1
  9. package/dist/internal/cache-engine/types.d.ts +16 -0
  10. package/dist/internal/cache-engine.d.ts +2 -2
  11. package/dist/internal/cache-engine.js +1 -1
  12. package/dist/protocol.d.ts +9 -2
  13. package/dist/protocol.js +35 -7
  14. package/dist/replica/command-runtime/create.js +499 -57
  15. package/dist/replica/command-runtime/index.d.ts +1 -1
  16. package/dist/replica/command-runtime/index.js +1 -1
  17. package/dist/replica/command-runtime/lib/effects.d.ts +22 -9
  18. package/dist/replica/command-runtime/lib/effects.js +118 -20
  19. package/dist/replica/command-runtime/lib/projection.d.ts +2 -2
  20. package/dist/replica/command-runtime/lib/projection.js +14 -6
  21. package/dist/replica/command-runtime/lib/status.js +18 -10
  22. package/dist/replica/command-runtime/lib/transport.js +4 -0
  23. package/dist/replica/command-runtime/lib/util.js +8 -3
  24. package/dist/replica/command-runtime/symbols.d.ts +9 -0
  25. package/dist/replica/command-runtime/symbols.js +9 -0
  26. package/dist/replica/command-runtime/types.d.ts +15 -6
  27. package/dist/replica/command-runtime/types.js +1 -1
  28. package/dist/replica/command-runtime.d.ts +1 -1
  29. package/dist/replica/command-runtime.js +1 -1
  30. package/dist/replica/commands/clone.js +2 -1
  31. package/dist/replica/commands/index.d.ts +1 -0
  32. package/dist/replica/commands/prepare.js +7 -4
  33. package/dist/replica/commands/receipt.js +30 -16
  34. package/dist/replica/commands/types.d.ts +10 -5
  35. package/dist/replica/commands/validate.d.ts +5 -1
  36. package/dist/replica/commands/validate.js +129 -62
  37. package/dist/replica/diagnostics/inspect.js +51 -19
  38. package/dist/replica/diagnostics/types.d.ts +7 -7
  39. package/dist/replica/distributed-replica/helpers.js +22 -8
  40. package/dist/replica/distributed-replica/hydration.js +14 -2
  41. package/dist/replica/distributed-replica/impl-diagnostics.d.ts +1 -1
  42. package/dist/replica/distributed-replica/impl-diagnostics.js +4 -3
  43. package/dist/replica/distributed-replica/impl-hydration-orchestrate.d.ts +1 -1
  44. package/dist/replica/distributed-replica/impl-hydration-orchestrate.js +76 -42
  45. package/dist/replica/distributed-replica/impl-optimistic.d.ts +11 -2
  46. package/dist/replica/distributed-replica/impl-optimistic.js +22 -6
  47. package/dist/replica/distributed-replica/impl-protocol.js +4 -2
  48. package/dist/replica/distributed-replica/impl.d.ts +8 -2
  49. package/dist/replica/distributed-replica/impl.js +22 -5
  50. package/dist/replica/distributed-replica/optimistic.js +31 -3
  51. package/dist/replica/distributed-replica/types.d.ts +1 -0
  52. package/dist/replica/index-maintenance/engine.js +14 -6
  53. package/dist/replica/index.d.ts +4 -0
  54. package/dist/replica/index.js +2 -0
  55. package/dist/replica/materialize.js +25 -0
  56. package/dist/replica/mutation-cache.d.ts +62 -0
  57. package/dist/replica/mutation-cache.js +91 -0
  58. package/dist/replica/operation-binding.js +17 -6
  59. package/dist/replica/persistence/state.js +9 -1
  60. package/dist/replica/projection-delta/canonical.d.ts +6 -0
  61. package/dist/replica/projection-delta/canonical.js +29 -0
  62. package/dist/replica/projection-delta/index.d.ts +5 -0
  63. package/dist/replica/projection-delta/index.js +3 -0
  64. package/dist/replica/projection-delta/resolve.d.ts +8 -0
  65. package/dist/replica/projection-delta/resolve.js +266 -0
  66. package/dist/replica/projection-delta/types.d.ts +415 -0
  67. package/dist/replica/projection-delta/types.js +6 -0
  68. package/dist/replica/projection-delta/validate.d.ts +18 -0
  69. package/dist/replica/projection-delta/validate.js +1718 -0
  70. package/dist/replica/projection-delta/wasm-pure.d.ts +36 -0
  71. package/dist/replica/projection-delta/wasm-pure.js +71 -0
  72. package/dist/replica/query-plan/pagination.js +18 -8
  73. package/dist/replica/types.d.ts +13 -2
  74. package/dist/sveltekit/replica.d.ts +1 -1
  75. package/dist/sveltekit/replica.js +3 -0
  76. package/dist/sveltekit/vite.d.ts +6 -6
  77. package/dist/sveltekit/vite.js +6 -6
  78. package/package.json +3 -3
@@ -0,0 +1,415 @@
1
+ import type { ReplicaValue } from '../types.js';
2
+ export declare const PROJECTION_DELTA_WIRE_VERSION: 1;
3
+ export declare const COMMAND_PROJECTION_METADATA_WIRE_VERSION: 1;
4
+ export declare const COMMAND_PROJECTION_ARTIFACT_VERSION: 2;
5
+ export declare const PROJECTION_PROGRAM_VERSION: 2;
6
+ export declare const PROJECTION_PROGRAM_IR_VERSION: 1;
7
+ export declare const PROJECTION_OPERATION_SEMANTICS_VERSION: 1;
8
+ export type ProjectionDeltaSurface = Readonly<{
9
+ kind: 'role';
10
+ name: string;
11
+ }> | Readonly<{
12
+ kind: 'application';
13
+ name: string;
14
+ eligible_roles: readonly string[];
15
+ schema_roles: readonly string[];
16
+ }>;
17
+ export type ProjectionDeltaIdentity = Readonly<{
18
+ manifest_version: 2;
19
+ client_protocol_version: 1;
20
+ surface: ProjectionDeltaSurface;
21
+ schema_fingerprint: string;
22
+ protocol_fingerprint: string;
23
+ authorization_generation: string;
24
+ cache_scope_token: string;
25
+ command_causation_id: string;
26
+ }>;
27
+ export type ProjectionDeltaProjectionIdentity = Readonly<{
28
+ program_id: string;
29
+ binding_id: string;
30
+ epoch: string;
31
+ program_ir_version: 1;
32
+ operation_semantics_version: 1;
33
+ }>;
34
+ export type ProjectionDeltaOccurrence = Readonly<{
35
+ causation_id: string;
36
+ ordinal: number;
37
+ occurrence_id: string;
38
+ }>;
39
+ export type ProjectionDeltaValue = Readonly<{
40
+ type: 'null';
41
+ }> | Readonly<{
42
+ type: 'boolean';
43
+ value: boolean;
44
+ }> | Readonly<{
45
+ type: 'i64' | 'u64' | 'f64' | 'string';
46
+ value: string;
47
+ }> | Readonly<{
48
+ type: 'enum';
49
+ value: Readonly<{
50
+ enum_type: string;
51
+ variant: string;
52
+ }>;
53
+ }> | Readonly<{
54
+ type: 'list';
55
+ value: readonly ProjectionDeltaValue[];
56
+ }> | Readonly<{
57
+ type: 'object';
58
+ value: readonly ProjectionDeltaField[];
59
+ }>;
60
+ export type ProjectionDeltaField = Readonly<{
61
+ field: string;
62
+ value: ProjectionDeltaValue;
63
+ }>;
64
+ export type ProjectionDeltaKeyField = Readonly<{
65
+ ordinal: number;
66
+ field: string;
67
+ value: ProjectionDeltaValue;
68
+ }>;
69
+ export type ProjectionDeltaPartition = Readonly<{
70
+ kind: 'unit';
71
+ }> | Readonly<{
72
+ kind: 'opaque';
73
+ token: string;
74
+ }>;
75
+ export type ProjectionDeltaScope = Readonly<{
76
+ partition: ProjectionDeltaPartition;
77
+ model: string;
78
+ key: readonly ProjectionDeltaKeyField[];
79
+ }>;
80
+ export type ProjectionDeltaMutation = Readonly<{
81
+ op: 'upsert';
82
+ scope: ProjectionDeltaScope;
83
+ fields: readonly ProjectionDeltaField[];
84
+ replace: readonly string[];
85
+ }> | Readonly<{
86
+ op: 'patch';
87
+ scope: ProjectionDeltaScope;
88
+ set: readonly ProjectionDeltaField[];
89
+ unset: readonly string[];
90
+ if_present: true;
91
+ }> | Readonly<{
92
+ op: 'delete';
93
+ scope: ProjectionDeltaScope;
94
+ }> | Readonly<{
95
+ op: 'link' | 'unlink';
96
+ relationship: string;
97
+ source: ProjectionDeltaScope;
98
+ target: ProjectionDeltaScope;
99
+ }> | Readonly<{
100
+ op: 'invalidate_model';
101
+ partition?: ProjectionDeltaPartition;
102
+ model: string;
103
+ }> | Readonly<{
104
+ op: 'invalidate_relationship';
105
+ relationship: string;
106
+ source: ProjectionDeltaScope;
107
+ }>;
108
+ export type ProjectionDeltaOperation = Readonly<{
109
+ occurrence_ordinal: number;
110
+ projection_refs: readonly number[];
111
+ mutation: ProjectionDeltaMutation;
112
+ }>;
113
+ export type ProjectionDeltaRecoveryTarget = Readonly<{
114
+ kind: 'record';
115
+ scope: ProjectionDeltaScope;
116
+ }> | Readonly<{
117
+ kind: 'relationship';
118
+ relationship: string;
119
+ source: ProjectionDeltaScope;
120
+ }> | Readonly<{
121
+ kind: 'model';
122
+ partition?: ProjectionDeltaPartition;
123
+ model: string;
124
+ }>;
125
+ export type ProjectionDeltaRecovery = Readonly<{
126
+ occurrence_ordinal: number;
127
+ projection_refs: readonly number[];
128
+ condition: 'always' | 'if_record_missing';
129
+ target: ProjectionDeltaRecoveryTarget;
130
+ }>;
131
+ export type ProjectionDelta = Readonly<{
132
+ wire_version: 1;
133
+ identity: ProjectionDeltaIdentity;
134
+ projections: readonly ProjectionDeltaProjectionIdentity[];
135
+ occurrences: readonly ProjectionDeltaOccurrence[];
136
+ operations: readonly ProjectionDeltaOperation[];
137
+ recoveries: readonly ProjectionDeltaRecovery[];
138
+ }>;
139
+ export type CommandProjectionObligation = Readonly<{
140
+ projectionRef: number;
141
+ model: string;
142
+ scopeToken: string;
143
+ }>;
144
+ /**
145
+ * Opaque server-authenticated deployment identity for historical lifecycle
146
+ * checks. Clients validate only its bounded wire shape and never interpret it
147
+ * as authority to apply an old-scope delta.
148
+ */
149
+ export type CommandProjectionLifecycleProof = Readonly<{
150
+ projectionRef: number;
151
+ token: string;
152
+ }>;
153
+ export type CommandProjectionMetadata = Readonly<{
154
+ wireVersion: 1;
155
+ issuedAtUnixMs: number;
156
+ expiresAtUnixMs: number;
157
+ delta: ProjectionDelta;
158
+ lifecycleProofs: readonly CommandProjectionLifecycleProof[];
159
+ obligations: readonly CommandProjectionObligation[];
160
+ revalidate: boolean;
161
+ }>;
162
+ export type ProjectionPreviewValue = Readonly<{
163
+ kind: 'input' | 'generated_default';
164
+ path: readonly string[];
165
+ }> | Readonly<{
166
+ kind: 'trusted_preset';
167
+ name: string;
168
+ codec: string;
169
+ }> | Readonly<{
170
+ kind: 'constant';
171
+ value: ProjectionDeltaValue;
172
+ }> | Readonly<{
173
+ kind: 'null';
174
+ }> | Readonly<{
175
+ kind: 'list';
176
+ values: readonly ProjectionPreviewValue[];
177
+ }> | Readonly<{
178
+ kind: 'object';
179
+ fields: readonly Readonly<{
180
+ name: string;
181
+ value: ProjectionPreviewValue;
182
+ }>[];
183
+ }> | Readonly<{
184
+ kind: 'transform';
185
+ transform: 'string_concat' | 'first_present';
186
+ arguments: readonly ProjectionPreviewValue[];
187
+ }>;
188
+ export type ProjectionPreviewPartition = Readonly<{
189
+ kind: 'unit';
190
+ }> | Readonly<{
191
+ kind: 'expression';
192
+ expression: ProjectionPreviewValue;
193
+ requires: 'current_cache_partition';
194
+ }>;
195
+ export type ProjectionPreviewScope = Readonly<{
196
+ partition: ProjectionPreviewPartition;
197
+ model: string;
198
+ key: readonly Readonly<{
199
+ ordinal: number;
200
+ field: string;
201
+ value: ProjectionPreviewValue;
202
+ }>[];
203
+ }>;
204
+ export type ProjectionPreviewField = Readonly<{
205
+ field: string;
206
+ value: ProjectionPreviewValue;
207
+ }>;
208
+ export type ProjectionCapabilityPartition = Readonly<{
209
+ kind: 'unit';
210
+ }> | Readonly<{
211
+ kind: 'opaque';
212
+ expression_fingerprint: string;
213
+ }>;
214
+ export type ProjectionCapabilityMutation = Readonly<{
215
+ kind: 'record';
216
+ model: string;
217
+ key: readonly string[];
218
+ fields: readonly string[];
219
+ replace: readonly string[];
220
+ upsert: boolean;
221
+ patch: boolean;
222
+ delete: boolean;
223
+ }> | Readonly<{
224
+ kind: 'relationship';
225
+ relationship: string;
226
+ source_model: string;
227
+ source_key: readonly string[];
228
+ target_model: string;
229
+ target_key: readonly string[];
230
+ link: boolean;
231
+ unlink: boolean;
232
+ }> | Readonly<{
233
+ kind: 'model';
234
+ model: string;
235
+ }>;
236
+ export type ProjectionCapabilityArm = Readonly<{
237
+ event: Readonly<{
238
+ id: string;
239
+ name: string;
240
+ version: number;
241
+ }>;
242
+ projection_ref: number;
243
+ arm: string;
244
+ partition: ProjectionCapabilityPartition;
245
+ mutations: readonly ProjectionCapabilityMutation[];
246
+ }>;
247
+ /**
248
+ * Pure reduce: load the known cache row for `scope`, run a named pure function
249
+ * with resolved `args`, and patch `assign` fields from the result.
250
+ *
251
+ * Fail-closed: missing row or pure failure → no invent (same as patch ifPresent).
252
+ */
253
+ export type ProjectionPreviewPureReduce = Readonly<{
254
+ fn: string;
255
+ /** App lib-relative module (gen-client); optional at runtime. */
256
+ clientModule?: string;
257
+ /** Named export (gen-client); optional at runtime. */
258
+ clientExport?: string;
259
+ scope: ProjectionPreviewScope;
260
+ args: readonly Readonly<{
261
+ name: string;
262
+ value: ProjectionPreviewValue;
263
+ }>[];
264
+ /** Fields taken from the pure result and written onto the known record. */
265
+ assign: readonly string[];
266
+ occurrence_ordinal: number;
267
+ projection_refs: readonly number[];
268
+ }>;
269
+ export type ProjectionPreviewMutation = Readonly<{
270
+ op: 'upsert';
271
+ scope: ProjectionPreviewScope;
272
+ fields: readonly ProjectionPreviewField[];
273
+ replace: readonly string[];
274
+ }> | Readonly<{
275
+ op: 'patch';
276
+ scope: ProjectionPreviewScope;
277
+ set: readonly ProjectionPreviewField[];
278
+ unset?: readonly string[];
279
+ if_present: true;
280
+ }> | Readonly<{
281
+ op: 'delete';
282
+ scope: ProjectionPreviewScope;
283
+ }> | Readonly<{
284
+ op: 'link' | 'unlink';
285
+ relationship: string;
286
+ source: ProjectionPreviewScope;
287
+ target: ProjectionPreviewScope;
288
+ }> | Readonly<{
289
+ op: 'invalidate_model';
290
+ partition?: ProjectionPreviewPartition;
291
+ model: string;
292
+ }> | Readonly<{
293
+ op: 'invalidate_relationship';
294
+ relationship: string;
295
+ source: ProjectionPreviewScope;
296
+ }>;
297
+ export type ProjectionPreviewRecoveryTarget = Readonly<{
298
+ kind: 'record';
299
+ scope: ProjectionPreviewScope;
300
+ }> | Readonly<{
301
+ kind: 'relationship';
302
+ relationship: string;
303
+ source: ProjectionPreviewScope;
304
+ }> | Readonly<{
305
+ kind: 'model';
306
+ partition?: ProjectionPreviewPartition;
307
+ model: string;
308
+ }>;
309
+ export type ReplicaCommandProjection = Readonly<{
310
+ version: 2;
311
+ deltaWireVersion: 1;
312
+ projectionProgramVersion: 2;
313
+ operationSemanticsVersion: 1;
314
+ projections: readonly Readonly<{
315
+ programId: string;
316
+ bindingId: string;
317
+ epoch: string;
318
+ programIrVersion: 1;
319
+ operationSemanticsVersion: 1;
320
+ }>[];
321
+ eventSet: readonly Readonly<{
322
+ id: string;
323
+ name: string;
324
+ version: number;
325
+ }>[];
326
+ capabilities: Readonly<{
327
+ version: 1;
328
+ arms: readonly ProjectionCapabilityArm[];
329
+ }>;
330
+ preview: Readonly<{
331
+ version: 1;
332
+ occurrences: readonly Readonly<{
333
+ ordinal: number;
334
+ event: Readonly<{
335
+ id: string;
336
+ name: string;
337
+ version: number;
338
+ }>;
339
+ }>[];
340
+ operations: readonly Readonly<{
341
+ occurrence_ordinal: number;
342
+ projection_refs: readonly number[];
343
+ mutation: ProjectionPreviewMutation;
344
+ }>[];
345
+ recoveries: readonly Readonly<{
346
+ occurrence_ordinal: number;
347
+ projection_refs: readonly number[];
348
+ condition: 'always' | 'if_record_missing';
349
+ target: ProjectionPreviewRecoveryTarget;
350
+ }>[];
351
+ }>;
352
+ /**
353
+ * Optional pure reducers over known cache rows. Expanded at optimistic
354
+ * apply time (needs the live record); not ordinary preview expressions.
355
+ */
356
+ pureReduces?: readonly ProjectionPreviewPureReduce[];
357
+ fallback: 'revalidate';
358
+ }>;
359
+ export type PreparedProjectionOperation = Readonly<{
360
+ kind: 'upsert';
361
+ scope: PreparedProjectionScope;
362
+ fields: Readonly<Record<string, ReplicaValue>>;
363
+ replace: readonly string[];
364
+ }> | Readonly<{
365
+ kind: 'patch';
366
+ scope: PreparedProjectionScope;
367
+ fields: Readonly<Record<string, ReplicaValue>>;
368
+ unset: readonly string[];
369
+ ifPresent: true;
370
+ }> | Readonly<{
371
+ kind: 'delete';
372
+ scope: PreparedProjectionScope;
373
+ }> | Readonly<{
374
+ kind: 'link' | 'unlink';
375
+ relationship: string;
376
+ source: PreparedProjectionScope;
377
+ target: PreparedProjectionScope;
378
+ }> | Readonly<{
379
+ kind: 'invalidate_model';
380
+ model: string;
381
+ }> | Readonly<{
382
+ kind: 'invalidate_relationship';
383
+ relationship: string;
384
+ source: PreparedProjectionScope;
385
+ }> | Readonly<{
386
+ kind: 'reduce_known_record';
387
+ fn: string;
388
+ scope: PreparedProjectionScope;
389
+ args: Readonly<Record<string, ReplicaValue>>;
390
+ assign: readonly string[];
391
+ }>;
392
+ export type PreparedProjectionScope = Readonly<{
393
+ model: string;
394
+ key: readonly Readonly<{
395
+ field: string;
396
+ value: ReplicaValue;
397
+ }>[];
398
+ }>;
399
+ /** Named pure function: known record + resolved args → fields to patch. */
400
+ export type ReplicaPureFunction = (record: Readonly<Record<string, ReplicaValue>>, args: Readonly<Record<string, ReplicaValue>>) => Readonly<Record<string, ReplicaValue>> | null;
401
+ export type PreparedCommandProjection = Readonly<{
402
+ contract: ReplicaCommandProjection;
403
+ preview: readonly PreparedProjectionOperation[];
404
+ revalidate: boolean;
405
+ }>;
406
+ export type AppliedProjectionDelta = Readonly<{
407
+ canonical: string;
408
+ revalidate: boolean;
409
+ models: readonly string[];
410
+ relationships: readonly Readonly<{
411
+ sourceModel: string;
412
+ field: string;
413
+ targetModel: string;
414
+ }>[];
415
+ }>;
@@ -0,0 +1,6 @@
1
+ export const PROJECTION_DELTA_WIRE_VERSION = 1;
2
+ export const COMMAND_PROJECTION_METADATA_WIRE_VERSION = 1;
3
+ export const COMMAND_PROJECTION_ARTIFACT_VERSION = 2;
4
+ export const PROJECTION_PROGRAM_VERSION = 2;
5
+ export const PROJECTION_PROGRAM_IR_VERSION = 1;
6
+ export const PROJECTION_OPERATION_SEMANTICS_VERSION = 1;
@@ -0,0 +1,18 @@
1
+ import { canonicalCommandProjectionMetadata, canonicalProjectionDelta } from './canonical.js';
2
+ import { type CommandProjectionMetadata, type ProjectionDelta, type ProjectionDeltaSurface, type ReplicaCommandProjection } from './types.js';
3
+ export declare class ProjectionDeltaValidationError extends TypeError {
4
+ readonly path: string;
5
+ constructor(path: string);
6
+ }
7
+ export declare function parseProjectionDelta(value: unknown): ProjectionDelta;
8
+ export declare function parseCommandProjectionMetadata(value: unknown): CommandProjectionMetadata;
9
+ export declare function validateCommandProjectionArtifact(value: unknown, path?: string): ReplicaCommandProjection;
10
+ export declare function validateProjectionMetadataAuthority(metadata: CommandProjectionMetadata, contract: ReplicaCommandProjection, authority: Readonly<{
11
+ surface: ProjectionDeltaSurface;
12
+ schemaHash: string;
13
+ protocolHash: string;
14
+ authorizationGeneration: string;
15
+ cacheScope: string;
16
+ causationId: string;
17
+ }>, nowUnixMs?: number): string;
18
+ export { canonicalCommandProjectionMetadata, canonicalProjectionDelta };