@syncular/core 0.0.1-60

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 (72) hide show
  1. package/dist/blobs.d.ts +137 -0
  2. package/dist/blobs.d.ts.map +1 -0
  3. package/dist/blobs.js +47 -0
  4. package/dist/blobs.js.map +1 -0
  5. package/dist/conflict.d.ts +22 -0
  6. package/dist/conflict.d.ts.map +1 -0
  7. package/dist/conflict.js +81 -0
  8. package/dist/conflict.js.map +1 -0
  9. package/dist/index.d.ts +21 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +30 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/kysely-serialize.d.ts +22 -0
  14. package/dist/kysely-serialize.d.ts.map +1 -0
  15. package/dist/kysely-serialize.js +147 -0
  16. package/dist/kysely-serialize.js.map +1 -0
  17. package/dist/logger.d.ts +46 -0
  18. package/dist/logger.d.ts.map +1 -0
  19. package/dist/logger.js +48 -0
  20. package/dist/logger.js.map +1 -0
  21. package/dist/proxy/index.d.ts +5 -0
  22. package/dist/proxy/index.d.ts.map +1 -0
  23. package/dist/proxy/index.js +5 -0
  24. package/dist/proxy/index.js.map +1 -0
  25. package/dist/proxy/types.d.ts +54 -0
  26. package/dist/proxy/types.d.ts.map +1 -0
  27. package/dist/proxy/types.js +7 -0
  28. package/dist/proxy/types.js.map +1 -0
  29. package/dist/schemas/blobs.d.ts +76 -0
  30. package/dist/schemas/blobs.d.ts.map +1 -0
  31. package/dist/schemas/blobs.js +63 -0
  32. package/dist/schemas/blobs.js.map +1 -0
  33. package/dist/schemas/common.d.ts +28 -0
  34. package/dist/schemas/common.d.ts.map +1 -0
  35. package/dist/schemas/common.js +26 -0
  36. package/dist/schemas/common.js.map +1 -0
  37. package/dist/schemas/index.d.ts +7 -0
  38. package/dist/schemas/index.d.ts.map +1 -0
  39. package/dist/schemas/index.js +7 -0
  40. package/dist/schemas/index.js.map +1 -0
  41. package/dist/schemas/sync.d.ts +391 -0
  42. package/dist/schemas/sync.d.ts.map +1 -0
  43. package/dist/schemas/sync.js +156 -0
  44. package/dist/schemas/sync.js.map +1 -0
  45. package/dist/scopes/index.d.ts +65 -0
  46. package/dist/scopes/index.d.ts.map +1 -0
  47. package/dist/scopes/index.js +67 -0
  48. package/dist/scopes/index.js.map +1 -0
  49. package/dist/transforms.d.ts +146 -0
  50. package/dist/transforms.d.ts.map +1 -0
  51. package/dist/transforms.js +155 -0
  52. package/dist/transforms.js.map +1 -0
  53. package/dist/types.d.ts +129 -0
  54. package/dist/types.d.ts.map +1 -0
  55. package/dist/types.js +20 -0
  56. package/dist/types.js.map +1 -0
  57. package/package.json +56 -0
  58. package/src/__tests__/conflict.test.ts +325 -0
  59. package/src/blobs.ts +187 -0
  60. package/src/conflict.ts +92 -0
  61. package/src/index.ts +30 -0
  62. package/src/kysely-serialize.ts +214 -0
  63. package/src/logger.ts +80 -0
  64. package/src/proxy/index.ts +10 -0
  65. package/src/proxy/types.ts +57 -0
  66. package/src/schemas/blobs.ts +101 -0
  67. package/src/schemas/common.ts +45 -0
  68. package/src/schemas/index.ts +7 -0
  69. package/src/schemas/sync.ts +222 -0
  70. package/src/scopes/index.ts +122 -0
  71. package/src/transforms.ts +256 -0
  72. package/src/types.ts +158 -0
