@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,657 @@
1
+ import type { GqlError, GraphqlVariables } from '../types.js';
2
+ import type { DistributedCommandMetadata, DistributedLiveCursor, DistributedTrustedPresetCodec, GraphqlResponseExtensions } from '../protocol.js';
3
+ import type { ReplicaDiagnosticsSink } from './diagnostics.js';
4
+ export type ReplicaRevision = number | string | bigint;
5
+ export type ReplicaValue = null | boolean | number | string | readonly ReplicaValue[] | {
6
+ readonly [key: string]: ReplicaValue;
7
+ };
8
+ export type ReplicaIndexRecordChange = {
9
+ readonly kind: 'upsert';
10
+ readonly model: string;
11
+ readonly key: string;
12
+ readonly fields: Readonly<Record<string, ReplicaValue>>;
13
+ readonly dependencies?: readonly string[];
14
+ } | {
15
+ readonly kind: 'delete';
16
+ readonly model: string;
17
+ readonly key: string;
18
+ readonly dependencies?: readonly string[];
19
+ };
20
+ export type ReplicaIndexRelationshipChange = {
21
+ readonly kind: 'link' | 'unlink';
22
+ readonly sourceModel: string;
23
+ readonly field: string;
24
+ readonly targetModel: string;
25
+ readonly sourceKey: string;
26
+ readonly targetKey: string;
27
+ readonly dependencies: readonly string[];
28
+ };
29
+ export type ReplicaIndexDependencyChange = {
30
+ readonly kind: 'invalidate';
31
+ readonly dependencies: readonly string[];
32
+ };
33
+ /** Compiler/runtime semantic evidence carried by one optimistic layer. */
34
+ export type ReplicaIndexSemanticChange = ReplicaIndexRecordChange | ReplicaIndexRelationshipChange | ReplicaIndexDependencyChange;
35
+ export type ReplicaIndexCoverage = {
36
+ readonly kind: 'complete';
37
+ } | {
38
+ readonly kind: 'unknown';
39
+ } | {
40
+ readonly kind: 'offset';
41
+ readonly offset: number;
42
+ readonly limit?: number;
43
+ readonly returned?: number;
44
+ readonly hasNext?: boolean;
45
+ } | {
46
+ readonly kind: 'cursor';
47
+ readonly after?: ReplicaValue;
48
+ readonly before?: ReplicaValue;
49
+ readonly first?: number;
50
+ readonly last?: number;
51
+ readonly start?: ReplicaValue;
52
+ readonly end?: ReplicaValue;
53
+ readonly hasNext?: boolean;
54
+ readonly hasPrevious?: boolean;
55
+ };
56
+ /** Minimal model identity emitted by a generated operation artifact. */
57
+ export type ReplicaModelArtifact = {
58
+ readonly id: string;
59
+ readonly identityFields: readonly string[];
60
+ };
61
+ export type ReplicaLiteralValue = {
62
+ readonly kind: 'literal';
63
+ readonly value: ReplicaValue;
64
+ };
65
+ export type ReplicaVariableValue = {
66
+ readonly kind: 'variable';
67
+ readonly name: string;
68
+ };
69
+ export type ReplicaListValue = {
70
+ readonly kind: 'list';
71
+ readonly items: readonly ReplicaArgumentValue[];
72
+ };
73
+ export type ReplicaObjectValue = {
74
+ readonly kind: 'object';
75
+ readonly fields: Readonly<Record<string, ReplicaArgumentValue>>;
76
+ };
77
+ export type ReplicaArgumentValue = ReplicaLiteralValue | ReplicaVariableValue | ReplicaListValue | ReplicaObjectValue;
78
+ export type ReplicaArgumentsArtifact = Readonly<Record<string, ReplicaArgumentValue>>;
79
+ export type ReplicaVariableScalarInputRef = {
80
+ readonly kind: 'scalar';
81
+ readonly scalar: string;
82
+ readonly codec: string;
83
+ readonly nullable: boolean;
84
+ };
85
+ export type ReplicaVariableEnumInputRef = {
86
+ readonly kind: 'enum';
87
+ readonly name: string;
88
+ readonly values: readonly string[];
89
+ readonly nullable: boolean;
90
+ };
91
+ export type ReplicaVariableNamedInputRef = {
92
+ readonly kind: 'input';
93
+ readonly name: string;
94
+ readonly nullable: boolean;
95
+ /** Required for filter inputs; omitted for other named inputs. */
96
+ readonly filterBaseDepth?: number;
97
+ };
98
+ export type ReplicaVariableListInputRef = {
99
+ readonly kind: 'list';
100
+ readonly nullable: boolean;
101
+ /** Most restrictive list-width cap across every use of this variable. */
102
+ readonly maxItems?: number;
103
+ readonly item: ReplicaVariableInputRef;
104
+ };
105
+ /** Compiler-owned GraphQL input coercion contract for one operation variable. */
106
+ export type ReplicaVariableInputRef = ReplicaVariableScalarInputRef | ReplicaVariableEnumInputRef | ReplicaVariableNamedInputRef | ReplicaVariableListInputRef;
107
+ export type ReplicaVariableFilterInputField = {
108
+ readonly field: string;
109
+ readonly scalar: string;
110
+ readonly codec: string;
111
+ /** Record-column nullability; comparison operands follow the GraphQL input grammar. */
112
+ readonly nullable: boolean;
113
+ readonly operators: readonly ReplicaFilterOperator[];
114
+ };
115
+ export type ReplicaVariableFilterInputTarget = {
116
+ readonly kind: 'input';
117
+ readonly name: string;
118
+ } | {
119
+ readonly kind: 'opaque';
120
+ };
121
+ export type ReplicaVariableFilterInputRelationship = {
122
+ readonly field: string;
123
+ readonly target: ReplicaVariableFilterInputTarget;
124
+ };
125
+ export type ReplicaVariableFilterInputDefinition = {
126
+ readonly kind: 'filter';
127
+ readonly model: string;
128
+ readonly fields: readonly ReplicaVariableFilterInputField[];
129
+ readonly relationships: readonly ReplicaVariableFilterInputRelationship[];
130
+ };
131
+ export type ReplicaVariableOrderInputField = {
132
+ readonly field: string;
133
+ readonly scalar: string;
134
+ readonly codec: string;
135
+ readonly nullable: boolean;
136
+ };
137
+ export type ReplicaVariableOrderInputDefinition = {
138
+ readonly kind: 'order';
139
+ readonly model: string;
140
+ readonly fields: readonly ReplicaVariableOrderInputField[];
141
+ readonly values: readonly string[];
142
+ };
143
+ export type ReplicaVariableInputDefinition = ReplicaVariableFilterInputDefinition | ReplicaVariableOrderInputDefinition;
144
+ export type ReplicaVariableCodecLimits = {
145
+ readonly maxDepth: number;
146
+ readonly maxBoolWidth: number;
147
+ readonly maxInList: number;
148
+ };
149
+ /** Exact variable codec emitted beside a generated operation artifact. */
150
+ export type ReplicaVariableCodecArtifact = {
151
+ readonly version: 1;
152
+ readonly limits: ReplicaVariableCodecLimits;
153
+ readonly variables: Readonly<Record<string, ReplicaVariableInputRef>>;
154
+ readonly inputs: Readonly<Record<string, ReplicaVariableInputDefinition>>;
155
+ };
156
+ export type ReplicaFilterOperator = '_eq' | '_neq' | '_gt' | '_gte' | '_lt' | '_lte' | '_in' | '_nin' | '_is_null' | '_like' | '_ilike' | '_contains' | '_contained_in' | '_has_key';
157
+ export type ReplicaFilterFieldArtifact = {
158
+ readonly field: string;
159
+ readonly scalar: string;
160
+ readonly codec: string;
161
+ readonly nullable: boolean;
162
+ readonly operators: readonly ReplicaFilterOperator[];
163
+ };
164
+ export type ReplicaRelationshipKind = 'has_many' | 'belongs_to' | 'many_to_many';
165
+ export type ReplicaRelationshipKeyMapping = {
166
+ readonly kind: 'direct';
167
+ readonly local: readonly string[];
168
+ readonly remote: readonly string[];
169
+ } | {
170
+ readonly kind: 'through';
171
+ readonly local: readonly string[];
172
+ readonly remote: readonly string[];
173
+ readonly table: string;
174
+ readonly sourceForeignKey: string;
175
+ readonly targetForeignKey: string;
176
+ } | {
177
+ readonly kind: 'through_opaque';
178
+ readonly local: readonly string[];
179
+ readonly remote: readonly string[];
180
+ readonly dependency: string;
181
+ } | {
182
+ readonly kind: 'embedded';
183
+ };
184
+ /**
185
+ * Compiler-owned relationship facts. Task 8 consumes this descriptor to
186
+ * resolve predicates and maintain links without rediscovering schema metadata.
187
+ */
188
+ export type ReplicaRelationshipArtifact = {
189
+ readonly field: string;
190
+ readonly targetModel: string;
191
+ readonly kind: ReplicaRelationshipKind;
192
+ readonly keyMapping: ReplicaRelationshipKeyMapping;
193
+ readonly maintenance: 'local' | 'revalidate';
194
+ readonly dependencies: readonly string[];
195
+ };
196
+ export type ReplicaFilterLiteral = {
197
+ readonly kind: 'string';
198
+ readonly value: string;
199
+ } | {
200
+ readonly kind: 'i64';
201
+ readonly value: number;
202
+ } | {
203
+ readonly kind: 'f64';
204
+ readonly value: number;
205
+ } | {
206
+ readonly kind: 'bool';
207
+ readonly value: boolean;
208
+ } | {
209
+ readonly kind: 'json';
210
+ readonly value: ReplicaValue;
211
+ } | {
212
+ readonly kind: 'null';
213
+ };
214
+ /** Manifest-v5 row-policy operand, preserved without ambient claim access. */
215
+ export type ReplicaFilterOperand = {
216
+ readonly kind: 'lit';
217
+ readonly value: ReplicaFilterLiteral;
218
+ } | {
219
+ readonly kind: 'claim';
220
+ readonly value: {
221
+ readonly header: string;
222
+ };
223
+ };
224
+ /** Manifest-v5 tagged row-policy expression. */
225
+ export type ReplicaFilterExpression = {
226
+ readonly kind: 'and' | 'or';
227
+ readonly value: readonly ReplicaFilterExpression[];
228
+ } | {
229
+ readonly kind: 'not';
230
+ readonly value: ReplicaFilterExpression;
231
+ } | {
232
+ readonly kind: 'cmp';
233
+ readonly value: {
234
+ readonly column: string;
235
+ readonly op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'contains' | 'contained_in' | 'has_key';
236
+ readonly rhs: ReplicaFilterOperand;
237
+ };
238
+ } | {
239
+ readonly kind: 'in';
240
+ readonly value: {
241
+ readonly column: string;
242
+ readonly values: readonly ReplicaFilterOperand[];
243
+ readonly negated: boolean;
244
+ };
245
+ } | {
246
+ readonly kind: 'is_null';
247
+ readonly value: {
248
+ readonly column: string;
249
+ readonly is_null: boolean;
250
+ };
251
+ } | {
252
+ readonly kind: 'rel';
253
+ readonly value: {
254
+ readonly field: string;
255
+ readonly predicate: ReplicaFilterExpression;
256
+ };
257
+ };
258
+ export type ReplicaRowPolicyArtifact = {
259
+ readonly kind: 'unrestricted';
260
+ } | {
261
+ readonly kind: 'server_only';
262
+ } | {
263
+ readonly kind: 'predicate';
264
+ readonly expression: ReplicaFilterExpression;
265
+ };
266
+ export type ReplicaFilterArtifact = {
267
+ /** Exact literal or variable supplying the operation's `where` input. */
268
+ readonly input?: ReplicaArgumentValue;
269
+ readonly fields: readonly ReplicaFilterFieldArtifact[];
270
+ readonly relationships: readonly ReplicaRelationshipArtifact[];
271
+ readonly rowPolicy: ReplicaRowPolicyArtifact;
272
+ };
273
+ export type ReplicaOrderFieldArtifact = {
274
+ readonly field: string;
275
+ readonly scalar: string;
276
+ readonly codec: string;
277
+ readonly nullable: boolean;
278
+ };
279
+ export type ReplicaOrderTieBreakerArtifact = {
280
+ readonly field: string;
281
+ readonly scalar: string;
282
+ readonly codec: string;
283
+ /** Generated identity fields are always non-null. */
284
+ readonly nullable: false;
285
+ };
286
+ export type ReplicaOrderArtifact = {
287
+ /** Exact literal or variable supplying the operation's `order_by` input. */
288
+ readonly input?: ReplicaArgumentValue;
289
+ readonly fields: readonly ReplicaOrderFieldArtifact[];
290
+ /** Server-appended primary-key fields, in their exact comparison order. */
291
+ readonly tieBreakers: readonly ReplicaOrderTieBreakerArtifact[];
292
+ };
293
+ export type ReplicaPaginationDisposition = 'local' | 'revalidate';
294
+ type ReplicaPaginationPolicies = {
295
+ readonly insert: ReplicaPaginationDisposition;
296
+ readonly delete: ReplicaPaginationDisposition;
297
+ readonly reorder: ReplicaPaginationDisposition;
298
+ readonly stableUpdate: ReplicaPaginationDisposition;
299
+ };
300
+ export type ReplicaPaginationArtifact = ReplicaPaginationPolicies & ({
301
+ readonly kind: 'complete' | 'offset';
302
+ } | {
303
+ /**
304
+ * Cursor locality is unavailable until the compiler emits a
305
+ * versioned proof IR understood by the runtime.
306
+ */
307
+ readonly kind: 'cursor';
308
+ });
309
+ export type ReplicaCoverageArtifact = {
310
+ readonly kind: 'complete';
311
+ } | {
312
+ readonly kind: 'offset';
313
+ readonly offsetArgument?: string;
314
+ readonly limitArgument?: string;
315
+ readonly defaultLimit?: number;
316
+ readonly maxLimit?: number;
317
+ } | {
318
+ readonly kind: 'cursor';
319
+ readonly afterArgument?: string;
320
+ readonly beforeArgument?: string;
321
+ readonly firstArgument?: string;
322
+ readonly lastArgument?: string;
323
+ };
324
+ export type ReplicaScalarSelection = {
325
+ readonly kind: 'scalar';
326
+ /** GraphQL response key after aliases are applied. */
327
+ readonly responseKey: string;
328
+ /** Canonical schema/read-model field name. */
329
+ readonly field: string;
330
+ /** Exact scalar codec and nullability emitted by the client compiler. */
331
+ readonly codec: string;
332
+ readonly nullable: boolean;
333
+ /** Wire-only identity fields set this false. */
334
+ readonly expose?: boolean;
335
+ };
336
+ export type ReplicaSelectionStorage = {
337
+ readonly kind: 'normalized';
338
+ readonly model: string;
339
+ readonly identityFields: readonly string[];
340
+ } | {
341
+ readonly kind: 'embedded';
342
+ };
343
+ export type ReplicaBranchSemantic = 'relationship' | 'aggregate' | 'aggregate_fields' | 'aggregate_nodes';
344
+ /** Recursive compiler-owned object algebra used by manifest v7 artifacts. */
345
+ export type ReplicaObjectSelection = {
346
+ readonly typename: string;
347
+ readonly storage: ReplicaSelectionStorage;
348
+ readonly members: readonly ReplicaObjectMember[];
349
+ };
350
+ type ReplicaObjectBranchBase = {
351
+ readonly kind: 'branch';
352
+ readonly responseKey: string;
353
+ readonly field: string;
354
+ readonly cardinality: 'one' | 'many';
355
+ readonly nullable: boolean;
356
+ readonly arguments?: ReplicaArgumentsArtifact;
357
+ readonly dependencies: readonly string[];
358
+ readonly coverage?: ReplicaCoverageArtifact;
359
+ readonly filter?: ReplicaFilterArtifact;
360
+ readonly order?: ReplicaOrderArtifact;
361
+ readonly pagination?: ReplicaPaginationArtifact;
362
+ readonly selection: ReplicaObjectSelection;
363
+ };
364
+ export type ReplicaObjectBranch = (ReplicaObjectBranchBase & {
365
+ readonly semantic: 'relationship';
366
+ readonly relationship: ReplicaRelationshipArtifact;
367
+ }) | (ReplicaObjectBranchBase & {
368
+ readonly semantic: Exclude<ReplicaBranchSemantic, 'relationship'>;
369
+ readonly relationship?: never;
370
+ });
371
+ export type ReplicaObjectMember = ReplicaScalarSelection | ReplicaObjectBranch;
372
+ export type ReplicaRootSelection = {
373
+ readonly responseKey: string;
374
+ readonly field: string;
375
+ readonly cardinality: 'one' | 'many';
376
+ readonly nullable: boolean;
377
+ readonly arguments?: ReplicaArgumentsArtifact;
378
+ readonly dependencies: readonly string[];
379
+ readonly coverage?: ReplicaCoverageArtifact;
380
+ readonly filter?: ReplicaFilterArtifact;
381
+ readonly order?: ReplicaOrderArtifact;
382
+ readonly pagination?: ReplicaPaginationArtifact;
383
+ readonly selection: ReplicaObjectSelection;
384
+ };
385
+ /**
386
+ * Narrow runtime contract expected from generated code.
387
+ *
388
+ * It deliberately does not mirror the Rust client-manifest JSON. The compiler
389
+ * owns lowering the manifest and GraphQL AST into this executable descriptor.
390
+ */
391
+ type ReplicaOperationArtifactBase<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables> = {
392
+ readonly id: string;
393
+ readonly document: string;
394
+ /** Normalized compiler-owned provenance for diagnostics and support tooling. */
395
+ readonly source?: ReplicaOperationSourceLocation;
396
+ readonly roots: readonly ReplicaRootSelection[];
397
+ readonly live?: {
398
+ readonly id: string;
399
+ readonly document: string;
400
+ };
401
+ /** Phantom slots preserve generated result/variables types. */
402
+ readonly __result?: TData;
403
+ readonly __variables?: TVariables;
404
+ };
405
+ export type ReplicaOperationSourceLocation = {
406
+ readonly path: string;
407
+ readonly line: number;
408
+ readonly column: number;
409
+ };
410
+ export type ReplicaOperationProtocol = {
411
+ readonly version: 1;
412
+ /** Opaque service schema fingerprint, compared byte-for-byte. */
413
+ readonly schemaHash: string;
414
+ readonly surface: ReplicaClientSurface;
415
+ /** Opaque operation identity, required to match the artifact id exactly. */
416
+ readonly operation: string;
417
+ /**
418
+ * Exact descriptor union for the selected client surface. Generated
419
+ * artifacts repeat this small static contract so every query can validate
420
+ * scope-bound preset values without depending on command registration.
421
+ */
422
+ readonly trustedPresets: readonly ReplicaSurfaceTrustedPresetDescriptor[];
423
+ };
424
+ export type ReplicaSurfaceTrustedPresetDescriptor = {
425
+ readonly name: string;
426
+ readonly codec: DistributedTrustedPresetCodec;
427
+ };
428
+ /** Exact static client surface selected at code-generation time. */
429
+ export type ReplicaClientSurface = {
430
+ readonly kind: 'role';
431
+ readonly name: string;
432
+ } | {
433
+ readonly kind: 'application';
434
+ readonly name: string;
435
+ readonly roles: readonly string[];
436
+ };
437
+ /** Compiler-owned causal artifact. Protocol and variable identity are inseparable. */
438
+ export type ReplicaProtocolOperationArtifact<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables> = ReplicaOperationArtifactBase<TData, TVariables> & {
439
+ readonly protocol: ReplicaOperationProtocol;
440
+ /** Exact compiler-owned GraphQL variable coercion and identity contract. */
441
+ readonly variableCodec: ReplicaVariableCodecArtifact;
442
+ };
443
+ export type ReplicaOperationArtifact<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables> = ReplicaProtocolOperationArtifact<TData, TVariables>;
444
+ export type ReplicaWriteSource = 'network' | 'live' | 'ssr' | 'restore' | 'projected';
445
+ export type ReplicaResultEnvelope<TData = unknown> = {
446
+ readonly data?: TData | null;
447
+ readonly errors?: readonly GqlError[];
448
+ /** Strictly parsed Distributed v1 response metadata. */
449
+ readonly extensions?: GraphqlResponseExtensions;
450
+ };
451
+ export type ReplicaTransportRequest<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables> = {
452
+ readonly operation: 'query' | 'live';
453
+ readonly operationId: string;
454
+ readonly document: string;
455
+ readonly variables: TVariables;
456
+ readonly artifact: ReplicaOperationArtifact<TData, TVariables>;
457
+ /** Generated surface/schema selector forwarded as GraphQL request extensions. */
458
+ readonly extensions?: Readonly<Record<string, unknown>>;
459
+ /**
460
+ * Authorization-generation cancellation. Transports must forward this to
461
+ * their underlying HTTP request when they support cancellation.
462
+ */
463
+ readonly signal?: AbortSignal;
464
+ /** Latest server-issued cursors for the private generated resume extension. */
465
+ readonly resume?: readonly DistributedLiveCursor[];
466
+ };
467
+ export type ReplicaLiveObserver<TData = unknown> = {
468
+ next(result: ReplicaResultEnvelope<TData>): void;
469
+ error(error: unknown): void;
470
+ complete(): void;
471
+ };
472
+ export type ReplicaTransport = {
473
+ fetch<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables>(request: ReplicaTransportRequest<TData, TVariables>): Promise<ReplicaResultEnvelope<TData>>;
474
+ subscribe?<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables>(request: ReplicaTransportRequest<TData, TVariables>, observer: ReplicaLiveObserver<TData>): () => void;
475
+ };
476
+ export type ReplicaStatus = 'loading' | 'ready' | 'stale' | 'error';
477
+ export type ReplicaLiveState = 'off' | 'connecting' | 'active' | 'error';
478
+ /** The exact runtime shape while some selected cache fields are still absent. */
479
+ export type ReplicaSparse<T> = T extends readonly (infer TItem)[] ? readonly ReplicaSparse<TItem>[] : T extends object ? {
480
+ readonly [K in keyof T]?: ReplicaSparse<T[K]>;
481
+ } : T;
482
+ type ReplicaSnapshotState = {
483
+ readonly fetching: boolean;
484
+ readonly errors: readonly GqlError[];
485
+ readonly live: ReplicaLiveState;
486
+ };
487
+ /**
488
+ * A structurally complete snapshot carries the generated result type even
489
+ * while its freshness is stale or a refresh failed. Only snapshots missing
490
+ * selected fields or index structure expose a deep sparse result.
491
+ */
492
+ export type ReplicaSnapshot<TData> = ReplicaSnapshotState & (({
493
+ readonly data: TData;
494
+ readonly complete: true;
495
+ } & ({
496
+ readonly status: 'ready';
497
+ readonly stale: false;
498
+ } | {
499
+ readonly status: 'stale';
500
+ readonly stale: true;
501
+ } | {
502
+ readonly status: 'error';
503
+ readonly stale: boolean;
504
+ })) | {
505
+ readonly data: ReplicaSparse<TData>;
506
+ readonly status: 'loading';
507
+ readonly stale: false;
508
+ readonly complete: false;
509
+ } | {
510
+ readonly data: ReplicaSparse<TData>;
511
+ readonly status: 'stale';
512
+ readonly stale: true;
513
+ readonly complete: false;
514
+ } | {
515
+ readonly data: ReplicaSparse<TData>;
516
+ readonly status: 'error';
517
+ readonly stale: boolean;
518
+ readonly complete: false;
519
+ });
520
+ export type ReplicaWatch<TData> = {
521
+ get(): ReplicaSnapshot<TData>;
522
+ subscribe(listener: (snapshot: ReplicaSnapshot<TData>) => void): () => void;
523
+ refresh(): Promise<void>;
524
+ destroy(): void;
525
+ };
526
+ export type WatchReplicaOptions = {
527
+ readonly live?: boolean;
528
+ };
529
+ export type DistributedReplicaOptions = {
530
+ readonly transport?: ReplicaTransport;
531
+ readonly onObserverError?: (error: AggregateError) => void;
532
+ /** Opt-in framework-neutral diagnostics; absent in production by default. */
533
+ readonly diagnostics?: ReplicaDiagnosticsSink;
534
+ };
535
+ /** Server-issued authorization/cache namespace. Client-decoded claims never create one. */
536
+ export type ReplicaAuthoritativeScope = {
537
+ readonly protocolVersion: 1;
538
+ readonly schemaHash: string;
539
+ readonly cacheScope: string;
540
+ };
541
+ /**
542
+ * Opaque, engine-independent SSR transfer owned by Distributed.
543
+ *
544
+ * `payload` is intentionally not a public cache-engine schema. Applications
545
+ * pass the value back to `hydrate` without interpreting it.
546
+ */
547
+ export type ReplicaDehydratedState = {
548
+ readonly version: 1;
549
+ readonly scope: ReplicaAuthoritativeScope;
550
+ readonly payload: unknown;
551
+ };
552
+ export type ReplicaRecordInspection = {
553
+ readonly key: string;
554
+ readonly revision: string;
555
+ readonly incarnation: string;
556
+ readonly presentFields: readonly string[];
557
+ };
558
+ export type ReplicaIndexInspection = {
559
+ readonly key: string;
560
+ readonly revision: string;
561
+ readonly staleRevision?: string;
562
+ readonly records: readonly string[];
563
+ readonly complete: boolean;
564
+ readonly field: string;
565
+ readonly parent?: string;
566
+ readonly arguments: Readonly<Record<string, ReplicaValue>>;
567
+ readonly coverage: ReplicaIndexCoverage;
568
+ readonly dependencies: readonly string[];
569
+ readonly staleReason?: string;
570
+ readonly nullValue: boolean;
571
+ };
572
+ export type ReplicaIdentity = ReplicaValue | readonly ReplicaValue[];
573
+ /** Exact relationship identity used to target authoritative query revalidation. */
574
+ export type ReplicaRevalidationRelationship = {
575
+ readonly sourceModel: string;
576
+ readonly field: string;
577
+ readonly targetModel: string;
578
+ };
579
+ /**
580
+ * Compiler-owned inventory used to find active operations affected by a
581
+ * command. An empty inventory conservatively targets every active operation.
582
+ */
583
+ export type ReplicaRevalidationPlan = {
584
+ readonly dependencies: readonly string[];
585
+ readonly models: readonly string[];
586
+ readonly relationships: readonly ReplicaRevalidationRelationship[];
587
+ };
588
+ export type ReplicaIndexTarget = {
589
+ readonly parent?: string;
590
+ readonly field: string;
591
+ readonly arguments?: Readonly<Record<string, ReplicaValue>>;
592
+ readonly coverage?: ReplicaIndexCoverage;
593
+ readonly dependencies?: readonly string[];
594
+ readonly complete?: boolean;
595
+ readonly staleReason?: string;
596
+ readonly nullValue?: boolean;
597
+ };
598
+ export type ReplicaRecordPatch = {
599
+ readonly fields?: Readonly<Record<string, ReplicaValue>>;
600
+ readonly links?: Readonly<Record<string, string | readonly string[] | null>>;
601
+ };
602
+ export interface ReplicaOptimisticWriter {
603
+ writeRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity, patch: ReplicaRecordPatch): void;
604
+ tombstoneRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity): void;
605
+ writeIndex(target: ReplicaIndexTarget, records: readonly string[]): void;
606
+ deleteIndex(target: ReplicaIndexTarget): void;
607
+ }
608
+ export interface ReplicaBaseWriter {
609
+ writeRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity, revision: ReplicaRevision, patch: ReplicaRecordPatch & {
610
+ readonly incarnation?: ReplicaRevision;
611
+ }): boolean;
612
+ tombstoneRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity, revision: ReplicaRevision): boolean;
613
+ writeIndex(target: ReplicaIndexTarget, records: readonly string[], revision: ReplicaRevision): boolean;
614
+ deleteIndex(target: ReplicaIndexTarget, revision: ReplicaRevision): boolean;
615
+ }
616
+ export interface DistributedReplica {
617
+ /** The current server-issued scope, absent until authoritative evidence arrives. */
618
+ readonly scope: ReplicaAuthoritativeScope | undefined;
619
+ /** Monotonic local fence for authorization changes and server scope changes. */
620
+ readonly authorizationGeneration: number;
621
+ read<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>, variables: TVariables): ReplicaSnapshot<TData>;
622
+ watch<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>, variables: TVariables, options?: WatchReplicaOptions): ReplicaWatch<TData>;
623
+ writeResult<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>, variables: TVariables, envelope: ReplicaResultEnvelope<TData>, source: ReplicaWriteSource): void;
624
+ /**
625
+ * Force deduplicated authoritative reads for active operations selected by a
626
+ * compiler-owned dependency/model/relationship inventory.
627
+ */
628
+ revalidate(plan: ReplicaRevalidationPlan): Promise<void>;
629
+ /**
630
+ * Proactively closes the current authorization generation.
631
+ *
632
+ * Token/session changes may call this before the next server response, but
633
+ * they cannot choose or restore a cache scope.
634
+ */
635
+ invalidateAuthorization(): void;
636
+ /** Serialize confirmed state reachable from operations rendered by this replica. */
637
+ dehydrate(): ReplicaDehydratedState;
638
+ /**
639
+ * Restore a server-rendered payload against the independently authoritative
640
+ * scope for the current SSR response. Returns false on scope/schema mismatch
641
+ * and never partially restores malformed state. Persisted state must wait for
642
+ * a fresh server scope and pass that scope here.
643
+ */
644
+ hydrate(state: ReplicaDehydratedState, authoritativeScope: ReplicaAuthoritativeScope): boolean;
645
+ createOptimisticLayer(id: string, update: (writer: ReplicaOptimisticWriter) => void, semanticChanges?: readonly ReplicaIndexSemanticChange[]): void;
646
+ markOptimisticLayerAccepted(id: string, receipt?: DistributedCommandMetadata): boolean;
647
+ confirmOptimisticLayer<T>(id: string, update: (writer: ReplicaBaseWriter) => T): T;
648
+ rejectOptimisticLayer(id: string): boolean;
649
+ tombstoneRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity, revision: ReplicaRevision): boolean;
650
+ markIndexStale(target: ReplicaIndexTarget, reason: string): boolean;
651
+ retainRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity): void;
652
+ releaseRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity): void;
653
+ gc(): readonly string[];
654
+ inspectRecord(model: ReplicaModelArtifact, identity: ReplicaIdentity): ReplicaRecordInspection | undefined;
655
+ inspectIndex(target: ReplicaIndexTarget): ReplicaIndexInspection | undefined;
656
+ }
657
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { type GqlDocument } from './document.js';
2
+ import type { GqlAuth, GqlResult, GraphqlVariables } from './types.js';
3
+ /** Fetch-compatible transport, including SvelteKit's request-scoped `fetch`. */
4
+ export type FetchLike = typeof globalThis.fetch;
5
+ export type RequestGraphqlOptions = {
6
+ /** Override the runtime's global fetch implementation. */
7
+ fetch?: FetchLike;
8
+ /** Framework-owned GraphQL request extensions. */
9
+ extensions?: Readonly<Record<string, unknown>>;
10
+ /** Cancel the underlying HTTP request when its authorization generation closes. */
11
+ signal?: AbortSignal;
12
+ };
13
+ /** POST a GraphQL document to `url`. */
14
+ export declare function requestGraphql<TData = Record<string, unknown>, TVariables extends GraphqlVariables = GraphqlVariables>(url: string, document: GqlDocument<TData, TVariables>, auth?: GqlAuth, variables?: TVariables, options?: RequestGraphqlOptions): Promise<GqlResult<TData>>;
15
+ export type { GqlDocument } from './document.js';
16
+ export { documentToString } from './document.js';
17
+ export { buildAuthHeaders } from './auth-headers.js';