@prisma/orm-mongo 8.0.1-dev.1 → 8.0.1-dev.11
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/init-quick-reference.md +1 -1
- package/dist/{mongo-static-CfvV1-qX-DdckMRxc.mjs → mongo-static-Co8FYiQU-C4pwzXLx.mjs} +3 -3
- package/dist/mongo-static-Co8FYiQU-C4pwzXLx.mjs.map +1 -0
- package/dist/runtime.d.mts +2 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +12 -81
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/contract.md +6 -6
- package/skills/prisma-8/references/debug.md +1 -1
- package/skills/prisma-8/references/migration-review.md +1 -1
- package/skills/prisma-8/references/migrations.md +8 -6
- package/skills/prisma-8/references/queries-postgres.md +2 -2
- package/skills/prisma-8/references/quickstart.md +1 -1
- package/skills/prisma-8/references/supabase.md +2 -2
- package/dist/adapter.d.mts +0 -1
- package/dist/adapter.mjs +0 -2
- package/dist/adapter__control.d.mts +0 -3
- package/dist/adapter__control.mjs +0 -3
- package/dist/adapter__runtime.d.mts +0 -3
- package/dist/adapter__runtime.mjs +0 -3
- package/dist/components.d.mts +0 -1
- package/dist/components.mjs +0 -2
- package/dist/components__authoring.d.mts +0 -1
- package/dist/components__authoring.mjs +0 -2
- package/dist/components__codec.d.mts +0 -1
- package/dist/components__codec.mjs +0 -2
- package/dist/components__components.d.mts +0 -1
- package/dist/components__components.mjs +0 -2
- package/dist/components__control.d.mts +0 -1
- package/dist/components__control.mjs +0 -2
- package/dist/components__emission.d.mts +0 -1
- package/dist/components__emission.mjs +0 -2
- package/dist/components__execution.d.mts +0 -1
- package/dist/components__execution.mjs +0 -2
- package/dist/components__ir.d.mts +0 -1
- package/dist/components__ir.mjs +0 -2
- package/dist/components__psl-ast.d.mts +0 -1
- package/dist/components__psl-ast.mjs +0 -2
- package/dist/components__utils.d.mts +0 -1
- package/dist/components__utils.mjs +0 -2
- package/dist/contract.d.mts +0 -1
- package/dist/contract.mjs +0 -2
- package/dist/contract__apply-specifier-default-control-policy.d.mts +0 -1
- package/dist/contract__apply-specifier-default-control-policy.mjs +0 -2
- package/dist/contract__contract-validation-error.d.mts +0 -1
- package/dist/contract__contract-validation-error.mjs +0 -2
- package/dist/contract__default-namespace.d.mts +0 -1
- package/dist/contract__default-namespace.mjs +0 -2
- package/dist/contract__enum-accessor.d.mts +0 -1
- package/dist/contract__enum-accessor.mjs +0 -2
- package/dist/contract__format-version.d.mts +0 -1
- package/dist/contract__format-version.mjs +0 -2
- package/dist/contract__hashing-utils.d.mts +0 -1
- package/dist/contract__hashing-utils.mjs +0 -2
- package/dist/contract__hashing.d.mts +0 -1
- package/dist/contract__hashing.mjs +0 -2
- package/dist/contract__internal__format-version.d.mts +0 -1
- package/dist/contract__internal__format-version.mjs +0 -2
- package/dist/contract__is-plain-record.d.mts +0 -1
- package/dist/contract__is-plain-record.mjs +0 -2
- package/dist/contract__resolve-domain-model.d.mts +0 -1
- package/dist/contract__resolve-domain-model.mjs +0 -2
- package/dist/contract__validate-domain.d.mts +0 -1
- package/dist/contract__validate-domain.mjs +0 -2
- package/dist/contract__validate-once.d.mts +0 -1
- package/dist/contract__validate-once.mjs +0 -2
- package/dist/contract__validate-storage.d.mts +0 -1
- package/dist/contract__validate-storage.mjs +0 -2
- package/dist/driver.d.mts +0 -1
- package/dist/driver.mjs +0 -2
- package/dist/driver__control.d.mts +0 -3
- package/dist/driver__control.mjs +0 -3
- package/dist/driver__runtime.d.mts +0 -3
- package/dist/driver__runtime.mjs +0 -3
- package/dist/family-contract__canonicalization-hooks.d.mts +0 -1
- package/dist/family-contract__canonicalization-hooks.mjs +0 -2
- package/dist/family-contract__data-type.d.mts +0 -1
- package/dist/family-contract__data-type.mjs +0 -2
- package/dist/family-contract__entity-kinds.d.mts +0 -1
- package/dist/family-contract__entity-kinds.mjs +0 -2
- package/dist/family__control-adapter.d.mts +0 -1
- package/dist/family__control-adapter.mjs +0 -2
- package/dist/family__ir.d.mts +0 -1
- package/dist/family__ir.mjs +0 -2
- package/dist/family__migration.d.mts +0 -1
- package/dist/family__migration.mjs +0 -2
- package/dist/family__pack.d.mts +0 -3
- package/dist/family__pack.mjs +0 -3
- package/dist/family__runtime.d.mts +0 -1
- package/dist/family__runtime.mjs +0 -2
- package/dist/family__schema-verify.d.mts +0 -1
- package/dist/family__schema-verify.mjs +0 -2
- package/dist/migration-tools__contract-snapshot-store.d.mts +0 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +0 -2
- package/dist/mongo-static-CfvV1-qX-DdckMRxc.mjs.map +0 -1
- package/dist/query-ast.d.mts +0 -1
- package/dist/query-ast.mjs +0 -2
- package/dist/query-ast__control.d.mts +0 -1
- package/dist/query-ast__control.mjs +0 -2
- package/dist/query-builder__contract-free.d.mts +0 -1
- package/dist/query-builder__contract-free.mjs +0 -2
- package/dist/target__codecs.d.mts +0 -1
- package/dist/target__codecs.mjs +0 -2
- package/dist/target__control.d.mts +0 -1
- package/dist/target__control.mjs +0 -2
- package/dist/target__data-types.d.mts +0 -1
- package/dist/target__data-types.mjs +0 -2
- package/dist/target__pack.d.mts +0 -3
- package/dist/target__pack.mjs +0 -3
- package/dist/target__server-version.d.mts +0 -1
- package/dist/target__server-version.mjs +0 -2
- package/dist/utils.d.mts +0 -1
- package/dist/utils.mjs +0 -2
- package/dist/utils__abortable.d.mts +0 -1
- package/dist/utils__abortable.mjs +0 -2
- package/dist/utils__array-equal.d.mts +0 -1
- package/dist/utils__array-equal.mjs +0 -2
- package/dist/utils__assertions.d.mts +0 -1
- package/dist/utils__assertions.mjs +0 -2
- package/dist/utils__canonical-stringify.d.mts +0 -1
- package/dist/utils__canonical-stringify.mjs +0 -2
- package/dist/utils__casts.d.mts +0 -1
- package/dist/utils__casts.mjs +0 -2
- package/dist/utils__defined.d.mts +0 -1
- package/dist/utils__defined.mjs +0 -2
- package/dist/utils__guards.d.mts +0 -1
- package/dist/utils__guards.mjs +0 -2
- package/dist/utils__hash-content.d.mts +0 -1
- package/dist/utils__hash-content.mjs +0 -2
- package/dist/utils__internal-error.d.mts +0 -1
- package/dist/utils__internal-error.mjs +0 -2
- package/dist/utils__json.d.mts +0 -1
- package/dist/utils__json.mjs +0 -2
- package/dist/utils__promise.d.mts +0 -1
- package/dist/utils__promise.mjs +0 -2
- package/dist/utils__redact-db-url.d.mts +0 -1
- package/dist/utils__redact-db-url.mjs +0 -2
- package/dist/utils__result.d.mts +0 -1
- package/dist/utils__result.mjs +0 -2
- package/dist/utils__simplify-deep.d.mts +0 -1
- package/dist/utils__simplify-deep.mjs +0 -2
- package/dist/utils__structured-error.d.mts +0 -1
- package/dist/utils__structured-error.mjs +0 -2
- package/dist/utils__suppress-idle-connection-errors.d.mts +0 -1
- package/dist/utils__suppress-idle-connection-errors.mjs +0 -2
- package/dist/utils__text.d.mts +0 -1
- package/dist/utils__text.mjs +0 -2
- package/dist/utils__types.d.mts +0 -1
- package/dist/utils__types.mjs +0 -2
- package/dist/utils__upgrade-guides.d.mts +0 -1
- package/dist/utils__upgrade-guides.mjs +0 -2
- package/dist/value__mongodb-types.d.mts +0 -1
- package/dist/value__mongodb-types.mjs +0 -2
|
@@ -42,7 +42,7 @@ If you use a framework like Next.js or Vite, the Prisma ORM plugin will do this
|
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
44
|
import 'dotenv/config';
|
|
45
|
-
import { definePrismaConfig } from '
|
|
45
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
46
46
|
import { defineConfig as ormConfig } from '{{configEntrypoint}}';
|
|
47
47
|
|
|
48
48
|
export default definePrismaConfig({
|
|
@@ -9,8 +9,8 @@ import { buildNamespacedEnums } from "@prisma/orm-framework/contract/enum-access
|
|
|
9
9
|
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
10
10
|
import { mongoQuery } from "@prisma/orm-family-mongo/query-builder";
|
|
11
11
|
import { assertDefined } from "@prisma/orm-framework/utils/assertions";
|
|
12
|
-
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-
|
|
13
|
-
var version = "8.0.1-dev.
|
|
12
|
+
//#region ../../../3-targets/mongo/9-facade/dist/mongo-static-Co8FYiQU.mjs
|
|
13
|
+
var version = "8.0.1-dev.11";
|
|
14
14
|
const serializer = new MongoContractSerializer();
|
|
15
15
|
const validator = `${mongoRuntimeTarget.targetId}@${version}`;
|
|
16
16
|
/**
|
|
@@ -71,4 +71,4 @@ function mongoStatic(options) {
|
|
|
71
71
|
//#endregion
|
|
72
72
|
export { validateMongoContract as i, contractFromJson as n, mongoStatic as r, buildMongoStaticContext as t };
|
|
73
73
|
|
|
74
|
-
//# sourceMappingURL=mongo-static-
|
|
74
|
+
//# sourceMappingURL=mongo-static-Co8FYiQU-C4pwzXLx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo-static-Co8FYiQU-C4pwzXLx.mjs","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/mongo-static-Co8FYiQU.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.11\";\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-Co8FYiQU.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"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { n as MongoTargetId, t as MongoStaticContext } from "./mongo-static-Dabe
|
|
|
2
2
|
import { MongoClient as MongoClient$1 } from "mongodb";
|
|
3
3
|
import { MongoOrmClient, MongoPreparable, MongoQueryExecutor, MongoQueryPlan, MongoRawClient } from "@prisma/orm-family-mongo/orm";
|
|
4
4
|
import { MongoDeclaration, MongoExecutionContext, MongoMiddleware, MongoParamsFromDeclaration, MongoPlaceholders, MongoPreparedFor, MongoRuntime, MongoRuntimeExtensionDescriptor } from "@prisma/orm-family-mongo/runtime";
|
|
5
|
+
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
5
6
|
import { MongoBinding, MongoBinding as MongoBinding$1 } from "@prisma/orm-target-mongo/driver/runtime";
|
|
6
7
|
import { RuntimeExecuteOptions, RuntimeLog, RuntimeMode } from "@prisma/orm-framework/components/runtime";
|
|
7
8
|
import { AnyMongoTypeMaps, ExtractMongoCodecTypes, MongoCodecTypesBase, MongoContract, MongoContractWithTypeMaps } from "@prisma/orm-family-mongo/contract";
|
|
@@ -104,5 +105,5 @@ type MongoOptions<TContract extends MongoContractWithTypeMaps<MongoContract, Any
|
|
|
104
105
|
*/
|
|
105
106
|
declare function mongo<TContract extends MongoContractWithTypeMaps<MongoContract, AnyMongoTypeMaps>>(options: MongoOptions<TContract>): MongoClient<TContract>;
|
|
106
107
|
//#endregion
|
|
107
|
-
export { type MongoBinding, type MongoBindingInput, type MongoClient, type MongoOptions, type MongoPrepareMember, type MongoPreparedFrom, type MongoPreparedRowQuery, type MongoTargetId, mongo as default };
|
|
108
|
+
export { type MongoBinding, type MongoBindingInput, type MongoClient, type MongoOptions, type MongoPrepareMember, type MongoPreparedFrom, type MongoPreparedRowQuery, type MongoTargetId, mongo as default, isStructuredError };
|
|
108
109
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.d.mts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../../../../3-targets/mongo/9-facade/dist/runtime.d.mts"],"mappings":";;;;;;;;;;KASK;WACM,SAAS;WACT;WACA;WACA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA,aAAa;WACb;WACA;WACA;WACA;;;;;UAKD,sBAAsB,QAAQ;EACtC,MAAM,QAAQ,oBAAoB,QAAQ,QAAQ,UAAU,wBAAwB;;;KAGjF,kBAAkB,QAAQ,KAAK,UAAU,+BAA+B,UAAU,sBAAsB,QAAQ,UAAU,UAAU,qBAAqB,WAAW,WAAW,iBAAiB,QAAQ,KAAK;;UAExM,mBAAmB,kBAAkB,0BAA0B,eAAe;;;;EAItF,QAAQ,UAAU,iBAAiB,KAAK,UAAU,iBAAiB,mCAAmC,WAAW,sBAAsB,uBAAuB,YAAY,aAAa,GAAG,WAAW,cAAc,kBAAkB,OAAO,IAAI,QAAQ,kBAAkB,2BAA2B,GAAG,KAAK;;;;KAI1S,aAAa,kBAAkB,0BAA0B,eAAe,qBAAqB,mBAAmB;;;;UAI3G,YAAY,kBAAkB,0BAA0B,eAAe,2BAA2B,mBAAmB;WACpH,KAAK,eAAe;WACpB,OAAO,mBAAmB;WAC1B,KAAK,eAAe;WACpB,UAAU;WACV,OAAO,aAAa;WACpB,SAAS,sBAAsB;EACxC,QAAQ,eAAe,oBAAoB,QAAQ;EACnD,WAAW,QAAQ;EACnB,SAAS;GACR,OAAO,iBAAiB;;UAEjB;WACC,sBAAsB,gCAAgC;WACtD,OAAO;;;;WAIP,sBAAsB;;WAEtB,MAAM;;UAEP;WACC,UAAU;WACV;WACA;WACA;WACA,gCAAgC;;KAEtC,aAAa,kBAAkB,0BAA0B,eAAe,qBAAqB,sBAAsB;WAC7G,UAAU;;;;;;;;;;;;;;;;;;;iBAmBJ,MAAM,kBAAkB,0BAA0B,eAAe,mBAAmB,SAAS,aAAa,aAAa,YAAY"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-
|
|
1
|
+
import { i as validateMongoContract, t as buildMongoStaticContext } from "./mongo-static-Co8FYiQU-C4pwzXLx.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";
|
|
5
5
|
import { createMongoExecutionStack, createMongoRuntime } from "@prisma/orm-family-mongo/runtime";
|
|
6
6
|
import mongoRuntimeTarget from "@prisma/orm-target-mongo/target/runtime";
|
|
7
|
+
import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
7
8
|
import mongoRuntimeDriver from "@prisma/orm-target-mongo/driver/runtime";
|
|
8
9
|
import { AsyncIterableResult } from "@prisma/orm-framework/components/runtime";
|
|
9
10
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
10
11
|
import { ConnectionString } from "mongodb-connection-string-url";
|
|
11
|
-
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
12
12
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
13
13
|
//#region ../../../3-targets/mongo/9-facade/dist/runtime.mjs
|
|
14
14
|
function mongoError(code, message, options) {
|
|
@@ -235,6 +235,6 @@ function mongo(options) {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
//#endregion
|
|
238
|
-
export { mongo as default };
|
|
238
|
+
export { mongo as default, isStructuredError };
|
|
239
239
|
|
|
240
240
|
//# sourceMappingURL=runtime.mjs.map
|
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-CfvV1-qX.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\t...ifDefined(\"log\", options.log)\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"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,cAAc;GAC3B,IAAI,QAAQ,MAAM,YAAY;GAC9B,IAAI,mBAAmB,KAAK,GAAG;IAC9B,IAAI,iBAAiB,KAAK,GAAG,MAAM,WAAW,4BAA4B,iCAAiC;KAC1G,KAAK;KACL,KAAK;IACN,CAAC;IACD,MAAM,UAAU,MAAM;IACtB,IAAI,QAAQ,MAAM,YAAY;IAC9B,OAAO;GACR;GACA,IAAI,iBAAiB,KAAK,GAAG,UAAU,oBAAoB,YAAY;GACvE,IAAI,YAAY,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-Co8FYiQU.mjs\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { isStructuredError, structuredError } from \"@internal/utils/structured-error\";\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 { 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\t...ifDefined(\"log\", options.log)\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, isStructuredError };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,WAAW,MAAM,SAAS,SAAS;CAC3C,OAAO,gBAAgB,MAAM,SAAS;EACrC,GAAG;EACH,MAAM;GACL,GAA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4B,iCAAiC;KAC1G,KAAK;KACL,KAAK;IACN,CAAC;IACD,MAAM,UAAU,MAAM;IACtB,IAAI,QAAQ,MAAM,YAAY;IAC9B,OAAO;GACR;GACA,IAAI,iBAAiB,KAAK,GAAG,UAAU,oBAAoB,YAAY;GACvE,IAAI,YAAY,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"}
|
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-Co8FYiQU-C4pwzXLx.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.1-dev.
|
|
3
|
+
"version": "8.0.1-dev.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -19,21 +19,21 @@
|
|
|
19
19
|
"temporal-spec": "1.0.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@internal/mongo": "8.0.1-dev.
|
|
23
|
-
"@prisma/orm-family-mongo": "8.0.1-dev.
|
|
24
|
-
"@prisma/orm-framework": "8.0.1-dev.
|
|
25
|
-
"@prisma/orm-target-mongo": "8.0.1-dev.
|
|
26
|
-
"@prisma/orm-toolchain": "8.0.1-dev.
|
|
27
|
-
"@repo/tsconfig": "8.0.1-dev.
|
|
28
|
-
"@repo/tsdown": "8.0.1-dev.
|
|
22
|
+
"@internal/mongo": "8.0.1-dev.11",
|
|
23
|
+
"@prisma/orm-family-mongo": "8.0.1-dev.11",
|
|
24
|
+
"@prisma/orm-framework": "8.0.1-dev.11",
|
|
25
|
+
"@prisma/orm-target-mongo": "8.0.1-dev.11",
|
|
26
|
+
"@prisma/orm-toolchain": "8.0.1-dev.11",
|
|
27
|
+
"@repo/tsconfig": "8.0.1-dev.11",
|
|
28
|
+
"@repo/tsdown": "8.0.1-dev.11",
|
|
29
29
|
"tsdown": "0.22.14",
|
|
30
30
|
"typescript": "5.9.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@prisma/orm-family-mongo": "8.0.1-dev.
|
|
34
|
-
"@prisma/orm-framework": "8.0.1-dev.
|
|
35
|
-
"@prisma/orm-target-mongo": "8.0.1-dev.
|
|
36
|
-
"@prisma/orm-toolchain": "8.0.1-dev.
|
|
33
|
+
"@prisma/orm-family-mongo": "8.0.1-dev.11",
|
|
34
|
+
"@prisma/orm-framework": "8.0.1-dev.11",
|
|
35
|
+
"@prisma/orm-target-mongo": "8.0.1-dev.11",
|
|
36
|
+
"@prisma/orm-toolchain": "8.0.1-dev.11",
|
|
37
37
|
"mongodb": "^7.0.0",
|
|
38
38
|
"temporal-polyfill": "^1.0.8",
|
|
39
39
|
"typescript": ">=5.9"
|
|
@@ -44,103 +44,34 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"exports": {
|
|
47
|
-
"./adapter": "./dist/adapter.mjs",
|
|
48
|
-
"./adapter/control": "./dist/adapter__control.mjs",
|
|
49
|
-
"./adapter/runtime": "./dist/adapter__runtime.mjs",
|
|
50
47
|
"./bson": "./dist/bson.mjs",
|
|
51
|
-
"./components": "./dist/components.mjs",
|
|
52
|
-
"./components/authoring": "./dist/components__authoring.mjs",
|
|
53
|
-
"./components/codec": "./dist/components__codec.mjs",
|
|
54
|
-
"./components/components": "./dist/components__components.mjs",
|
|
55
|
-
"./components/control": "./dist/components__control.mjs",
|
|
56
|
-
"./components/emission": "./dist/components__emission.mjs",
|
|
57
|
-
"./components/execution": "./dist/components__execution.mjs",
|
|
58
|
-
"./components/ir": "./dist/components__ir.mjs",
|
|
59
|
-
"./components/psl-ast": "./dist/components__psl-ast.mjs",
|
|
60
48
|
"./components/runtime": "./dist/components__runtime.mjs",
|
|
61
|
-
"./components/utils": "./dist/components__utils.mjs",
|
|
62
49
|
"./config": "./dist/config.mjs",
|
|
63
|
-
"./contract": "./dist/contract.mjs",
|
|
64
|
-
"./contract/apply-specifier-default-control-policy": "./dist/contract__apply-specifier-default-control-policy.mjs",
|
|
65
|
-
"./contract/contract-validation-error": "./dist/contract__contract-validation-error.mjs",
|
|
66
|
-
"./contract/default-namespace": "./dist/contract__default-namespace.mjs",
|
|
67
|
-
"./contract/enum-accessor": "./dist/contract__enum-accessor.mjs",
|
|
68
|
-
"./contract/format-version": "./dist/contract__format-version.mjs",
|
|
69
|
-
"./contract/hashing": "./dist/contract__hashing.mjs",
|
|
70
|
-
"./contract/hashing-utils": "./dist/contract__hashing-utils.mjs",
|
|
71
|
-
"./contract/internal/format-version": "./dist/contract__internal__format-version.mjs",
|
|
72
|
-
"./contract/is-plain-record": "./dist/contract__is-plain-record.mjs",
|
|
73
|
-
"./contract/resolve-domain-model": "./dist/contract__resolve-domain-model.mjs",
|
|
74
50
|
"./contract/types": "./dist/contract__types.mjs",
|
|
75
|
-
"./contract/validate-domain": "./dist/contract__validate-domain.mjs",
|
|
76
|
-
"./contract/validate-once": "./dist/contract__validate-once.mjs",
|
|
77
|
-
"./contract/validate-storage": "./dist/contract__validate-storage.mjs",
|
|
78
51
|
"./contract-builder": "./dist/contract-builder.mjs",
|
|
79
52
|
"./contract-types": "./dist/contract-types.mjs",
|
|
80
53
|
"./control": "./dist/control.mjs",
|
|
81
|
-
"./driver": "./dist/driver.mjs",
|
|
82
|
-
"./driver/control": "./dist/driver__control.mjs",
|
|
83
|
-
"./driver/runtime": "./dist/driver__runtime.mjs",
|
|
84
54
|
"./family": "./dist/family.mjs",
|
|
85
55
|
"./family/control": "./dist/family__control.mjs",
|
|
86
|
-
"./family/control-adapter": "./dist/family__control-adapter.mjs",
|
|
87
|
-
"./family/ir": "./dist/family__ir.mjs",
|
|
88
|
-
"./family/migration": "./dist/family__migration.mjs",
|
|
89
|
-
"./family/pack": "./dist/family__pack.mjs",
|
|
90
|
-
"./family/runtime": "./dist/family__runtime.mjs",
|
|
91
|
-
"./family/schema-verify": "./dist/family__schema-verify.mjs",
|
|
92
56
|
"./family-contract": "./dist/family-contract.mjs",
|
|
93
|
-
"./family-contract/canonicalization-hooks": "./dist/family-contract__canonicalization-hooks.mjs",
|
|
94
|
-
"./family-contract/data-type": "./dist/family-contract__data-type.mjs",
|
|
95
|
-
"./family-contract/entity-kinds": "./dist/family-contract__entity-kinds.mjs",
|
|
96
57
|
"./family-runtime": "./dist/family-runtime.mjs",
|
|
97
58
|
"./init": "./dist/init.mjs",
|
|
98
59
|
"./migration": "./dist/migration.mjs",
|
|
99
60
|
"./migration-tools/aggregate": "./dist/migration-tools__aggregate.mjs",
|
|
100
|
-
"./migration-tools/contract-snapshot-store": "./dist/migration-tools__contract-snapshot-store.mjs",
|
|
101
61
|
"./migration-tools/hash": "./dist/migration-tools__hash.mjs",
|
|
102
62
|
"./migration-tools/io": "./dist/migration-tools__io.mjs",
|
|
103
63
|
"./migration-tools/spaces": "./dist/migration-tools__spaces.mjs",
|
|
104
64
|
"./orm": "./dist/orm.mjs",
|
|
105
|
-
"./query-ast": "./dist/query-ast.mjs",
|
|
106
|
-
"./query-ast/control": "./dist/query-ast__control.mjs",
|
|
107
65
|
"./query-ast/execution": "./dist/query-ast__execution.mjs",
|
|
108
66
|
"./query-builder": "./dist/query-builder.mjs",
|
|
109
|
-
"./query-builder/contract-free": "./dist/query-builder__contract-free.mjs",
|
|
110
67
|
"./runtime": "./dist/runtime.mjs",
|
|
111
68
|
"./static": "./dist/static.mjs",
|
|
112
69
|
"./target": "./dist/target.mjs",
|
|
113
70
|
"./target/codec-ids": "./dist/target__codec-ids.mjs",
|
|
114
71
|
"./target/codec-types": "./dist/target__codec-types.mjs",
|
|
115
|
-
"./target/codecs": "./dist/target__codecs.mjs",
|
|
116
|
-
"./target/control": "./dist/target__control.mjs",
|
|
117
|
-
"./target/data-types": "./dist/target__data-types.mjs",
|
|
118
72
|
"./target/migration": "./dist/target__migration.mjs",
|
|
119
|
-
"./target/pack": "./dist/target__pack.mjs",
|
|
120
73
|
"./target/runtime": "./dist/target__runtime.mjs",
|
|
121
|
-
"./target/server-version": "./dist/target__server-version.mjs",
|
|
122
|
-
"./utils": "./dist/utils.mjs",
|
|
123
|
-
"./utils/abortable": "./dist/utils__abortable.mjs",
|
|
124
|
-
"./utils/array-equal": "./dist/utils__array-equal.mjs",
|
|
125
|
-
"./utils/assertions": "./dist/utils__assertions.mjs",
|
|
126
|
-
"./utils/canonical-stringify": "./dist/utils__canonical-stringify.mjs",
|
|
127
|
-
"./utils/casts": "./dist/utils__casts.mjs",
|
|
128
|
-
"./utils/defined": "./dist/utils__defined.mjs",
|
|
129
|
-
"./utils/guards": "./dist/utils__guards.mjs",
|
|
130
|
-
"./utils/hash-content": "./dist/utils__hash-content.mjs",
|
|
131
|
-
"./utils/internal-error": "./dist/utils__internal-error.mjs",
|
|
132
|
-
"./utils/json": "./dist/utils__json.mjs",
|
|
133
|
-
"./utils/promise": "./dist/utils__promise.mjs",
|
|
134
|
-
"./utils/redact-db-url": "./dist/utils__redact-db-url.mjs",
|
|
135
|
-
"./utils/result": "./dist/utils__result.mjs",
|
|
136
|
-
"./utils/simplify-deep": "./dist/utils__simplify-deep.mjs",
|
|
137
|
-
"./utils/structured-error": "./dist/utils__structured-error.mjs",
|
|
138
|
-
"./utils/suppress-idle-connection-errors": "./dist/utils__suppress-idle-connection-errors.mjs",
|
|
139
|
-
"./utils/text": "./dist/utils__text.mjs",
|
|
140
|
-
"./utils/types": "./dist/utils__types.mjs",
|
|
141
|
-
"./utils/upgrade-guides": "./dist/utils__upgrade-guides.mjs",
|
|
142
74
|
"./value": "./dist/value.mjs",
|
|
143
|
-
"./value/mongodb-types": "./dist/value__mongodb-types.mjs",
|
|
144
75
|
"./vite-plugin-contract-emit": "./dist/vite-plugin-contract-emit.mjs",
|
|
145
76
|
"./package.json": "./package.json"
|
|
146
77
|
},
|
package/skills/prisma-8/SKILL.md
CHANGED
|
@@ -46,13 +46,13 @@ Both files are **emitted artefacts**. Edit the source; never the JSON or `.d.ts`
|
|
|
46
46
|
- **`contract.prisma` (PSL)** — schema-flavoured DSL. Canonical for typical apps and brownfield Prisma users. Wired by `contract: './<path>/contract.prisma'` — the target config (`ormConfig`, below) detects the `.prisma` extension and routes through the PSL provider. On PostgreSQL the entry is an object that also lists every capability the contract requires: `contract: { path: './<path>/contract.prisma', requiredCapabilities: [...postgres18, ...postgresDriver] }`, with `postgres18` (what PostgreSQL 18 provides; `postgres15` to `postgres17` for older databases) and `postgresDriver` (what the driver's connection provides, such as interactive transactions) imported from `@prisma/orm-postgres/config`. The list must not be empty and nothing is added to it; filter a key out to stop requiring it. The first line of every `.prisma` file is `// use prisma-8`; `orm init` and `contract infer` write it, and the language server only serves diagnostics, completion, and formatting on files that carry it (it still recognises the header earlier releases wrote and rewrites it on Format).
|
|
47
47
|
- **`contract.ts` (TypeScript builder)** — programmatic authoring with `defineContract({...}, ({ field, model, rel, type }) => ({...}))` from `@prisma/orm-postgres/contract-builder` (or `@prisma/orm-mongo/contract-builder`, `@prisma/orm-sqlite/contract-builder`, `@prisma/orm-mysql/contract-builder`, `@prisma/orm-mariadb/contract-builder`). Wired by `contract: './<path>/contract.ts'` — the database package detects the `.ts` extension and routes through the TS provider. On PostgreSQL, `defineContract` takes `requiredCapabilities: [...postgres18, ...postgresDriver]` the same way, imported from `@prisma/orm-postgres/contract-builder`. Use when you need programmatic composition (per-tenant variants, generated fields) or constructs PSL doesn't yet express (e.g. registering a parameterised extension type — see pgvector's contract).
|
|
48
48
|
- **An existing Prisma schema, during adoption.** A project that still runs an earlier Prisma can point `contract:` at its current `schema.prisma` instead of writing a Prisma 8 contract: `contract: prisma6Schema('prisma/schema.prisma')` from `@prisma/orm-mongo/config` reads a Prisma 6 MongoDB schema, and `prisma7Schema` from `@prisma/orm-postgres/config` reads a Prisma 7 Postgres schema. The earlier Prisma keeps owning the database; after each change there, run `contract emit` and `db sign`. A construct Prisma 8 cannot express fails `contract emit` with a `PSL.PRISMA6_MONGO_*` or `PSL.PRISMA7_*` diagnostic. See the database package READMEs for the details.
|
|
49
|
-
- **`prisma.config.ts`.** Wires the contract source, the database connection, the migrations directory, and any installed extensions. The file is an *envelope*: the unified CLI's `definePrismaConfig({...})` from
|
|
49
|
+
- **`prisma.config.ts`.** Wires the contract source, the database connection, the migrations directory, and any installed extensions. The file is an *envelope*: the unified CLI's `definePrismaConfig({...})` from `prisma/config` wraps an `orm:` section built by the target's `defineConfig` — conventionally imported as `ormConfig` from `@prisma/orm-postgres/config` (or `@prisma/orm-mongo/config`). There is no flat form; a bare `defineConfig({ contract, ... })` default export fails with `CONFIG.VERSION_MARKER_MISSING`. Pass `formatter: { indent, newline }` to `ormConfig` to set how `prisma contract format` and the language server lay out PSL files: `indent` is a whole number of spaces, 1 or more (default 2), or `'tab'`. `newline` is `'LF'` or `'CRLF'`; without it, `contract format` uses the operating system's line ending and the language server uses LF.
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
52
|
// prisma.config.ts — what `prisma orm init` scaffolds
|
|
53
53
|
import 'dotenv/config';
|
|
54
54
|
import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
55
|
-
import { definePrismaConfig } from '
|
|
55
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
56
56
|
|
|
57
57
|
export default definePrismaConfig({
|
|
58
58
|
orm: ormConfig({
|
|
@@ -170,7 +170,7 @@ Values the client generates are written `@onCreate(fn())` and `@onUpdate(fn())`:
|
|
|
170
170
|
|
|
171
171
|
In the TS builder, an alias is a constant passed as the field, because field builders are immutable: `const Slug = field.column(type.String({ storage: 'varchar', length: 64 }))`, `const UpdatedAt = field.column(type.TimestampString(3)).onCreate(gen.now()).onUpdate(gen.now())`, then `slug: Slug, updatedAt: UpdatedAt.default(now())`. `type.*` has a helper for every PSL type constructor, and the contributed aliases are `type.temporal.CreatedAt()`, `type.temporal.UpdatedAt()` and the identifier aliases such as `type.Ulid()` (`type.sql.Ulid()` on every SQL target), used as `field.column(type.temporal.UpdatedAt())` and `field.column(type.Ulid()).id().onCreate(gen.ulid())`. A definition has no `types` key (`CONTRACT.TYPES_KEY_REMOVED`), and `field.namedType(...)` takes only an enum handle.
|
|
172
172
|
|
|
173
|
-
Note: scalar lists (e.g. `String[]`) are gated on the
|
|
173
|
+
Note: scalar lists (e.g. `String[]`) are gated on the contract requiring `db.scalarList`, which `postgres15` to `postgres18` include, so `tags String[]` lowers to an array column (with a generated no-NULL-elements check; write `tags String?[]` for a list whose elements may be null, which gets no such check); SQLite's list does not, and SQLite rejects the field with `PSL_SCALAR_LIST_UNSUPPORTED_TARGET`. Implicit Prisma-ORM many-to-many (list navigation on both sides without a join model) is rejected by the SQL interpreter — declare the join model explicitly and the ORM traverses it for you (`references/queries.md`). Composite/embeddable types (`type Address { ... }` with `address Address` on a model) are supported: the interpreter lowers them to storage value objects, at `storage.namespaces.<ns>.entries.valueObject`, and stores them as `jsonb` columns. See *Workflow — Value objects* below.
|
|
174
174
|
|
|
175
175
|
## Workflow — Edit a model / field / relation (TS builder)
|
|
176
176
|
|
|
@@ -211,7 +211,7 @@ The concept: an extension contributes a namespace (`pgvector.*`) plus two descri
|
|
|
211
211
|
|
|
212
212
|
```typescript
|
|
213
213
|
import 'dotenv/config';
|
|
214
|
-
import { definePrismaConfig } from '
|
|
214
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
215
215
|
import pgvector from '@prisma/orm-extension-pgvector/control';
|
|
216
216
|
import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
217
217
|
|
|
@@ -480,7 +480,7 @@ The concept: the Supabase extension provides the `supabase` contract space (the
|
|
|
480
480
|
`prisma.config.ts` (mirrors `examples/supabase/prisma.config.ts`):
|
|
481
481
|
|
|
482
482
|
```typescript
|
|
483
|
-
import { definePrismaConfig } from '
|
|
483
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
484
484
|
import supabasePack from '@prisma/orm-extension-supabase/pack';
|
|
485
485
|
import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
486
486
|
|
|
@@ -541,7 +541,7 @@ Infer captures indexes at full fidelity — expression, partial (`where:`), uniq
|
|
|
541
541
|
## Checklist
|
|
542
542
|
|
|
543
543
|
- [ ] Read `prisma.config.ts` and identified the contract source (path string ending in `.prisma` or `.ts`) and the installed `extensions: [...]`.
|
|
544
|
-
- [ ] Every Prisma ORM import in a user-authored file resolves to `@prisma/orm-<target>/<subpath>` (e.g. `@prisma/orm-postgres/config`) or to `@prisma/orm-extension-<name>` or one of its subpaths, apart from `definePrismaConfig` in `prisma.config.ts`, which comes from
|
|
544
|
+
- [ ] Every Prisma ORM import in a user-authored file resolves to `@prisma/orm-<target>/<subpath>` (e.g. `@prisma/orm-postgres/config`) or to `@prisma/orm-extension-<name>` or one of its subpaths, apart from `definePrismaConfig` in `prisma.config.ts`, which comes from `prisma/config`. No imports from `@prisma/orm-framework`, `@prisma/orm-family-*`, `@prisma/orm-target-*` or `@prisma/orm-toolchain` in user files.
|
|
545
545
|
- [ ] Edited the contract source (`contract.prisma` or `contract.ts`), not an emitted artefact.
|
|
546
546
|
- [ ] For new extension namespaces: added the package, imported its control descriptor (`@prisma/orm-extension-<name>/control`, or `/pack` for a package with no `/control` entry, such as Supabase), added it to `extensions: [...]` in `ormConfig({...})` (and the matching pack descriptor to `defineContract({extensions: {...}})` if using the TS builder).
|
|
547
547
|
- [ ] `prisma.config.ts` is the envelope form — `definePrismaConfig({ orm: ormConfig({...}) })` — not a flat `defineConfig({...})`.
|
|
@@ -49,7 +49,7 @@ Every code is a dotted `NAMESPACE.SUBCODE`; the namespace is the prefix (`CONFIG
|
|
|
49
49
|
{ name: 'RuntimeError', code: 'BUDGET.TIME_EXCEEDED', category: 'BUDGET', severity: 'error', message: '...', details: { ... } }
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
`category` is the prefix of `code` (`PLAN`, `CONTRACT`, `LINT`, `BUDGET`, `RUNTIME`, `ORM`, …). `details` holds the structured context (`details` is the runtime envelope's equivalent of the CLI envelope's `meta`). Recognise
|
|
52
|
+
`category` is the prefix of `code` (`PLAN`, `CONTRACT`, `LINT`, `BUDGET`, `RUNTIME`, `ORM`, …). `details` holds the structured context (`details` is the runtime envelope's equivalent of the CLI envelope's `meta`). Recognise a thrown runtime error with `isStructuredError`, imported from the database package's `runtime` (`import { isStructuredError } from '@prisma/orm-postgres/runtime'`), and match on `error.code` — never `instanceof`. The CLI envelope is JSON output, with `summary` and no `message`, so `isStructuredError` does not recognise it; a script reads `code` from the parsed JSON instead.
|
|
53
53
|
|
|
54
54
|
**3. SQL driver errors** — surface as `SqlQueryError` / `SqlConnectionError` (see `packages/2-sql-family/1-core/errors/`). Fields on `SqlQueryError`: `kind: 'sql_query'`, `sqlState` (Postgres SQLSTATE, e.g. `'23505'`), `constraint`, `table`, `column`, `detail`, `cause`. These carry no dotted code — route on `sqlState` and the constraint metadata. SQL driver errors are typically wrapped by middleware before reaching the user, but raw-SQL paths can surface them directly.
|
|
55
55
|
|
|
@@ -58,7 +58,7 @@ The graph is a static, committed artifact. Several branch tips may coexist, roll
|
|
|
58
58
|
|
|
59
59
|
| Code | Meaning in the navigation model | Next move |
|
|
60
60
|
|---|---|---|
|
|
61
|
-
| `MIGRATION.MARKER_NOT_IN_HISTORY` | Online; marker hash is not a node in the graph. The database was changed outside the migration system. | Follow the finding's advice, which depends on the database's change policy. When the policy includes `reconcile`, decide which side is truth: `db sign` (accept DB as truth), `db update` (push contract to DB), `contract infer` (re-derive contract from DB), or `db verify` (inspect first). When it is `migrate` alone, `db sign` and `db update` are refused: author migrations that bring the database back onto the graph. When the policies cannot be read, have `meta.policies`
|
|
61
|
+
| `MIGRATION.MARKER_NOT_IN_HISTORY` | Online; marker hash is not a node in the graph. The database was changed outside the migration system. | Follow the finding's advice, which depends on the database's change policy. When the policy includes `reconcile`, decide which side is truth: `db sign` (accept DB as truth), `db update` (push contract to DB), `contract infer` (re-derive contract from DB), or `db verify` (inspect first). When it is `migrate` alone, `db sign` and `db update` are refused: author migrations that bring the database back onto the graph. When the policies cannot be read, have them corrected first: on Postgres the `policies` column of `prisma.config`, elsewhere `meta.policies` in the application space's marker. **Not** the same as `MIGRATION.MARKER_MISMATCH`, which `db migrate` (before any DDL) and `db migrate --show` raise as an error when the marker hash is not a graph node. |
|
|
62
62
|
| `MIGRATION.MISSING_INVARIANTS` | Marker reached the destination structurally but lacks invariants the target ref declares. | `db migrate --to <name> --db $URL` to take a path that covers them. |
|
|
63
63
|
| `CONTRACT.UNREADABLE` | `contract.json` couldn't be read. | `contract emit` to regenerate it. |
|
|
64
64
|
|
|
@@ -45,10 +45,10 @@ Once the contract changes, you choose how the change reaches the database. This
|
|
|
45
45
|
- **`this.dataTransform(contract, name, { check, run })`.** The Postgres data-transform factory. `check` is a rowset query whose presence-of-any-row signals "work remains"; `run` is one or more mutation queries that perform the backfill. Both are lazy closures returning query plans built with the SQL query builder over the end contract. `contract` is the `contract` that `postgres({ contract: contractFromJson<End>(endContract) })` returns, not the imported `endContract` JSON the planner renders (see *Fill a placeholder*). The runner wraps `check` as `EXISTS(...)` for precheck and `NOT EXISTS(...)` for postcheck, so the same closure asserts both "there is work" and "the work is done".
|
|
46
46
|
- **`pendingPlaceholders`.** A boolean field on the JSON result of `migration plan`. `true` means the package was written but contains unfilled placeholders — `db migrate` will throw `MIGRATION.UNFILLED_PLACEHOLDER` until you edit `migration.ts` and self-emit.
|
|
47
47
|
- **`migrationHash`.** Content-addressed identity of a migration package. `MIGRATION.HASH_MISMATCH` fires when the stored hash in `migration.json` disagrees with the hash recomputed from the on-disk files (almost always: someone edited `migration.ts` without self-emitting).
|
|
48
|
-
- **Marker.** Records "this database is at contract hash X for space Y". **Postgres:** a row in `
|
|
48
|
+
- **Marker.** Records "this database is at contract hash X for space Y". **Postgres:** a row in `prisma.signatures`. **Mongo:** a document in the `_prisma_migrations` collection (keyed by space). Each successful migration advances the marker once schema verification passes for that space. `db sign` writes the marker from the current contract hash, but only after a schema-verification pass succeeds (it will not sign a database whose live schema disagrees with the contract).
|
|
49
49
|
- **Apply atomicity.** **Postgres:** one `db migrate` run is one transaction — the runner issues a single `BEGIN`, applies every pending migration for every contract space, then one `COMMIT`; any failure issues `ROLLBACK` for the whole run, so the marker stays where it was before the command. **Mongo:** DDL ops (`createCollection`, `createIndex`, `collMod`, `setValidation`, …) are not wrapped in a multi-document transaction; the runner applies ops, verifies the live schema against the destination contract, and advances the marker only on verify-pass (resumable across spaces — see the MongoDB family doc). Ordinary DDL + `dataTransform` flows stay consistent; partial state from failed mid-migration runs is diagnosed with `db verify` / `db schema`, not assumed away.
|
|
50
50
|
- **Changed foreign key actions and primary keys (Postgres).** A changed `onDelete`/`onUpdate` plans a drop and an add of the foreign key. A moved or removed primary key plans a drop (and an add), and the foreign keys that reference the old key are dropped first and added back after it. These ask no data-loss question.
|
|
51
|
-
- **Policies.** A database records
|
|
51
|
+
- **Policies.** A database records how it may be changed (**Postgres:** in the one row of `prisma.config`; **Mongo** and the other SQL targets: in the application space's marker, under `meta.policies`): its *change policy* (`migrate`, `reconcile` or both; `reconcile` is what `db update` and `db sign` do) and its *data protection policy* (`dataLoss` and `accessWidening`, each `forbidden`, `with-consent` or `permitted`). Every command that changes a database obeys both. A ref declares the policies its database should have in a `policies` field. See *Policies: what a database says about how it may change* below.
|
|
52
52
|
- **Operation classes.** Every operation declares an `operationClass`: `additive`, `widening`, `data`, or `destructive`. `additive` adds structure and leaves existing structure and data as they are. `widening` changes existing structure without losing data; an operation that cannot keep every value fails instead, so a tightened constraint such as `SET NOT NULL` is widening. `destructive` can lose rows or values: dropping a table or column, or a type change that can change values. `data` reads and writes rows as its author wrote them, such as a backfill or a type conversion; a `dataTransform` is always `data`. Each operation factory sets its own class (`this.alterColumnType` is `data` with `using` and `destructive` without it, unless you pass `operationClass`). A `rawSql` step you write takes the class of the factory that would express it, or the class the definitions above give. The CLI surfaces these in the plan preview and in JSON output. There is no `long-running` class and the framework does not emit `CREATE INDEX CONCURRENTLY` — operations stay transactional.
|
|
53
53
|
|
|
54
54
|
## `migration.ts` is framework-rendered, not hand-authored
|
|
@@ -77,7 +77,9 @@ Treat the rendered import lines as framework-managed on both targets:
|
|
|
77
77
|
| `CLI.CONSENT_REQUIRED` | `migration plan` / `db update` run with nobody to answer (`--no-interactive`, CI, `--yes`) | The plan would lose data or (on `db update`) widen access. `meta.unanswered` and `nextActions` list each question with the flags that answer it: `--delete <subject>`, `--rename <subject>:<new name>`, `--allow <Model>`. Re-run with the ones you mean. `--confirm` and `--yes` answer none of them. |
|
|
78
78
|
| `CLI.CONSENT_UNUSED` | `migration plan` / `db update` | Every question was answered, and a `--delete` or `--allow` was left over: a typo, a subject the plan does not touch, or a `--confirm` (which consents to nothing). Fix or drop the flag. A typo next to a question nobody answered is reported as `CLI.CONSENT_REQUIRED` instead, which names the flag that matched nothing. On `db update --dry-run` the same mistake is `MIGRATION.STATEMENT_ANSWERS_NO_QUESTION`. |
|
|
79
79
|
| `MIGRATION.STATEMENT_DID_NOT_RESOLVE_LOSS` | A rename typed at the data-loss prompt | The plan was made again with the rename and still loses the subject's data. Answer with `delete`, or give a rename whose old name is the subject. |
|
|
80
|
-
| `CONTRACT.MARKER_MISMATCH` | `db verify` (finding, exit 4) | The marker disagrees with the contract hash (**Postgres:** `
|
|
80
|
+
| `CONTRACT.MARKER_MISMATCH` | `db verify` (finding, exit 4) | The marker disagrees with the contract hash (**Postgres:** `prisma.signatures`; **Mongo:** `_prisma_migrations`). The DB is at a different contract version than the code thinks. Either run a migration forward, or — if the DB is correct and the marker is stale after a manual fix-up — run `db sign`. |
|
|
81
|
+
| `CONTRACT.PRISMA_SPACE_BEHIND` | `db verify`, `migration status`, `migration log`, dry runs; the client's first query (a warning, only when the client is given a `log`) | The records Prisma keeps for itself in the database are not up to date with the installed release, for example a database a release candidate set up, whose tables are in `prisma_contract`. Run the command the project already uses to change its database: `prisma db migrate` with migrations, `prisma db update` with `db update`, or `prisma db sign` if it only signs. Each brings the records up to date before its usual work. Then run the read again. |
|
|
82
|
+
| `MIGRATION.INSTALLED_SPACE_UNREACHABLE` | `db init`, `db update`, `db migrate`, `db sign`, `db verify` | The records Prisma keeps for itself were changed by a release this one cannot follow: `meta.reason` is `laterMajor` when a later major version of Prisma changed them, `unknownContract` otherwise. Use the release that last changed the database, or a newer one. Do not edit them by hand. |
|
|
81
83
|
| `CONTRACT.MARKER_MISSING` | `db verify` (finding, exit 4), runtime startup (warning) | The DB has no marker yet. Run `prisma db init --db <url>` to baseline an empty database, `db update --db <url>` to apply the current contract directly, or `db sign --db <url>` if the schema already matches the contract. |
|
|
82
84
|
| `MIGRATION.STATEMENT_INVALID` | `migration plan` / `db update` with `--rename` | The statement is malformed, mixes a model and a field, renames something to itself, swaps two names, or repeats a name. The error's next step is the statement to type instead; use it. |
|
|
83
85
|
| `MIGRATION.STATEMENT_UNRESOLVED` | `migration plan` / `db update` with `--rename` | A name is not where a rename needs it. The error lists the names it found and says what to type: the statement the right way round, the order that works, or to leave out a rename that has already happened. |
|
|
@@ -424,7 +426,7 @@ Postgres and SQLite first; MongoDB below. `migration plan` cannot see rows, so t
|
|
|
424
426
|
- **An optional field made required** is tightened directly. If rows hold NULL, the apply fails and counts them (`3 rows of "Item" hold NULL in "note", so it cannot become required.`); set the values and re-run, or plan with `--backfill`.
|
|
425
427
|
- **On MongoDB** the same questions are asked about the documents. A validator change (`collMod(..., { ..., checkDocuments: true })`) checks the documents as its own precheck, after the plan's rewrites, and stops while one does not fit; operations that ran before it stay applied, and a re-run skips them. To apply a validator over documents that do not fit, set `checkDocuments: false` on its `collMod` in `migration.ts`. `--delete User.age` casts with `$convert` (`castField`), only where the result keeps what the values mean: `String` to `Boolean` or `DateTime` to `Int` offer `--convert` only; a cast that keeps every value, such as `Int` to `BigInt`, asks nothing. `--convert User.age` and `--backfill User.plan` write `dataTransform('User.age', { check, run })` with the filter written and the update as `placeholder('User.age:update')`, which you replace with an update document (`{ $set: { … } }`) or an aggregation pipeline (`[{ $set: { age: { $toInt: '$age' } } }]`); the `run` uses `rawUpdateMany(..., { bypassDocumentValidation: true })`, and a hand-written one must skip validation too. A new required field gets a temporary value (`fillField`), unless it has a unique index or its type has none, such as a date, or it is a variant's discriminator, since no temporary value names a variant. A discriminator renamed without `--rename` is refused, and the refusal gives the `--rename` to pass; a model's first discriminator is left to the document check. On a collection with documents, such a field stops the apply: a unique one at its index build, where the documents that lack it all hold `null`, and any other at the validator change's document check. Both errors name `--backfill`, so use it. A required field of a variant new to the collection, such as `Bug.severity` when `Task` gains its first discriminator, has no documents to backfill yet: set it in the update you write for `--backfill Task.type`, or keep it optional until a later change. A field that gains an enum or changes type inside a value object is not a statement: the plan warns, and you add a `dataTransform` before the validator change.
|
|
426
428
|
- **Adopting a Prisma 6 MongoDB database.** A Prisma 6 database has no validator, and the first Prisma 8 plan adds one, which checks the documents first. If documents do not fit, the apply stops and names what the change touches, one `_id`, and the `mongosh` query that finds the rest. The error says why the document it shows does not fit, such as a field the new validator does not name. Fix those documents and run the command again; a plain update works, since the collection has no validator yet. Or, under `db migrate`, apply the validator over them: set `checkDocuments: false` on that `collMod` in `migration.ts`, run the file with `node`, and run `db migrate` again; they then fail their next update until they fit.
|
|
427
|
-
- **Following failure advice under `db migrate`:** the migration is already written, so the error says to copy any code you wrote in its `migration.ts`, delete its directory, and run the printed `migration plan --from <hash> --name <name> …` command, which keeps the migration's name, together with the other statements you planned it with. Paths in the advice are relative to the directory the command ran from, and the commands it prints repeat the `--config` it was given, so each runs as printed from there.
|
|
429
|
+
- **Following failure advice under `db migrate`:** the migration is already written, so the error says to copy any code you wrote in its `migration.ts`, delete its directory, and run the printed `migration plan --from <hash> --name <name> …` command, which keeps the migration's name, together with the other statements you planned it with. Paths in the advice are relative to the directory the command ran from, and the commands it prints repeat the `--config` it was given, so each runs as printed from there. A printed command that connects to a database carries `--db <url>` when the run was given `--db`, or when `db.connection` in `prisma.config.ts` has no value (for example, its environment variable is not set): replace `<url>` with the database's URL.
|
|
428
430
|
|
|
429
431
|
## Workflow — Author a migration by hand
|
|
430
432
|
|
|
@@ -493,7 +495,7 @@ pnpm prisma db verify --db $DATABASE_URL
|
|
|
493
495
|
|
|
494
496
|
## Policies: what a database says about how it may change
|
|
495
497
|
|
|
496
|
-
Every database records two policies
|
|
498
|
+
Every database records two policies, and every command obeys them. On Postgres they are in `prisma.config`; on the other targets they are in the application space's marker. Read them from the error that refuses you, or with `prisma migration status --to <ref> --db <url>`, which reports where the ref's declared policies differ from the database's.
|
|
497
499
|
|
|
498
500
|
**Change policy.** The strategies the database may be changed by:
|
|
499
501
|
|
|
@@ -552,7 +554,7 @@ Write the field by hand, or with the `migration ref policy` commands, which chan
|
|
|
552
554
|
|
|
553
555
|
No other command changes a ref's policies. Commands that rewrite a ref (`migration ref set`, `db update`, `db sign`, `db migrate`, and the `migration ref policy` commands) keep the `hash`, `invariants` and `policies` they do not change, and write `formatVersion` themselves. A ref file with any other field is refused with `MIGRATION.INVALID_REF_FILE`, and the file is left as it was: remove the field by hand.
|
|
554
556
|
|
|
555
|
-
**Applying a declared policy.** `db migrate --to <ref>` and `db update --to <ref>` compare the ref's declarations with the database before running anything. If they differ, the command fails with `MIGRATION.POLICY_MISMATCH` and nothing runs. The database's policy changes only when the deploy is told it may: `prisma db migrate --to production --permit-policy-change --db <url>`. The run is checked against the ref's policies, runs, and
|
|
557
|
+
**Applying a declared policy.** `db migrate --to <ref>` and `db update --to <ref>` compare the ref's declarations with the database before running anything. If they differ, the command fails with `MIGRATION.POLICY_MISMATCH` and nothing runs. The database's policy changes only when the deploy is told it may: `prisma db migrate --to production --permit-policy-change --db <url>`. The run is checked against the ref's policies, runs, and records them in the database (on Postgres in `prisma.config`, elsewhere in the marker) when it succeeds, so a failed run leaves the old policy. With nothing pending, the run writes only the policies. A pipeline that should apply reviewed policy changes passes the flag on every deploy; a cautious team leaves it out and applies policy changes by hand. The flag needs `--to <ref>`: with a hash, `@db`, `@empty` or no `--to`, the command fails with `CLI.INVALID_ARGUMENTS` before it connects. A ref that declares no policies is accepted and changes nothing, so a pipeline can pass the flag on every deploy.
|
|
556
558
|
|
|
557
559
|
The flag is consent, like `--delete`. It is for the person who owns the database and reviewed the ref change. Never add it to make your own deploy pass, and never change a database's or a ref's policies, by hand or with `migration ref policy set` or `delete`, to get a deploy, a plan or `db update` past a refusal or a mismatch: the policy is there to stop exactly that.
|
|
558
560
|
|
|
@@ -586,7 +586,7 @@ const { affectedRows } = await db.execute(deletePlan);
|
|
|
586
586
|
|
|
587
587
|
Each row must include every column that is not nullable and has no default; leaving one out is a type error that names the column. A value typed `T | undefined` for such a column is also an error, so narrow it first.
|
|
588
588
|
|
|
589
|
-
`.returning(...)` requires the contract to require `
|
|
589
|
+
`.returning(...)` requires the contract to require `db.returning`. `postgres15` to `postgres18` list it.
|
|
590
590
|
|
|
591
591
|
### Computed projections and joins
|
|
592
592
|
|
|
@@ -696,7 +696,7 @@ Cross-namespace relations (e.g. `public.Profile` → `auth.User`) follow the sam
|
|
|
696
696
|
5. **Importing `and` / `or` / `not` from an internal package.** They are exported from `@prisma/orm-postgres/orm-client`; do not import them from a platform package such as `@prisma/orm-family-sql`.
|
|
697
697
|
6. **Trying to `db.sql.from(tables.user)`.** That surface does not exist. The builder is table-shaped: `db.sql.<ns>.<tableName>.select(...)`. There is no `db.schema.tables` either.
|
|
698
698
|
7. **Reading rows with `execute`.** Plans run through the client: `db.query(plan)` for rows, `db.execute(plan)` for a non-returning write (`{ affectedRows }`). Inside a transaction, `tx.query(plan)` / `tx.execute(plan)`. `execute` never yields rows — a `select` or `.returning(...)` plan passed to it gives you statistics, not data.
|
|
699
|
-
8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `
|
|
699
|
+
8. **Setting `capabilities: { lateral: true }` in `prisma.config.ts`.** The ORM config (`ormConfig({...})`) does not take `capabilities`. The contract lists every capability it requires in `requiredCapabilities`, beside the path in the contract entry or in `defineContract`, usually `[...postgres18, ...postgresDriver]`, which includes `db.lateral`, `db.jsonAgg` and `db.returning`. To require one more, add its key to that list (see `references/contract.md`).
|
|
700
700
|
9. **Confabulating a TypedSQL or `.stream()` surface.** Neither exists. Raw SQL does: the client's raw lane, ``db.raw.sql`…` ``. Reusable statements do: `db.prepare(...)` (see *Prepared statements* in [`queries.md`](./queries.md)). Streaming: `for await` over a read terminal or `runtime.query(plan)` — with the caveats in *Streaming* in [`queries.md`](./queries.md).
|
|
701
701
|
10. **Mixing the ORM mutation return with `db.query(plan)` / `db.execute(plan)`.** ORM terminals issue the query themselves and return rows. `query` and `execute` are for plans.
|
|
702
702
|
11. **Adding a `cursor()` to a relation, count, operation or `nulls` order.** It throws `ORM.ARGUMENT_INVALID`. Use `.limit(n).offset(n)`, or order by plain columns.
|
|
@@ -37,7 +37,7 @@ This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, S
|
|
|
37
37
|
- **Why the application lists them.** The application must have exactly one copy of each. Prisma does not accept a value that another copy of its own code created, and a package manager takes a peer dependency only from the application's own list. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker.
|
|
38
38
|
- **Yarn Plug'n'Play.** `prisma orm init` does not support it. With Yarn, set `nodeLinker: node-modules` in `.yarnrc.yml` first.
|
|
39
39
|
- **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses.
|
|
40
|
-
- **Marker**: a row in the `
|
|
40
|
+
- **Marker**: a row in the `prisma.signatures` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
|
|
41
41
|
|
|
42
42
|
### Canonical on-disk layout
|
|
43
43
|
|
|
@@ -33,11 +33,11 @@ This skill covers using Prisma 8 against a **Supabase** project end-to-end: comp
|
|
|
33
33
|
|
|
34
34
|
## Workflow — Wire the pack into the config
|
|
35
35
|
|
|
36
|
-
The concept: the pack registers the Supabase contract space so your contract can reference it and the planner/verifier know what Supabase owns. Its descriptor is the `pack` export and it goes into the ordinary `extensions` array of the target config, inside the standard envelope (see `references/contract.md` § *Key Concepts*).
|
|
36
|
+
The concept: the pack registers the Supabase contract space so your contract can reference it and the planner/verifier know what Supabase owns. Its descriptor is the `pack` export and it goes into the ordinary `extensions` array of the target config, inside the standard envelope (see `references/contract.md` § *Key Concepts*). It imports `definePrismaConfig` from `prisma/config`, which the project's `prisma` development dependency provides (`prisma orm init` adds it):
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
39
|
// prisma.config.ts
|
|
40
|
-
import { definePrismaConfig } from '
|
|
40
|
+
import { definePrismaConfig } from 'prisma/config';
|
|
41
41
|
import supabasePack from '@prisma/orm-extension-supabase/pack';
|
|
42
42
|
import { defineConfig as ormConfig, postgres18, postgresDriver } from '@prisma/orm-postgres/config';
|
|
43
43
|
|
package/dist/adapter.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-target-mongo/adapter";
|
package/dist/adapter.mjs
DELETED
package/dist/components.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components";
|
package/dist/components.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@prisma/orm-framework/components/authoring";
|