@ankhorage/db-supabase 0.0.0-stage → 2.0.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +346 -0
  2. package/LICENSE +21 -0
  3. package/README.md +23 -2
  4. package/dist/adapter.d.ts +3 -0
  5. package/dist/adapter.d.ts.map +1 -0
  6. package/dist/adapter.js +170 -0
  7. package/dist/adapter.js.map +1 -0
  8. package/dist/admin.d.ts +4 -0
  9. package/dist/admin.d.ts.map +1 -0
  10. package/dist/admin.js +145 -0
  11. package/dist/admin.js.map +1 -0
  12. package/dist/errors.d.ts +5 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +37 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +4 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/query.d.ts +4 -0
  21. package/dist/query.d.ts.map +1 -0
  22. package/dist/query.js +94 -0
  23. package/dist/query.js.map +1 -0
  24. package/dist/realtime.d.ts +10 -0
  25. package/dist/realtime.d.ts.map +1 -0
  26. package/dist/realtime.js +74 -0
  27. package/dist/realtime.js.map +1 -0
  28. package/dist/types.d.ts +53 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/types.js +2 -0
  31. package/dist/types.js.map +1 -0
  32. package/dist/validation.d.ts +7 -0
  33. package/dist/validation.d.ts.map +1 -0
  34. package/dist/validation.js +43 -0
  35. package/dist/validation.js.map +1 -0
  36. package/package.json +79 -4
  37. package/src/adapter.test.ts +171 -0
  38. package/src/adapter.ts +237 -0
  39. package/src/admin.test.ts +106 -0
  40. package/src/admin.ts +204 -0
  41. package/src/errors.ts +66 -0
  42. package/src/index.ts +27 -0
  43. package/src/metadata/repository.json +42 -0
  44. package/src/query.ts +122 -0
  45. package/src/realtime.test.ts +174 -0
  46. package/src/realtime.ts +127 -0
  47. package/src/types.ts +69 -0
  48. package/src/validation.ts +57 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,346 @@
