@supacloud/js 0.39.0 → 0.41.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/PROCEDURES.md +60 -15
- package/QUERY.md +13 -5
- package/README.md +1 -0
- package/dist/index.cjs +279 -63
- package/dist/index.d.cts +36 -4
- package/dist/index.d.mts +36 -4
- package/dist/index.mjs +279 -63
- package/dist/procedure-client.d.cts +11 -1
- package/dist/procedure-client.d.mts +11 -1
- package/dist/procedure-error.d.cts +14 -2
- package/dist/procedure-error.d.mts +14 -2
- package/dist/procedure-runtime.d.cts +9 -0
- package/dist/procedure-runtime.d.mts +9 -0
- package/dist/query.cjs +78 -4
- package/dist/query.d.cts +4 -4
- package/dist/query.d.mts +4 -4
- package/dist/query.mjs +76 -4
- package/dist/queue-rpc.d.cts +5 -0
- package/dist/queue-rpc.d.mts +5 -0
- package/package.json +2 -1
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { SupabaseClient } from "./supabase-types.mjs";
|
|
2
2
|
import type { FetchTransport } from "./bounded-rpc-fetch.mjs";
|
|
3
|
-
|
|
3
|
+
import { type SupaCloudProcedureExecution, type SupaCloudProcedureMetadata } from "./procedure-runtime.mjs";
|
|
4
|
+
export { SupaCloudProcedureError, isSupaCloudProcedureError, isSupaCloudProcedureErrorCode, isSupaCloudProcedureHttpError, isSupaCloudProcedureTransportError, type SupaCloudProcedureErrorCode, type SupaCloudProcedureErrorOptions, } from "./procedure-error.mjs";
|
|
4
5
|
export interface SupaCloudGeneratedClientConfig {
|
|
5
6
|
fetch: FetchTransport;
|
|
7
|
+
errorMapper?: (error: unknown) => unknown | Promise<unknown>;
|
|
8
|
+
procedureExecutionValidator?: (metadata: SupaCloudProcedureMetadata, execution?: SupaCloudProcedureExecution) => void;
|
|
6
9
|
}
|
|
7
10
|
export type SupaCloudGeneratedClientFactory<TClient extends object = object> = (config: SupaCloudGeneratedClientConfig) => TClient;
|
|
11
|
+
export type SupaCloudGeneratedClientOptions<TFactory extends SupaCloudGeneratedClientFactory> = Omit<NonNullable<Parameters<TFactory>[0]>, keyof SupaCloudGeneratedClientConfig> & {
|
|
12
|
+
fetch?: never;
|
|
13
|
+
errorMapper?: never;
|
|
14
|
+
procedureExecutionValidator?: never;
|
|
15
|
+
};
|
|
8
16
|
export interface SupaCloudProcedureClientOptions<TClient extends SupabaseClient, TFactory extends SupaCloudGeneratedClientFactory> {
|
|
9
17
|
/** The existing user-scoped Supabase client; it owns auth and session refresh. */
|
|
10
18
|
supabase: TClient;
|
|
@@ -12,6 +20,8 @@ export interface SupaCloudProcedureClientOptions<TClient extends SupabaseClient,
|
|
|
12
20
|
functionName: string;
|
|
13
21
|
/** The generated createApiClient factory for the application contract. */
|
|
14
22
|
generated: TFactory;
|
|
23
|
+
/** Additional generated-client settings; transport and facade policies are owned by this wrapper. */
|
|
24
|
+
generatedConfig?: SupaCloudGeneratedClientOptions<NoInfer<TFactory>>;
|
|
15
25
|
}
|
|
16
26
|
export type SupaCloudProcedureClient<TFactory extends SupaCloudGeneratedClientFactory> = ReturnType<TFactory>;
|
|
17
27
|
/**
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export type SupaCloudProcedureErrorCode = "API_HTTP_ERROR" | "API_RESPONSE_INVALID" | "API_RESPONSE_UNDECLARED" | "SUPACLOUD_EXECUTION_ERROR" | "SUPACLOUD_FUNCTIONS_ERROR" | "SUPACLOUD_TRANSPORT_ERROR" | "SUPACLOUD_CLIENT_ERROR";
|
|
2
|
+
export declare function isSupaCloudProcedureErrorCode(value: unknown): value is SupaCloudProcedureErrorCode;
|
|
2
3
|
export interface SupaCloudProcedureErrorOptions {
|
|
3
|
-
code:
|
|
4
|
+
code: SupaCloudProcedureErrorCode;
|
|
4
5
|
status?: number | null;
|
|
5
6
|
requestId?: string | null;
|
|
7
|
+
upstreamCode?: string | null;
|
|
6
8
|
details?: unknown;
|
|
7
9
|
response?: Response | undefined;
|
|
8
10
|
cause?: unknown;
|
|
@@ -11,11 +13,21 @@ export interface SupaCloudProcedureErrorOptions {
|
|
|
11
13
|
export declare function procedureErrorIdentifier(value: unknown): string | undefined;
|
|
12
14
|
/** Failure metadata is not proof that a server-side mutation rolled back. */
|
|
13
15
|
export declare class SupaCloudProcedureError extends Error {
|
|
14
|
-
readonly code:
|
|
16
|
+
readonly code: SupaCloudProcedureErrorCode;
|
|
15
17
|
readonly status: number | null;
|
|
16
18
|
readonly requestId: string | null;
|
|
19
|
+
readonly upstreamCode: string | null;
|
|
17
20
|
readonly details: unknown;
|
|
18
21
|
readonly response: Response | undefined;
|
|
19
22
|
readonly cause: unknown;
|
|
20
23
|
constructor(message: string, options: SupaCloudProcedureErrorOptions);
|
|
21
24
|
}
|
|
25
|
+
/** Recognizes errors from separately bundled SDK entrypoints. */
|
|
26
|
+
export declare function isSupaCloudProcedureError(value: unknown): value is SupaCloudProcedureError;
|
|
27
|
+
export declare function isSupaCloudProcedureHttpError(value: unknown): value is SupaCloudProcedureError & {
|
|
28
|
+
status: number;
|
|
29
|
+
response: Response;
|
|
30
|
+
};
|
|
31
|
+
export declare function isSupaCloudProcedureTransportError(value: unknown): value is SupaCloudProcedureError & {
|
|
32
|
+
code: "SUPACLOUD_FUNCTIONS_ERROR" | "SUPACLOUD_TRANSPORT_ERROR";
|
|
33
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export type SupaCloudProcedureErrorCode = "API_HTTP_ERROR" | "API_RESPONSE_INVALID" | "API_RESPONSE_UNDECLARED" | "SUPACLOUD_EXECUTION_ERROR" | "SUPACLOUD_FUNCTIONS_ERROR" | "SUPACLOUD_TRANSPORT_ERROR" | "SUPACLOUD_CLIENT_ERROR";
|
|
2
|
+
export declare function isSupaCloudProcedureErrorCode(value: unknown): value is SupaCloudProcedureErrorCode;
|
|
2
3
|
export interface SupaCloudProcedureErrorOptions {
|
|
3
|
-
code:
|
|
4
|
+
code: SupaCloudProcedureErrorCode;
|
|
4
5
|
status?: number | null;
|
|
5
6
|
requestId?: string | null;
|
|
7
|
+
upstreamCode?: string | null;
|
|
6
8
|
details?: unknown;
|
|
7
9
|
response?: Response | undefined;
|
|
8
10
|
cause?: unknown;
|
|
@@ -11,11 +13,21 @@ export interface SupaCloudProcedureErrorOptions {
|
|
|
11
13
|
export declare function procedureErrorIdentifier(value: unknown): string | undefined;
|
|
12
14
|
/** Failure metadata is not proof that a server-side mutation rolled back. */
|
|
13
15
|
export declare class SupaCloudProcedureError extends Error {
|
|
14
|
-
readonly code:
|
|
16
|
+
readonly code: SupaCloudProcedureErrorCode;
|
|
15
17
|
readonly status: number | null;
|
|
16
18
|
readonly requestId: string | null;
|
|
19
|
+
readonly upstreamCode: string | null;
|
|
17
20
|
readonly details: unknown;
|
|
18
21
|
readonly response: Response | undefined;
|
|
19
22
|
readonly cause: unknown;
|
|
20
23
|
constructor(message: string, options: SupaCloudProcedureErrorOptions);
|
|
21
24
|
}
|
|
25
|
+
/** Recognizes errors from separately bundled SDK entrypoints. */
|
|
26
|
+
export declare function isSupaCloudProcedureError(value: unknown): value is SupaCloudProcedureError;
|
|
27
|
+
export declare function isSupaCloudProcedureHttpError(value: unknown): value is SupaCloudProcedureError & {
|
|
28
|
+
status: number;
|
|
29
|
+
response: Response;
|
|
30
|
+
};
|
|
31
|
+
export declare function isSupaCloudProcedureTransportError(value: unknown): value is SupaCloudProcedureError & {
|
|
32
|
+
code: "SUPACLOUD_FUNCTIONS_ERROR" | "SUPACLOUD_TRANSPORT_ERROR";
|
|
33
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SupaCloudProcedureMetadata {
|
|
2
|
+
readonly idempotency: "none" | "required";
|
|
3
|
+
}
|
|
4
|
+
export interface SupaCloudProcedureExecution {
|
|
5
|
+
readonly idempotencyKey?: string;
|
|
6
|
+
readonly signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function isValidSupaCloudIdempotencyKey(value: unknown): value is string;
|
|
9
|
+
export declare function validateSupaCloudProcedureExecution(metadata: SupaCloudProcedureMetadata, execution?: unknown): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SupaCloudProcedureMetadata {
|
|
2
|
+
readonly idempotency: "none" | "required";
|
|
3
|
+
}
|
|
4
|
+
export interface SupaCloudProcedureExecution {
|
|
5
|
+
readonly idempotencyKey?: string;
|
|
6
|
+
readonly signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export declare function isValidSupaCloudIdempotencyKey(value: unknown): value is string;
|
|
9
|
+
export declare function validateSupaCloudProcedureExecution(metadata: SupaCloudProcedureMetadata, execution?: unknown): void;
|
package/dist/query.cjs
CHANGED
|
@@ -42,9 +42,81 @@ __export(exports_query, {
|
|
|
42
42
|
createSupaCloudQueryAdapter: () => createSupaCloudQueryAdapter
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(exports_query);
|
|
45
|
+
|
|
46
|
+
// src/procedure-error.ts
|
|
47
|
+
var procedureErrorCodes = new Set([
|
|
48
|
+
"API_HTTP_ERROR",
|
|
49
|
+
"API_RESPONSE_INVALID",
|
|
50
|
+
"API_RESPONSE_UNDECLARED",
|
|
51
|
+
"SUPACLOUD_EXECUTION_ERROR",
|
|
52
|
+
"SUPACLOUD_FUNCTIONS_ERROR",
|
|
53
|
+
"SUPACLOUD_TRANSPORT_ERROR",
|
|
54
|
+
"SUPACLOUD_CLIENT_ERROR"
|
|
55
|
+
]);
|
|
56
|
+
function procedureErrorIdentifier(value) {
|
|
57
|
+
return typeof value === "string" && /^[A-Za-z0-9._:-]{1,256}$/.test(value) ? value : undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class SupaCloudProcedureError extends Error {
|
|
61
|
+
code;
|
|
62
|
+
status;
|
|
63
|
+
requestId;
|
|
64
|
+
upstreamCode;
|
|
65
|
+
details;
|
|
66
|
+
response;
|
|
67
|
+
cause;
|
|
68
|
+
constructor(message, options) {
|
|
69
|
+
super(message, { cause: options.cause });
|
|
70
|
+
this.name = "SupaCloudProcedureError";
|
|
71
|
+
this.code = options.code;
|
|
72
|
+
this.status = options.status ?? null;
|
|
73
|
+
this.requestId = procedureErrorIdentifier(options.requestId) ?? null;
|
|
74
|
+
this.upstreamCode = procedureErrorIdentifier(options.upstreamCode) ?? null;
|
|
75
|
+
this.details = options.details;
|
|
76
|
+
this.response = options.response;
|
|
77
|
+
this.cause = options.cause;
|
|
78
|
+
Object.defineProperty(this, "response", { enumerable: false });
|
|
79
|
+
Object.defineProperty(this, "cause", { enumerable: false });
|
|
80
|
+
Object.defineProperty(this, "upstreamCode", { enumerable: false });
|
|
81
|
+
Object.defineProperty(this, "details", { enumerable: false });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/procedure-runtime.ts
|
|
86
|
+
var idempotencyKeyPattern = /^[A-Za-z0-9._:-]{1,512}$/;
|
|
87
|
+
function isValidSupaCloudIdempotencyKey(value) {
|
|
88
|
+
return typeof value === "string" && idempotencyKeyPattern.test(value);
|
|
89
|
+
}
|
|
90
|
+
function isRecord(value) {
|
|
91
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
function validateSupaCloudProcedureExecution(metadata, execution) {
|
|
94
|
+
if (execution !== undefined && !isRecord(execution)) {
|
|
95
|
+
throw new SupaCloudProcedureError("Procedure execution must be an options object", {
|
|
96
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const signal = isRecord(execution) ? execution.signal : undefined;
|
|
100
|
+
if (signal !== undefined && (typeof AbortSignal === "undefined" || !(signal instanceof AbortSignal))) {
|
|
101
|
+
throw new SupaCloudProcedureError("Procedure signal must be an AbortSignal", {
|
|
102
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const key = isRecord(execution) ? execution.idempotencyKey : undefined;
|
|
106
|
+
if (metadata.idempotency === "required" && key === undefined || key !== undefined && !isValidSupaCloudIdempotencyKey(key)) {
|
|
107
|
+
throw new SupaCloudProcedureError("This procedure requires a valid idempotencyKey", {
|
|
108
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/query.ts
|
|
45
114
|
function metadataOf(procedure, kind) {
|
|
115
|
+
if (typeof procedure !== "function") {
|
|
116
|
+
throw new TypeError(`Expected a generated ${kind} procedure; regenerate the application client`);
|
|
117
|
+
}
|
|
46
118
|
const metadata = procedure.__supacloudProcedure;
|
|
47
|
-
if (!metadata || metadata.kind !== kind || typeof metadata.method !== "string" || typeof metadata.path !== "string" || !["none", "required"].includes(metadata.idempotency)) {
|
|
119
|
+
if (!metadata || metadata.kind !== kind || typeof metadata.key !== "string" || typeof metadata.method !== "string" || typeof metadata.path !== "string" || !["none", "required"].includes(metadata.idempotency)) {
|
|
48
120
|
throw new TypeError(`Expected a generated ${kind} procedure; regenerate the application client`);
|
|
49
121
|
}
|
|
50
122
|
return metadata;
|
|
@@ -72,8 +144,10 @@ function snapshot(value, ancestors = new Set) {
|
|
|
72
144
|
}
|
|
73
145
|
}
|
|
74
146
|
function callProcedure(procedure, input, execution) {
|
|
147
|
+
validateSupaCloudProcedureExecution(procedure.__supacloudProcedure, execution);
|
|
148
|
+
const capturedExecution = Object.freeze({ ...execution });
|
|
75
149
|
const call = procedure;
|
|
76
|
-
const signal =
|
|
150
|
+
const signal = capturedExecution.signal;
|
|
77
151
|
return new Promise((resolve, reject) => {
|
|
78
152
|
const onAbort = () => reject(signal?.reason ?? new DOMException("Procedure cancelled", "AbortError"));
|
|
79
153
|
if (signal?.aborted) {
|
|
@@ -83,7 +157,7 @@ function callProcedure(procedure, input, execution) {
|
|
|
83
157
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
84
158
|
Promise.resolve().then(() => {
|
|
85
159
|
signal?.throwIfAborted();
|
|
86
|
-
return call(input,
|
|
160
|
+
return call(input, capturedExecution);
|
|
87
161
|
}).then(resolve, reject).finally(() => signal?.removeEventListener("abort", onAbort));
|
|
88
162
|
});
|
|
89
163
|
}
|
|
@@ -126,7 +200,7 @@ function createSupaCloudQueryAdapter({
|
|
|
126
200
|
mutationKey: procedureKey(procedure, "mutation"),
|
|
127
201
|
retry: false,
|
|
128
202
|
mutationFn: async (variables) => {
|
|
129
|
-
const execution = variables.execution
|
|
203
|
+
const execution = variables.execution === undefined ? {} : variables.execution;
|
|
130
204
|
return callProcedure(procedure, variables.input, execution);
|
|
131
205
|
}
|
|
132
206
|
};
|
package/dist/query.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataTag, DefaultError, MutationKey, MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions } from "@tanstack/query-core";
|
|
2
|
-
type
|
|
2
|
+
import type { SupaCloudProcedureExecution } from "./procedure-runtime.cjs";
|
|
3
|
+
type Procedure<Kind extends "query" | "mutation"> = ((...args: never) => Promise<unknown>) & {
|
|
3
4
|
readonly __supacloudProcedure: {
|
|
4
5
|
readonly key: string;
|
|
5
6
|
readonly method: string;
|
|
@@ -16,8 +17,7 @@ export type SupaCloudProcedureResult<TProcedure> = TProcedure extends (...args:
|
|
|
16
17
|
type ProcedureInput<TProcedure> = {} extends SupaCloudProcedureInput<TProcedure> ? SupaCloudProcedureInput<TProcedure> | undefined : SupaCloudProcedureInput<TProcedure>;
|
|
17
18
|
type QueryResult<TProcedure> = Exclude<SupaCloudProcedureResult<TProcedure>, undefined | void> | (undefined extends SupaCloudProcedureResult<TProcedure> ? null : never);
|
|
18
19
|
type TaggedQueryKey<TProcedure, TError = DefaultError> = DataTag<QueryKey, QueryResult<TProcedure>, TError>;
|
|
19
|
-
export interface SupaCloudProcedureExecutionOptions {
|
|
20
|
-
idempotencyKey?: string;
|
|
20
|
+
export interface SupaCloudProcedureExecutionOptions extends SupaCloudProcedureExecution {
|
|
21
21
|
/** Pass an existing CommandAttempt signal to bind a mutation to component lifetime. */
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
}
|
|
@@ -56,7 +56,7 @@ export declare function createSupaCloudQueryAdapter({ keyPrefix, }: SupaCloudQue
|
|
|
56
56
|
<TProcedure extends Procedure<"query">>(procedure: TProcedure, input: NoInfer<ProcedureInput<TProcedure>>): TaggedQueryKey<TProcedure>;
|
|
57
57
|
};
|
|
58
58
|
queryOptions: <TProcedure extends Procedure<"query">, TError = Error, TData = QueryResult<TProcedure>>(procedure: TProcedure, input: NoInfer<ProcedureInput<TProcedure>>, options?: SupaCloudQueryOptions<NoInfer<TProcedure>, TError, TData>) => SupaCloudQueryOptionsResult<TProcedure, TError, TData>;
|
|
59
|
-
mutationKey:
|
|
59
|
+
mutationKey: <TProcedure extends Procedure<"mutation">>(procedure: TProcedure) => readonly unknown[];
|
|
60
60
|
mutationOptions: <TProcedure extends Procedure<"mutation">, TError = Error, TContext = unknown>(procedure: TProcedure, options?: SupaCloudMutationOptions<NoInfer<TProcedure>, TError, TContext>) => SupaCloudMutationOptionsResult<TProcedure, TError, TContext>;
|
|
61
61
|
};
|
|
62
62
|
export {};
|
package/dist/query.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DataTag, DefaultError, MutationKey, MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions } from "@tanstack/query-core";
|
|
2
|
-
type
|
|
2
|
+
import type { SupaCloudProcedureExecution } from "./procedure-runtime.mjs";
|
|
3
|
+
type Procedure<Kind extends "query" | "mutation"> = ((...args: never) => Promise<unknown>) & {
|
|
3
4
|
readonly __supacloudProcedure: {
|
|
4
5
|
readonly key: string;
|
|
5
6
|
readonly method: string;
|
|
@@ -16,8 +17,7 @@ export type SupaCloudProcedureResult<TProcedure> = TProcedure extends (...args:
|
|
|
16
17
|
type ProcedureInput<TProcedure> = {} extends SupaCloudProcedureInput<TProcedure> ? SupaCloudProcedureInput<TProcedure> | undefined : SupaCloudProcedureInput<TProcedure>;
|
|
17
18
|
type QueryResult<TProcedure> = Exclude<SupaCloudProcedureResult<TProcedure>, undefined | void> | (undefined extends SupaCloudProcedureResult<TProcedure> ? null : never);
|
|
18
19
|
type TaggedQueryKey<TProcedure, TError = DefaultError> = DataTag<QueryKey, QueryResult<TProcedure>, TError>;
|
|
19
|
-
export interface SupaCloudProcedureExecutionOptions {
|
|
20
|
-
idempotencyKey?: string;
|
|
20
|
+
export interface SupaCloudProcedureExecutionOptions extends SupaCloudProcedureExecution {
|
|
21
21
|
/** Pass an existing CommandAttempt signal to bind a mutation to component lifetime. */
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
}
|
|
@@ -56,7 +56,7 @@ export declare function createSupaCloudQueryAdapter({ keyPrefix, }: SupaCloudQue
|
|
|
56
56
|
<TProcedure extends Procedure<"query">>(procedure: TProcedure, input: NoInfer<ProcedureInput<TProcedure>>): TaggedQueryKey<TProcedure>;
|
|
57
57
|
};
|
|
58
58
|
queryOptions: <TProcedure extends Procedure<"query">, TError = Error, TData = QueryResult<TProcedure>>(procedure: TProcedure, input: NoInfer<ProcedureInput<TProcedure>>, options?: SupaCloudQueryOptions<NoInfer<TProcedure>, TError, TData>) => SupaCloudQueryOptionsResult<TProcedure, TError, TData>;
|
|
59
|
-
mutationKey:
|
|
59
|
+
mutationKey: <TProcedure extends Procedure<"mutation">>(procedure: TProcedure) => readonly unknown[];
|
|
60
60
|
mutationOptions: <TProcedure extends Procedure<"mutation">, TError = Error, TContext = unknown>(procedure: TProcedure, options?: SupaCloudMutationOptions<NoInfer<TProcedure>, TError, TContext>) => SupaCloudMutationOptionsResult<TProcedure, TError, TContext>;
|
|
61
61
|
};
|
|
62
62
|
export {};
|
package/dist/query.mjs
CHANGED
|
@@ -1,7 +1,77 @@
|
|
|
1
|
+
// src/procedure-error.ts
|
|
2
|
+
var procedureErrorCodes = new Set([
|
|
3
|
+
"API_HTTP_ERROR",
|
|
4
|
+
"API_RESPONSE_INVALID",
|
|
5
|
+
"API_RESPONSE_UNDECLARED",
|
|
6
|
+
"SUPACLOUD_EXECUTION_ERROR",
|
|
7
|
+
"SUPACLOUD_FUNCTIONS_ERROR",
|
|
8
|
+
"SUPACLOUD_TRANSPORT_ERROR",
|
|
9
|
+
"SUPACLOUD_CLIENT_ERROR"
|
|
10
|
+
]);
|
|
11
|
+
function procedureErrorIdentifier(value) {
|
|
12
|
+
return typeof value === "string" && /^[A-Za-z0-9._:-]{1,256}$/.test(value) ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class SupaCloudProcedureError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
status;
|
|
18
|
+
requestId;
|
|
19
|
+
upstreamCode;
|
|
20
|
+
details;
|
|
21
|
+
response;
|
|
22
|
+
cause;
|
|
23
|
+
constructor(message, options) {
|
|
24
|
+
super(message, { cause: options.cause });
|
|
25
|
+
this.name = "SupaCloudProcedureError";
|
|
26
|
+
this.code = options.code;
|
|
27
|
+
this.status = options.status ?? null;
|
|
28
|
+
this.requestId = procedureErrorIdentifier(options.requestId) ?? null;
|
|
29
|
+
this.upstreamCode = procedureErrorIdentifier(options.upstreamCode) ?? null;
|
|
30
|
+
this.details = options.details;
|
|
31
|
+
this.response = options.response;
|
|
32
|
+
this.cause = options.cause;
|
|
33
|
+
Object.defineProperty(this, "response", { enumerable: false });
|
|
34
|
+
Object.defineProperty(this, "cause", { enumerable: false });
|
|
35
|
+
Object.defineProperty(this, "upstreamCode", { enumerable: false });
|
|
36
|
+
Object.defineProperty(this, "details", { enumerable: false });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/procedure-runtime.ts
|
|
41
|
+
var idempotencyKeyPattern = /^[A-Za-z0-9._:-]{1,512}$/;
|
|
42
|
+
function isValidSupaCloudIdempotencyKey(value) {
|
|
43
|
+
return typeof value === "string" && idempotencyKeyPattern.test(value);
|
|
44
|
+
}
|
|
45
|
+
function isRecord(value) {
|
|
46
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
function validateSupaCloudProcedureExecution(metadata, execution) {
|
|
49
|
+
if (execution !== undefined && !isRecord(execution)) {
|
|
50
|
+
throw new SupaCloudProcedureError("Procedure execution must be an options object", {
|
|
51
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const signal = isRecord(execution) ? execution.signal : undefined;
|
|
55
|
+
if (signal !== undefined && (typeof AbortSignal === "undefined" || !(signal instanceof AbortSignal))) {
|
|
56
|
+
throw new SupaCloudProcedureError("Procedure signal must be an AbortSignal", {
|
|
57
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const key = isRecord(execution) ? execution.idempotencyKey : undefined;
|
|
61
|
+
if (metadata.idempotency === "required" && key === undefined || key !== undefined && !isValidSupaCloudIdempotencyKey(key)) {
|
|
62
|
+
throw new SupaCloudProcedureError("This procedure requires a valid idempotencyKey", {
|
|
63
|
+
code: "SUPACLOUD_EXECUTION_ERROR"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
1
68
|
// src/query.ts
|
|
2
69
|
function metadataOf(procedure, kind) {
|
|
70
|
+
if (typeof procedure !== "function") {
|
|
71
|
+
throw new TypeError(`Expected a generated ${kind} procedure; regenerate the application client`);
|
|
72
|
+
}
|
|
3
73
|
const metadata = procedure.__supacloudProcedure;
|
|
4
|
-
if (!metadata || metadata.kind !== kind || typeof metadata.method !== "string" || typeof metadata.path !== "string" || !["none", "required"].includes(metadata.idempotency)) {
|
|
74
|
+
if (!metadata || metadata.kind !== kind || typeof metadata.key !== "string" || typeof metadata.method !== "string" || typeof metadata.path !== "string" || !["none", "required"].includes(metadata.idempotency)) {
|
|
5
75
|
throw new TypeError(`Expected a generated ${kind} procedure; regenerate the application client`);
|
|
6
76
|
}
|
|
7
77
|
return metadata;
|
|
@@ -29,8 +99,10 @@ function snapshot(value, ancestors = new Set) {
|
|
|
29
99
|
}
|
|
30
100
|
}
|
|
31
101
|
function callProcedure(procedure, input, execution) {
|
|
102
|
+
validateSupaCloudProcedureExecution(procedure.__supacloudProcedure, execution);
|
|
103
|
+
const capturedExecution = Object.freeze({ ...execution });
|
|
32
104
|
const call = procedure;
|
|
33
|
-
const signal =
|
|
105
|
+
const signal = capturedExecution.signal;
|
|
34
106
|
return new Promise((resolve, reject) => {
|
|
35
107
|
const onAbort = () => reject(signal?.reason ?? new DOMException("Procedure cancelled", "AbortError"));
|
|
36
108
|
if (signal?.aborted) {
|
|
@@ -40,7 +112,7 @@ function callProcedure(procedure, input, execution) {
|
|
|
40
112
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
41
113
|
Promise.resolve().then(() => {
|
|
42
114
|
signal?.throwIfAborted();
|
|
43
|
-
return call(input,
|
|
115
|
+
return call(input, capturedExecution);
|
|
44
116
|
}).then(resolve, reject).finally(() => signal?.removeEventListener("abort", onAbort));
|
|
45
117
|
});
|
|
46
118
|
}
|
|
@@ -83,7 +155,7 @@ function createSupaCloudQueryAdapter({
|
|
|
83
155
|
mutationKey: procedureKey(procedure, "mutation"),
|
|
84
156
|
retry: false,
|
|
85
157
|
mutationFn: async (variables) => {
|
|
86
|
-
const execution = variables.execution
|
|
158
|
+
const execution = variables.execution === undefined ? {} : variables.execution;
|
|
87
159
|
return callProcedure(procedure, variables.input, execution);
|
|
88
160
|
}
|
|
89
161
|
};
|
package/dist/queue-rpc.d.cts
CHANGED
|
@@ -21,6 +21,11 @@ export type SupaCloudQueueSendResult = {
|
|
|
21
21
|
status: "pending";
|
|
22
22
|
payload: SupaCloudQueueJson;
|
|
23
23
|
};
|
|
24
|
+
/** Deduplication confirms the original enqueue, not current pending/execution state. */
|
|
25
|
+
export type SupaCloudQueueIdempotentSendResult = Omit<SupaCloudQueueSendResult, "status"> & {
|
|
26
|
+
status: "pending" | "deduplicated";
|
|
27
|
+
deduplicated: boolean;
|
|
28
|
+
};
|
|
24
29
|
export type SupaCloudQueueMutationResult = {
|
|
25
30
|
id: string;
|
|
26
31
|
msg_id: string;
|
package/dist/queue-rpc.d.mts
CHANGED
|
@@ -21,6 +21,11 @@ export type SupaCloudQueueSendResult = {
|
|
|
21
21
|
status: "pending";
|
|
22
22
|
payload: SupaCloudQueueJson;
|
|
23
23
|
};
|
|
24
|
+
/** Deduplication confirms the original enqueue, not current pending/execution state. */
|
|
25
|
+
export type SupaCloudQueueIdempotentSendResult = Omit<SupaCloudQueueSendResult, "status"> & {
|
|
26
|
+
status: "pending" | "deduplicated";
|
|
27
|
+
deduplicated: boolean;
|
|
28
|
+
};
|
|
24
29
|
export type SupaCloudQueueMutationResult = {
|
|
25
30
|
id: string;
|
|
26
31
|
msg_id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Platform SDK for SupaCloud, built on top of supabase-js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -106,6 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
108
|
"@supacloud/contracts": "0.8.0",
|
|
109
|
+
"@supacloud/query": "0.2.0",
|
|
109
110
|
"rxjs": "7.8.2"
|
|
110
111
|
},
|
|
111
112
|
"devDependencies": {
|