@hops-ops/distributed 0.0.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 (242) hide show
  1. package/README.md +454 -0
  2. package/dist/auth-headers.d.ts +8 -0
  3. package/dist/auth-headers.js +35 -0
  4. package/dist/diagnostics.d.ts +2 -0
  5. package/dist/diagnostics.js +1 -0
  6. package/dist/document.d.ts +8 -0
  7. package/dist/document.js +6 -0
  8. package/dist/identity.d.ts +23 -0
  9. package/dist/identity.js +73 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.js +6 -0
  12. package/dist/internal/cache-engine/create.d.ts +5 -0
  13. package/dist/internal/cache-engine/create.js +7 -0
  14. package/dist/internal/cache-engine/engine.d.ts +32 -0
  15. package/dist/internal/cache-engine/engine.js +1287 -0
  16. package/dist/internal/cache-engine/errors.d.ts +5 -0
  17. package/dist/internal/cache-engine/errors.js +10 -0
  18. package/dist/internal/cache-engine/helpers.d.ts +55 -0
  19. package/dist/internal/cache-engine/helpers.js +545 -0
  20. package/dist/internal/cache-engine/index.d.ts +3 -0
  21. package/dist/internal/cache-engine/index.js +2 -0
  22. package/dist/internal/cache-engine/types.d.ts +300 -0
  23. package/dist/internal/cache-engine/types.js +1 -0
  24. package/dist/internal/cache-engine.d.ts +3 -0
  25. package/dist/internal/cache-engine.js +2 -0
  26. package/dist/lib/assert-name.d.ts +2 -0
  27. package/dist/lib/assert-name.js +6 -0
  28. package/dist/lib/compare-code-units.d.ts +2 -0
  29. package/dist/lib/compare-code-units.js +4 -0
  30. package/dist/lib/deep-equal.d.ts +2 -0
  31. package/dist/lib/deep-equal.js +24 -0
  32. package/dist/lib/freeze-record.d.ts +2 -0
  33. package/dist/lib/freeze-record.js +13 -0
  34. package/dist/lib/index.d.ts +6 -0
  35. package/dist/lib/index.js +6 -0
  36. package/dist/lib/is-plain-record.d.ts +2 -0
  37. package/dist/lib/is-plain-record.js +8 -0
  38. package/dist/lib/report.d.ts +7 -0
  39. package/dist/lib/report.js +26 -0
  40. package/dist/protocol.d.ts +179 -0
  41. package/dist/protocol.js +558 -0
  42. package/dist/react/context.d.ts +20 -0
  43. package/dist/react/context.js +24 -0
  44. package/dist/react/index.d.ts +2 -0
  45. package/dist/react/index.js +3 -0
  46. package/dist/react/query.d.ts +20 -0
  47. package/dist/react/query.js +99 -0
  48. package/dist/replica/command-id.d.ts +2 -0
  49. package/dist/replica/command-id.js +19 -0
  50. package/dist/replica/command-runtime/constants.d.ts +5 -0
  51. package/dist/replica/command-runtime/constants.js +5 -0
  52. package/dist/replica/command-runtime/create.d.ts +2 -0
  53. package/dist/replica/command-runtime/create.js +644 -0
  54. package/dist/replica/command-runtime/errors.d.ts +16 -0
  55. package/dist/replica/command-runtime/errors.js +41 -0
  56. package/dist/replica/command-runtime/index.d.ts +5 -0
  57. package/dist/replica/command-runtime/index.js +4 -0
  58. package/dist/replica/command-runtime/lib/binding.d.ts +4 -0
  59. package/dist/replica/command-runtime/lib/binding.js +64 -0
  60. package/dist/replica/command-runtime/lib/effects.d.ts +11 -0
  61. package/dist/replica/command-runtime/lib/effects.js +89 -0
  62. package/dist/replica/command-runtime/lib/index.d.ts +9 -0
  63. package/dist/replica/command-runtime/lib/index.js +9 -0
  64. package/dist/replica/command-runtime/lib/inventory.d.ts +10 -0
  65. package/dist/replica/command-runtime/lib/inventory.js +141 -0
  66. package/dist/replica/command-runtime/lib/output.d.ts +13 -0
  67. package/dist/replica/command-runtime/lib/output.js +190 -0
  68. package/dist/replica/command-runtime/lib/projection.d.ts +20 -0
  69. package/dist/replica/command-runtime/lib/projection.js +255 -0
  70. package/dist/replica/command-runtime/lib/status.d.ts +7 -0
  71. package/dist/replica/command-runtime/lib/status.js +127 -0
  72. package/dist/replica/command-runtime/lib/transport.d.ts +16 -0
  73. package/dist/replica/command-runtime/lib/transport.js +112 -0
  74. package/dist/replica/command-runtime/lib/util.d.ts +16 -0
  75. package/dist/replica/command-runtime/lib/util.js +127 -0
  76. package/dist/replica/command-runtime/lifecycle.d.ts +11 -0
  77. package/dist/replica/command-runtime/lifecycle.js +13 -0
  78. package/dist/replica/command-runtime/symbols.d.ts +30 -0
  79. package/dist/replica/command-runtime/symbols.js +30 -0
  80. package/dist/replica/command-runtime/types.d.ts +222 -0
  81. package/dist/replica/command-runtime/types.js +1 -0
  82. package/dist/replica/command-runtime.d.ts +3 -0
  83. package/dist/replica/command-runtime.js +2 -0
  84. package/dist/replica/commands/clone.d.ts +12 -0
  85. package/dist/replica/commands/clone.js +187 -0
  86. package/dist/replica/commands/constants.d.ts +6 -0
  87. package/dist/replica/commands/constants.js +6 -0
  88. package/dist/replica/commands/errors.d.ts +7 -0
  89. package/dist/replica/commands/errors.js +22 -0
  90. package/dist/replica/commands/implementation.d.ts +8 -0
  91. package/dist/replica/commands/implementation.js +8 -0
  92. package/dist/replica/commands/index.d.ts +5 -0
  93. package/dist/replica/commands/index.js +4 -0
  94. package/dist/replica/commands/prepare.d.ts +27 -0
  95. package/dist/replica/commands/prepare.js +77 -0
  96. package/dist/replica/commands/presets.d.ts +12 -0
  97. package/dist/replica/commands/presets.js +84 -0
  98. package/dist/replica/commands/receipt.d.ts +3 -0
  99. package/dist/replica/commands/receipt.js +36 -0
  100. package/dist/replica/commands/resolve.d.ts +11 -0
  101. package/dist/replica/commands/resolve.js +165 -0
  102. package/dist/replica/commands/types.d.ts +278 -0
  103. package/dist/replica/commands/types.js +2 -0
  104. package/dist/replica/commands/util.d.ts +21 -0
  105. package/dist/replica/commands/util.js +96 -0
  106. package/dist/replica/commands/validate.d.ts +18 -0
  107. package/dist/replica/commands/validate.js +477 -0
  108. package/dist/replica/commands.d.ts +3 -0
  109. package/dist/replica/commands.js +2 -0
  110. package/dist/replica/diagnostics/event-log.d.ts +4 -0
  111. package/dist/replica/diagnostics/event-log.js +463 -0
  112. package/dist/replica/diagnostics/implementation.d.ts +4 -0
  113. package/dist/replica/diagnostics/implementation.js +4 -0
  114. package/dist/replica/diagnostics/index.d.ts +2 -0
  115. package/dist/replica/diagnostics/index.js +1 -0
  116. package/dist/replica/diagnostics/inspect.d.ts +6 -0
  117. package/dist/replica/diagnostics/inspect.js +170 -0
  118. package/dist/replica/diagnostics/types.d.ts +295 -0
  119. package/dist/replica/diagnostics/types.js +2 -0
  120. package/dist/replica/diagnostics.d.ts +3 -0
  121. package/dist/replica/diagnostics.js +2 -0
  122. package/dist/replica/distributed-replica/clocks.d.ts +23 -0
  123. package/dist/replica/distributed-replica/clocks.js +156 -0
  124. package/dist/replica/distributed-replica/constants.d.ts +12 -0
  125. package/dist/replica/distributed-replica/constants.js +10 -0
  126. package/dist/replica/distributed-replica/helpers.d.ts +48 -0
  127. package/dist/replica/distributed-replica/helpers.js +445 -0
  128. package/dist/replica/distributed-replica/hydration.d.ts +19 -0
  129. package/dist/replica/distributed-replica/hydration.js +380 -0
  130. package/dist/replica/distributed-replica/impl-diagnostics.d.ts +22 -0
  131. package/dist/replica/distributed-replica/impl-diagnostics.js +189 -0
  132. package/dist/replica/distributed-replica/impl-fetch-live.d.ts +39 -0
  133. package/dist/replica/distributed-replica/impl-fetch-live.js +395 -0
  134. package/dist/replica/distributed-replica/impl-hydration-orchestrate.d.ts +56 -0
  135. package/dist/replica/distributed-replica/impl-hydration-orchestrate.js +299 -0
  136. package/dist/replica/distributed-replica/impl-optimistic.d.ts +31 -0
  137. package/dist/replica/distributed-replica/impl-optimistic.js +172 -0
  138. package/dist/replica/distributed-replica/impl-protocol.d.ts +53 -0
  139. package/dist/replica/distributed-replica/impl-protocol.js +108 -0
  140. package/dist/replica/distributed-replica/impl.d.ts +44 -0
  141. package/dist/replica/distributed-replica/impl.js +1776 -0
  142. package/dist/replica/distributed-replica/index.d.ts +2 -0
  143. package/dist/replica/distributed-replica/index.js +4 -0
  144. package/dist/replica/distributed-replica/optimistic.d.ts +30 -0
  145. package/dist/replica/distributed-replica/optimistic.js +221 -0
  146. package/dist/replica/distributed-replica/types.d.ts +147 -0
  147. package/dist/replica/distributed-replica/types.js +1 -0
  148. package/dist/replica/distributed-replica/watch.d.ts +19 -0
  149. package/dist/replica/distributed-replica/watch.js +95 -0
  150. package/dist/replica/distributed-replica.d.ts +2 -0
  151. package/dist/replica/distributed-replica.js +2 -0
  152. package/dist/replica/graphql-transport.d.ts +24 -0
  153. package/dist/replica/graphql-transport.js +122 -0
  154. package/dist/replica/identity/clone.d.ts +6 -0
  155. package/dist/replica/identity/clone.js +54 -0
  156. package/dist/replica/identity/codec.d.ts +48 -0
  157. package/dist/replica/identity/codec.js +789 -0
  158. package/dist/replica/identity/constants.d.ts +3 -0
  159. package/dist/replica/identity/constants.js +18 -0
  160. package/dist/replica/identity/implementation.d.ts +5 -0
  161. package/dist/replica/identity/implementation.js +5 -0
  162. package/dist/replica/identity/index.d.ts +3 -0
  163. package/dist/replica/identity/index.js +3 -0
  164. package/dist/replica/identity/keys.d.ts +29 -0
  165. package/dist/replica/identity/keys.js +173 -0
  166. package/dist/replica/identity.d.ts +2 -0
  167. package/dist/replica/identity.js +2 -0
  168. package/dist/replica/index-maintenance/engine.d.ts +84 -0
  169. package/dist/replica/index-maintenance/engine.js +677 -0
  170. package/dist/replica/index-maintenance/implementation.d.ts +4 -0
  171. package/dist/replica/index-maintenance/implementation.js +4 -0
  172. package/dist/replica/index-maintenance/index.d.ts +2 -0
  173. package/dist/replica/index-maintenance/index.js +1 -0
  174. package/dist/replica/index-maintenance/registry.d.ts +2 -0
  175. package/dist/replica/index-maintenance/registry.js +49 -0
  176. package/dist/replica/index-maintenance/types.d.ts +58 -0
  177. package/dist/replica/index-maintenance/types.js +1 -0
  178. package/dist/replica/index-maintenance.d.ts +3 -0
  179. package/dist/replica/index-maintenance.js +2 -0
  180. package/dist/replica/index.d.ts +17 -0
  181. package/dist/replica/index.js +9 -0
  182. package/dist/replica/materialize.d.ts +10 -0
  183. package/dist/replica/materialize.js +163 -0
  184. package/dist/replica/normalize.d.ts +27 -0
  185. package/dist/replica/normalize.js +298 -0
  186. package/dist/replica/operation-binding.d.ts +14 -0
  187. package/dist/replica/operation-binding.js +76 -0
  188. package/dist/replica/persistence/idb.d.ts +20 -0
  189. package/dist/replica/persistence/idb.js +193 -0
  190. package/dist/replica/persistence/implementation.d.ts +4 -0
  191. package/dist/replica/persistence/implementation.js +4 -0
  192. package/dist/replica/persistence/index.d.ts +2 -0
  193. package/dist/replica/persistence/index.js +1 -0
  194. package/dist/replica/persistence/state.d.ts +104 -0
  195. package/dist/replica/persistence/state.js +734 -0
  196. package/dist/replica/persistence/types.d.ts +54 -0
  197. package/dist/replica/persistence/types.js +1 -0
  198. package/dist/replica/persistence.d.ts +3 -0
  199. package/dist/replica/persistence.js +2 -0
  200. package/dist/replica/query-plan/constants.d.ts +13 -0
  201. package/dist/replica/query-plan/constants.js +7 -0
  202. package/dist/replica/query-plan/filter.d.ts +39 -0
  203. package/dist/replica/query-plan/filter.js +544 -0
  204. package/dist/replica/query-plan/index.d.ts +4 -0
  205. package/dist/replica/query-plan/index.js +3 -0
  206. package/dist/replica/query-plan/order.d.ts +11 -0
  207. package/dist/replica/query-plan/order.js +158 -0
  208. package/dist/replica/query-plan/pagination.d.ts +6 -0
  209. package/dist/replica/query-plan/pagination.js +90 -0
  210. package/dist/replica/query-plan/resolve.d.ts +14 -0
  211. package/dist/replica/query-plan/resolve.js +163 -0
  212. package/dist/replica/query-plan/types.d.ts +89 -0
  213. package/dist/replica/query-plan/types.js +1 -0
  214. package/dist/replica/query-plan/util.d.ts +13 -0
  215. package/dist/replica/query-plan/util.js +62 -0
  216. package/dist/replica/query-plan.d.ts +3 -0
  217. package/dist/replica/query-plan.js +2 -0
  218. package/dist/replica/revalidation.d.ts +9 -0
  219. package/dist/replica/revalidation.js +86 -0
  220. package/dist/replica/selection.d.ts +20 -0
  221. package/dist/replica/selection.js +109 -0
  222. package/dist/replica/types.d.ts +657 -0
  223. package/dist/replica/types.js +1 -0
  224. package/dist/request.d.ts +17 -0
  225. package/dist/request.js +123 -0
  226. package/dist/sveltekit/auth.d.ts +18 -0
  227. package/dist/sveltekit/auth.js +9 -0
  228. package/dist/sveltekit/context.d.ts +28 -0
  229. package/dist/sveltekit/context.js +58 -0
  230. package/dist/sveltekit/index.d.ts +4 -0
  231. package/dist/sveltekit/index.js +4 -0
  232. package/dist/sveltekit/replica.d.ts +145 -0
  233. package/dist/sveltekit/replica.js +491 -0
  234. package/dist/sveltekit/server-replica.d.ts +52 -0
  235. package/dist/sveltekit/server-replica.js +176 -0
  236. package/dist/sveltekit/vite.d.ts +103 -0
  237. package/dist/sveltekit/vite.js +878 -0
  238. package/dist/types.d.ts +33 -0
  239. package/dist/types.js +1 -0
  240. package/dist/websocket.d.ts +41 -0
  241. package/dist/websocket.js +187 -0
  242. package/package.json +95 -0
