@syncular/server 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 (211) hide show
  1. package/dist/blobs/adapters/database.d.ts +83 -0
  2. package/dist/blobs/adapters/database.d.ts.map +1 -0
  3. package/dist/blobs/adapters/database.js +180 -0
  4. package/dist/blobs/adapters/database.js.map +1 -0
  5. package/dist/blobs/adapters/s3.d.ts +82 -0
  6. package/dist/blobs/adapters/s3.d.ts.map +1 -0
  7. package/dist/blobs/adapters/s3.js +170 -0
  8. package/dist/blobs/adapters/s3.js.map +1 -0
  9. package/dist/blobs/index.d.ts +9 -0
  10. package/dist/blobs/index.d.ts.map +1 -0
  11. package/dist/blobs/index.js +9 -0
  12. package/dist/blobs/index.js.map +1 -0
  13. package/dist/blobs/manager.d.ts +195 -0
  14. package/dist/blobs/manager.d.ts.map +1 -0
  15. package/dist/blobs/manager.js +440 -0
  16. package/dist/blobs/manager.js.map +1 -0
  17. package/dist/blobs/migrate.d.ts +27 -0
  18. package/dist/blobs/migrate.d.ts.map +1 -0
  19. package/dist/blobs/migrate.js +119 -0
  20. package/dist/blobs/migrate.js.map +1 -0
  21. package/dist/blobs/types.d.ts +54 -0
  22. package/dist/blobs/types.d.ts.map +1 -0
  23. package/dist/blobs/types.js +5 -0
  24. package/dist/blobs/types.js.map +1 -0
  25. package/dist/clients.d.ts +14 -0
  26. package/dist/clients.d.ts.map +1 -0
  27. package/dist/clients.js +7 -0
  28. package/dist/clients.js.map +1 -0
  29. package/dist/compaction.d.ts +27 -0
  30. package/dist/compaction.d.ts.map +1 -0
  31. package/dist/compaction.js +49 -0
  32. package/dist/compaction.js.map +1 -0
  33. package/dist/dialect/index.d.ts +5 -0
  34. package/dist/dialect/index.d.ts.map +1 -0
  35. package/dist/dialect/index.js +5 -0
  36. package/dist/dialect/index.js.map +1 -0
  37. package/dist/dialect/types.d.ts +170 -0
  38. package/dist/dialect/types.d.ts.map +1 -0
  39. package/dist/dialect/types.js +8 -0
  40. package/dist/dialect/types.js.map +1 -0
  41. package/dist/helpers/conflict.d.ts +52 -0
  42. package/dist/helpers/conflict.d.ts.map +1 -0
  43. package/dist/helpers/conflict.js +49 -0
  44. package/dist/helpers/conflict.js.map +1 -0
  45. package/dist/helpers/emitted-change.d.ts +56 -0
  46. package/dist/helpers/emitted-change.d.ts.map +1 -0
  47. package/dist/helpers/emitted-change.js +46 -0
  48. package/dist/helpers/emitted-change.js.map +1 -0
  49. package/dist/helpers/index.d.ts +10 -0
  50. package/dist/helpers/index.d.ts.map +1 -0
  51. package/dist/helpers/index.js +10 -0
  52. package/dist/helpers/index.js.map +1 -0
  53. package/dist/helpers/paginate.d.ts +49 -0
  54. package/dist/helpers/paginate.d.ts.map +1 -0
  55. package/dist/helpers/paginate.js +54 -0
  56. package/dist/helpers/paginate.js.map +1 -0
  57. package/dist/helpers/scope-strings.d.ts +74 -0
  58. package/dist/helpers/scope-strings.d.ts.map +1 -0
  59. package/dist/helpers/scope-strings.js +82 -0
  60. package/dist/helpers/scope-strings.js.map +1 -0
  61. package/dist/index.d.ts +28 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +27 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/migrate.d.ts +14 -0
  66. package/dist/migrate.d.ts.map +1 -0
  67. package/dist/migrate.js +13 -0
  68. package/dist/migrate.js.map +1 -0
  69. package/dist/proxy/handler.d.ts +42 -0
  70. package/dist/proxy/handler.d.ts.map +1 -0
  71. package/dist/proxy/handler.js +99 -0
  72. package/dist/proxy/handler.js.map +1 -0
  73. package/dist/proxy/index.d.ts +9 -0
  74. package/dist/proxy/index.d.ts.map +1 -0
  75. package/dist/proxy/index.js +14 -0
  76. package/dist/proxy/index.js.map +1 -0
  77. package/dist/proxy/mutation-detector.d.ts +31 -0
  78. package/dist/proxy/mutation-detector.d.ts.map +1 -0
  79. package/dist/proxy/mutation-detector.js +61 -0
  80. package/dist/proxy/mutation-detector.js.map +1 -0
  81. package/dist/proxy/oplog.d.ts +30 -0
  82. package/dist/proxy/oplog.d.ts.map +1 -0
  83. package/dist/proxy/oplog.js +110 -0
  84. package/dist/proxy/oplog.js.map +1 -0
  85. package/dist/proxy/registry.d.ts +35 -0
  86. package/dist/proxy/registry.d.ts.map +1 -0
  87. package/dist/proxy/registry.js +49 -0
  88. package/dist/proxy/registry.js.map +1 -0
  89. package/dist/proxy/types.d.ts +44 -0
  90. package/dist/proxy/types.d.ts.map +1 -0
  91. package/dist/proxy/types.js +7 -0
  92. package/dist/proxy/types.js.map +1 -0
  93. package/dist/prune.d.ts +37 -0
  94. package/dist/prune.d.ts.map +1 -0
  95. package/dist/prune.js +112 -0
  96. package/dist/prune.js.map +1 -0
  97. package/dist/pull.d.ts +31 -0
  98. package/dist/pull.d.ts.map +1 -0
  99. package/dist/pull.js +414 -0
  100. package/dist/pull.js.map +1 -0
  101. package/dist/push.d.ts +33 -0
  102. package/dist/push.d.ts.map +1 -0
  103. package/dist/push.js +329 -0
  104. package/dist/push.js.map +1 -0
  105. package/dist/realtime/in-memory.d.ts +13 -0
  106. package/dist/realtime/in-memory.d.ts.map +1 -0
  107. package/dist/realtime/in-memory.js +28 -0
  108. package/dist/realtime/in-memory.js.map +1 -0
  109. package/dist/realtime/index.d.ts +3 -0
  110. package/dist/realtime/index.d.ts.map +1 -0
  111. package/dist/realtime/index.js +2 -0
  112. package/dist/realtime/index.js.map +1 -0
  113. package/dist/realtime/types.d.ts +50 -0
  114. package/dist/realtime/types.d.ts.map +1 -0
  115. package/dist/realtime/types.js +7 -0
  116. package/dist/realtime/types.js.map +1 -0
  117. package/dist/schema.d.ts +164 -0
  118. package/dist/schema.d.ts.map +1 -0
  119. package/dist/schema.js +10 -0
  120. package/dist/schema.js.map +1 -0
  121. package/dist/shapes/create-handler.d.ts +119 -0
  122. package/dist/shapes/create-handler.d.ts.map +1 -0
  123. package/dist/shapes/create-handler.js +327 -0
  124. package/dist/shapes/create-handler.js.map +1 -0
  125. package/dist/shapes/index.d.ts +4 -0
  126. package/dist/shapes/index.d.ts.map +1 -0
  127. package/dist/shapes/index.js +4 -0
  128. package/dist/shapes/index.js.map +1 -0
  129. package/dist/shapes/registry.d.ts +20 -0
  130. package/dist/shapes/registry.d.ts.map +1 -0
  131. package/dist/shapes/registry.js +88 -0
  132. package/dist/shapes/registry.js.map +1 -0
  133. package/dist/shapes/types.d.ts +204 -0
  134. package/dist/shapes/types.d.ts.map +1 -0
  135. package/dist/shapes/types.js +2 -0
  136. package/dist/shapes/types.js.map +1 -0
  137. package/dist/snapshot-chunks/adapters/s3.d.ts +63 -0
  138. package/dist/snapshot-chunks/adapters/s3.d.ts.map +1 -0
  139. package/dist/snapshot-chunks/adapters/s3.js +50 -0
  140. package/dist/snapshot-chunks/adapters/s3.js.map +1 -0
  141. package/dist/snapshot-chunks/db-metadata.d.ts +33 -0
  142. package/dist/snapshot-chunks/db-metadata.d.ts.map +1 -0
  143. package/dist/snapshot-chunks/db-metadata.js +169 -0
  144. package/dist/snapshot-chunks/db-metadata.js.map +1 -0
  145. package/dist/snapshot-chunks/index.d.ts +9 -0
  146. package/dist/snapshot-chunks/index.d.ts.map +1 -0
  147. package/dist/snapshot-chunks/index.js +9 -0
  148. package/dist/snapshot-chunks/index.js.map +1 -0
  149. package/dist/snapshot-chunks/types.d.ts +65 -0
  150. package/dist/snapshot-chunks/types.d.ts.map +1 -0
  151. package/dist/snapshot-chunks/types.js +8 -0
  152. package/dist/snapshot-chunks/types.js.map +1 -0
  153. package/dist/snapshot-chunks.d.ts +59 -0
  154. package/dist/snapshot-chunks.d.ts.map +1 -0
  155. package/dist/snapshot-chunks.js +202 -0
  156. package/dist/snapshot-chunks.js.map +1 -0
  157. package/dist/stats.d.ts +19 -0
  158. package/dist/stats.d.ts.map +1 -0
  159. package/dist/stats.js +57 -0
  160. package/dist/stats.js.map +1 -0
  161. package/dist/subscriptions/index.d.ts +2 -0
  162. package/dist/subscriptions/index.d.ts.map +1 -0
  163. package/dist/subscriptions/index.js +2 -0
  164. package/dist/subscriptions/index.js.map +1 -0
  165. package/dist/subscriptions/resolve.d.ts +35 -0
  166. package/dist/subscriptions/resolve.d.ts.map +1 -0
  167. package/dist/subscriptions/resolve.js +134 -0
  168. package/dist/subscriptions/resolve.js.map +1 -0
  169. package/package.json +80 -0
  170. package/src/blobs/adapters/database.ts +290 -0
  171. package/src/blobs/adapters/s3.ts +271 -0
  172. package/src/blobs/index.ts +9 -0
  173. package/src/blobs/manager.ts +600 -0
  174. package/src/blobs/migrate.ts +150 -0
  175. package/src/blobs/types.ts +70 -0
  176. package/src/clients.ts +21 -0
  177. package/src/compaction.ts +77 -0
  178. package/src/dialect/index.ts +5 -0
  179. package/src/dialect/types.ts +222 -0
  180. package/src/helpers/conflict.ts +64 -0
  181. package/src/helpers/emitted-change.ts +69 -0
  182. package/src/helpers/index.ts +10 -0
  183. package/src/helpers/paginate.ts +82 -0
  184. package/src/helpers/scope-strings.ts +101 -0
  185. package/src/index.ts +28 -0
  186. package/src/migrate.ts +20 -0
  187. package/src/proxy/handler.ts +152 -0
  188. package/src/proxy/index.ts +18 -0
  189. package/src/proxy/mutation-detector.ts +83 -0
  190. package/src/proxy/oplog.ts +144 -0
  191. package/src/proxy/registry.ts +56 -0
  192. package/src/proxy/types.ts +46 -0
  193. package/src/prune.ts +200 -0
  194. package/src/pull.ts +551 -0
  195. package/src/push.ts +457 -0
  196. package/src/realtime/in-memory.ts +33 -0
  197. package/src/realtime/index.ts +5 -0
  198. package/src/realtime/types.ts +55 -0
  199. package/src/schema.ts +172 -0
  200. package/src/shapes/create-handler.ts +590 -0
  201. package/src/shapes/index.ts +3 -0
  202. package/src/shapes/registry.ts +109 -0
  203. package/src/shapes/types.ts +267 -0
  204. package/src/snapshot-chunks/adapters/s3.ts +68 -0
  205. package/src/snapshot-chunks/db-metadata.ts +238 -0
  206. package/src/snapshot-chunks/index.ts +9 -0
  207. package/src/snapshot-chunks/types.ts +79 -0
  208. package/src/snapshot-chunks.ts +301 -0
  209. package/src/stats.ts +104 -0
  210. package/src/subscriptions/index.ts +1 -0
  211. package/src/subscriptions/resolve.ts +185 -0
