@dontcode2/backend 0.1.0 → 0.2.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/README.md +53 -0
- package/dist/chunk-2OGEV57K.js +850 -0
- package/dist/chunk-2OGEV57K.js.map +1 -0
- package/dist/index.cjs +261 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +196 -3
- package/dist/index.d.ts +196 -3
- package/dist/index.js +253 -36
- package/dist/index.js.map +1 -1
- package/dist/mock/cli.cjs +956 -0
- package/dist/mock/cli.cjs.map +1 -0
- package/dist/mock/cli.d.cts +1 -0
- package/dist/mock/cli.d.ts +1 -0
- package/dist/mock/cli.js +90 -0
- package/dist/mock/cli.js.map +1 -0
- package/dist/mock/index.cjs +886 -0
- package/dist/mock/index.cjs.map +1 -0
- package/dist/mock/index.d.cts +38 -0
- package/dist/mock/index.d.ts +38 -0
- package/dist/mock/index.js +7 -0
- package/dist/mock/index.js.map +1 -0
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -45,6 +45,59 @@ const client = dontcode({
|
|
|
45
45
|
If no key is set in either place, requests fail naturally with the gateway's
|
|
46
46
|
`401 Missing API key`.
|
|
47
47
|
|
|
48
|
+
## Local development (the mock gateway)
|
|
49
|
+
|
|
50
|
+
You don't need the hosted backend to build against this SDK. Because the SDK is a
|
|
51
|
+
thin proxy over a fixed wire protocol, the package ships a local server that speaks
|
|
52
|
+
that same protocol — auth, database, and storage — so you can develop fully offline:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx dontcode-mock # http://localhost:4000, state persisted to ./.dontcode-mock
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then point your app at it — no code changes, just config:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
DONTCODE_API_URL=http://localhost:4000
|
|
62
|
+
DONTCODE_API_KEY=dc_local_dev # any dc_… value is accepted by default
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Apply your schema the same way you would in production, then use the client normally:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const client = dontcode() // reads the env vars above
|
|
69
|
+
await client.db.migrate({ sql: 'CREATE TABLE IF NOT EXISTS notes (id serial primary key, body text);' })
|
|
70
|
+
await client.db.notes.insert({ body: 'hello from the mock' })
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
How faithful is it? The database runs your real DDL and the SDK's real structured
|
|
74
|
+
queries against in-process Postgres ([PGlite](https://pglite.dev)), including the
|
|
75
|
+
`409` conflict signal; auth issues real JWT-shaped tokens that `decodeAccessToken`
|
|
76
|
+
and `getSession` read exactly as in production; storage stores real files and serves
|
|
77
|
+
them over the same server. It is a **development tool** — passwords are stored in
|
|
78
|
+
plaintext, tokens are unsigned, and there is no rate limiting — so never expose it
|
|
79
|
+
to an untrusted network.
|
|
80
|
+
|
|
81
|
+
PGlite ships as an optional dependency, so `npx dontcode-mock` works out of the box.
|
|
82
|
+
(If your install skipped optional deps, add it: `pnpm add -D @electric-sql/pglite`.)
|
|
83
|
+
|
|
84
|
+
**Useful flags:** `--port <n>`, `--data-dir <dir>`, `--ephemeral` (in-memory, starts
|
|
85
|
+
empty each run — ideal for tests), `--api-key <key>` (require exactly that key).
|
|
86
|
+
Run `dontcode-mock --help` for the full list.
|
|
87
|
+
|
|
88
|
+
You can also drive it programmatically — handy for integration tests that need a
|
|
89
|
+
clean backend per run:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { startMockServer } from '@dontcode2/backend/mock'
|
|
93
|
+
import { dontcode } from '@dontcode2/backend'
|
|
94
|
+
|
|
95
|
+
const mock = await startMockServer({ dataDir: null }) // ephemeral
|
|
96
|
+
const client = dontcode({ baseUrl: mock.url, apiKey: 'dc_test' })
|
|
97
|
+
// … exercise the client …
|
|
98
|
+
await mock.close()
|
|
99
|
+
```
|
|
100
|
+
|
|
48
101
|
## Auth
|
|
49
102
|
|
|
50
103
|
The API key (`Authorization: Bearer dc_…`) identifies your **project** and is sent on
|