@supacloud/js 0.38.0 → 0.39.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/PROCEDURES.md +145 -0
- package/QUERY.md +22 -4
- package/README.md +20 -0
- package/dist/api-fetch.d.cts +2 -0
- package/dist/api-fetch.d.mts +2 -0
- package/dist/index.cjs +225 -5
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +225 -5
- package/dist/procedure-client.d.cts +31 -0
- package/dist/procedure-client.d.mts +31 -0
- package/dist/procedure-error.d.cts +33 -0
- package/dist/procedure-error.d.mts +33 -0
- package/dist/procedure-runtime.d.cts +9 -0
- package/dist/procedure-runtime.d.mts +9 -0
- package/dist/query.cjs +78 -9
- package/dist/query.d.cts +4 -4
- package/dist/query.d.mts +4 -4
- package/dist/query.mjs +76 -9
- package/package.json +2 -1
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
|
}
|
|
@@ -78,17 +150,12 @@ function createSupaCloudQueryAdapter({
|
|
|
78
150
|
};
|
|
79
151
|
}
|
|
80
152
|
function mutationOptions(procedure, options) {
|
|
81
|
-
const metadata = metadataOf(procedure, "mutation");
|
|
82
153
|
return {
|
|
83
154
|
...options,
|
|
84
155
|
mutationKey: procedureKey(procedure, "mutation"),
|
|
85
156
|
retry: false,
|
|
86
157
|
mutationFn: async (variables) => {
|
|
87
|
-
const execution = variables.execution
|
|
88
|
-
const key = execution.idempotencyKey;
|
|
89
|
-
if (metadata.idempotency === "required" && key === undefined || key !== undefined && (typeof key !== "string" || !/^[A-Za-z0-9._:-]{1,512}$/.test(key))) {
|
|
90
|
-
throw new TypeError("This mutation requires a valid idempotencyKey");
|
|
91
|
-
}
|
|
158
|
+
const execution = variables.execution === undefined ? {} : variables.execution;
|
|
92
159
|
return callProcedure(procedure, variables.input, execution);
|
|
93
160
|
}
|
|
94
161
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "Platform SDK for SupaCloud, built on top of supabase-js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"dist",
|
|
65
65
|
"README.md",
|
|
66
66
|
"COMPATIBILITY.md",
|
|
67
|
+
"PROCEDURES.md",
|
|
67
68
|
"QUERY.md",
|
|
68
69
|
"REACTIVE.md"
|
|
69
70
|
],
|