@supacloud/js 0.37.0 → 0.39.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/dist/query.mjs ADDED
@@ -0,0 +1,100 @@
1
+ // src/query.ts
2
+ function metadataOf(procedure, kind) {
3
+ const metadata = procedure.__supacloudProcedure;
4
+ if (!metadata || metadata.kind !== kind || typeof metadata.method !== "string" || typeof metadata.path !== "string" || !["none", "required"].includes(metadata.idempotency)) {
5
+ throw new TypeError(`Expected a generated ${kind} procedure; regenerate the application client`);
6
+ }
7
+ return metadata;
8
+ }
9
+ function snapshot(value, ancestors = new Set) {
10
+ if (value === undefined || value === null || typeof value === "string" || typeof value === "boolean")
11
+ return value;
12
+ if (typeof value === "number" && Number.isFinite(value))
13
+ return value;
14
+ if (typeof value !== "object" || ancestors.has(value)) {
15
+ throw new TypeError("Procedure input must be acyclic JSON data");
16
+ }
17
+ const prototype = Object.getPrototypeOf(value);
18
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
19
+ throw new TypeError("Procedure input must be JSON data");
20
+ }
21
+ ancestors.add(value);
22
+ try {
23
+ if (Array.isArray(value)) {
24
+ return Object.freeze(value.map((item) => snapshot(item, ancestors) ?? null));
25
+ }
26
+ return Object.freeze(Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined).map(([key, item]) => [key, snapshot(item, ancestors)])));
27
+ } finally {
28
+ ancestors.delete(value);
29
+ }
30
+ }
31
+ function callProcedure(procedure, input, execution) {
32
+ const call = procedure;
33
+ const signal = execution.signal;
34
+ return new Promise((resolve, reject) => {
35
+ const onAbort = () => reject(signal?.reason ?? new DOMException("Procedure cancelled", "AbortError"));
36
+ if (signal?.aborted) {
37
+ onAbort();
38
+ return;
39
+ }
40
+ signal?.addEventListener("abort", onAbort, { once: true });
41
+ Promise.resolve().then(() => {
42
+ signal?.throwIfAborted();
43
+ return call(input, execution);
44
+ }).then(resolve, reject).finally(() => signal?.removeEventListener("abort", onAbort));
45
+ });
46
+ }
47
+ function createSupaCloudQueryAdapter({
48
+ keyPrefix
49
+ }) {
50
+ if (!Array.isArray(keyPrefix) || keyPrefix.length === 0 || keyPrefix.some((part) => typeof part !== "string" || !part.trim())) {
51
+ throw new TypeError("keyPrefix must contain nonempty identity values");
52
+ }
53
+ const prefix = Object.freeze(["supacloud", ...keyPrefix]);
54
+ function procedureKey(procedure, kind) {
55
+ const metadata = metadataOf(procedure, kind);
56
+ return Object.freeze([...prefix, kind, metadata.method, metadata.path]);
57
+ }
58
+ function queryKey(procedure, ...args) {
59
+ if (args.length === 0)
60
+ return procedureKey(procedure, "query");
61
+ return Object.freeze([
62
+ ...procedureKey(procedure, "query"),
63
+ snapshot(args[0] ?? {})
64
+ ]);
65
+ }
66
+ function queryOptions(procedure, input, options) {
67
+ const capturedInput = snapshot(input ?? {});
68
+ return {
69
+ ...options,
70
+ queryKey: Object.freeze([
71
+ ...procedureKey(procedure, "query"),
72
+ capturedInput
73
+ ]),
74
+ queryFn: async ({ signal }) => {
75
+ const result = await callProcedure(procedure, capturedInput, { signal });
76
+ return result === undefined ? null : result;
77
+ }
78
+ };
79
+ }
80
+ function mutationOptions(procedure, options) {
81
+ return {
82
+ ...options,
83
+ mutationKey: procedureKey(procedure, "mutation"),
84
+ retry: false,
85
+ mutationFn: async (variables) => {
86
+ const execution = variables.execution ?? {};
87
+ return callProcedure(procedure, variables.input, execution);
88
+ }
89
+ };
90
+ }
91
+ return {
92
+ queryKey,
93
+ queryOptions,
94
+ mutationKey: (procedure) => procedureKey(procedure, "mutation"),
95
+ mutationOptions
96
+ };
97
+ }
98
+ export {
99
+ createSupaCloudQueryAdapter
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/js",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "Platform SDK for SupaCloud, built on top of supabase-js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -46,6 +46,16 @@
46
46
  "types": "./dist/reactive.d.cts",
47
47
  "default": "./dist/reactive.cjs"
48
48
  }
