@syncular/core 0.0.1 → 0.0.2-127
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.
- package/README.md +24 -0
- package/dist/blobs.d.ts +9 -4
- package/dist/blobs.d.ts.map +1 -1
- package/dist/blobs.js +0 -12
- package/dist/blobs.js.map +1 -1
- package/dist/column-codecs.d.ts +55 -0
- package/dist/column-codecs.d.ts.map +1 -0
- package/dist/column-codecs.js +124 -0
- package/dist/column-codecs.js.map +1 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/kysely-serialize.d.ts +1 -1
- package/dist/kysely-serialize.d.ts.map +1 -1
- package/dist/logger.d.ts +7 -32
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +6 -40
- package/dist/logger.js.map +1 -1
- package/dist/proxy/types.d.ts +0 -9
- package/dist/proxy/types.d.ts.map +1 -1
- package/dist/schemas/index.js +3 -3
- package/dist/schemas/sync.d.ts +120 -6
- package/dist/schemas/sync.d.ts.map +1 -1
- package/dist/schemas/sync.js +17 -3
- package/dist/schemas/sync.js.map +1 -1
- package/dist/scopes/index.d.ts +39 -64
- package/dist/scopes/index.d.ts.map +1 -1
- package/dist/scopes/index.js +9 -154
- package/dist/scopes/index.js.map +1 -1
- package/dist/snapshot-chunks.d.ts +26 -0
- package/dist/snapshot-chunks.d.ts.map +1 -0
- package/dist/snapshot-chunks.js +89 -0
- package/dist/snapshot-chunks.js.map +1 -0
- package/dist/telemetry.d.ts +114 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +113 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +12 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +8 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/object.d.ts.map +1 -0
- package/dist/utils/object.js +4 -0
- package/dist/utils/object.js.map +1 -0
- package/package.json +28 -8
- package/src/__tests__/telemetry.test.ts +170 -0
- package/src/__tests__/utils.test.ts +27 -0
- package/src/blobs.ts +15 -14
- package/src/column-codecs.ts +228 -0
- package/src/index.ts +15 -41
- package/src/kysely-serialize.ts +1 -1
- package/src/logger.ts +10 -68
- package/src/proxy/types.ts +0 -10
- package/src/schemas/sync.ts +27 -3
- package/src/scopes/index.ts +72 -200
- package/src/snapshot-chunks.ts +112 -0
- package/src/telemetry.ts +238 -0
- package/src/types.ts +14 -18
- package/src/utils/id.ts +7 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/object.ts +3 -0
package/dist/schemas/sync.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ export declare const SyncBootstrapStateSchema: z.ZodObject<{
|
|
|
95
95
|
export type SyncBootstrapState = z.infer<typeof SyncBootstrapStateSchema>;
|
|
96
96
|
export declare const SyncSubscriptionRequestSchema: z.ZodObject<{
|
|
97
97
|
id: z.ZodString;
|
|
98
|
-
|
|
98
|
+
table: z.ZodString;
|
|
99
99
|
scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
100
100
|
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
101
101
|
cursor: z.ZodNumber;
|
|
@@ -115,7 +115,7 @@ export declare const SyncPullRequestSchema: z.ZodObject<{
|
|
|
115
115
|
dedupeRows: z.ZodOptional<z.ZodBoolean>;
|
|
116
116
|
subscriptions: z.ZodArray<z.ZodObject<{
|
|
117
117
|
id: z.ZodString;
|
|
118
|
-
|
|
118
|
+
table: z.ZodString;
|
|
119
119
|
scopes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
120
120
|
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
121
121
|
cursor: z.ZodNumber;
|
|
@@ -161,7 +161,7 @@ export declare const SyncSnapshotChunkRefSchema: z.ZodObject<{
|
|
|
161
161
|
id: z.ZodString;
|
|
162
162
|
byteLength: z.ZodNumber;
|
|
163
163
|
sha256: z.ZodString;
|
|
164
|
-
encoding: z.ZodLiteral<"
|
|
164
|
+
encoding: z.ZodLiteral<"json-row-frame-v1">;
|
|
165
165
|
compression: z.ZodLiteral<"gzip">;
|
|
166
166
|
}, z.core.$strip>;
|
|
167
167
|
export type SyncSnapshotChunkRef = z.infer<typeof SyncSnapshotChunkRefSchema>;
|
|
@@ -172,7 +172,7 @@ export declare const SyncSnapshotSchema: z.ZodObject<{
|
|
|
172
172
|
id: z.ZodString;
|
|
173
173
|
byteLength: z.ZodNumber;
|
|
174
174
|
sha256: z.ZodString;
|
|
175
|
-
encoding: z.ZodLiteral<"
|
|
175
|
+
encoding: z.ZodLiteral<"json-row-frame-v1">;
|
|
176
176
|
compression: z.ZodLiteral<"gzip">;
|
|
177
177
|
}, z.core.$strip>>>;
|
|
178
178
|
isFirstPage: z.ZodBoolean;
|
|
@@ -217,7 +217,7 @@ export declare const SyncPullSubscriptionResponseSchema: z.ZodObject<{
|
|
|
217
217
|
id: z.ZodString;
|
|
218
218
|
byteLength: z.ZodNumber;
|
|
219
219
|
sha256: z.ZodString;
|
|
220
|
-
encoding: z.ZodLiteral<"
|
|
220
|
+
encoding: z.ZodLiteral<"json-row-frame-v1">;
|
|
221
221
|
compression: z.ZodLiteral<"gzip">;
|
|
222
222
|
}, z.core.$strip>>>;
|
|
223
223
|
isFirstPage: z.ZodBoolean;
|
|
@@ -265,7 +265,7 @@ export declare const SyncPullResponseSchema: z.ZodObject<{
|
|
|
265
265
|
id: z.ZodString;
|
|
266
266
|
byteLength: z.ZodNumber;
|
|
267
267
|
sha256: z.ZodString;
|
|
268
|
-
encoding: z.ZodLiteral<"
|
|
268
|
+
encoding: z.ZodLiteral<"json-row-frame-v1">;
|
|
269
269
|
compression: z.ZodLiteral<"gzip">;
|
|
270
270
|
}, z.core.$strip>>>;
|
|
271
271
|
isFirstPage: z.ZodBoolean;
|
|
@@ -274,4 +274,118 @@ export declare const SyncPullResponseSchema: z.ZodObject<{
|
|
|
274
274
|
}, z.core.$strip>>;
|
|
275
275
|
}, z.core.$strip>;
|
|
276
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
|
+
table: 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<"json-row-frame-v1">;
|
|
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>;
|
|
277
391
|
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAUxB,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,e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AAC,CAAC;AAE9E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;iBAM7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAS7C,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,kCAAkC,CAC1C,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,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"}
|
package/dist/schemas/sync.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Type inference
|
|
8
8
|
*/
|
|
9
9
|
import { z } from 'zod';
|
|
10
|
+
import { SYNC_SNAPSHOT_CHUNK_COMPRESSION, SYNC_SNAPSHOT_CHUNK_ENCODING, } from '../snapshot-chunks.js';
|
|
10
11
|
// ============================================================================
|
|
11
12
|
// Operation Types
|
|
12
13
|
// ============================================================================
|
|
@@ -84,7 +85,7 @@ export const SyncBootstrapStateSchema = z.object({
|
|
|
84
85
|
// ============================================================================
|
|
85
86
|
export const SyncSubscriptionRequestSchema = z.object({
|
|
86
87
|
id: z.string().min(1),
|
|
87
|
-
|
|
88
|
+
table: z.string().min(1),
|
|
88
89
|
scopes: ScopeValuesSchema,
|
|
89
90
|
params: z.record(z.string(), z.unknown()).optional(),
|
|
90
91
|
cursor: z.number().int(),
|
|
@@ -116,8 +117,8 @@ export const SyncSnapshotChunkRefSchema = z.object({
|
|
|
116
117
|
id: z.string(),
|
|
117
118
|
byteLength: z.number().int(),
|
|
118
119
|
sha256: z.string(),
|
|
119
|
-
encoding: z.literal(
|
|
120
|
-
compression: z.literal(
|
|
120
|
+
encoding: z.literal(SYNC_SNAPSHOT_CHUNK_ENCODING),
|
|
121
|
+
compression: z.literal(SYNC_SNAPSHOT_CHUNK_COMPRESSION),
|
|
121
122
|
});
|
|
122
123
|
export const SyncSnapshotSchema = z.object({
|
|
123
124
|
table: z.string(),
|
|
@@ -140,4 +141,17 @@ export const SyncPullResponseSchema = z.object({
|
|
|
140
141
|
ok: z.literal(true),
|
|
141
142
|
subscriptions: z.array(SyncPullSubscriptionResponseSchema),
|
|
142
143
|
});
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Combined Sync Request/Response Schemas
|
|
146
|
+
// ============================================================================
|
|
147
|
+
export const SyncCombinedRequestSchema = z.object({
|
|
148
|
+
clientId: z.string().min(1),
|
|
149
|
+
push: SyncPushRequestSchema.omit({ clientId: true }).optional(),
|
|
150
|
+
pull: SyncPullRequestSchema.omit({ clientId: true }).optional(),
|
|
151
|
+
});
|
|
152
|
+
export const SyncCombinedResponseSchema = z.object({
|
|
153
|
+
ok: z.literal(true),
|
|
154
|
+
push: SyncPushResponseSchema.optional(),
|
|
155
|
+
pull: SyncPullResponseSchema.optional(),
|
|
156
|
+
});
|
|
143
157
|
//# sourceMappingURL=sync.js.map
|
package/dist/schemas/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/schem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+9,10 @@
|
|
|
9
9
|
* Scope pattern string, e.g., 'user:{user_id}', 'project:{project_id}'
|
|
10
10
|
*/
|
|
11
11
|
export type ScopePattern = string;
|
|
12
|
+
/**
|
|
13
|
+
* Scope value for a single scope key.
|
|
14
|
+
*/
|
|
15
|
+
export type ScopeValue = string | string[];
|
|
12
16
|
/**
|
|
13
17
|
* Scope values - the actual values for scope variables.
|
|
14
18
|
* Values can be single strings or arrays (for multi-value subscriptions).
|
|
@@ -18,7 +22,7 @@ export type ScopePattern = string;
|
|
|
18
22
|
* { project_id: ['P1', 'P2'] }
|
|
19
23
|
* { year: '2025', month: '03' }
|
|
20
24
|
*/
|
|
21
|
-
export type ScopeValues = Record<string,
|
|
25
|
+
export type ScopeValues = Record<string, ScopeValue>;
|
|
22
26
|
/**
|
|
23
27
|
* Stored scopes on a change - always single values (not arrays).
|
|
24
28
|
* This is what gets stored in the JSONB column.
|
|
@@ -28,17 +32,37 @@ export type ScopeValues = Record<string, string | string[]>;
|
|
|
28
32
|
*/
|
|
29
33
|
export type StoredScopes = Record<string, string>;
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
32
|
-
* Maps scope patterns to their variable types.
|
|
35
|
+
* Extract scope keys from a scope pattern at the type level.
|
|
33
36
|
*
|
|
34
37
|
* @example
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
* ScopeKeysFromPattern<'user:{user_id}'> // 'user_id'
|
|
39
|
+
* ScopeKeysFromPattern<'event:{year}:{month}'> // 'year' | 'month'
|
|
40
|
+
*/
|
|
41
|
+
export type ScopeKeysFromPattern<Pattern extends ScopePattern> = string extends Pattern ? string : Pattern extends `${string}{${infer Key}}${infer Rest}` ? Key | ScopeKeysFromPattern<Rest> : never;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the pattern string from a scope definition.
|
|
44
|
+
*/
|
|
45
|
+
export type ScopePatternFromDefinition<Definition extends ScopeDefinition> = Definition extends ScopePattern ? Definition : Definition extends {
|
|
46
|
+
pattern: infer Pattern extends ScopePattern;
|
|
47
|
+
} ? Pattern : never;
|
|
48
|
+
/**
|
|
49
|
+
* Extract scope keys from a list of scope definitions.
|
|
50
|
+
*/
|
|
51
|
+
export type ScopeKeysFromDefinitions<Definitions extends readonly ScopeDefinition[]> = ScopeKeysFromPattern<ScopePatternFromDefinition<Definitions[number]>>;
|
|
52
|
+
/**
|
|
53
|
+
* Scope values constrained to known scope keys.
|
|
54
|
+
*
|
|
55
|
+
* Unknown keys are rejected at compile-time when literals are used.
|
|
40
56
|
*/
|
|
41
|
-
export type
|
|
57
|
+
export type ScopeValuesForKeys<ScopeKeys extends string> = Partial<Record<ScopeKeys, ScopeValue>>;
|
|
58
|
+
/**
|
|
59
|
+
* Scope values inferred from scope definitions.
|
|
60
|
+
*/
|
|
61
|
+
export type ScopeValuesFromPatterns<Definitions extends readonly ScopeDefinition[]> = ScopeValuesForKeys<ScopeKeysFromDefinitions<Definitions>>;
|
|
62
|
+
/**
|
|
63
|
+
* Stored scopes constrained to known scope keys.
|
|
64
|
+
*/
|
|
65
|
+
export type StoredScopesForKeys<ScopeKeys extends string> = Partial<Record<ScopeKeys, string>>;
|
|
42
66
|
/**
|
|
43
67
|
* Simplified scope definition.
|
|
44
68
|
* Can be a simple pattern string or an object with explicit column mapping.
|
|
@@ -54,21 +78,17 @@ export type SharedScopesDefinition = Record<ScopePattern, Record<string, string>
|
|
|
54
78
|
* ]
|
|
55
79
|
* ```
|
|
56
80
|
*/
|
|
57
|
-
export type ScopeDefinition =
|
|
58
|
-
pattern:
|
|
81
|
+
export type ScopeDefinition = ScopePattern | {
|
|
82
|
+
pattern: ScopePattern;
|
|
59
83
|
column: string;
|
|
60
84
|
};
|
|
61
85
|
/**
|
|
62
|
-
*
|
|
86
|
+
* Keep scope definitions as a typed tuple for downstream inference.
|
|
63
87
|
*
|
|
64
88
|
* @example
|
|
65
|
-
*
|
|
89
|
+
* const scopes = defineScopePatterns(['user:{user_id}'] as const);
|
|
66
90
|
*/
|
|
67
|
-
export declare function
|
|
68
|
-
/**
|
|
69
|
-
* Check if a scope string matches a pattern.
|
|
70
|
-
*/
|
|
71
|
-
export declare function scopeKeyMatchesPattern(pattern: string, scopeKey: string): boolean;
|
|
91
|
+
export declare function defineScopePatterns<const Definitions extends readonly ScopeDefinition[]>(scopes: Definitions): Definitions;
|
|
72
92
|
/**
|
|
73
93
|
* Normalize scope definitions to a pattern-to-column map.
|
|
74
94
|
*
|
|
@@ -76,15 +96,7 @@ export declare function scopeKeyMatchesPattern(pattern: string, scopeKey: string
|
|
|
76
96
|
* normalizeScopes(['user:{user_id}'])
|
|
77
97
|
* // → { 'user:{user_id}': 'user_id' }
|
|
78
98
|
*/
|
|
79
|
-
export declare function normalizeScopes(scopes: ScopeDefinition[]): Record<
|
|
80
|
-
/**
|
|
81
|
-
* Find the matching pattern and extract value from a scope string.
|
|
82
|
-
*/
|
|
83
|
-
export declare function findMatchingPattern(patterns: Record<string, string>, scopeKey: string): {
|
|
84
|
-
pattern: string;
|
|
85
|
-
column: string;
|
|
86
|
-
value: string;
|
|
87
|
-
} | null;
|
|
99
|
+
export declare function normalizeScopes(scopes: readonly ScopeDefinition[]): Record<ScopePattern, string>;
|
|
88
100
|
/**
|
|
89
101
|
* Extract variable names from a scope pattern.
|
|
90
102
|
*
|
|
@@ -93,41 +105,4 @@ export declare function findMatchingPattern(patterns: Record<string, string>, sc
|
|
|
93
105
|
* extractScopeVars('event_date:{year}:{month}') // ['year', 'month']
|
|
94
106
|
*/
|
|
95
107
|
export declare function extractScopeVars(pattern: ScopePattern): string[];
|
|
96
|
-
/**
|
|
97
|
-
* Build scope values from a row based on a scope pattern.
|
|
98
|
-
* Uses the pattern's variable names to extract values from the row.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* buildScopeValuesFromRow('project:{project_id}', { id: '1', project_id: 'P1' })
|
|
102
|
-
* // { project_id: 'P1' }
|
|
103
|
-
*/
|
|
104
|
-
export declare function buildScopeValuesFromRow(pattern: ScopePattern, row: Record<string, unknown>): StoredScopes;
|
|
105
|
-
/**
|
|
106
|
-
* Merge multiple scope value objects into one.
|
|
107
|
-
* Later values override earlier ones.
|
|
108
|
-
*/
|
|
109
|
-
export declare function mergeScopeValues(...sources: StoredScopes[]): StoredScopes;
|
|
110
|
-
/**
|
|
111
|
-
* Check if two stored scopes are equal.
|
|
112
|
-
*/
|
|
113
|
-
export declare function scopesEqual(a: StoredScopes, b: StoredScopes): boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Check if stored scopes match a subscription's scope values.
|
|
116
|
-
* Handles array values in subscription (OR semantics).
|
|
117
|
-
* Missing keys in subscription are treated as wildcards (match any).
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: 'P1' }) // true
|
|
121
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: ['P1', 'P2'] }) // true
|
|
122
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: 'P2' }) // false
|
|
123
|
-
*/
|
|
124
|
-
export declare function scopesMatchSubscription(stored: StoredScopes, subscription: ScopeValues): boolean;
|
|
125
|
-
/**
|
|
126
|
-
* Normalize scope values to always use arrays (for consistent handling).
|
|
127
|
-
*/
|
|
128
|
-
export declare function normalizeScopeValues(values: ScopeValues): Record<string, string[]>;
|
|
129
|
-
/**
|
|
130
|
-
* Get all scope variable names from a set of patterns.
|
|
131
|
-
*/
|
|
132
|
-
export declare function getAllScopeVars(patterns: ScopePattern[]): string[];
|
|
133
108
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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ACH,MAAM,MAAM,mBAAmB,CAAC,SAAS,SAAS,MAAM,IAAI,OAAO,CACjE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAC1B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ;IAAE,OAAO,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,CAAC,WAAW,SAAS,SAAS,eAAe,EAAE,EACpD,MAAM,EAAE,WAAW,GAAG,WAAW,CAElC;AA+BD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,eAAe,EAAE,GACjC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAgB9B;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,EAAE,CAIhE"}
|
package/dist/scopes/index.js
CHANGED
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
* Scopes are stored as JSONB on changes for flexible filtering.
|
|
6
6
|
* Patterns use `{placeholder}` syntax to extract or inject values.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Keep scope definitions as a typed tuple for downstream inference.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const scopes = defineScopePatterns(['user:{user_id}'] as const);
|
|
13
|
+
*/
|
|
14
|
+
export function defineScopePatterns(scopes) {
|
|
15
|
+
return scopes;
|
|
16
|
+
}
|
|
8
17
|
// ── Pattern parsing (internal helpers) ───────────────────────────────
|
|
9
18
|
/**
|
|
10
19
|
* Extract the placeholder name from a pattern.
|
|
@@ -20,29 +29,6 @@ function extractPlaceholder(pattern) {
|
|
|
20
29
|
suffix: match[3],
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Match a scope string against a pattern and extract the value.
|
|
25
|
-
*/
|
|
26
|
-
function matchScopePattern(pattern, scopeKey) {
|
|
27
|
-
const parsed = extractPlaceholder(pattern);
|
|
28
|
-
if (!parsed) {
|
|
29
|
-
// No placeholder - exact match
|
|
30
|
-
return pattern === scopeKey ? '' : null;
|
|
31
|
-
}
|
|
32
|
-
const { prefix, suffix } = parsed;
|
|
33
|
-
if (!scopeKey.startsWith(prefix)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
if (suffix && !scopeKey.endsWith(suffix)) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const valueStart = prefix.length;
|
|
40
|
-
const valueEnd = suffix ? scopeKey.length - suffix.length : scopeKey.length;
|
|
41
|
-
if (valueStart >= valueEnd) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return scopeKey.slice(valueStart, valueEnd);
|
|
45
|
-
}
|
|
46
32
|
/**
|
|
47
33
|
* Extract the placeholder name from a pattern.
|
|
48
34
|
*/
|
|
@@ -50,26 +36,6 @@ function getPlaceholderName(pattern) {
|
|
|
50
36
|
const parsed = extractPlaceholder(pattern);
|
|
51
37
|
return parsed?.placeholder ?? null;
|
|
52
38
|
}
|
|
53
|
-
// ── Pattern operations (public) ──────────────────────────────────────
|
|
54
|
-
/**
|
|
55
|
-
* Build a scope string from a pattern and value.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* buildScopeKey('user:{user_id}', '123') // 'user:123'
|
|
59
|
-
*/
|
|
60
|
-
export function buildScopeKey(pattern, value) {
|
|
61
|
-
const parsed = extractPlaceholder(pattern);
|
|
62
|
-
if (!parsed) {
|
|
63
|
-
return pattern;
|
|
64
|
-
}
|
|
65
|
-
return `${parsed.prefix}${value}${parsed.suffix}`;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Check if a scope string matches a pattern.
|
|
69
|
-
*/
|
|
70
|
-
export function scopeKeyMatchesPattern(pattern, scopeKey) {
|
|
71
|
-
return matchScopePattern(pattern, scopeKey) !== null;
|
|
72
|
-
}
|
|
73
39
|
/**
|
|
74
40
|
* Normalize scope definitions to a pattern-to-column map.
|
|
75
41
|
*
|
|
@@ -93,18 +59,6 @@ export function normalizeScopes(scopes) {
|
|
|
93
59
|
}
|
|
94
60
|
return result;
|
|
95
61
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Find the matching pattern and extract value from a scope string.
|
|
98
|
-
*/
|
|
99
|
-
export function findMatchingPattern(patterns, scopeKey) {
|
|
100
|
-
for (const [pattern, column] of Object.entries(patterns)) {
|
|
101
|
-
const value = matchScopePattern(pattern, scopeKey);
|
|
102
|
-
if (value !== null) {
|
|
103
|
-
return { pattern, column, value };
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
62
|
// ── Value operations (public) ────────────────────────────────────────
|
|
109
63
|
/**
|
|
110
64
|
* Extract variable names from a scope pattern.
|
|
@@ -119,103 +73,4 @@ export function extractScopeVars(pattern) {
|
|
|
119
73
|
return [];
|
|
120
74
|
return matches.map((m) => m.slice(1, -1));
|
|
121
75
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Build scope values from a row based on a scope pattern.
|
|
124
|
-
* Uses the pattern's variable names to extract values from the row.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* buildScopeValuesFromRow('project:{project_id}', { id: '1', project_id: 'P1' })
|
|
128
|
-
* // { project_id: 'P1' }
|
|
129
|
-
*/
|
|
130
|
-
export function buildScopeValuesFromRow(pattern, row) {
|
|
131
|
-
const vars = extractScopeVars(pattern);
|
|
132
|
-
const result = {};
|
|
133
|
-
for (const varName of vars) {
|
|
134
|
-
const value = row[varName];
|
|
135
|
-
if (value === null || value === undefined) {
|
|
136
|
-
result[varName] = '';
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
result[varName] = String(value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Merge multiple scope value objects into one.
|
|
146
|
-
* Later values override earlier ones.
|
|
147
|
-
*/
|
|
148
|
-
export function mergeScopeValues(...sources) {
|
|
149
|
-
const result = {};
|
|
150
|
-
for (const source of sources) {
|
|
151
|
-
for (const [key, value] of Object.entries(source)) {
|
|
152
|
-
result[key] = value;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Check if two stored scopes are equal.
|
|
159
|
-
*/
|
|
160
|
-
export function scopesEqual(a, b) {
|
|
161
|
-
const keysA = Object.keys(a).sort();
|
|
162
|
-
const keysB = Object.keys(b).sort();
|
|
163
|
-
if (keysA.length !== keysB.length)
|
|
164
|
-
return false;
|
|
165
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
166
|
-
if (keysA[i] !== keysB[i])
|
|
167
|
-
return false;
|
|
168
|
-
if (a[keysA[i]] !== b[keysB[i]])
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Check if stored scopes match a subscription's scope values.
|
|
175
|
-
* Handles array values in subscription (OR semantics).
|
|
176
|
-
* Missing keys in subscription are treated as wildcards (match any).
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: 'P1' }) // true
|
|
180
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: ['P1', 'P2'] }) // true
|
|
181
|
-
* scopesMatchSubscription({ project_id: 'P1' }, { project_id: 'P2' }) // false
|
|
182
|
-
*/
|
|
183
|
-
export function scopesMatchSubscription(stored, subscription) {
|
|
184
|
-
for (const [key, subValue] of Object.entries(subscription)) {
|
|
185
|
-
const storedValue = stored[key];
|
|
186
|
-
if (storedValue === undefined)
|
|
187
|
-
return false;
|
|
188
|
-
if (Array.isArray(subValue)) {
|
|
189
|
-
if (!subValue.includes(storedValue))
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
if (storedValue !== subValue)
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Normalize scope values to always use arrays (for consistent handling).
|
|
201
|
-
*/
|
|
202
|
-
export function normalizeScopeValues(values) {
|
|
203
|
-
const result = {};
|
|
204
|
-
for (const [key, value] of Object.entries(values)) {
|
|
205
|
-
result[key] = Array.isArray(value) ? value : [value];
|
|
206
|
-
}
|
|
207
|
-
return result;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get all scope variable names from a set of patterns.
|
|
211
|
-
*/
|
|
212
|
-
export function getAllScopeVars(patterns) {
|
|
213
|
-
const vars = new Set();
|
|
214
|
-
for (const pattern of patterns) {
|
|
215
|
-
for (const v of extractScopeVars(pattern)) {
|
|
216
|
-
vars.add(v);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return Array.from(vars);
|
|
220
|
-
}
|
|
221
76
|
//# sourceMappingURL=index.js.map
|
package/dist/scopes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scopes/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA2GH;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAEjC,MAAmB,EAAe;IAClC,OAAO,MAAM,CAAC;AAAA,CACf;AAED,0IAAwE;AAExE;;;GAGG;AACH,SAAS,kBAAkB,CAAC,OAAe,EAIlC;IACP,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,OAAO;QACL,MAAM,EAAE,KAAK,CAA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
|
+
/**
|
|
2
|
+
* @syncular/core - Snapshot chunk encoding helpers
|
|
3
|
+
*/
|
|
4
|
+
export declare const SYNC_SNAPSHOT_CHUNK_ENCODING = "json-row-frame-v1";
|
|
5
|
+
export type SyncSnapshotChunkEncoding = typeof SYNC_SNAPSHOT_CHUNK_ENCODING;
|
|
6
|
+
export declare const SYNC_SNAPSHOT_CHUNK_COMPRESSION = "gzip";
|
|
7
|
+
export type SyncSnapshotChunkCompression = typeof SYNC_SNAPSHOT_CHUNK_COMPRESSION;
|
|
8
|
+
/**
|
|
9
|
+
* Encode rows as framed JSON bytes without the format header.
|
|
10
|
+
*/
|
|
11
|
+
export declare function encodeSnapshotRowFrames(rows: readonly unknown[]): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Encode rows as framed JSON bytes with a format header.
|
|
14
|
+
*
|
|
15
|
+
* Format:
|
|
16
|
+
* - 4-byte magic header ("SRF1")
|
|
17
|
+
* - repeated frames of:
|
|
18
|
+
* - 4-byte big-endian payload byte length
|
|
19
|
+
* - UTF-8 JSON payload
|
|
20
|
+
*/
|
|
21
|
+
export declare function encodeSnapshotRows(rows: readonly unknown[]): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Decode framed JSON bytes into rows.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeSnapshotRows(bytes: Uint8Array): unknown[];
|
|
26
|
+
//# sourceMappingURL=snapshot-chunks.d.ts.map
|