@syncular/core 0.0.1-100

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 (99) hide show
  1. package/dist/blobs.d.ts +146 -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 +24 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +36 -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 +29 -0
  18. package/dist/logger.d.ts.map +1 -0
  19. package/dist/logger.js +26 -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 +157 -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/snapshot-chunks.d.ts +26 -0
  50. package/dist/snapshot-chunks.d.ts.map +1 -0
  51. package/dist/snapshot-chunks.js +89 -0
  52. package/dist/snapshot-chunks.js.map +1 -0
  53. package/dist/telemetry.d.ts +114 -0
  54. package/dist/telemetry.d.ts.map +1 -0
  55. package/dist/telemetry.js +113 -0
  56. package/dist/telemetry.js.map +1 -0
  57. package/dist/transforms.d.ts +146 -0
  58. package/dist/transforms.d.ts.map +1 -0
  59. package/dist/transforms.js +155 -0
  60. package/dist/transforms.js.map +1 -0
  61. package/dist/types.d.ts +129 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +20 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/utils/id.d.ts +2 -0
  66. package/dist/utils/id.d.ts.map +1 -0
  67. package/dist/utils/id.js +8 -0
  68. package/dist/utils/id.js.map +1 -0
  69. package/dist/utils/index.d.ts +3 -0
  70. package/dist/utils/index.d.ts.map +1 -0
  71. package/dist/utils/index.js +3 -0
  72. package/dist/utils/index.js.map +1 -0
  73. package/dist/utils/object.d.ts +2 -0
  74. package/dist/utils/object.d.ts.map +1 -0
  75. package/dist/utils/object.js +4 -0
  76. package/dist/utils/object.js.map +1 -0
  77. package/package.json +57 -0
  78. package/src/__tests__/conflict.test.ts +325 -0
  79. package/src/__tests__/telemetry.test.ts +170 -0
  80. package/src/__tests__/utils.test.ts +27 -0
  81. package/src/blobs.ts +202 -0
  82. package/src/conflict.ts +92 -0
  83. package/src/index.ts +36 -0
  84. package/src/kysely-serialize.ts +214 -0
  85. package/src/logger.ts +38 -0
  86. package/src/proxy/index.ts +10 -0
  87. package/src/proxy/types.ts +57 -0
  88. package/src/schemas/blobs.ts +101 -0
  89. package/src/schemas/common.ts +45 -0
  90. package/src/schemas/index.ts +7 -0
  91. package/src/schemas/sync.ts +226 -0
  92. package/src/scopes/index.ts +122 -0
  93. package/src/snapshot-chunks.ts +112 -0
  94. package/src/telemetry.ts +238 -0
  95. package/src/transforms.ts +256 -0
  96. package/src/types.ts +158 -0
  97. package/src/utils/id.ts +7 -0
  98. package/src/utils/index.ts +2 -0
  99. package/src/utils/object.ts +3 -0