49
+ },
50
+ "./query": {
51
+ "import": {
52
+ "types": "./dist/query.d.mts",
53
+ "default": "./dist/query.mjs"
54
+ },
55
+ "require": {
56
+ "types": "./dist/query.d.cts",
57
+ "default": "./dist/query.cjs"
58
+ }
49
59
  }
50
60
  },
51
61
  "files": [
@@ -54,6 +64,8 @@
54
64
  "dist",
55
65
  "README.md",
56
66
  "COMPATIBILITY.md",
67
+ "PROCEDURES.md",
68
+ "QUERY.md",
57
69
  "REACTIVE.md"
58
70
  ],
59
71
  "scripts": {
@@ -67,8 +79,8 @@
67
79
  "typecheck": "tsc -p tsconfig.json --noEmit",
68
80
  "typecheck:test": "tsc -p tsconfig.test.json --noEmit",
69
81
  "check:package": "node ../../.github/scripts/esm-package-policy.mjs --pack .",
70
- "build:js:esm": "bun build src/index.ts src/task-events.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target node --external @supabase/supabase-js --external @supacloud/contracts && bun build src/contracts.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target browser --external @supacloud/contracts && bun build src/reactive.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target browser --external rxjs",
71
- "build:js:cjs": "bun build src/index.ts src/task-events.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target node --external @supabase/supabase-js --external @supacloud/contracts && bun build src/contracts.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target browser --external @supacloud/contracts && bun build src/reactive.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target browser --external rxjs"
82
+ "build:js:esm": "bun build src/index.ts src/task-events.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target node --external @supabase/supabase-js --external @supacloud/contracts && bun build src/contracts.ts src/query.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target browser --external @supacloud/contracts --external @tanstack/query-core && bun build src/reactive.ts --outdir dist --format esm --entry-naming \"[name].mjs\" --chunk-naming \"[name]-[hash].mjs\" --target browser --external rxjs",
83
+ "build:js:cjs": "bun build src/index.ts src/task-events.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target node --external @supabase/supabase-js --external @supacloud/contracts && bun build src/contracts.ts src/query.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target browser --external @supacloud/contracts --external @tanstack/query-core && bun build src/reactive.ts --outdir dist --format cjs --entry-naming \"[name].cjs\" --chunk-naming \"[name]-[hash].cjs\" --target browser --external rxjs"
72
84
  },
73
85
  "keywords": [
74
86
  "supacloud",
@@ -84,7 +96,13 @@
84
96
  "directory": "packages/supacloud-js"
85
97
  },
86
98
  "peerDependencies": {
87
- "@supabase/supabase-js": "^2.115.0"
99
+ "@supabase/supabase-js": "^2.115.0",
100
+ "@tanstack/query-core": "^5.104.1"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "@tanstack/query-core": {
104
+ "optional": true
105
+ }
88
106
  },
89
107
  "dependencies": {
90
108
  "@supacloud/contracts": "0.8.0",
@@ -93,7 +111,11 @@
93
111
  "devDependencies": {
94
112
  "@types/bun": "^1.4.2",
95
113
  "@supabase/supabase-js": "^2.115.0",
96
- "typescript": "^7.0.2"
114
+ "typescript": "^7.0.2",
115
+ "@tanstack/query-core": "5.104.1",
116
+ "@tanstack/svelte-query": "6.3.1",
117
+ "typebox": "1.3.34",
118
+ "svelte": "5.57.1"
97
119
  },
98
120
  "engines": {
99
121
  "node": ">=22.12.0"