@prisma/composer 0.11.0 → 0.12.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 (50) hide show
  1. package/dist/{app-config-DF2_vkH7-D-BcHjYm.d.mts → app-config-CooZZhD4-EAGtxAPU.d.mts} +12 -4
  2. package/dist/{app-config-DF2_vkH7-D-BcHjYm.d.mts.map → app-config-CooZZhD4-EAGtxAPU.d.mts.map} +1 -1
  3. package/dist/config-BmK1pGlA.d.mts +1 -0
  4. package/dist/config.d.mts +2 -2
  5. package/dist/control.d.mts +5 -5
  6. package/dist/control.mjs +5 -5
  7. package/dist/control.mjs.map +1 -1
  8. package/dist/deploy-BmK1pGlA.d.mts +1 -0
  9. package/dist/deploy.d.mts +2 -2
  10. package/dist/deploy.mjs +1 -1
  11. package/dist/deploy.mjs.map +1 -1
  12. package/dist/{dist-C5rZnr4n.mjs → dist-BwC61F08.mjs} +2 -2
  13. package/dist/dist-BwC61F08.mjs.map +1 -0
  14. package/dist/{execute-deploy-destroy-DJ3BlpgU-ozOg0xCh.mjs → execute-deploy-destroy-Bsdh8hf4-ConszqTa.mjs} +4 -3
  15. package/dist/execute-deploy-destroy-Bsdh8hf4-ConszqTa.mjs.map +1 -0
  16. package/dist/{execute-dev-CQ0Lo2eN-BXIHSzKA.mjs → execute-dev-CQ0Lo2eN-BL3PmI0m.mjs} +2 -2
  17. package/dist/{execute-dev-CQ0Lo2eN-BXIHSzKA.mjs.map → execute-dev-CQ0Lo2eN-BL3PmI0m.mjs.map} +1 -1
  18. package/dist/{execute-log-CUzTOzSj-D5c_igNr.mjs → execute-log-CUzTOzSj-v-J7hbAb.mjs} +2 -2
  19. package/dist/{execute-log-CUzTOzSj-D5c_igNr.mjs.map → execute-log-CUzTOzSj-v-J7hbAb.mjs.map} +1 -1
  20. package/dist/{graph-BJgUfGB0-kvgFzT4q.mjs → graph-BfKAg2Ap-CrhKkEzd.mjs} +152 -11
  21. package/dist/graph-BfKAg2Ap-CrhKkEzd.mjs.map +1 -0
  22. package/dist/{graph-DqklX5Sf-BNS2aO1j.d.mts → graph-CPeatmoF-DfDx8ctT.d.mts} +3 -3
  23. package/dist/graph-CPeatmoF-DfDx8ctT.d.mts.map +1 -0
  24. package/dist/{graph-types-N6brq1zY-1VMNwtkJ.d.mts → graph-types-BTTaRnih-BF6PobQ3.d.mts} +44 -3
  25. package/dist/{graph-types-N6brq1zY-1VMNwtkJ.d.mts.map → graph-types-BTTaRnih-BF6PobQ3.d.mts.map} +1 -1
  26. package/dist/{index-DryPyF9U.d.mts → index-DeocL1di.d.mts} +3 -3
  27. package/dist/{index-DryPyF9U.d.mts.map → index-DeocL1di.d.mts.map} +1 -1
  28. package/dist/index.d.mts +4 -4
  29. package/dist/index.mjs +3 -3
  30. package/dist/local-target.d.mts +1 -1
  31. package/dist/{nextjs-DLyeRR7M-DZODs9tk.d.mts → nextjs-DLyeRR7M-D7UOddVQ.d.mts} +3 -3
  32. package/dist/{nextjs-DLyeRR7M-DZODs9tk.d.mts.map → nextjs-DLyeRR7M-D7UOddVQ.d.mts.map} +1 -1
  33. package/dist/nextjs-control.d.mts +4 -4
  34. package/dist/nextjs.d.mts +1 -1
  35. package/dist/node-control.d.mts +3 -3
  36. package/dist/node.d.mts +2 -2
  37. package/dist/{pipeline-Bt8QocRh-DMU4GXz9.mjs → pipeline-Bt8QocRh-Dw2LMte5.mjs} +3 -3
  38. package/dist/{pipeline-Bt8QocRh-DMU4GXz9.mjs.map → pipeline-Bt8QocRh-Dw2LMte5.mjs.map} +1 -1
  39. package/dist/report.d.mts +2 -2
  40. package/dist/service-rpc.d.mts +2 -2
  41. package/dist/service-rpc.mjs +2 -2
  42. package/dist/testing.d.mts +1 -1
  43. package/package.json +16 -15
  44. package/skills/prisma-composer/SKILL.md +786 -0
  45. package/dist/config-Cgdex2ik.d.mts +0 -1
  46. package/dist/deploy-Cgdex2ik.d.mts +0 -1
  47. package/dist/dist-C5rZnr4n.mjs.map +0 -1
  48. package/dist/execute-deploy-destroy-DJ3BlpgU-ozOg0xCh.mjs.map +0 -1
  49. package/dist/graph-BJgUfGB0-kvgFzT4q.mjs.map +0 -1
  50. package/dist/graph-DqklX5Sf-BNS2aO1j.d.mts.map +0 -1
