@svadmin/supabase 0.17.0 → 0.18.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.
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/supacloud.ts +33 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/supabase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Supabase adapters — DataProvider, AuthProvider, LiveProvider, AuditHandler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"migration": null
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@svadmin/core": "^0.
|
|
39
|
+
"@svadmin/core": "^0.58.0",
|
|
40
40
|
"@supabase/supabase-js": "^2.112.4",
|
|
41
41
|
"@refinedev/supabase": "^6.0.2",
|
|
42
|
-
"@supacloud/js": "^0.
|
|
42
|
+
"@supacloud/js": "^0.33.0"
|
|
43
43
|
},
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"author": "zuohuadong",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@sinclair/typebox": "^0.34.52",
|
|
71
|
-
"@svadmin/refine-adapter": "^0.12.
|
|
71
|
+
"@svadmin/refine-adapter": "^0.12.2"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@supacloud/js": "0.
|
|
75
|
-
"@supabase/supabase-js": "
|
|
74
|
+
"@supacloud/js": "0.33.0",
|
|
75
|
+
"@supabase/supabase-js": "2.117.1"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/index.ts
CHANGED
package/src/supacloud.ts
CHANGED
|
@@ -26,6 +26,17 @@ const snapshotSchema = Type.Object({
|
|
|
26
26
|
updatedAt: Type.Optional(Type.Union([text, Type.Null()])),
|
|
27
27
|
}, { additionalProperties: false });
|
|
28
28
|
const liveParamsSchema = Type.Object({ taskId: idSchema }, { additionalProperties: false });
|
|
29
|
+
const timerSchema = Type.Integer({ minimum: 0, maximum: 2_147_483_647 });
|
|
30
|
+
const subscriptionSchema = Type.Object({
|
|
31
|
+
realtime: Type.Optional(Type.Object({
|
|
32
|
+
schema: Type.String({ pattern: '^[A-Za-z_][A-Za-z0-9_]{0,62}$' }),
|
|
33
|
+
table: Type.String({ pattern: '^[A-Za-z_][A-Za-z0-9_]{0,62}$' }),
|
|
34
|
+
}, { additionalProperties: false })),
|
|
35
|
+
pollingIntervalMs: Type.Optional(Type.Integer({ minimum: 1, maximum: 2_147_483_647 })),
|
|
36
|
+
realtimeTimeoutMs: Type.Optional(timerSchema),
|
|
37
|
+
reconcileIntervalMs: Type.Optional(timerSchema),
|
|
38
|
+
stopOnTerminal: Type.Optional(Type.Boolean()),
|
|
39
|
+
}, { additionalProperties: false });
|
|
29
40
|
const eventSchema = Type.Object({
|
|
30
41
|
type: Type.Union([Type.Literal('INSERT'), Type.Literal('UPDATE'), Type.Literal('DELETE')]),
|
|
31
42
|
resource: text, payload: Type.Record(Type.String(), Type.Unknown()),
|
|
@@ -43,7 +54,9 @@ export interface SupaCloudTaskSdkSubmitOptions {
|
|
|
43
54
|
metadata?: Record<string, unknown>;
|
|
44
55
|
}
|
|
45
56
|
|
|
46
|
-
export
|
|
57
|
+
export type SupaCloudTaskSubscriptionOptions = Static<typeof subscriptionSchema>;
|
|
58
|
+
|
|
59
|
+
export interface SupaCloudTaskSubscribeOptions extends SupaCloudTaskSubscriptionOptions {
|
|
47
60
|
onUpdate: (snapshot: unknown) => void;
|
|
48
61
|
onError: (error: unknown) => void;
|
|
49
62
|
}
|
|
@@ -80,6 +93,7 @@ export interface SupaCloudTaskProvider extends TaskProvider<SupaCloudTaskRecord>
|
|
|
80
93
|
export interface CreateSupaCloudTaskProviderOptions {
|
|
81
94
|
supacloud: SupaCloudTaskClient;
|
|
82
95
|
onError?: (error: TaskError) => void;
|
|
96
|
+
subscription?: SupaCloudTaskSubscriptionOptions;
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
export interface CreateSupaCloudTaskLiveProviderOptions {
|
|
@@ -87,6 +101,7 @@ export interface CreateSupaCloudTaskLiveProviderOptions {
|
|
|
87
101
|
resource?: string;
|
|
88
102
|
mapTaskToEvent?: (task: SupaCloudTaskRecord, resource: string) => unknown;
|
|
89
103
|
onError?: (error: TaskError) => void;
|
|
104
|
+
subscription?: SupaCloudTaskSubscriptionOptions;
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
function decode<S extends TSchema>(schema: S, value: unknown, input = false, write = false): Static<S> {
|
|
@@ -179,7 +194,10 @@ function submitOptions(value: SubmitTaskOptions | undefined): SupaCloudTaskSdkSu
|
|
|
179
194
|
});
|
|
180
195
|
}
|
|
181
196
|
|
|
182
|
-
function receipt(
|
|
197
|
+
function receipt(
|
|
198
|
+
value: unknown, subscription: SupaCloudTaskSubscriptionOptions,
|
|
199
|
+
onError?: (error: TaskError) => void,
|
|
200
|
+
): SupaCloudTaskHandle {
|
|
183
201
|
const id = decode(idSchema, ownField(value, 'taskId', true), false, true);
|
|
184
202
|
decode(statusSchema, ownField(value, 'status', true), false, true);
|
|
185
203
|
const wait = method(value, 'wait', true);
|
|
@@ -196,7 +214,7 @@ function receipt(value: unknown, onError?: (error: TaskError) => void): SupaClou
|
|
|
196
214
|
async cancel() { return taskRecord(await request(() => cancel(), true), id, true); },
|
|
197
215
|
async retry() { return taskRecord(await request(() => retry(), true), id, true); },
|
|
198
216
|
subscribe(callback, subscriptionError) {
|
|
199
|
-
return listen(options => subscribe(options), id, callback, subscriptionError ?? onError);
|
|
217
|
+
return listen(options => subscribe({ ...subscription, ...options }), id, callback, subscriptionError ?? onError);
|
|
200
218
|
},
|
|
201
219
|
};
|
|
202
220
|
}
|
|
@@ -211,6 +229,7 @@ export function createSupaCloudTaskProvider(options: CreateSupaCloudTaskProvider
|
|
|
211
229
|
const retry = requiredTaskClientMethod(sdk, 'retry');
|
|
212
230
|
const subscribe = requiredTaskClientMethod(sdk, 'subscribe');
|
|
213
231
|
const onError = errorCallback(taskClientField(options, 'onError'));
|
|
232
|
+
const subscription = subscriptionOptions(options);
|
|
214
233
|
const listResult = (value: unknown) => {
|
|
215
234
|
const values = decode(Type.Array(Type.Unknown()), value);
|
|
216
235
|
const data = values.map(value => taskRecord(value));
|
|
@@ -220,7 +239,7 @@ export function createSupaCloudTaskProvider(options: CreateSupaCloudTaskProvider
|
|
|
220
239
|
async submit(name, options) {
|
|
221
240
|
const taskName = decode(nameSchema, name, true);
|
|
222
241
|
const params = submitOptions(options);
|
|
223
|
-
return receipt(await request(() => submit(taskName, params), true), onError);
|
|
242
|
+
return receipt(await request(() => submit(taskName, params), true), subscription, onError);
|
|
224
243
|
},
|
|
225
244
|
async get(taskId) {
|
|
226
245
|
const id = decode(idSchema, taskId, true);
|
|
@@ -244,7 +263,7 @@ export function createSupaCloudTaskProvider(options: CreateSupaCloudTaskProvider
|
|
|
244
263
|
},
|
|
245
264
|
subscribe(taskId, callback, subscriptionError) {
|
|
246
265
|
const id = decode(idSchema, taskId, true);
|
|
247
|
-
return listen(options => subscribe(id, options), id, callback, subscriptionError ?? onError);
|
|
266
|
+
return listen(options => subscribe(id, { ...subscription, ...options }), id, callback, subscriptionError ?? onError);
|
|
248
267
|
},
|
|
249
268
|
};
|
|
250
269
|
}
|
|
@@ -255,6 +274,13 @@ function errorCallback(value: unknown): ((error: TaskError) => unknown) | undefi
|
|
|
255
274
|
return error => { const result: unknown = Reflect.apply(value, undefined, [error]); return result; };
|
|
256
275
|
}
|
|
257
276
|
|
|
277
|
+
function subscriptionOptions(options: unknown): SupaCloudTaskSubscriptionOptions {
|
|
278
|
+
const value = taskClientField(options, 'subscription');
|
|
279
|
+
const subscription = decode(subscriptionSchema, value === undefined ? {} : value, true);
|
|
280
|
+
if (subscription.realtime) Object.freeze(subscription.realtime);
|
|
281
|
+
return Object.freeze(subscription);
|
|
282
|
+
}
|
|
283
|
+
|
|
258
284
|
export function createSupaCloudTaskLiveProvider(options: CreateSupaCloudTaskLiveProviderOptions): LiveProvider {
|
|
259
285
|
const sdk = taskClientField(taskClientField(options, 'supacloud'), 'tasks');
|
|
260
286
|
const subscribe = requiredTaskClientMethod(sdk, 'subscribe');
|
|
@@ -263,12 +289,13 @@ export function createSupaCloudTaskLiveProvider(options: CreateSupaCloudTaskLive
|
|
|
263
289
|
const map = taskClientField(options, 'mapTaskToEvent');
|
|
264
290
|
if (map !== undefined && typeof map !== 'function') throw new TaskError('INVALID_TASK_INPUT');
|
|
265
291
|
const onError = errorCallback(taskClientField(options, 'onError'));
|
|
292
|
+
const subscription = subscriptionOptions(options);
|
|
266
293
|
return {
|
|
267
294
|
subscribe({ resource, liveParams, callback }) {
|
|
268
295
|
const resourceId = decode(text, resource === undefined ? resourceName : resource, true);
|
|
269
296
|
const { taskId } = decode(liveParamsSchema, liveParams, true);
|
|
270
297
|
return validatedTaskSubscription(
|
|
271
|
-
(onUpdate, onError) => subscribe(taskId, { onUpdate, onError }),
|
|
298
|
+
(onUpdate, onError) => subscribe(taskId, { ...subscription, onUpdate, onError }),
|
|
272
299
|
value => {
|
|
273
300
|
const task = taskSnapshot(value, taskId);
|
|
274
301
|
let mapped: unknown;
|