@syncular/core 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +5 -19
  2. package/dist/blob-ref.d.ts +21 -0
  3. package/dist/blob-ref.js +97 -0
  4. package/dist/bytes.d.ts +45 -0
  5. package/dist/bytes.js +242 -0
  6. package/dist/canonical-json.d.ts +10 -0
  7. package/dist/canonical-json.js +18 -0
  8. package/dist/constants.d.ts +5 -0
  9. package/dist/constants.js +5 -0
  10. package/dist/crypto.d.ts +60 -0
  11. package/dist/crypto.js +251 -0
  12. package/dist/errors.d.ts +14 -0
  13. package/dist/errors.js +17 -0
  14. package/dist/frames.d.ts +24 -0
  15. package/dist/frames.js +42 -0
  16. package/dist/index.d.ts +18 -26
  17. package/dist/index.js +18 -43
  18. package/dist/message.d.ts +157 -0
  19. package/dist/message.js +786 -0
  20. package/dist/realtime.d.ts +92 -0
  21. package/dist/realtime.js +222 -0
  22. package/dist/render.d.ts +22 -0
  23. package/dist/render.js +273 -0
  24. package/dist/row-codec.d.ts +39 -0
  25. package/dist/row-codec.js +176 -0
  26. package/dist/segment.d.ts +18 -0
  27. package/dist/segment.js +105 -0
  28. package/dist/stream.d.ts +20 -0
  29. package/dist/stream.js +102 -0
  30. package/package.json +7 -59
  31. package/src/blob-ref.ts +135 -0
  32. package/src/bytes.ts +301 -0
  33. package/src/canonical-json.ts +20 -0
  34. package/src/constants.ts +7 -0
  35. package/src/crypto.ts +335 -0
  36. package/src/errors.ts +18 -0
  37. package/src/frames.ts +47 -0
  38. package/src/index.ts +18 -43
  39. package/src/message.ts +1024 -0
  40. package/src/realtime.ts +340 -0
  41. package/src/render.ts +325 -0
  42. package/src/row-codec.ts +265 -0
  43. package/src/segment.ts +150 -0
  44. package/src/stream.ts +128 -0
  45. package/dist/blobs.d.ts +0 -153
  46. package/dist/blobs.d.ts.map +0 -1
  47. package/dist/blobs.js +0 -47
  48. package/dist/blobs.js.map +0 -1
  49. package/dist/column-codecs.d.ts +0 -59
  50. package/dist/column-codecs.d.ts.map +0 -1
  51. package/dist/column-codecs.js +0 -159
  52. package/dist/column-codecs.js.map +0 -1
  53. package/dist/conflict.d.ts +0 -22
  54. package/dist/conflict.d.ts.map +0 -1
  55. package/dist/conflict.js +0 -81
  56. package/dist/conflict.js.map +0 -1
  57. package/dist/database.d.ts +0 -7
  58. package/dist/database.d.ts.map +0 -1
  59. package/dist/database.js +0 -14
  60. package/dist/database.js.map +0 -1
  61. package/dist/dialect.d.ts +0 -7
  62. package/dist/dialect.d.ts.map +0 -1
  63. package/dist/dialect.js +0 -2
  64. package/dist/dialect.js.map +0 -1
  65. package/dist/error-responses.d.ts +0 -393
  66. package/dist/error-responses.d.ts.map +0 -1
  67. package/dist/error-responses.js +0 -393
  68. package/dist/error-responses.js.map +0 -1
  69. package/dist/http/api-client.d.ts +0 -11
  70. package/dist/http/api-client.d.ts.map +0 -1
  71. package/dist/http/api-client.js +0 -30
  72. package/dist/http/api-client.js.map +0 -1
  73. package/dist/http/blob.d.ts +0 -6
  74. package/dist/http/blob.d.ts.map +0 -1
  75. package/dist/http/blob.js +0 -46
  76. package/dist/http/blob.js.map +0 -1
  77. package/dist/http/generated/api.d.ts +0 -5241
  78. package/dist/http/generated/api.d.ts.map +0 -1
  79. package/dist/http/generated/api.js +0 -6
  80. package/dist/http/generated/api.js.map +0 -1
  81. package/dist/http/index.d.ts +0 -18
  82. package/dist/http/index.d.ts.map +0 -1
  83. package/dist/http/index.js +0 -212
  84. package/dist/http/index.js.map +0 -1
  85. package/dist/http/shared.d.ts +0 -45
  86. package/dist/http/shared.d.ts.map +0 -1
  87. package/dist/http/shared.js +0 -122
  88. package/dist/http/shared.js.map +0 -1
  89. package/dist/http/transport-client.d.ts +0 -31
  90. package/dist/http/transport-client.d.ts.map +0 -1
  91. package/dist/http/transport-client.js +0 -193
  92. package/dist/http/transport-client.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/kysely-column-codecs.d.ts +0 -31
  96. package/dist/kysely-column-codecs.d.ts.map +0 -1
  97. package/dist/kysely-column-codecs.js +0 -452
  98. package/dist/kysely-column-codecs.js.map +0 -1
  99. package/dist/logger.d.ts +0 -29
  100. package/dist/logger.d.ts.map +0 -1
  101. package/dist/logger.js +0 -26
  102. package/dist/logger.js.map +0 -1
  103. package/dist/proxy/index.d.ts +0 -54
  104. package/dist/proxy/index.d.ts.map +0 -1
  105. package/dist/proxy/index.js +0 -7
  106. package/dist/proxy/index.js.map +0 -1
  107. package/dist/schemas/blobs.d.ts +0 -82
  108. package/dist/schemas/blobs.d.ts.map +0 -1
  109. package/dist/schemas/blobs.js +0 -64
  110. package/dist/schemas/blobs.js.map +0 -1
  111. package/dist/schemas/common.d.ts +0 -100
  112. package/dist/schemas/common.d.ts.map +0 -1
  113. package/dist/schemas/common.js +0 -64
  114. package/dist/schemas/common.js.map +0 -1
  115. package/dist/schemas/index.d.ts +0 -7
  116. package/dist/schemas/index.d.ts.map +0 -1
  117. package/dist/schemas/index.js +0 -7
  118. package/dist/schemas/index.js.map +0 -1
  119. package/dist/schemas/sync.d.ts +0 -1065
  120. package/dist/schemas/sync.d.ts.map +0 -1
  121. package/dist/schemas/sync.js +0 -361
  122. package/dist/schemas/sync.js.map +0 -1
  123. package/dist/scopes/index.d.ts +0 -113
  124. package/dist/scopes/index.d.ts.map +0 -1
  125. package/dist/scopes/index.js +0 -103
  126. package/dist/scopes/index.js.map +0 -1
  127. package/dist/sentry.d.ts +0 -31
  128. package/dist/sentry.d.ts.map +0 -1
  129. package/dist/sentry.js +0 -147
  130. package/dist/sentry.js.map +0 -1
  131. package/dist/snapshot-chunks.d.ts +0 -110
  132. package/dist/snapshot-chunks.d.ts.map +0 -1
  133. package/dist/snapshot-chunks.js +0 -682
  134. package/dist/snapshot-chunks.js.map +0 -1
  135. package/dist/sync-packs.d.ts +0 -33
  136. package/dist/sync-packs.d.ts.map +0 -1
  137. package/dist/sync-packs.js +0 -821
  138. package/dist/sync-packs.js.map +0 -1
  139. package/dist/telemetry.d.ts +0 -114
  140. package/dist/telemetry.d.ts.map +0 -1
  141. package/dist/telemetry.js +0 -114
  142. package/dist/telemetry.js.map +0 -1
  143. package/dist/transforms.d.ts +0 -146
  144. package/dist/transforms.d.ts.map +0 -1
  145. package/dist/transforms.js +0 -155
  146. package/dist/transforms.js.map +0 -1
  147. package/dist/types.d.ts +0 -210
  148. package/dist/types.d.ts.map +0 -1
  149. package/dist/types.js +0 -20
  150. package/dist/types.js.map +0 -1
  151. package/dist/utils/bytes.d.ts +0 -4
  152. package/dist/utils/bytes.d.ts.map +0 -1
  153. package/dist/utils/bytes.js +0 -66
  154. package/dist/utils/bytes.js.map +0 -1
  155. package/dist/utils/compression.d.ts +0 -22
  156. package/dist/utils/compression.d.ts.map +0 -1
  157. package/dist/utils/compression.js +0 -129
  158. package/dist/utils/compression.js.map +0 -1
  159. package/dist/utils/crypto.d.ts +0 -13
  160. package/dist/utils/crypto.d.ts.map +0 -1
  161. package/dist/utils/crypto.js +0 -107
  162. package/dist/utils/crypto.js.map +0 -1
  163. package/dist/utils/id.d.ts +0 -3
  164. package/dist/utils/id.d.ts.map +0 -1
  165. package/dist/utils/id.js +0 -25
  166. package/dist/utils/id.js.map +0 -1
  167. package/dist/utils/index.d.ts +0 -10
  168. package/dist/utils/index.d.ts.map +0 -1
  169. package/dist/utils/index.js +0 -10
  170. package/dist/utils/index.js.map +0 -1
  171. package/dist/utils/internal-runtime.d.ts +0 -16
  172. package/dist/utils/internal-runtime.d.ts.map +0 -1
  173. package/dist/utils/internal-runtime.js +0 -14
  174. package/dist/utils/internal-runtime.js.map +0 -1
  175. package/dist/utils/object.d.ts +0 -2
  176. package/dist/utils/object.d.ts.map +0 -1
  177. package/dist/utils/object.js +0 -4
  178. package/dist/utils/object.js.map +0 -1
  179. package/dist/utils/realtime-change-index.d.ts +0 -9
  180. package/dist/utils/realtime-change-index.d.ts.map +0 -1
  181. package/dist/utils/realtime-change-index.js +0 -36
  182. package/dist/utils/realtime-change-index.js.map +0 -1
  183. package/dist/utils/realtime-connection-registry.d.ts +0 -40
  184. package/dist/utils/realtime-connection-registry.d.ts.map +0 -1
  185. package/dist/utils/realtime-connection-registry.js +0 -237
  186. package/dist/utils/realtime-connection-registry.js.map +0 -1
  187. package/dist/utils/table-registry.d.ts +0 -10
  188. package/dist/utils/table-registry.d.ts.map +0 -1
  189. package/dist/utils/table-registry.js +0 -54
  190. package/dist/utils/table-registry.js.map +0 -1
  191. package/dist/utils/url.d.ts +0 -3
  192. package/dist/utils/url.d.ts.map +0 -1
  193. package/dist/utils/url.js +0 -20
  194. package/dist/utils/url.js.map +0 -1
  195. package/src/blobs.ts +0 -219
  196. package/src/column-codecs.ts +0 -262
  197. package/src/conflict.ts +0 -92
  198. package/src/database.ts +0 -21
  199. package/src/dialect.ts +0 -8
  200. package/src/error-responses.ts +0 -423
  201. package/src/http/api-client.ts +0 -39
  202. package/src/http/blob.ts +0 -95
  203. package/src/http/generated/api.ts +0 -5241
  204. package/src/http/index.ts +0 -365
  205. package/src/http/shared.ts +0 -220
  206. package/src/http/transport-client.ts +0 -314
  207. package/src/kysely-column-codecs.ts +0 -585
  208. package/src/logger.ts +0 -38
  209. package/src/proxy/index.ts +0 -57
  210. package/src/schemas/blobs.ts +0 -110
  211. package/src/schemas/common.ts +0 -89
  212. package/src/schemas/index.ts +0 -7
  213. package/src/schemas/sync.ts +0 -517
  214. package/src/scopes/index.ts +0 -237
  215. package/src/sentry.ts +0 -200
  216. package/src/snapshot-chunks.ts +0 -964
  217. package/src/sync-packs.ts +0 -1096
  218. package/src/telemetry.ts +0 -243
  219. package/src/transforms.ts +0 -256
  220. package/src/types.ts +0 -267
  221. package/src/utils/bytes.ts +0 -75
  222. package/src/utils/compression.ts +0 -187
  223. package/src/utils/crypto.ts +0 -146
  224. package/src/utils/id.ts +0 -34
  225. package/src/utils/index.ts +0 -9
  226. package/src/utils/internal-runtime.ts +0 -39
  227. package/src/utils/object.ts +0 -3
  228. package/src/utils/realtime-change-index.ts +0 -44
  229. package/src/utils/realtime-connection-registry.ts +0 -286
  230. package/src/utils/table-registry.ts +0 -67
  231. package/src/utils/url.ts +0 -29
