@supacloud/js 0.34.1 → 0.36.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/COMPATIBILITY.md +84 -0
- package/LICENSE +202 -661
- package/NOTICE +8 -13
- package/REACTIVE.md +93 -0
- package/README.md +6 -0
- package/dist/api-error.d.mts +6 -0
- package/dist/{artifact-fetch.d.ts → artifact-fetch.d.cts} +1 -1
- package/dist/artifact-fetch.d.mts +6 -0
- package/dist/{artifact-link.d.ts → artifact-link.d.cts} +2 -2
- package/dist/artifact-link.d.mts +8 -0
- package/dist/{artifact-read.d.ts → artifact-read.d.cts} +2 -2
- package/dist/artifact-read.d.mts +13 -0
- package/dist/{artifact-register.d.ts → artifact-register.d.cts} +2 -2
- package/dist/artifact-register.d.mts +14 -0
- package/dist/{artifact-rpc.d.ts → artifact-rpc.d.cts} +1 -1
- package/dist/artifact-rpc.d.mts +2 -0
- package/dist/{artifacts.d.ts → artifacts.d.cts} +4 -4
- package/dist/artifacts.d.mts +53 -0
- package/dist/auth-fetch.d.mts +27 -0
- package/dist/bounded-rpc-fetch.d.mts +2 -0
- package/dist/{command-fetch.d.ts → command-fetch.d.cts} +1 -1
- package/dist/command-fetch.d.mts +6 -0
- package/dist/{commands.d.ts → commands.d.cts} +1 -1
- package/dist/commands.d.mts +44 -0
- package/dist/contracts.cjs +48 -0
- package/dist/contracts.d.mts +1 -0
- package/dist/index.cjs +3732 -0
- package/dist/{index.d.ts → index.d.cts} +20 -20
- package/dist/index.d.mts +360 -0
- package/dist/{oauth-clients.d.ts → oauth-clients.d.cts} +1 -1
- package/dist/oauth-clients.d.mts +95 -0
- package/dist/{oauth-server.d.ts → oauth-server.d.cts} +1 -1
- package/dist/oauth-server.d.mts +104 -0
- package/dist/{queue-rpc.d.ts → queue-rpc.d.cts} +1 -1
- package/dist/queue-rpc.d.mts +54 -0
- package/dist/reactive.cjs +119 -0
- package/dist/reactive.d.cts +26 -0
- package/dist/reactive.d.mts +26 -0
- package/dist/reactive.mjs +79 -0
- package/dist/{service-role-rpc.d.ts → service-role-rpc.d.cts} +1 -1
- package/dist/service-role-rpc.d.mts +2 -0
- package/dist/supabase-types.d.cts +9 -0
- package/dist/supabase-types.d.mts +9 -0
- package/dist/task-events.cjs +352 -0
- package/dist/task-events.d.mts +66 -0
- package/dist/{workflow-advance.d.ts → workflow-advance.d.cts} +2 -2
- package/dist/workflow-advance.d.mts +8 -0
- package/dist/{workflow-attempt.d.ts → workflow-attempt.d.cts} +1 -1
- package/dist/workflow-attempt.d.mts +4 -0
- package/dist/{workflow-cancel.d.ts → workflow-cancel.d.cts} +2 -2
- package/dist/workflow-cancel.d.mts +14 -0
- package/dist/{workflow-claim.d.ts → workflow-claim.d.cts} +2 -2
- package/dist/workflow-claim.d.mts +12 -0
- package/dist/{workflow-complete.d.ts → workflow-complete.d.cts} +2 -2
- package/dist/workflow-complete.d.mts +8 -0
- package/dist/{workflow-events.d.ts → workflow-events.d.cts} +2 -2
- package/dist/workflow-events.d.mts +14 -0
- package/dist/{workflow-fail.d.ts → workflow-fail.d.cts} +2 -2
- package/dist/workflow-fail.d.mts +8 -0
- package/dist/{workflow-fetch.d.ts → workflow-fetch.d.cts} +1 -1
- package/dist/workflow-fetch.d.mts +9 -0
- package/dist/workflow-json.d.mts +2 -0
- package/dist/{workflow-retry.d.ts → workflow-retry.d.cts} +2 -2
- package/dist/workflow-retry.d.mts +8 -0
- package/dist/{workflow-rpc.d.ts → workflow-rpc.d.cts} +1 -1
- package/dist/workflow-rpc.d.mts +6 -0
- package/dist/{workflow-run.d.ts → workflow-run.d.cts} +2 -2
- package/dist/workflow-run.d.mts +8 -0
- package/dist/{workflow-start.d.ts → workflow-start.d.cts} +2 -2
- package/dist/workflow-start.d.mts +8 -0
- package/dist/workflow-timestamp.d.mts +1 -0
- package/dist/{workflows.d.ts → workflows.d.cts} +10 -10
- package/dist/workflows.d.mts +141 -0
- package/package.json +54 -20
- /package/dist/{api-error.d.ts → api-error.d.cts} +0 -0
- /package/dist/{auth-fetch.d.ts → auth-fetch.d.cts} +0 -0
- /package/dist/{bounded-rpc-fetch.d.ts → bounded-rpc-fetch.d.cts} +0 -0
- /package/dist/{contracts.d.ts → contracts.d.cts} +0 -0
- /package/dist/{contracts.js → contracts.mjs} +0 -0
- /package/dist/{index.js → index.mjs} +0 -0
- /package/dist/{task-events.d.ts → task-events.d.cts} +0 -0
- /package/dist/{task-events.js → task-events.mjs} +0 -0
- /package/dist/{workflow-json.d.ts → workflow-json.d.cts} +0 -0
- /package/dist/{workflow-timestamp.d.ts → workflow-timestamp.d.cts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SupaCloudApiError } from "./api-error.mjs";
|
|
2
|
+
export type SupaCloudQueueJson = null | boolean | number | string | SupaCloudQueueJson[] | {
|
|
3
|
+
[key: string]: SupaCloudQueueJson;
|
|
4
|
+
};
|
|
5
|
+
export type SupaCloudQueueMessage = {
|
|
6
|
+
id: string;
|
|
7
|
+
msg_id: string;
|
|
8
|
+
read_ct?: number;
|
|
9
|
+
enqueued_at?: string | null;
|
|
10
|
+
vt?: string | null;
|
|
11
|
+
message: SupaCloudQueueJson;
|
|
12
|
+
payload: SupaCloudQueueJson;
|
|
13
|
+
status?: string;
|
|
14
|
+
queue_name?: string;
|
|
15
|
+
task_type?: string;
|
|
16
|
+
};
|
|
17
|
+
export type SupaCloudQueueSendResult = {
|
|
18
|
+
id: string;
|
|
19
|
+
msg_id: string;
|
|
20
|
+
queue_name: string;
|
|
21
|
+
status: "pending";
|
|
22
|
+
payload: SupaCloudQueueJson;
|
|
23
|
+
};
|
|
24
|
+
export type SupaCloudQueueMutationResult = {
|
|
25
|
+
id: string;
|
|
26
|
+
msg_id: string;
|
|
27
|
+
queue_name: string;
|
|
28
|
+
status: "archived" | "deleted" | "released";
|
|
29
|
+
success: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare class SupaCloudQueueError extends SupaCloudApiError {
|
|
32
|
+
readonly mutationMayHaveApplied: boolean;
|
|
33
|
+
constructor(mutationMayHaveApplied?: boolean, code?: string);
|
|
34
|
+
}
|
|
35
|
+
export declare function queueMessageId(value: unknown): string;
|
|
36
|
+
export declare function queueInteger(value: unknown, min: number, max?: number): number;
|
|
37
|
+
export declare function queueSeconds(options: {
|
|
38
|
+
sleepSeconds?: number;
|
|
39
|
+
sleep_seconds?: number;
|
|
40
|
+
delayMs?: number;
|
|
41
|
+
visibilityTimeoutSec?: number;
|
|
42
|
+
}): number;
|
|
43
|
+
export declare function queueReadCount(options: unknown, single?: boolean): number;
|
|
44
|
+
export declare function queueJsonSnapshot(value: unknown): SupaCloudQueueJson;
|
|
45
|
+
export declare function queueRpcIds(value: unknown, expected: number): string[];
|
|
46
|
+
export declare function queueRpcId(value: unknown): string;
|
|
47
|
+
export declare function queueRpcBoolean(value: unknown): boolean;
|
|
48
|
+
export declare function queueMessage(value: unknown, expected?: {
|
|
49
|
+
queueName?: string;
|
|
50
|
+
messageId?: string;
|
|
51
|
+
status?: string;
|
|
52
|
+
rpc?: boolean;
|
|
53
|
+
}): SupaCloudQueueMessage;
|
|
54
|
+
export declare function queueRpcMessages(queueName: string, value: unknown, max: number, status: string): SupaCloudQueueMessage[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/reactive.ts
|
|
40
|
+
var exports_reactive = {};
|
|
41
|
+
__export(exports_reactive, {
|
|
42
|
+
observeQuery: () => observeQuery,
|
|
43
|
+
observeTask: () => observeTask
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_reactive);
|
|
46
|
+
var import_rxjs = require("rxjs");
|
|
47
|
+
function observeQuery(query, options = {}) {
|
|
48
|
+
const signal = options.signal;
|
|
49
|
+
return new import_rxjs.Observable((subscriber) => {
|
|
50
|
+
if (signal?.aborted) {
|
|
51
|
+
subscriber.complete();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const controller = new AbortController;
|
|
55
|
+
let pending = true;
|
|
56
|
+
const abort = () => subscriber.complete();
|
|
57
|
+
subscriber.add(() => {
|
|
58
|
+
signal?.removeEventListener("abort", abort);
|
|
59
|
+
if (pending)
|
|
60
|
+
controller.abort(signal?.reason);
|
|
61
|
+
});
|
|
62
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
63
|
+
if (signal?.aborted) {
|
|
64
|
+
abort();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let work;
|
|
68
|
+
try {
|
|
69
|
+
work = query(controller.signal);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
subscriber.error(error);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
Promise.resolve(work).then((response) => {
|
|
75
|
+
pending = false;
|
|
76
|
+
if (subscriber.closed)
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
if (response.error !== null && response.error !== undefined) {
|
|
80
|
+
subscriber.error(response.error);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
subscriber.next(response);
|
|
84
|
+
subscriber.complete();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
subscriber.error(error);
|
|
87
|
+
}
|
|
88
|
+
}, (error) => {
|
|
89
|
+
pending = false;
|
|
90
|
+
subscriber.error(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function observeTask(task, options = {}) {
|
|
95
|
+
const { signal, ...settings } = options;
|
|
96
|
+
const captured = {
|
|
97
|
+
...settings,
|
|
98
|
+
...settings.realtime ? { realtime: { ...settings.realtime } } : {}
|
|
99
|
+
};
|
|
100
|
+
return new import_rxjs.Observable((subscriber) => {
|
|
101
|
+
const abort = () => subscriber.complete();
|
|
102
|
+
subscriber.add(() => signal?.removeEventListener("abort", abort));
|
|
103
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
104
|
+
if (signal?.aborted) {
|
|
105
|
+
subscriber.complete();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const subscription = task.subscribe({
|
|
109
|
+
...captured,
|
|
110
|
+
onUpdate: (snapshot) => subscriber.next(snapshot),
|
|
111
|
+
onError: (error) => subscriber.error(error),
|
|
112
|
+
onStateChange: (state) => {
|
|
113
|
+
if (state === "closed")
|
|
114
|
+
subscriber.complete();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
subscriber.add(() => subscription.unsubscribe());
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Official RxJS adapters. No runtime import of the SDK root or a second Supabase client. */
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import type { SupaCloudTaskReceipt, SupaCloudTaskSnapshot, SupaCloudTaskSubscribeOptions } from "./index.cjs";
|
|
4
|
+
export interface ObserveQueryOptions {
|
|
5
|
+
/** Owner cancellation completes observation and aborts cooperative I/O. */
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a fresh read/query per subscription, including Supabase PromiseLike builders.
|
|
10
|
+
* Keeps the original response envelope (data/count/status); error envelopes enter error().
|
|
11
|
+
* Pass the provided signal to .abortSignal(signal) or the native SDK request options.
|
|
12
|
+
* No retries, global cache or sharing. Keep commands/submission on their awaited SDK APIs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function observeQuery<TResponse extends {
|
|
15
|
+
error: unknown;
|
|
16
|
+
}>(query: (signal: AbortSignal) => PromiseLike<TResponse>, options?: ObserveQueryOptions): Observable<TResponse>;
|
|
17
|
+
export type ObserveTaskOptions = Omit<SupaCloudTaskSubscribeOptions, "onUpdate" | "onError" | "onStateChange"> & {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Observe an EXISTING task receipt, preserving its project binding and result decoder.
|
|
22
|
+
* Each subscriber owns its SDK subscription; unsubscribe never calls task.cancel/retry.
|
|
23
|
+
* SDK read/decoder failures terminate the stream. SDK Realtime->polling fallback is retained.
|
|
24
|
+
* Terminal business states are emitted normally, then the SDK's closed state completes it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function observeTask<TResult>(task: Pick<SupaCloudTaskReceipt<TResult>, "subscribe">, options?: ObserveTaskOptions): Observable<SupaCloudTaskSnapshot<TResult>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Official RxJS adapters. No runtime import of the SDK root or a second Supabase client. */
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import type { SupaCloudTaskReceipt, SupaCloudTaskSnapshot, SupaCloudTaskSubscribeOptions } from "./index.mjs";
|
|
4
|
+
export interface ObserveQueryOptions {
|
|
5
|
+
/** Owner cancellation completes observation and aborts cooperative I/O. */
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a fresh read/query per subscription, including Supabase PromiseLike builders.
|
|
10
|
+
* Keeps the original response envelope (data/count/status); error envelopes enter error().
|
|
11
|
+
* Pass the provided signal to .abortSignal(signal) or the native SDK request options.
|
|
12
|
+
* No retries, global cache or sharing. Keep commands/submission on their awaited SDK APIs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function observeQuery<TResponse extends {
|
|
15
|
+
error: unknown;
|
|
16
|
+
}>(query: (signal: AbortSignal) => PromiseLike<TResponse>, options?: ObserveQueryOptions): Observable<TResponse>;
|
|
17
|
+
export type ObserveTaskOptions = Omit<SupaCloudTaskSubscribeOptions, "onUpdate" | "onError" | "onStateChange"> & {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Observe an EXISTING task receipt, preserving its project binding and result decoder.
|
|
22
|
+
* Each subscriber owns its SDK subscription; unsubscribe never calls task.cancel/retry.
|
|
23
|
+
* SDK read/decoder failures terminate the stream. SDK Realtime->polling fallback is retained.
|
|
24
|
+
* Terminal business states are emitted normally, then the SDK's closed state completes it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function observeTask<TResult>(task: Pick<SupaCloudTaskReceipt<TResult>, "subscribe">, options?: ObserveTaskOptions): Observable<SupaCloudTaskSnapshot<TResult>>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/reactive.ts
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
function observeQuery(query, options = {}) {
|
|
4
|
+
const signal = options.signal;
|
|
5
|
+
return new Observable((subscriber) => {
|
|
6
|
+
if (signal?.aborted) {
|
|
7
|
+
subscriber.complete();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const controller = new AbortController;
|
|
11
|
+
let pending = true;
|
|
12
|
+
const abort = () => subscriber.complete();
|
|
13
|
+
subscriber.add(() => {
|
|
14
|
+
signal?.removeEventListener("abort", abort);
|
|
15
|
+
if (pending)
|
|
16
|
+
controller.abort(signal?.reason);
|
|
17
|
+
});
|
|
18
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
19
|
+
if (signal?.aborted) {
|
|
20
|
+
abort();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let work;
|
|
24
|
+
try {
|
|
25
|
+
work = query(controller.signal);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
subscriber.error(error);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
Promise.resolve(work).then((response) => {
|
|
31
|
+
pending = false;
|
|
32
|
+
if (subscriber.closed)
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
if (response.error !== null && response.error !== undefined) {
|
|
36
|
+
subscriber.error(response.error);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
subscriber.next(response);
|
|
40
|
+
subscriber.complete();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
subscriber.error(error);
|
|
43
|
+
}
|
|
44
|
+
}, (error) => {
|
|
45
|
+
pending = false;
|
|
46
|
+
subscriber.error(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function observeTask(task, options = {}) {
|
|
51
|
+
const { signal, ...settings } = options;
|
|
52
|
+
const captured = {
|
|
53
|
+
...settings,
|
|
54
|
+
...settings.realtime ? { realtime: { ...settings.realtime } } : {}
|
|
55
|
+
};
|
|
56
|
+
return new Observable((subscriber) => {
|
|
57
|
+
const abort = () => subscriber.complete();
|
|
58
|
+
subscriber.add(() => signal?.removeEventListener("abort", abort));
|
|
59
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
60
|
+
if (signal?.aborted) {
|
|
61
|
+
subscriber.complete();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const subscription = task.subscribe({
|
|
65
|
+
...captured,
|
|
66
|
+
onUpdate: (snapshot) => subscriber.next(snapshot),
|
|
67
|
+
onError: (error) => subscriber.error(error),
|
|
68
|
+
onStateChange: (state) => {
|
|
69
|
+
if (state === "closed")
|
|
70
|
+
subscriber.complete();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
subscriber.add(() => subscription.unsubscribe());
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
observeQuery,
|
|
78
|
+
observeTask
|
|
79
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SupabaseClient } from "
|
|
1
|
+
import type { SupabaseClient } from "./supabase-types.cjs";
|
|
2
2
|
export declare function invokeServiceRoleRpc<T>(supabase: SupabaseClient, functionName: string, request: object): Promise<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase ships separate ESM and CommonJS class declarations. Their protected
|
|
3
|
+
* members are nominally distinct even when the runtime APIs are identical.
|
|
4
|
+
* Preserve the caller's exact client type while accepting either declaration
|
|
5
|
+
* graph. Type-only imports add no CommonJS runtime or duplicated state.
|
|
6
|
+
*/
|
|
7
|
+
import type { SupabaseClient as EsmSupabaseClient } from "@supabase/supabase-js" with { "resolution-mode": "import" };
|
|
8
|
+
import type { SupabaseClient as CommonJsSupabaseClient } from "@supabase/supabase-js" with { "resolution-mode": "require" };
|
|
9
|
+
export type SupabaseClient = EsmSupabaseClient | CommonJsSupabaseClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supabase ships separate ESM and CommonJS class declarations. Their protected
|
|
3
|
+
* members are nominally distinct even when the runtime APIs are identical.
|
|
4
|
+
* Preserve the caller's exact client type while accepting either declaration
|
|
5
|
+
* graph. Type-only imports add no CommonJS runtime or duplicated state.
|
|
6
|
+
*/
|
|
7
|
+
import type { SupabaseClient as EsmSupabaseClient } from "@supabase/supabase-js" with { "resolution-mode": "import" };
|
|
8
|
+
import type { SupabaseClient as CommonJsSupabaseClient } from "@supabase/supabase-js" with { "resolution-mode": "require" };
|
|
9
|
+
export type SupabaseClient = EsmSupabaseClient | CommonJsSupabaseClient;
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/task-events.ts
|
|
40
|
+
var exports_task_events = {};
|
|
41
|
+
__export(exports_task_events, {
|
|
42
|
+
TaskEventError: () => TaskEventError,
|
|
43
|
+
createTaskEventClient: () => createTaskEventClient
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_task_events);
|
|
46
|
+
|
|
47
|
+
class TaskEventError extends Error {
|
|
48
|
+
status;
|
|
49
|
+
code;
|
|
50
|
+
details;
|
|
51
|
+
constructor(status, code, details = {}) {
|
|
52
|
+
super(code);
|
|
53
|
+
this.status = status;
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.details = details;
|
|
56
|
+
this.name = "TaskEventError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
60
|
+
var MAX_CURSOR = 9223372036854775807n;
|
|
61
|
+
var MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
62
|
+
var STATES = new Set(["pending", "leased", "running", "retry_scheduled", "succeeded", "failed", "dead_lettered", "cancelled"]);
|
|
63
|
+
var TERMINAL = new Set(["succeeded", "failed", "dead_lettered", "cancelled"]);
|
|
64
|
+
var OUTPUTS = new Set(["output.delta", "output.snapshot", "progress", "warning"]);
|
|
65
|
+
function invalid() {
|
|
66
|
+
throw new TaskEventError(0, "TASK_OUTPUT_INVALID_RESPONSE");
|
|
67
|
+
}
|
|
68
|
+
function record(value) {
|
|
69
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
70
|
+
}
|
|
71
|
+
function cursor(value) {
|
|
72
|
+
if (typeof value !== "string" || !/^(0|[1-9][0-9]{0,18})$/.test(value) || BigInt(value) > MAX_CURSOR) {
|
|
73
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_CURSOR");
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
function taskId(value) {
|
|
78
|
+
if (!UUID.test(value))
|
|
79
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_TASK");
|
|
80
|
+
return value.toLowerCase();
|
|
81
|
+
}
|
|
82
|
+
function integer(value, minimum, maximum) {
|
|
83
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= minimum && value <= maximum;
|
|
84
|
+
}
|
|
85
|
+
function event(value, ref, id) {
|
|
86
|
+
if (!record(value) || value.schema_version !== 1 || value.project_ref !== ref || value.task_id !== id || typeof value.event_id !== "string" || !UUID.test(value.event_id) || !integer(value.attempt, 0, 2147483647) || typeof value.type !== "string" || !(OUTPUTS.has(value.type) || value.type.startsWith("task.") && STATES.has(value.type.slice(5))) || !record(value.payload) || typeof value.created_at !== "string" || !Number.isFinite(Date.parse(value.created_at)))
|
|
87
|
+
invalid();
|
|
88
|
+
const sequence = cursor(value.sequence);
|
|
89
|
+
if (sequence === "0" || OUTPUTS.has(value.type) && value.attempt < 1)
|
|
90
|
+
invalid();
|
|
91
|
+
return {
|
|
92
|
+
schema_version: 1,
|
|
93
|
+
project_ref: ref,
|
|
94
|
+
task_id: id,
|
|
95
|
+
event_id: value.event_id,
|
|
96
|
+
sequence,
|
|
97
|
+
attempt: value.attempt,
|
|
98
|
+
type: value.type,
|
|
99
|
+
payload: value.payload,
|
|
100
|
+
created_at: value.created_at
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function page(value, ref, id, after, limit) {
|
|
104
|
+
if (!record(value) || value.schema_version !== 1 || value.project_ref !== ref || value.task_id !== id || typeof value.enabled !== "boolean" || typeof value.task_status !== "string" || !STATES.has(value.task_status) || !integer(value.attempt, 0, 2147483647) || !Array.isArray(value.events) || value.events.length > limit || typeof value.has_more !== "boolean" || value.replay_available !== true)
|
|
105
|
+
invalid();
|
|
106
|
+
const next = cursor(value.next_cursor), last = cursor(value.last_sequence), retained = cursor(value.retained_after);
|
|
107
|
+
if (BigInt(retained) > BigInt(after) || BigInt(after) > BigInt(last))
|
|
108
|
+
invalid();
|
|
109
|
+
let position = BigInt(after);
|
|
110
|
+
const events = value.events.map((raw) => {
|
|
111
|
+
const item = event(raw, ref, id);
|
|
112
|
+
if (BigInt(item.sequence) !== position + 1n)
|
|
113
|
+
invalid();
|
|
114
|
+
position = BigInt(item.sequence);
|
|
115
|
+
return item;
|
|
116
|
+
});
|
|
117
|
+
if (next !== position.toString() || position > BigInt(last) || value.has_more !== position < BigInt(last) || value.has_more && events.length !== limit || !value.enabled && last !== "0")
|
|
118
|
+
invalid();
|
|
119
|
+
return {
|
|
120
|
+
schema_version: 1,
|
|
121
|
+
project_ref: ref,
|
|
122
|
+
task_id: id,
|
|
123
|
+
enabled: value.enabled,
|
|
124
|
+
task_status: value.task_status,
|
|
125
|
+
attempt: value.attempt,
|
|
126
|
+
events,
|
|
127
|
+
next_cursor: next,
|
|
128
|
+
last_sequence: last,
|
|
129
|
+
retained_after: retained,
|
|
130
|
+
has_more: value.has_more,
|
|
131
|
+
replay_available: true
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function abortError(signal) {
|
|
135
|
+
return signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
136
|
+
}
|
|
137
|
+
function abortable(work, signal) {
|
|
138
|
+
if (signal.aborted) {
|
|
139
|
+
work.catch(() => {});
|
|
140
|
+
return Promise.reject(abortError(signal));
|
|
141
|
+
}
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
const abort = () => {
|
|
144
|
+
cleanup();
|
|
145
|
+
reject(abortError(signal));
|
|
146
|
+
};
|
|
147
|
+
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
148
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
149
|
+
work.then((value) => {
|
|
150
|
+
cleanup();
|
|
151
|
+
resolve(value);
|
|
152
|
+
}, (error) => {
|
|
153
|
+
cleanup();
|
|
154
|
+
reject(error);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async function jsonBody(response, signal) {
|
|
159
|
+
if (!response.body)
|
|
160
|
+
invalid();
|
|
161
|
+
const reader = response.body.getReader();
|
|
162
|
+
const chunks = [];
|
|
163
|
+
let length = 0;
|
|
164
|
+
try {
|
|
165
|
+
for (;; ) {
|
|
166
|
+
const { value, done } = await abortable(reader.read(), signal);
|
|
167
|
+
if (done)
|
|
168
|
+
break;
|
|
169
|
+
length += value.byteLength;
|
|
170
|
+
if (length > MAX_RESPONSE_BYTES || chunks.length >= 32768)
|
|
171
|
+
throw new TaskEventError(0, "TASK_OUTPUT_RESPONSE_TOO_LARGE");
|
|
172
|
+
chunks.push(value);
|
|
173
|
+
}
|
|
174
|
+
const bytes = new Uint8Array(length);
|
|
175
|
+
let offset = 0;
|
|
176
|
+
for (const chunk of chunks) {
|
|
177
|
+
bytes.set(chunk, offset);
|
|
178
|
+
offset += chunk.byteLength;
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
182
|
+
} catch {
|
|
183
|
+
invalid();
|
|
184
|
+
}
|
|
185
|
+
} finally {
|
|
186
|
+
reader.cancel().catch(() => {});
|
|
187
|
+
reader.releaseLock();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function createTaskEventClient(options) {
|
|
191
|
+
const base = new URL(options.baseUrl);
|
|
192
|
+
if (!["http:", "https:"].includes(base.protocol) || base.username || base.password || base.search || base.hash || !/^[a-zA-Z0-9_-]{1,20}$/.test(options.projectRef))
|
|
193
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_CLIENT");
|
|
194
|
+
const ref = options.projectRef;
|
|
195
|
+
const basePath = base.pathname.replace(/\/$/, "");
|
|
196
|
+
const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
197
|
+
async function request(id, query, input, signal) {
|
|
198
|
+
signal?.throwIfAborted();
|
|
199
|
+
const controller = new AbortController;
|
|
200
|
+
const stop = () => controller.abort(signal?.reason);
|
|
201
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
202
|
+
const timeout = setTimeout(() => controller.abort(new TaskEventError(408, "TASK_OUTPUT_REQUEST_TIMEOUT")), 30000);
|
|
203
|
+
try {
|
|
204
|
+
let headers;
|
|
205
|
+
try {
|
|
206
|
+
headers = new Headers(await abortable(Promise.resolve().then(options.getHeaders), controller.signal));
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (controller.signal.aborted)
|
|
209
|
+
throw error;
|
|
210
|
+
throw new TaskEventError(0, "TASK_OUTPUT_HEADERS_ERROR");
|
|
211
|
+
}
|
|
212
|
+
headers.set("accept", "application/json");
|
|
213
|
+
if (input)
|
|
214
|
+
headers.set("content-type", "application/json");
|
|
215
|
+
const url = new URL(`${basePath}/v1/projects/${encodeURIComponent(ref)}/tasks/${id}/events${query}`, base.origin);
|
|
216
|
+
const response = await abortable(fetchImpl(url, {
|
|
217
|
+
method: input ? "POST" : "GET",
|
|
218
|
+
headers,
|
|
219
|
+
body: input ? JSON.stringify(input) : undefined,
|
|
220
|
+
signal: controller.signal,
|
|
221
|
+
redirect: "error",
|
|
222
|
+
credentials: "omit",
|
|
223
|
+
cache: "no-store"
|
|
224
|
+
}), controller.signal);
|
|
225
|
+
let data;
|
|
226
|
+
try {
|
|
227
|
+
data = await jsonBody(response, controller.signal);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (!response.ok && error instanceof TaskEventError && error.code === "TASK_OUTPUT_INVALID_RESPONSE") {
|
|
230
|
+
throw new TaskEventError(response.status, "TASK_OUTPUT_HTTP_ERROR");
|
|
231
|
+
}
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
if (!response.ok)
|
|
235
|
+
throw new TaskEventError(response.status, record(data) && typeof data.code === "string" ? data.code : "TASK_OUTPUT_HTTP_ERROR", record(data) ? data : {});
|
|
236
|
+
return data;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (controller.signal.aborted)
|
|
239
|
+
throw abortError(controller.signal);
|
|
240
|
+
if (error instanceof TaskEventError)
|
|
241
|
+
throw error;
|
|
242
|
+
throw new TaskEventError(0, "TASK_OUTPUT_NETWORK_ERROR");
|
|
243
|
+
} finally {
|
|
244
|
+
clearTimeout(timeout);
|
|
245
|
+
signal?.removeEventListener("abort", stop);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function list(id, settings = {}) {
|
|
249
|
+
id = taskId(id);
|
|
250
|
+
const after = cursor(settings.after ?? "0"), limit = settings.limit ?? 50;
|
|
251
|
+
if (!integer(limit, 1, 100))
|
|
252
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_LIMIT");
|
|
253
|
+
const query = `?${new URLSearchParams({ after, limit: String(limit) })}`;
|
|
254
|
+
return page(await request(id, query, undefined, settings.signal), ref, id, after, limit);
|
|
255
|
+
}
|
|
256
|
+
async function append(id, input, settings = {}) {
|
|
257
|
+
id = taskId(id);
|
|
258
|
+
if (!record(input) || !integer(input.attempt, 1, 2147483647) || !UUID.test(input.event_id) || !OUTPUTS.has(input.type) || !record(input.payload))
|
|
259
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_INPUT");
|
|
260
|
+
let encoded;
|
|
261
|
+
try {
|
|
262
|
+
encoded = JSON.stringify({ attempt: input.attempt, event_id: input.event_id, type: input.type, payload: input.payload });
|
|
263
|
+
} catch {
|
|
264
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_INPUT");
|
|
265
|
+
}
|
|
266
|
+
if (new TextEncoder().encode(encoded).byteLength > 20 * 1024)
|
|
267
|
+
throw new TaskEventError(413, "TASK_OUTPUT_LIMIT");
|
|
268
|
+
const snapshot = JSON.parse(encoded);
|
|
269
|
+
if (!record(snapshot.payload))
|
|
270
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_INPUT");
|
|
271
|
+
const output = event(await request(id, "", snapshot, settings.signal), ref, id);
|
|
272
|
+
if (output.attempt !== snapshot.attempt || output.event_id !== snapshot.event_id.toLowerCase() || output.type !== snapshot.type)
|
|
273
|
+
invalid();
|
|
274
|
+
return output;
|
|
275
|
+
}
|
|
276
|
+
async function* watch(id, settings = {}) {
|
|
277
|
+
id = taskId(id);
|
|
278
|
+
let after = cursor(settings.after ?? "0");
|
|
279
|
+
const interval = settings.pollIntervalMs ?? 1000, maxRetries = settings.maxRetries ?? 5;
|
|
280
|
+
if (!integer(interval, 10, 60000) || !integer(maxRetries, 0, 20))
|
|
281
|
+
throw new TaskEventError(400, "TASK_OUTPUT_INVALID_INPUT");
|
|
282
|
+
settings.signal?.throwIfAborted();
|
|
283
|
+
let pending = false;
|
|
284
|
+
let wakeWaiter;
|
|
285
|
+
let unsubscribe;
|
|
286
|
+
let retries = 0;
|
|
287
|
+
const wake = () => {
|
|
288
|
+
pending = true;
|
|
289
|
+
wakeWaiter?.();
|
|
290
|
+
};
|
|
291
|
+
async function wait(ms, notifications) {
|
|
292
|
+
settings.signal?.throwIfAborted();
|
|
293
|
+
if (notifications && pending) {
|
|
294
|
+
pending = false;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
await new Promise((resolve, reject) => {
|
|
298
|
+
const finish = () => {
|
|
299
|
+
cleanup();
|
|
300
|
+
resolve();
|
|
301
|
+
};
|
|
302
|
+
const stop = () => {
|
|
303
|
+
cleanup();
|
|
304
|
+
reject(abortError(settings.signal));
|
|
305
|
+
};
|
|
306
|
+
const timeout = setTimeout(finish, ms);
|
|
307
|
+
const cleanup = () => {
|
|
308
|
+
clearTimeout(timeout);
|
|
309
|
+
wakeWaiter = undefined;
|
|
310
|
+
settings.signal?.removeEventListener("abort", stop);
|
|
311
|
+
};
|
|
312
|
+
if (notifications)
|
|
313
|
+
wakeWaiter = finish;
|
|
314
|
+
settings.signal?.addEventListener("abort", stop, { once: true });
|
|
315
|
+
});
|
|
316
|
+
if (notifications)
|
|
317
|
+
pending = false;
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
unsubscribe = settings.subscribe?.(wake);
|
|
321
|
+
for (;; ) {
|
|
322
|
+
settings.signal?.throwIfAborted();
|
|
323
|
+
let current;
|
|
324
|
+
try {
|
|
325
|
+
current = await list(id, { after, limit: settings.limit, signal: settings.signal });
|
|
326
|
+
retries = 0;
|
|
327
|
+
} catch (error) {
|
|
328
|
+
settings.signal?.throwIfAborted();
|
|
329
|
+
const retryable = error instanceof TaskEventError && ([408, 429, 502, 503, 504].includes(error.status) || error.code === "TASK_OUTPUT_NETWORK_ERROR");
|
|
330
|
+
if (!retryable || retries++ >= maxRetries)
|
|
331
|
+
throw error;
|
|
332
|
+
await wait(Math.min(30000, interval * 2 ** retries), false);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
for (const item of current.events) {
|
|
336
|
+
settings.signal?.throwIfAborted();
|
|
337
|
+
yield item;
|
|
338
|
+
await settings.onCursor?.(item.sequence);
|
|
339
|
+
after = item.sequence;
|
|
340
|
+
}
|
|
341
|
+
if (current.has_more)
|
|
342
|
+
continue;
|
|
343
|
+
if (TERMINAL.has(current.task_status))
|
|
344
|
+
return;
|
|
345
|
+
await wait(interval, true);
|
|
346
|
+
}
|
|
347
|
+
} finally {
|
|
348
|
+
await unsubscribe?.();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return { list, append, watch };
|
|
352
|
+
}
|