@@ -0,0 +1,786 @@
1
+ ---
2
+ name: prisma-composer
3
+ metadata:
4
+ library: "@prisma/composer"
5
+ library_version: "0.12.0"
6
+ description: >-
7
+ How to write, test, and deploy an app with Prisma Composer
8
+ (`@prisma/composer`): declare services with `compute()` and typed
9
+ dependencies, define RPC contracts, compose Modules, declare the service
10
+ input (config and secrets as one schema, read back with `input()`),
11
+ compose the ready-made cron/storage/streams Modules, provision a
12
+ raw S3-compatible object-store bucket with `bucket()`, find extensions (npm
13
+ packages named `prisma-composer-*`), test with `mockService`/`bootstrapService`,
14
+ run the whole app locally with `prisma-composer dev` and tail its logs with
15
+ `prisma-composer log`, and deploy with `prisma-composer deploy` (stages,
16
+ destroy). Use when building a Prisma App, wiring a service dependency, adding
17
+ a Postgres database, adding scheduled jobs / blob storage / event streams / a
18
+ raw bucket, writing tests for composed services, running an app locally,
19
+ reading its logs, or deploying/tearing down an environment. Triggers on
20
+ "prisma composer", "@prisma/composer", "prisma app", "compute()",
21
+ "service.load()", "module()", "contract()", "mockService",
22
+ "bootstrapService", "prisma-composer dev", "prisma-composer log",
23
+ "prisma-composer deploy", "--stage", "--fresh", "--tail",
24
+ "prisma-composer destroy", "prisma-composer-", "bucket()".
25
+ ---
26
+
27
+ # Writing apps with Prisma Composer
28
+
29
+ A **Prisma App** is a tree of **Modules** composed in TypeScript. The leaves
30
+ are **services** (`compute()`) and **resources** (`postgres()`); the root
31
+ module wires them together by their typed ports. Your code receives everything
32
+ from exactly one place — the service node:
33
+
34
+ - `service.load()` — dependencies (typed RPC clients, database bindings)
35
+ - `service.input()` — the service's whole input, one schema-validated typed
36
+ object; credentials in it are redacting `SecretString` boxes
37
+ - `service.port()` — the reserved port to bind (default 3000), typed; never
38
+ `process.env`
39
+
40
+ The framework never bundles or transforms your code. You build your app with
41
+ whatever bundler you like (`bun build`, `next build`); `prisma-composer deploy`
42
+ assembles the built output and provisions it on Prisma Cloud (Compute + Prisma
43
+ Postgres).
44
+
45
+ Two things make building here fast and hard to get wrong — lean on both:
46
+
47
+ - **Compose before you write.** Reach for an existing Module (below) before
48
+ implementing a capability yourself; wiring one in is a couple of lines.
49
+ - **The compiler checks the wiring.** A dependency wired to the wrong
50
+ producer, a missing RPC handler, a config value of the wrong shape — all of
51
+ it fails `tsc`, not the deploy. Typecheck, then build, then deploy; don't
52
+ reach for the cloud to find out whether the app is correct.
53
+
54
+ Two packages, and only two, appear in your `package.json`:
55
+
56
+ | Package | Provides |
57
+ | --- | --- |
58
+ | `@prisma/composer` | Core authoring: `module`, `secret`, `isSecretString`, `/arktype` (the `secretString()` schema leaf), `/rpc`, `/node`, `/nextjs`, `/config`, `/testing`, the `prisma-composer` CLI |
59
+ | `@prisma/composer-prisma-cloud` | The Prisma Cloud target: `compute`, `postgres`, `envSecret`, `envParam`, `/control`, `/testing`, and the shared `/cron`, `/storage`, `/streams`, `/prisma-next` modules |
60
+
61
+ ## tsconfig and import specifiers
62
+
63
+ Within the entry graph (everything reachable from `module.ts`) relative
64
+ imports may use `./service.js` or extensionless `./service`. The CLI maps
65
+ `.js` and extensionless specifiers to the matching `.ts` source under Node;
66
+ Bun does this natively.
67
+
68
+ A minimal tsconfig:
69
+
70
+ ```jsonc
71
+ {
72
+ "compilerOptions": {
73
+ "target": "ES2022",
74
+ "module": "Preserve",
75
+ "moduleResolution": "bundler",
76
+ "noEmit": true,
77
+ "strict": true,
78
+ "skipLibCheck": true,
79
+ "types": ["bun"]
80
+ },
81
+ "include": ["module.ts", "src"]
82
+ }
83
+ ```
84
+
85
+ ## Anatomy of a service
86
+
87
+ A service is four small files. Worked example: an `auth` service that owns a
88
+ Postgres database and serves an RPC contract, consumed by a `storefront`
89
+ Next.js app.
90
+
91
+ **The contract** lives with the service that owns it. Any Standard Schema
92
+ validator types the messages; arktype is the house choice:
93
+
94
+ ```ts
95
+ // auth/src/contract.ts
96
+ import { contract, rpc } from '@prisma/composer/service-rpc';
97
+ import { type } from 'arktype';
98
+
99
+ export const authContract = contract({
100
+ verify: rpc({ input: type({ token: 'string' }), output: type({ ok: 'boolean' }) }),
101
+ });
102
+ ```
103
+
104
+ **The service declaration** is pure data — name, dependencies, build, exposed
105
+ ports. No behavior, no platform keys:
106
+
107
+ ```ts
108
+ // auth/src/service.ts
109
+ import node from '@prisma/composer/node';
110
+ import { compute, postgres } from '@prisma/composer-prisma-cloud';
111
+ import { authContract } from './contract.ts';
112
+
113
+ export default compute({
114
+ name: 'auth',
115
+ deps: { db: postgres() },
116
+ build: node({ module: import.meta.url, entry: '../dist/server.mjs' }),
117
+ expose: { rpc: authContract },
118
+ });
119
+ ```
120
+
121
+ **The server entry** is what your build produces and the platform boots. It
122
+ reads its dependencies through `load()` and serves the contract with
123
+ `serve()` — the handler map is keyed by the expose port's name and is
124
+ exhaustive at compile time:
125
+
126
+ ```ts
127
+ // auth/src/server.ts
128
+ import { serve } from '@prisma/composer/service-rpc';
129
+ import { SQL } from 'bun';
130
+ import service from './service.ts';
131
+
132
+ const { db } = service.load(); // { url } — you build your own client
133
+ const port = service.port(); // the reserved port, resolved (default 3000)
134
+
135
+ const sql = new SQL({ url: db.url, max: 1, idleTimeout: 10 });
136
+
137
+ const handler = serve(service, {
138
+ rpc: {
139
+ verify: async ({ token }) => ({ ok: token.length > 0 }),
140
+ },
141
+ });
142
+ export default handler;
143
+
144
+ // Bind all interfaces — Compute routes external HTTP to the VM; a
145
+ // loopback-only listener is unreachable.
146
+ Bun.serve({ port, hostname: '0.0.0.0', fetch: handler });
147
+ ```
148
+
149
+ **The consumer** declares the dependency as `rpc(contract)` and gets a typed
150
+ client back from `load()`:
151
+
152
+ ```ts
153
+ // storefront/src/service.ts
154
+ import nextjs from '@prisma/composer/nextjs';
155
+ import { rpc } from '@prisma/composer/service-rpc';
156
+ import { compute } from '@prisma/composer-prisma-cloud';
157
+ import { authContract } from '@my-app/auth/contract';
158
+
159
+ export default compute({
160
+ name: 'storefront',
161
+ deps: { auth: rpc(authContract) },
162
+ build: nextjs({ module: import.meta.url, appDir: '..' }),
163
+ });
164
+ ```
165
+
166
+ ```tsx
167
+ // storefront/app/page.tsx
168
+ import service from '../src/service.ts';
169
+
170
+ // load() reads the runtime environment, which doesn't exist at build time —
171
+ // render per request instead of prerendering.
172
+ export const dynamic = 'force-dynamic';
173
+
174
+ export default async function Home() {
175
+ const { auth } = service.load();
176
+ const { ok } = await auth.verify({ token: 'demo-token' });
177
+ return <p>Signed in: {String(ok)}</p>;
178
+ }
179
+ ```
180
+
181
+ **Service-to-service calls are authenticated for you.** At deploy the
182
+ framework mints a distinct, unguessable **service key** per consumer→provider
183
+ binding: the consumer's client sends it on every call, and `serve()` returns
184
+ `401` to anything else *before* the handler runs. Nothing declares it — no key
185
+ in the contract, the service, the module, or the app's code.
186
+
187
+ Two rules follow for you specifically: **don't build your own
188
+ service-to-service auth** on top of this, and **don't tell a user to `curl` a
189
+ deployed `/rpc/<method>` to check it works** — an unwired caller always gets
190
+ `401`, which looks like a broken deploy and isn't. Debug through a consumer,
191
+ or locally.
192
+
193
+ **Calls carry an idempotency key and retry safely for you.** Every call the
194
+ generated client makes carries an `Idempotency-Key`; a call dropped while the
195
+ target cold-starts is retried with a backoff, and `serve()` runs one call per
196
+ key — a retry that arrives after the first completed replays that answer
197
+ instead of re-running the handler. So every method is safely retryable and no
198
+ contract declares anything about it (do not add an "is this idempotent" flag —
199
+ the framework does not have one). Two consequences for you: a handler may take
200
+ an **optional third argument** `(input, deps, ctx)` and read `ctx.idempotencyKey`
201
+ (`string | undefined` — it's absent for a keyless caller) if it needs exactly-once
202
+ beyond one instance's memory (most don't); and a request without the header is
203
+ served once without deduplication rather than rejected, so a hand-rolled probe
204
+ works but gets no retry safety.
205
+
206
+ | | |
207
+ | --- | --- |
208
+ | Locally / in tests | nothing is provisioned, so `serve()` passes every call through — never supply a key in `inputs` |
209
+ | Per binding | two consumers of one provider hold different keys, so one leaking can't impersonate the other |
210
+ | Scope | service-level — any valid key reaches every method that service exposes; split into two services to gate separately |
211
+ | Rotation | remove the binding (or destroy the stack) and redeploy — a plain redeploy is a no-op, not a rotation |
212
+ | Storage | `COMPOSER_*` variables the deploy owns and rewrites; never hand-edit one |
213
+
214
+ It's a capability token ("I'm a service this app wired to you"), not a secret,
215
+ and its value lives in deploy state — deliberately unlike `secret()`, whose
216
+ value the framework never holds. `docs/design/90-decisions/ADR-0030…` in the
217
+ prisma/composer repo carries the reasoning.
218
+
219
+ ## The root module
220
+
221
+ The root module provisions the pieces and wires exposed ports into dependency
222
+ slots. It is the app — `prisma-composer deploy` loads its default export:
223
+
224
+ ```ts
225
+ // module.ts
226
+ import { module } from '@prisma/composer';
227
+ import authModule from '@my-app/auth';
228
+ import storefrontService from '@my-app/storefront';
229
+
230
+ export default module('my-app', ({ provision }) => {
231
+ const auth = provision(authModule);
232
+ provision(storefrontService, { deps: { auth: auth.rpc } });
233
+ });
234
+ ```
235
+
236
+ `provision(node, opts?)` accepts `id` (defaults to the node's own name),
237
+ `deps` (wire each declared dependency to a provisioned ref or exposed port),
238
+ `input` (the service's input binding — required exactly when it declares an
239
+ input schema, see § Service input), and `secrets` (bind a module boundary's
240
+ forwarded secret needs).
241
+
242
+ ## Builds are yours
243
+
244
+ The framework assembles only what you built — users build, the framework
245
+ assembles. For a plain server process, `entry` must point at a single
246
+ self-contained ESM file: everything inlined except runtime built-ins (`bun`,
247
+ `bun:*`, `node:*`), which the deploy VM provides. Deploy copies that one file
248
+ and never ships `node_modules`, so anything left un-inlined fails at boot. Any
249
+ bundler that produces such a file works. With bun:
250
+
251
+ ```sh
252
+ bun build src/server.ts --target=bun --outfile dist/server.mjs
253
+ ```
254
+
255
+ Two services in one package means two separate builds, one per entry — not one
256
+ multi-entry build, which would split shared code into a chunk neither output
257
+ contains.
258
+
259
+ If the build emits a directory rather than one file — a server plus the client
260
+ bundle, CSS and images it serves, as Bun's HTML import produces — name the
261
+ directory with `dir` and the booting file inside it with `entry`:
262
+
263
+ ```ts
264
+ build: node({ module: import.meta.url, dir: '../dist/server', entry: 'server.js' })
265
+ ```
266
+
267
+ `dir` resolves relative to the service module; `entry` resolves inside `dir`
268
+ and may be nested. Deploy copies the tree verbatim and boots the named file,
269
+ so the server must resolve its siblings against `import.meta.url`, not the
270
+ working directory. Nothing is inferred, and two rules bite: the tree must
271
+ contain no symlinks (the packager rejects them — assembly fails and names the
272
+ link), and `entry` must be a file inside `dir` (`../` is an error, not an
273
+ escape). Omit `dir` for the single-file form.
274
+
275
+ For Next.js, `next build` with `output: 'standalone'` is the whole build;
276
+ `nextjs({ module, appDir })` tells the deploy where the app root is.
277
+
278
+ Always build before deploying — `prisma-composer deploy` does not build for
279
+ you.
280
+
281
+ ## Deploy config
282
+
283
+ `prisma-composer.config.ts` usually sits next to `module.ts`, but it may live in
284
+ any ancestor directory: the CLI searches the entry's directory first, then each
285
+ parent, and uses the nearest one. It is read only by `prisma-composer
286
+ deploy`/`destroy`, never imported by app code. A plain-JavaScript project can
287
+ name it `prisma-composer.config.mjs` or `.js` to keep it out of its TypeScript
288
+ build (a build with `allowJs` still needs an explicit `exclude`); `.mts` is the
289
+ TypeScript ES-module spelling. Within one directory `.ts` wins, then `.mts`,
290
+ `.mjs`, `.js`:
291
+
292
+ ```ts
293
+ // prisma-composer.config.ts
294
+ import { defineConfig } from '@prisma/composer/config';
295
+ import { nodeBuild } from '@prisma/composer/node/control';
296
+ import { prismaCloud, prismaState } from '@prisma/composer-prisma-cloud/control';
297
+
298
+ export default defineConfig({
299
+ extensions: [prismaCloud(), nodeBuild()],
300
+ state: () => prismaState(), // deploy state, in its own database on the stage's branch
301
+ });
302
+ ```
303
+
304
+ Add `nextjsBuild()` from `@prisma/composer/nextjs/control` to `extensions`
305
+ when the app contains a Next.js service.
306
+
307
+ ## Databases
308
+
309
+ Two kinds of Postgres dependency:
310
+
311
+ **`postgres()`** — the binding is `{ url }` and the app owns its client.
312
+ Construct it in your server entry, as in the auth example above.
313
+
314
+ **`pnPostgres(...)`** — a Prisma Next-typed database: `load()`
315
+ returns the typed client the framework constructs from your data contract, so
316
+ queries like `db.orm.public.Product.all()` are compile-time checked. The
317
+ contract is emitted from `contract.prisma` by `prisma-next contract emit` and
318
+ wrapped once, referenced by both ends:
319
+
320
+ ```ts
321
+ // src/data.ts — the ONE value both ends reference
322
+ import { pnContract } from '@prisma/composer-prisma-cloud/prisma-next';
323
+ import type { Contract } from '../contract.d.ts';
324
+ import contractJson from '../contract.json' with { type: 'json' };
325
+
326
+ export const catalogData = pnContract<Contract>(contractJson);
327
+ ```
328
+
329
+ The dependency end is `deps: { db: pnPostgres(catalogData) }`. The resource
330
+ end (inside the module that owns the database) also names the
331
+ `prisma-next.config.ts` path, which the deploy's migration step loads to find
332
+ `migrations/` — migrations are applied at deploy, before the service starts:
333
+
334
+ ```ts
335
+ const db = provision(
336
+ pnPostgres({ name: 'database', contract: catalogData, config: './prisma-next.config.ts' }),
337
+ );
338
+ ```
339
+
340
+ (`pnPostgres` is both ends: the contract alone is the dependency end; the
341
+ options object is the resource end.)
342
+
343
+ See `examples/store/modules/catalog` in the prisma/composer repo for the
344
+ complete pattern.
345
+
346
+ ## Object Storage
347
+
348
+ `bucket` is a raw S3-compatible object-store bucket, imported alongside `postgres`:
349
+
350
+ ```ts
351
+ import { bucket, compute } from '@prisma/composer-prisma-cloud';
352
+
353
+ // service.ts — dependency end: receives { url, bucket, accessKeyId, secretAccessKey }
354
+ export default compute({ name: 'uploads', deps: { store: bucket() } });
355
+
356
+ // module.ts — resource end: provisions the bucket and mints a keypair
357
+ const store = provision(bucket({ name: 'uploads' }));
358
+ provision(uploadsService, { deps: { store } });
359
+ ```
360
+
361
+ Use any S3-compatible client with the binding: the shape matches the standard S3
362
+ config and is also compatible with the `s3()` dependency from `/storage`, so any
363
+ service wired to `s3()` can be rewired to a `bucket` resource without changing
364
+ the service declaration.
365
+
366
+ ## Reusable Modules
367
+
368
+ A Module is the unit of reuse: it owns its internals (its database, its
369
+ services) and exposes only typed ports. Declare the boundary in the second
370
+ argument; wire internals in the builder; return the exposed ports:
371
+
372
+ ```ts
373
+ // auth/src/module.ts — a Module that owns its own Postgres
374
+ import { module, secret } from '@prisma/composer';
375
+ import { postgres } from '@prisma/composer-prisma-cloud';
376
+ import { authContract } from './contract.ts';
377
+ import authService from './service.ts';
378
+
379
+ export default module(
380
+ 'auth',
381
+ { secrets: { signingKey: secret() }, expose: { rpc: authContract } },
382
+ ({ secrets, provision }) => {
383
+ const db = provision(postgres({ name: 'database' }));
384
+ const service = provision(authService, {
385
+ id: 'service',
386
+ deps: { db },
387
+ input: { signingKey: secrets.signingKey }, // forwarded ref as a binding leaf
388
+ });
389
+ return { rpc: service.rpc };
390
+ },
391
+ );
392
+ ```
393
+
394
+ Naming rules that bite: a provision id shorter than 3 characters is rejected
395
+ by the platform (name the database `'database'`, not `'db'`), and a service
396
+ whose name equals its enclosing module's reads as `auth.auth` unless you give
397
+ it an explicit `id`.
398
+
399
+ A module can also declare boundary `deps` — inputs the parent wires exactly as
400
+ it would wire a service's. The consumer never sees the module's internals.
401
+
402
+ ### The building blocks you can compose
403
+
404
+ Modules are the building blocks: provision one, wire its exposed port, and
405
+ you're done — you never reimplement what a Module already owns. The
406
+ first-party set ships inside `@prisma/composer-prisma-cloud`. It's small, and
407
+ growing:
408
+
409
+ | Import | What it provisions | Exposes |
410
+ | --- | --- | --- |
411
+ | `cron` from `/cron` | An always-on scheduler firing your schedule at your runner service | nothing |
412
+ | `storage` from `/storage` | An S3-backed blob store (own Postgres + minted credentials) | `store` |
413
+ | `streams` from `/streams` | Durable append-only event streams over a `store` | `streams` |
414
+
415
+ **Finding more.** A Composer extension — a package that brings its own
416
+ Modules, resources, or deploy target — is published on npm under the name
417
+ `prisma-composer-*`. That name is the convention, so it's how you look for
418
+ one. The ecosystem is new: today the blocks above plus the app Modules you
419
+ write are the whole set, so don't reach for a `prisma-composer-*` package
420
+ without checking that it actually exists on npm first.
421
+
422
+ Cron end to end — the schedule is one source of truth; `serveSchedule` is
423
+ exhaustive over its job ids at compile time:
424
+
425
+ ```ts
426
+ // service.ts
427
+ import { defineSchedule, triggerContract } from '@prisma/composer-prisma-cloud/cron';
428
+ export const schedule = defineSchedule({ tick: '60s' });
429
+ // the runner service exposes { trigger: triggerContract }
430
+
431
+ // server.ts
432
+ import { serveSchedule } from '@prisma/composer-prisma-cloud/cron';
433
+ const handler = serveSchedule(service, schedule, {
434
+ tick: (deps) => deps.worker.tick({}),
435
+ });
436
+
437
+ // module.ts — the cron module's boundary deps mirror the runner's own
438
+ provision(cron({ schedule, runner: runnerService }), { deps: { worker: worker.rpc } });
439
+ ```
440
+
441
+ ## Service input
442
+
443
+ Choosing the channel is most of the decision:
444
+
445
+ | The value is… | Declare | Provide | Read |
446
+ | --- | --- | --- | --- |
447
+ | produced by another node | `deps: { db: postgres() }` | wire at `provision()` | `load()` |
448
+ | anything else — config or credential | one field of the `input` schema | bind at `provision()`: literal, `envParam()`, or `envSecret()` | `input()` |
449
+
450
+ The service declares its whole incoming configuration — plain values and
451
+ credentials together — as **one
452
+ [Standard Schema](https://standardschema.dev)** (arktype is the house
453
+ choice). A credential is a field typed as the redacting `SecretString` box;
454
+ conditional legality ("no stripe key unless billing is on") is an ordinary
455
+ schema union:
456
+
457
+ ```ts
458
+ // service.ts — the shapes that are legal
459
+ import { secretString } from '@prisma/composer/arktype';
460
+ import { type } from 'arktype';
461
+
462
+ compute({
463
+ name: 'scheduler',
464
+ input: type({
465
+ jobs: type({ jobId: 'string', every: 'string' }).array(),
466
+ 'region?': 'string',
467
+ apiKey: secretString(),
468
+ }),
469
+ // ...
470
+ });
471
+
472
+ // module.ts — where each value comes from; the binding mirrors the schema's shape
473
+ import { envParam, envSecret } from '@prisma/composer-prisma-cloud';
474
+ provision(scheduler, {
475
+ input: {
476
+ jobs: [{ jobId: 'tick', every: '60s' }], // a literal
477
+ region: envParam('REGION'), // a per-stage platform variable
478
+ apiKey: envSecret('SCHEDULER_API_KEY'), // a credential — name only, never the value
479
+ },
480
+ });
481
+
482
+ // server.ts — one call, one validated typed object
483
+ const input = service.input();
484
+ input.apiKey.expose(); // the only way to a secret's value; the box redacts everywhere else
485
+ ```
486
+
487
+ Rules that bite:
488
+
489
+ - **Secretness is enforced by validation**: a literal bound where the schema
490
+ expects `SecretString` fails the deploy, and `envSecret` bound to a plain
491
+ string field fails the same way. Don't put credentials in plain fields.
492
+ - **`envParam` values arrive as raw strings** — bind them to string fields.
493
+ The stage's platform variable is the store; the deploying shell only seeds
494
+ it (preflight copies a missing name up from the shell, and fails early,
495
+ naming the variable, when both lack it). Changing the platform value needs
496
+ a redeploy.
497
+ - **Absence is the schema's call**: an env-bound field whose variable is
498
+ unset (or empty) resolves to *key omitted* — legal only if the schema says
499
+ so (optional field, union arm). The deploy report prints the serialized
500
+ input document (secret-free: secrets ride as `{"$secret":"VAR"}` pointers)
501
+ and every key that resolved absent.
502
+ - **The reserved `port` (default 3000) is outside the schema** — read it
503
+ through `service.port()` (a sibling of `service.origin()`), never
504
+ `process.env`. The framework also exports `PORT` for Next.js standalone,
505
+ which binds it itself.
506
+ - A module forwards a secret need without learning the platform name
507
+ (the auth Module above); the forwarded ref is a binding leaf.
508
+
509
+ `examples/env-param` and `examples/storefront-auth` in the prisma/composer
510
+ repo are the working versions.
511
+
512
+ ## Testing
513
+
514
+ You test by deciding what `load()` gives the code, never by editing the code
515
+ under test:
516
+
517
+ | You want to… | Use | From |
518
+ | --- | --- | --- |
519
+ | Test a page / action / handler in isolation | `mockService` | `@prisma/composer/testing` |
520
+ | Run the real boot + request path against a fake dependency | `bootstrapService` | `@prisma/composer-prisma-cloud/testing` |
521
+
522
+ **Unit — `mockService`.** Returns a copy of the service whose `load()` yields
523
+ your doubles (type-checked against the declared deps) and whose `input()`
524
+ yields the object you pass under the reserved `input` key, in one flat
525
+ object (required exactly when the service declares an input schema; handed
526
+ over as-is, not validated). Wiring the module substitution is your runner's
527
+ job (`vi.mock` in Vitest, `mock.module` in bun test):
528
+
529
+ ```tsx
530
+ // page.test.tsx
531
+ import { mockService } from '@prisma/composer/testing';
532
+ import realService from '../src/service.ts';
533
+
534
+ vi.mock('../src/service.ts', () => ({
535
+ default: mockService(realService, {
536
+ auth: { verify: async () => ({ ok: true }) }, // wrong shape = compile error
537
+ }),
538
+ }));
539
+
540
+ import Page from './page.tsx';
541
+ expect(renderToString(await Page())).toContain('Signed in: true');
542
+ ```
543
+
544
+ **Integration — `bootstrapService`.** Boots the service's real built entry
545
+ in-process against a config you choose, exactly as a deployed boot would;
546
+ drive it over real HTTP. Run under `bun test`:
547
+
548
+ ```ts
549
+ import { bootstrapService } from '@prisma/composer-prisma-cloud/testing';
550
+ import fakeAuth from '@my-app/auth/fake'; // in-memory handler, no db
551
+ import storefront from '../src/service.ts';
552
+
553
+ const fake = Bun.serve({ port: 0, fetch: fakeAuth });
554
+
555
+ const app = await bootstrapService(storefront, {
556
+ service: { port: 4310 },
557
+ inputs: { auth: { url: fake.url.href } },
558
+ });
559
+
560
+ const res = await app.fetch(new Request(app.url));
561
+ ```
562
+
563
+ - **`service.port` must be concrete** — the entry self-listens; no OS-assigned
564
+ port is reported back.
565
+ - **No `close()`** — run each integration-test file in its own process (bun
566
+ test does).
567
+ - **Next.js services take a third argument**, a boot thunk, because the built
568
+ entry lives in Next's standalone output — resolve it with
569
+ `standaloneServerPath` from `@prisma/composer/nextjs/control`.
570
+ `bootstrapService` exports the resolved port as `process.env.PORT` before
571
+ booting, which is what Next's standalone server binds.
572
+ - **A service with an input schema takes `input`** in the config — a binding
573
+ exactly like `provision()`'s, run through the real serialize/read path, so
574
+ `input()` in the booted entry sees what a deploy would produce.
575
+
576
+ **The fake you pass.** A dependency's type is its contract, so any value of
577
+ that shape is a valid double: a bare object (fastest), the real client over an
578
+ in-memory handler, or a real local server (what `bootstrapService` drives).
579
+ Ship a dependency's fake from its own package as a `/fake` entry point,
580
+ outside `src/`, so the fake and the real service always share one contract.
581
+
582
+ ## Running locally
583
+
584
+ `prisma-composer dev module.ts` runs the whole app on this machine — every
585
+ service, its Postgres and buckets, wired as they deploy — with **no cloud
586
+ credentials** (no `PRISMA_*`). It runs the same pipeline as deploy against
587
+ local emulators, so build first, exactly like deploy:
588
+
589
+ ```sh
590
+ turbo run build && prisma-composer dev module.ts
591
+ ```
592
+
593
+ It prints each service's local URL (the "front door"), watches built output
594
+ and restarts a service when its build changes, and runs until Ctrl-C. Ctrl-C
595
+ stops the app's processes but leaves the local databases, buckets, and their
596
+ data up, so the next `dev` is a warm start; `--fresh` wipes this app's local
597
+ instances and data first.
598
+
599
+ `dev` does **not** print service logs — that would bury the front door once
600
+ several services run. Logs are their own command:
601
+
602
+ | You want to… | Run |
603
+ | --- | --- |
604
+ | Run the app locally | `prisma-composer dev module.ts` |
605
+ | Start clean (wipe local data) | `prisma-composer dev module.ts --fresh` |
606
+ | Tail every service's logs | `prisma-composer log module.ts` |
607
+ | Tail one service | `prisma-composer log module.ts <address>` |
608
+ | Show more history first | `prisma-composer log module.ts --tail <n>` |
609
+
610
+ `prisma-composer log` follows the merged logs of the already-running app, each
611
+ line prefixed with its service (`[catalog.service] …`); pass a dotted address
612
+ to narrow to one. It only reads — it never builds, provisions, starts, or
613
+ stops anything. `--tail <n>` sets how much recent history to show before live
614
+ output (default 20; `0` for live-only). An unset secret doesn't block a local
615
+ run: it becomes a placeholder plus a warning, and only the code path that
616
+ spends it fails, at the real external service it calls. Windows isn't
617
+ supported yet.
618
+
619
+ ## Deploying
620
+
621
+ Requires exactly two environment variables: `PRISMA_SERVICE_TOKEN` and
622
+ `PRISMA_WORKSPACE_ID`. The target environment — a **stage** — is chosen on the
623
+ command line, never in code:
624
+
625
+ | You want to… | Run |
626
+ | --- | --- |
627
+ | Deploy to production | `prisma-composer deploy module.ts` |
628
+ | Deploy an isolated environment | `prisma-composer deploy module.ts --stage <name>` |
629
+ | Override the app name for one run | `prisma-composer deploy module.ts --name demo-42` |
630
+ | Tear down an isolated environment | `prisma-composer destroy module.ts --stage <name>` |
631
+ | Tear down production's resources | `prisma-composer destroy module.ts --production` |
632
+
633
+ A Prisma App is one Project; a stage is a Branch of it — its
634
+ own compute, its own empty database, its own configuration. Deploys are
635
+ idempotent: re-deploying a stage updates the resources inside it. A stage name
636
+ must be a valid git ref name; an invalid name is a hard error.
637
+
638
+ Destroy always requires an explicit target — a bare `prisma-composer destroy`
639
+ is an error, and `--stage` with `--production` is too. Destroying a stage
640
+ deletes its Branch after removing its resources; the production Branch itself
641
+ is never deleted, only the resources inside it. Destroying production also
642
+ deletes the Project itself once it's empty, so hand-run stacks don't leave
643
+ behind empty Projects — but a Project still holding another stage's resources
644
+ is kept. Destroy never creates anything: destroying a never-deployed stage
645
+ fails rather than standing one up.
646
+
647
+ ```sh
648
+ turbo run build && prisma-composer deploy module.ts --stage pr-42
649
+ ```
650
+
651
+ ### What a deploy prints
652
+
653
+ A deploy ends by printing the app's own topology — authored names, the
654
+ platform resource each became, and public URLs. The tree is the module
655
+ structure (`auth.api` is the `api` service inside the `auth` module):
656
+
657
+ ```
658
+ storefront-auth
659
+ ├─ auth
660
+ │ └─ api compute-service cps_abc123
661
+ │ https://xyz.ewr.prisma.build
662
+ ├─ db postgres-database db_def456
663
+ └─ web compute-service cps_ghi789
664
+ https://uvw.ewr.prisma.build
665
+ ```
666
+
667
+ Read ids out of this rather than telling the user to go hunting in the
668
+ Console. A URL appears only where the address is genuinely public — a compute
669
+ service prints one, a database never does (it has a connection string, not a
670
+ public endpoint), and a node whose product is secret material (an
671
+ `s3-credentials` keypair) reports no resource line at all. A node that
672
+ published nothing reportable still appears, marked `(no entities reported)`.
673
+
674
+ Older deploys ended with a raw `{ outputs: {} }` blob from the deploy engine —
675
+ always empty, never about the app. It is gone; nothing configured it and
676
+ nothing consumed it.
677
+
678
+ ### The connection contract is checked at deploy
679
+
680
+ A connection declares the values it needs by name, and the producer on the
681
+ other end must supply them. A producer that omits one fails the deploy, naming
682
+ the edge, the param, and what the producer did supply:
683
+
684
+ ```
685
+ Connection input "auth.db" declares param "url", but its producer "db" did not
686
+ supply it — the producer's outputs carry [host].
687
+ ```
688
+
689
+ Fix it at whichever end is wrong: add the name to the outputs the producer
690
+ returns from its lowering, or mark the param `optional` on the connection if absent is
691
+ genuinely legal (the consumer then reads `undefined`).
692
+
693
+ This is a deploy-time refusal, not a broken deploy — and it can appear on an
694
+ app whose code didn't change. The gap used to pass silently: the value reached
695
+ the consumer as `undefined`, went into its environment, and crashed *that*
696
+ service at boot, blaming the reader instead of the supplier. Don't route around
697
+ it by making the param optional unless absent really is valid; that reinstates
698
+ the silent `undefined`.
699
+
700
+ Only reachable if you authored the connection or the extension on one side —
701
+ every shipped block supplies what it declares.
702
+
703
+ ### Driving deploys from code
704
+
705
+ `@prisma/composer/control` exposes the CLI's operations in-process: typed
706
+ `deploy`, `destroy`, `dev`, and `log` returning structured results — no argv,
707
+ no CLI rendering, no exit codes (the spawned deploy engine's own inherited
708
+ output can still reach the host terminal). The CLI itself is a renderer over
709
+ them.
710
+
711
+ ```ts
712
+ import { deploy } from '@prisma/composer/control';
713
+ const result = await deploy({ entry: 'module.ts', stage: 'pr-42' });
714
+ // result: { ok: true, value: { summary? } } | { ok: false, failure }
715
+ ```
716
+
717
+ - Failures come back as `{ ok: false, failure }` where `failure` is a
718
+ structured error: branch on its dotted `failure.code` (e.g.
719
+ `ASSEMBLE.BUILD_FAILED`, `DEPLOY.ENGINE_FAILED` — ADR-0044's closed
720
+ registry), with the same fix-naming `message`/`why`/`fix` the CLI renders.
721
+ An engine failure's `meta.diagnostics` (exit code, reproduce command; read
722
+ it with the exported `executionDiagnostics(failure)`) describes the current
723
+ execution mechanism — branch on `code`/`message`/`cause` for anything
724
+ durable. The effect version conflict is `DEPS.EFFECT_VERSION_CONFLICT`, and
725
+ importing the module executes nothing until an operation runs. A
726
+ non-structured rejection out of an operation is a bug in composer, not an
727
+ expected failure.
728
+ - `destroy` takes `target: { kind: 'production' } | { kind: 'stage', stage }`
729
+ — explicit, never defaulted.
730
+ - `deploy`'s `summary` (the deployed topology) is best-effort; `undefined` on
731
+ a successful deploy is normal.
732
+ - The deploy engine's live output still streams to the host process's stdio —
733
+ the current mechanism; the operations don't capture it.
734
+ - `dev` resolves to `{ ok: true, value: session }` or a failure; the
735
+ session is `{ endpoints, stop(), closed }` with progress via `onEvent`, and
736
+ the host owns signal handling. `log` resolves to
737
+ `{ ok: true, value: { appName, services, lines } }` or a failure, where
738
+ `lines` is an `AsyncIterable` ended by a caller-owned `AbortSignal` (or by
739
+ the consumer stopping early); zero running services is a valid result, not
740
+ an error.
741
+
742
+ ## Production pitfalls
743
+
744
+ - **Scale-to-zero closes idle database connections.** A persistent client
745
+ crashes into a 502 restart loop unless you keep the pool small and
746
+ reconnect-friendly (`new SQL({ url, max: 1, idleTimeout: 10 })` for Bun) and
747
+ log `uncaughtException`/`unhandledRejection` instead of dying.
748
+ - **Bind `0.0.0.0`**, not loopback — Compute routes external HTTP to the VM.
749
+ - **Next.js pages that call `load()` need `export const dynamic =
750
+ 'force-dynamic'`** — the runtime environment doesn't exist at build time,
751
+ and Next ignores runtime env for prerendered routes.
752
+ - **A deployed `/rpc/<method>` returns `401` to anything but a wired peer.**
753
+ Every RPC binding carries an auto-provisioned service key, so a hand-rolled
754
+ `curl` is never authorized, and a provider with no wired consumers rejects
755
+ everything. Not a broken deploy — reach it through a consumer, or run it
756
+ locally where nothing is enforced.
757
+ - **Cold starts reset service-to-service connections.** A call into a
758
+ scaled-to-zero service can get `ECONNRESET`; retry it.
759
+ - **Every `prisma-composer` command stops at start-up on an `effect` version
760
+ conflict** (`Dependency conflict: alchemy resolves effect@...`). Another
761
+ dependency floated a newer `effect` and the package manager hoisted it over
762
+ Composer's pin. Do what the error says: pin the whole `effect`
763
+ constellation in the app's `package.json` `overrides` (yarn: `resolutions`;
764
+ pnpm: `pnpm.overrides`) — `effect` plus `@effect/sql-d1`, `@effect/sql-pg`,
765
+ `@effect/vitest`, and `@effect/platform-bun`/`-node`/`-node-shared`, all at
766
+ Composer's exact pin — and reinstall. (A workaround for an upstream alchemy
767
+ bug: its own effect-family ranges float past what its code supports. The
768
+ repo's examples carry the block.)
769
+ - **The ingress buffers streaming responses.** An open SSE tail delivers
770
+ nothing and times out at 60s — don't build on streamed HTTP responses.
771
+
772
+ ## What Composer doesn't do yet
773
+
774
+ Name the gap instead of inventing an API:
775
+
776
+ - **No interactive auth.** Deploys authenticate only via a static
777
+ `PRISMA_SERVICE_TOKEN`; there is no `login` flow.
778
+ - **No in-memory contract bindings.** A dependency can't yet be wired to a
779
+ co-located handler without HTTP; use `bootstrapService` with a loopback
780
+ fake.
781
+ - **RPC over HTTP is the only contract kind.** No gRPC, WebSocket, or
782
+ streaming contracts.
783
+
784
+ For anything else missing, check the examples and design docs in the
785
+ prisma/composer repo (`examples/`, `docs/design/10-domains/`,
786
+ `docs/design/90-decisions/`), then file an issue there rather than guessing.