@@ -0,0 +1,295 @@
1
+ import type { GraphqlVariables } from '../../types.js';
2
+ import type { ReplicaCommandArtifact } from '../commands.js';
3
+ import type { ReplicaIndexCoverage, ReplicaOperationArtifact, ReplicaValue, ReplicaWriteSource } from '../types.js';
4
+ export declare const DIAGNOSTICS_BUNDLE_MARKER: "distributed-replica-diagnostics-v1";
5
+ declare const developmentCapabilityBrand: unique symbol;
6
+ export type ReplicaDevelopmentCapability = Readonly<{
7
+ readonly version: 1;
8
+ readonly [developmentCapabilityBrand]: true;
9
+ }>;
10
+ export type ReplicaDiagnosticFieldValueContext = Readonly<{
11
+ recordKey: string;
12
+ model?: string;
13
+ field: string;
14
+ kind: 'field' | 'link';
15
+ }>;
16
+ export type ReplicaDiagnosticFieldValuePolicy = Readonly<{
17
+ capability: ReplicaDevelopmentCapability;
18
+ /** A field must be explicitly authorized before its value reaches the redactor. */
19
+ allow(context: ReplicaDiagnosticFieldValueContext): boolean;
20
+ /**
21
+ * Return a support-safe replacement. Returning undefined omits the value.
22
+ * Raw values are never retained before this function returns.
23
+ */
24
+ redact(value: ReplicaValue, context: ReplicaDiagnosticFieldValueContext): ReplicaValue | undefined;
25
+ }>;
26
+ export type ReplicaDiagnosticReasonContext = Readonly<{
27
+ kind: 'index-stale';
28
+ indexKey: string;
29
+ }> | Readonly<{
30
+ kind: 'layer';
31
+ layerId: string;
32
+ action: 'created' | 'rebased' | 'accepted' | 'retired' | 'rejected';
33
+ }>;
34
+ export type ReplicaDiagnosticReasonPolicy = Readonly<{
35
+ capability: ReplicaDevelopmentCapability;
36
+ /**
37
+ * Return a bounded support-safe replacement. Returning undefined keeps the
38
+ * structural default (`application-stale`, for example).
39
+ */
40
+ redact(reason: string, context: ReplicaDiagnosticReasonContext): string | undefined;
41
+ }>;
42
+ export type ReplicaDiagnosticsOptions = Readonly<{
43
+ maxEvents?: number;
44
+ development?: ReplicaDevelopmentCapability;
45
+ fieldValues?: ReplicaDiagnosticFieldValuePolicy;
46
+ reasons?: ReplicaDiagnosticReasonPolicy;
47
+ now?: () => number;
48
+ onObserverError?: (error: AggregateError) => void;
49
+ }>;
50
+ export type ReplicaDiagnosticScopeInput = Readonly<{
51
+ generation: number;
52
+ established: boolean;
53
+ protocolVersion?: 1;
54
+ schemaHash?: string;
55
+ }>;
56
+ export type ReplicaDiagnosticRecordInput = Readonly<{
57
+ key: string;
58
+ model?: string;
59
+ revision: string;
60
+ incarnation: string;
61
+ tombstone: boolean;
62
+ tombstoneRevision?: string;
63
+ presentFields: readonly string[];
64
+ presentLinks: readonly string[];
65
+ /**
66
+ * Values in this object must already be support-safe redactor output. Replica
67
+ * core obtains them only through `redactRecordValue`.
68
+ */
69
+ values?: Readonly<Record<string, ReplicaValue>>;
70
+ }>;
71
+ export type ReplicaDiagnosticIndexInput = Readonly<{
72
+ key: string;
73
+ revision: string;
74
+ staleRevision?: string;
75
+ records: readonly string[];
76
+ complete: boolean;
77
+ deleted: boolean;
78
+ field?: string;
79
+ parent?: string;
80
+ argumentNames?: readonly string[];
81
+ arguments?: Readonly<Record<string, ReplicaValue>>;
82
+ coverage?: ReplicaIndexCoverage;
83
+ dependencies?: readonly string[];
84
+ staleReason?: string;
85
+ nullValue?: boolean;
86
+ }>;
87
+ export type ReplicaDiagnosticLayerInput = Readonly<{
88
+ id: string;
89
+ sequence: number;
90
+ state: 'optimistic' | 'accepted';
91
+ recordChanges: number;
92
+ indexChanges: number;
93
+ semanticChanges: number;
94
+ }>;
95
+ export type ReplicaDiagnosticReceiptExpectationInput = Readonly<{
96
+ projection: string;
97
+ model: string;
98
+ observed: boolean;
99
+ }>;
100
+ export type ReplicaDiagnosticReceiptInput = Readonly<{
101
+ commandId: string;
102
+ state: 'optimistic' | 'accepted' | 'accepted_pending_projection';
103
+ consistency?: 'accepted' | 'fact' | 'projected';
104
+ expectations: readonly ReplicaDiagnosticReceiptExpectationInput[];
105
+ }>;
106
+ /** Engine-independent state contract implemented by DistributedReplica. */
107
+ export type ReplicaDiagnosticStateInput = Readonly<{
108
+ scope: ReplicaDiagnosticScopeInput;
109
+ records: readonly ReplicaDiagnosticRecordInput[];
110
+ indexes: readonly ReplicaDiagnosticIndexInput[];
111
+ layers: readonly ReplicaDiagnosticLayerInput[];
112
+ receipts: readonly ReplicaDiagnosticReceiptInput[];
113
+ }>;
114
+ export type ReplicaDiagnosticEventInput = Readonly<{
115
+ kind: 'normalization';
116
+ operation: string;
117
+ source: ReplicaWriteSource;
118
+ records: number;
119
+ indexes: number;
120
+ partial: boolean;
121
+ }> | Readonly<{
122
+ kind: 'index-decision';
123
+ index: string;
124
+ decision: 'maintained' | 'stale' | 'revalidate';
125
+ reason?: string;
126
+ }> | Readonly<{
127
+ kind: 'revalidation';
128
+ operation: string;
129
+ action: 'requested' | 'deduplicated' | 'skipped-complete';
130
+ reason: 'watch' | 'refresh' | 'stale';
131
+ }> | Readonly<{
132
+ kind: 'layer';
133
+ layer: string;
134
+ action: 'created' | 'rebased' | 'accepted' | 'retired' | 'rejected';
135
+ recordChanges?: number;
136
+ indexChanges?: number;
137
+ reason?: string;
138
+ }> | Readonly<{
139
+ kind: 'receipt';
140
+ command: string;
141
+ state: 'optimistic' | 'accepted' | 'accepted_pending_projection' | 'projected' | 'rejected';
142
+ obligations: number;
143
+ observed: number;
144
+ }> | Readonly<{
145
+ kind: 'response-fenced';
146
+ operation: string;
147
+ transport: 'http' | 'live';
148
+ reason: 'authorization-generation' | 'operation-generation' | 'superseded';
149
+ }> | Readonly<{
150
+ kind: 'gc';
151
+ records: number;
152
+ }> | Readonly<{
153
+ kind: 'hydration';
154
+ action: 'accepted' | 'rejected';
155
+ reason: 'accepted' | 'invalid' | 'scope-mismatch' | 'artifact-mismatch' | 'active-scope-mismatch' | 'metadata-mismatch';
156
+ }> | Readonly<{
157
+ kind: 'scope';
158
+ action: 'established' | 'changed' | 'invalidated';
159
+ generation: number;
160
+ schemaHash?: string;
161
+ }>;
162
+ export type ReplicaDiagnosticEvent = ReplicaDiagnosticEventInput & Readonly<{
163
+ sequence: number;
164
+ at: number;
165
+ }>;
166
+ export type ReplicaDiagnosticRecord = Readonly<{
167
+ key: string;
168
+ model?: string;
169
+ revision: string;
170
+ incarnation: string;
171
+ tombstone: boolean;
172
+ tombstoneRevision?: string;
173
+ presentFields: readonly string[];
174
+ presentLinks: readonly string[];
175
+ values?: Readonly<Record<string, ReplicaValue>>;
176
+ }>;
177
+ export type ReplicaDiagnosticIndex = Readonly<{
178
+ key: string;
179
+ revision: string;
180
+ staleRevision?: string;
181
+ records: readonly string[];
182
+ complete: boolean;
183
+ deleted: boolean;
184
+ field?: string;
185
+ parent?: string;
186
+ argumentNames: readonly string[];
187
+ arguments?: Readonly<Record<string, ReplicaValue>>;
188
+ coverage?: ReplicaIndexCoverage;
189
+ dependencies: readonly string[];
190
+ staleReason?: string;
191
+ nullValue: boolean;
192
+ }>;
193
+ export type ReplicaDiagnosticLayer = Readonly<{
194
+ id: string;
195
+ sequence: number;
196
+ state: 'optimistic' | 'accepted';
197
+ recordChanges: number;
198
+ indexChanges: number;
199
+ semanticChanges: number;
200
+ }>;
201
+ export type ReplicaDiagnosticReceipt = Readonly<{
202
+ commandId: string;
203
+ state: 'optimistic' | 'accepted' | 'accepted_pending_projection';
204
+ consistency?: 'accepted' | 'fact' | 'projected';
205
+ expectations: readonly ReplicaDiagnosticReceiptExpectationInput[];
206
+ }>;
207
+ export type ReplicaArtifactSourceLocation = Readonly<{
208
+ path: string;
209
+ line: number;
210
+ column: number;
211
+ }>;
212
+ export type ReplicaOperationInjectedFieldInspection = Readonly<{
213
+ path: string;
214
+ responseKey: string;
215
+ field: string;
216
+ }>;
217
+ export type ReplicaOperationIndexInspection = Readonly<{
218
+ path: string;
219
+ field: string;
220
+ cardinality: 'one' | 'many';
221
+ dependencies: readonly string[];
222
+ coverage?: ReplicaIndexCoverage['kind'];
223
+ filtered: boolean;
224
+ ordered: boolean;
225
+ pagination?: 'complete' | 'offset' | 'cursor';
226
+ }>;
227
+ export type ReplicaOperationArtifactInspection = Readonly<{
228
+ kind: 'operation';
229
+ id: string;
230
+ source?: ReplicaArtifactSourceLocation;
231
+ rootFields: readonly string[];
232
+ injectedFields: readonly ReplicaOperationInjectedFieldInspection[];
233
+ dependencies: readonly string[];
234
+ indexes: readonly ReplicaOperationIndexInspection[];
235
+ live?: Readonly<{
236
+ operation: string;
237
+ }>;
238
+ }>;
239
+ export type ReplicaCommandEffectInspection = Readonly<{
240
+ kind: 'upsert' | 'patch' | 'delete' | 'link' | 'unlink' | 'invalidate_model' | 'invalidate_relationship';
241
+ models: readonly string[];
242
+ fields: readonly string[];
243
+ valueSources: readonly ('input' | 'trusted_preset' | 'constant' | 'null')[];
244
+ }>;
245
+ export type ReplicaCommandArtifactInspection = Readonly<{
246
+ kind: 'command';
247
+ name: string;
248
+ operation: string;
249
+ consistency: 'accepted' | 'fact' | 'projected';
250
+ effects: readonly ReplicaCommandEffectInspection[];
251
+ revalidation: Readonly<{
252
+ required: boolean;
253
+ dependencies: readonly string[];
254
+ models: readonly string[];
255
+ }>;
256
+ }>;
257
+ export type ReplicaDiagnosticsSnapshot = Readonly<{
258
+ version: 1;
259
+ marker: typeof DIAGNOSTICS_BUNDLE_MARKER;
260
+ mode: 'redacted' | 'development';
261
+ sequence: number;
262
+ scope: ReplicaDiagnosticScopeInput;
263
+ records: readonly ReplicaDiagnosticRecord[];
264
+ indexes: readonly ReplicaDiagnosticIndex[];
265
+ layers: readonly ReplicaDiagnosticLayer[];
266
+ receipts: readonly ReplicaDiagnosticReceipt[];
267
+ artifacts: Readonly<{
268
+ operations: readonly ReplicaOperationArtifactInspection[];
269
+ commands: readonly ReplicaCommandArtifactInspection[];
270
+ }>;
271
+ events: readonly ReplicaDiagnosticEvent[];
272
+ }>;
273
+ /**
274
+ * Small core-facing contract. Implementations must not throw into replica
275
+ * transactions; DistributedReplica also catches sink failures defensively.
276
+ */
277
+ export interface ReplicaDiagnosticsSink {
278
+ readonly includeStructuralIdentities: boolean;
279
+ redactRecordValue?(context: ReplicaDiagnosticFieldValueContext, value: ReplicaValue): ReplicaValue | undefined;
280
+ update(state: ReplicaDiagnosticStateInput): void;
281
+ event(event: ReplicaDiagnosticEventInput): void;
282
+ operation<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>): void;
283
+ command<TInput, TOutput>(artifact: ReplicaCommandArtifact<TInput, TOutput>): void;
284
+ }
285
+ export interface ReplicaDiagnostics extends ReplicaDiagnosticsSink {
286
+ snapshot(): ReplicaDiagnosticsSnapshot;
287
+ /** React/useSyncExternalStore-compatible alias with stable referential output. */
288
+ getSnapshot(): ReplicaDiagnosticsSnapshot;
289
+ subscribe(listener: (snapshot: ReplicaDiagnosticsSnapshot) => void): () => void;
290
+ inspectOperation<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>): ReplicaOperationArtifactInspection;
291
+ inspectCommand<TInput, TOutput>(artifact: ReplicaCommandArtifact<TInput, TOutput>): ReplicaCommandArtifactInspection;
292
+ clear(): void;
293
+ }
294
+ export {};
295
+ /** Create an unforgeable, process-local opt-in to development identities. */
@@ -0,0 +1,2 @@
1
+ export const DIAGNOSTICS_BUNDLE_MARKER = 'distributed-replica-diagnostics-v1';
2
+ /** Create an unforgeable, process-local opt-in to development identities. */
@@ -0,0 +1,3 @@
1
+ /** Replica diagnostics sink and artifact inspection; implementation in ./diagnostics/. */
2
+ export { createReplicaDevelopmentCapability, createReplicaDiagnostics, inspectReplicaCommandArtifact, inspectReplicaOperationArtifact } from './diagnostics/index.js';
3
+ export type { ReplicaArtifactSourceLocation, ReplicaCommandArtifactInspection, ReplicaCommandEffectInspection, ReplicaDevelopmentCapability, ReplicaDiagnosticEvent, ReplicaDiagnosticEventInput, ReplicaDiagnosticFieldValueContext, ReplicaDiagnosticFieldValuePolicy, ReplicaDiagnosticIndex, ReplicaDiagnosticIndexInput, ReplicaDiagnosticLayer, ReplicaDiagnosticLayerInput, ReplicaDiagnosticReceipt, ReplicaDiagnosticReceiptExpectationInput, ReplicaDiagnosticReceiptInput, ReplicaDiagnosticRecord, ReplicaDiagnosticRecordInput, ReplicaDiagnosticReasonContext, ReplicaDiagnosticReasonPolicy, ReplicaDiagnostics, ReplicaDiagnosticsOptions, ReplicaDiagnosticsSink, ReplicaDiagnosticsSnapshot, ReplicaDiagnosticScopeInput, ReplicaDiagnosticStateInput, ReplicaOperationArtifactInspection, ReplicaOperationIndexInspection, ReplicaOperationInjectedFieldInspection } from './diagnostics/index.js';
@@ -0,0 +1,2 @@
1
+ /** Replica diagnostics sink and artifact inspection; implementation in ./diagnostics/. */
2
+ export { createReplicaDevelopmentCapability, createReplicaDiagnostics, inspectReplicaCommandArtifact, inspectReplicaOperationArtifact } from './diagnostics/index.js';
@@ -0,0 +1,23 @@
1
+ import type { CacheValue } from '../../internal/cache-engine.js';
2
+ import { type DistributedIndexRevision, type DistributedLiveCursor, type DistributedProtocolEnvelope, type DistributedQuerySnapshot, type DistributedRecordRevision } from '../../protocol.js';
3
+ import type { ReplicaValue } from '../types.js';
4
+ import type { IndexDisposition, IndexProtocolClock, OperationProtocolState, ProjectedRecordFence, RecordProtocolClock } from './types.js';
5
+ import { deepEqual } from '../../lib/deep-equal.js';
6
+ export declare function sameRecordRevision(left: DistributedRecordRevision, right: DistributedRecordRevision): boolean;
7
+ export declare function recordKeyMatchesModel(recordKey: string, model: string): boolean;
8
+ export declare function modelFromRecordKey(recordKey: string): string | undefined;
9
+ export declare function compareIndexVector(current: ReadonlyMap<string, IndexProtocolClock>, incoming: readonly DistributedIndexRevision[]): IndexDisposition;
10
+ export declare function compareSnapshotToOperationState(state: OperationProtocolState, snapshot: DistributedQuerySnapshot): IndexDisposition;
11
+ export declare function isComparableHandoffDisposition(disposition: IndexDisposition): boolean;
12
+ export declare function indexClockMap(indexes: readonly DistributedIndexRevision[]): Map<string, IndexProtocolClock>;
13
+ export declare function latestCursors(snapshot: DistributedQuerySnapshot, live: DistributedProtocolEnvelope['live']): readonly DistributedLiveCursor[];
14
+ export declare function responsePathKey(path: readonly string[]): string;
15
+ export declare function compareRecordClock(left: RecordProtocolClock, right: RecordProtocolClock): -1 | 0 | 1;
16
+ export declare function compareEvidenceToProjectedFence(evidence: DistributedRecordRevision, fence: ProjectedRecordFence): -1 | 0 | 1 | undefined;
17
+ export declare function sameRecordClock(left: RecordProtocolClock, right: RecordProtocolClock): boolean;
18
+ export declare function incrementCanonicalDecimal(value: string): string;
19
+ export declare function compareCanonicalDecimalStrings(left: string, right: string): number;
20
+ export declare function protocolInvalid(path: string): never;
21
+ export declare function freezeRecordClock(clock: RecordProtocolClock): RecordProtocolClock;
22
+ export declare function compareProjectedRecordFields(projected: Readonly<Record<string, ReplicaValue>>, incoming: Readonly<Record<string, CacheValue>>): 'conflict' | 'partial' | 'complete';
23
+ export { deepEqual };
@@ -0,0 +1,156 @@
1
+ import { compareDistributedDecimal, DistributedProtocolError } from '../../protocol.js';
2
+ import { deepEqual } from '../../lib/deep-equal.js';
3
+ export function sameRecordRevision(left, right) {
4
+ return (left.model === right.model &&
5
+ left.scopeToken === right.scopeToken &&
6
+ left.incarnation === right.incarnation &&
7
+ left.revision === right.revision &&
8
+ left.tombstone === right.tombstone);
9
+ }
10
+ export function recordKeyMatchesModel(recordKey, model) {
11
+ return recordKey.startsWith(`record:${encodeURIComponent(model)}:`);
12
+ }
13
+ export function modelFromRecordKey(recordKey) {
14
+ if (!recordKey.startsWith('record:'))
15
+ return undefined;
16
+ const separator = recordKey.indexOf(':', 'record:'.length);
17
+ if (separator === -1)
18
+ return undefined;
19
+ try {
20
+ const model = decodeURIComponent(recordKey.slice('record:'.length, separator));
21
+ return model.length === 0 ? undefined : model;
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }
27
+ export function compareIndexVector(current, incoming) {
28
+ if (current.size === 0)
29
+ return 'fresh';
30
+ if (current.size !== incoming.length)
31
+ return 'incomparable';
32
+ let lower = false;
33
+ let higher = false;
34
+ for (const evidence of incoming) {
35
+ const previous = current.get(evidence.projection);
36
+ if (previous === undefined ||
37
+ previous.scopeToken !== evidence.scopeToken) {
38
+ return 'incomparable';
39
+ }
40
+ const comparison = compareDistributedDecimal(evidence.position, previous.position);
41
+ lower ||= comparison < 0;
42
+ higher ||= comparison > 0;
43
+ }
44
+ if (lower && higher)
45
+ return 'incomparable';
46
+ if (lower)
47
+ return 'lower';
48
+ if (higher)
49
+ return 'higher';
50
+ return 'equal';
51
+ }
52
+ export function compareSnapshotToOperationState(state, snapshot) {
53
+ if (state.snapshotScope === undefined)
54
+ return 'fresh';
55
+ if (state.snapshotScope !== snapshot.scopeToken)
56
+ return 'incomparable';
57
+ if (state.indexClocks.size === 0 || snapshot.indexes.length === 0) {
58
+ return state.indexClocks.size === snapshot.indexes.length
59
+ ? 'equal'
60
+ : 'incomparable';
61
+ }
62
+ return compareIndexVector(state.indexClocks, snapshot.indexes);
63
+ }
64
+ export function isComparableHandoffDisposition(disposition) {
65
+ return (disposition === 'fresh' ||
66
+ disposition === 'equal' ||
67
+ disposition === 'higher');
68
+ }
69
+ export function indexClockMap(indexes) {
70
+ return new Map(indexes.map((index) => [
71
+ index.projection,
72
+ {
73
+ scopeToken: index.scopeToken,
74
+ position: index.position
75
+ }
76
+ ]));
77
+ }
78
+ export function latestCursors(snapshot, live) {
79
+ if (live !== undefined) {
80
+ return live.supported ? live.cursors : Object.freeze([]);
81
+ }
82
+ return Object.freeze(snapshot.indexes.flatMap((index) => index.resume === undefined ? [] : [index.resume]));
83
+ }
84
+ export function responsePathKey(path) {
85
+ return JSON.stringify(path);
86
+ }
87
+ export function compareRecordClock(left, right) {
88
+ const incarnation = compareDistributedDecimal(left.incarnation, right.incarnation);
89
+ return incarnation === 0
90
+ ? compareDistributedDecimal(left.revision, right.revision)
91
+ : incarnation;
92
+ }
93
+ export function compareEvidenceToProjectedFence(evidence, fence) {
94
+ if (evidence.scopeToken !== fence.clock.scopeToken)
95
+ return undefined;
96
+ return compareRecordClock({
97
+ scopeToken: evidence.scopeToken,
98
+ incarnation: evidence.incarnation,
99
+ revision: evidence.revision,
100
+ tombstone: evidence.tombstone
101
+ }, fence.clock);
102
+ }
103
+ export function sameRecordClock(left, right) {
104
+ return (left.scopeToken === right.scopeToken &&
105
+ left.incarnation === right.incarnation &&
106
+ left.revision === right.revision &&
107
+ left.tombstone === right.tombstone);
108
+ }
109
+ export function incrementCanonicalDecimal(value) {
110
+ const digits = [...value];
111
+ let carry = true;
112
+ for (let index = digits.length - 1; index >= 0 && carry; index -= 1) {
113
+ const digit = digits[index];
114
+ if (digit === '9') {
115
+ digits[index] = '0';
116
+ }
117
+ else {
118
+ digits[index] = '0123456789'['0123456789'.indexOf(digit) + 1];
119
+ carry = false;
120
+ }
121
+ }
122
+ if (carry)
123
+ digits.unshift('1');
124
+ return digits.join('');
125
+ }
126
+ export function compareCanonicalDecimalStrings(left, right) {
127
+ return left.length === right.length
128
+ ? left.localeCompare(right)
129
+ : left.length < right.length
130
+ ? -1
131
+ : 1;
132
+ }
133
+ export function protocolInvalid(path) {
134
+ throw new DistributedProtocolError('DISTRIBUTED_PROTOCOL_INVALID', path);
135
+ }
136
+ export function freezeRecordClock(clock) {
137
+ return Object.freeze({
138
+ scopeToken: clock.scopeToken,
139
+ incarnation: clock.incarnation,
140
+ revision: clock.revision,
141
+ tombstone: clock.tombstone
142
+ });
143
+ }
144
+ export function compareProjectedRecordFields(projected, incoming) {
145
+ let complete = true;
146
+ for (const [field, value] of Object.entries(projected)) {
147
+ if (!Object.prototype.hasOwnProperty.call(incoming, field)) {
148
+ complete = false;
149
+ continue;
150
+ }
151
+ if (!deepEqual(value, incoming[field]))
152
+ return 'conflict';
153
+ }
154
+ return complete ? 'complete' : 'partial';
155
+ }
156
+ export { deepEqual };
@@ -0,0 +1,12 @@
1
+ import type { GqlError } from '../../types.js';
2
+ import type { DistributedTrustedPreset } from '../../protocol.js';
3
+ export declare const EMPTY_ERRORS: readonly GqlError[];
4
+ /** Matches protocol.ts MAX_EVIDENCE_ITEMS without making it public API. */
5
+ export declare const MAX_ANONYMOUS_RECORD_CLOCKS = 4096;
6
+ export declare const SHA256: RegExp;
7
+ export declare const EMPTY_TRUSTED_PRESETS: readonly DistributedTrustedPreset[];
8
+ export declare const EMPTY_CACHE_SNAPSHOT: Readonly<{
9
+ version: 1;
10
+ records: readonly never[];
11
+ indexes: readonly never[];
12
+ }>;
@@ -0,0 +1,10 @@
1
+ export const EMPTY_ERRORS = Object.freeze([]);
2
+ /** Matches protocol.ts MAX_EVIDENCE_ITEMS without making it public API. */
3
+ export const MAX_ANONYMOUS_RECORD_CLOCKS = 4_096;
4
+ export const SHA256 = /^sha256:[0-9a-f]{64}$/;
5
+ export const EMPTY_TRUSTED_PRESETS = Object.freeze([]);
6
+ export const EMPTY_CACHE_SNAPSHOT = Object.freeze({
7
+ version: 1,
8
+ records: Object.freeze([]),
9
+ indexes: Object.freeze([])
10
+ });
@@ -0,0 +1,48 @@
1
+ import { type BaseCacheWriter, type CacheEngineSnapshot, type CacheIndexMetadata, type OptimisticLayerView } from '../../internal/cache-engine.js';
2
+ import type { GqlError, GraphqlVariables } from '../../types.js';
3
+ import { type DistributedQuerySnapshot, type DistributedRecordRevision, type DistributedTrustedPreset } from '../../protocol.js';
4
+ import type { ReplicaTrustedPresetDescriptor } from '../commands.js';
5
+ import type { ReplicaCommandSurfaceContract } from '../command-runtime.js';
6
+ import { type ReplicaIndexMaintenanceSnapshot, type ReplicaIndexSemanticLayer } from '../index-maintenance.js';
7
+ import type { MaterializedReplicaResult } from '../materialize.js';
8
+ import { type RuntimeObjectBranch, type RuntimeObjectSelection, type RuntimeRootSelection } from '../selection.js';
9
+ import type { ReplicaBaseWriter, ReplicaIndexTarget, ReplicaOperationArtifact, ReplicaResultEnvelope, ReplicaSnapshot, ReplicaWriteSource } from '../types.js';
10
+ import type { OperationProtocolSource, QueryState, RegisteredCommandAuthorityContract } from './types.js';
11
+ import { reportSafely, reportUnhandledError } from '../../lib/report.js';
12
+ export { deepEqual } from './clocks.js';
13
+ export declare function prepareRecordEvidence(snapshot: DistributedQuerySnapshot, commandRecords: readonly DistributedRecordRevision[]): {
14
+ byPath: Map<string, DistributedRecordRevision>;
15
+ tombstones: readonly DistributedRecordRevision[];
16
+ pathless: readonly DistributedRecordRevision[];
17
+ livePaths: ReadonlySet<string>;
18
+ };
19
+ export declare function replicaResultIndexKeys<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>, variables: TVariables, envelope: ReplicaResultEnvelope<TData>, snapshot: DistributedQuerySnapshot): ReadonlySet<string>;
20
+ export declare function collectResultBranchIndexKeys(artifactId: string, selection: RuntimeRootSelection | RuntimeObjectBranch, value: unknown, path: readonly (string | number)[], enclosingIndexKey: string, variables: GraphqlVariables, errorPaths: readonly (readonly (string | number)[])[], evidencePaths: ReadonlySet<string>, keys: Set<string>): void;
21
+ export declare function collectResultObjectIndexKeys(artifactId: string, selection: RuntimeObjectSelection, value: unknown, path: readonly (string | number)[], enclosingIndexKey: string, ordinal: number | undefined, variables: GraphqlVariables, errorPaths: readonly (readonly (string | number)[])[], evidencePaths: ReadonlySet<string>, keys: Set<string>): void;
22
+ export declare function resultPathBlocked(errorPaths: readonly (readonly (string | number)[])[], path: readonly (string | number)[]): boolean;
23
+ export declare function resultPathHasErrors(errorPaths: readonly (readonly (string | number)[])[], path: readonly (string | number)[]): boolean;
24
+ export declare function resultPathPrefix(prefix: readonly (string | number)[], value: readonly (string | number)[]): boolean;
25
+ export declare function isReplicaResultObject(value: unknown): value is Readonly<Record<string, unknown>>;
26
+ export declare function indexMaintenanceSnapshot(confirmed: CacheEngineSnapshot): ReplicaIndexMaintenanceSnapshot;
27
+ export declare function indexSemanticLayer(layer: OptimisticLayerView): ReplicaIndexSemanticLayer;
28
+ export declare function baseWriter(writer: BaseCacheWriter): ReplicaBaseWriter;
29
+ export declare function metadataFromTarget(target: ReplicaIndexTarget): CacheIndexMetadata;
30
+ export declare function indexKeyFromTarget(target: ReplicaIndexTarget): string;
31
+ export declare function replicaClientRequestExtensions<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>): {
32
+ readonly extensions?: Readonly<Record<string, unknown>>;
33
+ };
34
+ export declare function validatedCommandAuthorityContract(value: ReplicaCommandSurfaceContract): RegisteredCommandAuthorityContract;
35
+ export declare function canonicalTrustedPresets(value: readonly DistributedTrustedPreset[]): readonly DistributedTrustedPreset[];
36
+ export declare function trustedPresetInventoryFingerprint(value: readonly DistributedTrustedPreset[]): string;
37
+ export declare function trustedPresetDescriptorFingerprint(value: readonly ReplicaTrustedPresetDescriptor[]): string;
38
+ export declare function operationKey<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>, variables: TVariables): string;
39
+ export declare function validatedSurfaceIdentity(value: NonNullable<ReplicaOperationArtifact['protocol']>['surface']): string;
40
+ export declare function snapshotFrom<TData>(materialized: MaterializedReplicaResult<TData>, state: QueryState): ReplicaSnapshot<TData>;
41
+ export declare function snapshotEqual<TData>(left: ReplicaSnapshot<TData>, right: ReplicaSnapshot<TData>): boolean;
42
+ export declare function freezeErrors(errors: readonly GqlError[]): readonly GqlError[];
43
+ export declare function stableErrors(current: readonly GqlError[], next: readonly GqlError[]): readonly GqlError[];
44
+ export declare function graphqlError(error: unknown): GqlError;
45
+ export declare function assertWriteSource(source: ReplicaWriteSource): void;
46
+ export declare function protocolOperationSource(source: ReplicaWriteSource): OperationProtocolSource;
47
+ export { reportSafely };
48
+ export declare const reportUnhandledObserverError: typeof reportUnhandledError;