@@ -0,0 +1,391 @@
1
+ /**
2
+ * @syncular/core - Sync protocol Zod schemas
3
+ *
4
+ * These schemas define the sync protocol types and can be used for:
5
+ * - Runtime validation
6
+ * - OpenAPI spec generation
7
+ * - Type inference
8
+ */
9
+ import { z } from 'zod';
10
+ export declare const SyncOpSchema: z.ZodEnum<{
11
+ delete: "delete";
12
+ upsert: "upsert";
13
+ }>;
14
+ export type SyncOp = z.infer<typeof SyncOpSchema>;
15
+ /**
16
+ * Scope values in a subscription request (can be arrays)
17
+ */
18
+ export declare const ScopeValuesSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
19
+ export declare const SyncOperationSchema: z.ZodObject<{
20
+ table: z.ZodString;
21
+ row_id: z.ZodString;
22
+ op: z.ZodEnum<{
23
+ delete: "delete";
24
+ upsert: "upsert";
25
+ }>;
26
+ payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
27
+ base_version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
28
+ }, z.core.$strip>;
29
+ export type SyncOperation = z.infer<typeof SyncOperationSchema>;
30
+ export declare const SyncPushRequestSchema: z.ZodObject<{
31
+ clientId: z.ZodString;
32
+ clientCommitId: z.ZodString;
33
+ operations: z.ZodArray<z.ZodObject<{
34
+ table: z.ZodString;
35
+ row_id: z.ZodString;
36
+ op: z.ZodEnum<{
37
+ delete: "delete";
38
+ upsert: "upsert";
39
+ }>;
40
+ payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
+ base_version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
42
+ }, z.core.$strip>>;
43
+ schemaVersion: z.ZodNumber;
44
+ }, z.core.$strip>;
45
+ export type SyncPushRequest = z.infer<typeof SyncPushRequestSchema>;
46
+ export declare const SyncOperationResultSchema: z.ZodUnion<readonly [z.ZodObject<{
47
+ opIndex: z.ZodNumber;
48
+ status: z.ZodLiteral<"applied">;
49
+ }, z.core.$strip>, z.ZodObject<{
50
+ opIndex: z.ZodNumber;
51
+ status: z.ZodLiteral<"conflict">;
52
+ message: z.ZodString;
53
+ server_version: z.ZodNumber;
54
+ server_row: z.ZodUnknown;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ opIndex: z.ZodNumber;
57
+ status: z.ZodLiteral<"error">;
58
+ error: z.ZodString;
59
+ code: z.ZodOptional<z.ZodString>;
60
+ retriable: z.ZodOptional<z.ZodBoolean>;
61
+ }, z.core.$strip>]>;
62
+ export type SyncOperationResult = z.infer<typeof SyncOperationResultSchema>;
63
+ export declare const SyncPushResponseSchema: z.ZodObject<{
64
+ ok: z.ZodLiteral<true>;
65
+ status: z.ZodEnum<{
66
+ applied: "applied";
67
+ cached: "cached";
68
+ rejected: "rejected";
69
+ }>;
70
+ commitSeq: z.ZodOptional<z.ZodNumber>;
71
+ results: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
72
+ opIndex: z.ZodNumber;
73
+ status: z.ZodLiteral<"applied">;
74
+ }, z.core.$strip>, z.ZodObject<{
75
+ opIndex: z.ZodNumber;
76
+ status: z.ZodLiteral<"conflict">;
77
+ message: z.ZodString;
78
+ server_version: z.ZodNumber;
79
+ server_row: z.ZodUnknown;
80
+ }, z.core.$strip>, z.ZodObject<{
81
+ opIndex: z.ZodNumber;
82
+ status: z.ZodLiteral<"error">;
83
+ error: z.ZodString;
84
+ code: z.ZodOptional<z.ZodString>;
85
+ retriable: z.ZodOptional<z.ZodBoolean>;
86
+ }, z.core.$strip>]>>;
87
+ }, z.core.$strip>;
88
+ export type SyncPushResponse = z.infer<typeof SyncPushResponseSchema>;
89
+ export declare const SyncBootstrapStateSchema: z.ZodObject<{
90
+ asOfCommitSeq: z.ZodNumber;
91
+ tables: z.ZodArray<z.ZodString>;
92
+ tableIndex: z.ZodNumber;
93
+ rowCursor: z.ZodNullable<z.ZodString>;
94
+ }, z.core.$strip>;
95
+ export type SyncBootstrapState = z.infer<typeof SyncBootstrapStateSchema>;
96
+ export declare const SyncSubscriptionRequestSchema: z.ZodObject<{
97
+ id: z.ZodString;
98
+ shape: z.ZodString;
99
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
100
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
101
+ cursor: z.ZodNumber;
102
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
103
+ asOfCommitSeq: z.ZodNumber;
104
+ tables: z.ZodArray<z.ZodString>;
105
+ tableIndex: z.ZodNumber;
106
+ rowCursor: z.ZodNullable<z.ZodString>;
107
+ }, z.core.$strip>>>;
108
+ }, z.core.$strip>;
109
+ export type SyncSubscriptionRequest = z.infer<typeof SyncSubscriptionRequestSchema>;
110
+ export declare const SyncPullRequestSchema: z.ZodObject<{
111
+ clientId: z.ZodString;
112
+ limitCommits: z.ZodNumber;
113
+ limitSnapshotRows: z.ZodOptional<z.ZodNumber>;
114
+ maxSnapshotPages: z.ZodOptional<z.ZodNumber>;
115
+ dedupeRows: z.ZodOptional<z.ZodBoolean>;
116
+ subscriptions: z.ZodArray<z.ZodObject<{
117
+ id: z.ZodString;
118
+ shape: z.ZodString;
119
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
120
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
121
+ cursor: z.ZodNumber;
122
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
123
+ asOfCommitSeq: z.ZodNumber;
124
+ tables: z.ZodArray<z.ZodString>;
125
+ tableIndex: z.ZodNumber;
126
+ rowCursor: z.ZodNullable<z.ZodString>;
127
+ }, z.core.$strip>>>;
128
+ }, z.core.$strip>>;
129
+ }, z.core.$strip>;
130
+ export type SyncPullRequest = z.infer<typeof SyncPullRequestSchema>;
131
+ export declare const SyncChangeSchema: z.ZodObject<{
132
+ table: z.ZodString;
133
+ row_id: z.ZodString;
134
+ op: z.ZodEnum<{
135
+ delete: "delete";
136
+ upsert: "upsert";
137
+ }>;
138
+ row_json: z.ZodNullable<z.ZodUnknown>;
139
+ row_version: z.ZodNullable<z.ZodNumber>;
140
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
141
+ }, z.core.$strip>;
142
+ export type SyncChange = z.infer<typeof SyncChangeSchema>;
143
+ export declare const SyncCommitSchema: z.ZodObject<{
144
+ commitSeq: z.ZodNumber;
145
+ createdAt: z.ZodString;
146
+ actorId: z.ZodString;
147
+ changes: z.ZodArray<z.ZodObject<{
148
+ table: z.ZodString;
149
+ row_id: z.ZodString;
150
+ op: z.ZodEnum<{
151
+ delete: "delete";
152
+ upsert: "upsert";
153
+ }>;
154
+ row_json: z.ZodNullable<z.ZodUnknown>;
155
+ row_version: z.ZodNullable<z.ZodNumber>;
156
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
157
+ }, z.core.$strip>>;
158
+ }, z.core.$strip>;
159
+ export type SyncCommit = z.infer<typeof SyncCommitSchema>;
160
+ export declare const SyncSnapshotChunkRefSchema: z.ZodObject<{
161
+ id: z.ZodString;
162
+ byteLength: z.ZodNumber;
163
+ sha256: z.ZodString;
164
+ encoding: z.ZodLiteral<"ndjson">;
165
+ compression: z.ZodLiteral<"gzip">;
166
+ }, z.core.$strip>;
167
+ export type SyncSnapshotChunkRef = z.infer<typeof SyncSnapshotChunkRefSchema>;
168
+ export declare const SyncSnapshotSchema: z.ZodObject<{
169
+ table: z.ZodString;
170
+ rows: z.ZodArray<z.ZodUnknown>;
171
+ chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
172
+ id: z.ZodString;
173
+ byteLength: z.ZodNumber;
174
+ sha256: z.ZodString;
175
+ encoding: z.ZodLiteral<"ndjson">;
176
+ compression: z.ZodLiteral<"gzip">;
177
+ }, z.core.$strip>>>;
178
+ isFirstPage: z.ZodBoolean;
179
+ isLastPage: z.ZodBoolean;
180
+ }, z.core.$strip>;
181
+ export type SyncSnapshot = z.infer<typeof SyncSnapshotSchema>;
182
+ export declare const SyncPullSubscriptionResponseSchema: z.ZodObject<{
183
+ id: z.ZodString;
184
+ status: z.ZodEnum<{
185
+ active: "active";
186
+ revoked: "revoked";
187
+ }>;
188
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
189
+ bootstrap: z.ZodBoolean;
190
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
191
+ asOfCommitSeq: z.ZodNumber;
192
+ tables: z.ZodArray<z.ZodString>;
193
+ tableIndex: z.ZodNumber;
194
+ rowCursor: z.ZodNullable<z.ZodString>;
195
+ }, z.core.$strip>>>;
196
+ nextCursor: z.ZodNumber;
197
+ commits: z.ZodArray<z.ZodObject<{
198
+ commitSeq: z.ZodNumber;
199
+ createdAt: z.ZodString;
200
+ actorId: z.ZodString;
201
+ changes: z.ZodArray<z.ZodObject<{
202
+ table: z.ZodString;
203
+ row_id: z.ZodString;
204
+ op: z.ZodEnum<{
205
+ delete: "delete";
206
+ upsert: "upsert";
207
+ }>;
208
+ row_json: z.ZodNullable<z.ZodUnknown>;
209
+ row_version: z.ZodNullable<z.ZodNumber>;
210
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
211
+ }, z.core.$strip>>;
212
+ }, z.core.$strip>>;
213
+ snapshots: z.ZodOptional<z.ZodArray<z.ZodObject<{
214
+ table: z.ZodString;
215
+ rows: z.ZodArray<z.ZodUnknown>;
216
+ chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
217
+ id: z.ZodString;
218
+ byteLength: z.ZodNumber;
219
+ sha256: z.ZodString;
220
+ encoding: z.ZodLiteral<"ndjson">;
221
+ compression: z.ZodLiteral<"gzip">;
222
+ }, z.core.$strip>>>;
223
+ isFirstPage: z.ZodBoolean;
224
+ isLastPage: z.ZodBoolean;
225
+ }, z.core.$strip>>>;
226
+ }, z.core.$strip>;
227
+ export type SyncPullSubscriptionResponse = z.infer<typeof SyncPullSubscriptionResponseSchema>;
228
+ export declare const SyncPullResponseSchema: z.ZodObject<{
229
+ ok: z.ZodLiteral<true>;
230
+ subscriptions: z.ZodArray<z.ZodObject<{
231
+ id: z.ZodString;
232
+ status: z.ZodEnum<{
233
+ active: "active";
234
+ revoked: "revoked";
235
+ }>;
236
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
237
+ bootstrap: z.ZodBoolean;
238
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
239
+ asOfCommitSeq: z.ZodNumber;
240
+ tables: z.ZodArray<z.ZodString>;
241
+ tableIndex: z.ZodNumber;
242
+ rowCursor: z.ZodNullable<z.ZodString>;
243
+ }, z.core.$strip>>>;
244
+ nextCursor: z.ZodNumber;
245
+ commits: z.ZodArray<z.ZodObject<{
246
+ commitSeq: z.ZodNumber;
247
+ createdAt: z.ZodString;
248
+ actorId: z.ZodString;
249
+ changes: z.ZodArray<z.ZodObject<{
250
+ table: z.ZodString;
251
+ row_id: z.ZodString;
252
+ op: z.ZodEnum<{
253
+ delete: "delete";
254
+ upsert: "upsert";
255
+ }>;
256
+ row_json: z.ZodNullable<z.ZodUnknown>;
257
+ row_version: z.ZodNullable<z.ZodNumber>;
258
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
259
+ }, z.core.$strip>>;
260
+ }, z.core.$strip>>;
261
+ snapshots: z.ZodOptional<z.ZodArray<z.ZodObject<{
262
+ table: z.ZodString;
263
+ rows: z.ZodArray<z.ZodUnknown>;
264
+ chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
265
+ id: z.ZodString;
266
+ byteLength: z.ZodNumber;
267
+ sha256: z.ZodString;
268
+ encoding: z.ZodLiteral<"ndjson">;
269
+ compression: z.ZodLiteral<"gzip">;
270
+ }, z.core.$strip>>>;
271
+ isFirstPage: z.ZodBoolean;
272
+ isLastPage: z.ZodBoolean;
273
+ }, z.core.$strip>>>;
274
+ }, z.core.$strip>>;
275
+ }, z.core.$strip>;
276
+ export type SyncPullResponse = z.infer<typeof SyncPullResponseSchema>;
277
+ export declare const SyncCombinedRequestSchema: z.ZodObject<{
278
+ clientId: z.ZodString;
279
+ push: z.ZodOptional<z.ZodObject<{
280
+ clientCommitId: z.ZodString;
281
+ operations: z.ZodArray<z.ZodObject<{
282
+ table: z.ZodString;
283
+ row_id: z.ZodString;
284
+ op: z.ZodEnum<{
285
+ delete: "delete";
286
+ upsert: "upsert";
287
+ }>;
288
+ payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
289
+ base_version: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
290
+ }, z.core.$strip>>;
291
+ schemaVersion: z.ZodNumber;
292
+ }, z.core.$strip>>;
293
+ pull: z.ZodOptional<z.ZodObject<{
294
+ limitCommits: z.ZodNumber;
295
+ limitSnapshotRows: z.ZodOptional<z.ZodNumber>;
296
+ maxSnapshotPages: z.ZodOptional<z.ZodNumber>;
297
+ dedupeRows: z.ZodOptional<z.ZodBoolean>;
298
+ subscriptions: z.ZodArray<z.ZodObject<{
299
+ id: z.ZodString;
300
+ shape: z.ZodString;
301
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
302
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
303
+ cursor: z.ZodNumber;
304
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
305
+ asOfCommitSeq: z.ZodNumber;
306
+ tables: z.ZodArray<z.ZodString>;
307
+ tableIndex: z.ZodNumber;
308
+ rowCursor: z.ZodNullable<z.ZodString>;
309
+ }, z.core.$strip>>>;
310
+ }, z.core.$strip>>;
311
+ }, z.core.$strip>>;
312
+ }, z.core.$strip>;
313
+ export type SyncCombinedRequest = z.infer<typeof SyncCombinedRequestSchema>;
314
+ export declare const SyncCombinedResponseSchema: z.ZodObject<{
315
+ ok: z.ZodLiteral<true>;
316
+ push: z.ZodOptional<z.ZodObject<{
317
+ ok: z.ZodLiteral<true>;
318
+ status: z.ZodEnum<{
319
+ applied: "applied";
320
+ cached: "cached";
321
+ rejected: "rejected";
322
+ }>;
323
+ commitSeq: z.ZodOptional<z.ZodNumber>;
324
+ results: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
325
+ opIndex: z.ZodNumber;
326
+ status: z.ZodLiteral<"applied">;
327
+ }, z.core.$strip>, z.ZodObject<{
328
+ opIndex: z.ZodNumber;
329
+ status: z.ZodLiteral<"conflict">;
330
+ message: z.ZodString;
331
+ server_version: z.ZodNumber;
332
+ server_row: z.ZodUnknown;
333
+ }, z.core.$strip>, z.ZodObject<{
334
+ opIndex: z.ZodNumber;
335
+ status: z.ZodLiteral<"error">;
336
+ error: z.ZodString;
337
+ code: z.ZodOptional<z.ZodString>;
338
+ retriable: z.ZodOptional<z.ZodBoolean>;
339
+ }, z.core.$strip>]>>;
340
+ }, z.core.$strip>>;
341
+ pull: z.ZodOptional<z.ZodObject<{
342
+ ok: z.ZodLiteral<true>;
343
+ subscriptions: z.ZodArray<z.ZodObject<{
344
+ id: z.ZodString;
345
+ status: z.ZodEnum<{
346
+ active: "active";
347
+ revoked: "revoked";
348
+ }>;
349
+ scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
350
+ bootstrap: z.ZodBoolean;
351
+ bootstrapState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
352
+ asOfCommitSeq: z.ZodNumber;
353
+ tables: z.ZodArray<z.ZodString>;
354
+ tableIndex: z.ZodNumber;
355
+ rowCursor: z.ZodNullable<z.ZodString>;
356
+ }, z.core.$strip>>>;
357
+ nextCursor: z.ZodNumber;
358
+ commits: z.ZodArray<z.ZodObject<{
359
+ commitSeq: z.ZodNumber;
360
+ createdAt: z.ZodString;
361
+ actorId: z.ZodString;
362
+ changes: z.ZodArray<z.ZodObject<{
363
+ table: z.ZodString;
364
+ row_id: z.ZodString;
365
+ op: z.ZodEnum<{
366
+ delete: "delete";
367
+ upsert: "upsert";
368
+ }>;
369
+ row_json: z.ZodNullable<z.ZodUnknown>;
370
+ row_version: z.ZodNullable<z.ZodNumber>;
371
+ scopes: z.ZodRecord<z.ZodString, z.ZodString>;
372
+ }, z.core.$strip>>;
373
+ }, z.core.$strip>>;
374
+ snapshots: z.ZodOptional<z.ZodArray<z.ZodObject<{
375
+ table: z.ZodString;
376
+ rows: z.ZodArray<z.ZodUnknown>;
377
+ chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
378
+ id: z.ZodString;
379
+ byteLength: z.ZodNumber;
380
+ sha256: z.ZodString;
381
+ encoding: z.ZodLiteral<"ndjson">;
382
+ compression: z.ZodLiteral<"gzip">;
383
+ }, z.core.$strip>>>;
384
+ isFirstPage: z.ZodBoolean;
385
+ isLastPage: z.ZodBoolean;
386
+ }, z.core.$strip>>>;
387
+ }, z.core.$strip>>;
388
+ }, z.core.$strip>>;
389
+ }, z.core.$strip>;
390
+ export type SyncCombinedResponse = z.infer<typeof SyncCombinedResponseSchema>;
391
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/schemas/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,YAAY;;;EAA+B,CAAC;AACzD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAWlD;;GAEG;AACH,eAAO,MAAM,iBAAiB,uFAG7B,CAAC;AAMF,eAAO,MAAM,mBAAmB;;;;;;;;;iBAM9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAMhE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;iBAKhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAuBpE,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;mBAIpC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;iBAKjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAMtE,eAAO,MAAM,wBAAwB;;;;;iBAKnC,CAAC;AAEH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OAAO,sBAAsB,CAAC,CAAC;AAMtE,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIpC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIrC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * @syncular/core - Sync protocol Zod schemas
3
+ *
4
+ * These schemas define the sync protocol types and can be used for:
5
+ * - Runtime validation
6
+ * - OpenAPI spec generation
7
+ * - Type inference
8
+ */
9
+ import { z } from 'zod';
10
+ // ============================================================================
11
+ // Operation Types
12
+ // ============================================================================
13
+ export const SyncOpSchema = z.enum(['upsert', 'delete']);
14
+ // ============================================================================
15
+ // Scope Schemas
16
+ // ============================================================================
17
+ /**
18
+ * Stored scopes on a change (single values only)
19
+ */
20
+ const StoredScopesSchema = z.record(z.string(), z.string());
21
+ /**
22
+ * Scope values in a subscription request (can be arrays)
23
+ */
24
+ export const ScopeValuesSchema = z.record(z.string(), z.union([z.string(), z.array(z.string())]));
25
+ // ============================================================================
26
+ // Sync Operation Schema
27
+ // ============================================================================
28
+ export const SyncOperationSchema = z.object({
29
+ table: z.string(),
30
+ row_id: z.string(),
31
+ op: SyncOpSchema,
32
+ payload: z.record(z.string(), z.unknown()).nullable(),
33
+ base_version: z.number().int().nullable().optional(),
34
+ });
35
+ // ============================================================================
36
+ // Push Request/Response Schemas
37
+ // ============================================================================
38
+ export const SyncPushRequestSchema = z.object({
39
+ clientId: z.string().min(1),
40
+ clientCommitId: z.string().min(1),
41
+ operations: z.array(SyncOperationSchema).min(1),
42
+ schemaVersion: z.number().int().min(1),
43
+ });
44
+ const SyncOperationResultAppliedSchema = z.object({
45
+ opIndex: z.number().int(),
46
+ status: z.literal('applied'),
47
+ });
48
+ const SyncOperationResultConflictSchema = z.object({
49
+ opIndex: z.number().int(),
50
+ status: z.literal('conflict'),
51
+ message: z.string(),
52
+ server_version: z.number().int(),
53
+ server_row: z.unknown(),
54
+ });
55
+ const SyncOperationResultErrorSchema = z.object({
56
+ opIndex: z.number().int(),
57
+ status: z.literal('error'),
58
+ error: z.string(),
59
+ code: z.string().optional(),
60
+ retriable: z.boolean().optional(),
61
+ });
62
+ export const SyncOperationResultSchema = z.union([
63
+ SyncOperationResultAppliedSchema,
64
+ SyncOperationResultConflictSchema,
65
+ SyncOperationResultErrorSchema,
66
+ ]);
67
+ export const SyncPushResponseSchema = z.object({
68
+ ok: z.literal(true),
69
+ status: z.enum(['applied', 'cached', 'rejected']),
70
+ commitSeq: z.number().int().optional(),
71
+ results: z.array(SyncOperationResultSchema),
72
+ });
73
+ // ============================================================================
74
+ // Bootstrap State Schema
75
+ // ============================================================================
76
+ export const SyncBootstrapStateSchema = z.object({
77
+ asOfCommitSeq: z.number().int(),
78
+ tables: z.array(z.string()),
79
+ tableIndex: z.number().int(),
80
+ rowCursor: z.string().nullable(),
81
+ });
82
+ // ============================================================================
83
+ // Pull Request/Response Schemas
84
+ // ============================================================================
85
+ export const SyncSubscriptionRequestSchema = z.object({
86
+ id: z.string().min(1),
87
+ shape: z.string().min(1),
88
+ scopes: ScopeValuesSchema,
89
+ params: z.record(z.string(), z.unknown()).optional(),
90
+ cursor: z.number().int(),
91
+ bootstrapState: SyncBootstrapStateSchema.nullable().optional(),
92
+ });
93
+ export const SyncPullRequestSchema = z.object({
94
+ clientId: z.string().min(1),
95
+ limitCommits: z.number().int().min(1),
96
+ limitSnapshotRows: z.number().int().min(1).optional(),
97
+ maxSnapshotPages: z.number().int().min(1).optional(),
98
+ dedupeRows: z.boolean().optional(),
99
+ subscriptions: z.array(SyncSubscriptionRequestSchema),
100
+ });
101
+ export const SyncChangeSchema = z.object({
102
+ table: z.string(),
103
+ row_id: z.string(),
104
+ op: SyncOpSchema,
105
+ row_json: z.unknown().nullable(),
106
+ row_version: z.number().int().nullable(),
107
+ scopes: StoredScopesSchema,
108
+ });
109
+ export const SyncCommitSchema = z.object({
110
+ commitSeq: z.number().int(),
111
+ createdAt: z.string(),
112
+ actorId: z.string(),
113
+ changes: z.array(SyncChangeSchema),
114
+ });
115
+ export const SyncSnapshotChunkRefSchema = z.object({
116
+ id: z.string(),
117
+ byteLength: z.number().int(),
118
+ sha256: z.string(),
119
+ encoding: z.literal('ndjson'),
120
+ compression: z.literal('gzip'),
121
+ });
122
+ export const SyncSnapshotSchema = z.object({
123
+ table: z.string(),
124
+ rows: z.array(z.unknown()),
125
+ chunks: z.array(SyncSnapshotChunkRefSchema).optional(),
126
+ isFirstPage: z.boolean(),
127
+ isLastPage: z.boolean(),
128
+ });
129
+ export const SyncPullSubscriptionResponseSchema = z.object({
130
+ id: z.string(),
131
+ status: z.enum(['active', 'revoked']),
132
+ scopes: ScopeValuesSchema,
133
+ bootstrap: z.boolean(),
134
+ bootstrapState: SyncBootstrapStateSchema.nullable().optional(),
135
+ nextCursor: z.number().int(),
136
+ commits: z.array(SyncCommitSchema),
137
+ snapshots: z.array(SyncSnapshotSchema).optional(),
138
+ });
139
+ export const SyncPullResponseSchema = z.object({
140
+ ok: z.literal(true),
141
+ subscriptions: z.array(SyncPullSubscriptionResponseSchema),
142
+ });
143
+ // ============================================================================
144
+ // Combined Sync Request/Response Schemas
145
+ // ============================================================================
146
+ export const SyncCombinedRequestSchema = z.object({
147
+ clientId: z.string().min(1),
148
+ push: SyncPushRequestSchema.omit({ clientId: true }).optional(),
149
+ pull: SyncPullRequestSchema.omit({ clientId: true }).optional(),
150
+ });
151
+ export const SyncCombinedResponseSchema = z.object({
152
+ ok: z.literal(true),
153
+ push: SyncPushResponseSchema.optional(),
154
+ pull: SyncPullResponseSchema.optional(),
155
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Q,EAAE,CAAC,QAAQ,EAAE;IAC9D,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAClC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAC;AAMH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACnB,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,kCAAkC,CAAC;CAC3D,CAAC,CAAC;AAIH,+EAA+E;AAC/E,yCAAyC;AACzC,+EAA+E;AAE/E,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,IAAI,EAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC/D,IAAI,EAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;CAChE,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACnB,IAAI,EAAE,sBAAsB,CAAC,QAAQ,EAAE;IACvC,IAAI,EAAE,sBAAsB,CAAC,QAAQ,EAAE;CACxC,CAAC,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @syncular/core - Scope types, patterns, and utilities
3
+ *
4
+ * Scope patterns define how data is partitioned for sync.
5
+ * Scopes are stored as JSONB on changes for flexible filtering.
6
+ * Patterns use `{placeholder}` syntax to extract or inject values.
7
+ */
8
+ /**
9
+ * Scope pattern string, e.g., 'user:{user_id}', 'project:{project_id}'
10
+ */
11
+ export type ScopePattern = string;
12
+ /**
13
+ * Scope values - the actual values for scope variables.
14
+ * Values can be single strings or arrays (for multi-value subscriptions).
15
+ *
16
+ * @example
17
+ * { user_id: 'U1' }
18
+ * { project_id: ['P1', 'P2'] }
19
+ * { year: '2025', month: '03' }
20
+ */
21
+ export type ScopeValues = Record<string, string | string[]>;
22
+ /**
23
+ * Stored scopes on a change - always single values (not arrays).
24
+ * This is what gets stored in the JSONB column.
25
+ *
26
+ * @example
27
+ * { user_id: 'U1', project_id: 'P1' }
28
+ */
29
+ export type StoredScopes = Record<string, string>;
30
+ /**
31
+ * Simplified scope definition.
32
+ * Can be a simple pattern string or an object with explicit column mapping.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Simple: pattern column is auto-derived
37
+ * scopes: ['user:{user_id}', 'org:{org_id}']
38
+ *
39
+ * // Explicit: when column differs from pattern variable
40
+ * scopes: [
41
+ * { pattern: 'user:{user_id}', column: 'owner_id' }
42
+ * ]
43
+ * ```
44
+ */
45
+ export type ScopeDefinition = string | {
46
+ pattern: string;
47
+ column: string;
48
+ };
49
+ /**
50
+ * Normalize scope definitions to a pattern-to-column map.
51
+ *
52
+ * @example
53
+ * normalizeScopes(['user:{user_id}'])
54
+ * // → { 'user:{user_id}': 'user_id' }
55
+ */
56
+ export declare function normalizeScopes(scopes: ScopeDefinition[]): Record<string, string>;
57
+ /**
58
+ * Extract variable names from a scope pattern.
59
+ *
60
+ * @example
61
+ * extractScopeVars('project:{project_id}') // ['project_id']
62
+ * extractScopeVars('event_date:{year}:{month}') // ['year', 'month']
63
+ */
64
+ export declare function extractScopeVars(pattern: ScopePattern): string[];
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA+B3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EAAE,GACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxB;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,EAAE,CAIhE"}