@@ -0,0 +1,155 @@
1
+ /**
2
+ * @syncular/core - Data transformation hooks
3
+ *
4
+ * Provides interfaces for field-level transformations (e.g., encryption/decryption)
5
+ * that can be applied during sync operations.
6
+ */
7
+ /**
8
+ * Registry for managing data transforms.
9
+ *
10
+ * @example
11
+ * const transforms = new TransformRegistry();
12
+ *
13
+ * transforms.register({
14
+ * scope: 'tasks',
15
+ * fields: [{
16
+ * field: 'secret_notes',
17
+ * async transform(value, ctx) {
18
+ * const key = await getUserEncryptionKey(ctx.userId);
19
+ * return ctx.direction === 'toClient'
20
+ * ? decrypt(value as string, key)
21
+ * : encrypt(value as string, key);
22
+ * }
23
+ * }]
24
+ * });
25
+ *
26
+ * // Apply transforms to data
27
+ * const transformed = await transforms.apply(
28
+ * [{ id: '1', secret_notes: 'encrypted...' }],
29
+ * { direction: 'toClient', scope: 'tasks', ... }
30
+ * );
31
+ */
32
+ export class TransformRegistry {
33
+ configs = new Map();
34
+ /**
35
+ * Register transform config for a scope.
36
+ * @throws If config for this scope is already registered
37
+ */
38
+ register(config) {
39
+ if (this.configs.has(config.scope)) {
40
+ throw new Error(`Transform config for scope "${config.scope}" is already registered`);
41
+ }
42
+ this.configs.set(config.scope, config);
43
+ }
44
+ /**
45
+ * Unregister transform config by scope.
46
+ * @returns true if config was found and removed
47
+ */
48
+ unregister(scope) {
49
+ return this.configs.delete(scope);
50
+ }
51
+ /**
52
+ * Get config for a scope.
53
+ */
54
+ get(scope) {
55
+ return this.configs.get(scope);
56
+ }
57
+ /**
58
+ * Check if any transforms are registered for a scope.
59
+ */
60
+ hasTransforms(scope) {
61
+ const config = this.configs.get(scope);
62
+ return config !== undefined && (config.fields?.length ?? 0) > 0;
63
+ }
64
+ /**
65
+ * Get all registered configs.
66
+ */
67
+ getAll() {
68
+ return Array.from(this.configs.values());
69
+ }
70
+ /**
71
+ * Apply transforms to a single row.
72
+ *
73
+ * @param row - Row data to transform
74
+ * @param ctx - Transform context (without rowId, will be extracted from row)
75
+ * @param rowIdField - Field name for row ID (default: 'id')
76
+ * @returns Transformed row
77
+ */
78
+ async applyToRow(row, ctx, rowIdField = 'id') {
79
+ const config = this.configs.get(ctx.scope);
80
+ if (!config?.fields?.length) {
81
+ return row;
82
+ }
83
+ const rowId = String(row[rowIdField] ?? '');
84
+ const fullCtx = { ...ctx, rowId };
85
+ const result = { ...row };
86
+ for (const transformer of config.fields) {
87
+ if (transformer.field in result) {
88
+ try {
89
+ result[transformer.field] = (await transformer.transform(result[transformer.field], fullCtx));
90
+ }
91
+ catch (err) {
92
+ console.error(`[transforms] Error transforming field "${transformer.field}" for ${ctx.scope}:${rowId}:`, err);
93
+ // Keep original value on error
94
+ }
95
+ }
96
+ }
97
+ return result;
98
+ }
99
+ /**
100
+ * Apply transforms to multiple rows.
101
+ *
102
+ * @param rows - Array of rows to transform
103
+ * @param ctx - Transform context (without rowId)
104
+ * @param rowIdField - Field name for row ID (default: 'id')
105
+ * @returns Transformed rows
106
+ */
107
+ async apply(rows, ctx, rowIdField = 'id') {
108
+ const config = this.configs.get(ctx.scope);
109
+ if (!config?.fields?.length) {
110
+ return rows;
111
+ }
112
+ return Promise.all(rows.map((row) => this.applyToRow(row, ctx, rowIdField)));
113
+ }
114
+ /**
115
+ * Apply transforms to a mutation payload.
116
+ *
117
+ * @param payload - Mutation payload (may be partial row)
118
+ * @param ctx - Full transform context
119
+ * @returns Transformed payload
120
+ */
121
+ async applyToPayload(payload, ctx) {
122
+ if (!payload)
123
+ return null;
124
+ const config = this.configs.get(ctx.scope);
125
+ if (!config?.fields?.length) {
126
+ return payload;
127
+ }
128
+ const result = { ...payload };
129
+ for (const transformer of config.fields) {
130
+ if (transformer.field in result) {
131
+ try {
132
+ result[transformer.field] = (await transformer.transform(result[transformer.field], ctx));
133
+ }
134
+ catch (err) {
135
+ console.error(`[transforms] Error transforming field "${transformer.field}" for ${ctx.scope}:${ctx.rowId}:`, err);
136
+ // Keep original value on error
137
+ }
138
+ }
139
+ }
140
+ return result;
141
+ }
142
+ /**
143
+ * Clear all registered configs.
144
+ */
145
+ clear() {
146
+ this.configs.clear();
147
+ }
148
+ }
149
+ /**
150
+ * Create a new transform registry.
151
+ */
152
+ export function createTransformRegistry() {
153
+ return new TransformRegistry();
154
+ }
155
+ //# sourceMappingURL=transforms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transforms.js","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6DH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,iBAAiB;IACpB,OAAO,GAAsC,IAAI,GAAG,EAAE,CAAC;IAE/D;;;OAGG;IACH,QAAQ,CAAC,MAA4B,EAAQ;QAC3C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,+BAA+B,MAAM,CAAC,KAAK,yBAAyB,CACrE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAAA,CACxC;IAED;;;OAGG;IACH,UAAU,CAAC,KAAa,EAAW;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAAA,CACnC;IAED;;OAEG;IACH,GAAG,CAAC,KAAa,EAAoC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK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,WAAW,CAAC,KAAK,CAAC,EACzB,GAAG,CACJ,CAAe,CAAC;gBACnB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CACX,0CAA0C,WAAW,CAAC,KAAK,SAAS,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,GAAG,EAC7F,GAAG,CACJ,CAAC;oBACF,+BAA+B;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAAA,CACf;IAED;;OAEG;IACH,KAAK,GAAS;QACZ,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAAA,CACtB;CACF;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,GAAsB;IAC3D,OAAO,IAAI,iBAAiB,EAAE,CAAC;AAAA,CAChC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @syncular/core - Shared types for sync infrastructure
3
+ *
4
+ * Non-protocol types: conflict detection, transport interfaces.
5
+ * Protocol types (SyncOp, SyncPushRequest, etc.) live in ./schemas/sync.ts
6
+ */
7
+ import type { SyncCombinedRequest, SyncCombinedResponse } from './schemas/sync';
8
+ /**
9
+ * Result of a conflict check - no conflict
10
+ */
11
+ interface ConflictCheckResultOk {
12
+ hasConflict: false;
13
+ }
14
+ /**
15
+ * Result of a conflict check - conflict detected
16
+ */
17
+ interface ConflictCheckResultConflict {
18
+ hasConflict: true;
19
+ /** Fields with conflicting changes */
20
+ conflictingFields: string[];
21
+ /** Current server row state */
22
+ serverRow: Record<string, unknown>;
23
+ /** Current server version */
24
+ serverVersion: number;
25
+ }
26
+ /**
27
+ * Union type for conflict check results
28
+ */
29
+ export type ConflictCheckResult = ConflictCheckResultOk | ConflictCheckResultConflict;
30
+ /**
31
+ * Result of a field-level merge - can merge
32
+ */
33
+ export interface MergeResultOk {
34
+ canMerge: true;
35
+ /** Merged payload combining client and server changes */
36
+ mergedPayload: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Result of a field-level merge - cannot merge
40
+ */
41
+ export interface MergeResultConflict {
42
+ canMerge: false;
43
+ /** Fields that cannot be auto-merged */
44
+ conflictingFields: string[];
45
+ }
46
+ /**
47
+ * Union type for merge results
48
+ */
49
+ export type MergeResult = MergeResultOk | MergeResultConflict;
50
+ /**
51
+ * Options for transport operations.
52
+ * Provides hooks for auth errors and cancellation support.
53
+ */
54
+ export interface SyncTransportOptions {
55
+ /**
56
+ * Called when auth fails (401/403).
57
+ * Return true to retry the request after refreshing auth.
58
+ */
59
+ onAuthError?: () => Promise<boolean>;
60
+ /**
61
+ * Abort signal for cancellation support.
62
+ */
63
+ signal?: AbortSignal;
64
+ }
65
+ /**
66
+ * Blob transport operations (optional extension to SyncTransport).
67
+ * When present, enables blob upload/download through the same transport.
68
+ */
69
+ export interface SyncTransportBlobs {
70
+ /**
71
+ * Initiate a blob upload.
72
+ * Returns presigned URL info or indicates blob already exists (dedup).
73
+ */
74
+ initiateUpload(args: {
75
+ hash: string;
76
+ size: number;
77
+ mimeType: string;
78
+ }): Promise<{
79
+ exists: boolean;
80
+ uploadUrl?: string;
81
+ uploadMethod?: 'PUT' | 'POST';
82
+ uploadHeaders?: Record<string, string>;
83
+ }>;
84
+ /**
85
+ * Complete a blob upload.
86
+ * Call this after uploading to the presigned URL.
87
+ */
88
+ completeUpload(hash: string): Promise<{
89
+ ok: boolean;
90
+ error?: string;
91
+ }>;
92
+ /**
93
+ * Get a presigned download URL.
94
+ */
95
+ getDownloadUrl(hash: string): Promise<{
96
+ url: string;
97
+ expiresAt: string;
98
+ }>;
99
+ }
100
+ /**
101
+ * Transport interface for sync operations.
102
+ */
103
+ export interface SyncTransport {
104
+ /**
105
+ * Combined push+pull in a single round-trip.
106
+ */
107
+ sync(request: SyncCombinedRequest, options?: SyncTransportOptions): Promise<SyncCombinedResponse>;
108
+ /**
109
+ * Download an encoded bootstrap snapshot chunk.
110
+ */
111
+ fetchSnapshotChunk(request: {
112
+ chunkId: string;
113
+ }, options?: SyncTransportOptions): Promise<Uint8Array>;
114
+ /**
115
+ * Optional blob operations.
116
+ * When present, enables blob upload/download functionality.
117
+ */
118
+ blobs?: SyncTransportBlobs;
119
+ }
120
+ /**
121
+ * Transport error with additional context
122
+ */
123
+ export declare class SyncTransportError extends Error {
124
+ readonly status?: number | undefined;
125
+ readonly code?: string | undefined;
126
+ constructor(message: string, status?: number | undefined, code?: string | undefined);
127
+ }
128
+ export {};
129
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAMhF;;GAEG;AACH,UAAU,qBAAqB;IAC7B,WAAW,EAAE,KAAK,CAAC;CACpB;AAED;;GAEG;AACH,UAAU,2BAA2B;IACnC,WAAW,EAAE,IAAI,CAAC;IAClB,sCAAsC;IACtC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,qBAAqB,GACrB,2BAA2B,CAAC;AAEhC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,yDAAyD;IACzD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,KAAK,CAAC;IAChB,wCAAwC;IACxC,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAM9D;;;GAGG;AACH,MAAM,WAAW,oBAA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SAAQ,KAAK;aAGzB,MAAM,CAAC;aACP,IAAI,CAAC;IAHvB,YACE,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,oBAAQ,EACf,IAAI,CAAC,oBAAQ,EAI9B;CACF"}
package/dist/types.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @syncular/core - Shared types for sync infrastructure
3
+ *
4
+ * Non-protocol types: conflict detection, transport interfaces.
5
+ * Protocol types (SyncOp, SyncPushRequest, etc.) live in ./schemas/sync.ts
6
+ */
7
+ /**
8
+ * Transport error with additional context
9
+ */
10
+ export class SyncTransportError extends Error {
11
+ status;
12
+ code;
13
+ constructor(message, status, code) {
14
+ super(message);
15
+ this.status = status;
16
+ this.code = code;
17
+ this.name = 'SyncTransportError';
18
+ }
19
+ }
20
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4IH;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB,MAAM;IACN,IAAI;IAHtB,YACE,OAAe,EACC,MAAe,EACf,IAAa,EAC7B;QACA,KAAK,CAAC,OAAO,CAAC,CAAC;sBAHC,MAAM;oBACN,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAAA,CAClC;CACF"}
@@ -0,0 +1,2 @@
1
+ export declare function randomId(): string;
2
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,IAAI,MAAM,CAMjC"}
@@ -0,0 +1,8 @@
1
+ export function randomId() {
2
+ const cryptoObj = globalThis.crypto;
3
+ if (cryptoObj && typeof cryptoObj.randomUUID === 'function') {
4
+ return cryptoObj.randomUUID();
5
+ }
6
+ return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
7
+ }
8
+ //# sourceMappingURL=id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,GAAW;IACjC,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,IAAI,SAAS,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5D,OAAO,SAAS,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAAA,CAC/D"}
@@ -0,0 +1,3 @@
1
+ export * from './id';
2
+ export * from './object';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './id.js';
2
+ export * from './object.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE"}
@@ -0,0 +1,4 @@
1
+ export function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAoC;IACzE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CAC7E"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@syncular/core",
3
+ "version": "0.0.1-100",
4
+ "description": "Core protocol types and shared utilities for the Syncular sync framework",
5
+ "license": "MIT",
6
+ "author": "Benjamin Kniffler",
7
+ "homepage": "https://syncular.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/syncular/syncular.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/syncular/syncular/issues"
15
+ },
16
+ "keywords": [
17
+ "sync",
18
+ "offline-first",
19
+ "realtime",
20
+ "database",
21
+ "typescript"
22
+ ],
23
+ "private": false,
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "bun": "./src/index.ts",
31
+ "browser": "./src/index.ts",
32
+ "import": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ }
36
+ }
37
+ },
38
+ "scripts": {
39
+ "test": "bun test src/__tests__",
40
+ "tsgo": "tsgo --noEmit",
41
+ "build": "tsgo",
42
+ "release": "bunx syncular-publish"
43
+ },
44
+ "peerDependencies": {
45
+ "kysely": "^0.28.0",
46
+ "zod": "^4.0.0"
47
+ },
48
+ "devDependencies": {
49
+ "@syncular/config": "0.0.0",
50
+ "kysely": "*",
51
+ "zod": "*"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "src"
56
+ ]
57
+ }