1
+ # @ankhorage/supabase-db
2
+
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - d37d432: Rename the Supabase database adapter package from `@ankhorage/supabase-db` to `@ankhorage/db-supabase`.
8
+
9
+ ### Patch Changes
10
+
11
+ - f048ff1: Update Ankhorage dependencies: `@ankhorage/contracts`.
12
+ - 06e1f4e: Update Renovate-managed workflows.
13
+ - a0aa750: Update dependencies: `@ankhorage/devtools`.
14
+ - d261579: Update dependencies: `@ankhorage/contracts`.
15
+ - 7c593b3: Update Renovate-managed workflows.
16
+ - d18b18a: Update dependencies: `@ankhorage/devtools`.
17
+ - 64c37b1: Update dependencies: `@ankhorage/contracts`.
18
+ - 561db5e: Update Renovate-managed workflows.
19
+ - dd258ac: Update Renovate-managed workflows.
20
+ - 1992dce: Update dependencies: `@ankhorage/devtools`.
21
+ - f816497: Update Renovate-managed workflows.
22
+ - f82d82e: Update dependencies: `@ankhorage/devtools`.
23
+ - a9ed378: Update dependencies: `@ankhorage/contracts`.
24
+ - 44a0e50: Update Renovate-managed workflows.
25
+ - 211f539: Update Renovate-managed workflows.
26
+ - b81c649: Update dependencies: `@ankhorage/devtools`.
27
+ - d51b2ed: Update dependencies: `@ankhorage/contracts`.
28
+ - ed1e768: Update dependencies: `@ankhorage/contracts`.
29
+ - fd176fe: Update Renovate-managed workflows.
30
+ - 0298360: Update dependencies: `@ankhorage/devtools`.
31
+ - 4431071: Update dependencies: `@ankhorage/contracts`.
32
+ - b3a29e5: Update Renovate-managed workflows.
33
+ - 2abb8a9: Update dependencies: `@ankhorage/devtools`.
34
+ - b122e78: Update dependencies: `@ankhorage/contracts`.
35
+ - a916cc3: Update Renovate-managed workflows.
36
+ - 8c6668b: Update dependencies: `@ankhorage/devtools`.
37
+ - 61ba6f5: Update Renovate-managed workflows.
38
+ - e687d30: Update dependencies: `@ankhorage/devtools`.
39
+ - a86383c: Update dependencies: `@ankhorage/contracts`.
40
+ - f2a7dd1: Update dependencies: `@ankhorage/devtools`.
41
+ - e2b456a: Update Renovate-managed workflows.
42
+ - 7918cd6: Update dependencies: `@ankhorage/contracts`.
43
+ - 7993551: Update dependencies: `@ankhorage/contracts`.
44
+ - 7085074: Update dependencies: `@ankhorage/devtools`.
45
+ - a43c510: Update dependencies: `@ankhorage/contracts`.
46
+ - 5e85bc7: Update dependencies: `@ankhorage/contracts`.
47
+ - da91b23: Update dependencies: `@ankhorage/contracts`.
48
+ - e63d660: Update Renovate-managed workflows.
49
+ - 8c738a5: Update dependencies: `@ankhorage/contracts`.
50
+ - f252e2a: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
51
+ - 446de15: Update Renovate-managed workflows.
52
+ - f642ba2: Update dependencies: `@ankhorage/devtools`.
53
+ - f6766ec: Update Renovate-managed workflows.
54
+ - a926329: Update dependencies: `@ankhorage/devtools`.
55
+ - 8f3d61c: Update Renovate-managed workflows.
56
+ - f3f2c29: Update dependencies: `@ankhorage/contracts`.
57
+ - 2cbedf2: Update dependencies: `@ankhorage/contracts`.
58
+ - a90678d: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
59
+ - 25e78a7: Update Renovate-managed workflows.
60
+ - 21132d0: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
61
+ - 2e37969: Update Renovate-managed workflows.
62
+ - 143bb3d: Update dependencies: `@ankhorage/devtools`.
63
+ - 29f8d80: Update Renovate-managed workflows.
64
+ - 80582d1: Update dependencies: `@ankhorage/devtools`.
65
+ - 17d01b0: Update dependencies: `@types/node`.
66
+ - 73078b0: Update dependencies: `@ankhorage/devtools`.
67
+ - aa99016: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
68
+ - f712d7f: Update Renovate-managed workflows.
69
+ - 69963d9: Update Renovate-managed workflows.
70
+ - e8008be: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
71
+ - 2bcaa96: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
72
+ - 3ccef0d: Update Renovate-managed workflows.
73
+ - ca48d27: Update dependencies: `@ankhorage/contracts`, `@ankhorage/devtools`.
74
+ - d7f380a: Update Renovate-managed workflows.
75
+ - 63de714: Update dependencies: `@ankhorage/paradox`.
76
+ - f5d8e89: Update Renovate-managed workflows.
77
+ - 451eb59: Update dependencies: `@ankhorage/devtools`.
78
+ - 5af9a99: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
79
+ - 13a9c27: Update Renovate-managed workflows.
80
+ - 083625e: Update dependencies: `@ankhorage/contracts`.
81
+ - e6082cf: Update Renovate-managed workflows.
82
+ - 2f13be0: Update dependencies: `@ankhorage/devtools`.
83
+ - 1898f73: Update dependencies: `@ankhorage/contracts`.
84
+ - ca551f6: Update dependencies: `@ankhorage/devtools`.
85
+ - 8a2b82b: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
86
+ - 5d8f2d6: Update Renovate-managed workflows.
87
+ - 4b4e88a: Update dependencies: `@ankhorage/devtools`.
88
+ - 87c295b: Update Renovate-managed workflows.
89
+ - bfcfa7d: Update dependencies: `@ankhorage/contracts`.
90
+ - bdf5c34: Update Renovate-managed workflows.
91
+ - ab7105f: Update dependencies: `@ankhorage/devtools`.
92
+ - 838a4d0: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
93
+ - 0a511dc: Update Renovate-managed workflows.
94
+ - 40284bc: Update dependencies: `@ankhorage/contracts`.
95
+ - dbf04a2: Update dependencies: `@ankhorage/contracts`.
96
+ - 1f0ee94: Update Renovate-managed workflows.
97
+ - 64ae025: Update dependencies: `@ankhorage/devtools`.
98
+ - 0908c1b: Update dependencies: `@ankhorage/contracts`.
99
+ - c59781a: Update dependencies: `@ankhorage/contracts`.
100
+ - ac547c8: Update dependencies: `@ankhorage/contracts`, `@ankhorage/devtools`.
101
+ - 2a7934e: Update Renovate-managed workflows.
102
+ - 220902f: Update dependencies: `@ankhorage/devtools`.
103
+ - 4dc57a3: Update dependencies: `@ankhorage/contracts`.
104
+ - fad9105: Update Renovate-managed workflows.
105
+ - 7f27afa: Update dependencies: `@ankhorage/devtools`.
106
+ - 84e9548: Update dependencies: `@ankhorage/contracts`.
107
+ - 415bdc5: Update dependencies: `@ankhorage/devtools`.
108
+ - 3f1eac0: Update dependencies: `@ankhorage/contracts`.
109
+ - 5a50bdc: Update Renovate-managed workflows.
110
+ - 8a8b31f: Update dependencies: `@ankhorage/devtools`.
111
+ - 66d048a: Update Renovate-managed workflows.
112
+ - deda86b: Update dependencies: `@ankhorage/devtools`.
113
+ - 95a6763: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
114
+ - be3713e: Update dependencies: `@ankhorage/devtools`.
115
+ - 2164f84: Update Renovate-managed workflows.
116
+ - dd9007c: Update dependencies: `@ankhorage/devtools`.
117
+ - 330588b: Update Renovate-managed workflows.
118
+ - 7f69b3b: Update dependencies: `@ankhorage/devtools`.
119
+ - 02cf298: Update Renovate-managed workflows.
120
+ - 9a03403: Update dependencies: `@ankhorage/devtools`.
121
+ - e7277ae: Update Renovate-managed workflows.
122
+ - 90211e2: Update dependencies: `@ankhorage/devtools`.
123
+ - d8d70dd: Update Renovate-managed workflows.
124
+ - 0f37268: Update dependencies: `@ankhorage/devtools`.
125
+ - 6db3108: Update Renovate-managed workflows.
126
+ - e5c7e97: Update dependencies: `@ankhorage/devtools`.
127
+ - 6331c9b: Update dependencies: `@ankhorage/contracts`.
128
+ - c540aba: Update Renovate-managed workflows.
129
+ - 681ca05: Update dependencies: `@ankhorage/devtools`.
130
+ - 3e10440: Update Renovate-managed workflows.
131
+ - d4539c5: Update dependencies: `@ankhorage/devtools`.
132
+ - acb4865: Update dependencies: `@ankhorage/contracts`.
133
+ - 93d5356: Update dependencies: `@ankhorage/devtools`.
134
+ - 3e63da6: Update dependencies: `@ankhorage/contracts`.
135
+ - 1cd40a0: Update Renovate-managed workflows.
136
+ - f36f0d4: Update dependencies: `@ankhorage/devtools`.
137
+ - de77508: Update dependencies: `@ankhorage/contracts`.
138
+ - 0212e7c: Update Renovate-managed workflows.
139
+ - eef2696: Update dependencies: `@ankhorage/devtools`.
140
+ - a723a19: Update Renovate-managed workflows.
141
+ - b4c004e: Update dependencies: `@ankhorage/devtools`.
142
+ - b0294dd: Update dependencies: `@ankhorage/contracts`.
143
+ - 60aea84: Update Renovate-managed workflows.
144
+ - 6dc530b: Update dependencies: `@ankhorage/devtools`.
145
+ - 1c2aeb5: Update dependencies: `@ankhorage/contracts`.
146
+ - c8d45ca: Update Renovate-managed workflows.
147
+ - c2af41c: Update dependencies: `@ankhorage/devtools`.
148
+ - 5460433: Update Renovate-managed workflows.
149
+ - 2412b51: Update dependencies: `@ankhorage/devtools`.
150
+ - c6239e8: Update dependencies: `@ankhorage/contracts`.
151
+ - 69cab0b: Update Renovate-managed workflows.
152
+ - c0a3254: Update dependencies: `@ankhorage/devtools`.
153
+ - f90d4a5: Update dependencies: `@ankhorage/contracts`.
154
+ - 280d375: Update dependencies: `@ankhorage/devtools`.
155
+ - d697cba: Update dependencies: `@ankhorage/contracts`.
156
+ - 4f8e151: Update Renovate-managed workflows.
157
+ - d7aea73: Update dependencies: `@ankhorage/devtools`.
158
+ - c410cde: Update Renovate-managed workflows.
159
+ - 756ceaf: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
160
+ - 386254d: Update dependencies: `@ankhorage/contracts`.
161
+ - 33d9673: Update dependencies: `@ankhorage/contracts`.
162
+ - 67e4f9e: Update dependencies: `@ankhorage/contracts`.
163
+ - 668319c: Update dependencies: `@ankhorage/contracts`.
164
+ - f40dd4c: Update dependencies: `@ankhorage/contracts`.
165
+ - 8e61486: Update dependencies: `@ankhorage/contracts`.
166
+ - e632467: Update dependencies: `@ankhorage/contracts`.
167
+ - 4b2ab60: Update dependencies: `@ankhorage/contracts`.
168
+ - d5b0cc2: Update dependencies: `@ankhorage/contracts`.
169
+ - 29a1e31: Update dependencies: `@ankhorage/contracts`.
170
+ - 87a8192: Update dependencies: `@ankhorage/contracts`.
171
+ - 5f93b6a: Update dependencies: `@ankhorage/contracts`.
172
+ - f63450b: Update dependencies: `@ankhorage/contracts`.
173
+ - d381517: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
174
+ - ace45a3: Update dependencies: `@ankhorage/contracts`.
175
+ - 82fa552: Update dependencies: `@ankhorage/contracts`.
176
+ - 1633737: Update dependencies: `@ankhorage/contracts`.
177
+ - 46703cd: Update dependencies: `@ankhorage/contracts`, `@ankhorage/paradox`.
178
+ - 96f6fc5: Update dependencies: `@ankhorage/contracts`.
179
+ - cb6a3f7: Update dependencies: `@ankhorage/contracts`.
180
+ - b4a2d56: Update dependencies: `@ankhorage/contracts`.
181
+ - a9ba898: Update dependencies: `@ankhorage/contracts`.
182
+ - f4f3413: Update dependencies: `@ankhorage/contracts`.
183
+ - 2b9ed30: Update dependencies: `@ankhorage/contracts`.
184
+ - 0de28ba: Update dependencies: `@ankhorage/contracts`.
185
+ - 5d06e20: Update dependencies: `@ankhorage/contracts`.
186
+ - d2af64b: Update dependencies: `@ankhorage/contracts`.
187
+ - 7de76b9: Update dependencies: `@ankhorage/contracts`.
188
+ - 6750dd7: Update dependencies: `@ankhorage/contracts`.
189
+ - c464368: Update dependencies: `@ankhorage/contracts`.
190
+ - ae8d9dd: Update dependencies: `@ankhorage/contracts`.
191
+ - 32c5f85: Update dependencies: `@ankhorage/contracts`.
192
+ - 48cd629: Update dependencies: `@ankhorage/contracts`.
193
+ - c4539b8: Update dependencies: `@ankhorage/contracts`.
194
+ - 2545441: Update dependencies: `@ankhorage/contracts`.
195
+ - ce0461c: Update dependencies: `@ankhorage/contracts`.
196
+ - e5dca6d: Update dependencies: `@ankhorage/contracts`.
197
+
198
+ ## 1.0.20
199
+
200
+ ### Patch Changes
201
+
202
+ - a57b44e: Update Ankhorage dependencies: `@ankhorage/contracts`.
203
+
204
+ ## 1.0.19
205
+
206
+ ### Patch Changes
207
+
208
+ - 048b747: Update Ankhorage dependencies: `@ankhorage/contracts`.
209
+
210
+ ## 1.0.18
211
+
212
+ ### Patch Changes
213
+
214
+ - 1524240: Update Ankhorage dependencies: `@ankhorage/contracts`.
215
+
216
+ ## 1.0.17
217
+
218
+ ### Patch Changes
219
+
220
+ - dca9d9e: Update Ankhorage dependencies: `@ankhorage/contracts`.
221
+
222
+ ## 1.0.16
223
+
224
+ ### Patch Changes
225
+
226
+ - 2fc0b01: Update Ankhorage dependencies: `@ankhorage/contracts`.
227
+
228
+ ## 1.0.15
229
+
230
+ ### Patch Changes
231
+
232
+ - 15863e8: Update Ankhorage dependencies: `@ankhorage/contracts`.
233
+
234
+ ## 1.0.14
235
+
236
+ ### Patch Changes
237
+
238
+ - d7f85b4: Update Ankhorage dependencies: `@ankhorage/contracts`.
239
+
240
+ ## 1.0.13
241
+
242
+ ### Patch Changes
243
+
244
+ - 890f927: Update Ankhorage dependencies: `@ankhorage/contracts`.
245
+
246
+ ## 1.0.12
247
+
248
+ ### Patch Changes
249
+
250
+ - a8db26d: Update Ankhorage dependencies: `@ankhorage/contracts`.
251
+
252
+ ## 1.0.11
253
+
254
+ ### Patch Changes
255
+
256
+ - abe7e82: Update Ankhorage dependencies: `@ankhorage/contracts`.
257
+
258
+ ## 1.0.10
259
+
260
+ ### Patch Changes
261
+
262
+ - 1f22283: Update Ankhorage dependencies: `@ankhorage/contracts`.
263
+
264
+ ## 1.0.9
265
+
266
+ ### Patch Changes
267
+
268
+ - 9fc3c52: Update Ankhorage dependencies: `@ankhorage/contracts`.
269
+
270
+ ## 1.0.8
271
+
272
+ ### Patch Changes
273
+
274
+ - 8b34408: Update Ankhorage dependencies: `@ankhorage/contracts`.
275
+
276
+ ## 1.0.7
277
+
278
+ ### Patch Changes
279
+
280
+ - 2319745: Update Ankhorage dependencies: `@ankhorage/contracts`.
281
+
282
+ ## 1.0.6
283
+
284
+ ### Patch Changes
285
+
286
+ - cd3e0bf: Update Ankhorage dependencies: `@ankhorage/contracts`.
287
+ - c4e6c33: Update Ankhorage dependencies: `@ankhorage/contracts`.
288
+
289
+ ## 1.0.5
290
+
291
+ ### Patch Changes
292
+
293
+ - b9bd9c2: Update Ankhorage dependencies: `@ankhorage/contracts`.
294
+
295
+ ## 1.0.4
296
+
297
+ ### Patch Changes
298
+
299
+ - 383df35: Update Ankhorage dependencies: `@ankhorage/contracts`.
300
+ - e5ff046: Update Ankhorage dependencies: `@ankhorage/contracts`.
301
+
302
+ ## 1.0.3
303
+
304
+ ### Patch Changes
305
+
306
+ - 5c0d97e: Update Ankhorage dependencies: `@ankhorage/contracts`.
307
+
308
+ ## 1.0.2
309
+
310
+ ### Patch Changes
311
+
312
+ - fb8cbd4: Update Ankhorage dependencies: `@ankhorage/contracts`.
313
+
314
+ ## 1.0.1
315
+
316
+ ### Patch Changes
317
+
318
+ - 21cec50: Update Ankhorage dependencies: `@ankhorage/contracts`.
319
+
320
+ ## 1.0.0
321
+
322
+ ### Major Changes
323
+
324
+ - 15c9ed6: Move the public database adapter contract boundary from Contracts 2 to Contracts 4 so generated Runtime 1 database operations consume one canonical DbAdapter type surface.
325
+
326
+ ## 0.3.0
327
+
328
+ ### Minor Changes
329
+
330
+ - 8eff108: Align the Supabase database adapter with the canonical database realtime and admin/schema contracts from `@ankhorage/contracts/db`.
331
+
332
+ ### Patch Changes
333
+
334
+ - 3897e95: Fix CI pipeline
335
+
336
+ ## 0.2.1
337
+
338
+ ### Patch Changes
339
+
340
+ - Release trigger
341
+
342
+ ## 0.2.0
343
+
344
+ ### Minor Changes
345
+
346
+ - 8d13cfd: Implement the initial Supabase database adapter package with provider-neutral CRUD operations, optional realtime subscriptions, guarded schema/admin SQL generation, offline tests, README documentation, and agent rules.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ankhorage
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ <!-- markdownlint-disable MD013 MD033 -->
2
+ <!-- This file is generated by Paradox. Do not edit manually. -->
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ # @ankhorage/db-supabase
5
+
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v2.0.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: warnings](././paradox/badges/docs.svg)
7
+
8
+ Adapts Supabase Postgres to portable Ankhorage database contracts with CRUD, administration, query, and optional realtime behavior.
9
+
10
+ Provide a Supabase-backed database boundary without coupling consumers to provider-specific query and realtime details.
11
+
12
+ ## Documentation
13
+
14
+ Open `./paradox/index.html` locally in your browser to browse the complete documentation.
15
+
16
+ ## Contributors
17
+
18
+ <a href="https://github.com/artiphishle"><img src="https://avatars.githubusercontent.com/u/137318798?s=64" width="40" height="40" alt="artiphishle" /></a>
19
+
20
+ ## Donation
21
+
22
+ If this project is useful to you, you can support its continued development.
23
+
24
+ [Support @ankhorage](https://github.com/sponsors/ankhorage)
@@ -0,0 +1,3 @@
1
+ import type { SupabaseDbAdapter, SupabaseDbAdapterOptions } from './types.js';
2
+ export declare function createSupabaseDbAdapter(options: SupabaseDbAdapterOptions): SupabaseDbAdapter;
3
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAkB9E,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAW5F"}
@@ -0,0 +1,170 @@
1
+ import { createDbError, mapHttpError, mapNetworkError } from './errors.js';
2
+ import { buildMutationUrl, buildSelectUrl } from './query.js';
3
+ import { createRealtimeApi } from './realtime.js';
4
+ import { validateFilters, validateKey, validateUrl } from './validation.js';
5
+ export function createSupabaseDbAdapter(options) {
6
+ const config = normalizeConfig(options);
7
+ const baseAdapter = createBaseAdapter(config);
8
+ if (!config.realtime || config.realtimeClient === undefined)
9
+ return baseAdapter;
10
+ return {
11
+ ...baseAdapter,
12
+ realtime: createRealtimeApi({
13
+ client: config.realtimeClient,
14
+ defaultSchema: config.schema,
15
+ }),
16
+ };
17
+ }
18
+ function createBaseAdapter(config) {
19
+ return {
20
+ capabilities: {
21
+ transactions: false,
22
+ returning: true,
23
+ realtime: config.realtime && config.realtimeClient !== undefined,
24
+ },
25
+ select(input) {
26
+ return selectRows(config, input);
27
+ },
28
+ findById(input) {
29
+ return findRowById(config, input);
30
+ },
31
+ insert(input) {
32
+ return insertRows(config, input);
33
+ },
34
+ update(input) {
35
+ return updateRows(config, input);
36
+ },
37
+ delete(input) {
38
+ return deleteRows(config, input);
39
+ },
40
+ };
41
+ }
42
+ function deleteRows(config, input) {
43
+ const validationError = validateRequiredFilters(input.filters, 'Delete');
44
+ if (validationError !== null)
45
+ return Promise.resolve(validationError);
46
+ const url = buildMutationUrl(config.url, input.table, input.filters);
47
+ return requestRows(config, url, { method: 'DELETE' });
48
+ }
49
+ async function findRowById(config, input) {
50
+ const result = await requestRows(config, buildSelectUrl(config.url, {
51
+ table: input.table,
52
+ columns: input.columns,
53
+ filters: [{ field: input.idField ?? 'id', operator: 'eq', value: input.id }],
54
+ page: { limit: 1 },
55
+ schema: input.schema,
56
+ }), { method: 'GET' });
57
+ if (!result.ok)
58
+ return result;
59
+ const success = {
60
+ ok: true,
61
+ data: result.data[0] ?? null,
62
+ };
63
+ return success;
64
+ }
65
+ function insertRows(config, input) {
66
+ const url = buildMutationUrl(config.url, input.table, []);
67
+ return requestRows(config, url, {
68
+ method: 'POST',
69
+ body: JSON.stringify(input.values),
70
+ });
71
+ }
72
+ function normalizeConfig(options) {
73
+ const fetchImplementation = options.fetch ?? globalThis.fetch;
74
+ if (typeof fetchImplementation !== 'function') {
75
+ throw new TypeError('A fetch implementation is required to use Supabase Database.');
76
+ }
77
+ return {
78
+ url: validateUrl(options.url),
79
+ anonKey: validateKey(options.anonKey, 'Supabase anon key'),
80
+ schema: options.schema ?? 'public',
81
+ fetch: fetchImplementation,
82
+ realtime: options.realtime ?? false,
83
+ realtimeClient: options.realtimeClient,
84
+ };
85
+ }
86
+ async function requestRows(config, url, init) {
87
+ try {
88
+ const response = await config.fetch(url, {
89
+ ...init,
90
+ headers: createHeaders(config, init.headers),
91
+ });
92
+ const body = await readJsonBody(response);
93
+ if (!response.ok)
94
+ return { ok: false, error: mapHttpError(response.status, body) };
95
+ const records = normalizeRecords(body);
96
+ if (records === null) {
97
+ return {
98
+ ok: false,
99
+ error: createDbError('provider_error', 'Supabase Database returned an invalid records response.', body),
100
+ };
101
+ }
102
+ return { ok: true, data: records };
103
+ }
104
+ catch (error) {
105
+ if (error instanceof TypeError) {
106
+ return { ok: false, error: createDbError('validation_error', error.message, error) };
107
+ }
108
+ return { ok: false, error: mapNetworkError(error) };
109
+ }
110
+ }
111
+ function selectRows(config, input) {
112
+ return requestRows(config, buildSelectUrl(config.url, input), { method: 'GET' });
113
+ }
114
+ function updateRows(config, input) {
115
+ const validationError = validateRequiredFilters(input.filters, 'Update');
116
+ if (validationError !== null)
117
+ return Promise.resolve(validationError);
118
+ const url = buildMutationUrl(config.url, input.table, input.filters);
119
+ return requestRows(config, url, {
120
+ method: 'PATCH',
121
+ body: JSON.stringify(input.values),
122
+ });
123
+ }
124
+ function validateRequiredFilters(filters, label) {
125
+ try {
126
+ validateFilters(filters, label);
127
+ return null;
128
+ }
129
+ catch (error) {
130
+ return {
131
+ ok: false,
132
+ error: createDbError('validation_error', error instanceof Error ? error.message : `${label} filters are invalid.`, error),
133
+ };
134
+ }
135
+ }
136
+ function createHeaders(config, existingHeaders) {
137
+ const headers = new Headers(existingHeaders);
138
+ headers.set('apikey', config.anonKey);
139
+ headers.set('Authorization', `Bearer ${config.anonKey}`);
140
+ headers.set('Accept', 'application/json');
141
+ headers.set('Content-Type', 'application/json');
142
+ headers.set('Prefer', 'return=representation');
143
+ if (config.schema !== 'public') {
144
+ headers.set('Accept-Profile', config.schema);
145
+ headers.set('Content-Profile', config.schema);
146
+ }
147
+ return headers;
148
+ }
149
+ async function readJsonBody(response) {
150
+ const text = await response.text();
151
+ if (text.trim().length === 0)
152
+ return [];
153
+ try {
154
+ return JSON.parse(text);
155
+ }
156
+ catch {
157
+ return text;
158
+ }
159
+ }
160
+ function normalizeRecords(value) {
161
+ if (Array.isArray(value))
162
+ return value.filter((isRecord));
163
+ if (isRecord(value))
164
+ return [value];
165
+ return null;
166
+ }
167
+ function isRecord(value) {
168
+ return typeof value === 'object' && value !== null;
169
+ }
170
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"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BAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,QAAkB;IAC5C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAyB,KAAc;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAA,QAAiB,CAAA,CAAC,CAAC;IACjE,IAAI,QAAQ,CAAU,KAAK,CAAC;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAyB,KAAc;IACtD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC","sourcesContent":["import type {\n DbAdapter,\n DbDeleteInput,\n DbFilter,\n DbFindByIdInput,\n DbInsertInput,\n DbRecord,\n DbResult,\n DbSelectInput,\n DbUpdateInput,\n} from '@ankhorage/contracts/db';\n\nimport { createDbError, mapHttpError, mapNetworkError } from './errors.js';\nimport { buildMutationUrl, buildSelectUrl } from './query.js';\nimport { createRealtimeApi } from './realtime.js';\nimport type { SupabaseDbAdapter, SupabaseDbAdapterOptions } from './types.js';\nimport { validateFilters, validateKey, validateUrl } from './validation.js';\n\ninterface NormalizedConfig {\n readonly url: string;\n readonly anonKey: string;\n readonly schema: string;\n readonly fetch: typeof fetch;\n readonly realtime: boolean;\n readonly realtimeClient: SupabaseDbAdapterOptions['realtimeClient'];\n}\n\ntype DbFailureResult = Extract<DbResult<unknown>, { readonly ok: false }>;\ninterface DbFindByIdSuccessResult<TRecord extends object> {\n readonly ok: true;\n readonly data: TRecord | null;\n}\n\nexport function createSupabaseDbAdapter(options: SupabaseDbAdapterOptions): SupabaseDbAdapter {\n const config = normalizeConfig(options);\n const baseAdapter = createBaseAdapter(config);\n if (!config.realtime || config.realtimeClient === undefined) return baseAdapter;\n return {\n ...baseAdapter,\n realtime: createRealtimeApi({\n client: config.realtimeClient,\n defaultSchema: config.schema,\n }),\n };\n}\n\nfunction createBaseAdapter(config: NormalizedConfig): DbAdapter {\n return {\n capabilities: {\n transactions: false,\n returning: true,\n realtime: config.realtime && config.realtimeClient !== undefined,\n },\n select<TRecord extends object = DbRecord>(input: DbSelectInput) {\n return selectRows<TRecord>(config, input);\n },\n findById<TRecord extends object = DbRecord>(input: DbFindByIdInput) {\n return findRowById<TRecord>(config, input);\n },\n insert<TRecord extends object = DbRecord>(input: DbInsertInput<TRecord>) {\n return insertRows<TRecord>(config, input);\n },\n update<TRecord extends object = DbRecord>(input: DbUpdateInput<TRecord>) {\n return updateRows<TRecord>(config, input);\n },\n delete<TRecord extends object = DbRecord>(input: DbDeleteInput) {\n return deleteRows<TRecord>(config, input);\n },\n };\n}\n\nfunction deleteRows<TRecord extends object>(\n config: NormalizedConfig,\n input: DbDeleteInput,\n): Promise<DbResult<TRecord[]>> {\n const validationError = validateRequiredFilters(input.filters, 'Delete');\n if (validationError !== null) return Promise.resolve(validationError);\n const url = buildMutationUrl(config.url, input.table, input.filters);\n return requestRows<TRecord>(config, url, { method: 'DELETE' });\n}\n\nasync function findRowById<TRecord extends object>(\n config: NormalizedConfig,\n input: DbFindByIdInput,\n): Promise<DbResult<TRecord | null>> {\n const result = await requestRows<TRecord>(\n config,\n buildSelectUrl(config.url, {\n table: input.table,\n columns: input.columns,\n filters: [{ field: input.idField ?? 'id', operator: 'eq', value: input.id }],\n page: { limit: 1 },\n schema: input.schema,\n }),\n { method: 'GET' },\n );\n if (!result.ok) return result;\n const success: DbFindByIdSuccessResult<TRecord> = {\n ok: true,\n data: result.data[0] ?? null,\n };\n return success;\n}\n\nfunction insertRows<TRecord extends object>(\n config: NormalizedConfig,\n input: DbInsertInput<TRecord>,\n): Promise<DbResult<TRecord[]>> {\n const url = buildMutationUrl(config.url, input.table, []);\n return requestRows<TRecord>(config, url, {\n method: 'POST',\n body: JSON.stringify(input.values),\n });\n}\n\nfunction normalizeConfig(options: SupabaseDbAdapterOptions): NormalizedConfig {\n const fetchImplementation = options.fetch ?? globalThis.fetch;\n if (typeof fetchImplementation !== 'function') {\n throw new TypeError('A fetch implementation is required to use Supabase Database.');\n }\n return {\n url: validateUrl(options.url),\n anonKey: validateKey(options.anonKey, 'Supabase anon key'),\n schema: options.schema ?? 'public',\n fetch: fetchImplementation,\n realtime: options.realtime ?? false,\n realtimeClient: options.realtimeClient,\n };\n}\n\nasync function requestRows<TRecord extends object>(\n config: NormalizedConfig,\n url: URL,\n init: RequestInit,\n): Promise<DbResult<TRecord[]>> {\n try {\n const response = await config.fetch(url, {\n ...init,\n headers: createHeaders(config, init.headers),\n });\n const body = await readJsonBody(response);\n if (!response.ok) return { ok: false, error: mapHttpError(response.status, body) };\n const records = normalizeRecords<TRecord>(body);\n if (records === null) {\n return {\n ok: false,\n error: createDbError(\n 'provider_error',\n 'Supabase Database returned an invalid records response.',\n body,\n ),\n };\n }\n return { ok: true, data: records };\n } catch (error) {\n if (error instanceof TypeError) {\n return { ok: false, error: createDbError('validation_error', error.message, error) };\n }\n return { ok: false, error: mapNetworkError(error) };\n }\n}\n\nfunction selectRows<TRecord extends object>(\n config: NormalizedConfig,\n input: DbSelectInput,\n): Promise<DbResult<TRecord[]>> {\n return requestRows<TRecord>(config, buildSelectUrl(config.url, input), { method: 'GET' });\n}\n\nfunction updateRows<TRecord extends object>(\n config: NormalizedConfig,\n input: DbUpdateInput<TRecord>,\n): Promise<DbResult<TRecord[]>> {\n const validationError = validateRequiredFilters(input.filters, 'Update');\n if (validationError !== null) return Promise.resolve(validationError);\n const url = buildMutationUrl(config.url, input.table, input.filters);\n return requestRows<TRecord>(config, url, {\n method: 'PATCH',\n body: JSON.stringify(input.values),\n });\n}\n\nfunction validateRequiredFilters(\n filters: readonly DbFilter[],\n label: string,\n): DbFailureResult | null {\n try {\n validateFilters(filters, label);\n return null;\n } catch (error) {\n return {\n ok: false,\n error: createDbError(\n 'validation_error',\n error instanceof Error ? error.message : `${label} filters are invalid.`,\n error,\n ),\n };\n }\n}\n\nfunction createHeaders(\n config: NormalizedConfig,\n existingHeaders: HeadersInit | undefined,\n): Headers {\n const headers = new Headers(existingHeaders);\n headers.set('apikey', config.anonKey);\n headers.set('Authorization', `Bearer ${config.anonKey}`);\n headers.set('Accept', 'application/json');\n headers.set('Content-Type', 'application/json');\n headers.set('Prefer', 'return=representation');\n if (config.schema !== 'public') {\n headers.set('Accept-Profile', config.schema);\n headers.set('Content-Profile', config.schema);\n }\n return headers;\n}\n\nasync function readJsonBody(response: Response): Promise<unknown> {\n const text = await response.text();\n if (text.trim().length === 0) return [];\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction normalizeRecords<TRecord extends object>(value: unknown): TRecord[] | null {\n if (Array.isArray(value)) return value.filter(isRecord<TRecord>);\n if (isRecord<TRecord>(value)) return [value];\n return null;\n}\n\nfunction isRecord<TRecord extends object>(value: unknown): value is TRecord {\n return typeof value === 'object' && value !== null;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { DbAdminAdapter } from '@ankhorage/contracts/db';
2
+ import type { SupabaseDbAdminAdapterOptions } from './types.js';
3
+ export declare function createSupabaseDbAdminAdapter(options: SupabaseDbAdminAdapterOptions): DbAdminAdapter;
4
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../src/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAWhE,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,6BAA6B,GACrC,cAAc,CAqChB"}