package/src/schema.ts ADDED
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @syncular/server - database schema types
3
+ *
4
+ * Commit-log based sync tables:
5
+ * - sync_commits: one row per committed push
6
+ * - sync_changes: one row per emitted change, stamped with scopes
7
+ * - sync_table_commits: commit routing index for fast pull
8
+ */
9
+
10
+ import type { SyncOp } from '@syncular/core';
11
+ import type { Generated } from 'kysely';
12
+
13
+ /**
14
+ * Commit log.
15
+ */
16
+ export interface SyncCommitsTable {
17
+ /** Monotonic commit sequence (server-assigned) */
18
+ commit_seq: Generated<number>;
19
+ /** Logical partition key (tenant / demo / workspace) */
20
+ partition_id: string;
21
+ /** Actor who produced the commit */
22
+ actor_id: string;
23
+ /** Client/device identifier */
24
+ client_id: string;
25
+ /** Client-provided commit idempotency key (unique per client) */
26
+ client_commit_id: string;
27
+ /** Creation timestamp */
28
+ created_at: Generated<string>;
29
+ /** Optional metadata */
30
+ meta: unknown | null;
31
+ /** Cached push response for idempotency */
32
+ result_json: unknown | null;
33
+ /** Number of emitted changes (denormalized for observability) */
34
+ change_count: Generated<number>;
35
+ /**
36
+ * Tables affected by this commit (for realtime notifications).
37
+ * Array of table names that had changes.
38
+ */
39
+ affected_tables: Generated<string[]>;
40
+ }
41
+
42
+ /**
43
+ * Change log entries (filtered by scopes on pull).
44
+ */
45
+ export interface SyncChangesTable {
46
+ /** Monotonic change id */
47
+ change_id: Generated<number>;
48
+ /** Logical partition key (tenant / demo / workspace) */
49
+ partition_id: string;
50
+ /** Commit sequence this change belongs to */
51
+ commit_seq: number;
52
+ /** Table name being changed */
53
+ table: string;
54
+ /** Row primary key */
55
+ row_id: string;
56
+ /** Operation: 'upsert' or 'delete' */
57
+ op: SyncOp;
58
+ /** Row data as JSON (null for deletes) */
59
+ row_json: unknown | null;
60
+ /** Optional row version for optimistic concurrency */
61
+ row_version: number | null;
62
+ /**
63
+ * Scope values for routing/filtering (JSONB).
64
+ * Example: { "user_id": "U1", "project_id": "P1" }
65
+ */
66
+ scopes: unknown;
67
+ }
68
+
69
+ /**
70
+ * Per-client cursor tracking (for pruning + observability).
71
+ */
72
+ export interface SyncClientCursorsTable {
73
+ /** Logical partition key (tenant / demo / workspace) */
74
+ partition_id: string;
75
+ /** Client/device identifier */
76
+ client_id: string;
77
+ /** Actor currently associated with the client */
78
+ actor_id: string;
79
+ /** Last successfully pulled commit_seq */
80
+ cursor: number;
81
+ /**
82
+ * Effective scope values for the client's last pull (JSONB).
83
+ * This is the intersection of requested scopes and allowed scopes.
84
+ */
85
+ effective_scopes: unknown;
86
+ /** Last update timestamp */
87
+ updated_at: Generated<string>;
88
+ }
89
+
90
+ /**
91
+ * Cached bootstrap snapshot chunks (encoded, for large read-only bootstraps).
92
+ */
93
+ export interface SyncSnapshotChunksTable {
94
+ /** Opaque chunk id */
95
+ chunk_id: string;
96
+ /** Logical partition key (tenant / demo / workspace) */
97
+ partition_id: string;
98
+ /** Effective scope key this chunk belongs to */
99
+ scope_key: string;
100
+ /** Scope identifier */
101
+ scope: string;
102
+ /** Snapshot as-of commit sequence */
103
+ as_of_commit_seq: number;
104
+ /** Snapshot row cursor key (empty string represents null) */
105
+ row_cursor: string;
106
+ /** Snapshot row limit used to produce this chunk */
107
+ row_limit: number;
108
+ /** Row encoding (e.g. 'ndjson') */
109
+ encoding: string;
110
+ /** Compression algorithm (e.g. 'gzip') */
111
+ compression: string;
112
+ /** Hex-encoded sha256 of content */
113
+ sha256: string;
114
+ /** Byte length of content */
115
+ byte_length: number;
116
+ /** Reference to blob storage (new field for external storage) */
117
+ blob_hash: string;
118
+ /** Encoded chunk bytes (deprecated: use blob storage via blob_hash) */
119
+ body?: Uint8Array | null;
120
+ /** Created timestamp */
121
+ created_at: Generated<string>;
122
+ /** Expiration timestamp (server may delete after this) */
123
+ expires_at: string;
124
+ }
125
+
126
+ /**
127
+ * Index table: which commits affect which tables.
128
+ *
129
+ * Used to efficiently find commit_seq values for a table without scanning
130
+ * the (much larger) change log.
131
+ */
132
+ export interface SyncTableCommitsTable {
133
+ /** Logical partition key (tenant / demo / workspace) */
134
+ partition_id: string;
135
+ table: string;
136
+ commit_seq: number;
137
+ }
138
+
139
+ /**
140
+ * Database interface for sync infrastructure tables
141
+ * Merge this with your app's database interface
142
+ */
143
+ export interface SyncCoreDb {
144
+ sync_commits: SyncCommitsTable;
145
+ sync_changes: SyncChangesTable;
146
+ sync_client_cursors: SyncClientCursorsTable;
147
+ sync_table_commits: SyncTableCommitsTable;
148
+ sync_snapshot_chunks: SyncSnapshotChunksTable;
149
+ }
150
+
151
+ /**
152
+ * Commit metadata row for pull responses
153
+ */
154
+ export interface SyncCommitRow {
155
+ commit_seq: number;
156
+ actor_id: string;
157
+ created_at: string;
158
+ result_json: unknown | null;
159
+ }
160
+
161
+ /**
162
+ * Change row for pull responses
163
+ */
164
+ export interface SyncChangeRow {
165
+ commit_seq: number;
166
+ table: string;
167
+ row_id: string;
168
+ op: SyncOp;
169
+ row_json: unknown | null;
170
+ row_version: number | null;
171
+ scopes: unknown;
172
+ }