@supacloud/js 0.47.0 → 0.48.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/README.md +4 -3
- package/dist/index.cjs +97 -49
- package/dist/index.d.cts +37 -8
- package/dist/index.d.mts +37 -8
- package/dist/index.mjs +97 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -446,12 +446,13 @@ That table must expose the platform task `id`, `project_ref` and `status`,
|
|
|
446
446
|
and have appropriate publication, SELECT privileges and row-level policies.
|
|
447
447
|
The SDK does not create the table or grant access. Schema/table names must be
|
|
448
448
|
simple identifiers of at most 63 characters. Explicit Realtime subscriptions
|
|
449
|
-
retain Management polling on connection failure
|
|
449
|
+
retain Management polling on connection failure, retry Realtime while polling,
|
|
450
|
+
and perform periodic reconciliation after reconnecting.
|
|
450
451
|
An omitted source no longer guesses `public.tasks`; malformed source options
|
|
451
452
|
are rejected before opening a channel.
|
|
452
453
|
Polling intervals must be integer milliseconds from 1 through 2,147,483,647.
|
|
453
|
-
Realtime connection timeout and reconciliation intervals accept the
|
|
454
|
-
range plus 0 to disable that timer. Invalid explicit values, including null,
|
|
454
|
+
Realtime connection timeout, recovery, and reconciliation intervals accept the
|
|
455
|
+
same range plus 0 to disable that timer. Invalid explicit values, including null,
|
|
455
456
|
are rejected before authentication or subscription work. The computed default
|
|
456
457
|
reconciliation interval is capped at the same maximum.
|
|
457
458
|
Subscription options are captured at creation. Callbacks must be functions,
|
package/dist/index.cjs
CHANGED
|
@@ -4145,6 +4145,7 @@ function captureTaskSubscribeOptions(options) {
|
|
|
4145
4145
|
"realtime",
|
|
4146
4146
|
"pollingIntervalMs",
|
|
4147
4147
|
"realtimeTimeoutMs",
|
|
4148
|
+
"realtimeRecoveryIntervalMs",
|
|
4148
4149
|
"reconcileIntervalMs",
|
|
4149
4150
|
"onUpdate",
|
|
4150
4151
|
"onStateChange",
|
|
@@ -4487,10 +4488,12 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4487
4488
|
let channel = null;
|
|
4488
4489
|
let pollTimer = null;
|
|
4489
4490
|
let realtimeTimeoutTimer = null;
|
|
4491
|
+
let realtimeRecoveryTimer = null;
|
|
4490
4492
|
let reconcileTimer = null;
|
|
4491
4493
|
let mode = "connecting";
|
|
4492
4494
|
const pollingIntervalMs = taskTimerMs(options.pollingIntervalMs === undefined ? this.options.pollingIntervalMs : options.pollingIntervalMs);
|
|
4493
4495
|
const realtimeTimeoutMs = taskTimerMs(options.realtimeTimeoutMs === undefined ? 1e4 : options.realtimeTimeoutMs, true);
|
|
4496
|
+
const realtimeRecoveryIntervalMs = taskTimerMs(options.realtimeRecoveryIntervalMs === undefined ? Math.min(MAX_TASK_TIMER_MS, Math.max(30000, pollingIntervalMs * 10)) : options.realtimeRecoveryIntervalMs, true);
|
|
4494
4497
|
const reconcileIntervalMs = taskTimerMs(options.reconcileIntervalMs === undefined ? Math.min(MAX_TASK_TIMER_MS, Math.max(30000, pollingIntervalMs * 10)) : options.reconcileIntervalMs, true);
|
|
4495
4498
|
const stopOnTerminal = options.stopOnTerminal ?? true;
|
|
4496
4499
|
const readController = new AbortController;
|
|
@@ -4534,6 +4537,12 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4534
4537
|
realtimeTimeoutTimer = null;
|
|
4535
4538
|
}
|
|
4536
4539
|
};
|
|
4540
|
+
const stopRealtimeRecovery = () => {
|
|
4541
|
+
if (realtimeRecoveryTimer) {
|
|
4542
|
+
clearTimeout(realtimeRecoveryTimer);
|
|
4543
|
+
realtimeRecoveryTimer = null;
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4537
4546
|
const stopReconcile = () => {
|
|
4538
4547
|
if (reconcileTimer) {
|
|
4539
4548
|
clearTimeout(reconcileTimer);
|
|
@@ -4558,6 +4567,7 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4558
4567
|
readController.abort();
|
|
4559
4568
|
stopPolling();
|
|
4560
4569
|
stopRealtimeTimeout();
|
|
4570
|
+
stopRealtimeRecovery();
|
|
4561
4571
|
stopReconcile();
|
|
4562
4572
|
try {
|
|
4563
4573
|
await teardownRealtime();
|
|
@@ -4621,14 +4631,80 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4621
4631
|
reconcileOnce();
|
|
4622
4632
|
}, reconcileIntervalMs);
|
|
4623
4633
|
};
|
|
4634
|
+
const scheduleRealtimeRecovery = () => {
|
|
4635
|
+
if (closed || !realtime2 || mode !== "polling" || realtimeRecoveryIntervalMs <= 0)
|
|
4636
|
+
return;
|
|
4637
|
+
stopRealtimeRecovery();
|
|
4638
|
+
realtimeRecoveryTimer = setTimeout(() => {
|
|
4639
|
+
realtimeRecoveryTimer = null;
|
|
4640
|
+
startRealtime();
|
|
4641
|
+
}, realtimeRecoveryIntervalMs);
|
|
4642
|
+
};
|
|
4624
4643
|
const startPolling = (error) => {
|
|
4625
4644
|
if (closed)
|
|
4626
4645
|
return;
|
|
4627
4646
|
stopPolling();
|
|
4628
4647
|
stopRealtimeTimeout();
|
|
4629
4648
|
stopReconcile();
|
|
4649
|
+
stopRealtimeRecovery();
|
|
4630
4650
|
setMode("polling", { error });
|
|
4631
4651
|
pollOnce();
|
|
4652
|
+
scheduleRealtimeRecovery();
|
|
4653
|
+
};
|
|
4654
|
+
const startRealtime = () => {
|
|
4655
|
+
if (closed || !realtime2 || channel)
|
|
4656
|
+
return;
|
|
4657
|
+
stopRealtimeRecovery();
|
|
4658
|
+
channel = this.options.supabase.channel(`supacloud-task:${this.options.projectRef}:${taskId}`).on("postgres_changes", {
|
|
4659
|
+
event: "*",
|
|
4660
|
+
schema: realtime2.schema,
|
|
4661
|
+
table: realtime2.table,
|
|
4662
|
+
filter: `id=eq.${taskId}`
|
|
4663
|
+
}, (payload) => {
|
|
4664
|
+
const next = payload.new && Object.keys(payload.new).length > 0 ? payload.new : payload.old;
|
|
4665
|
+
if (next)
|
|
4666
|
+
emitTask(next);
|
|
4667
|
+
});
|
|
4668
|
+
channel.subscribe(async (status, error) => {
|
|
4669
|
+
if (closed)
|
|
4670
|
+
return;
|
|
4671
|
+
if (status === "SUBSCRIBED") {
|
|
4672
|
+
stopPolling();
|
|
4673
|
+
stopRealtimeTimeout();
|
|
4674
|
+
setMode("realtime");
|
|
4675
|
+
if (closed)
|
|
4676
|
+
return;
|
|
4677
|
+
try {
|
|
4678
|
+
emitTask(await readTask(readController.signal));
|
|
4679
|
+
} catch (err) {
|
|
4680
|
+
if (!closed)
|
|
4681
|
+
reportError(err);
|
|
4682
|
+
}
|
|
4683
|
+
startReconcile();
|
|
4684
|
+
return;
|
|
4685
|
+
}
|
|
4686
|
+
if (status === "TIMED_OUT" || status === "CHANNEL_ERROR" || status === "CLOSED") {
|
|
4687
|
+
await teardownRealtime();
|
|
4688
|
+
if (mode === "polling") {
|
|
4689
|
+
scheduleRealtimeRecovery();
|
|
4690
|
+
} else {
|
|
4691
|
+
startPolling(error);
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
});
|
|
4695
|
+
if (!closed && channel && mode !== "realtime" && realtimeTimeoutMs > 0) {
|
|
4696
|
+
realtimeTimeoutTimer = setTimeout(() => {
|
|
4697
|
+
if (!closed && channel) {
|
|
4698
|
+
teardownRealtime().finally(() => {
|
|
4699
|
+
if (mode === "polling") {
|
|
4700
|
+
scheduleRealtimeRecovery();
|
|
4701
|
+
} else {
|
|
4702
|
+
startPolling(new Error("SupaCloud Realtime subscription timed out"));
|
|
4703
|
+
}
|
|
4704
|
+
});
|
|
4705
|
+
}
|
|
4706
|
+
}, realtimeTimeoutMs);
|
|
4707
|
+
}
|
|
4632
4708
|
};
|
|
4633
4709
|
const subscription = {
|
|
4634
4710
|
get connectionState() {
|
|
@@ -4642,49 +4718,8 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4642
4718
|
startPolling();
|
|
4643
4719
|
return subscription;
|
|
4644
4720
|
}
|
|
4645
|
-
channel = this.options.supabase.channel(`supacloud-task:${this.options.projectRef}:${taskId}`).on("postgres_changes", {
|
|
4646
|
-
event: "*",
|
|
4647
|
-
schema: realtime2.schema,
|
|
4648
|
-
table: realtime2.table,
|
|
4649
|
-
filter: `id=eq.${taskId}`
|
|
4650
|
-
}, (payload) => {
|
|
4651
|
-
const next = payload.new && Object.keys(payload.new).length > 0 ? payload.new : payload.old;
|
|
4652
|
-
if (next)
|
|
4653
|
-
emitTask(next);
|
|
4654
|
-
});
|
|
4655
|
-
channel.subscribe(async (status, error) => {
|
|
4656
|
-
if (closed)
|
|
4657
|
-
return;
|
|
4658
|
-
if (status === "SUBSCRIBED") {
|
|
4659
|
-
stopPolling();
|
|
4660
|
-
stopRealtimeTimeout();
|
|
4661
|
-
setMode("realtime");
|
|
4662
|
-
if (closed)
|
|
4663
|
-
return;
|
|
4664
|
-
try {
|
|
4665
|
-
emitTask(await readTask(readController.signal));
|
|
4666
|
-
} catch (err) {
|
|
4667
|
-
if (!closed)
|
|
4668
|
-
reportError(err);
|
|
4669
|
-
}
|
|
4670
|
-
startReconcile();
|
|
4671
|
-
return;
|
|
4672
|
-
}
|
|
4673
|
-
if (status === "TIMED_OUT" || status === "CHANNEL_ERROR" || status === "CLOSED") {
|
|
4674
|
-
await teardownRealtime();
|
|
4675
|
-
startPolling(error);
|
|
4676
|
-
}
|
|
4677
|
-
});
|
|
4678
|
-
if (!closed && realtimeTimeoutMs > 0) {
|
|
4679
|
-
realtimeTimeoutTimer = setTimeout(() => {
|
|
4680
|
-
if (!closed && mode === "connecting") {
|
|
4681
|
-
teardownRealtime().finally(() => {
|
|
4682
|
-
startPolling(new Error("SupaCloud Realtime subscription timed out"));
|
|
4683
|
-
});
|
|
4684
|
-
}
|
|
4685
|
-
}, realtimeTimeoutMs);
|
|
4686
|
-
}
|
|
4687
4721
|
setMode("connecting");
|
|
4722
|
+
startRealtime();
|
|
4688
4723
|
return subscription;
|
|
4689
4724
|
}
|
|
4690
4725
|
}
|
|
@@ -4881,6 +4916,12 @@ function openSupabaseChannel(supabase, topic, config) {
|
|
|
4881
4916
|
}
|
|
4882
4917
|
});
|
|
4883
4918
|
}
|
|
4919
|
+
function createApplicationSurface(apiClient) {
|
|
4920
|
+
return {
|
|
4921
|
+
procedures: createProcedureClient(apiClient),
|
|
4922
|
+
queryAdapter: (options) => createQueryAdapter(apiClient, options)
|
|
4923
|
+
};
|
|
4924
|
+
}
|
|
4884
4925
|
function createSupaCloudClient(options) {
|
|
4885
4926
|
const normalized = {
|
|
4886
4927
|
...options,
|
|
@@ -4902,6 +4943,7 @@ function createSupaCloudClient(options) {
|
|
|
4902
4943
|
});
|
|
4903
4944
|
const instance = {
|
|
4904
4945
|
supabase: options.supabase,
|
|
4946
|
+
compat: { supabase: options.supabase },
|
|
4905
4947
|
projectRef: normalized.projectRef,
|
|
4906
4948
|
managementApiUrl: normalized.managementApiUrl,
|
|
4907
4949
|
auth: {
|
|
@@ -4921,21 +4963,27 @@ function createSupaCloudClient(options) {
|
|
|
4921
4963
|
}
|
|
4922
4964
|
};
|
|
4923
4965
|
const withClient = (apiClient) => {
|
|
4966
|
+
const app = createApplicationSurface(apiClient);
|
|
4924
4967
|
return {
|
|
4925
4968
|
...instance,
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4969
|
+
app,
|
|
4970
|
+
procedures: app.procedures,
|
|
4971
|
+
queryAdapter: app.queryAdapter,
|
|
4972
|
+
withClient,
|
|
4973
|
+
withApp: withClient
|
|
4929
4974
|
};
|
|
4930
4975
|
};
|
|
4976
|
+
const app = options.apiClient === undefined ? undefined : createApplicationSurface(options.apiClient);
|
|
4931
4977
|
return {
|
|
4932
4978
|
...instance,
|
|
4933
|
-
|
|
4979
|
+
app,
|
|
4980
|
+
procedures: app === undefined ? undefined : app.procedures,
|
|
4934
4981
|
queryAdapter: (adapterOptions) => {
|
|
4935
|
-
if (
|
|
4982
|
+
if (app === undefined)
|
|
4936
4983
|
throw new Error("No procedure client attached");
|
|
4937
|
-
return
|
|
4984
|
+
return app.queryAdapter(adapterOptions);
|
|
4938
4985
|
},
|
|
4939
|
-
withClient
|
|
4986
|
+
withClient,
|
|
4987
|
+
withApp: withClient
|
|
4940
4988
|
};
|
|
4941
4989
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,8 +7,8 @@ import { type FetchTransport } from "./bounded-rpc-fetch.cjs";
|
|
|
7
7
|
import { SupaCloudOAuthClientsClient } from "./oauth-clients.cjs";
|
|
8
8
|
import { SupaCloudOAuthServerClient } from "./oauth-server.cjs";
|
|
9
9
|
import { type RealtimeChannelConfig, type RealtimeTransport, type SupaCloudRealtimeChannel, type SupaCloudRealtimeAdapter } from "./realtime.cjs";
|
|
10
|
-
import { createQueryAdapter, type ProcedureSource, type ProceduresOf, type QueryAdapterOptions } from "@supacloud/query";
|
|
11
|
-
export { createProcedureClient, createQueryAdapter, createQueryKey, invalidateByTags, type QueryAdapter, type QueryAdapterOptions, } from "@supacloud/query";
|
|
10
|
+
import { createQueryAdapter, type ProcedureSource, type ProceduresOf, type QueryAdapter, type QueryAdapterOptions } from "@supacloud/query";
|
|
11
|
+
export { createProcedureClient, createQueryAdapter, createQueryKey, invalidateByTags, type ProcedureSource, type ProceduresOf, type QueryAdapter, type QueryAdapterOptions, } from "@supacloud/query";
|
|
12
12
|
import { type SupaCloudQueueJson, type SupaCloudQueueMessage, type SupaCloudQueueSendResult, type SupaCloudQueueIdempotentSendResult, type SupaCloudQueueMutationResult } from "./queue-rpc.cjs";
|
|
13
13
|
export { SupaCloudApiError } from "./api-error.cjs";
|
|
14
14
|
export { SupaCloudQueueError, type SupaCloudQueueJson, type SupaCloudQueueMessage, type SupaCloudQueueSendResult, type SupaCloudQueueIdempotentSendResult, type SupaCloudQueueMutationResult, } from "./queue-rpc.cjs";
|
|
@@ -205,6 +205,7 @@ export type SupaCloudTaskSubscribeOptions<TResult = unknown> = {
|
|
|
205
205
|
};
|
|
206
206
|
pollingIntervalMs?: number;
|
|
207
207
|
realtimeTimeoutMs?: number;
|
|
208
|
+
realtimeRecoveryIntervalMs?: number;
|
|
208
209
|
reconcileIntervalMs?: number;
|
|
209
210
|
onUpdate: (task: SupaCloudTaskSnapshot<TResult>) => void;
|
|
210
211
|
onStateChange?: (state: SupaCloudTaskSubscribeState, details?: {
|
|
@@ -230,6 +231,21 @@ export type SupaCloudClientOptions<TClient extends SupabaseClient = SupabaseClie
|
|
|
230
231
|
pollingIntervalMs?: number;
|
|
231
232
|
realtimeTransport?: RealtimeTransport | null;
|
|
232
233
|
};
|
|
234
|
+
/**
|
|
235
|
+
* Compatibility-lane access remains owned by the caller's Supabase client.
|
|
236
|
+
* This facade never creates a second session store or protocol client.
|
|
237
|
+
*/
|
|
238
|
+
export type SupaCloudCompatibilitySurface<TClient extends SupabaseClient = SupabaseClient> = {
|
|
239
|
+
readonly supabase: TClient;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Application-lane access is compiler-generated and intentionally separate
|
|
243
|
+
* from compatibility CRUD so domain writes have an explicit API boundary.
|
|
244
|
+
*/
|
|
245
|
+
export type SupaCloudApplicationSurface<TApiClient extends ProcedureSource> = {
|
|
246
|
+
readonly procedures: ProceduresOf<TApiClient>;
|
|
247
|
+
readonly queryAdapter: (options: QueryAdapterOptions) => QueryAdapter<TApiClient>;
|
|
248
|
+
};
|
|
233
249
|
export declare class SupaCloudTaskSubmitError extends Error {
|
|
234
250
|
readonly code = "TASK_SUBMIT_UNCONFIRMED";
|
|
235
251
|
readonly mutationMayHaveApplied = true;
|
|
@@ -355,6 +371,7 @@ declare class SupaCloudQueuesClient<TClient extends SupabaseClient = SupabaseCli
|
|
|
355
371
|
}
|
|
356
372
|
type SupaCloudClientBase<TClient extends SupabaseClient> = {
|
|
357
373
|
readonly supabase: TClient;
|
|
374
|
+
readonly compat: SupaCloudCompatibilitySurface<TClient>;
|
|
358
375
|
readonly projectRef: string;
|
|
359
376
|
readonly managementApiUrl: string;
|
|
360
377
|
readonly auth: {
|
|
@@ -373,11 +390,23 @@ type SupaCloudClientBase<TClient extends SupabaseClient> = {
|
|
|
373
390
|
invokeBackground(functionName: string, submitOptions?: SupaCloudTaskSubmitOptions): Promise<SupaCloudTaskReceipt<unknown>>;
|
|
374
391
|
};
|
|
375
392
|
};
|
|
376
|
-
type
|
|
377
|
-
readonly procedures:
|
|
393
|
+
type SupaCloudClientWithApplication<TClient extends SupabaseClient, TApiClient extends ProcedureSource> = SupaCloudClientBase<TClient> & {
|
|
394
|
+
readonly procedures: ProceduresOf<TApiClient>;
|
|
395
|
+
readonly app: SupaCloudApplicationSurface<TApiClient>;
|
|
396
|
+
queryAdapter(options: QueryAdapterOptions): QueryAdapter<TApiClient>;
|
|
397
|
+
withClient<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
398
|
+
withApp<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
399
|
+
};
|
|
400
|
+
type SupaCloudClientUnbound<TClient extends SupabaseClient> = SupaCloudClientBase<TClient> & {
|
|
401
|
+
readonly procedures: undefined;
|
|
402
|
+
readonly app: undefined;
|
|
378
403
|
queryAdapter(options: QueryAdapterOptions): ReturnType<typeof createQueryAdapter>;
|
|
379
|
-
withClient<T extends ProcedureSource>(apiClient: T):
|
|
404
|
+
withClient<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
405
|
+
withApp<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
380
406
|
};
|
|
381
|
-
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient, TApiClient extends ProcedureSource
|
|
382
|
-
apiClient
|
|
383
|
-
}):
|
|
407
|
+
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient, TApiClient extends ProcedureSource = ProcedureSource>(options: SupaCloudClientOptions<TClient> & {
|
|
408
|
+
apiClient: TApiClient;
|
|
409
|
+
}): SupaCloudClientWithApplication<TClient, TApiClient>;
|
|
410
|
+
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudClientOptions<TClient> & {
|
|
411
|
+
apiClient?: undefined;
|
|
412
|
+
}): SupaCloudClientUnbound<TClient>;
|
package/dist/index.d.mts
CHANGED
|
@@ -7,8 +7,8 @@ import { type FetchTransport } from "./bounded-rpc-fetch.mjs";
|
|
|
7
7
|
import { SupaCloudOAuthClientsClient } from "./oauth-clients.mjs";
|
|
8
8
|
import { SupaCloudOAuthServerClient } from "./oauth-server.mjs";
|
|
9
9
|
import { type RealtimeChannelConfig, type RealtimeTransport, type SupaCloudRealtimeChannel, type SupaCloudRealtimeAdapter } from "./realtime.mjs";
|
|
10
|
-
import { createQueryAdapter, type ProcedureSource, type ProceduresOf, type QueryAdapterOptions } from "@supacloud/query";
|
|
11
|
-
export { createProcedureClient, createQueryAdapter, createQueryKey, invalidateByTags, type QueryAdapter, type QueryAdapterOptions, } from "@supacloud/query";
|
|
10
|
+
import { createQueryAdapter, type ProcedureSource, type ProceduresOf, type QueryAdapter, type QueryAdapterOptions } from "@supacloud/query";
|
|
11
|
+
export { createProcedureClient, createQueryAdapter, createQueryKey, invalidateByTags, type ProcedureSource, type ProceduresOf, type QueryAdapter, type QueryAdapterOptions, } from "@supacloud/query";
|
|
12
12
|
import { type SupaCloudQueueJson, type SupaCloudQueueMessage, type SupaCloudQueueSendResult, type SupaCloudQueueIdempotentSendResult, type SupaCloudQueueMutationResult } from "./queue-rpc.mjs";
|
|
13
13
|
export { SupaCloudApiError } from "./api-error.mjs";
|
|
14
14
|
export { SupaCloudQueueError, type SupaCloudQueueJson, type SupaCloudQueueMessage, type SupaCloudQueueSendResult, type SupaCloudQueueIdempotentSendResult, type SupaCloudQueueMutationResult, } from "./queue-rpc.mjs";
|
|
@@ -205,6 +205,7 @@ export type SupaCloudTaskSubscribeOptions<TResult = unknown> = {
|
|
|
205
205
|
};
|
|
206
206
|
pollingIntervalMs?: number;
|
|
207
207
|
realtimeTimeoutMs?: number;
|
|
208
|
+
realtimeRecoveryIntervalMs?: number;
|
|
208
209
|
reconcileIntervalMs?: number;
|
|
209
210
|
onUpdate: (task: SupaCloudTaskSnapshot<TResult>) => void;
|
|
210
211
|
onStateChange?: (state: SupaCloudTaskSubscribeState, details?: {
|
|
@@ -230,6 +231,21 @@ export type SupaCloudClientOptions<TClient extends SupabaseClient = SupabaseClie
|
|
|
230
231
|
pollingIntervalMs?: number;
|
|
231
232
|
realtimeTransport?: RealtimeTransport | null;
|
|
232
233
|
};
|
|
234
|
+
/**
|
|
235
|
+
* Compatibility-lane access remains owned by the caller's Supabase client.
|
|
236
|
+
* This facade never creates a second session store or protocol client.
|
|
237
|
+
*/
|
|
238
|
+
export type SupaCloudCompatibilitySurface<TClient extends SupabaseClient = SupabaseClient> = {
|
|
239
|
+
readonly supabase: TClient;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Application-lane access is compiler-generated and intentionally separate
|
|
243
|
+
* from compatibility CRUD so domain writes have an explicit API boundary.
|
|
244
|
+
*/
|
|
245
|
+
export type SupaCloudApplicationSurface<TApiClient extends ProcedureSource> = {
|
|
246
|
+
readonly procedures: ProceduresOf<TApiClient>;
|
|
247
|
+
readonly queryAdapter: (options: QueryAdapterOptions) => QueryAdapter<TApiClient>;
|
|
248
|
+
};
|
|
233
249
|
export declare class SupaCloudTaskSubmitError extends Error {
|
|
234
250
|
readonly code = "TASK_SUBMIT_UNCONFIRMED";
|
|
235
251
|
readonly mutationMayHaveApplied = true;
|
|
@@ -355,6 +371,7 @@ declare class SupaCloudQueuesClient<TClient extends SupabaseClient = SupabaseCli
|
|
|
355
371
|
}
|
|
356
372
|
type SupaCloudClientBase<TClient extends SupabaseClient> = {
|
|
357
373
|
readonly supabase: TClient;
|
|
374
|
+
readonly compat: SupaCloudCompatibilitySurface<TClient>;
|
|
358
375
|
readonly projectRef: string;
|
|
359
376
|
readonly managementApiUrl: string;
|
|
360
377
|
readonly auth: {
|
|
@@ -373,11 +390,23 @@ type SupaCloudClientBase<TClient extends SupabaseClient> = {
|
|
|
373
390
|
invokeBackground(functionName: string, submitOptions?: SupaCloudTaskSubmitOptions): Promise<SupaCloudTaskReceipt<unknown>>;
|
|
374
391
|
};
|
|
375
392
|
};
|
|
376
|
-
type
|
|
377
|
-
readonly procedures:
|
|
393
|
+
type SupaCloudClientWithApplication<TClient extends SupabaseClient, TApiClient extends ProcedureSource> = SupaCloudClientBase<TClient> & {
|
|
394
|
+
readonly procedures: ProceduresOf<TApiClient>;
|
|
395
|
+
readonly app: SupaCloudApplicationSurface<TApiClient>;
|
|
396
|
+
queryAdapter(options: QueryAdapterOptions): QueryAdapter<TApiClient>;
|
|
397
|
+
withClient<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
398
|
+
withApp<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
399
|
+
};
|
|
400
|
+
type SupaCloudClientUnbound<TClient extends SupabaseClient> = SupaCloudClientBase<TClient> & {
|
|
401
|
+
readonly procedures: undefined;
|
|
402
|
+
readonly app: undefined;
|
|
378
403
|
queryAdapter(options: QueryAdapterOptions): ReturnType<typeof createQueryAdapter>;
|
|
379
|
-
withClient<T extends ProcedureSource>(apiClient: T):
|
|
404
|
+
withClient<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
405
|
+
withApp<T extends ProcedureSource>(apiClient: T): SupaCloudClientWithApplication<TClient, T>;
|
|
380
406
|
};
|
|
381
|
-
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient, TApiClient extends ProcedureSource
|
|
382
|
-
apiClient
|
|
383
|
-
}):
|
|
407
|
+
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient, TApiClient extends ProcedureSource = ProcedureSource>(options: SupaCloudClientOptions<TClient> & {
|
|
408
|
+
apiClient: TApiClient;
|
|
409
|
+
}): SupaCloudClientWithApplication<TClient, TApiClient>;
|
|
410
|
+
export declare function createSupaCloudClient<TClient extends SupabaseClient = SupabaseClient>(options: SupaCloudClientOptions<TClient> & {
|
|
411
|
+
apiClient?: undefined;
|
|
412
|
+
}): SupaCloudClientUnbound<TClient>;
|
package/dist/index.mjs
CHANGED
|
@@ -4049,6 +4049,7 @@ function captureTaskSubscribeOptions(options) {
|
|
|
4049
4049
|
"realtime",
|
|
4050
4050
|
"pollingIntervalMs",
|
|
4051
4051
|
"realtimeTimeoutMs",
|
|
4052
|
+
"realtimeRecoveryIntervalMs",
|
|
4052
4053
|
"reconcileIntervalMs",
|
|
4053
4054
|
"onUpdate",
|
|
4054
4055
|
"onStateChange",
|
|
@@ -4391,10 +4392,12 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4391
4392
|
let channel = null;
|
|
4392
4393
|
let pollTimer = null;
|
|
4393
4394
|
let realtimeTimeoutTimer = null;
|
|
4395
|
+
let realtimeRecoveryTimer = null;
|
|
4394
4396
|
let reconcileTimer = null;
|
|
4395
4397
|
let mode = "connecting";
|
|
4396
4398
|
const pollingIntervalMs = taskTimerMs(options.pollingIntervalMs === undefined ? this.options.pollingIntervalMs : options.pollingIntervalMs);
|
|
4397
4399
|
const realtimeTimeoutMs = taskTimerMs(options.realtimeTimeoutMs === undefined ? 1e4 : options.realtimeTimeoutMs, true);
|
|
4400
|
+
const realtimeRecoveryIntervalMs = taskTimerMs(options.realtimeRecoveryIntervalMs === undefined ? Math.min(MAX_TASK_TIMER_MS, Math.max(30000, pollingIntervalMs * 10)) : options.realtimeRecoveryIntervalMs, true);
|
|
4398
4401
|
const reconcileIntervalMs = taskTimerMs(options.reconcileIntervalMs === undefined ? Math.min(MAX_TASK_TIMER_MS, Math.max(30000, pollingIntervalMs * 10)) : options.reconcileIntervalMs, true);
|
|
4399
4402
|
const stopOnTerminal = options.stopOnTerminal ?? true;
|
|
4400
4403
|
const readController = new AbortController;
|
|
@@ -4438,6 +4441,12 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4438
4441
|
realtimeTimeoutTimer = null;
|
|
4439
4442
|
}
|
|
4440
4443
|
};
|
|
4444
|
+
const stopRealtimeRecovery = () => {
|
|
4445
|
+
if (realtimeRecoveryTimer) {
|
|
4446
|
+
clearTimeout(realtimeRecoveryTimer);
|
|
4447
|
+
realtimeRecoveryTimer = null;
|
|
4448
|
+
}
|
|
4449
|
+
};
|
|
4441
4450
|
const stopReconcile = () => {
|
|
4442
4451
|
if (reconcileTimer) {
|
|
4443
4452
|
clearTimeout(reconcileTimer);
|
|
@@ -4462,6 +4471,7 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4462
4471
|
readController.abort();
|
|
4463
4472
|
stopPolling();
|
|
4464
4473
|
stopRealtimeTimeout();
|
|
4474
|
+
stopRealtimeRecovery();
|
|
4465
4475
|
stopReconcile();
|
|
4466
4476
|
try {
|
|
4467
4477
|
await teardownRealtime();
|
|
@@ -4525,14 +4535,80 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4525
4535
|
reconcileOnce();
|
|
4526
4536
|
}, reconcileIntervalMs);
|
|
4527
4537
|
};
|
|
4538
|
+
const scheduleRealtimeRecovery = () => {
|
|
4539
|
+
if (closed || !realtime2 || mode !== "polling" || realtimeRecoveryIntervalMs <= 0)
|
|
4540
|
+
return;
|
|
4541
|
+
stopRealtimeRecovery();
|
|
4542
|
+
realtimeRecoveryTimer = setTimeout(() => {
|
|
4543
|
+
realtimeRecoveryTimer = null;
|
|
4544
|
+
startRealtime();
|
|
4545
|
+
}, realtimeRecoveryIntervalMs);
|
|
4546
|
+
};
|
|
4528
4547
|
const startPolling = (error) => {
|
|
4529
4548
|
if (closed)
|
|
4530
4549
|
return;
|
|
4531
4550
|
stopPolling();
|
|
4532
4551
|
stopRealtimeTimeout();
|
|
4533
4552
|
stopReconcile();
|
|
4553
|
+
stopRealtimeRecovery();
|
|
4534
4554
|
setMode("polling", { error });
|
|
4535
4555
|
pollOnce();
|
|
4556
|
+
scheduleRealtimeRecovery();
|
|
4557
|
+
};
|
|
4558
|
+
const startRealtime = () => {
|
|
4559
|
+
if (closed || !realtime2 || channel)
|
|
4560
|
+
return;
|
|
4561
|
+
stopRealtimeRecovery();
|
|
4562
|
+
channel = this.options.supabase.channel(`supacloud-task:${this.options.projectRef}:${taskId}`).on("postgres_changes", {
|
|
4563
|
+
event: "*",
|
|
4564
|
+
schema: realtime2.schema,
|
|
4565
|
+
table: realtime2.table,
|
|
4566
|
+
filter: `id=eq.${taskId}`
|
|
4567
|
+
}, (payload) => {
|
|
4568
|
+
const next = payload.new && Object.keys(payload.new).length > 0 ? payload.new : payload.old;
|
|
4569
|
+
if (next)
|
|
4570
|
+
emitTask(next);
|
|
4571
|
+
});
|
|
4572
|
+
channel.subscribe(async (status, error) => {
|
|
4573
|
+
if (closed)
|
|
4574
|
+
return;
|
|
4575
|
+
if (status === "SUBSCRIBED") {
|
|
4576
|
+
stopPolling();
|
|
4577
|
+
stopRealtimeTimeout();
|
|
4578
|
+
setMode("realtime");
|
|
4579
|
+
if (closed)
|
|
4580
|
+
return;
|
|
4581
|
+
try {
|
|
4582
|
+
emitTask(await readTask(readController.signal));
|
|
4583
|
+
} catch (err) {
|
|
4584
|
+
if (!closed)
|
|
4585
|
+
reportError(err);
|
|
4586
|
+
}
|
|
4587
|
+
startReconcile();
|
|
4588
|
+
return;
|
|
4589
|
+
}
|
|
4590
|
+
if (status === "TIMED_OUT" || status === "CHANNEL_ERROR" || status === "CLOSED") {
|
|
4591
|
+
await teardownRealtime();
|
|
4592
|
+
if (mode === "polling") {
|
|
4593
|
+
scheduleRealtimeRecovery();
|
|
4594
|
+
} else {
|
|
4595
|
+
startPolling(error);
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
});
|
|
4599
|
+
if (!closed && channel && mode !== "realtime" && realtimeTimeoutMs > 0) {
|
|
4600
|
+
realtimeTimeoutTimer = setTimeout(() => {
|
|
4601
|
+
if (!closed && channel) {
|
|
4602
|
+
teardownRealtime().finally(() => {
|
|
4603
|
+
if (mode === "polling") {
|
|
4604
|
+
scheduleRealtimeRecovery();
|
|
4605
|
+
} else {
|
|
4606
|
+
startPolling(new Error("SupaCloud Realtime subscription timed out"));
|
|
4607
|
+
}
|
|
4608
|
+
});
|
|
4609
|
+
}
|
|
4610
|
+
}, realtimeTimeoutMs);
|
|
4611
|
+
}
|
|
4536
4612
|
};
|
|
4537
4613
|
const subscription = {
|
|
4538
4614
|
get connectionState() {
|
|
@@ -4546,49 +4622,8 @@ class SupaCloudTasksClient extends SupaCloudManagementClient {
|
|
|
4546
4622
|
startPolling();
|
|
4547
4623
|
return subscription;
|
|
4548
4624
|
}
|
|
4549
|
-
channel = this.options.supabase.channel(`supacloud-task:${this.options.projectRef}:${taskId}`).on("postgres_changes", {
|
|
4550
|
-
event: "*",
|
|
4551
|
-
schema: realtime2.schema,
|
|
4552
|
-
table: realtime2.table,
|
|
4553
|
-
filter: `id=eq.${taskId}`
|
|
4554
|
-
}, (payload) => {
|
|
4555
|
-
const next = payload.new && Object.keys(payload.new).length > 0 ? payload.new : payload.old;
|
|
4556
|
-
if (next)
|
|
4557
|
-
emitTask(next);
|
|
4558
|
-
});
|
|
4559
|
-
channel.subscribe(async (status, error) => {
|
|
4560
|
-
if (closed)
|
|
4561
|
-
return;
|
|
4562
|
-
if (status === "SUBSCRIBED") {
|
|
4563
|
-
stopPolling();
|
|
4564
|
-
stopRealtimeTimeout();
|
|
4565
|
-
setMode("realtime");
|
|
4566
|
-
if (closed)
|
|
4567
|
-
return;
|
|
4568
|
-
try {
|
|
4569
|
-
emitTask(await readTask(readController.signal));
|
|
4570
|
-
} catch (err) {
|
|
4571
|
-
if (!closed)
|
|
4572
|
-
reportError(err);
|
|
4573
|
-
}
|
|
4574
|
-
startReconcile();
|
|
4575
|
-
return;
|
|
4576
|
-
}
|
|
4577
|
-
if (status === "TIMED_OUT" || status === "CHANNEL_ERROR" || status === "CLOSED") {
|
|
4578
|
-
await teardownRealtime();
|
|
4579
|
-
startPolling(error);
|
|
4580
|
-
}
|
|
4581
|
-
});
|
|
4582
|
-
if (!closed && realtimeTimeoutMs > 0) {
|
|
4583
|
-
realtimeTimeoutTimer = setTimeout(() => {
|
|
4584
|
-
if (!closed && mode === "connecting") {
|
|
4585
|
-
teardownRealtime().finally(() => {
|
|
4586
|
-
startPolling(new Error("SupaCloud Realtime subscription timed out"));
|
|
4587
|
-
});
|
|
4588
|
-
}
|
|
4589
|
-
}, realtimeTimeoutMs);
|
|
4590
|
-
}
|
|
4591
4625
|
setMode("connecting");
|
|
4626
|
+
startRealtime();
|
|
4592
4627
|
return subscription;
|
|
4593
4628
|
}
|
|
4594
4629
|
}
|
|
@@ -4785,6 +4820,12 @@ function openSupabaseChannel(supabase, topic, config) {
|
|
|
4785
4820
|
}
|
|
4786
4821
|
});
|
|
4787
4822
|
}
|
|
4823
|
+
function createApplicationSurface(apiClient) {
|
|
4824
|
+
return {
|
|
4825
|
+
procedures: createProcedureClient(apiClient),
|
|
4826
|
+
queryAdapter: (options) => createQueryAdapter(apiClient, options)
|
|
4827
|
+
};
|
|
4828
|
+
}
|
|
4788
4829
|
function createSupaCloudClient(options) {
|
|
4789
4830
|
const normalized = {
|
|
4790
4831
|
...options,
|
|
@@ -4806,6 +4847,7 @@ function createSupaCloudClient(options) {
|
|
|
4806
4847
|
});
|
|
4807
4848
|
const instance = {
|
|
4808
4849
|
supabase: options.supabase,
|
|
4850
|
+
compat: { supabase: options.supabase },
|
|
4809
4851
|
projectRef: normalized.projectRef,
|
|
4810
4852
|
managementApiUrl: normalized.managementApiUrl,
|
|
4811
4853
|
auth: {
|
|
@@ -4825,22 +4867,28 @@ function createSupaCloudClient(options) {
|
|
|
4825
4867
|
}
|
|
4826
4868
|
};
|
|
4827
4869
|
const withClient = (apiClient) => {
|
|
4870
|
+
const app = createApplicationSurface(apiClient);
|
|
4828
4871
|
return {
|
|
4829
4872
|
...instance,
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4873
|
+
app,
|
|
4874
|
+
procedures: app.procedures,
|
|
4875
|
+
queryAdapter: app.queryAdapter,
|
|
4876
|
+
withClient,
|
|
4877
|
+
withApp: withClient
|
|
4833
4878
|
};
|
|
4834
4879
|
};
|
|
4880
|
+
const app = options.apiClient === undefined ? undefined : createApplicationSurface(options.apiClient);
|
|
4835
4881
|
return {
|
|
4836
4882
|
...instance,
|
|
4837
|
-
|
|
4883
|
+
app,
|
|
4884
|
+
procedures: app === undefined ? undefined : app.procedures,
|
|
4838
4885
|
queryAdapter: (adapterOptions) => {
|
|
4839
|
-
if (
|
|
4886
|
+
if (app === undefined)
|
|
4840
4887
|
throw new Error("No procedure client attached");
|
|
4841
|
-
return
|
|
4888
|
+
return app.queryAdapter(adapterOptions);
|
|
4842
4889
|
},
|
|
4843
|
-
withClient
|
|
4890
|
+
withClient,
|
|
4891
|
+
withApp: withClient
|
|
4844
4892
|
};
|
|
4845
4893
|
}
|
|
4846
4894
|
export {
|