@intentsolutionsio/supabase-pack 1.0.0 → 1.0.3
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/LICENSE +1 -1
- package/README.md +73 -47
- package/package.json +4 -4
- package/skills/supabase-advanced-troubleshooting/SKILL.md +404 -200
- package/skills/supabase-advanced-troubleshooting/references/errors.md +11 -0
- package/skills/supabase-advanced-troubleshooting/references/evidence-collection-framework.md +34 -0
- package/skills/supabase-advanced-troubleshooting/references/examples.md +11 -0
- package/skills/supabase-advanced-troubleshooting/references/rls-edge-functions-realtime.md +363 -0
- package/skills/supabase-advanced-troubleshooting/references/systematic-isolation.md +56 -0
- package/skills/supabase-advanced-troubleshooting/references/timing-analysis.md +35 -0
- package/skills/supabase-architecture-variants/SKILL.md +395 -216
- package/skills/supabase-architecture-variants/references/errors.md +11 -0
- package/skills/supabase-architecture-variants/references/examples.md +12 -0
- package/skills/supabase-architecture-variants/references/serverless-and-multi-tenant.md +251 -0
- package/skills/supabase-architecture-variants/references/variant-a-monolith-(simple).md +44 -0
- package/skills/supabase-architecture-variants/references/variant-b-service-layer-(moderate).md +72 -0
- package/skills/supabase-architecture-variants/references/variant-c-microservice-(complex).md +81 -0
- package/skills/supabase-auth-storage-realtime-core/SKILL.md +471 -37
- package/skills/supabase-ci-integration/SKILL.md +315 -67
- package/skills/supabase-ci-integration/references/errors.md +10 -0
- package/skills/supabase-ci-integration/references/examples.md +36 -0
- package/skills/supabase-ci-integration/references/implementation.md +54 -0
- package/skills/supabase-common-errors/SKILL.md +320 -62
- package/skills/supabase-common-errors/references/errors.md +53 -0
- package/skills/supabase-common-errors/references/examples.md +23 -0
- package/skills/supabase-cost-tuning/SKILL.md +365 -131
- package/skills/supabase-cost-tuning/references/cost-estimation.md +34 -0
- package/skills/supabase-cost-tuning/references/cost-reduction-strategies.md +40 -0
- package/skills/supabase-cost-tuning/references/errors.md +11 -0
- package/skills/supabase-cost-tuning/references/examples.md +15 -0
- package/skills/supabase-data-handling/SKILL.md +378 -145
- package/skills/supabase-data-handling/references/errors.md +11 -0
- package/skills/supabase-data-handling/references/examples.md +27 -0
- package/skills/supabase-data-handling/references/implementation.md +223 -0
- package/skills/supabase-data-handling/references/retention-and-backup.md +221 -0
- package/skills/supabase-debug-bundle/SKILL.md +267 -73
- package/skills/supabase-debug-bundle/references/errors.md +12 -0
- package/skills/supabase-debug-bundle/references/examples.md +24 -0
- package/skills/supabase-debug-bundle/references/implementation.md +54 -0
- package/skills/supabase-deploy-integration/SKILL.md +258 -147
- package/skills/supabase-deploy-integration/references/errors.md +11 -0
- package/skills/supabase-deploy-integration/references/examples.md +21 -0
- package/skills/supabase-deploy-integration/references/google-cloud-run.md +36 -0
- package/skills/supabase-deploy-integration/references/vercel-deployment.md +35 -0
- package/skills/supabase-enterprise-rbac/SKILL.md +327 -160
- package/skills/supabase-enterprise-rbac/references/api-scoping-and-enforcement.md +255 -0
- package/skills/supabase-enterprise-rbac/references/errors.md +11 -0
- package/skills/supabase-enterprise-rbac/references/examples.md +12 -0
- package/skills/supabase-enterprise-rbac/references/role-implementation.md +33 -0
- package/skills/supabase-enterprise-rbac/references/sso-integration.md +35 -0
- package/skills/supabase-hello-world/SKILL.md +160 -54
- package/skills/supabase-incident-runbook/SKILL.md +453 -131
- package/skills/supabase-incident-runbook/references/errors.md +11 -0
- package/skills/supabase-incident-runbook/references/examples.md +10 -0
- package/skills/supabase-incident-runbook/references/immediate-actions-by-error-type.md +41 -0
- package/skills/supabase-install-auth/SKILL.md +186 -50
- package/skills/supabase-install-auth/references/examples.md +102 -0
- package/skills/supabase-known-pitfalls/SKILL.md +411 -241
- package/skills/supabase-known-pitfalls/references/errors.md +11 -0
- package/skills/supabase-known-pitfalls/references/examples.md +12 -0
- package/skills/supabase-load-scale/SKILL.md +346 -217
- package/skills/supabase-load-scale/references/capacity-planning.md +47 -0
- package/skills/supabase-load-scale/references/errors.md +11 -0
- package/skills/supabase-load-scale/references/examples.md +26 -0
- package/skills/supabase-load-scale/references/load-testing-with-k6.md +59 -0
- package/skills/supabase-load-scale/references/scaling-patterns.md +65 -0
- package/skills/supabase-load-scale/references/table-partitioning.md +263 -0
- package/skills/supabase-local-dev-loop/SKILL.md +272 -73
- package/skills/supabase-local-dev-loop/references/errors.md +11 -0
- package/skills/supabase-local-dev-loop/references/examples.md +21 -0
- package/skills/supabase-local-dev-loop/references/implementation.md +60 -0
- package/skills/supabase-migration-deep-dive/SKILL.md +338 -177
- package/skills/supabase-migration-deep-dive/references/backfill-versioning-rollback.md +258 -0
- package/skills/supabase-migration-deep-dive/references/errors.md +11 -0
- package/skills/supabase-migration-deep-dive/references/examples.md +12 -0
- package/skills/supabase-migration-deep-dive/references/implementation-plan.md +80 -0
- package/skills/supabase-migration-deep-dive/references/pre-migration-assessment.md +39 -0
- package/skills/supabase-multi-env-setup/SKILL.md +393 -152
- package/skills/supabase-multi-env-setup/references/configuration-structure.md +59 -0
- package/skills/supabase-multi-env-setup/references/errors.md +11 -0
- package/skills/supabase-multi-env-setup/references/examples.md +11 -0
- package/skills/supabase-observability/SKILL.md +318 -196
- package/skills/supabase-observability/references/alert-configuration.md +40 -0
- package/skills/supabase-observability/references/errors.md +11 -0
- package/skills/supabase-observability/references/examples.md +13 -0
- package/skills/supabase-observability/references/metrics-collection.md +65 -0
- package/skills/supabase-performance-tuning/SKILL.md +304 -160
- package/skills/supabase-performance-tuning/references/caching-strategy.md +49 -0
- package/skills/supabase-performance-tuning/references/errors.md +11 -0
- package/skills/supabase-performance-tuning/references/examples.md +13 -0
- package/skills/supabase-policy-guardrails/SKILL.md +248 -221
- package/skills/supabase-policy-guardrails/references/ci-cost-security.md +484 -0
- package/skills/supabase-policy-guardrails/references/errors.md +11 -0
- package/skills/supabase-policy-guardrails/references/eslint-rules.md +46 -0
- package/skills/supabase-policy-guardrails/references/examples.md +10 -0
- package/skills/supabase-prod-checklist/SKILL.md +474 -84
- package/skills/supabase-prod-checklist/references/errors.md +63 -0
- package/skills/supabase-prod-checklist/references/examples.md +153 -0
- package/skills/supabase-prod-checklist/references/implementation.md +113 -0
- package/skills/supabase-rate-limits/SKILL.md +311 -98
- package/skills/supabase-rate-limits/references/errors.md +11 -0
- package/skills/supabase-rate-limits/references/examples.md +46 -0
- package/skills/supabase-rate-limits/references/implementation.md +66 -0
- package/skills/supabase-reference-architecture/SKILL.md +249 -182
- package/skills/supabase-reference-architecture/references/errors.md +29 -0
- package/skills/supabase-reference-architecture/references/examples.md +116 -0
- package/skills/supabase-reference-architecture/references/key-components.md +244 -0
- package/skills/supabase-reference-architecture/references/project-structure.md +109 -0
- package/skills/supabase-reliability-patterns/SKILL.md +229 -234
- package/skills/supabase-reliability-patterns/references/circuit-breaker.md +36 -0
- package/skills/supabase-reliability-patterns/references/dead-letter-queue.md +48 -0
- package/skills/supabase-reliability-patterns/references/errors.md +11 -0
- package/skills/supabase-reliability-patterns/references/examples.md +11 -0
- package/skills/supabase-reliability-patterns/references/idempotency-keys.md +36 -0
- package/skills/supabase-reliability-patterns/references/offline-degradation-health-dualwrite.md +489 -0
- package/skills/supabase-schema-from-requirements/SKILL.md +373 -34
- package/skills/supabase-sdk-patterns/SKILL.md +388 -99
- package/skills/supabase-sdk-patterns/references/errors.md +11 -0
- package/skills/supabase-sdk-patterns/references/examples.md +45 -0
- package/skills/supabase-sdk-patterns/references/implementation.md +67 -0
- package/skills/supabase-security-basics/SKILL.md +282 -102
- package/skills/supabase-security-basics/references/errors.md +10 -0
- package/skills/supabase-security-basics/references/examples.md +70 -0
- package/skills/supabase-security-basics/references/implementation.md +39 -0
- package/skills/supabase-upgrade-migration/SKILL.md +248 -66
- package/skills/supabase-upgrade-migration/references/errors.md +10 -0
- package/skills/supabase-upgrade-migration/references/examples.md +51 -0
- package/skills/supabase-upgrade-migration/references/implementation.md +29 -0
- package/skills/supabase-webhooks-events/SKILL.md +412 -138
- package/skills/supabase-webhooks-events/references/errors.md +55 -0
- package/skills/supabase-webhooks-events/references/event-handler-pattern.md +106 -0
- package/skills/supabase-webhooks-events/references/examples.md +133 -0
- package/skills/supabase-webhooks-events/references/signature-verification.md +165 -0
|
@@ -1,117 +1,316 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: supabase-local-dev-loop
|
|
3
|
-
description:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
description: 'Configure Supabase local development with the CLI, Docker, and migration
|
|
4
|
+
workflow.
|
|
5
|
+
|
|
6
|
+
Use when initializing a Supabase project locally, starting the local stack,
|
|
7
|
+
|
|
8
|
+
writing migrations, seeding data, or iterating on schema changes.
|
|
9
|
+
|
|
10
|
+
Trigger with phrases like "supabase local dev", "supabase start",
|
|
11
|
+
|
|
12
|
+
"supabase init", "supabase db reset", "supabase local setup".
|
|
13
|
+
|
|
14
|
+
'
|
|
15
|
+
allowed-tools: Read, Write, Edit, Bash(npx:*), Bash(supabase:*), Bash(docker:*), Bash(curl:*),
|
|
16
|
+
Grep
|
|
10
17
|
version: 1.0.0
|
|
11
18
|
license: MIT
|
|
12
19
|
author: Jeremy Longshore <jeremy@intentsolutions.io>
|
|
20
|
+
tags:
|
|
21
|
+
- saas
|
|
22
|
+
- supabase
|
|
23
|
+
- local-development
|
|
24
|
+
- docker
|
|
25
|
+
- postgres
|
|
26
|
+
compatibility: Designed for Claude Code
|
|
13
27
|
---
|
|
14
|
-
|
|
15
28
|
# Supabase Local Dev Loop
|
|
16
29
|
|
|
17
30
|
## Overview
|
|
18
|
-
|
|
31
|
+
|
|
32
|
+
Run the full Supabase stack locally — Postgres, Auth, Storage, Realtime, Edge Functions, and Studio — using Docker and the Supabase CLI. Local development mirrors production APIs exactly, enabling offline work, fast iteration, and repeatable migration workflows. Schema changes flow through `supabase db diff` to generate migrations, and `supabase db reset` replays them cleanly.
|
|
19
33
|
|
|
20
34
|
## Prerequisites
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
35
|
+
|
|
36
|
+
- Docker Desktop installed and running (required for all local services)
|
|
37
|
+
- Node.js 18+ (for `npx supabase` commands)
|
|
38
|
+
- No global install needed — all commands use `npx supabase`
|
|
25
39
|
|
|
26
40
|
## Instructions
|
|
27
41
|
|
|
28
|
-
### Step 1:
|
|
42
|
+
### Step 1: Initialize Project and Start Local Stack
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Initialize Supabase in your project root
|
|
46
|
+
npx supabase init
|
|
29
47
|
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
│ └── supabase.test.ts
|
|
39
|
-
├── .env.local # Local secrets (git-ignored)
|
|
40
|
-
├── .env.example # Template for team
|
|
41
|
-
└── package.json
|
|
48
|
+
|
|
49
|
+
This creates a `supabase/` directory:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
supabase/
|
|
53
|
+
├── config.toml # Local stack configuration (ports, auth settings)
|
|
54
|
+
├── migrations/ # SQL migration files (version-controlled)
|
|
55
|
+
└── seed.sql # Seed data (runs after migrations on db reset)
|
|
42
56
|
```
|
|
43
57
|
|
|
44
|
-
|
|
58
|
+
Start the local stack (first run pulls Docker images — takes a few minutes):
|
|
59
|
+
|
|
45
60
|
```bash
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
npx supabase start
|
|
62
|
+
```
|
|
48
63
|
|
|
49
|
-
|
|
50
|
-
npm install
|
|
64
|
+
The CLI prints all local endpoints and keys:
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
```
|
|
67
|
+
API URL: http://localhost:54321
|
|
68
|
+
GraphQL URL: http://localhost:54321/graphql/v1
|
|
69
|
+
S3 Storage URL: http://localhost:54321/storage/v1/s3
|
|
70
|
+
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
|
|
71
|
+
Studio URL: http://localhost:54323
|
|
72
|
+
Inbucket URL: http://localhost:54324
|
|
73
|
+
anon key: eyJhbGciOiJI...
|
|
74
|
+
service_role key: eyJhbGciOiJI...
|
|
54
75
|
```
|
|
55
76
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
77
|
+
Create `.env.local` from these values (git-ignored):
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
# .env.local
|
|
81
|
+
SUPABASE_URL=http://localhost:54321
|
|
82
|
+
SUPABASE_ANON_KEY=<anon-key-from-supabase-start>
|
|
83
|
+
SUPABASE_SERVICE_ROLE_KEY=<service-role-key-from-supabase-start>
|
|
84
|
+
DATABASE_URL=postgresql://postgres:postgres@localhost:54322/postgres
|
|
65
85
|
```
|
|
66
86
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
Verify the stack is running:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx supabase status
|
|
91
|
+
```
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
93
|
+
### Step 2: Create Migrations and Seed Data
|
|
94
|
+
|
|
95
|
+
Create a migration file with a descriptive name:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx supabase migration new create_profiles
|
|
99
|
+
# Creates: supabase/migrations/<timestamp>_create_profiles.sql
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Write the migration SQL:
|
|
103
|
+
|
|
104
|
+
```sql
|
|
105
|
+
-- supabase/migrations/<timestamp>_create_profiles.sql
|
|
106
|
+
create table public.profiles (
|
|
107
|
+
id uuid references auth.users(id) primary key,
|
|
108
|
+
username text unique not null,
|
|
109
|
+
avatar_url text,
|
|
110
|
+
created_at timestamptz default now(),
|
|
111
|
+
updated_at timestamptz default now()
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
-- Always enable RLS on public tables
|
|
115
|
+
alter table public.profiles enable row level security;
|
|
116
|
+
|
|
117
|
+
create policy "Public profiles are viewable by everyone"
|
|
118
|
+
on public.profiles for select
|
|
119
|
+
using (true);
|
|
120
|
+
|
|
121
|
+
create policy "Users can update own profile"
|
|
122
|
+
on public.profiles for update
|
|
123
|
+
using (auth.uid() = id);
|
|
124
|
+
|
|
125
|
+
-- Auto-create profile on signup via trigger
|
|
126
|
+
create or replace function public.handle_new_user()
|
|
127
|
+
returns trigger as $$
|
|
128
|
+
begin
|
|
129
|
+
insert into public.profiles (id, username)
|
|
130
|
+
values (new.id, new.raw_user_meta_data->>'username');
|
|
131
|
+
return new;
|
|
132
|
+
end;
|
|
133
|
+
$$ language plpgsql security definer;
|
|
134
|
+
|
|
135
|
+
create trigger on_auth_user_created
|
|
136
|
+
after insert on auth.users
|
|
137
|
+
for each row execute procedure public.handle_new_user();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Add seed data for local development:
|
|
141
|
+
|
|
142
|
+
```sql
|
|
143
|
+
-- supabase/seed.sql (runs automatically after migrations on db reset)
|
|
144
|
+
insert into auth.users (id, email, raw_user_meta_data)
|
|
145
|
+
values
|
|
146
|
+
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'alice@example.com',
|
|
147
|
+
'{"username": "alice"}'),
|
|
148
|
+
('b2c3d4e5-f6a7-8901-bcde-f12345678901', 'bob@example.com',
|
|
149
|
+
'{"username": "bob"}');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Apply migrations and seed data in one command:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npx supabase db reset
|
|
156
|
+
# Drops the database, replays all migrations, runs seed.sql
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Step 3: Iterate with Diff-Based Migrations
|
|
160
|
+
|
|
161
|
+
The core iteration loop: make changes in Studio, diff them into migration files, then verify with a clean reset.
|
|
162
|
+
|
|
163
|
+
Open Studio at `http://localhost:54323` and make schema changes interactively (add columns, create tables, modify RLS policies). Then capture those changes as a migration:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Generate a migration from the diff between migrations and current DB state
|
|
167
|
+
npx supabase db diff -f add_bio_to_profiles
|
|
168
|
+
|
|
169
|
+
# Review the generated file
|
|
170
|
+
cat supabase/migrations/*_add_bio_to_profiles.sql
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The generated migration captures exactly what changed:
|
|
174
|
+
|
|
175
|
+
```sql
|
|
176
|
+
-- Auto-generated by supabase db diff
|
|
177
|
+
alter table public.profiles add column bio text;
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Verify the full migration chain replays cleanly:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
npx supabase db reset
|
|
184
|
+
# Success = all migrations + seed apply without errors
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Push verified migrations to a remote Supabase project:
|
|
188
|
+
|
|
189
|
+
```text
|
|
190
|
+
# Link to remote project first (one-time)
|
|
191
|
+
npx supabase link --project-ref <your-project-ref>
|
|
192
|
+
|
|
193
|
+
# Push migrations to remote
|
|
194
|
+
npx supabase db push
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Daily workflow summary:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Start of day
|
|
201
|
+
npx supabase start
|
|
202
|
+
|
|
203
|
+
# After schema changes in Studio
|
|
204
|
+
npx supabase db diff -f descriptive_name
|
|
205
|
+
npx supabase db reset # Verify clean replay
|
|
206
|
+
|
|
207
|
+
# Before committing
|
|
208
|
+
npx supabase db reset # Final verification
|
|
209
|
+
npm test # Run tests against local instance
|
|
210
|
+
|
|
211
|
+
# End of day
|
|
212
|
+
npx supabase stop
|
|
78
213
|
```
|
|
79
214
|
|
|
80
215
|
## Output
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
216
|
+
|
|
217
|
+
- Local Supabase stack running all services via Docker (Postgres, Auth, Storage, Realtime, Studio)
|
|
218
|
+
- Version-controlled migration files in `supabase/migrations/`
|
|
219
|
+
- Seed data for repeatable local state
|
|
220
|
+
- Diff-based migration workflow for safe schema iteration
|
|
221
|
+
- `.env.local` with local connection credentials
|
|
85
222
|
|
|
86
223
|
## Error Handling
|
|
224
|
+
|
|
87
225
|
| Error | Cause | Solution |
|
|
88
226
|
|-------|-------|----------|
|
|
89
|
-
|
|
|
90
|
-
| Port in use |
|
|
91
|
-
|
|
|
92
|
-
|
|
|
227
|
+
| `Cannot connect to Docker daemon` | Docker not running | Start Docker Desktop, then retry `npx supabase start` |
|
|
228
|
+
| `Port 54321 already in use` | Previous instance still running | Run `npx supabase stop` then `npx supabase start` |
|
|
229
|
+
| `supabase db reset` fails | Syntax error in migration SQL | Check the failing migration file, fix SQL, re-run reset |
|
|
230
|
+
| `Permission denied` on start | Docker socket permissions | Add user to `docker` group: `sudo usermod -aG docker $USER` |
|
|
231
|
+
| `supabase db diff` empty | No schema changes detected | Verify changes were made in the local DB, not just Studio UI cache |
|
|
232
|
+
| `relation "auth.users" does not exist` | Running migration outside Supabase | Auth schema only exists in the Supabase-managed Postgres instance |
|
|
93
233
|
|
|
94
234
|
## Examples
|
|
95
235
|
|
|
96
|
-
###
|
|
236
|
+
### Connect from Application Code
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { createClient } from '@supabase/supabase-js'
|
|
240
|
+
|
|
241
|
+
const supabase = createClient(
|
|
242
|
+
process.env.SUPABASE_URL!, // http://localhost:54321 locally
|
|
243
|
+
process.env.SUPABASE_ANON_KEY! // Local anon key from supabase start
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
// Fetch profiles — works identically in local and production
|
|
247
|
+
const { data, error } = await supabase
|
|
248
|
+
.from('profiles')
|
|
249
|
+
.select('username, avatar_url')
|
|
250
|
+
.limit(10)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Test Against Local Instance with Vitest
|
|
254
|
+
|
|
97
255
|
```typescript
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
256
|
+
import { createClient } from '@supabase/supabase-js'
|
|
257
|
+
import { describe, it, expect, beforeAll } from 'vitest'
|
|
258
|
+
|
|
259
|
+
const supabase = createClient(
|
|
260
|
+
'http://localhost:54321',
|
|
261
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' // Local anon key
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
describe('profiles', () => {
|
|
265
|
+
beforeAll(async () => {
|
|
266
|
+
// Seed data is already loaded via supabase db reset
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it('fetches public profiles', async () => {
|
|
270
|
+
const { data, error } = await supabase
|
|
271
|
+
.from('profiles')
|
|
272
|
+
.select('username')
|
|
273
|
+
.limit(1)
|
|
274
|
+
|
|
275
|
+
expect(error).toBeNull()
|
|
276
|
+
expect(data).toHaveLength(1)
|
|
277
|
+
expect(data![0].username).toBeDefined()
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
it('enforces RLS on update', async () => {
|
|
281
|
+
// Anon users cannot update profiles (no auth.uid())
|
|
282
|
+
const { error } = await supabase
|
|
283
|
+
.from('profiles')
|
|
284
|
+
.update({ username: 'hacker' })
|
|
285
|
+
.eq('username', 'alice')
|
|
286
|
+
|
|
287
|
+
expect(error).not.toBeNull()
|
|
288
|
+
})
|
|
289
|
+
})
|
|
103
290
|
```
|
|
104
291
|
|
|
105
|
-
###
|
|
292
|
+
### Edge Function Local Development
|
|
293
|
+
|
|
106
294
|
```bash
|
|
107
|
-
#
|
|
108
|
-
|
|
295
|
+
# Create and serve an Edge Function with hot reload
|
|
296
|
+
npx supabase functions new hello-world
|
|
297
|
+
npx supabase functions serve --env-file .env.local
|
|
298
|
+
|
|
299
|
+
# Test it
|
|
300
|
+
curl -X POST http://localhost:54321/functions/v1/hello-world \
|
|
301
|
+
-H "Authorization: Bearer $SUPABASE_ANON_KEY" \
|
|
302
|
+
-H "Content-Type: application/json" \
|
|
303
|
+
-d '{"name": "World"}'
|
|
109
304
|
```
|
|
110
305
|
|
|
111
306
|
## Resources
|
|
112
|
-
|
|
113
|
-
- [
|
|
114
|
-
- [
|
|
307
|
+
|
|
308
|
+
- [Local Development Overview](https://supabase.com/docs/guides/local-development/overview)
|
|
309
|
+
- [Supabase CLI Reference](https://supabase.com/docs/reference/cli/introduction)
|
|
310
|
+
- [Database Migrations](https://supabase.com/docs/guides/deployment/database-migrations)
|
|
311
|
+
- [Edge Functions Quickstart](https://supabase.com/docs/guides/functions/quickstart)
|
|
312
|
+
- [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
|
|
115
313
|
|
|
116
314
|
## Next Steps
|
|
117
|
-
|
|
315
|
+
|
|
316
|
+
Proceed to `supabase-sdk-patterns` for production-ready client initialization, typed queries, and real-time subscriptions.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Error Handling Reference
|
|
2
|
+
|
|
3
|
+
| Error | Cause | Solution |
|
|
4
|
+
|-------|-------|----------|
|
|
5
|
+
| Module not found | Missing dependency | Run `npm install` |
|
|
6
|
+
| Port in use | Another process | Kill process or change port |
|
|
7
|
+
| Env not loaded | Missing .env.local | Copy from .env.example |
|
|
8
|
+
| Test timeout | Slow network | Increase test timeout |
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## Examples
|
|
2
|
+
|
|
3
|
+
### Mock Supabase Responses
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
vi.mock('@supabase/supabase-js', () => ({
|
|
7
|
+
SupabaseClient: vi.fn().mockImplementation(() => ({
|
|
8
|
+
// Mock methods here
|
|
9
|
+
})),
|
|
10
|
+
}));
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Debug Mode
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Enable verbose logging
|
|
17
|
+
DEBUG=SUPABASE=* npm run dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
## Implementation Guide
|
|
2
|
+
|
|
3
|
+
### Step 1: Create Project Structure
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
my-supabase-project/
|
|
7
|
+
├── src/
|
|
8
|
+
│ ├── supabase/
|
|
9
|
+
│ │ ├── client.ts # Supabase client wrapper
|
|
10
|
+
│ │ ├── config.ts # Configuration management
|
|
11
|
+
│ │ └── utils.ts # Helper functions
|
|
12
|
+
│ └── index.ts
|
|
13
|
+
├── tests/
|
|
14
|
+
│ └── supabase.test.ts
|
|
15
|
+
├── .env.local # Local secrets (git-ignored)
|
|
16
|
+
├── .env.example # Template for team
|
|
17
|
+
└── package.json
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Step 2: Configure Environment
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Copy environment template
|
|
24
|
+
cp .env.example .env.local
|
|
25
|
+
|
|
26
|
+
# Install dependencies
|
|
27
|
+
npm install
|
|
28
|
+
|
|
29
|
+
# Start development server
|
|
30
|
+
npm run dev
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Step 3: Setup Hot Reload
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "tsx watch src/index.ts",
|
|
39
|
+
"test": "vitest",
|
|
40
|
+
"test:watch": "vitest --watch"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Step 4: Configure Testing
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
49
|
+
import { SupabaseClient } from '../src/supabase/client';
|
|
50
|
+
|
|
51
|
+
describe('Supabase Client', () => {
|
|
52
|
+
it('should initialize with API key', () => {
|
|
53
|
+
const client = new SupabaseClient({ apiKey: 'test-key' });
|
|
54
|
+
expect(client).toBeDefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|