@prisma/orm-mongo 8.0.0-rc.9-dev.13 → 8.0.1-dev.2
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 +48 -8
- package/dist/components-CWskH7lF-Dkc9ysZz.mjs +18 -0
- package/dist/components-CWskH7lF-Dkc9ysZz.mjs.map +1 -0
- package/dist/config.d.mts +14 -5
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +47 -25
- package/dist/config.mjs.map +1 -1
- package/dist/contract-builder.d.mts +33 -91
- package/dist/contract-builder.d.mts.map +1 -1
- package/dist/contract-builder.mjs +23 -7
- package/dist/contract-builder.mjs.map +1 -1
- package/dist/contract-types.d.mts +3 -0
- package/dist/contract-types.mjs +1 -0
- package/dist/contract__format-version.d.mts +1 -0
- package/dist/contract__format-version.mjs +2 -0
- package/dist/contract__internal__format-version.d.mts +1 -0
- package/dist/contract__internal__format-version.mjs +2 -0
- package/dist/contract__validate-once.d.mts +1 -0
- package/dist/contract__validate-once.mjs +2 -0
- package/dist/contract__validate-storage.d.mts +1 -0
- package/dist/contract__validate-storage.mjs +2 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +3 -9
- package/dist/control.mjs.map +1 -1
- package/dist/driver__runtime.d.mts +3 -0
- package/dist/driver__runtime.mjs +3 -0
- package/dist/family-contract__data-type.d.mts +1 -0
- package/dist/family-contract__data-type.mjs +2 -0
- package/dist/init-quick-reference.md +116 -0
- package/dist/init-readme.md +35 -0
- package/dist/init.d.mts +7 -0
- package/dist/init.d.mts.map +1 -0
- package/dist/init.mjs +245 -0
- package/dist/init.mjs.map +1 -0
- package/dist/migration.d.mts +1 -0
- package/dist/migration.mjs +2 -0
- package/dist/module-base-B70DHaBE-k_c3Klu4.mjs +6 -0
- package/dist/module-base-B70DHaBE-k_c3Klu4.mjs.map +1 -0
- package/dist/mongo-static-BrplLPTr-DGOk19X8.mjs +74 -0
- package/dist/mongo-static-BrplLPTr-DGOk19X8.mjs.map +1 -0
- package/dist/{mongo-static-BdSGXYgQ-DSA-2DiK.d.mts → mongo-static-DabeBtmV-DILuhcbE.d.mts} +18 -5
- package/dist/mongo-static-DabeBtmV-DILuhcbE.d.mts.map +1 -0
- package/dist/runtime.d.mts +49 -44
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +104 -42
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.d.mts +24 -2
- package/dist/static.d.mts.map +1 -0
- package/dist/static.mjs +2 -2
- package/dist/target__codec-ids.d.mts +1 -0
- package/dist/target__codec-ids.mjs +2 -0
- package/dist/target__codecs.d.mts +1 -0
- package/dist/target__codecs.mjs +2 -0
- package/dist/target__data-types.d.mts +1 -0
- package/dist/target__data-types.mjs +2 -0
- package/dist/target__server-version.d.mts +1 -0
- package/dist/target__server-version.mjs +2 -0
- package/dist/utils__guards.d.mts +1 -0
- package/dist/utils__guards.mjs +2 -0
- package/dist/utils__text.d.mts +1 -0
- package/dist/utils__text.mjs +2 -0
- package/dist/utils__upgrade-guides.d.mts +1 -0
- package/dist/utils__upgrade-guides.mjs +2 -0
- package/package.json +37 -13
- package/skills/prisma-8/SKILL.md +23 -18
- package/skills/prisma-8/references/build-a-target-package.md +117 -0
- package/skills/prisma-8/references/build.md +12 -16
- package/skills/prisma-8/references/contract.md +181 -75
- package/skills/prisma-8/references/debug.md +35 -24
- package/skills/prisma-8/references/feedback.md +8 -8
- package/skills/prisma-8/references/migration-model.md +23 -14
- package/skills/prisma-8/references/migration-review.md +23 -52
- package/skills/prisma-8/references/migrations.md +294 -80
- package/skills/prisma-8/references/queries-mongo.md +53 -17
- package/skills/prisma-8/references/queries-postgres.md +345 -34
- package/skills/prisma-8/references/queries.md +44 -25
- package/skills/prisma-8/references/quickstart.md +25 -22
- package/skills/prisma-8/references/runtime.md +172 -72
- package/skills/prisma-8/references/supabase.md +22 -19
- package/skills/prisma-8/references/upgrade-app.md +57 -22
- package/skills/prisma-8/references/upgrade-extension.md +72 -23
- package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/multifile-psl/add-use-prisma-8-directive.mjs +60 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/scripts/sql-expression-literals-psl/rewrite-sql-strings.mjs +271 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +803 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +586 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/scripts/value-objects-in-storage/value-objects-in-storage.ts +1184 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +480 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/scripts/mongo-index-names/mongo-index-names.ts +317 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +336 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1561 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +13 -0
- package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +464 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +410 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +303 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1593 -0
- package/dist/adapter__codec-ids.d.mts +0 -1
- package/dist/adapter__codec-ids.mjs +0 -2
- package/dist/adapter__codec-types.d.mts +0 -1
- package/dist/adapter__codec-types.mjs +0 -2
- package/dist/adapter__codecs.d.mts +0 -1
- package/dist/adapter__codecs.mjs +0 -2
- package/dist/mongo-static-BdSGXYgQ-DSA-2DiK.d.mts.map +0 -1
- package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs +0 -38
- package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Welcome to Prisma ORM!
|
|
2
|
+
|
|
3
|
+
Prisma ORM lets you query your database in simple, easy-to-read TypeScript. Define what your data looks like, and Prisma ORM gives you a fully typed client — with autocomplete for every collection, field, and relation.
|
|
4
|
+
|
|
5
|
+
This project is set up for MongoDB. Prisma ORM also supports other databases.
|
|
6
|
+
|
|
7
|
+
{{requirements}}
|
|
8
|
+
|
|
9
|
+
## Your data contract
|
|
10
|
+
|
|
11
|
+
Your data contract is the heart of your application. It lives at [`{{schemaPath}}`]({{schemaPath}}) and describes your models:
|
|
12
|
+
|
|
13
|
+
{{schemaSample}}
|
|
14
|
+
|
|
15
|
+
Every model you define in your contract can be queried from your app. Your editor will autocomplete the query methods and show you what type each field is:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { db } from '{{dbImportPath}}';
|
|
19
|
+
|
|
20
|
+
const user = await db.orm.users
|
|
21
|
+
.where({ email: 'alice@example.com' })
|
|
22
|
+
.first();
|
|
23
|
+
|
|
24
|
+
// Your editor will show the type of user as
|
|
25
|
+
// { id: ObjectId; email: string; username: string | null; name: string | null; posts: Post[] } | null
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`db` connects to MongoDB lazily on the first query, so there is no manual `connect(...)` step in your application code. Call `await db.close()` if you need to release the underlying connection (typically only in tests or short-lived scripts). After `close()` the client is single-shot — any further query, `connect()`, or `runtime()` call rejects with `"Mongo client is closed"`. Construct a new `mongo({...})` if you need to use it again.
|
|
29
|
+
|
|
30
|
+
Your contract has two companion files in the same directory:
|
|
31
|
+
|
|
32
|
+
- **`contract.json`** — this tells your application what models exist, just like `package-lock.json` tells your package manager what dependencies your project has
|
|
33
|
+
- **`contract.d.ts`** — this powers autocomplete and type checking in your editor
|
|
34
|
+
|
|
35
|
+
Commit both files to git. When you change your contract, run `{{pkgRun}} contract emit` to update them.
|
|
36
|
+
|
|
37
|
+
If you use a framework like Next.js or Vite, the Prisma ORM plugin will do this for you automatically.
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
[`prisma.config.ts`](prisma.config.ts) tells the CLI where your contract lives and how to connect to your database. It loads environment variables from `.env` automatically:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import 'dotenv/config';
|
|
45
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
46
|
+
import { defineConfig as ormConfig } from '{{configEntrypoint}}';
|
|
47
|
+
|
|
48
|
+
export default definePrismaConfig({
|
|
49
|
+
orm: ormConfig({
|
|
50
|
+
contract: './{{schemaPath}}',
|
|
51
|
+
db: {
|
|
52
|
+
connection: process.env['DATABASE_URL']!,
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Notice the `DATABASE_URL` above? It's defined in your [`.env`](./.env) file:
|
|
59
|
+
|
|
60
|
+
```env
|
|
61
|
+
DATABASE_URL="mongodb://localhost:27017/mydb"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can customize how your environment variables are loaded by changing or removing the `import 'dotenv/config'` line.
|
|
65
|
+
|
|
66
|
+
## Quick reference
|
|
67
|
+
|
|
68
|
+
### Commands
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
{{pkgRun}} contract emit # Update contract.json and contract.d.ts
|
|
72
|
+
{{pkgRun}} db init # Create collections in the database
|
|
73
|
+
{{pkgRun}} migration status # Show migration status
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Files
|
|
77
|
+
|
|
78
|
+
| File | Purpose |
|
|
79
|
+
|---|---|
|
|
80
|
+
| [`{{schemaPath}}`]({{schemaPath}}) | Your data contract — define your models here |
|
|
81
|
+
| [`prisma.config.ts`](prisma.config.ts) | CLI configuration |
|
|
82
|
+
| [`{{schemaDir}}/db.ts`]({{schemaDir}}/db.ts) | Database client — `import { db } from '{{dbImportPath}}'` |
|
|
83
|
+
| `{{schemaDir}}/contract.json` | Compiled contract (generated) |
|
|
84
|
+
| `{{schemaDir}}/contract.d.ts` | Contract types (generated) |
|
|
85
|
+
|
|
86
|
+
### Workflow
|
|
87
|
+
|
|
88
|
+
1. Edit [`{{schemaPath}}`]({{schemaPath}}) to add or change models.
|
|
89
|
+
2. Run `{{pkgRun}} contract emit` to regenerate the contract.
|
|
90
|
+
3. Query your models — your IDE will autocomplete everything.
|
|
91
|
+
|
|
92
|
+
## Transactions and change streams (Mongo)
|
|
93
|
+
|
|
94
|
+
Multi-document transactions and change streams require MongoDB to run as a **replica set** — even single-node setups for development. A standalone `mongod` will reject `withTransaction()` at runtime. For local development you have a few options:
|
|
95
|
+
|
|
96
|
+
- **Docker Compose:** start `mongo` with `--replSet rs0` and run `rs.initiate()` once.
|
|
97
|
+
- **`mongodb-memory-server`:** use `MongoMemoryReplSet` instead of `MongoMemoryServer` in tests.
|
|
98
|
+
- **MongoDB Atlas:** every Atlas cluster is already a replica set.
|
|
99
|
+
|
|
100
|
+
The transaction API (`db.transaction(...)`) is on the roadmap and tracked under [TML-2313](https://linear.app/prisma-company/issue/TML-2313/mongo-dev-replica-set-story-is-missing-transactions-change-streams). Prisma ORM's Mongo facade does not expose it yet — until that ticket lands, drive transactions yourself with a raw `MongoClient` using the escape hatch in the next section.
|
|
101
|
+
|
|
102
|
+
## Escape hatches
|
|
103
|
+
|
|
104
|
+
The ORM covers the common cases. For the rest, two escape hatches are designed in:
|
|
105
|
+
|
|
106
|
+
- **Typed raw aggregations — `db.query`.** The facade exposes `db.query`, a typed builder for aggregation pipelines that runs through the same runtime + middleware + codec stack as `db.orm`. Reach for it when the ORM can't express a `$lookup`/`$facet`/`$graphLookup`/window-function pipeline.
|
|
107
|
+
- **Direct `mongodb` driver control — `mongoClient` binding.** Construct your own `MongoClient` and pass it to `mongo({ contract, mongoClient, dbName })`. Your code keeps the `MongoClient` reference and uses it directly (transactions, change streams, sessions, anything Prisma ORM doesn't surface yet); the same `db` object continues to give you the typed ORM.
|
|
108
|
+
|
|
109
|
+
`db.runtime()` is **not** the escape hatch — it returns the internal executor (`MongoRuntime`), not a `mongodb` `MongoClient` or `Db`. Use `db.query` for raw aggregations and the `mongoClient` binding for direct driver control.
|
|
110
|
+
|
|
111
|
+
## Monorepo notes (pnpm workspaces)
|
|
112
|
+
|
|
113
|
+
If this project lives inside a pnpm workspace, a few things are worth knowing:
|
|
114
|
+
|
|
115
|
+
- **Catalogs.** When the workspace's `pnpm-workspace.yaml` defines a `catalogs` entry for `prisma` or `{{pkg}}`, pnpm uses the catalog version everywhere — `init` does too. If you wanted the published `latest` instead, update or remove the catalog entry, then re-run `pnpm install`.
|
|
116
|
+
- **`pnpm dlx`.** `pnpm dlx prisma@latest orm init …` works in any directory. Inside a workspace, pnpm still resolves dependencies through the workspace's catalog/overrides rather than the registry; expect the installed Prisma ORM packages to reflect the workspace's catalog rather than `latest`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
Generated by `prisma orm init` with the Minimal template.
|
|
4
|
+
|
|
5
|
+
## First run
|
|
6
|
+
|
|
7
|
+
1. `{{runDbUp}}` — start the local MongoDB replica set with `mongodb-memory-server`. Data persists in `.mongo-data/` across restarts.
|
|
8
|
+
2. `{{runDev}}` — runs `src/index.ts`, which writes one row and reads it back.
|
|
9
|
+
|
|
10
|
+
## Available scripts
|
|
11
|
+
|
|
12
|
+
- `{{runDev}}` — run the Prisma ORM sample script
|
|
13
|
+
|
|
14
|
+
### Database and migrations
|
|
15
|
+
|
|
16
|
+
- `{{runContractEmit}}` — emit contract artifacts after contract changes
|
|
17
|
+
- `{{runDbUp}}` — start the local MongoDB replica set with `mongodb-memory-server`. Data persists in `.mongo-data/` across restarts.
|
|
18
|
+
- `{{runDbDown}}` — stop the local MongoDB process (data preserved)
|
|
19
|
+
- `{{runDbReset}}` — stop and wipe `.mongo-data/` for a clean slate
|
|
20
|
+
- `{{runMigrationPlan}}` — create a MongoDB migration plan
|
|
21
|
+
- `{{runMigrate}}` — apply the planned MongoDB migration
|
|
22
|
+
- `{{runDbSeed}}` — insert sample users manually
|
|
23
|
+
|
|
24
|
+
## Prisma ORM
|
|
25
|
+
|
|
26
|
+
Prisma ORM setup is scaffolded in:
|
|
27
|
+
|
|
28
|
+
- `{{contractPath}}`
|
|
29
|
+
- `prisma.config.ts`
|
|
30
|
+
- `prisma/db.ts`
|
|
31
|
+
- `src/lib/prisma.ts`
|
|
32
|
+
|
|
33
|
+
For provider-specific Prisma ORM reference docs, see `prisma-8.md`. Prisma ORM skills live in the upstream `skills/` directory: https://github.com/prisma/prisma/tree/main/skills.
|
|
34
|
+
|
|
35
|
+
Node-based Prisma ORM projects expect Node.js 24 LTS or newer.
|
package/dist/init.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InitContribution } from "@prisma/orm-toolchain/cli/init-contribution";
|
|
2
|
+
//#region ../../../3-targets/mongo/9-facade/dist/init.d.mts
|
|
3
|
+
//#region src/init/init-contribution.d.ts
|
|
4
|
+
declare const contribution: InitContribution;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { contribution as default };
|
|
7
|
+
//# sourceMappingURL=init.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.mts","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/init.d.mts"],"mappings":";;;cAEc,cAAc"}
|
package/dist/init.mjs
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { t as moduleBase } from "./module-base-B70DHaBE-k_c3Klu4.mjs";
|
|
2
|
+
import { dirname, join } from "pathe";
|
|
3
|
+
import { MONGO_MIN_SERVER_VERSION } from "@prisma/orm-target-mongo/target/server-version";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
//#region ../../../3-targets/mongo/9-facade/dist/init.mjs
|
|
6
|
+
/**
|
|
7
|
+
* The driver's own deadlines, which every 7.x driver honours: `serverSelectionTimeoutMS` for finding
|
|
8
|
+
* a server, `connectTimeoutMS` for opening the connection and its handshake, and `socketTimeoutMS`
|
|
9
|
+
* for a reply, so an unreachable server or a stalled `buildInfo` rejects instead of hanging. Not
|
|
10
|
+
* `timeoutMS`: the driver ignores it from 7.8 on.
|
|
11
|
+
*/
|
|
12
|
+
const PROBE_TIMEOUT_MS = 2e4;
|
|
13
|
+
function isModuleNotFound(error) {
|
|
14
|
+
return error instanceof Error && Reflect.get(error, "code") === "ERR_MODULE_NOT_FOUND";
|
|
15
|
+
}
|
|
16
|
+
function causeMessage(error) {
|
|
17
|
+
return error instanceof Error ? error.message : String(error);
|
|
18
|
+
}
|
|
19
|
+
async function probeMongo(databaseUrl, signal, loadDriver = () => import("mongodb")) {
|
|
20
|
+
let mongodb;
|
|
21
|
+
try {
|
|
22
|
+
mongodb = await loadDriver();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
kind: isModuleNotFound(error) ? "driver-missing" : "driver-failed",
|
|
26
|
+
driver: "mongodb",
|
|
27
|
+
cause: causeMessage(error)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const client = new mongodb.MongoClient(databaseUrl, {
|
|
31
|
+
serverSelectionTimeoutMS: PROBE_TIMEOUT_MS,
|
|
32
|
+
connectTimeoutMS: PROBE_TIMEOUT_MS,
|
|
33
|
+
socketTimeoutMS: PROBE_TIMEOUT_MS
|
|
34
|
+
});
|
|
35
|
+
const closeOnAbort = () => {
|
|
36
|
+
client.close().catch(() => void 0);
|
|
37
|
+
};
|
|
38
|
+
signal.addEventListener("abort", closeOnAbort, { once: true });
|
|
39
|
+
try {
|
|
40
|
+
await client.connect();
|
|
41
|
+
let buildInfo;
|
|
42
|
+
try {
|
|
43
|
+
buildInfo = await client.db().admin().command({ buildInfo: 1 });
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
kind: "version-unreadable",
|
|
47
|
+
detail: `buildInfo failed: ${causeMessage(error)}`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const versionString = String(buildInfo["version"] ?? "");
|
|
51
|
+
return versionString.length === 0 ? {
|
|
52
|
+
kind: "version-unreadable",
|
|
53
|
+
detail: "buildInfo did not include a `version` field"
|
|
54
|
+
} : {
|
|
55
|
+
kind: "server-version",
|
|
56
|
+
serverVersion: versionString
|
|
57
|
+
};
|
|
58
|
+
} finally {
|
|
59
|
+
signal.removeEventListener("abort", closeOnAbort);
|
|
60
|
+
await client.close().catch(() => void 0);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fills each `{{name}}` of the template in one pass, so a value is inserted as it is: a value
|
|
65
|
+
* holding `$&` or another placeholder is not read again.
|
|
66
|
+
*/
|
|
67
|
+
function renderTemplate(templateFile, vars) {
|
|
68
|
+
return readFileSync(join(import.meta.dirname, templateFile), "utf-8").replace(/\{\{(\w+)\}\}/g, (placeholder, name) => Object.hasOwn(vars, name) ? vars[name] ?? placeholder : placeholder);
|
|
69
|
+
}
|
|
70
|
+
const configModule = `${moduleBase}/config`;
|
|
71
|
+
const builder = `${moduleBase}/contract-builder`;
|
|
72
|
+
function starterContract(mode) {
|
|
73
|
+
return mode === "typescript" ? starterContractTs() : starterContractPsl();
|
|
74
|
+
}
|
|
75
|
+
function contractSample(mode) {
|
|
76
|
+
return mode === "typescript" ? contractSampleTs() : contractSamplePsl();
|
|
77
|
+
}
|
|
78
|
+
function contractSamplePsl() {
|
|
79
|
+
return `\`\`\`prisma
|
|
80
|
+
model User {
|
|
81
|
+
id ObjectId @id @map("_id")
|
|
82
|
+
email String @unique
|
|
83
|
+
username String?
|
|
84
|
+
name String?
|
|
85
|
+
@@map("users")
|
|
86
|
+
}
|
|
87
|
+
\`\`\``;
|
|
88
|
+
}
|
|
89
|
+
function contractSampleTs() {
|
|
90
|
+
return `\`\`\`typescript
|
|
91
|
+
import { defineContract } from '${builder}';
|
|
92
|
+
|
|
93
|
+
export const contract = defineContract(
|
|
94
|
+
{},
|
|
95
|
+
({ field, model, type }) => ({
|
|
96
|
+
models: {
|
|
97
|
+
User: model('User', {
|
|
98
|
+
collection: 'users',
|
|
99
|
+
fields: {
|
|
100
|
+
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
101
|
+
email: field.scalar(type.String()),
|
|
102
|
+
username: field.scalar(type.String()).optional(),
|
|
103
|
+
name: field.scalar(type.String()).optional(),
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
\`\`\``;
|
|
110
|
+
}
|
|
111
|
+
function starterContractPsl() {
|
|
112
|
+
return `// use prisma-8
|
|
113
|
+
|
|
114
|
+
model User {
|
|
115
|
+
id ObjectId @id @map("_id")
|
|
116
|
+
email String @unique
|
|
117
|
+
username String?
|
|
118
|
+
name String?
|
|
119
|
+
posts Post[]
|
|
120
|
+
@@map("users")
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
model Post {
|
|
124
|
+
id ObjectId @id @map("_id")
|
|
125
|
+
title String
|
|
126
|
+
content String?
|
|
127
|
+
author User @relation(fields: [authorId], references: [id])
|
|
128
|
+
authorId ObjectId
|
|
129
|
+
@@map("posts")
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
function starterContractTs() {
|
|
134
|
+
return `import { defineContract } from '${builder}';
|
|
135
|
+
|
|
136
|
+
export const contract = defineContract(
|
|
137
|
+
{},
|
|
138
|
+
({ field, model, rel, type }) => ({
|
|
139
|
+
models: {
|
|
140
|
+
User: model('User', {
|
|
141
|
+
collection: 'users',
|
|
142
|
+
fields: {
|
|
143
|
+
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
144
|
+
email: field.scalar(type.String()),
|
|
145
|
+
username: field.scalar(type.String()).optional(),
|
|
146
|
+
name: field.scalar(type.String()).optional(),
|
|
147
|
+
},
|
|
148
|
+
relations: {
|
|
149
|
+
posts: rel.hasMany('Post', { from: 'id', to: 'authorId' }),
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
|
|
153
|
+
Post: model('Post', {
|
|
154
|
+
collection: 'posts',
|
|
155
|
+
fields: {
|
|
156
|
+
id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),
|
|
157
|
+
title: field.scalar(type.String()),
|
|
158
|
+
content: field.scalar(type.String()).optional(),
|
|
159
|
+
authorId: field.scalar(type.ObjectId()),
|
|
160
|
+
},
|
|
161
|
+
relations: {
|
|
162
|
+
author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
function databaseFile() {
|
|
171
|
+
return `import 'dotenv/config';
|
|
172
|
+
import mongo from '${moduleBase}/runtime';
|
|
173
|
+
import { contractFromJson } from '${moduleBase}/static';
|
|
174
|
+
import type { Contract } from './contract.d.js';
|
|
175
|
+
import contractJson from './contract.json' with { type: 'json' };
|
|
176
|
+
|
|
177
|
+
export const contract = contractFromJson<Contract>(contractJson);
|
|
178
|
+
|
|
179
|
+
export const db = mongo({
|
|
180
|
+
contract,
|
|
181
|
+
url: process.env['DATABASE_URL']!,
|
|
182
|
+
});
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
function envExample() {
|
|
186
|
+
return [
|
|
187
|
+
"# Connection string for MongoDB.",
|
|
188
|
+
`# Requires MongoDB >= ${MONGO_MIN_SERVER_VERSION}.`,
|
|
189
|
+
"",
|
|
190
|
+
"# Standalone local mongod / `docker run mongo:8` — no replica set required for first-run queries.",
|
|
191
|
+
"# Transactions and change streams need a replica set; add ?replicaSet=... only after initiating one.",
|
|
192
|
+
"",
|
|
193
|
+
"DATABASE_URL=\"mongodb://user:password@localhost:27017/mydb\"",
|
|
194
|
+
""
|
|
195
|
+
].join("\n");
|
|
196
|
+
}
|
|
197
|
+
function quickReference(input) {
|
|
198
|
+
const schemaDir = dirname(input.schemaPath);
|
|
199
|
+
return renderTemplate("init-quick-reference.md", {
|
|
200
|
+
schemaPath: input.schemaPath,
|
|
201
|
+
schemaDir,
|
|
202
|
+
dbImportPath: `./${schemaDir}/db`,
|
|
203
|
+
pkgRun: input.cliCommand,
|
|
204
|
+
pkg: moduleBase,
|
|
205
|
+
configEntrypoint: configModule,
|
|
206
|
+
schemaSample: contractSample(input.mode),
|
|
207
|
+
requirements: input.requirements
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function readme(input) {
|
|
211
|
+
const run = input.runScript;
|
|
212
|
+
return renderTemplate("init-readme.md", {
|
|
213
|
+
projectName: input.projectName,
|
|
214
|
+
contractPath: input.contractPath,
|
|
215
|
+
runDev: run("dev"),
|
|
216
|
+
runContractEmit: run("contract:emit"),
|
|
217
|
+
runDbUp: run("db:up"),
|
|
218
|
+
runDbDown: run("db:down"),
|
|
219
|
+
runDbReset: run("db:reset"),
|
|
220
|
+
runMigrationPlan: run("migration:plan"),
|
|
221
|
+
runMigrate: run("migrate"),
|
|
222
|
+
runDbSeed: run("db:seed")
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const contribution = {
|
|
226
|
+
label: "MongoDB",
|
|
227
|
+
configModule,
|
|
228
|
+
peerPackages: ["mongodb"],
|
|
229
|
+
authoringModes: ["psl", "typescript"],
|
|
230
|
+
starterContract,
|
|
231
|
+
contractSample,
|
|
232
|
+
databaseFile,
|
|
233
|
+
envExample,
|
|
234
|
+
quickReference,
|
|
235
|
+
readme,
|
|
236
|
+
serverRequirement: {
|
|
237
|
+
minVersion: MONGO_MIN_SERVER_VERSION,
|
|
238
|
+
checkCommand: "db.runCommand({ buildInfo: 1 })"
|
|
239
|
+
},
|
|
240
|
+
probe: (databaseUrl, signal) => probeMongo(databaseUrl, signal)
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { contribution as default };
|
|
244
|
+
|
|
245
|
+
//# sourceMappingURL=init.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/init.mjs"],"sourcesContent":["import { t as moduleBase } from \"./module-base-B70DHaBE.mjs\";\nimport { dirname, join } from \"pathe\";\nimport { MONGO_MIN_SERVER_VERSION } from \"@internal/target-mongo/server-version\";\nimport { readFileSync } from \"node:fs\";\n//#region src/init/probe.ts\n/**\n* The driver's own deadlines, which every 7.x driver honours: `serverSelectionTimeoutMS` for finding\n* a server, `connectTimeoutMS` for opening the connection and its handshake, and `socketTimeoutMS`\n* for a reply, so an unreachable server or a stalled `buildInfo` rejects instead of hanging. Not\n* `timeoutMS`: the driver ignores it from 7.8 on.\n*/\nconst PROBE_TIMEOUT_MS = 2e4;\nfunction isModuleNotFound(error) {\n\treturn error instanceof Error && Reflect.get(error, \"code\") === \"ERR_MODULE_NOT_FOUND\";\n}\nfunction causeMessage(error) {\n\treturn error instanceof Error ? error.message : String(error);\n}\nasync function probeMongo(databaseUrl, signal, loadDriver = () => import(\"mongodb\")) {\n\tlet mongodb;\n\ttry {\n\t\tmongodb = await loadDriver();\n\t} catch (error) {\n\t\treturn {\n\t\t\tkind: isModuleNotFound(error) ? \"driver-missing\" : \"driver-failed\",\n\t\t\tdriver: \"mongodb\",\n\t\t\tcause: causeMessage(error)\n\t\t};\n\t}\n\tconst client = new mongodb.MongoClient(databaseUrl, {\n\t\tserverSelectionTimeoutMS: PROBE_TIMEOUT_MS,\n\t\tconnectTimeoutMS: PROBE_TIMEOUT_MS,\n\t\tsocketTimeoutMS: PROBE_TIMEOUT_MS\n\t});\n\tconst closeOnAbort = () => {\n\t\tclient.close().catch(() => void 0);\n\t};\n\tsignal.addEventListener(\"abort\", closeOnAbort, { once: true });\n\ttry {\n\t\tawait client.connect();\n\t\tlet buildInfo;\n\t\ttry {\n\t\t\tbuildInfo = await client.db().admin().command({ buildInfo: 1 });\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tkind: \"version-unreadable\",\n\t\t\t\tdetail: `buildInfo failed: ${causeMessage(error)}`\n\t\t\t};\n\t\t}\n\t\tconst versionString = String(buildInfo[\"version\"] ?? \"\");\n\t\treturn versionString.length === 0 ? {\n\t\t\tkind: \"version-unreadable\",\n\t\t\tdetail: \"buildInfo did not include a `version` field\"\n\t\t} : {\n\t\t\tkind: \"server-version\",\n\t\t\tserverVersion: versionString\n\t\t};\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", closeOnAbort);\n\t\tawait client.close().catch(() => void 0);\n\t}\n}\n//#endregion\n//#region src/init/render.ts\n/**\n* Fills each `{{name}}` of the template in one pass, so a value is inserted as it is: a value\n* holding `$&` or another placeholder is not read again.\n*/\nfunction renderTemplate(templateFile, vars) {\n\treturn readFileSync(join(import.meta.dirname, templateFile), \"utf-8\").replace(/\\{\\{(\\w+)\\}\\}/g, (placeholder, name) => Object.hasOwn(vars, name) ? vars[name] ?? placeholder : placeholder);\n}\n//#endregion\n//#region src/init/templates.ts\nconst configModule = `${moduleBase}/config`;\nconst builder = `${moduleBase}/contract-builder`;\nfunction starterContract(mode) {\n\treturn mode === \"typescript\" ? starterContractTs() : starterContractPsl();\n}\nfunction contractSample(mode) {\n\treturn mode === \"typescript\" ? contractSampleTs() : contractSamplePsl();\n}\nfunction contractSamplePsl() {\n\treturn `\\`\\`\\`prisma\nmodel User {\n id ObjectId @id @map(\"_id\")\n email String @unique\n username String?\n name String?\n @@map(\"users\")\n}\n\\`\\`\\``;\n}\nfunction contractSampleTs() {\n\treturn `\\`\\`\\`typescript\nimport { defineContract } from '${builder}';\n\nexport const contract = defineContract(\n {},\n ({ field, model, type }) => ({\n models: {\n User: model('User', {\n collection: 'users',\n fields: {\n id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),\n email: field.scalar(type.String()),\n username: field.scalar(type.String()).optional(),\n name: field.scalar(type.String()).optional(),\n },\n }),\n },\n }),\n);\n\\`\\`\\``;\n}\nfunction starterContractPsl() {\n\treturn `// use prisma-8\n\nmodel User {\n id ObjectId @id @map(\"_id\")\n email String @unique\n username String?\n name String?\n posts Post[]\n @@map(\"users\")\n}\n\nmodel Post {\n id ObjectId @id @map(\"_id\")\n title String\n content String?\n author User @relation(fields: [authorId], references: [id])\n authorId ObjectId\n @@map(\"posts\")\n}\n`;\n}\nfunction starterContractTs() {\n\treturn `import { defineContract } from '${builder}';\n\nexport const contract = defineContract(\n {},\n ({ field, model, rel, type }) => ({\n models: {\n User: model('User', {\n collection: 'users',\n fields: {\n id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),\n email: field.scalar(type.String()),\n username: field.scalar(type.String()).optional(),\n name: field.scalar(type.String()).optional(),\n },\n relations: {\n posts: rel.hasMany('Post', { from: 'id', to: 'authorId' }),\n },\n }),\n\n Post: model('Post', {\n collection: 'posts',\n fields: {\n id: field.scalar(type.ObjectId()).mongo({ field: '_id' }),\n title: field.scalar(type.String()),\n content: field.scalar(type.String()).optional(),\n authorId: field.scalar(type.ObjectId()),\n },\n relations: {\n author: rel.belongsTo('User', { from: 'authorId', to: 'id' }),\n },\n }),\n },\n }),\n);\n`;\n}\nfunction databaseFile() {\n\treturn `import 'dotenv/config';\nimport mongo from '${moduleBase}/runtime';\nimport { contractFromJson } from '${moduleBase}/static';\nimport type { Contract } from './contract.d.js';\nimport contractJson from './contract.json' with { type: 'json' };\n\nexport const contract = contractFromJson<Contract>(contractJson);\n\nexport const db = mongo({\n contract,\n url: process.env['DATABASE_URL']!,\n});\n`;\n}\nfunction envExample() {\n\treturn [\n\t\t\"# Connection string for MongoDB.\",\n\t\t`# Requires MongoDB >= ${MONGO_MIN_SERVER_VERSION}.`,\n\t\t\"\",\n\t\t\"# Standalone local mongod / `docker run mongo:8` — no replica set required for first-run queries.\",\n\t\t\"# Transactions and change streams need a replica set; add ?replicaSet=... only after initiating one.\",\n\t\t\"\",\n\t\t\"DATABASE_URL=\\\"mongodb://user:password@localhost:27017/mydb\\\"\",\n\t\t\"\"\n\t].join(\"\\n\");\n}\n//#endregion\n//#region src/init/init-contribution.ts\nfunction quickReference(input) {\n\tconst schemaDir = dirname(input.schemaPath);\n\treturn renderTemplate(\"init-quick-reference.md\", {\n\t\tschemaPath: input.schemaPath,\n\t\tschemaDir,\n\t\tdbImportPath: `./${schemaDir}/db`,\n\t\tpkgRun: input.cliCommand,\n\t\tpkg: moduleBase,\n\t\tconfigEntrypoint: configModule,\n\t\tschemaSample: contractSample(input.mode),\n\t\trequirements: input.requirements\n\t});\n}\nfunction readme(input) {\n\tconst run = input.runScript;\n\treturn renderTemplate(\"init-readme.md\", {\n\t\tprojectName: input.projectName,\n\t\tcontractPath: input.contractPath,\n\t\trunDev: run(\"dev\"),\n\t\trunContractEmit: run(\"contract:emit\"),\n\t\trunDbUp: run(\"db:up\"),\n\t\trunDbDown: run(\"db:down\"),\n\t\trunDbReset: run(\"db:reset\"),\n\t\trunMigrationPlan: run(\"migration:plan\"),\n\t\trunMigrate: run(\"migrate\"),\n\t\trunDbSeed: run(\"db:seed\")\n\t});\n}\nconst contribution = {\n\tlabel: \"MongoDB\",\n\tconfigModule,\n\tpeerPackages: [\"mongodb\"],\n\tauthoringModes: [\"psl\", \"typescript\"],\n\tstarterContract,\n\tcontractSample,\n\tdatabaseFile,\n\tenvExample,\n\tquickReference,\n\treadme,\n\tserverRequirement: {\n\t\tminVersion: MONGO_MIN_SERVER_VERSION,\n\t\tcheckCommand: \"db.runCommand({ buildInfo: 1 })\"\n\t},\n\tprobe: (databaseUrl, signal) => probeMongo(databaseUrl, signal)\n};\n//#endregion\nexport { contribution as default };\n\n//# sourceMappingURL=init.mjs.map"],"mappings":";;;;;;;;;;;AAWA,MAAM,mBAAmB;AACzB,SAAS,iBAAiB,OAAO;CAChC,OAAO,iBAAiB,SAAS,QAAQ,IAAI,OAAO,MAAM,MAAM;AACjE;AACA,SAAS,aAAa,OAAO;CAC5B,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;AACA,eAAe,WAAW,aAAa,QAAQ,mBAAmB,OAAO,YAAY;CACpF,IAAI;CACJ,IAAI;EACH,UAAU,MAAM,WAAW;CAC5B,SAAS,OAAO;EACf,OAAO;GACN,MAAM,iBAAiB,KAAK,IAAI,mBAAmB;GACnD,QAAQ;GACR,OAAO,aAAa,KAAK;EAC1B;CACD;CACA,MAAM,SAAS,IAAI,QAAQ,YAAY,aAAa;EACnD,0BAA0B;EAC1B,kBAAkB;EAClB,iBAAiB;CAClB,CAAC;CACD,MAAM,qBAAqB;EAC1B,OAAO,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC;CAClC;CACA,OAAO,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK,CAAC;CAC7D,IAAI;EACH,MAAM,OAAO,QAAQ;EACrB,IAAI;EACJ,IAAI;GACH,YAAY,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;EAC/D,SAAS,OAAO;GACf,OAAO;IACN,MAAM;IACN,QAAQ,qBAAqB,aAAa,KAAK;GAChD;EACD;EACA,MAAM,gBAAgB,OAAO,UAAU,cAAc,EAAE;EACvD,OAAO,cAAc,WAAW,IAAI;GACnC,MAAM;GACN,QAAQ;EACT,IAAI;GACH,MAAM;GACN,eAAe;EAChB;CACD,UAAU;EACT,OAAO,oBAAoB,SAAS,YAAY;EAChD,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC;CACxC;AACD;;;;;AAOA,SAAS,eAAe,cAAc,MAAM;CAC3C,OAAO,aAAa,KAAK,OAAO,KAAK,SAAS,YAAY,GAAG,OAAO,CAAC,CAAC,QAAQ,mBAAmB,aAAa,SAAS,OAAO,OAAO,MAAM,IAAI,IAAI,KAAK,SAAS,cAAc,WAAW;AAC3L;AAGA,MAAM,eAAe,GAAG,WAAW;AACnC,MAAM,UAAU,GAAG,WAAW;AAC9B,SAAS,gBAAgB,MAAM;CAC9B,OAAO,SAAS,eAAe,kBAAkB,IAAI,mBAAmB;AACzE;AACA,SAAS,eAAe,MAAM;CAC7B,OAAO,SAAS,eAAe,iBAAiB,IAAI,kBAAkB;AACvE;AACA,SAAS,oBAAoB;CAC5B,OAAO;;;;;;;;;AASR;AACA,SAAS,mBAAmB;CAC3B,OAAO;kCAC0B,QAAQ;;;;;;;;;;;;;;;;;;;AAmB1C;AACA,SAAS,qBAAqB;CAC7B,OAAO;;;;;;;;;;;;;;;;;;;;AAoBR;AACA,SAAS,oBAAoB;CAC5B,OAAO,mCAAmC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCnD;AACA,SAAS,eAAe;CACvB,OAAO;qBACa,WAAW;oCACI,WAAW;;;;;;;;;;;AAW/C;AACA,SAAS,aAAa;CACrB,OAAO;EACN;EACA,yBAAyB,yBAAyB;EAClD;EACA;EACA;EACA;EACA;EACA;CACD,CAAC,CAAC,KAAK,IAAI;AACZ;AAGA,SAAS,eAAe,OAAO;CAC9B,MAAM,YAAY,QAAQ,MAAM,UAAU;CAC1C,OAAO,eAAe,2BAA2B;EAChD,YAAY,MAAM;EAClB;EACA,cAAc,KAAK,UAAU;EAC7B,QAAQ,MAAM;EACd,KAAK;EACL,kBAAkB;EAClB,cAAc,eAAe,MAAM,IAAI;EACvC,cAAc,MAAM;CACrB,CAAC;AACF;AACA,SAAS,OAAO,OAAO;CACtB,MAAM,MAAM,MAAM;CAClB,OAAO,eAAe,kBAAkB;EACvC,aAAa,MAAM;EACnB,cAAc,MAAM;EACpB,QAAQ,IAAI,KAAK;EACjB,iBAAiB,IAAI,eAAe;EACpC,SAAS,IAAI,OAAO;EACpB,WAAW,IAAI,SAAS;EACxB,YAAY,IAAI,UAAU;EAC1B,kBAAkB,IAAI,gBAAgB;EACtC,YAAY,IAAI,SAAS;EACzB,WAAW,IAAI,SAAS;CACzB,CAAC;AACF;AACA,MAAM,eAAe;CACpB,OAAO;CACP;CACA,cAAc,CAAC,SAAS;CACxB,gBAAgB,CAAC,OAAO,YAAY;CACpC;CACA;CACA;CACA;CACA;CACA;CACA,mBAAmB;EAClB,YAAY;EACZ,cAAc;CACf;CACA,QAAQ,aAAa,WAAW,WAAW,aAAa,MAAM;AAC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@prisma/orm-target-mongo/target/migration";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-base-B70DHaBE-k_c3Klu4.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/module-base-B70DHaBE.mjs"],"sourcesContent":["//#region src/config/module-base.ts\nconst moduleBase = typeof __PRISMA_PUBLISHED_MODULE_BASE__MONGO === \"string\" ? __PRISMA_PUBLISHED_MODULE_BASE__MONGO : \"@internal/mongo\";\n//#endregion\nexport { moduleBase as t };\n\n//# sourceMappingURL=module-base-B70DHaBE.mjs.map"],"mappings":";AACA,MAAM,aAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import mongoRuntimeAdapter from "@prisma/orm-target-mongo/adapter/runtime";
|
|
2
|
+
import { mongoRaw } from "@prisma/orm-family-mongo/orm";
|
|
3
|
+
import { createMongoExecutionContext, createMongoExecutionStack, enumMemberCodecFor } from "@prisma/orm-family-mongo/runtime";
|
|
4
|
+
import mongoRuntimeTarget from "@prisma/orm-target-mongo/target/runtime";
|
|
5
|
+
import { isContractBuiltInMemory } from "@prisma/orm-framework/contract/internal/format-version";
|
|
6
|
+
import { validateContractOnce } from "@prisma/orm-framework/contract/validate-once";
|
|
7
|
+
import { MongoContractSerializer } from "@prisma/orm-family-mongo/family/ir";
|
|
8
|
+
import { buildNamespacedEnums } from "@prisma/orm-framework/contract/enum-accessor";
|
|
9
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
10
|
+
import { mongoQuery } from "@prisma/orm-family-mongo/query-builder";
|
|
11
|
+
import { assertDefined } from "@prisma/orm-framework/utils/assertions";
|
|
12
|
+
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-BrplLPTr.mjs
|
|
13
|
+
var version = "8.0.1-dev.2";
|
|
14
|
+
const serializer = new MongoContractSerializer();
|
|
15
|
+
const validator = `${mongoRuntimeTarget.targetId}@${version}`;
|
|
16
|
+
/**
|
|
17
|
+
* Validates an emitted Mongo `contract.json` and returns it as the contract type the application
|
|
18
|
+
* names, ready to pass to `mongo({ contract })` and `mongoStatic({ contract })`. Clients built from
|
|
19
|
+
* the result do not validate it again.
|
|
20
|
+
*
|
|
21
|
+
* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the
|
|
22
|
+
* returned value after the call: clients built from the value later do not validate it again.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import type { Contract } from './contract.d';
|
|
27
|
+
* import contractJson from './contract.json' with { type: 'json' };
|
|
28
|
+
*
|
|
29
|
+
* export const contract = contractFromJson<Contract>(contractJson);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function contractFromJson(json) {
|
|
33
|
+
return validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));
|
|
34
|
+
}
|
|
35
|
+
/** Validates a contract value for a Mongo client, once per value. */
|
|
36
|
+
function validateMongoContract(contract) {
|
|
37
|
+
return validateContractOnce(contract, validator, () => serializer.deserializeContract(isContractBuiltInMemory(contract) ? serializer.serializeContract(contract) : contract));
|
|
38
|
+
}
|
|
39
|
+
function buildMongoStaticContext(contract, stack) {
|
|
40
|
+
const context = createMongoExecutionContext({
|
|
41
|
+
contract,
|
|
42
|
+
stack
|
|
43
|
+
});
|
|
44
|
+
const enums = Object.freeze(buildNamespacedEnums(context.contract.domain, enumMemberCodecFor(context.codecs)))[UNBOUND_NAMESPACE_ID];
|
|
45
|
+
assertDefined(enums, "the unbound namespace always exists on a mongo builder output");
|
|
46
|
+
return {
|
|
47
|
+
context,
|
|
48
|
+
contract,
|
|
49
|
+
enums,
|
|
50
|
+
query: mongoQuery({ context }),
|
|
51
|
+
raw: mongoRaw({ context })
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The query surfaces of a Mongo client without a driver: `query`, `raw` and `enums`. Use it where
|
|
56
|
+
* loading `mongodb` is not wanted.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { enums } = mongoStatic({ contract: contractFromJson<Contract>(contractJson) });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function mongoStatic(options) {
|
|
64
|
+
const stack = createMongoExecutionStack({
|
|
65
|
+
target: mongoRuntimeTarget,
|
|
66
|
+
adapter: mongoRuntimeAdapter,
|
|
67
|
+
extensions: options.extensions ?? []
|
|
68
|
+
});
|
|
69
|
+
return buildMongoStaticContext(validateMongoContract(options.contract), stack);
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { validateMongoContract as i, contractFromJson as n, mongoStatic as r, buildMongoStaticContext as t };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=mongo-static-BrplLPTr-DGOk19X8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-static-BrplLPTr-DGOk19X8.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-BrplLPTr.mjs"],"sourcesContent":["import mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport { mongoRaw } from \"@internal/mongo-orm\";\nimport { createMongoExecutionContext, createMongoExecutionStack, enumMemberCodecFor } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { isContractBuiltInMemory } from \"@internal/contract/internal/format-version\";\nimport { validateContractOnce } from \"@internal/contract/validate-once\";\nimport { MongoContractSerializer } from \"@internal/family-mongo/ir\";\nimport { buildNamespacedEnums } from \"@internal/contract/enum-accessor\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { mongoQuery } from \"@internal/mongo-query-builder\";\nimport { assertDefined } from \"@internal/utils/assertions\";\n//#region package.json\nvar version = \"8.0.1-dev.2\";\n//#endregion\n//#region src/static/contract-from-json.ts\nconst serializer = new MongoContractSerializer();\nconst validator = `${mongoRuntimeTarget.targetId}@${version}`;\n/**\n* Validates an emitted Mongo `contract.json` and returns it as the contract type the application\n* names, ready to pass to `mongo({ contract })` and `mongoStatic({ contract })`. Clients built from\n* the result do not validate it again.\n*\n* The returned value's top level is frozen; its nested objects are not. Do not change `json` or the\n* returned value after the call: clients built from the value later do not validate it again.\n*\n* @example\n* ```ts\n* import type { Contract } from './contract.d';\n* import contractJson from './contract.json' with { type: 'json' };\n*\n* export const contract = contractFromJson<Contract>(contractJson);\n* ```\n*/\nfunction contractFromJson(json) {\n\treturn validateContractOnce(json, validator, (input) => serializer.deserializeContract(input));\n}\n/** Validates a contract value for a Mongo client, once per value. */\nfunction validateMongoContract(contract) {\n\treturn validateContractOnce(contract, validator, () => serializer.deserializeContract(isContractBuiltInMemory(contract) ? serializer.serializeContract(contract) : contract));\n}\n//#endregion\n//#region src/static/mongo-static.ts\nfunction buildMongoStaticContext(contract, stack) {\n\tconst context = createMongoExecutionContext({\n\t\tcontract,\n\t\tstack\n\t});\n\tconst enums = Object.freeze(buildNamespacedEnums(context.contract.domain, enumMemberCodecFor(context.codecs)))[UNBOUND_NAMESPACE_ID];\n\tassertDefined(enums, \"the unbound namespace always exists on a mongo builder output\");\n\treturn {\n\t\tcontext,\n\t\tcontract,\n\t\tenums,\n\t\tquery: mongoQuery({ context }),\n\t\traw: mongoRaw({ context })\n\t};\n}\n/**\n* The query surfaces of a Mongo client without a driver: `query`, `raw` and `enums`. Use it where\n* loading `mongodb` is not wanted.\n*\n* @example\n* ```ts\n* const { enums } = mongoStatic({ contract: contractFromJson<Contract>(contractJson) });\n* ```\n*/\nfunction mongoStatic(options) {\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\textensions: options.extensions ?? []\n\t});\n\treturn buildMongoStaticContext(validateMongoContract(options.contract), stack);\n}\n//#endregion\nexport { validateMongoContract as i, mongoStatic as n, contractFromJson as r, buildMongoStaticContext as t };\n\n//# sourceMappingURL=mongo-static-BrplLPTr.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,IAAI,UAAU;AAGd,MAAM,aAAa,IAAI,wBAAwB;AAC/C,MAAM,YAAY,GAAG,mBAAmB,SAAS,GAAG;;;;;;;;;;;;;;;;;AAiBpD,SAAS,iBAAiB,MAAM;CAC/B,OAAO,qBAAqB,MAAM,YAAY,UAAU,WAAW,oBAAoB,KAAK,CAAC;AAC9F;;AAEA,SAAS,sBAAsB,UAAU;CACxC,OAAO,qBAAqB,UAAU,iBAAiB,WAAW,oBAAoB,wBAAwB,QAAQ,IAAI,WAAW,kBAAkB,QAAQ,IAAI,QAAQ,CAAC;AAC7K;AAGA,SAAS,wBAAwB,UAAU,OAAO;CACjD,MAAM,UAAU,4BAA4B;EAC3C;EACA;CACD,CAAC;CACD,MAAM,QAAQ,OAAO,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,mBAAmB,QAAQ,MAAM,CAAC,CAAC,CAAC,CAAC;CAC/G,cAAc,OAAO,+DAA+D;CACpF,OAAO;EACN;EACA;EACA;EACA,OAAO,WAAW,EAAE,QAAQ,CAAC;EAC7B,KAAK,SAAS,EAAE,QAAQ,CAAC;CAC1B;AACD;;;;;;;;;;AAUA,SAAS,YAAY,SAAS;CAC7B,MAAM,QAAQ,0BAA0B;EACvC,QAAQ;EACR,SAAS;EACT,YAAY,QAAQ,cAAc,CAAC;CACpC,CAAC;CACD,OAAO,wBAAwB,sBAAsB,QAAQ,QAAQ,GAAG,KAAK;AAC9E"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { MongoRawClient } from "@prisma/orm-family-mongo/orm";
|
|
2
|
-
import { MongoExecutionContext } from "@prisma/orm-family-mongo/runtime";
|
|
2
|
+
import { MongoExecutionContext, MongoRuntimeExtensionDescriptor } from "@prisma/orm-family-mongo/runtime";
|
|
3
3
|
import { NamespacedEnums } from "@prisma/orm-framework/contract/enum-accessor";
|
|
4
4
|
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
5
5
|
import { mongoQuery } from "@prisma/orm-family-mongo/query-builder";
|
|
6
6
|
import { AnyMongoTypeMaps, MongoContract, MongoContractWithTypeMaps } from "@prisma/orm-family-mongo/contract";
|
|
7
|
-
//#region ../../../3-
|
|
7
|
+
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-DabeBtmV.d.mts
|
|
8
|
+
//#region src/runtime/mongo-target-id.d.ts
|
|
9
|
+
type MongoTargetId = 'mongo';
|
|
10
|
+
//#endregion
|
|
8
11
|
//#region src/static/mongo-static.d.ts
|
|
9
12
|
type UnboundEnums<TContract extends MongoContractWithTypeMaps<MongoContract, AnyMongoTypeMaps>> = NamespacedEnums<TContract>[typeof UNBOUND_NAMESPACE_ID];
|
|
10
13
|
interface MongoStaticContext<TContract extends MongoContractWithTypeMaps<MongoContract, AnyMongoTypeMaps>> {
|
|
@@ -14,9 +17,19 @@ interface MongoStaticContext<TContract extends MongoContractWithTypeMaps<MongoCo
|
|
|
14
17
|
readonly query: ReturnType<typeof mongoQuery<TContract>>;
|
|
15
18
|
readonly raw: MongoRawClient<TContract>;
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The query surfaces of a Mongo client without a driver: `query`, `raw` and `enums`. Use it where
|
|
22
|
+
* loading `mongodb` is not wanted.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const { enums } = mongoStatic({ contract: contractFromJson<Contract>(contractJson) });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
17
29
|
declare function mongoStatic<TContract extends MongoContractWithTypeMaps<MongoContract, AnyMongoTypeMaps>>(options: {
|
|
18
|
-
readonly
|
|
30
|
+
readonly contract: TContract;
|
|
31
|
+
readonly extensions?: readonly MongoRuntimeExtensionDescriptor<MongoTargetId>[];
|
|
19
32
|
}): MongoStaticContext<TContract>;
|
|
20
33
|
//#endregion
|
|
21
|
-
export {
|
|
22
|
-
//# sourceMappingURL=mongo-static-
|
|
34
|
+
export { MongoTargetId as n, mongoStatic as r, MongoStaticContext as t };
|
|
35
|
+
//# sourceMappingURL=mongo-static-DabeBtmV-DILuhcbE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-static-DabeBtmV-DILuhcbE.d.mts","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-DabeBtmV.d.mts"],"mappings":";;;;;;;;KAOK;;;KAGA,aAAa,kBAAkB,0BAA0B,eAAe,qBAAqB,gBAAgB,kBAAkB;UAC1H,mBAAmB,kBAAkB,0BAA0B,eAAe;WAC7E,SAAS,sBAAsB;WAC/B,UAAU;WACV,OAAO,aAAa;WACpB,OAAO,kBAAkB,WAAW;WACpC,KAAK,eAAe;;;;;;;;;;;iBAWd,YAAY,kBAAkB,0BAA0B,eAAe,mBAAmB;WAChG,UAAU;WACV,sBAAsB,gCAAgC;IAC7D,mBAAmB"}
|