@ankhorage/supabase-db 0.3.0 → 1.0.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +56 -196
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ankhorage/supabase-db
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 21cec50: Update Ankhorage dependencies: `@ankhorage/contracts`.
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - 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.
14
+
3
15
  ## 0.3.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -1,199 +1,59 @@
1
- <!-- markdownlint-disable MD013 -->
1
+ <!-- markdownlint-disable MD013 MD033 -->
2
+ <!-- This file is generated by Paradox. Do not edit manually. -->
2
3
 
3
4
  # @ankhorage/supabase-db
4
5
 
5
- Supabase database adapter for Ankhorage data contracts.
6
-
7
- `@ankhorage/supabase-db` implements Supabase-specific persistence behind the provider-neutral database interfaces from `@ankhorage/contracts/db`. Higher-level packages can use typed CRUD operations, optional realtime subscriptions, and guarded schema helpers without importing Supabase details into UI, runtime rendering, generated apps, or ZORA components.
8
-
9
- ## Install
10
-
11
- ```bash
12
- bun add @ankhorage/supabase-db @ankhorage/contracts
13
- ```
14
-
15
- Install `@supabase/supabase-js` as well when you want to pass a Supabase realtime client:
16
-
17
- ```bash
18
- bun add @supabase/supabase-js
19
- ```
20
-
21
- ## Boundaries
22
-
23
- This package owns Supabase Database behavior:
24
-
25
- - adapter creation
26
- - table select workflows
27
- - insert, update, and delete workflows
28
- - filter, order, and pagination mapping
29
- - provider error normalization
30
- - optional realtime change subscriptions
31
- - guarded schema SQL generation and privileged execution hooks
32
-
33
- This package does not own:
34
-
35
- - ZORA components or patterns
36
- - Studio UI
37
- - runtime manifest interpretation
38
- - generated routes or layouts
39
- - CLI generation
40
- - deployment orchestration
41
- - auth or storage adapters
42
-
43
- ## Runtime CRUD adapter
44
-
45
- Use the runtime adapter with client-safe Supabase credentials. The adapter speaks the canonical `DbAdapter` shape from `@ankhorage/contracts/db`.
46
-
47
- ```ts
48
- import { createSupabaseDbAdapter } from '@ankhorage/supabase-db';
49
-
50
- const db = createSupabaseDbAdapter({
51
- url: process.env.SUPABASE_URL ?? '',
52
- anonKey: process.env.SUPABASE_ANON_KEY ?? '',
53
- });
54
-
55
- const posts = await db.select({
56
- table: 'posts',
57
- columns: ['id', 'title', 'created_at'],
58
- filters: [{ field: 'published', operator: 'eq', value: true }],
59
- sort: [{ field: 'created_at', direction: 'desc' }],
60
- page: { limit: 20 },
61
- });
62
-
63
- if (posts.ok) {
64
- console.log(posts.data);
65
- }
66
- ```
67
-
68
- The runtime adapter uses Supabase PostgREST endpoints and returns normalized `DbResult` values. Expected provider failures, permission errors, missing tables, and invalid queries are returned as stable adapter errors instead of raw Supabase response objects.
69
-
70
- ## Supported CRUD operations
71
-
72
- The adapter implements:
73
-
74
- - `select`
75
- - `findById`
76
- - `insert`
77
- - `update`
78
- - `delete`
79
-
80
- `update` and `delete` require at least one filter to avoid accidental whole-table mutations.
81
-
82
- ## Capabilities
83
-
84
- The adapter exposes the canonical `DbAdapterCapabilities` contract:
85
-
86
- ```ts
87
- const capabilities = db.capabilities;
88
-
89
- console.log(capabilities.transactions); // false
90
- console.log(capabilities.returning); // true
91
- console.log(capabilities.realtime); // true only when realtime is enabled and configured
92
- ```
93
-
94
- ## Realtime
95
-
96
- Realtime is optional. It is exposed through the canonical `DbRealtimeAdapter` contract only when enabled and configured.
97
-
98
- ```ts
99
- import { createClient } from '@supabase/supabase-js';
100
- import { createSupabaseDbAdapter } from '@ankhorage/supabase-db';
101
-
102
- const supabase = createClient(process.env.SUPABASE_URL ?? '', process.env.SUPABASE_ANON_KEY ?? '');
103
-
104
- const db = createSupabaseDbAdapter({
105
- url: process.env.SUPABASE_URL ?? '',
106
- anonKey: process.env.SUPABASE_ANON_KEY ?? '',
107
- realtime: true,
108
- realtimeClient: supabase,
109
- });
110
-
111
- const subscription = db.realtime?.subscribeToCollection({ table: 'posts' }, (event) => {
112
- console.log(event.kind, event.record, event.previousRecord);
113
- });
114
-
115
- await subscription?.unsubscribe();
116
- ```
117
-
118
- Realtime events are normalized to provider-neutral kinds:
119
-
120
- - `insert`
121
- - `update`
122
- - `delete`
123
-
124
- Supabase projects must have database change replication configured for realtime table events. If realtime is not enabled or no realtime client is provided, CRUD still works and `capabilities.realtime` is `false`.
125
-
126
- ## Admin/schema adapter
127
-
128
- Schema operations are privileged and separate from runtime CRUD. The admin adapter implements the canonical `DbAdminAdapter` contract from `@ankhorage/contracts/db`.
129
-
130
- By default, the admin adapter generates SQL only:
131
-
132
- ```ts
133
- import { createSupabaseDbAdminAdapter } from '@ankhorage/supabase-db';
134
-
135
- const admin = createSupabaseDbAdminAdapter({
136
- url: process.env.SUPABASE_URL ?? '',
137
- serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
138
- });
139
-
140
- const plan = admin.generateCreateCollectionSql({
141
- name: 'posts',
142
- fields: [
143
- { name: 'title', type: 'text', required: true },
144
- { name: 'body', type: 'text' },
145
- { name: 'created_at', type: 'datetime' },
146
- ],
147
- });
148
-
149
- if (plan.ok) {
150
- console.log(plan.sql);
151
- }
152
- ```
153
-
154
- Direct execution requires all of the following:
155
-
156
- - `execute: true`
157
- - a `serviceRoleKey`
158
- - an injected `executeSql(sql)` callback from a privileged environment
159
-
160
- ```ts
161
- const admin = createSupabaseDbAdminAdapter({
162
- url: process.env.SUPABASE_URL ?? '',
163
- serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
164
- execute: true,
165
- executeSql: async (sql) => {
166
- // Run SQL through a trusted backend, migration runner, or RPC you control.
167
- return { ok: true };
168
- },
169
- });
170
- ```
171
-
172
- > Do not use service-role credentials in client/runtime code.
173
-
174
- The admin adapter is intended for trusted Studio backends, CLI tooling, deployment tooling, or migration workflows. It must not be bundled into generated client screens.
175
-
176
- ## Data binding architecture
177
-
178
- A future app flow should look like this:
179
-
180
- ```txt
181
- Studio creates a collection definition
182
- -> privileged adapter generates or applies schema
183
- Runtime queries rows through DbAdapter
184
- -> runtime maps row fields to component props
185
- ZORA renders presentational patterns only
186
- ```
187
-
188
- For example, a future ZORA `PostCard` should receive props. It should not import Supabase or this package.
189
-
190
- ## Development
191
-
192
- ```bash
193
- bun install
194
- bun run build
195
- bun run lint:fix
196
- bun run test
197
- ```
198
-
199
- Tests are mocked and must not call real Supabase services.
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.3.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: checked](././paradox/badges/tests.svg) ![docs: paradox](././paradox/badges/docs.svg)
7
+
8
+ Provider-neutral Supabase database adapter exposing typed CRUD, schema management, and realtime subscriptions.
9
+
10
+ ## Generated documentation
11
+
12
+ - [Interactive documentation app](././paradox/index.html)
13
+ - [Public API reference](././paradox/exports.md)
14
+ - [Component registry](././paradox/components.md)
15
+ - [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
16
+ - [Module relationships](././paradox/diagrams/module-relationships.mmd)
17
+ - [Export graph](././paradox/diagrams/export-graph.mmd)
18
+ - [createSupabaseDbAdapter sequence](././paradox/diagrams/sequences/create-supabase-db-adapter.mmd)
19
+ - [createSupabaseDbAdminAdapter sequence](././paradox/diagrams/sequences/create-supabase-db-admin-adapter.mmd)
20
+ - [normalizeRealtimeEvent sequence](././paradox/diagrams/sequences/normalize-realtime-event.mmd)
21
+
22
+ ## Architecture preview
23
+
24
+ <details>
25
+ <summary>Architecture overview</summary>
26
+
27
+ ```mermaid
28
+ graph TD
29
+ package__ankhorage_supabase_db["@ankhorage/supabase-db"]
30
+ entrypoint_src_index_ts["src/index.ts"]
31
+ package__ankhorage_supabase_db --> entrypoint_src_index_ts
32
+ module_src_adapter_ts["src/adapter.ts"]
33
+ package__ankhorage_supabase_db -.-> module_src_adapter_ts
34
+ module_src_adapter_ts --> module_src_errors_ts
35
+ module_src_adapter_ts --> module_src_query_ts
36
+ module_src_adapter_ts --> module_src_realtime_ts
37
+ module_src_adapter_ts --> module_src_types_ts
38
+ module_src_adapter_ts --> module_src_validation_ts
39
+ module_src_admin_ts["src/admin.ts"]
40
+ package__ankhorage_supabase_db -.-> module_src_admin_ts
41
+ module_src_admin_ts --> module_src_types_ts
42
+ module_src_admin_ts --> module_src_validation_ts
43
+ module_src_errors_ts["src/errors.ts"]
44
+ package__ankhorage_supabase_db -.-> module_src_errors_ts
45
+ module_src_index_ts["src/index.ts"]
46
+ module_src_query_ts["src/query.ts"]
47
+ package__ankhorage_supabase_db -.-> module_src_query_ts
48
+ module_src_query_ts --> module_src_validation_ts
49
+ module_src_realtime_ts["src/realtime.ts"]
50
+ package__ankhorage_supabase_db -.-> module_src_realtime_ts
51
+ module_src_realtime_ts --> module_src_types_ts
52
+ module_src_realtime_ts --> module_src_validation_ts
53
+ module_src_types_ts["src/types.ts"]
54
+ package__ankhorage_supabase_db -.-> module_src_types_ts
55
+ module_src_validation_ts["src/validation.ts"]
56
+ package__ankhorage_supabase_db -.-> module_src_validation_ts
57
+ ```
58
+
59
+ </details>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ankhorage/supabase-db",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "1.0.1",
5
5
  "description": "Supabase database adapter for Ankhorage contracts with CRUD, schema management, and optional realtime support.",
6
6
  "homepage": "https://github.com/ankhorage/supabase-db#readme",
7
7
  "bugs": {
@@ -25,7 +25,7 @@
25
25
  "adapter"
26
26
  ],
27
27
  "dependencies": {
28
- "@ankhorage/contracts": "^1.3.0"
28
+ "@ankhorage/contracts": "^8.0.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@supabase/supabase-js": "^2.105.3"