@supacloud/js 0.47.0 → 0.47.1
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 +77 -42
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +77 -42
- 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
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -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?: {
|
package/dist/index.d.mts
CHANGED
|
@@ -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?: {
|
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
|
}
|