@@ -1,423 +0,0 @@
1
- import type {
2
- ErrorResponse,
3
- SyncularErrorCategory,
4
- SyncularErrorRecommendedAction,
5
- } from './schemas/common';
6
-
7
- export const SYNCULAR_ERROR_DEFINITIONS = {
8
- 'sync.auth_required': {
9
- category: 'auth-required',
10
- retryable: true,
11
- recommendedAction: 'refreshAuth',
12
- message: 'Authentication is required.',
13
- },
14
- 'sync.auth_lease_missing': {
15
- category: 'auth-required',
16
- retryable: true,
17
- recommendedAction: 'refreshAuth',
18
- message: 'The queued commit is missing required auth lease provenance.',
19
- },
20
- 'sync.auth_lease_invalid': {
21
- category: 'auth-required',
22
- retryable: true,
23
- recommendedAction: 'refreshAuth',
24
- message: 'The queued commit auth lease provenance is invalid.',
25
- },
26
- 'sync.auth_lease_expired': {
27
- category: 'auth-required',
28
- retryable: true,
29
- recommendedAction: 'refreshAuth',
30
- message: 'The queued commit auth lease expired before replay.',
31
- },
32
- 'sync.auth_lease_schema_mismatch': {
33
- category: 'schema-mismatch',
34
- retryable: false,
35
- recommendedAction: 'regenerateClient',
36
- message:
37
- 'The queued commit auth lease was issued for an incompatible schema.',
38
- },
39
- 'sync.auth_lease_scope_mismatch': {
40
- category: 'forbidden',
41
- retryable: false,
42
- recommendedAction: 'checkPermissions',
43
- message: 'The queued commit auth lease does not cover the pushed scopes.',
44
- },
45
- 'sync.auth_lease_scope_revoked': {
46
- category: 'scope-revoked',
47
- retryable: false,
48
- recommendedAction: 'checkPermissions',
49
- message: 'The queued commit auth lease scope was revoked.',
50
- },
51
- 'sync.auth_lease_business_rejected': {
52
- category: 'conflict',
53
- retryable: false,
54
- recommendedAction: 'resolveConflict',
55
- message: 'The queued commit auth lease was rejected by application policy.',
56
- },
57
- 'sync.forbidden': {
58
- category: 'forbidden',
59
- retryable: false,
60
- recommendedAction: 'checkPermissions',
61
- message: 'The authenticated actor is not allowed to access this resource.',
62
- },
63
- 'sync.invalid_request': {
64
- category: 'invalid-request',
65
- retryable: false,
66
- recommendedAction: 'fixRequest',
67
- message: 'The sync request is invalid.',
68
- },
69
- 'sync.invalid_client_id': {
70
- category: 'invalid-request',
71
- retryable: false,
72
- recommendedAction: 'resetClientId',
73
- message: 'The client id cannot be used for this actor.',
74
- },
75
- 'sync.invalid_subscription': {
76
- category: 'invalid-request',
77
- retryable: false,
78
- recommendedAction: 'fixRequest',
79
- message: 'The subscription is invalid.',
80
- },
81
- 'sync.empty_commit': {
82
- category: 'invalid-request',
83
- retryable: false,
84
- recommendedAction: 'fixRequest',
85
- message: 'The pushed commit has no operations.',
86
- },
87
- 'sync.unknown_table': {
88
- category: 'schema-mismatch',
89
- retryable: false,
90
- recommendedAction: 'regenerateClient',
91
- message: 'The operation targets a table unknown to this server.',
92
- },
93
- 'sync.unsupported_operation': {
94
- category: 'invalid-request',
95
- retryable: false,
96
- recommendedAction: 'fixRequest',
97
- message: 'The operation type is not supported for this table.',
98
- },
99
- 'sync.row_missing': {
100
- category: 'not-found',
101
- retryable: false,
102
- recommendedAction: 'forceResync',
103
- message: 'The operation base row is missing on the server.',
104
- },
105
- 'sync.version_conflict': {
106
- category: 'conflict',
107
- retryable: false,
108
- recommendedAction: 'resolveConflict',
109
- message: 'The operation conflicts with a newer server row version.',
110
- },
111
- 'sync.constraint_violation': {
112
- category: 'invalid-request',
113
- retryable: false,
114
- recommendedAction: 'fixRequest',
115
- message: 'The operation violates a server-side data constraint.',
116
- },
117
- 'sync.missing_scopes': {
118
- category: 'internal',
119
- retryable: false,
120
- recommendedAction: 'inspectServer',
121
- message: 'The server handler emitted a change without scope metadata.',
122
- },
123
- 'sync.idempotency_cache_miss': {
124
- category: 'internal',
125
- retryable: true,
126
- recommendedAction: 'retryLater',
127
- message: 'The server could not read the cached idempotent push result.',
128
- },
129
- 'sync.too_many_operations': {
130
- category: 'invalid-request',
131
- retryable: false,
132
- recommendedAction: 'splitBatch',
133
- message: 'The push contains too many operations.',
134
- },
135
- 'sync.not_found': {
136
- category: 'not-found',
137
- retryable: false,
138
- recommendedAction: 'forceResync',
139
- message: 'The requested sync resource was not found.',
140
- },
141
- 'sync.rate_limited': {
142
- category: 'rate-limited',
143
- retryable: true,
144
- recommendedAction: 'retryLater',
145
- message: 'The request was rate limited.',
146
- },
147
- 'sync.schema_mismatch': {
148
- category: 'schema-mismatch',
149
- retryable: false,
150
- recommendedAction: 'regenerateClient',
151
- message: 'The generated client schema is not compatible with this server.',
152
- },
153
- 'sync.client_schema_unsupported': {
154
- category: 'schema-mismatch',
155
- retryable: false,
156
- recommendedAction: 'upgradeClient',
157
- message: 'The client schema version is no longer supported by this server.',
158
- },
159
- 'sync.integrity_rejected': {
160
- category: 'integrity-rejected',
161
- retryable: false,
162
- recommendedAction: 'forceResync',
163
- message: 'Sync data failed integrity verification.',
164
- },
165
- 'sync.scope_revoked': {
166
- category: 'scope-revoked',
167
- retryable: false,
168
- recommendedAction: 'checkPermissions',
169
- message: 'A synced subscription scope was revoked.',
170
- },
171
- 'sync.offline': {
172
- category: 'offline',
173
- retryable: true,
174
- recommendedAction: 'retryLater',
175
- message: 'The client is offline.',
176
- },
177
- 'sync.websocket_not_configured': {
178
- category: 'server',
179
- retryable: false,
180
- recommendedAction: 'inspectServer',
181
- message: 'The realtime websocket route is not configured.',
182
- },
183
- 'sync.websocket_connection_limit': {
184
- category: 'rate-limited',
185
- retryable: true,
186
- recommendedAction: 'retryLater',
187
- message: 'The realtime websocket connection limit was reached.',
188
- },
189
- 'sync.transport_failed': {
190
- category: 'transport',
191
- retryable: true,
192
- recommendedAction: 'retryLater',
193
- message: 'The sync transport failed.',
194
- },
195
- 'runtime.busy': {
196
- category: 'rate-limited',
197
- retryable: true,
198
- recommendedAction: 'retryLater',
199
- message: 'The Syncular runtime is busy.',
200
- },
201
- 'runtime.limit_exceeded': {
202
- category: 'limit-exceeded',
203
- retryable: false,
204
- recommendedAction: 'reduceInput',
205
- message: 'A Syncular runtime limit was exceeded.',
206
- },
207
- 'runtime.config_invalid': {
208
- category: 'invalid-request',
209
- retryable: false,
210
- recommendedAction: 'fixRequest',
211
- message: 'The Syncular runtime configuration is invalid.',
212
- },
213
- 'runtime.codegen_mismatch': {
214
- category: 'schema-mismatch',
215
- retryable: false,
216
- recommendedAction: 'regenerateClient',
217
- message: 'The generated client code is not compatible with the runtime.',
218
- },
219
- 'runtime.internal': {
220
- category: 'internal',
221
- retryable: false,
222
- recommendedAction: 'inspectServer',
223
- message: 'The Syncular runtime failed internally.',
224
- },
225
- 'storage.failed': {
226
- category: 'storage',
227
- retryable: false,
228
- recommendedAction: 'inspectStorage',
229
- message: 'The local Syncular storage operation failed.',
230
- },
231
- 'worker.closed': {
232
- category: 'invalid-request',
233
- retryable: false,
234
- recommendedAction: 'fixRequest',
235
- message: 'The Syncular browser worker client is closed.',
236
- },
237
- 'worker.not_open': {
238
- category: 'invalid-request',
239
- retryable: false,
240
- recommendedAction: 'fixRequest',
241
- message: 'The Syncular browser worker is not open.',
242
- },
243
- 'worker.protocol_mismatch': {
244
- category: 'schema-mismatch',
245
- retryable: false,
246
- recommendedAction: 'regenerateClient',
247
- message: 'The Syncular browser worker protocol is incompatible.',
248
- },
249
- 'worker.request_timeout': {
250
- category: 'rate-limited',
251
- retryable: true,
252
- recommendedAction: 'retryLater',
253
- message: 'The Syncular browser worker request timed out.',
254
- },
255
- 'worker.failed': {
256
- category: 'internal',
257
- retryable: false,
258
- recommendedAction: 'recreateClient',
259
- message: 'The Syncular browser worker failed.',
260
- },
261
- 'worker.message_unreadable': {
262
- category: 'internal',
263
- retryable: false,
264
- recommendedAction: 'recreateClient',
265
- message: 'The Syncular browser worker sent an unreadable message.',
266
- },
267
- 'console.auth_required': {
268
- category: 'auth-required',
269
- retryable: true,
270
- recommendedAction: 'refreshAuth',
271
- message: 'Console authentication is required.',
272
- },
273
- 'console.forbidden_origin': {
274
- category: 'forbidden',
275
- retryable: false,
276
- recommendedAction: 'checkPermissions',
277
- message: 'The console websocket origin is not allowed.',
278
- },
279
- 'console.invalid_request': {
280
- category: 'invalid-request',
281
- retryable: false,
282
- recommendedAction: 'fixRequest',
283
- message: 'The console request is invalid.',
284
- },
285
- 'console.schema_unavailable': {
286
- category: 'server',
287
- retryable: true,
288
- recommendedAction: 'retryLater',
289
- message: 'The console schema is not available.',
290
- },
291
- 'console.not_found': {
292
- category: 'not-found',
293
- retryable: false,
294
- recommendedAction: 'inspectServer',
295
- message: 'The requested console resource was not found.',
296
- },
297
- 'console.downstream_unavailable': {
298
- category: 'server',
299
- retryable: true,
300
- recommendedAction: 'retryLater',
301
- message: 'A console downstream instance is unavailable.',
302
- },
303
- 'console.downstream_invalid_response': {
304
- category: 'server',
305
- retryable: false,
306
- recommendedAction: 'inspectServer',
307
- message: 'A console downstream instance returned an invalid response.',
308
- },
309
- 'console.internal': {
310
- category: 'internal',
311
- retryable: false,
312
- recommendedAction: 'inspectServer',
313
- message: 'The console route failed internally.',
314
- },
315
- 'proxy.auth_required': {
316
- category: 'auth-required',
317
- retryable: true,
318
- recommendedAction: 'refreshAuth',
319
- message: 'Proxy authentication is required.',
320
- },
321
- 'proxy.forbidden_origin': {
322
- category: 'forbidden',
323
- retryable: false,
324
- recommendedAction: 'checkPermissions',
325
- message: 'The proxy websocket origin is not allowed.',
326
- },
327
- 'proxy.connection_limit': {
328
- category: 'rate-limited',
329
- retryable: true,
330
- recommendedAction: 'retryLater',
331
- message: 'The proxy websocket connection limit was reached.',
332
- },
333
- 'blob.invalid_request': {
334
- category: 'blob',
335
- retryable: false,
336
- recommendedAction: 'fixRequest',
337
- message: 'The blob request is invalid.',
338
- },
339
- 'blob.storage_not_configured': {
340
- category: 'blob',
341
- retryable: false,
342
- recommendedAction: 'inspectServer',
343
- message: 'Blob storage is not configured.',
344
- },
345
- 'blob.too_large': {
346
- category: 'blob',
347
- retryable: false,
348
- recommendedAction: 'fixRequest',
349
- message: 'The blob is too large.',
350
- },
351
- 'blob.not_found': {
352
- category: 'blob',
353
- retryable: false,
354
- recommendedAction: 'fixRequest',
355
- message: 'The blob was not found.',
356
- },
357
- 'blob.forbidden': {
358
- category: 'forbidden',
359
- retryable: false,
360
- recommendedAction: 'checkPermissions',
361
- message: 'The authenticated actor is not allowed to access this blob.',
362
- },
363
- 'blob.invalid_token': {
364
- category: 'auth-required',
365
- retryable: true,
366
- recommendedAction: 'refreshAuth',
367
- message: 'The blob token is invalid or expired.',
368
- },
369
- 'blob.upload_failed': {
370
- category: 'blob',
371
- retryable: true,
372
- recommendedAction: 'retryLater',
373
- message: 'The blob upload failed.',
374
- },
375
- 'blob.hash_mismatch': {
376
- category: 'integrity-rejected',
377
- retryable: false,
378
- recommendedAction: 'fixRequest',
379
- message: 'The blob content hash does not match.',
380
- },
381
- 'blob.size_mismatch': {
382
- category: 'blob',
383
- retryable: false,
384
- recommendedAction: 'fixRequest',
385
- message: 'The blob size does not match.',
386
- },
387
- } as const satisfies Record<
388
- string,
389
- {
390
- category: SyncularErrorCategory;
391
- retryable: boolean;
392
- recommendedAction: SyncularErrorRecommendedAction;
393
- message: string;
394
- }
395
- >;
396
-
397
- export type SyncularErrorCode = keyof typeof SYNCULAR_ERROR_DEFINITIONS;
398
-
399
- export interface CreateSyncularErrorResponseOptions {
400
- message?: string;
401
- details?: Record<string, unknown>;
402
- }
403
-
404
- export function createSyncularErrorResponse(
405
- code: SyncularErrorCode,
406
- options: CreateSyncularErrorResponseOptions = {}
407
- ): ErrorResponse & {
408
- code: SyncularErrorCode;
409
- category: SyncularErrorCategory;
410
- retryable: boolean;
411
- recommendedAction: SyncularErrorRecommendedAction;
412
- } {
413
- const definition = SYNCULAR_ERROR_DEFINITIONS[code];
414
- return {
415
- error: code,
416
- code,
417
- message: options.message ?? definition.message,
418
- category: definition.category,
419
- retryable: definition.retryable,
420
- recommendedAction: definition.recommendedAction,
421
- ...(options.details ? { details: options.details } : {}),
422
- };
423
- }
@@ -1,39 +0,0 @@
1
- import createClient from 'openapi-fetch';
2
- import type { paths } from './generated/api';
3
- import type { ClientOptions } from './shared';
4
-
5
- export type SyncClient = ReturnType<typeof createClient<paths>>;
6
-
7
- /**
8
- * Create a typed API client for the full Syncular API.
9
- *
10
- * Returns an openapi-fetch client with full type safety for all endpoints.
11
- */
12
- export function createApiClient(options: ClientOptions): SyncClient {
13
- const client = createClient<paths>({
14
- baseUrl: options.baseUrl,
15
- ...(options.fetch && { fetch: options.fetch }),
16
- });
17
-
18
- const getHeaders = options.getHeaders;
19
- const transportPath = options.transportPath ?? 'direct';
20
-
21
- client.use({
22
- async onRequest({ request }) {
23
- if (getHeaders) {
24
- const headers = await getHeaders();
25
- for (const [key, value] of Object.entries(headers)) {
26
- request.headers.set(key, value);
27
- }
28
- }
29
-
30
- if (!request.headers.has('x-syncular-transport-path')) {
31
- request.headers.set('x-syncular-transport-path', transportPath);
32
- }
33
-
34
- return request;
35
- },
36
- });
37
-
38
- return client;
39
- }
package/src/http/blob.ts DELETED
@@ -1,95 +0,0 @@
1
- import type { SyncTransport, SyncTransportBlobs } from '@syncular/core';
2
- import { SyncTransportError } from '@syncular/core';
3
- import { executeWithAuthRetry, getErrorMessage } from './shared';
4
- import {
5
- createTransportApiClient,
6
- createTransportAuthRetryResolver,
7
- HTTP_TRANSPORT_SOURCE,
8
- type HttpTransportSource,
9
- } from './transport-client';
10
-
11
- type HttpTransportWithSource = SyncTransport & {
12
- [HTTP_TRANSPORT_SOURCE]?: HttpTransportSource;
13
- };
14
-
15
- export function createHttpTransportBlobs(
16
- source: HttpTransportSource
17
- ): SyncTransportBlobs {
18
- const client = createTransportApiClient(source);
19
- const resolveAuthRetry = createTransportAuthRetryResolver(source);
20
-
21
- return {
22
- async initiateUpload(args) {
23
- const { data, error, response } = await executeWithAuthRetry(
24
- (signal) => client.initiateUpload(args, signal),
25
- undefined,
26
- 'blobInitiateUpload',
27
- resolveAuthRetry
28
- );
29
-
30
- if (error || !data) {
31
- throw new SyncTransportError(
32
- `Blob upload init failed: ${getErrorMessage(error) || response.statusText}`,
33
- response.status
34
- );
35
- }
36
-
37
- return data;
38
- },
39
-
40
- async completeUpload(hash) {
41
- const { data, error } = await executeWithAuthRetry(
42
- (signal) => client.completeUpload(hash, signal),
43
- undefined,
44
- 'blobCompleteUpload',
45
- resolveAuthRetry
46
- );
47
-
48
- if (error || !data) {
49
- return {
50
- ok: false,
51
- error: getErrorMessage(error) || 'Complete upload failed',
52
- };
53
- }
54
-
55
- return data;
56
- },
57
-
58
- async getDownloadUrl(hash) {
59
- const { data, error, response } = await executeWithAuthRetry(
60
- (signal) => client.getDownloadUrl(hash, signal),
61
- undefined,
62
- 'blobGetDownloadUrl',
63
- resolveAuthRetry
64
- );
65
-
66
- if (error || !data) {
67
- throw new SyncTransportError(
68
- `Get download URL failed: ${getErrorMessage(error) || response.statusText}`,
69
- response.status
70
- );
71
- }
72
-
73
- return data;
74
- },
75
- };
76
- }
77
-
78
- export function ensureHttpTransportBlobs(
79
- transport: SyncTransport
80
- ): SyncTransportBlobs | null {
81
- if (transport.blobs) {
82
- return transport.blobs;
83
- }
84
-
85
- const source = (transport as HttpTransportWithSource)[HTTP_TRANSPORT_SOURCE];
86
- if (!source) {
87
- return null;
88
- }
89
-
90
- const blobs = createHttpTransportBlobs(source);
91
- transport.blobs = blobs;
92
- return blobs;
93
- }
94
-
95
- export type { SyncClient } from './api-client';