@prisma/orm-mysql 8.0.0-rc.21 → 8.0.0-rc.22
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/dist/{mysql-static-DcYvSThw-BMxDuGkP.mjs → mysql-static-OuLxp97M-Cwhw8ZDv.mjs} +3 -3
- package/dist/{mysql-static-DcYvSThw-BMxDuGkP.mjs.map → mysql-static-OuLxp97M-Cwhw8ZDv.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +555 -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/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +432 -0
package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
---
|
|
2
|
+
from: "8.0.0-rc.21"
|
|
3
|
+
to: "8.0.0-rc.22"
|
|
4
|
+
changes:
|
|
5
|
+
- id: mongo-result-shapes-read-storage
|
|
6
|
+
summary: |
|
|
7
|
+
`contractModelToMongoResultShape` and `contractFieldToMongoFieldShape` from `@prisma/orm-mongo/query-builder` take the contract's storage, `{ storage: contract.storage }` and `contract.storage`, instead of its value objects. `compileMongoQuery` from `@prisma/orm-mongo/orm` takes the contract's storage as its fifth argument. `MongoValueObjects` is removed. This replaces the rc.14 advice to pass `valueObjects`.
|
|
8
|
+
detection:
|
|
9
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
10
|
+
matches:
|
|
11
|
+
- '\bMongoValueObjects\b'
|
|
12
|
+
- '\bcontractModelToMongoResultShape\s*\([\s\S]*?\bvalueObjects\b'
|
|
13
|
+
- '\bcontractFieldToMongoFieldShape\s*\('
|
|
14
|
+
- '\bcompileMongoQuery\s*\('
|
|
15
|
+
- id: postgres-check-expression-types-move
|
|
16
|
+
summary: |
|
|
17
|
+
`PostgresCheckKind`, `PostgresCheckExpressionInput` and `PostgresCheckExpressionCandidate` are removed from `@prisma/orm-postgres/target/types`. Use `CheckExpressionInput` and `CheckExpressionCandidate` from `@prisma/orm-postgres/family-contract/check-expressions` (also exported at the same path by `@prisma/orm-mysql` and `@prisma/orm-sqlite`). A candidate's `kind` is `'membership'`, `'elementNotNull'` or the new `'shape'`, the check of a value object column's shape.
|
|
18
|
+
detection:
|
|
19
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
20
|
+
matches:
|
|
21
|
+
- '\bPostgresCheck(?:Kind|ExpressionInput|ExpressionCandidate)\b'
|
|
22
|
+
- id: field-types-read-storage-value-objects
|
|
23
|
+
summary: |
|
|
24
|
+
In `@prisma/orm-framework/contract/types`, `ValueObjectTypesFromDomain` is now `ValueObjectTypesFromStorage`, which takes the contract's storage namespaces. `FieldTypesFromDomain` takes the storage namespaces as a new, required sixth argument, `Contract['storage']['namespaces']`, since it reads both planes. An override for a value object field is keyed by the value object's storage namespace, at `[storage namespace]['valueObjects'][valueObject][field]`, while a model field's override stays keyed by its domain namespace.
|
|
25
|
+
detection:
|
|
26
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
27
|
+
matches:
|
|
28
|
+
- '\bValueObjectTypesFromDomain\b'
|
|
29
|
+
- '\bFieldTypesFromDomain\s*<'
|
|
30
|
+
- id: value-object-reference-type
|
|
31
|
+
summary: |
|
|
32
|
+
In `@prisma/orm-framework/contract/types`, `ValueObjectFieldType` is renamed `ValueObjectReference`: the type of a field that refers to a value object, which is now the value object's storage coordinate. `ContractValueObjectField` stays the type of a value object's own field.
|
|
33
|
+
detection:
|
|
34
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
35
|
+
matches:
|
|
36
|
+
- '\bValueObjectFieldType\b'
|
|
37
|
+
- id: postgres-codec-json-type
|
|
38
|
+
summary: |
|
|
39
|
+
A PostgreSQL codec descriptor declares `jsonType`: the JSON type the codec's value is written as inside a JSON document, one of `'string'`, `'number'`, `'boolean'`, `'object'`, `'array'` or `'any'`. `'any'` means any JSON value, including `null`, as for a JSON codec. The derived check of a value object column requires a member to be of its codec's JSON type, and a required member is never JSON `null` unless its codec's type is `'any'`. A class that extends `PostgresCodecDescriptor`, or an object that implements `AnyPostgresCodecDescriptor`, declares it as a property. `postgresCodec(template, options)` reads it from the template, so a family codec template declares it. A registry accepts a descriptor without it, but a contract build that derives the check of a value object whose member uses such a codec refuses it with `CONTRACT.CODEC_JSON_TYPE_MISSING`.
|
|
40
|
+
detection:
|
|
41
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
42
|
+
matches:
|
|
43
|
+
- '\bextends\s+PostgresCodecDescriptor\b'
|
|
44
|
+
- '\bAnyPostgresCodecDescriptor\b'
|
|
45
|
+
- '\bpostgresCodec\s*\('
|
|
46
|
+
- id: sql-stack-with-driver-requires-driver
|
|
47
|
+
summary: |
|
|
48
|
+
`SqlExecutionStackWithDriver` now requires its `driver`, and `createSqlExecutionStack(...)` returns it only when given a driver. Without a driver it returns `SqlExecutionStack`, which has no `driver` member. `createToSql(stack, contract)` takes `SqlExecutionStack`. Type a stack built without a driver as `SqlExecutionStack`, and remove checks such as `if (!stack.driver) throw ...` on a stack typed `SqlExecutionStackWithDriver`, which can no longer fail. The framework `ExecutionStack` now declares `driver` optional. The detection matches files that name `SqlExecutionStackWithDriver` or read `driver` from a stack, such as `stack.driver`, `clientStack.driver` or `const { driver } = createSqlExecutionStack(...)`.
|
|
49
|
+
detection:
|
|
50
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
51
|
+
matches:
|
|
52
|
+
- '(?<![\w$])SqlExecutionStackWithDriver(?![\w$])'
|
|
53
|
+
- '(?<![\w$.])(?:this\.)?[\w$]*[sS]tack\.driver(?![\w$])'
|
|
54
|
+
- '\{(?:[^{}]*,)?\s*driver(?![\w$])[^{}]*\}\s*=\s*(?:createSqlExecutionStack\s*\(|(?:this\.)?[\w$]*[sS]tack(?![\w$]))'
|
|
55
|
+
- id: runtime-mode-from-framework-components
|
|
56
|
+
summary: |
|
|
57
|
+
No action is needed. `RuntimeMode` is now declared in `@internal/framework-components/runtime` and still exported from `@internal/sql-runtime`.
|
|
58
|
+
- id: declare-postgres-extension-in-pack-contract
|
|
59
|
+
summary: |
|
|
60
|
+
A Postgres pack whose migration installs an extension with `installExtension(...)` and an invariant cannot be adopted by `prisma db sign`, which refuses a space whose head ref requires an invariant its marker does not record. Declare the extension in the pack's contract instead, with `extension pg_trgm {}` in PSL or `entities: [extension('pg_trgm')]` in a TypeScript contract, re-run `prisma contract emit` for the pack, and plan two migrations with `prisma migration plan`: one from the old head (`--from <old head hash>`), whose one operation creates the extension if it is missing, and one from the empty contract (`--from @empty`). Wire both into the descriptor's `contractSpace.migrations`, keep the old install migration, and set `migrations/refs/head.json` to the new storage hash with no invariants.
|
|
61
|
+
detection:
|
|
62
|
+
glob: "**/*.{ts,mts,cts}"
|
|
63
|
+
matches:
|
|
64
|
+
- '(?<![\w$])installExtension\s*\('
|
|
65
|
+
- id: mongo-driver-from-runtime-descriptor
|
|
66
|
+
summary: |
|
|
67
|
+
`@internal/driver-mongo` has no root export any more, so `createMongoDriver` and `MongoDriverImpl` are gone, as `@internal/driver-postgres` has none. Create a runtime driver from the descriptor that `@prisma/orm-target-mongo/driver/runtime` exports by default, then connect it. `@prisma/orm-mongo/driver` and `@prisma/orm-target-mongo/driver` now export what `driver/control` and `driver/runtime` export. The detection matches files that name `createMongoDriver` or `MongoDriverImpl`, or import the root `@internal/driver-mongo`.
|
|
68
|
+
detection:
|
|
69
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
70
|
+
matches:
|
|
71
|
+
- '(?<![\w$])(?:createMongoDriver|MongoDriverImpl)(?![\w$])'
|
|
72
|
+
- '[''"]@internal/driver-mongo[''"]'
|
|
73
|
+
- id: mongo-driver-connect
|
|
74
|
+
summary: |
|
|
75
|
+
`@internal/mongo-lowering` adds `MongoQueryable`, with `execute` and `run`, as `SqlQueryable` is for SQL. `MongoDriver<TBinding = void>` extends it and adds `connect(binding)` and `close()`, as `SqlDriver<TBinding>` does. `MongoControlDriverInstance` extends `MongoQueryable`, not `MongoDriver`, so a control driver has no `connect`. `executeDdl`, `MongoRunnerDependencies.driver` and the migration runner now take `MongoQueryable`; `createMongoRuntime` takes `MongoDriver<unknown>`. Type code that only sends commands, or that receives a control driver, as `MongoQueryable`. A runtime driver you implement as `MongoDriver` adds `connect`. The detection matches classes that implement `MongoDriver`, interfaces and classes that extend it, type aliases that name it, and values, parameters and return types annotated or checked as `MongoDriver`, also inside a generic such as `Promise<MongoDriver>`.
|
|
76
|
+
detection:
|
|
77
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
78
|
+
matches:
|
|
79
|
+
- 'implements\s[^{]*(?<![\w$])MongoDriver(?![\w$])'
|
|
80
|
+
- '[\w$)]\??\s*:\s*MongoDriver(?![\w$])'
|
|
81
|
+
- '[\w$)]\??\s*:\s*[\w$.]+<[^;{=]*(?<![\w$])MongoDriver(?![\w$])'
|
|
82
|
+
- 'satisfies\s+MongoDriver(?![\w$])'
|
|
83
|
+
- '(?:interface|class)\s[^{]*extends\s[^{]*(?<![\w$])MongoDriver(?![\w$])'
|
|
84
|
+
- 'type\s+[\w$]+(?:<[^>]*>)?\s*=[^;]*(?<![\w$])MongoDriver(?![\w$])'
|
|
85
|
+
- id: mongo-query-takes-context
|
|
86
|
+
summary: |
|
|
87
|
+
`mongoQuery` (`@internal/mongo-query-builder`, published as `@prisma/orm-family-mongo/query-builder` and `@prisma/orm-mongo/query-builder`) takes `{ context }`, a `MongoExecutionContext`, instead of `{ contract }`, and reads the contract from it. Code that builds the builder itself passes the execution context it already has, for example `mongoQuery({ context })` after `createMongoExecutionContext({ contract, stack })`; code that has a client or a static context uses `db.query` or `mongoStatic({ contract }).query`. The detection matches files that call `mongoQuery` with a `contract` option, import it under another name, or call it through a namespace import.
|
|
88
|
+
detection:
|
|
89
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
90
|
+
matches:
|
|
91
|
+
- '(?<![\w$.])mongoQuery\s*(?:<[^>()]*>)?\s*\(\s*\{\s*contract\b'
|
|
92
|
+
- '(?<![\w$.])mongoQuery\s+as\s+[\w$]+'
|
|
93
|
+
- '(?<![\s\S])(?=[\s\S]*\bimport\s*\*\s*as\s+([\w$]+)\s+from\s*[\x27\x22](?:@prisma/orm-(?:family-)?mongo/query-builder|@internal/mongo-query-builder)[\x27\x22])[\s\S]*(?<![\w$.])\1\s*\.\s*mongoQuery\s*\('
|
|
94
|
+
- id: mongo-orm-takes-context
|
|
95
|
+
summary: |
|
|
96
|
+
`mongoOrm()` (`@internal/mongo-orm`, published as `@prisma/orm-family-mongo/orm` and `@prisma/orm-mongo/orm`) takes `{ context, runtime }`, as the SQL `orm({ context, runtime })` does. `MongoOrmOptions` loses `contract`, `executor`, `enums` and `mutationDefaults`: the ORM reads the contract, the codecs it builds enum accessors from, and the execution defaults from the context, and `runtime` is the executor. `mongoRaw()` takes `{ context }`. `createMongoCollection()` takes `({ context, runtime }, modelName)` (`MongoCollectionContext`, as the SQL ORM's `CollectionContext`) and always fills execution defaults. `MongoOrmEnums` and `ORM.MUTATION_DEFAULTS_MISSING` are removed, and the ORM no longer raises `ORM.ARGUMENT_INVALID` for missing enum accessors. The detection matches files that call `mongoOrm` or `mongoRaw` with a `contract` option, call `mongoOrm` with `executor` or `enums`, call `createMongoCollection` without a context object, pass `mutationDefaults`, or name `MongoOrmEnums` or `ORM.MUTATION_DEFAULTS_MISSING`.
|
|
97
|
+
detection:
|
|
98
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
99
|
+
matches:
|
|
100
|
+
- '(?<![\w$.])mongo(?:Orm|Raw)\s*(?:<[^>()]*>)?\s*\(\s*\{\s*contract\b'
|
|
101
|
+
- '(?<![\w$.])mongoOrm\s*(?:<[^>()]*>)?\s*\(\s*\{(?:[^{}]|\{[^{}]*\})*\b(?:executor|enums)\b'
|
|
102
|
+
- '(?<![\w$.])createMongoCollection\s*(?:<[^>()]*>)?\s*\(\s*(?!\{)'
|
|
103
|
+
- '(?<![\w$])mutationDefaults\s*:'
|
|
104
|
+
- '(?<![\w$])MongoOrmEnums(?![\w$])'
|
|
105
|
+
- 'MUTATION_DEFAULTS_MISSING'
|
|
106
|
+
- id: mongo-runtime-takes-adapter
|
|
107
|
+
summary: |
|
|
108
|
+
`MongoRuntimeOptions` is `{ context, adapter, driver, middleware?, mode? }`, as the SQL runtime's options are: the caller creates the adapter with `stack.adapter.create(stack)`, and the runtime checks middleware against `context.contract.target`, so `context` is a `MongoExecutionContext<MongoContract>`. `MongoExecutionContext` is declared in `@prisma/orm-family-mongo/query-ast/execution` (`@internal/mongo-query-ast/execution`), still exported from the runtime entry; it has no `stack` member and no second type parameter (`TTargetId`), and its type parameter is constrained as SQL's `ExecutionContext` is: `MongoExecutionContext<TContract extends MongoContract = MongoContract>`, and `createMongoExecutionContext` takes the same constraint. `createMongoExecutionStack()` still takes an optional `driver`; given one, it returns `MongoExecutionStackWithDriver`, whose `driver` is always set, and without one it returns `MongoExecutionStack`, which has no `driver` member, as `createSqlExecutionStack()` does. `buildMongoEnums()` and `MongoEnumAccessors` are removed, and `MongoExecutionContext` has no `enums` member, as SQL's `ExecutionContext` has none: the static context builds `db.enums` with the framework's `buildNamespacedEnums`, as `postgresStatic()` does, and the ORM builds the accessors it checks writes against from the context, once per client. The detection matches files that call `createMongoRuntime(`, read `.stack` from a context, give `MongoExecutionContext` two type arguments or a non-contract type argument, or name `buildMongoEnums` or `MongoEnumAccessors`.
|
|
109
|
+
detection:
|
|
110
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx}"
|
|
111
|
+
matches:
|
|
112
|
+
- '(?<![\w$.])createMongoRuntime\s*\('
|
|
113
|
+
- '(?<![\w$])[\w$]*[cC]ontext\s*\.\s*stack(?![\w$])'
|
|
114
|
+
- '(?<![\w$])MongoExecutionContext\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*,'
|
|
115
|
+
- '(?<![\w$])MongoExecutionContext\s*<\s*(?:unknown|\{)'
|
|
116
|
+
- '(?<![\w$.])(?:buildMongoEnums|MongoEnumAccessors)(?![\w$])'
|
|
117
|
+
- id: mongo-build-refusal-index-duplicate-removed
|
|
118
|
+
summary: |
|
|
119
|
+
The MongoDB contract builder's `BuildRefusal` type, exported from `@prisma/orm-family-mongo/contract-ts/contract-builder`, no longer has the kind `indexDuplicate`. The builder now merges identical and redundant indexes instead of refusing them. Remove any `case 'indexDuplicate'` and any other code that reads that kind.
|
|
120
|
+
detection:
|
|
121
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
122
|
+
matches:
|
|
123
|
+
- '\bindexDuplicate\b'
|
|
124
|
+
- id: mongo-index-lookup-key-moved
|
|
125
|
+
summary: |
|
|
126
|
+
`indexLookupKey`, `MONGO_INDEX_OPTION_KEYS`, `MongoIndexOptionKey` and `canonicalize` are no longer exported from `@prisma/orm-family-mongo/schema-ir`. Import them from `@prisma/orm-family-mongo/contract`.
|
|
127
|
+
detection:
|
|
128
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
129
|
+
matches:
|
|
130
|
+
- 'import\s+(?:type\s+)?\{[^}]*\b(?:indexLookupKey|MONGO_INDEX_OPTION_KEYS|MongoIndexOptionKey|canonicalize)\b[^}]*\}\s*from\s*[\x27"]@prisma/orm-family-mongo/schema-ir[\x27"]'
|
|
131
|
+
- id: client-connect-safe-to-call-again
|
|
132
|
+
summary: |
|
|
133
|
+
`connect()` without options on a `postgres()`, `sqlite()`, `mysql()` or `mongo()` client no longer rejects when the client is connecting or connected. It waits for the connection and resolves with the runtime. `connect(options)` on such a client still rejects with `DRIVER.ALREADY_CONNECTED`, but its message is now `<Target> client is already bound` (for example `Postgres client is already bound`), it has a `why`, and its `fix` changed. Update code or tests that branch on `DRIVER.ALREADY_CONNECTED` after a `connect()` without options, or that match the old message `<Target> client already connected` or the old `fix` "Call connect() at most once per client.". Code that avoided a second `connect()` for fear of this error may call it freely. A `connect()` that is waiting when `close()` is called now rejects with `DRIVER.NOT_CONNECTED`.
|
|
134
|
+
detection:
|
|
135
|
+
glob: "**/*.{ts,mts,cts,tsx,js,mjs,cjs}"
|
|
136
|
+
matches:
|
|
137
|
+
- 'DRIVER\.ALREADY_CONNECTED'
|
|
138
|
+
- '(?:Postgres|SQLite|MySQL|Mongo) client already connected'
|
|
139
|
+
- 'Call connect\(\) at most once per client'
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
# 8.0.0-rc.21 → 8.0.0-rc.22 — Extension author upgrade instructions
|
|
143
|
+
|
|
144
|
+
No change in this guide comes with a script. Make the changes below in any order.
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## Value objects are storage entities
|
|
148
|
+
|
|
149
|
+
A contract keeps its value objects in storage, at `storage.namespaces.<ns>.entries.valueObject`, and a domain field names its value object by a storage coordinate. Code that read `domain.namespaces.<ns>.valueObjects` reads the storage namespaces instead.
|
|
150
|
+
|
|
151
|
+
### `mongo-result-shapes-read-storage`
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// before
|
|
155
|
+
contractModelToMongoResultShape(model, { includes: { author: authorShape }, valueObjects });
|
|
156
|
+
contractFieldToMongoFieldShape(field, valueObjects);
|
|
157
|
+
compileMongoQuery(collection, state, storageHash, model, valueObjects);
|
|
158
|
+
|
|
159
|
+
// after
|
|
160
|
+
contractModelToMongoResultShape(model, { includes: { author: authorShape }, storage: contract.storage });
|
|
161
|
+
contractFieldToMongoFieldShape(field, contract.storage);
|
|
162
|
+
compileMongoQuery(collection, state, storageHash, model, contract.storage);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
A value object field's shape is a document of its fields when `storage` holds the value object the field's coordinate names. Drop any `MongoValueObjects` type annotation; each parameter takes an object with the contract's storage `namespaces`.
|
|
166
|
+
|
|
167
|
+
### `postgres-check-expression-types-move`
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
// before
|
|
171
|
+
import type { PostgresCheckExpressionInput } from '@prisma/orm-postgres/target/types';
|
|
172
|
+
|
|
173
|
+
// after
|
|
174
|
+
import type { CheckExpressionInput } from '@prisma/orm-postgres/family-contract/check-expressions';
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`postgresRenderCheckExpressions` stays in `@prisma/orm-postgres/target/types`. Its input also takes `valueObject`, a `ResolvedColumnValueObject` (the column's nullability, whether its JSON value is an array, and the value object), or `undefined`.
|
|
178
|
+
|
|
179
|
+
### `field-types-read-storage-value-objects`
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
// before
|
|
183
|
+
import type { FieldTypesFromDomain, ValueObjectTypesFromDomain } from '@prisma/orm-framework/contract/types';
|
|
184
|
+
type Fields = FieldTypesFromDomain<Contract['domain']['namespaces'], CodecTypes, Parameterized, Overrides, 'output'>;
|
|
185
|
+
type ValueObjects = ValueObjectTypesFromDomain<Contract['domain']['namespaces'], CodecTypes, Parameterized, Overrides, 'output'>;
|
|
186
|
+
|
|
187
|
+
// after
|
|
188
|
+
import type { FieldTypesFromDomain, ValueObjectTypesFromStorage } from '@prisma/orm-framework/contract/types';
|
|
189
|
+
type Fields = FieldTypesFromDomain<Contract['domain']['namespaces'], CodecTypes, Parameterized, Overrides, 'output', Contract['storage']['namespaces']>;
|
|
190
|
+
type ValueObjects = ValueObjectTypesFromStorage<Contract['storage']['namespaces'], CodecTypes, Parameterized, Overrides, 'output'>;
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Pass the sixth argument for every contract, with value objects or without. `FieldTypeOverrides` has two kinds of key at its top level. Under `models`, the key is the domain namespace of the model. Under `valueObjects`, the key is the storage namespace that holds the value object. These can differ. On SQL every value object is stored in the default storage namespace, such as `public` on Postgres, whatever the namespace of the model that holds it. On MongoDB it is `__unbound__`.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
// a model `User` in the PSL namespace `billing`, with an `Address` field, on Postgres
|
|
197
|
+
type FieldTypeOverrides = {
|
|
198
|
+
readonly billing: { readonly models: { readonly User: { readonly status: { readonly output: 'active' | 'closed' } } } };
|
|
199
|
+
readonly public: { readonly valueObjects: { readonly Address: { readonly kind: { readonly output: 'home' | 'work' } } } };
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### `value-object-reference-type`
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// before
|
|
207
|
+
import type { ValueObjectFieldType } from '@prisma/orm-framework/contract/types';
|
|
208
|
+
const reference: ValueObjectFieldType = { kind: 'valueObject', name: 'Address' };
|
|
209
|
+
|
|
210
|
+
// after
|
|
211
|
+
import type { ValueObjectReference } from '@prisma/orm-framework/contract/types';
|
|
212
|
+
const reference: ValueObjectReference = {
|
|
213
|
+
kind: 'valueObject',
|
|
214
|
+
plane: 'storage',
|
|
215
|
+
namespaceId: 'public',
|
|
216
|
+
entityKind: 'valueObject',
|
|
217
|
+
entityName: 'Address',
|
|
218
|
+
};
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### `postgres-codec-json-type`
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
// before
|
|
225
|
+
export class CitextDescriptor extends PostgresCodecDescriptor<void> {
|
|
226
|
+
override readonly codecId = 'citext/text@1';
|
|
227
|
+
// ...
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// after
|
|
231
|
+
export class CitextDescriptor extends PostgresCodecDescriptor<void> {
|
|
232
|
+
override readonly jsonType = 'string' as const;
|
|
233
|
+
override readonly codecId = 'citext/text@1';
|
|
234
|
+
// ...
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Declare the type the codec's value is written as when the application value is turned into JSON: a vector is `'array'`, a geometry and bytes are `'object'`, and a JSON codec is `'any'`. A template passed to `postgresCodec(template, options)` declares `jsonType` itself, as the `sql/*` family codecs do.
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
## A SQL stack with a driver always has one
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
// Before
|
|
245
|
+
const stack: SqlExecutionStackWithDriver<'postgres'> = createSqlExecutionStack({ target, adapter });
|
|
246
|
+
if (!stack.driver) throw new Error('Driver descriptor missing from execution stack');
|
|
247
|
+
|
|
248
|
+
// After
|
|
249
|
+
const staticStack: SqlExecutionStack<'postgres'> = createSqlExecutionStack({ target, adapter });
|
|
250
|
+
const clientStack = createSqlExecutionStack({ target, adapter, driver });
|
|
251
|
+
const driverInstance = clientStack.driver.create();
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
## Declare a pack's Postgres extension in its contract
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
// Before: src/contract.ts
|
|
259
|
+
export const contract = defineContract(config, () => ({ models: {} }));
|
|
260
|
+
|
|
261
|
+
// After
|
|
262
|
+
import { defineContract, extension } from '@prisma/orm-postgres/contract-builder';
|
|
263
|
+
export const contract = defineContract(config, () => ({
|
|
264
|
+
models: {},
|
|
265
|
+
entities: [extension('vector')],
|
|
266
|
+
}));
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
After emitting the pack's contract, plan from the old head and from the empty contract, keep the old install migration in the descriptor, and list the two new migrations beside it. The head ref lists no invariants.
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
## Create a Mongo runtime driver from its descriptor
|
|
273
|
+
|
|
274
|
+
Put the descriptor on the execution stack, create the driver from the stack, and connect it to a binding. A `{ kind: 'url', url, dbName }` binding makes the driver open a `MongoClient` and close it on `close()`. A `{ kind: 'mongoClient', client, dbName }` binding uses your client and leaves it open.
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
// Before
|
|
278
|
+
import { createMongoDriver } from '@prisma/orm-target-mongo/driver';
|
|
279
|
+
|
|
280
|
+
const stack = createMongoExecutionStack({ target: mongoRuntimeTarget, adapter: mongoRuntimeAdapter });
|
|
281
|
+
const driver = await createMongoDriver(url, dbName);
|
|
282
|
+
|
|
283
|
+
// After
|
|
284
|
+
import mongoRuntimeDriver from '@prisma/orm-target-mongo/driver/runtime';
|
|
285
|
+
|
|
286
|
+
const stack = createMongoExecutionStack({
|
|
287
|
+
target: mongoRuntimeTarget,
|
|
288
|
+
adapter: mongoRuntimeAdapter,
|
|
289
|
+
driver: mongoRuntimeDriver,
|
|
290
|
+
});
|
|
291
|
+
const driver = stack.driver.create();
|
|
292
|
+
await driver.connect({ kind: 'url', url, dbName });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Replace `MongoDriverImpl.fromDb(client.db(dbName))` with `driver.connect({ kind: 'mongoClient', client, dbName })` on a driver created the same way. Code that only sends DDL through a control adapter can use the control driver instead: `await mongoControlDriver.create(url)`, with `mongoControlDriver` the default export of `@prisma/orm-target-mongo/driver/control`. The control driver uses the database the URL names, so put `dbName` in the URL's path, for example `mongodb://localhost:27017/app`.
|
|
296
|
+
|
|
297
|
+
`createMongoRuntime(...)` closes the driver when the runtime closes, so keep calling `runtime.close()` and drop any separate `driver.close()`.
|
|
298
|
+
|
|
299
|
+
## Send commands through `MongoQueryable`, connect through `MongoDriver`
|
|
300
|
+
|
|
301
|
+
Code that only sends commands takes `MongoQueryable`, so it accepts a control driver and a runtime driver alike:
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
// Before
|
|
305
|
+
async function seed(driver: MongoDriver): Promise<void> {
|
|
306
|
+
await driver.run(new CreateCollectionWireCommand('users', {}));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// After
|
|
310
|
+
async function seed(driver: MongoQueryable): Promise<void> {
|
|
311
|
+
await driver.run(new CreateCollectionWireCommand('users', {}));
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
A stub that stands in for a control driver or a runner's driver implements `MongoQueryable`. A runtime driver that implements `MongoDriver` adds `connect`:
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
// Before
|
|
319
|
+
class StubMongoDriver implements MongoDriver {
|
|
320
|
+
execute<Row>(command: AnyMongoDmlWireCommand): AsyncIterable<Row> { ... }
|
|
321
|
+
async run(command: AnyMongoDdlWireCommand): Promise<void> { ... }
|
|
322
|
+
async close(): Promise<void> {}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// After, when it only sends commands
|
|
326
|
+
class StubMongoDriver implements MongoQueryable {
|
|
327
|
+
execute<Row>(command: AnyMongoDmlWireCommand): AsyncIterable<Row> { ... }
|
|
328
|
+
async run(command: AnyMongoDdlWireCommand): Promise<void> { ... }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// After, when it is a runtime driver
|
|
332
|
+
class StubMongoDriver implements MongoDriver {
|
|
333
|
+
async connect(): Promise<void> {}
|
|
334
|
+
execute<Row>(command: AnyMongoDmlWireCommand): AsyncIterable<Row> { ... }
|
|
335
|
+
async run(command: AnyMongoDdlWireCommand): Promise<void> { ... }
|
|
336
|
+
async close(): Promise<void> {}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
## The MongoDB query surfaces and runtime take an execution context
|
|
342
|
+
|
|
343
|
+
`mongoQuery`, `mongoRaw` and `mongoOrm` take `{ context }`, a MongoDB execution context, instead of `{ contract }`, as `sql({ context })` and the SQL ORM do. The context comes from `mongoStatic({ contract })` or `mongo({ contract })`, which validate the contract once.
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
// Before
|
|
347
|
+
import { mongoQuery } from '@prisma/orm-mongo/query-builder';
|
|
348
|
+
const query = mongoQuery({ contract });
|
|
349
|
+
const raw = mongoRaw({ contract });
|
|
350
|
+
|
|
351
|
+
// After
|
|
352
|
+
import mongoStatic from '@prisma/orm-mongo/static';
|
|
353
|
+
const { query, raw } = mongoStatic({ contract });
|
|
354
|
+
|
|
355
|
+
// Or, with a client
|
|
356
|
+
const db = mongo({ contract, url });
|
|
357
|
+
db.query.from('orders');
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Code that builds the ORM itself passes the context, which also fills generated fields:
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
// Before
|
|
364
|
+
const orm = mongoOrm({ contract, executor, mutationDefaults: context, enums });
|
|
365
|
+
const users = createMongoCollection(contract, 'User', executor, enums, context);
|
|
366
|
+
|
|
367
|
+
// After, as the SQL orm({ context, runtime })
|
|
368
|
+
const orm = mongoOrm({ context, runtime: executor });
|
|
369
|
+
const users = createMongoCollection({ context, runtime: executor }, 'User');
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
The runtime takes an adapter beside the context, as the SQL runtime does, and reads the target from the context's contract:
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
// Before
|
|
376
|
+
const runtime = createMongoRuntime({ context, stack, driver });
|
|
377
|
+
|
|
378
|
+
// After
|
|
379
|
+
const stack = createMongoExecutionStack({ target, adapter });
|
|
380
|
+
const context = createMongoExecutionContext({ contract, stack });
|
|
381
|
+
const runtime = createMongoRuntime({ context, adapter: stack.adapter.create(stack), driver });
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
`MongoExecutionContext` takes one type parameter, a MongoDB contract: `MongoExecutionContext<Contract>`.
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
## MongoDB index identity: one refusal gone, four names moved
|
|
388
|
+
|
|
389
|
+
### `mongo-build-refusal-index-duplicate-removed`
|
|
390
|
+
|
|
391
|
+
Code that switches over `refusal.kind` no longer compiles while it names `indexDuplicate`. Delete that case:
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
switch (refusal.kind) {
|
|
395
|
+
case 'indexShape':
|
|
396
|
+
return describeShape(refusal);
|
|
397
|
+
// remove: case 'indexDuplicate': ...
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### `mongo-index-lookup-key-moved`
|
|
402
|
+
|
|
403
|
+
The contract builder, the planner and the verifier now identify an index by one function in the contract package. Move these names to the `contract` import:
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
import { MongoSchemaIndex } from '@prisma/orm-family-mongo/schema-ir';
|
|
407
|
+
import { indexLookupKey } from '@prisma/orm-family-mongo/contract';
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
## `connect()` on a client is safe to call again
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
// Before
|
|
415
|
+
await db.orm.public.User.first();
|
|
416
|
+
await db.connect(); // rejected with DRIVER.ALREADY_CONNECTED
|
|
417
|
+
|
|
418
|
+
// After
|
|
419
|
+
await db.orm.public.User.first();
|
|
420
|
+
await db.connect(); // resolves with the same runtime
|
|
421
|
+
await db.connect({ url: other }); // rejects: "Postgres client is already bound"
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Replace an assertion on the old message with the new one:
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
// Before
|
|
428
|
+
await expect(db.connect({ url })).rejects.toThrow('Postgres client already connected');
|
|
429
|
+
|
|
430
|
+
// After
|
|
431
|
+
await expect(db.connect({ url })).rejects.toThrow('Postgres client is already bound');
|
|
432
|
+
```
|