@prisma/orm-mongo 8.0.0-rc.25-dev.1 → 8.0.0-rc.25-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{mongo-static-HY6yvShA-BgApk2W4.mjs → mongo-static-BkZ1RBOd-BcJDkh_M.mjs} +3 -3
- package/dist/{mongo-static-HY6yvShA-BgApk2W4.mjs.map → mongo-static-BkZ1RBOd-BcJDkh_M.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.24-to-8.0.0-rc.25/instructions.md +64 -20
|
@@ -8,8 +8,8 @@ import { buildNamespacedEnums } from "@prisma/orm-framework/contract/enum-access
|
|
|
8
8
|
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
9
9
|
import { mongoQuery } from "@prisma/orm-family-mongo/query-builder";
|
|
10
10
|
import { assertDefined } from "@prisma/orm-framework/utils/assertions";
|
|
11
|
-
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-
|
|
12
|
-
var version = "8.0.0-rc.25-dev.
|
|
11
|
+
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-BkZ1RBOd.mjs
|
|
12
|
+
var version = "8.0.0-rc.25-dev.3";
|
|
13
13
|
const serializer = new MongoContractSerializer();
|
|
14
14
|
const validator = `${mongoRuntimeTarget.targetId}@${version}`;
|
|
15
15
|
/**
|
|
@@ -69,4 +69,4 @@ function mongoStatic(options) {
|
|
|
69
69
|
//#endregion
|
|
70
70
|
export { validateMongoContract as i, contractFromJson as n, mongoStatic as r, buildMongoStaticContext as t };
|
|
71
71
|
|
|
72
|
-
//# sourceMappingURL=mongo-static-
|
|
72
|
+
//# sourceMappingURL=mongo-static-BkZ1RBOd-BcJDkh_M.mjs.map
|
package/dist/{mongo-static-HY6yvShA-BgApk2W4.mjs.map → mongo-static-BkZ1RBOd-BcJDkh_M.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongo-static-
|
|
1
|
+
{"version":3,"file":"mongo-static-BkZ1RBOd-BcJDkh_M.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-BkZ1RBOd.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 { 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.0-rc.25-dev.3\";\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}\nfunction validateMongoContract(contract) {\n\treturn contractFromJson(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-BkZ1RBOd.mjs.map"],"mappings":";;;;;;;;;;;AAWA,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;AACA,SAAS,sBAAsB,UAAU;CACxC,OAAO,iBAAiB,QAAQ;AACjC;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"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-
|
|
1
|
+
import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-BkZ1RBOd-BcJDkh_M.mjs";
|
|
2
2
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
3
3
|
import mongoRuntimeAdapter from "@prisma/orm-target-mongo/adapter/runtime";
|
|
4
4
|
import { mongoOrm } from "@prisma/orm-family-mongo/orm";
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.mjs"],"sourcesContent":["import { i as validateMongoContract, t as buildMongoStaticContext } from \"./mongo-static-HY6yvShA.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport mongoRuntimeDriver from \"@internal/driver-mongo/runtime\";\nimport { AsyncIterableResult } from \"@internal/framework-components/runtime\";\nimport { mongoOrm } from \"@internal/mongo-orm\";\nimport { createMongoExecutionStack, createMongoRuntime } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { ConnectionString } from \"mongodb-connection-string-url\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/runtime/mongo-errors.ts\nfunction mongoError(code, message, options) {\n\treturn structuredError(code, message, {\n\t\t...options,\n\t\tmeta: {\n\t\t\t...options?.meta,\n\t\t\textension: \"mongo\"\n\t\t}\n\t});\n}\n//#endregion\n//#region src/runtime/binding.ts\nconst URL_SCHEME_PATTERN = /^([a-z][a-z\\d+.-]*):\\/\\//i;\nconst MONGO_SCHEMES = /* @__PURE__ */ new Set([\"mongodb\", \"mongodb+srv\"]);\nfunction validateMongoUrl(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a non-empty string\");\n\tconst scheme = URL_SCHEME_PATTERN.exec(trimmed)?.[1];\n\tif (scheme === void 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\tif (!MONGO_SCHEMES.has(scheme)) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must use mongodb:// or mongodb+srv://\");\n\ttry {\n\t\treturn new ConnectionString(trimmed);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction extractDbNameFromUrl(parsed) {\n\tconst [encodedDbName = \"\"] = parsed.pathname.slice(1).split(\"/\");\n\tif (encodedDbName.length === 0) return;\n\ttry {\n\t\treturn decodeURIComponent(encodedDbName);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction resolveMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return options.binding;\n\tif (options.url !== void 0) {\n\t\tconst parsed = validateMongoUrl(options.url);\n\t\tif (options.dbName !== void 0 && options.dbName.trim().length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { url, dbName } requires a non-empty dbName\");\n\t\tconst explicitDbName = options.dbName?.trim();\n\t\tconst dbName = explicitDbName !== void 0 && explicitDbName.length > 0 ? explicitDbName : extractDbNameFromUrl(parsed);\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must include a database name in its path (e.g. mongodb://host:27017/mydb), or pass dbName explicitly\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.url.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tif (options.uri !== void 0) {\n\t\tvalidateMongoUrl(options.uri);\n\t\tconst dbName = options.dbName?.trim();\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { uri, dbName } requires a non-empty dbName\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.uri.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tconst mongoClient = options.mongoClient;\n\tif (mongoClient === void 0) throw new InternalError(\"Invariant violation: expected mongo binding after validation\");\n\tconst dbName = options.dbName?.trim();\n\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { mongoClient, dbName } requires a non-empty dbName\");\n\treturn {\n\t\tkind: \"mongoClient\",\n\t\tclient: mongoClient,\n\t\tdbName\n\t};\n}\nfunction resolveOptionalMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount === 0) return;\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return resolveMongoBinding({ binding: options.binding });\n\tif (options.url !== void 0) return resolveMongoBinding(options.dbName !== void 0 ? {\n\t\turl: options.url,\n\t\tdbName: options.dbName\n\t} : { url: options.url });\n\tif (options.uri !== void 0) return resolveMongoBinding({\n\t\turi: options.uri,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tif (options.mongoClient !== void 0) return resolveMongoBinding({\n\t\tmongoClient: options.mongoClient,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tthrow new InternalError(\"Invariant violation: expected one mongo binding branch\");\n}\n//#endregion\n//#region src/runtime/prepared-row-query.ts\nasync function prepareMongoQuery(runtime, declaration, callback) {\n\tlet description;\n\tconst statement = await runtime.prepare(declaration, (placeholders) => {\n\t\tconst authored = callback(placeholders);\n\t\tif (\"plan\" in authored) {\n\t\t\tdescription = authored;\n\t\t\treturn authored.plan;\n\t\t}\n\t\treturn authored;\n\t});\n\treturn blindCast(description ? createMongoPreparedRowQuery(description, statement) : statement);\n}\nfunction createMongoPreparedRowQuery(description, statement) {\n\treturn Object.freeze({ query(target, params, options) {\n\t\treturn description.consume(statement.query(target, params, options));\n\t} });\n}\n//#endregion\n//#region src/runtime/mongo.ts\n/**\n* Creates a lazy Mongo client. The client infers its contract type from `contract`: a value from\n* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is\n* validated once, however many clients are built from it. The `orm` and `query` surfaces are\n* available at once; the driver connects on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-mongo/static';\n* import mongo from '@prisma/orm-mongo/runtime';\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* export const db = mongo({ contract, url: process.env['MONGODB_URL']! });\n* ```\n*/\nfunction mongo(options) {\n\tconst contract = validateMongoContract(options.contract);\n\tlet binding = resolveOptionalMongoBinding(options);\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\tdriver: mongoRuntimeDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst { context, query, enums, raw } = buildMongoStaticContext(contract, stack);\n\tlet runtimePromise;\n\tlet closed = false;\n\tlet runtimeInstance;\n\tconst closedError = () => mongoError(\"DRIVER.NOT_CONNECTED\", \"Mongo client is closed\");\n\tconst createRuntime = () => {\n\t\tif (runtimeInstance !== void 0) return runtimeInstance;\n\t\tconst driver = stack.driver.create();\n\t\truntimeInstance = {\n\t\t\truntime: createMongoRuntime({\n\t\t\t\tcontext,\n\t\t\t\tadapter: stack.adapter.create(stack),\n\t\t\t\tdriver,\n\t\t\t\t...ifDefined(\"mode\", options.mode),\n\t\t\t\t...ifDefined(\"middleware\", options.middleware)\n\t\t\t}),\n\t\t\tdriver\n\t\t};\n\t\treturn runtimeInstance;\n\t};\n\tconst buildRuntime = async (resolvedBinding) => {\n\t\tconst { runtime, driver } = createRuntime();\n\t\tawait driver.connect(resolvedBinding);\n\t\treturn runtime;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closed) return Promise.reject(closedError());\n\t\tif (runtimePromise !== void 0) return runtimePromise;\n\t\tif (binding === void 0) return Promise.reject(mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\"));\n\t\truntimePromise = buildRuntime(binding).catch((err) => {\n\t\t\truntimePromise = void 0;\n\t\t\tthrow err;\n\t\t});\n\t\treturn runtimePromise;\n\t};\n\tfunction queryRows(plan) {\n\t\tasync function* iterate() {\n\t\t\tyield* (await getRuntime()).query(plan);\n\t\t}\n\t\treturn new AsyncIterableResult(iterate());\n\t}\n\tasync function executeStats(plan) {\n\t\treturn (await getRuntime()).execute(plan);\n\t}\n\treturn {\n\t\torm: mongoOrm({\n\t\t\tcontext,\n\t\t\truntime: {\n\t\t\t\tquery: queryRows,\n\t\t\t\texecute: executeStats\n\t\t\t}\n\t\t}),\n\t\tquery,\n\t\traw,\n\t\tcontract,\n\t\tenums,\n\t\tcontext,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closed) throw closedError();\n\t\t\tif (runtimePromise !== void 0) {\n\t\t\t\tif (bindingInput !== void 0) throw mongoError(\"DRIVER.ALREADY_CONNECTED\", \"Mongo client is already bound\", {\n\t\t\t\t\twhy: \"connect() was given options after the client was bound to a database.\",\n\t\t\t\t\tfix: \"Call connect() without options, or create a new client for another database.\"\n\t\t\t\t});\n\t\t\t\tconst runtime = await runtimePromise;\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\treturn runtime;\n\t\t\t}\n\t\t\tif (bindingInput !== void 0) binding = resolveMongoBinding(bindingInput);\n\t\t\tif (binding === void 0) throw mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\");\n\t\t\tconst runtime = await getRuntime();\n\t\t\tif (closed) throw closedError();\n\t\t\treturn runtime;\n\t\t},\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tasync prepare(declaration, callback) {\n\t\t\tif (closed) throw closedError();\n\t\t\treturn prepareMongoQuery(createRuntime().runtime, declaration, callback);\n\t\t},\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tawait runtimePromise?.catch(() => void 0);\n\t\t\tawait runtimeInstance?.runtime.close();\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { mongo as default };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,WAAW,MAAM,SAAS,SAAS;CAC3C,OAAO,gBAAgB,MAAM,SAAS;EACrC,GAAG;EACH,MAAM;GACL,GAAG,SAAS;GACZ,WAAW;EACZ;CACD,CAAC;AACF;AAGA,MAAM,qBAAqB;AAC3B,MAAM,gCAAgC,IAAI,IAAI,CAAC,WAAW,aAAa,CAAC;AACxE,SAAS,iBAAiB,KAAK;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AAY,KAAK,GAAG,MAAM,WAAW,2BAA2B,yHAAyH;GAC7L,MAAM,UAAU,MAAM,WAAW;GACjC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO;EACR;EACA,UAAU;GACT,OAAO,WAAW;EACnB;EACA,MAAM,QAAQ,aAAa,UAAU;GACpC,IAAI,QAAQ,MAAM,YAAY;GAC9B,OAAO,kBAAkB,cAAc,CAAC,CAAC,SAAS,aAAa,QAAQ;EACxE;EACA,MAAM,QAAQ;GACb,IAAI,QAAQ;GACZ,SAAS;GACT,MAAM,gBAAgB,YAAY,KAAK,CAAC;GACxC,MAAM,iBAAiB,QAAQ,MAAM;EACtC;EACA,CAAC,OAAO,gBAAgB;GACvB,OAAO,KAAK,MAAM;EACnB;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.mjs"],"sourcesContent":["import { i as validateMongoContract, t as buildMongoStaticContext } from \"./mongo-static-BkZ1RBOd.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport mongoRuntimeAdapter from \"@internal/adapter-mongo/runtime\";\nimport mongoRuntimeDriver from \"@internal/driver-mongo/runtime\";\nimport { AsyncIterableResult } from \"@internal/framework-components/runtime\";\nimport { mongoOrm } from \"@internal/mongo-orm\";\nimport { createMongoExecutionStack, createMongoRuntime } from \"@internal/mongo-runtime\";\nimport mongoRuntimeTarget from \"@internal/target-mongo/runtime\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { ConnectionString } from \"mongodb-connection-string-url\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/runtime/mongo-errors.ts\nfunction mongoError(code, message, options) {\n\treturn structuredError(code, message, {\n\t\t...options,\n\t\tmeta: {\n\t\t\t...options?.meta,\n\t\t\textension: \"mongo\"\n\t\t}\n\t});\n}\n//#endregion\n//#region src/runtime/binding.ts\nconst URL_SCHEME_PATTERN = /^([a-z][a-z\\d+.-]*):\\/\\//i;\nconst MONGO_SCHEMES = /* @__PURE__ */ new Set([\"mongodb\", \"mongodb+srv\"]);\nfunction validateMongoUrl(url) {\n\tconst trimmed = url.trim();\n\tif (trimmed.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a non-empty string\");\n\tconst scheme = URL_SCHEME_PATTERN.exec(trimmed)?.[1];\n\tif (scheme === void 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\tif (!MONGO_SCHEMES.has(scheme)) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must use mongodb:// or mongodb+srv://\");\n\ttry {\n\t\treturn new ConnectionString(trimmed);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction extractDbNameFromUrl(parsed) {\n\tconst [encodedDbName = \"\"] = parsed.pathname.slice(1).split(\"/\");\n\tif (encodedDbName.length === 0) return;\n\ttry {\n\t\treturn decodeURIComponent(encodedDbName);\n\t} catch {\n\t\tthrow mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must be a valid URL\");\n\t}\n}\nfunction resolveMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return options.binding;\n\tif (options.url !== void 0) {\n\t\tconst parsed = validateMongoUrl(options.url);\n\t\tif (options.dbName !== void 0 && options.dbName.trim().length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { url, dbName } requires a non-empty dbName\");\n\t\tconst explicitDbName = options.dbName?.trim();\n\t\tconst dbName = explicitDbName !== void 0 && explicitDbName.length > 0 ? explicitDbName : extractDbNameFromUrl(parsed);\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo URL must include a database name in its path (e.g. mongodb://host:27017/mydb), or pass dbName explicitly\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.url.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tif (options.uri !== void 0) {\n\t\tvalidateMongoUrl(options.uri);\n\t\tconst dbName = options.dbName?.trim();\n\t\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { uri, dbName } requires a non-empty dbName\");\n\t\treturn {\n\t\t\tkind: \"url\",\n\t\t\turl: options.uri.trim(),\n\t\t\tdbName\n\t\t};\n\t}\n\tconst mongoClient = options.mongoClient;\n\tif (mongoClient === void 0) throw new InternalError(\"Invariant violation: expected mongo binding after validation\");\n\tconst dbName = options.dbName?.trim();\n\tif (dbName === void 0 || dbName.length === 0) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Mongo binding via { mongoClient, dbName } requires a non-empty dbName\");\n\treturn {\n\t\tkind: \"mongoClient\",\n\t\tclient: mongoClient,\n\t\tdbName\n\t};\n}\nfunction resolveOptionalMongoBinding(options) {\n\tconst providedCount = Number(options.binding !== void 0) + Number(options.url !== void 0) + Number(options.uri !== void 0) + Number(options.mongoClient !== void 0);\n\tif (providedCount === 0) return;\n\tif (providedCount !== 1) throw mongoError(\"RUNTIME.BINDING_INVALID\", \"Provide one binding input: binding, url, uri+dbName, or mongoClient+dbName\", { meta: { received: providedCount } });\n\tif (options.binding !== void 0) return resolveMongoBinding({ binding: options.binding });\n\tif (options.url !== void 0) return resolveMongoBinding(options.dbName !== void 0 ? {\n\t\turl: options.url,\n\t\tdbName: options.dbName\n\t} : { url: options.url });\n\tif (options.uri !== void 0) return resolveMongoBinding({\n\t\turi: options.uri,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tif (options.mongoClient !== void 0) return resolveMongoBinding({\n\t\tmongoClient: options.mongoClient,\n\t\tdbName: options.dbName ?? \"\"\n\t});\n\tthrow new InternalError(\"Invariant violation: expected one mongo binding branch\");\n}\n//#endregion\n//#region src/runtime/prepared-row-query.ts\nasync function prepareMongoQuery(runtime, declaration, callback) {\n\tlet description;\n\tconst statement = await runtime.prepare(declaration, (placeholders) => {\n\t\tconst authored = callback(placeholders);\n\t\tif (\"plan\" in authored) {\n\t\t\tdescription = authored;\n\t\t\treturn authored.plan;\n\t\t}\n\t\treturn authored;\n\t});\n\treturn blindCast(description ? createMongoPreparedRowQuery(description, statement) : statement);\n}\nfunction createMongoPreparedRowQuery(description, statement) {\n\treturn Object.freeze({ query(target, params, options) {\n\t\treturn description.consume(statement.query(target, params, options));\n\t} });\n}\n//#endregion\n//#region src/runtime/mongo.ts\n/**\n* Creates a lazy Mongo client. The client infers its contract type from `contract`: a value from\n* `contractFromJson` for an emitted contract, or a TypeScript-authored contract. A contract is\n* validated once, however many clients are built from it. The `orm` and `query` surfaces are\n* available at once; the driver connects on the first query or `connect()`.\n*\n* @example\n* ```ts\n* import { contractFromJson } from '@prisma/orm-mongo/static';\n* import mongo from '@prisma/orm-mongo/runtime';\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* export const db = mongo({ contract, url: process.env['MONGODB_URL']! });\n* ```\n*/\nfunction mongo(options) {\n\tconst contract = validateMongoContract(options.contract);\n\tlet binding = resolveOptionalMongoBinding(options);\n\tconst stack = createMongoExecutionStack({\n\t\ttarget: mongoRuntimeTarget,\n\t\tadapter: mongoRuntimeAdapter,\n\t\tdriver: mongoRuntimeDriver,\n\t\textensions: options.extensions ?? []\n\t});\n\tconst { context, query, enums, raw } = buildMongoStaticContext(contract, stack);\n\tlet runtimePromise;\n\tlet closed = false;\n\tlet runtimeInstance;\n\tconst closedError = () => mongoError(\"DRIVER.NOT_CONNECTED\", \"Mongo client is closed\");\n\tconst createRuntime = () => {\n\t\tif (runtimeInstance !== void 0) return runtimeInstance;\n\t\tconst driver = stack.driver.create();\n\t\truntimeInstance = {\n\t\t\truntime: createMongoRuntime({\n\t\t\t\tcontext,\n\t\t\t\tadapter: stack.adapter.create(stack),\n\t\t\t\tdriver,\n\t\t\t\t...ifDefined(\"mode\", options.mode),\n\t\t\t\t...ifDefined(\"middleware\", options.middleware)\n\t\t\t}),\n\t\t\tdriver\n\t\t};\n\t\treturn runtimeInstance;\n\t};\n\tconst buildRuntime = async (resolvedBinding) => {\n\t\tconst { runtime, driver } = createRuntime();\n\t\tawait driver.connect(resolvedBinding);\n\t\treturn runtime;\n\t};\n\tconst getRuntime = () => {\n\t\tif (closed) return Promise.reject(closedError());\n\t\tif (runtimePromise !== void 0) return runtimePromise;\n\t\tif (binding === void 0) return Promise.reject(mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\"));\n\t\truntimePromise = buildRuntime(binding).catch((err) => {\n\t\t\truntimePromise = void 0;\n\t\t\tthrow err;\n\t\t});\n\t\treturn runtimePromise;\n\t};\n\tfunction queryRows(plan) {\n\t\tasync function* iterate() {\n\t\t\tyield* (await getRuntime()).query(plan);\n\t\t}\n\t\treturn new AsyncIterableResult(iterate());\n\t}\n\tasync function executeStats(plan) {\n\t\treturn (await getRuntime()).execute(plan);\n\t}\n\treturn {\n\t\torm: mongoOrm({\n\t\t\tcontext,\n\t\t\truntime: {\n\t\t\t\tquery: queryRows,\n\t\t\t\texecute: executeStats\n\t\t\t}\n\t\t}),\n\t\tquery,\n\t\traw,\n\t\tcontract,\n\t\tenums,\n\t\tcontext,\n\t\tasync connect(bindingInput) {\n\t\t\tif (closed) throw closedError();\n\t\t\tif (runtimePromise !== void 0) {\n\t\t\t\tif (bindingInput !== void 0) throw mongoError(\"DRIVER.ALREADY_CONNECTED\", \"Mongo client is already bound\", {\n\t\t\t\t\twhy: \"connect() was given options after the client was bound to a database.\",\n\t\t\t\t\tfix: \"Call connect() without options, or create a new client for another database.\"\n\t\t\t\t});\n\t\t\t\tconst runtime = await runtimePromise;\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\treturn runtime;\n\t\t\t}\n\t\t\tif (bindingInput !== void 0) binding = resolveMongoBinding(bindingInput);\n\t\t\tif (binding === void 0) throw mongoError(\"RUNTIME.BINDING_MISSING\", \"Mongo binding not configured. Pass url/uri+dbName/mongoClient+dbName/binding to mongo(...) or call db.connect({ ... }).\");\n\t\t\tconst runtime = await getRuntime();\n\t\t\tif (closed) throw closedError();\n\t\t\treturn runtime;\n\t\t},\n\t\truntime() {\n\t\t\treturn getRuntime();\n\t\t},\n\t\tasync prepare(declaration, callback) {\n\t\t\tif (closed) throw closedError();\n\t\t\treturn prepareMongoQuery(createRuntime().runtime, declaration, callback);\n\t\t},\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tawait runtimePromise?.catch(() => void 0);\n\t\t\tawait runtimeInstance?.runtime.close();\n\t\t},\n\t\t[Symbol.asyncDispose]() {\n\t\t\treturn this.close();\n\t\t}\n\t};\n}\n//#endregion\nexport { mongo as default };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,WAAW,MAAM,SAAS,SAAS;CAC3C,OAAO,gBAAgB,MAAM,SAAS;EACrC,GAAG;EACH,MAAM;GACL,GAAG,SAAS;GACZ,WAAW;EACZ;CACD,CAAC;AACF;AAGA,MAAM,qBAAqB;AAC3B,MAAM,gCAAgC,IAAI,IAAI,CAAC,WAAW,aAAa,CAAC;AACxE,SAAS,iBAAiB,KAAK;CAC9B,MAAM,UAAU,IAAI,KAAK;CACzB,IAAI,QAAQ,WAAW,GAAG,MAAM,WAAW,2BAA2B,sCAAsC;CAC5G,MAAM,SAAS,mBAAmB,KAAK,OAAO,CAAC,GAAG;CAClD,IAAI,WAAW,KAAK,GAAG,MAAM,WAAW,2BAA2B,+BAA+B;CAClG,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,MAAM,YAAY;GAC9B,OAAO,kBAAkB,cAAc,CAAC,CAAC,SAAS,aAAa,QAAQ;EACxE;EACA,MAAM,QAAQ;GACb,IAAI,QAAQ;GACZ,SAAS;GACT,MAAM,gBAAgB,YAAY,KAAK,CAAC;GACxC,MAAM,iBAAiB,QAAQ,MAAM;EACtC;EACA,CAAC,OAAO,gBAAgB;GACvB,OAAO,KAAK,MAAM;EACnB;CACD;AACD"}
|
package/dist/static.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as contractFromJson, r as mongoStatic } from "./mongo-static-
|
|
1
|
+
import { n as contractFromJson, r as mongoStatic } from "./mongo-static-BkZ1RBOd-BcJDkh_M.mjs";
|
|
2
2
|
export { contractFromJson, mongoStatic as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/orm-mongo",
|
|
3
|
-
"version": "8.0.0-rc.25-dev.
|
|
3
|
+
"version": "8.0.0-rc.25-dev.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"skills"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@prisma/orm-family-mongo": "8.0.0-rc.25-dev.
|
|
17
|
-
"@prisma/orm-framework": "8.0.0-rc.25-dev.
|
|
18
|
-
"@prisma/orm-target-mongo": "8.0.0-rc.25-dev.
|
|
19
|
-
"@prisma/orm-toolchain": "8.0.0-rc.25-dev.
|
|
16
|
+
"@prisma/orm-family-mongo": "8.0.0-rc.25-dev.3",
|
|
17
|
+
"@prisma/orm-framework": "8.0.0-rc.25-dev.3",
|
|
18
|
+
"@prisma/orm-target-mongo": "8.0.0-rc.25-dev.3",
|
|
19
|
+
"@prisma/orm-toolchain": "8.0.0-rc.25-dev.3",
|
|
20
20
|
"mongodb-connection-string-url": "^7.0.2",
|
|
21
21
|
"pathe": "^2.0.3",
|
|
22
22
|
"tinyglobby": "^0.2.17",
|
|
23
23
|
"temporal-spec": "1.0.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@internal/mongo": "8.0.0-rc.25-dev.
|
|
27
|
-
"@repo/tsconfig": "8.0.0-rc.25-dev.
|
|
28
|
-
"@repo/tsdown": "8.0.0-rc.25-dev.
|
|
26
|
+
"@internal/mongo": "8.0.0-rc.25-dev.3",
|
|
27
|
+
"@repo/tsconfig": "8.0.0-rc.25-dev.3",
|
|
28
|
+
"@repo/tsdown": "8.0.0-rc.25-dev.3",
|
|
29
29
|
"tsdown": "0.22.14",
|
|
30
30
|
"typescript": "5.9.3"
|
|
31
31
|
},
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -264,25 +264,41 @@ changes:
|
|
|
264
264
|
A required field new inside a MongoDB value object or embedded model is now filled with a temporary value in the objects that lack it, as at the top level, unless `--backfill` names it.
|
|
265
265
|
- id: json-default-proto-key-kept
|
|
266
266
|
summary: |
|
|
267
|
-
A JSON column default that has a `__proto__` key now keeps that key in `contract.json` and in the storage hash; it used to be dropped. Re-emit the contract, then
|
|
267
|
+
A JSON column default that has a `__proto__` key now keeps that key in `contract.json` and, on Postgres and MySQL, in the storage hash; it used to be dropped. Re-emit the contract, then bring the database's default in line.
|
|
268
268
|
detection:
|
|
269
269
|
glob: "**/*.prisma"
|
|
270
270
|
matches:
|
|
271
271
|
- 'json`[^`]*__proto__'
|
|
272
|
+
- '@default\("(?:[^"\\\n]|\\.)*\\"__proto__\\"'
|
|
272
273
|
- id: mongo-proto-names-refused
|
|
273
274
|
summary: |
|
|
274
|
-
A MongoDB contract now refuses a model, composite type or value object, collection or root named `__proto__`, and the TypeScript builder refuses an enum with that name too. In a PSL contract, an enum named `__proto__` is not refused: it is left out of the contract without an error, together with every field typed by it. Choose another name.
|
|
275
|
+
A MongoDB contract now refuses a model, composite type or value object, collection or root named `__proto__`, and the TypeScript builder refuses an enum with that name too. In a PSL contract, an enum named `__proto__` is not refused: it is left out of the contract without an error, together with every field typed by it. A relation, a member of a composite type or value object, and a field stored under another name are not refused either. Choose another name.
|
|
275
276
|
detection:
|
|
276
|
-
glob: "**/*.{prisma,ts}"
|
|
277
|
+
glob: "**/*.{prisma,ts,mts,cts,tsx}"
|
|
277
278
|
matches:
|
|
278
279
|
- '__proto__'
|
|
279
280
|
- id: sql-proto-names-refused
|
|
280
281
|
summary: |
|
|
281
|
-
A SQL contract now refuses a
|
|
282
|
+
A SQL contract now refuses a table, column, model, field, relation, enum or other name that is `__proto__`. A field of that name stored under another name used to be left out of the contract without an error. Rename it in the contract source.
|
|
282
283
|
detection:
|
|
283
|
-
glob: "**/*.{prisma,ts}"
|
|
284
|
+
glob: "**/*.{prisma,ts,mts,cts,tsx}"
|
|
284
285
|
matches:
|
|
285
286
|
- '__proto__'
|
|
287
|
+
- id: sql-select-alias-proto-refused
|
|
288
|
+
summary: |
|
|
289
|
+
A SQL query builder `select` that names a result column `__proto__` is refused with `RUNTIME.AST_INVALID`. Choose another alias.
|
|
290
|
+
detection:
|
|
291
|
+
glob: "**/*.{ts,mts,cts,tsx}"
|
|
292
|
+
matches:
|
|
293
|
+
- 'select\(\s*[''"`]__proto__[''"`]'
|
|
294
|
+
- '\[\s*[''"`]__proto__[''"`]\s*[\],]'
|
|
295
|
+
- id: postgres-infer-proto-name-refused
|
|
296
|
+
summary: |
|
|
297
|
+
On Postgres, `prisma contract infer` now fails with `CONTRACT.INFER_UNSUPPORTED` when the database has a table or column named `__proto__`. Rename it in the database first.
|
|
298
|
+
detection:
|
|
299
|
+
glob: "{**/{package.json,*.sh,*.yml,*.yaml,Makefile,justfile},.github/workflows/*.{yml,yaml},.gitlab-ci.yml}"
|
|
300
|
+
contains:
|
|
301
|
+
- 'contract infer'
|
|
286
302
|
- id: update-data-refuses-discriminator
|
|
287
303
|
summary: |
|
|
288
304
|
Update data on a polymorphic model no longer takes the discriminator field: setting it is a type error, and at run time it is refused with `ORM.FIELD_IMMUTABLE`. Before, it changed only the base table and left the variant's rows inconsistent. Remove the discriminator from update data.
|
|
@@ -402,11 +418,11 @@ Do the steps in this order, and skip a step that does not apply to the project:
|
|
|
402
418
|
1. Before you deploy the upgrade, on PostgreSQL with `money` columns, make the database print `money` in the `C` form (`postgres-lc-monetary-not-set`). The old release still forces it on its own connections, so do this first.
|
|
403
419
|
2. Before you run the install for the upgrade, fix the dependencies in `package.json`: declare `pg` and `@types/pg` for the PostgreSQL packages (`pg-is-a-peer-dependency`), move a declared `temporal-polyfill` to `^1.0.8` (`temporal-polyfill-peer-range-moves-to-1-0-8`), and move a declared `@prisma/cli-engine` to `0.10.4` (`engine-pin-moves-to-0-10-4`). Then upgrade the Prisma packages.
|
|
404
420
|
3. Change the config and the scripts that call the control client: the renamed config type (`config-type-renamed-to-prisma-config`), the modules a hand-assembled config names (`hand-assembled-config-names-generated-file-modules`), `typesModule` and the removed `projectDir` (`control-api-takes-types-module`), the removed `publish-surface` entries (`toolchain-publish-surface-entrypoints-removed`), the arguments of `typescriptContractFromPath` (`typescript-contract-from-path-requires-target`), and the `migrate`, `dbUpdate` and `dbSign` options (`migrate-options-ref`, `db-sign-invocation`, `permit-policy-change`). Change the commands that run `prisma db migrate`, in scripts, deploys and docs, for the `db` ref it now advances (`db-migrate-advances-db-ref`).
|
|
405
|
-
4. Change the contract sources. Make each TypeScript contract import `defineContract` from its config's target (`typescript-contract-for-another-target-refused`). Save every schema file as UTF-8 (`psl-schema-must-be-utf8`). Rewrite the renamed types and helpers: `sql.String` (`psl-renamed-sql-string`, `ts-renamed-sql-string`), the PostgreSQL and SQLite column helpers (`ts-renamed-postgres-json-column-helper`, `ts-renamed-sqlite-column-helpers`), SQLite's `BigIntNumber` (`sqlite-bigintnumber-deprecated`) and MongoDB's `Int64` (`psl-renamed-mongo-int64`, `ts-removed-mongo-int64-helper`, and optionally `psl-optional-mongo-convenience-names`). Fix each `hasOne` relation without a unique key (`has-one-key-must-be-unique`) and each attribute of a single-table variant that emit refuses (`sti-variant-unscoped-index-refused`). Rename anything named `__proto__` (`sql-proto-names-refused`, `mongo-proto-names-refused`).
|
|
421
|
+
4. Change the contract sources. Make each TypeScript contract import `defineContract` from its config's target (`typescript-contract-for-another-target-refused`). Save every schema file as UTF-8 (`psl-schema-must-be-utf8`). Rewrite the renamed types and helpers: `sql.String` (`psl-renamed-sql-string`, `ts-renamed-sql-string`), the PostgreSQL and SQLite column helpers (`ts-renamed-postgres-json-column-helper`, `ts-renamed-sqlite-column-helpers`), SQLite's `BigIntNumber` (`sqlite-bigintnumber-deprecated`) and MongoDB's `Int64` (`psl-renamed-mongo-int64`, `ts-removed-mongo-int64-helper`, and optionally `psl-optional-mongo-convenience-names`). Fix each `hasOne` relation without a unique key (`has-one-key-must-be-unique`) and each attribute of a single-table variant that emit refuses (`sti-variant-unscoped-index-refused`). Rename anything named `__proto__` (`sql-proto-names-refused`, `mongo-proto-names-refused`); on MongoDB, read that section first, because a collection of that name needs its documents moved. On Postgres, rename a table or column named `__proto__` in the database before the next `prisma contract infer` (`postgres-infer-proto-name-refused`).
|
|
406
422
|
5. Run `prisma contract emit` once for every contract and commit what it writes. One emit covers `contract-types-import-from-the-target-package`, `re-emit-for-include-capabilities`, `re-emit-mysql-contract-for-aggregates`, `mysql-reemit-contract`, `sqlite-decimal-codec`, `ts-sqlite-decimal-codec`, `sti-variant-foreign-keys-stored`, `json-default-proto-key-kept` and `contract-artifacts-restamp`. Leave the contract copies under `migrations/` as they are.
|
|
407
423
|
6. Before you plan any migration, read what the planner now does: on PostgreSQL and SQLite a changed stored name is a rename (`sql-stored-name-change-is-a-rename`, `sql-stored-name-delete-is-unused`, `sql-stored-name-empty-table`, `sql-stored-name-swaps-refused`, `sql-lowered-table-names-renamed`), and on MongoDB changes inside documents are asked about and planned (`mongo-nested-removals-are-asked`, `mongo-nested-statements-are-planned`, `mongo-nested-required-field-gets-temporary-value`). A migration planned in the next step can hold such renames. If you add `@@map` to keep a table's old name, run `prisma contract emit` again first.
|
|
408
|
-
7. Bring each database up to date. Plan and apply a migration for a new unique key (`has-one-key-must-be-unique`), for a JSON default that has a `__proto__` key (`json-default-proto-key-kept
|
|
409
|
-
8. Change the application code: work sent on a transaction while an ORM write runs on it (`orm-write-inside-transaction-suspends-tx`), update data that sets a discriminator (`update-data-refuses-discriminator`), `update()` data that sets a foreign key and also has a callback on its relation (`foreign-key-with-relation-callback-refused`), tables whose only unique key has a nullable column (`nullable-unique-key-is-no-row-identity`), the ORM error codes of nested relation mutations (`relation-mutation-error-codes-merged`), nested creates on a polymorphic model (`nested-create-on-polymorphic-target-needs-variant`, `variant-create-without-returning-names-create`), `disconnect` (`disconnect-on-required-relation-refused`, `to-one-disconnect-criteria-applied`, `disconnect-empty-criteria-disconnects-nothing`), `onConflict: 'skip'` (`create-all-skip-refuses-rows-without-conflict-key`, `create-all-skip-refuses-tables-without-keys`), SQL builder comparisons (`sql-builder-enum-comparison-values-are-checked`), code that reads `meta.target` from a MySQL error (`mysql-errors-drop-meta-target`), scripts that read the `--json` result of `prisma orm init` (`init-target-takes-a-package-name`) and code that matches the first line of `CLI.CONSENT_REQUIRED` (`consent-required-summary-is-one-fixed-sentence`). Three of these fixes change the contract: giving a table a primary key or required key fields (`nullable-unique-key-is-no-row-identity`), giving a table a key for `onConflict: 'skip'` (`create-all-skip-refuses-tables-without-keys`), and making a foreign key optional (`disconnect-on-required-relation-refused`). After any of them, emit the contract and plan and apply a migration again.
|
|
424
|
+
7. Bring each database up to date. Plan and apply a migration for a new unique key (`has-one-key-must-be-unique`), for a JSON default that has a `__proto__` key (`json-default-proto-key-kept`; on MySQL its section has you write that change by hand, and on SQLite there is none) and for the indexes and foreign keys of single-table variants (`sti-variant-unscoped-index-refused`, `sti-variant-foreign-keys-stored`). On SQLite, fix stored values the stricter codecs refuse (`sqlite-decimal-codec`, `sqlite-integer-safe-range`), then sign the database with the new contract as the SQLite section describes. One migration can cover all of these. In a project that applied its earlier migrations with `db migrate` and no `--advance-ref`, there is no `db` ref for `migration plan` to start from: pass `--from <latest migration>`, as the SQLite section shows.
|
|
425
|
+
8. Change the application code: work sent on a transaction while an ORM write runs on it (`orm-write-inside-transaction-suspends-tx`), update data that sets a discriminator (`update-data-refuses-discriminator`), `update()` data that sets a foreign key and also has a callback on its relation (`foreign-key-with-relation-callback-refused`), tables whose only unique key has a nullable column (`nullable-unique-key-is-no-row-identity`), the ORM error codes of nested relation mutations (`relation-mutation-error-codes-merged`), nested creates on a polymorphic model (`nested-create-on-polymorphic-target-needs-variant`, `variant-create-without-returning-names-create`), `disconnect` (`disconnect-on-required-relation-refused`, `to-one-disconnect-criteria-applied`, `disconnect-empty-criteria-disconnects-nothing`), `onConflict: 'skip'` (`create-all-skip-refuses-rows-without-conflict-key`, `create-all-skip-refuses-tables-without-keys`), SQL builder comparisons (`sql-builder-enum-comparison-values-are-checked`), code that reads `meta.target` from a MySQL error (`mysql-errors-drop-meta-target`), scripts that read the `--json` result of `prisma orm init` (`init-target-takes-a-package-name`) and code that matches the first line of `CLI.CONSENT_REQUIRED` (`consent-required-summary-is-one-fixed-sentence`). Three of these fixes change the contract: giving a table a primary key or required key fields (`nullable-unique-key-is-no-row-identity`), giving a table a key for `onConflict: 'skip'` (`create-all-skip-refuses-tables-without-keys`), and making a foreign key optional (`disconnect-on-required-relation-refused`). After any of them, emit the contract and plan and apply a migration again. Choose another alias for a SQL `select` column named `__proto__` (`sql-select-alias-proto-refused`).
|
|
410
426
|
|
|
411
427
|
|
|
412
428
|
## PostgreSQL: `money` needs the database's `lc_monetary` to print the `C` form
|
|
@@ -1118,7 +1134,7 @@ To write your own value instead, plan the change with `migration plan --backfill
|
|
|
1118
1134
|
|
|
1119
1135
|
## Names and keys that JavaScript objects inherit
|
|
1120
1136
|
|
|
1121
|
-
Names such as `constructor` and `toString` now work everywhere as model, table, column and field names, and need no action.
|
|
1137
|
+
Names such as `constructor` and `toString` now work everywhere as model, table, column and field names, and need no action. Five cases with `__proto__` do, one section each below.
|
|
1122
1138
|
|
|
1123
1139
|
### `json-default-proto-key-kept`
|
|
1124
1140
|
|
|
@@ -1129,37 +1145,65 @@ model User {
|
|
|
1129
1145
|
}
|
|
1130
1146
|
```
|
|
1131
1147
|
|
|
1132
|
-
|
|
1148
|
+
A Prisma 7 schema writes the same default as a string, `meta Json @default("{\"__proto__\": {\"x\": 1}, \"a\": 2}")`, and is affected in the same way.
|
|
1133
1149
|
|
|
1134
|
-
|
|
1135
|
-
2. Run `prisma migration plan` and apply the migration, or run `prisma db update`. Either plans one operation per such column, `Set default on "<table>"."<column>"`.
|
|
1150
|
+
`prisma contract emit` used to leave the `__proto__` key out of `contract.json`. On Postgres and MySQL it also left it out of the storage hash, so the database got the default `{"a": 2}`. It now keeps the key. What to do for each file the detection matches depends on the database:
|
|
1136
1151
|
|
|
1137
|
-
|
|
1152
|
+
- **Postgres.** Run `prisma contract emit`; the storage hash changes. Then run `prisma migration plan` and apply the migration, or run `prisma db update`. Either plans one operation per such column, `Set default on "<table>"."<column>"`. The planned migration applies as it is. If you run its `migration.ts` to regenerate `ops.json`, the run fails with `CONTRACT.DEFAULT_INVALID`, because the file writes the key as `__proto__:`, with or without quotes, which JavaScript reads as the prototype; write the key as `['__proto__']:` in `migration.ts` first.
|
|
1153
|
+
- **MySQL.** Run `prisma contract emit`; the storage hash changes. The migration planner does not plan a change of a column's default, so create a migration with `prisma migration new` and write a raw SQL operation in it that sets the column's default.
|
|
1154
|
+
- **SQLite.** No action. SQLite stores the default as JSON text that already kept the key, so nothing changes.
|
|
1155
|
+
|
|
1156
|
+
Until the default is applied, the SQL runtime logs `CONTRACT.MARKER_MISMATCH` as a warning and still runs queries. If you do not want the key in the default, remove it from the contract source instead.
|
|
1138
1157
|
|
|
1139
1158
|
### `mongo-proto-names-refused`
|
|
1140
1159
|
|
|
1141
|
-
JavaScript reads `__proto__` as the prototype of an object rather than as a key, so a contract could not hold such a name: the client lost the model or collection. A MongoDB contract now refuses
|
|
1160
|
+
JavaScript reads `__proto__` as the prototype of an object rather than as a key, so a contract could not hold such a name: the client lost the model or collection. A MongoDB contract now refuses a model, composite type or value object, collection or root of that name, and the TypeScript builder refuses an enum of that name. The TypeScript builder raises `CONTRACT.NAME_UNUSABLE_AS_KEY`; a PSL contract reports `PSL_STORED_NAME_UNSUPPORTED`:
|
|
1142
1161
|
|
|
1143
1162
|
```text
|
|
1144
1163
|
A model is named "__proto__", which JavaScript reads as the prototype of an object rather than as a key. Choose another name.
|
|
1145
1164
|
```
|
|
1146
1165
|
|
|
1147
|
-
In a PSL contract, an enum named `__proto__` is
|
|
1166
|
+
Some cases are not refused in this release and still go wrong without an error. In a Mongo PSL contract, an enum named `__proto__` is left out of the contract, together with every field typed by it. A relation, a member of a composite type or value object, a field stored under another name, and a field of a Prisma 6 schema with no `@map` are, depending on the contract source, left out of the contract or out of every row the client reads. Rename the enum, and a field whose stored name you keep with `@map`; neither changes a document. Leave a relation, a member and a Prisma 6 field with no `@map` as they are: a later release refuses them, and its guide covers the rename together with the values that documents hold under the old key.
|
|
1167
|
+
|
|
1168
|
+
Rename the model, composite type, enum or root. The TypeScript builder also refuses an object literal with a `__proto__` key, such as `models: { __proto__: Post, User }`, which used to drop the entry without an error.
|
|
1148
1169
|
|
|
1149
|
-
|
|
1170
|
+
For a collection, name another collection with `@@map`. `@@map` only changes which collection the client reads and writes: documents already in a collection named `__proto__` stay there. In `mongosh`, `db.__proto__` is not the collection, so name it with `db.getCollection("__proto__")`. Stop every process that writes to the old or the new collection before you start, and restart one only when the move has finished, including any copy you repeat, and the process uses the new name. A write that reaches `__proto__` after the move is lost, because `db update` drops that collection, or you drop it after the copy; and a repeated copy overwrites what a writer changed in the new collection in the meantime. How to move the documents depends on the command you apply changes with:
|
|
1171
|
+
|
|
1172
|
+
- **`prisma db update`.** Rename the collection in the database first, then emit the contract and run `db update`. If you run `db update` first, it plans to drop the collection named `__proto__`, with its documents.
|
|
1173
|
+
|
|
1174
|
+
```js
|
|
1175
|
+
db.getCollection("__proto__").renameCollection("<new name>")
|
|
1176
|
+
```
|
|
1177
|
+
|
|
1178
|
+
- **`prisma migration plan`.** Emit the contract and apply the migration, which creates the new collection. Then copy the documents into it, and drop the old collection when the application reads the new one correctly. The copy checks each document against the new collection's validator and stops at one it rejects; fix that document and run the copy again.
|
|
1179
|
+
|
|
1180
|
+
```js
|
|
1181
|
+
db.getCollection("__proto__").aggregate([{ $merge: { into: "<new name>" } }])
|
|
1182
|
+
db.getCollection("__proto__").drop()
|
|
1183
|
+
```
|
|
1150
1184
|
|
|
1151
1185
|
### `sql-proto-names-refused`
|
|
1152
1186
|
|
|
1153
|
-
A SQL contract refuses the
|
|
1187
|
+
A SQL contract now refuses `__proto__` as the name of a table, column, model, field, relation, enum, namespace or any other name it keys an object by, with `CONTRACT.NAME_UNUSABLE_AS_KEY`:
|
|
1154
1188
|
|
|
1155
1189
|
```text
|
|
1156
|
-
|
|
1190
|
+
The namespace of table "users" is named "__proto__", which JavaScript reads as the prototype of an object rather than as a key. Choose another name.
|
|
1157
1191
|
```
|
|
1158
1192
|
|
|
1159
|
-
|
|
1193
|
+
What happened before:
|
|
1194
|
+
|
|
1195
|
+
- A table or column stored as `__proto__`, and a model named `__proto__`, already failed `prisma contract emit` with an unrelated error. They now fail with this one.
|
|
1196
|
+
- A field named `__proto__` and stored under another name, as in `__proto__ String @map("label")`, emitted, but the field was missing from the model. So was an entry written as a `__proto__:` key in a TypeScript object literal. Both are now refused; the object literal has its own message, which says the record is not a plain object.
|
|
1197
|
+
|
|
1198
|
+
Rename the field in the contract source and keep its stored name with `@map`; no database change is needed. If the database has a table or column named `__proto__`, rename it in the database too.
|
|
1199
|
+
|
|
1200
|
+
### `sql-select-alias-proto-refused`
|
|
1201
|
+
|
|
1202
|
+
A SQL query builder `select` that names a result column `__proto__`, as in `select('__proto__', …)` or a `select` callback that returns a record with that key, is refused with `RUNTIME.AST_INVALID` while the query is built. Such a column could never come back as a key of the row. Choose another alias.
|
|
1160
1203
|
|
|
1161
|
-
|
|
1204
|
+
### `postgres-infer-proto-name-refused`
|
|
1162
1205
|
|
|
1206
|
+
`prisma contract infer` now fails with `CONTRACT.INFER_UNSUPPORTED` when the database has a table or column named `__proto__`, and names it. It used to leave such a table out of the inferred contract without a word, so the next plan would have dropped it. No contract source accepts the name, so rename the table or column in the database before running `contract infer` again.
|
|
1163
1207
|
|
|
1164
1208
|
## Concurrent work on `tx` during an ORM write
|
|
1165
1209
|
|