@prisma/orm-target-mongo 8.0.0-rc.18-dev.31 → 8.0.0-rc.18-dev.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/adapter.mjs +1 -1
  2. package/dist/adapter__control.mjs +1 -1
  3. package/dist/adapter__runtime.mjs +2 -2
  4. package/dist/{codec-types-DHjpzMTv.d.mts → codec-types-Daq7xQEA.d.mts} +2 -1
  5. package/dist/{codec-types-DHjpzMTv.d.mts.map → codec-types-Daq7xQEA.d.mts.map} +1 -1
  6. package/dist/{codecs-BVrMDhha-DBl_TLS8.mjs → codecs-CylyDRI5-DdzCZHek.mjs} +15 -11
  7. package/dist/codecs-CylyDRI5-DdzCZHek.mjs.map +1 -0
  8. package/dist/{control-lAuWLUE_.mjs → control-BkNtJldI.mjs} +63 -49
  9. package/dist/control-BkNtJldI.mjs.map +1 -0
  10. package/dist/{data-types-vptiHFHC-LUJwNRIq.mjs → data-types-BUNJnoE9-S7P2K-7r.mjs} +5 -11
  11. package/dist/data-types-BUNJnoE9-S7P2K-7r.mjs.map +1 -0
  12. package/dist/{descriptor-meta-BQBreSNF-CZ9uOPwO.mjs → descriptor-meta-DdeUSTJk-zJzD7C-n.mjs} +3 -3
  13. package/dist/{descriptor-meta-BQBreSNF-CZ9uOPwO.mjs.map → descriptor-meta-DdeUSTJk-zJzD7C-n.mjs.map} +1 -1
  14. package/dist/{descriptor-meta-runtime-D0YxXi85-CjeTEg7T.mjs → descriptor-meta-runtime-DeRjCidG-BzMW-qkN.mjs} +4 -4
  15. package/dist/{descriptor-meta-runtime-D0YxXi85-CjeTEg7T.mjs.map → descriptor-meta-runtime-DeRjCidG-BzMW-qkN.mjs.map} +1 -1
  16. package/dist/driver.mjs +1 -1
  17. package/dist/driver__control.mjs +1 -1
  18. package/dist/driver__control.mjs.map +1 -1
  19. package/dist/{mongo-adapter-Bo6ciURK-Cy0xnkRa.mjs → mongo-adapter-Bo6ciURK-Dvq-oZQ9.mjs} +2 -2
  20. package/dist/{mongo-adapter-Bo6ciURK-Cy0xnkRa.mjs.map → mongo-adapter-Bo6ciURK-Dvq-oZQ9.mjs.map} +1 -1
  21. package/dist/{mongo-driver-CLFI40WY-Bw4u6VrV.mjs → mongo-driver-GbMQwUg3-Cx-f8nHb.mjs} +3 -3
  22. package/dist/{mongo-driver-CLFI40WY-Bw4u6VrV.mjs.map → mongo-driver-GbMQwUg3-Cx-f8nHb.mjs.map} +1 -1
  23. package/dist/{pack-BuZ5LBMg.d.mts → pack-FxKc7yY0.d.mts} +2 -2
  24. package/dist/{pack-BuZ5LBMg.d.mts.map → pack-FxKc7yY0.d.mts.map} +1 -1
  25. package/dist/{prisma6-binding-DKZXqEL5.mjs → prisma6-binding-L_x2s5FV.mjs} +2 -2
  26. package/dist/{prisma6-binding-DKZXqEL5.mjs.map → prisma6-binding-L_x2s5FV.mjs.map} +1 -1
  27. package/dist/target.d.mts +2 -2
  28. package/dist/target.mjs +4 -4
  29. package/dist/target__codec-types.d.mts +1 -1
  30. package/dist/target__codecs.mjs +1 -1
  31. package/dist/target__control.mjs +1 -1
  32. package/dist/target__data-types.mjs +1 -1
  33. package/dist/target__pack.d.mts +2 -2
  34. package/dist/target__pack.mjs +1 -1
  35. package/dist/target__pack.mjs.map +1 -1
  36. package/dist/target__prisma6-binding.mjs +1 -1
  37. package/dist/target__runtime.mjs +1 -1
  38. package/dist/target__runtime.mjs.map +1 -1
  39. package/package.json +9 -9
  40. package/dist/codecs-BVrMDhha-DBl_TLS8.mjs.map +0 -1
  41. package/dist/control-lAuWLUE_.mjs.map +0 -1
  42. package/dist/data-types-vptiHFHC-LUJwNRIq.mjs.map +0 -1
package/dist/adapter.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { p as MONGO_VECTOR_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
2
- import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Cy0xnkRa.mjs";
2
+ import { a as lowerStage, i as lowerPipeline, n as lowerAggExpr, r as lowerFilter, t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Dvq-oZQ9.mjs";
3
3
  //#region ../../../3-mongo-target/2-mongo-adapter/dist/index.mjs
4
4
  const mongoVectorNearOperation = Object.freeze({
5
5
  self: { codecId: MONGO_VECTOR_CODEC_ID },
@@ -1,5 +1,5 @@
1
1
  import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
2
- import { t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Cy0xnkRa.mjs";
2
+ import { t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Dvq-oZQ9.mjs";
3
3
  import { structuredError } from "@prisma/orm-framework/utils/structured-error";
4
4
  import { blindCast } from "@prisma/orm-framework/utils/casts";
5
5
  import { type } from "arktype";
@@ -1,5 +1,5 @@
1
- import { t as buildStandardCodecRegistry } from "./codecs-BVrMDhha-DBl_TLS8.mjs";
2
- import { t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Cy0xnkRa.mjs";
1
+ import { t as buildStandardCodecRegistry } from "./codecs-CylyDRI5-DdzCZHek.mjs";
2
+ import { t as createMongoAdapter } from "./mongo-adapter-Bo6ciURK-Dvq-oZQ9.mjs";
3
3
  import { timestampNowRuntimeGenerator } from "@prisma/orm-family-mongo/family/runtime";
4
4
  //#region ../../../3-mongo-target/2-mongo-adapter/dist/runtime.mjs
5
5
  const mongoRuntimeAdapterDescriptor = {
@@ -55,6 +55,7 @@ type CodecTypes = {
55
55
  readonly input: string;
56
56
  readonly output: string;
57
57
  readonly traits: 'equality' | 'order' | 'numeric';
58
+ readonly keepsWrittenForm: true;
58
59
  };
59
60
  readonly 'mongo/binary@1': {
60
61
  readonly input: Uint8Array;
@@ -85,4 +86,4 @@ interface ParameterizedOutputTypesForTypeParams extends ParameterizedOutputTypes
85
86
  }
86
87
  //#endregion
87
88
  export { ParameterizedOutputTypesForTypeParams as a, CodecTypes as i, BsonScalar as n, Vector as o, BsonValue$1 as r, BsonInputValue$1 as t };
88
- //# sourceMappingURL=codec-types-DHjpzMTv.d.mts.map
89
+ //# sourceMappingURL=codec-types-Daq7xQEA.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codec-types-DHjpzMTv.d.mts","names":[],"sources":["../../../../3-mongo-target/1-mongo-target/dist/codec-types.d.mts"],"mappings":";;;;KAGK,OAAO;WACD,iBAAiB;;KAEvB;WACM;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;;KAGR,cAAc;WACR,kBAAkB;aAChB,cAAc;MACrB,OAAO;;;;;UAKH,8CAA8C;WAC7C,aAAa"}
1
+ {"version":3,"file":"codec-types-Daq7xQEA.d.mts","names":[],"sources":["../../../../3-mongo-target/1-mongo-target/dist/codec-types.d.mts"],"mappings":";;;;KAGK,OAAO;WACD,iBAAiB;;KAEvB;WACM;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;;WAEF;aACE;aACA;aACA;aACA;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;WAEF;aACE,OAAO;aACP,QAAQ;aACR;;;KAGR,cAAc;WACR,kBAAkB;aAChB,cAAc;MACrB,OAAO;;;;;UAKH,8CAA8C;WAC7C,aAAa"}
@@ -1,11 +1,11 @@
1
1
  import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, p as MONGO_VECTOR_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
2
2
  import { t as mongoTargetError } from "./mongo-target-errors-Btf3ML1w-B5EMYbz1.mjs";
3
- import { A as int64ToJson, B as mongoInt32, C as int32ToJson, D as int64NumberEncode, E as int64NumberDecode, F as mongoBson, G as mongoVector, H as mongoJson, J as objectIdToJson, L as mongoDate, M as isPlainObject, N as mongoBinary, O as int64NumberFromDigits, P as mongoBool, Q as where, R as mongoDecimal128, S as int32Encode, T as int64Encode, U as mongoObjectId, V as mongoInt64, W as mongoString, X as stringEncode, Y as readBsonJson, Z as vectorEncode, _ as decimalTextBigintLiteral, a as booleanEncode, b as doubleEncode, c as bsonTypeTag, d as dateEncode, f as dateToJson, g as decimal128ToJson, h as decimal128Encode, i as binaryToBase64, j as isPlainArray, k as int64NumberToJson, l as child, m as decimal128Decode, n as binaryEncode, o as bsonClassTag, p as dbRefEntries, q as objectIdEncode, r as binaryFromBase64, s as bsonToJson, t as binaryDecode, u as constructorName, v as decimalTextNumberLiteral, w as int64Decode, x as encodeBsonValue, y as decodeBsonValue, z as mongoDouble } from "./data-types-vptiHFHC-LUJwNRIq.mjs";
4
- import { floatToJson, readJsonFloat, renderTsLiteral } from "@prisma/orm-framework/components/codec";
3
+ import { A as isPlainObject, B as mongoJson, C as int64Encode, D as int64NumberToJson, E as int64NumberFromDigits, F as mongoDate, G as objectIdEncode, H as mongoString, I as mongoDecimal128, J as stringEncode, K as objectIdToJson, L as mongoDouble, M as mongoBool, N as mongoBson, O as int64ToJson, R as mongoInt32, S as int64Decode, T as int64NumberEncode, U as mongoVector, V as mongoObjectId, X as where, Y as vectorEncode, _ as decodeBsonValue, a as booleanEncode, b as int32Encode, c as bsonTypeTag, d as dateEncode, f as dateToJson, g as decimal128ToJson, h as decimal128Encode, i as binaryToBase64, j as mongoBinary, k as isPlainArray, l as child, m as decimal128Decode, n as binaryEncode, o as bsonClassTag, p as dbRefEntries, q as readBsonJson, r as binaryFromBase64, s as bsonToJson, t as binaryDecode, u as constructorName, v as doubleEncode, w as int64NumberDecode, x as int32ToJson, y as encodeBsonValue, z as mongoInt64 } from "./data-types-BUNJnoE9-S7P2K-7r.mjs";
4
+ import { decimalTextBigintLiteral, decimalTextNumberLiteral, floatNumberLiteral, floatToJson, readJsonFloat, renderTsLiteral } from "@prisma/orm-framework/components/codec";
5
5
  import { blindCast } from "@prisma/orm-framework/utils/casts";
6
6
  import { mongoCodec, newMongoCodecRegistry } from "@prisma/orm-family-mongo/codec";
7
7
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
8
- //#region ../../../3-mongo-target/1-mongo-target/dist/codecs-BVrMDhha.mjs
8
+ //#region ../../../3-mongo-target/1-mongo-target/dist/codecs-CylyDRI5.mjs
9
9
  const BSON_TYPE_BY_TAG = {
10
10
  ObjectId: "objectId",
11
11
  Decimal128: "decimal",
@@ -300,7 +300,8 @@ function descriptorFor(codec, metadata) {
300
300
  const built = metadata.withParams === void 0 || params === void 0 ? codec : metadata.withParams(params);
301
301
  return () => built;
302
302
  }),
303
- ...ifDefined("renderValueLiteral", metadata.renderValueLiteral)
303
+ ...ifDefined("renderValueLiteral", metadata.renderValueLiteral),
304
+ ...ifDefined("keepsWrittenForm", metadata.keepsWrittenForm)
304
305
  };
305
306
  }
306
307
  /**
@@ -322,7 +323,7 @@ const mongoCodecDescriptors = [
322
323
  "order",
323
324
  "numeric"
324
325
  ],
325
- renderValueLiteral: (value) => typeof value === "number" ? String(value) : void 0
326
+ renderValueLiteral: floatNumberLiteral
326
327
  }),
327
328
  descriptorFor(mongoInt32Codec, {
328
329
  traits: [
@@ -357,11 +358,14 @@ const mongoCodecDescriptors = [
357
358
  ],
358
359
  renderValueLiteral: decimalTextNumberLiteral
359
360
  }),
360
- descriptorFor(mongoDecimal128Codec, { traits: [
361
- "equality",
362
- "order",
363
- "numeric"
364
- ] }),
361
+ descriptorFor(mongoDecimal128Codec, {
362
+ traits: [
363
+ "equality",
364
+ "order",
365
+ "numeric"
366
+ ],
367
+ keepsWrittenForm: true
368
+ }),
365
369
  descriptorFor(mongoBinaryCodec, { traits: ["equality"] }),
366
370
  descriptorFor(mongoJsonCodec, { traits: [] }),
367
371
  descriptorFor(mongoBsonCodec, { traits: [] })
@@ -385,4 +389,4 @@ function buildStandardCodecRegistry() {
385
389
  //#endregion
386
390
  export { mongoStandardCodecs as i, mongoCodecDescriptors as n, mongoDescriptorById as r, buildStandardCodecRegistry as t };
387
391
 
388
- //# sourceMappingURL=codecs-BVrMDhha-DBl_TLS8.mjs.map
392
+ //# sourceMappingURL=codecs-CylyDRI5-DdzCZHek.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codecs-CylyDRI5-DdzCZHek.mjs","names":[],"sources":["../../../../3-mongo-target/1-mongo-target/dist/codecs-CylyDRI5.mjs"],"sourcesContent":["import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, p as MONGO_VECTOR_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from \"./codec-ids-WdrumsYA.mjs\";\nimport { A as int64NumberDecode, B as decodeBsonValue, C as decimal128Encode, D as int32ToJson, E as int32Encode, F as objectIdEncode, G as child, H as readBsonJson, I as objectIdToJson, J as isPlainArray, K as constructorName, L as stringEncode, M as int64NumberFromDigits, N as int64NumberToJson, O as int64Decode, P as int64ToJson, R as vectorEncode, S as decimal128Decode, T as doubleEncode, U as bsonClassTag, V as encodeBsonValue, W as bsonTypeTag, X as where, Y as isPlainObject, _ as binaryFromBase64, a as mongoDate, b as dateEncode, c as mongoInt32, d as mongoObjectId, f as mongoString, g as binaryEncode, h as binaryDecode, j as int64NumberEncode, k as int64Encode, l as mongoInt64, n as mongoBool, o as mongoDecimal128, p as mongoVector, q as dbRefEntries, r as mongoBson, s as mongoDouble, t as mongoBinary, u as mongoJson, v as binaryToBase64, w as decimal128ToJson, x as dateToJson, y as booleanEncode, z as bsonToJson } from \"./data-types-BUNJnoE9.mjs\";\nimport { t as mongoTargetError } from \"./mongo-target-errors-Btf3ML1w.mjs\";\nimport { decimalTextBigintLiteral, decimalTextNumberLiteral, floatNumberLiteral, floatToJson, readJsonFloat, renderTsLiteral } from \"@internal/framework-components/codec\";\nimport { mongoCodec, newMongoCodecRegistry } from \"@internal/mongo-codec\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { ifDefined } from \"@internal/utils/defined\";\n//#region src/core/json-codec-helpers.ts\nconst BSON_TYPE_BY_TAG = {\n\tObjectId: \"objectId\",\n\tDecimal128: \"decimal\",\n\tBinary: \"binData\",\n\tBSONRegExp: \"regex\",\n\tTimestamp: \"timestamp\",\n\tBSONSymbol: \"symbol\",\n\tCode: \"javascript\",\n\tMinKey: \"minKey\",\n\tMaxKey: \"maxKey\"\n};\nconst NOT_FINITE_FIX = \"JSON has no NaN or Infinity; store null or a string, or declare the field Bson.\";\nconst BSON_FIX = \"Declare the field Bson to store BSON values.\";\nconst PLAIN_VALUE_FIX = \"Convert it to a plain object or array.\";\nconst ENCODE_FIX_BY_RECEIVED = {\n\tDate: \"Store the date as an ISO 8601 string, or declare the field Bson.\",\n\tbigint: \"Store it as a number in the safe-integer range or as decimal text, or declare the field Int64 or Bson.\",\n\tNaN: NOT_FINITE_FIX,\n\tInfinity: NOT_FINITE_FIX,\n\t\"-Infinity\": NOT_FINITE_FIX,\n\tundefined: \"Leave the key out, or store null.\",\n\tUint8Array: \"Store the bytes as a base64 string, or declare the field Binary or Bson.\",\n\tBuffer: \"Store the bytes as a base64 string, or declare the field Binary or Bson.\",\n\tBinary: \"Store the bytes as a base64 string, or declare the field Binary or Bson.\",\n\tObjectId: \"Store its hex string, or declare the field ObjectId or Bson.\",\n\tLong: \"Store a number in the safe-integer range or decimal text, or declare the field Int64 or Bson.\",\n\tDecimal128: \"Store the decimal text, or declare the field Decimal128 or Bson.\",\n\tInt32: \"Pass a plain number.\",\n\tDouble: \"Pass a plain number.\",\n\tRegExp: \"Store the pattern as a string, or declare the field Bson.\",\n\tBSONRegExp: \"Store the pattern as a string, or declare the field Bson.\",\n\tsymbol: \"Store a string instead.\",\n\tfunction: \"Store data, not a function.\",\n\t\"circular reference\": \"Remove the cycle; a JSON value is a tree.\",\n\t\"sparse array hole\": \"Fill the hole with null.\",\n\tDBRef: \"Write it as a { $ref, $id } document instead.\"\n};\nfunction encodeFix(received) {\n\treturn ENCODE_FIX_BY_RECEIVED[received] ?? (Object.hasOwn(BSON_TYPE_BY_TAG, received) ? BSON_FIX : PLAIN_VALUE_FIX);\n}\nfunction encodeRefused(received, path) {\n\tthrow mongoTargetError(\"RUNTIME.ENCODE_FAILED\", `${MONGO_JSON_CODEC_ID} value must be a JSON value; received ${received} at ${where(path)}. ${encodeFix(received)}`, { meta: {\n\t\tcodecId: MONGO_JSON_CODEC_ID,\n\t\treceived,\n\t\tvaluePath: path\n\t} });\n}\nfunction describeNonJson(value) {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return void 0;\n\tif (typeof value === \"number\") return Number.isFinite(value) ? void 0 : String(value);\n\tif (typeof value !== \"object\") return typeof value;\n\tconst tag = bsonTypeTag(value);\n\tif (tag !== void 0) return tag;\n\tif (value instanceof Date) return \"Date\";\n\tif (isPlainArray(value)) return void 0;\n\treturn isPlainObject(value) ? void 0 : constructorName(value);\n}\nfunction assertJsonValue(value, path, ancestors) {\n\tconst received = describeNonJson(value);\n\tif (received !== void 0) encodeRefused(received, path);\n\tif (typeof value !== \"object\" || value === null) return;\n\tif (ancestors.has(value)) encodeRefused(\"circular reference\", path);\n\tancestors.add(value);\n\tif (Array.isArray(value)) for (let index = 0; index < value.length; index++) {\n\t\tif (!(index in value)) encodeRefused(\"sparse array hole\", child(path, index));\n\t\tassertJsonValue(value[index], child(path, index), ancestors);\n\t}\n\telse for (const [key, entry] of Object.entries(value)) assertJsonValue(entry, child(path, key), ancestors);\n\tancestors.delete(value);\n}\n/**\n* Returns `value` unchanged when it is a plain JSON value at every depth, and throws `RUNTIME.ENCODE_FAILED` naming the first value that is not, with its path.\n*/\nfunction encodeJsonValue(value) {\n\tassertJsonValue(value, \"\", /* @__PURE__ */ new Set());\n\treturn value;\n}\nfunction decodeRefused(bsonType, path) {\n\tthrow mongoTargetError(\"RUNTIME.DECODE_FAILED\", `${MONGO_JSON_CODEC_ID} wire value contains a non-JSON BSON ${bsonType} at ${where(path)}`, { meta: {\n\t\tcodecId: MONGO_JSON_CODEC_ID,\n\t\treceived: bsonType,\n\t\tvaluePath: path\n\t} });\n}\nfunction safeLong(value, path) {\n\tconst number = Number(value);\n\treturn Number.isSafeInteger(number) && BigInt(number) === value ? number : decodeRefused(\"long\", path);\n}\nfunction finiteDouble(value, path) {\n\tif (Number.isFinite(value)) return value;\n\tconst received = String(value);\n\tthrow mongoTargetError(\"RUNTIME.DECODE_FAILED\", `${MONGO_JSON_CODEC_ID} wire value contains ${received} at ${where(path)}; a JSON number cannot be NaN or Infinity`, { meta: {\n\t\tcodecId: MONGO_JSON_CODEC_ID,\n\t\treceived,\n\t\tvaluePath: path\n\t} });\n}\nfunction decodeEntries(entries, path) {\n\treturn Object.fromEntries(entries.map(([key, entry]) => [key, decodeValue(entry, child(path, key))]));\n}\nfunction decodeTagged(value, tag, path) {\n\tswitch (tag) {\n\t\tcase \"DBRef\": return decodeEntries(dbRefEntries(value), path);\n\t\tcase \"Long\": return safeLong(blindCast(value).toBigInt(), path);\n\t\tcase \"Int32\":\n\t\tcase \"Double\": return finiteDouble(Number(value.valueOf()), path);\n\t}\n\treturn decodeRefused(BSON_TYPE_BY_TAG[tag] ?? tag, path);\n}\nfunction decodeValue(value, path) {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") return finiteDouble(value, path);\n\tif (typeof value === \"bigint\") return safeLong(value, path);\n\tif (typeof value === \"undefined\") return decodeRefused(\"undefined\", path);\n\tif (typeof value === \"symbol\") return decodeRefused(\"symbol\", path);\n\tif (typeof value === \"function\") return decodeRefused(\"javascript\", path);\n\tconst tag = bsonClassTag(value);\n\tif (tag !== void 0) return decodeTagged(value, tag, path);\n\tif (value instanceof Date) return decodeRefused(\"date\", path);\n\tif (value instanceof RegExp) return decodeRefused(\"regex\", path);\n\tif (value instanceof Uint8Array) return decodeRefused(\"binData\", path);\n\tif (Array.isArray(value)) {\n\t\tconst decoded = value.map((entry, index) => decodeValue(entry, child(path, index)));\n\t\treturn decoded.some((entry, index) => entry !== value[index]) ? decoded : value;\n\t}\n\tif (!isPlainObject(value)) return decodeRefused(constructorName(value), path);\n\tconst entries = Object.entries(value);\n\tconst decoded = decodeEntries(entries, path);\n\treturn entries.some(([key, entry]) => decoded[key] !== entry) ? decoded : blindCast(value);\n}\n/**\n* Decodes a wire value to the JSON value it holds: a `long` in the safe-integer range and the driver's `Int32` and `Double` wrappers become numbers. Only the objects and arrays around a converted value are copied; a wire value that is already JSON is returned as the same object. Throws `RUNTIME.DECODE_FAILED` naming the BSON type and path of the first value that is not JSON.\n*/\nfunction decodeJsonValue(wire) {\n\treturn decodeValue(wire, \"\");\n}\n//#endregion\n//#region src/core/codecs.ts\nconst mongoObjectIdCodec = mongoCodec({\n\ttypeId: MONGO_OBJECTID_CODEC_ID,\n\tdataType: mongoObjectId,\n\tfromWire: (wire) => wire.toHexString(),\n\ttoWire: (value) => objectIdEncode(MONGO_OBJECTID_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoObjectId.valueFrom(objectIdToJson(MONGO_OBJECTID_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => value.value\n});\nconst mongoStringCodec = mongoCodec({\n\ttypeId: MONGO_STRING_CODEC_ID,\n\tdataType: mongoString,\n\tfromWire: (wire) => wire,\n\ttoWire: (value) => stringEncode(MONGO_STRING_CODEC_ID, value),\n\tfromDataTypeValue: (value) => value.value\n});\nconst mongoDoubleCodec = mongoCodec({\n\ttypeId: MONGO_DOUBLE_CODEC_ID,\n\tdataType: mongoDouble,\n\tfromWire: (wire) => Number(wire),\n\ttoWire: (value) => doubleEncode(MONGO_DOUBLE_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoDouble.valueFrom(floatToJson(value), {}),\n\tfromDataTypeValue: (value) => readJsonFloat(MONGO_DOUBLE_CODEC_ID, value.value)\n});\nconst mongoInt32Codec = mongoCodec({\n\ttypeId: MONGO_INT32_CODEC_ID,\n\tdataType: mongoInt32,\n\tfromWire: (wire) => wire,\n\ttoWire: (value) => int32Encode(MONGO_INT32_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoInt32.valueFrom(int32ToJson(MONGO_INT32_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => value.value\n});\nconst mongoBooleanCodec = mongoCodec({\n\ttypeId: MONGO_BOOLEAN_CODEC_ID,\n\tdataType: mongoBool,\n\tfromWire: (wire) => wire,\n\ttoWire: (value) => booleanEncode(MONGO_BOOLEAN_CODEC_ID, value),\n\tfromDataTypeValue: (value) => value.value\n});\nconst mongoDateCodec = mongoCodec({\n\ttypeId: MONGO_DATE_CODEC_ID,\n\tdataType: mongoDate,\n\tfromWire: (wire) => wire,\n\ttoWire: (value) => dateEncode(MONGO_DATE_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoDate.valueFrom(dateToJson(MONGO_DATE_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => new Date(value.value)\n});\n/** The vector codec for a column of `mongo/vector` with `params`. The dimension reaches only the TypeScript type `Vector<n>`. */\nfunction vectorCodec(params) {\n\treturn mongoCodec({\n\t\ttypeId: MONGO_VECTOR_CODEC_ID,\n\t\tdataType: mongoVector,\n\t\t...ifDefined(\"params\", params),\n\t\tfromWire: (wire) => wire,\n\t\ttoWire: (value) => vectorEncode(MONGO_VECTOR_CODEC_ID, value),\n\t\tfromDataTypeValue: (value) => value.value\n\t});\n}\nconst mongoVectorCodec = vectorCodec();\n/**\n* A BSON `long`. The application value is a `bigint`, because a `number` cannot hold the full 64-bit range; its stored form is decimal text.\n*/\nconst mongoInt64Codec = mongoCodec({\n\ttypeId: MONGO_INT64_CODEC_ID,\n\tdataType: mongoInt64,\n\tfromWire: (wire) => int64Decode(MONGO_INT64_CODEC_ID, wire),\n\ttoWire: (value) => int64Encode(MONGO_INT64_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoInt64.valueFrom(int64ToJson(MONGO_INT64_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => BigInt(value.value)\n});\n/**\n* A BSON `long` read and written as a `number` from -(2^53 - 1) to 2^53 - 1, the value a Prisma 6 `Int` presents. A value outside that range, or with a fraction, is refused rather than rounded.\n*/\nconst mongoInt64NumberCodec = mongoCodec({\n\ttypeId: MONGO_INT64_NUMBER_CODEC_ID,\n\tdataType: mongoInt64,\n\tfromWire: (wire) => int64NumberDecode(MONGO_INT64_NUMBER_CODEC_ID, wire),\n\ttoWire: (value) => int64NumberEncode(MONGO_INT64_NUMBER_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoInt64.valueFrom(int64NumberToJson(MONGO_INT64_NUMBER_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => int64NumberFromDigits(MONGO_INT64_NUMBER_CODEC_ID, value.value)\n});\n/**\n* A BSON `decimal`. The application value and its stored form are the same decimal text, written without an exponent.\n*/\nconst mongoDecimal128Codec = mongoCodec({\n\ttypeId: MONGO_DECIMAL128_CODEC_ID,\n\tdataType: mongoDecimal128,\n\tfromWire: (wire) => decimal128Decode(MONGO_DECIMAL128_CODEC_ID, wire),\n\ttoWire: (value) => decimal128Encode(MONGO_DECIMAL128_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoDecimal128.valueFrom(decimal128ToJson(MONGO_DECIMAL128_CODEC_ID, value), {}),\n\tfromDataTypeValue: (value) => value.value\n});\n/**\n* BSON `binData`. The application value is a `Uint8Array`; its stored form is unwrapped base64.\n*/\nconst mongoBinaryCodec = mongoCodec({\n\ttypeId: MONGO_BINARY_CODEC_ID,\n\tdataType: mongoBinary,\n\tfromWire: (wire) => binaryDecode(MONGO_BINARY_CODEC_ID, wire),\n\ttoWire: (value) => binaryEncode(MONGO_BINARY_CODEC_ID, value),\n\ttoDataTypeValue: (value) => mongoBinary.valueFrom(binaryToBase64(value), {}),\n\tfromDataTypeValue: (value) => binaryFromBase64(value.value)\n});\n/**\n* A JSON value, stored as the BSON object, array, string, number, boolean or null it maps to. Encode and decode refuse any other value at any depth, naming its path.\n*/\nconst mongoJsonCodec = mongoCodec({\n\ttypeId: MONGO_JSON_CODEC_ID,\n\tdataType: mongoJson,\n\tfromWire: (wire) => decodeJsonValue(wire),\n\ttoWire: (value) => encodeJsonValue(value)\n});\n/**\n* Any BSON value, passed through unchanged except that decode turns a `DBRef` back into the `{ $ref, $id }` document it was stored as. Encode takes a `BsonInputValue` and decode returns a `BsonValue`. Its stored form is canonical MongoDB Extended JSON v2, written with each number and `Uint8Array` as the BSON type the driver stores, so a round trip keeps the BSON bytes but may return wrapper classes such as `Int32` and `Double`.\n*/\nconst mongoBsonCodec = mongoCodec({\n\ttypeId: MONGO_BSON_CODEC_ID,\n\tdataType: mongoBson,\n\tfromWire: (wire) => decodeBsonValue(wire),\n\ttoWire: (value) => encodeBsonValue(value),\n\ttoDataTypeValue: (value) => mongoBson.valueFrom(bsonToJson(value), {}),\n\tfromDataTypeValue: (value) => readBsonJson(MONGO_BSON_CODEC_ID, value.value)\n});\n/**\n* The canonical set of Mongo wire-type codecs.\n*\n* Single source of truth for both control- and runtime-plane adapter descriptors. Don't duplicate this list — import it.\n*/\nconst mongoStandardCodecs = [\n\tmongoObjectIdCodec,\n\tmongoStringCodec,\n\tmongoDoubleCodec,\n\tmongoInt32Codec,\n\tmongoBooleanCodec,\n\tmongoDateCodec,\n\tmongoVectorCodec,\n\tmongoInt64Codec,\n\tmongoInt64NumberCodec,\n\tmongoDecimal128Codec,\n\tmongoBinaryCodec,\n\tmongoJsonCodec,\n\tmongoBsonCodec\n];\n/**\n* Build a {@link CodecDescriptor} for a Mongo wire-type codec.\n*\n* Wraps an existing {@link MongoCodec} instance into a descriptor whose factory hands out the same shared codec, or, for a codec whose data type has parameters, one built for the column's parameters. Mongo's full migration to descriptor-first authoring is tracked under TML-2324; for now the descriptor view is composed from the existing `mongoCodec()` outputs.\n*/\nfunction descriptorFor(codec, metadata) {\n\treturn {\n\t\tcodecId: codec.id,\n\t\tdataType: codec.dataType.id,\n\t\ttraits: metadata.traits,\n\t\tparamsSchema: blindCast(codec.dataType.params),\n\t\tisParameterized: codec.dataType.params !== void 0,\n\t\tfactory: blindCast((params) => {\n\t\t\tconst built = metadata.withParams === void 0 || params === void 0 ? codec : metadata.withParams(params);\n\t\t\treturn () => built;\n\t\t}),\n\t\t...ifDefined(\"renderValueLiteral\", metadata.renderValueLiteral),\n\t\t...ifDefined(\"keepsWrittenForm\", metadata.keepsWrittenForm)\n\t};\n}\n/**\n* Mongo wire-type codec descriptors. Static metadata such as `traits` lives here (the descriptor shape) — `MongoCodec` itself carries its data type and the four conversion methods (TML-2357).\n*/\nconst mongoCodecDescriptors = [\n\tdescriptorFor(mongoObjectIdCodec, { traits: [\"equality\"] }),\n\tdescriptorFor(mongoStringCodec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"textual\"\n\t\t],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoDoubleCodec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\trenderValueLiteral: floatNumberLiteral\n\t}),\n\tdescriptorFor(mongoInt32Codec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoBooleanCodec, {\n\t\ttraits: [\"equality\", \"boolean\"],\n\t\trenderValueLiteral: renderTsLiteral\n\t}),\n\tdescriptorFor(mongoDateCodec, { traits: [\"equality\", \"order\"] }),\n\tdescriptorFor(mongoVectorCodec, {\n\t\ttraits: [\"equality\"],\n\t\twithParams: vectorCodec\n\t}),\n\tdescriptorFor(mongoInt64Codec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\trenderValueLiteral: decimalTextBigintLiteral\n\t}),\n\tdescriptorFor(mongoInt64NumberCodec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\trenderValueLiteral: decimalTextNumberLiteral\n\t}),\n\tdescriptorFor(mongoDecimal128Codec, {\n\t\ttraits: [\n\t\t\t\"equality\",\n\t\t\t\"order\",\n\t\t\t\"numeric\"\n\t\t],\n\t\tkeepsWrittenForm: true\n\t}),\n\tdescriptorFor(mongoBinaryCodec, { traits: [\"equality\"] }),\n\tdescriptorFor(mongoJsonCodec, { traits: [] }),\n\tdescriptorFor(mongoBsonCodec, { traits: [] })\n];\n/**\n* Lookup descriptor metadata by codec id — used by tests and for descriptor-side reads of static metadata.\n*/\nfunction mongoDescriptorById(codecId) {\n\treturn mongoCodecDescriptors.find((d) => d.codecId === codecId);\n}\n/**\n* Build a {@link MongoCodecRegistry} preloaded with the standard Mongo wire-type codecs.\n*\n* Single point of truth for adapter-side codec construction: used by the legacy synchronous `createMongoAdapter()` factory and by the runtime adapter descriptor's `codecs()` getter. Userland code obtains a registry via the framework's execution-stack composition (see `createMongoExecutionContext`) instead of calling this directly.\n*/\nfunction buildStandardCodecRegistry() {\n\tconst registry = newMongoCodecRegistry();\n\tfor (const codec of mongoStandardCodecs) registry.register(codec);\n\treturn registry;\n}\n//#endregion\nexport { mongoStandardCodecs as i, mongoCodecDescriptors as n, mongoDescriptorById as r, buildStandardCodecRegistry as t };\n\n//# sourceMappingURL=codecs-CylyDRI5.mjs.map"],"mappings":";;;;;;;;AAQA,MAAM,mBAAmB;CACxB,UAAU;CACV,YAAY;CACZ,QAAQ;CACR,YAAY;CACZ,WAAW;CACX,YAAY;CACZ,MAAM;CACN,QAAQ;CACR,QAAQ;AACT;AACA,MAAM,iBAAiB;AACvB,MAAM,WAAW;AACjB,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;CAC9B,MAAM;CACN,QAAQ;CACR,KAAK;CACL,UAAU;CACV,aAAa;CACb,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,MAAM;CACN,YAAY;CACZ,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,YAAY;CACZ,QAAQ;CACR,UAAU;CACV,sBAAsB;CACtB,qBAAqB;CACrB,O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AAQ,CAAC,YAAY,OAAO,EAAE,CAAC;CAC/D,cAAc,kBAAkB;EAC/B,QAAQ,CAAC,UAAU;EACnB,YAAY;CACb,CAAC;CACD,cAAc,iBAAiB;EAC9B,QAAQ;GACP;GACA;GACA;EACD;EACA,oBAAoB;CACrB,CAAC;CACD,cAAc,uBAAuB;EACpC,QAAQ;GACP;GACA;GACA;EACD;EACA,oBAAoB;CACrB,CAAC;CACD,cAAc,sBAAsB;EACnC,QAAQ;GACP;GACA;GACA;EACD;EACA,kBAAkB;CACnB,CAAC;CACD,cAAc,kBAAkB,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC;CACxD,cAAc,gBAAgB,EAAE,QAAQ,CAAC,EAAE,CAAC;CAC5C,cAAc,gBAAgB,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC7C;;;;AAIA,SAAS,oBAAoB,SAAS;CACrC,OAAO,sBAAsB,MAAM,MAAM,EAAE,YAAY,OAAO;AAC/D;;;;;;AAMA,SAAS,6BAA6B;CACrC,MAAM,WAAW,sBAAsB;CACvC,KAAK,MAAM,SAAS,qBAAqB,SAAS,SAAS,KAAK;CAChE,OAAO;AACR"}
@@ -1,5 +1,5 @@
1
1
  import { t as mongoTargetError } from "./mongo-target-errors-Btf3ML1w-B5EMYbz1.mjs";
2
- import { t as mongoTargetDescriptorMeta } from "./descriptor-meta-BQBreSNF-CZ9uOPwO.mjs";
2
+ import { t as mongoTargetDescriptorMeta } from "./descriptor-meta-DdeUSTJk-zJzD7C-n.mjs";
3
3
  import { a as dropCollection, c as renameField, d as unsetField, n as createCollection, o as dropIndex, r as createIndex, s as renameCollection, t as collMod, u as unrewritableFieldNameReason } from "./migration-factories-jwrORVMV-BGqJk_WT.mjs";
4
4
  import { blindCast } from "@prisma/orm-framework/utils/casts";
5
5
  import { type } from "arktype";
@@ -11,17 +11,17 @@ import { AggregateCommand, MongoAddFieldsStage, MongoLimitStage, MongoLookupStag
11
11
  import { canonicalizeSchemasForVerification, contractToMongoSchemaIR, diffMongoSchemas, fieldRewriteOf } from "@prisma/orm-family-mongo/family/control";
12
12
  import { notOk, ok } from "@prisma/orm-framework/utils/result";
13
13
  import { MongoContractSerializerBase, MongoSchemaVerifierBase } from "@prisma/orm-family-mongo/family/ir";
14
- import { MongoCollection, MongoStorage, collectionControlPoliciesOf, collectionControlPolicyOf, collectionRootModelsOf, storedFieldNameOf, storesField, validatorFieldNamesOf, validatorRootShapesOf } from "@prisma/orm-family-mongo/contract";
14
+ import { MongoCollection, MongoStorage, collectionControlPoliciesOf, collectionControlPolicyOf, collectionRootModelsOf, hasOwnFieldStoredAs, modelAndBasesOf, mongoModelsOf, ownEmbedStoredNamesOf, ownStoredNameOf, ownStoredNamesOf, validatorFieldNamesOf, validatorRootShapesOf } from "@prisma/orm-family-mongo/contract";
15
15
  import { composeMongoEntityKinds } from "@prisma/orm-family-mongo/contract/entity-kinds";
16
16
  import { asNamespaceId, governingControlPolicy } from "@prisma/orm-framework/contract/types";
17
17
  import { APP_SPACE_ID, VERIFY_CODE_SCHEMA_FAILURE, contractSnapshotJsonSpecifier, contractSnapshotTypesSpecifier, describeMigrationStatement, issueOutcome, modelDisplayName } from "@prisma/orm-framework/components/control";
18
+ import { InternalError } from "@prisma/orm-framework/utils/internal-error";
18
19
  import { TsExpression, jsonToTsSource, renderImports } from "@prisma/orm-framework/ts-render";
19
20
  import { Migration } from "@prisma/orm-toolchain/migration-tools/migration";
20
21
  import { resolveRequirementSpecifiers } from "@prisma/orm-framework/components/emission";
21
22
  import { detectScaffoldRuntime, shebangLineFor } from "@prisma/orm-toolchain/migration-tools/migration-ts";
22
23
  import { errorRunnerFailed } from "@prisma/orm-framework/errors/execution";
23
24
  import { verifyMongoSchema } from "@prisma/orm-family-mongo/family/schema-verify";
24
- import { InternalError } from "@prisma/orm-framework/utils/internal-error";
25
25
  //#region ../../../3-mongo-target/1-mongo-target/dist/control.mjs
26
26
  /**
27
27
  * Mongo target `Namespace` concretion. In Mongo the "namespace" concept
@@ -384,8 +384,19 @@ function collectionOf(contract, coordinate) {
384
384
  return typeof collection === "string" ? collection : coordinate.model;
385
385
  }
386
386
  function modelAt(contract, coordinate) {
387
- const namespace = contract.domain.namespaces[coordinate.namespaceId];
388
- return namespace !== void 0 && Object.hasOwn(namespace.models, coordinate.model) ? namespace.models[coordinate.model] : void 0;
387
+ const models = mongoModelsOf(contract.domain, coordinate.namespaceId);
388
+ return Object.hasOwn(models, coordinate.model) ? models[coordinate.model] : void 0;
389
+ }
390
+ /** The stored name of `field` of the model at `coordinate`, or undefined when the model does not declare it. */
391
+ function storedFieldNameAt(contract, coordinate) {
392
+ const model = modelAt(contract, coordinate);
393
+ return model === void 0 || !Object.hasOwn(model.fields, coordinate.field) ? void 0 : ownStoredNameOf(model, coordinate.field);
394
+ }
395
+ /** The stored name of a field the statement's resolution found on the model at `coordinate`. */
396
+ function resolvedStoredNameAt(contract, coordinate) {
397
+ const storedName = storedFieldNameAt(contract, coordinate);
398
+ if (storedName === void 0) throw new InternalError(`Field "${coordinate.model}.${coordinate.field}" a statement names has no stored name`);
399
+ return storedName;
389
400
  }
390
401
  /**
391
402
  * The condition that selects a variant's documents in the collection it shares with its base: the
@@ -394,10 +405,13 @@ function modelAt(contract, coordinate) {
394
405
  function variantFilter(contract, coordinate) {
395
406
  const base = modelAt(contract, coordinate)?.base;
396
407
  if (base === void 0) return void 0;
397
- const baseModel = contract.domain.namespaces[base.namespace]?.models[base.model];
408
+ const baseModel = modelAt(contract, {
409
+ namespaceId: asNamespaceId(base.namespace),
410
+ model: base.model
411
+ });
398
412
  const field = baseModel?.discriminator?.field;
399
413
  const value = Object.entries(baseModel?.variants ?? {}).find(([, variant]) => variant.namespace === coordinate.namespaceId && variant.model === coordinate.model)?.[0];
400
- return field === void 0 || value === void 0 ? void 0 : { [field]: value };
414
+ return baseModel === void 0 || field === void 0 || value === void 0 ? void 0 : { [ownStoredNameOf(baseModel, field)]: value };
401
415
  }
402
416
  function declaredCollection(contract, collection) {
403
417
  return Object.values(contract.storage.namespaces).map((namespace) => namespace.entries["collection"]?.[collection]).find((entry) => entry instanceof MongoCollection);
@@ -467,21 +481,18 @@ function discriminatorValueOf(filter) {
467
481
  * The other models stored in `collection`, root models and their variants, whose documents a change of `storedName` with `filter` reaches, and which store the field themselves or through their base. No discriminator tells the documents of several root models apart, so without a filter, or with a base model's filter, every other root model's documents are reached. A variant's filter, one discriminator value, reaches a model only when its documents can hold that value: a variant of another root model with the same discriminator field and value, or a model that declares the discriminator field itself.
468
482
  */
469
483
  function otherModelsReached(contract, model, collection, filter, storedName) {
470
- const models = contract.domain.namespaces[model.namespaceId]?.models ?? {};
484
+ const models = mongoModelsOf(contract.domain, model.namespaceId);
471
485
  const baseOf = (name) => {
472
486
  const base = models[name]?.base;
473
487
  return base === void 0 ? void 0 : models[base.model];
474
488
  };
475
- const storesOrInherits = (name, field) => {
476
- const each = models[name];
477
- const base = baseOf(name);
478
- return each !== void 0 && storesField(each, field) || base !== void 0 && storesField(base, field);
479
- };
489
+ const storesOrInherits = (name, storedName) => modelAndBasesOf(models, name).some((each) => ownStores(each, storedName));
480
490
  const selected = discriminatorValueOf(filter);
481
491
  const canHold = (name) => {
482
492
  if (selected === void 0) return true;
483
493
  const base = baseOf(name);
484
- if (base?.discriminator?.field === selected.field) return Object.entries(base.variants ?? {}).some(([value, variant]) => variant.model === name && value === selected.value);
494
+ const discriminator = base?.discriminator?.field;
495
+ if (base !== void 0 && discriminator !== void 0 && ownStoredNameOf(base, discriminator) === selected.field) return Object.entries(base.variants ?? {}).some(([value, variant]) => variant.model === name && value === selected.value);
485
496
  return storesOrInherits(name, selected.field);
486
497
  };
487
498
  const subjectRoot = modelAt(contract, model)?.base?.model ?? model.model;
@@ -633,28 +644,28 @@ function planFieldStatement(statement, label, renamedCollections, schema, input)
633
644
  if (fromField.kind === "embed" || toField.kind === "embed") return refuse("the field is an embedded relation", `Renaming an embedded relation is not supported in this release. ${LEAVE_OUT}`);
634
645
  if (fromField.kind !== "field" && toField.kind !== "field") return { kind: "unchanged" };
635
646
  if (fromField.kind !== "field" || toField.kind !== "field") return refuse("the field is stored in documents on one side of the statement only", `A relation is not stored in documents, so a statement cannot rename a field to or from one. ${LEAVE_OUT}`);
636
- if (statement.from.field === "_id" || statement.to.field === "_id") return refuse("it renames _id", `MongoDB does not let a document change its _id. ${LEAVE_OUT}`);
637
- const unsafeFrom = unrewritableFieldNameReason(statement.from.field);
638
- if (unsafeFrom !== void 0) return refuse(`the stored field name "${statement.from.field}" cannot be rewritten`, `${unsafeFrom}, so a statement cannot move its values. Rename it in the database yourself, or ${LEAVE_OUT.toLowerCase()}`);
639
- const unsafeTo = unrewritableFieldNameReason(statement.to.field);
640
- if (unsafeTo !== void 0) return refuse(`the stored field name "${statement.to.field}" cannot be written`, `${unsafeTo}. Give the field a stored name without "." that does not start with "$" (with @map), or ${LEAVE_OUT.toLowerCase()}`);
647
+ const fromStored = resolvedStoredNameAt(input.fromContract, statement.from);
648
+ const toStored = resolvedStoredNameAt(input.contract, statement.to);
641
649
  const originCollection = collectionOf(input.fromContract, statement.from);
642
650
  const collection = renamedCollections.get(originCollection) ?? originCollection;
643
651
  const destinationCollection = collectionOf(input.contract, statement.to);
652
+ if (fromStored === toStored && collection === destinationCollection) return { kind: "unchanged" };
653
+ if (fromStored === "_id" || toStored === "_id") return refuse("it renames _id", `MongoDB does not let a document change its _id. ${LEAVE_OUT}`);
654
+ const unsafeFrom = unrewritableFieldNameReason(fromStored);
655
+ if (unsafeFrom !== void 0) return refuse(`the stored name "${fromStored}" cannot be rewritten`, `${unsafeFrom}, so a statement cannot move its values. Rename it in the database yourself, or ${LEAVE_OUT.toLowerCase()}`);
656
+ const unsafeTo = unrewritableFieldNameReason(toStored);
657
+ if (unsafeTo !== void 0) return refuse(`the stored name "${toStored}" cannot be written`, `${unsafeTo}. Give the field a stored name without "." that does not start with "$" (with @map), or ${LEAVE_OUT.toLowerCase()}`);
644
658
  if (collection !== destinationCollection) return refuse(`the model's collection changes from "${originCollection}" to "${destinationCollection}", and no statement renames it`, collectionChangeAdvice(statement, originCollection, destinationCollection));
645
- if (statement.from.field === statement.to.field) return { kind: "unchanged" };
646
- if (schema.collection(collection)?.options?.timeseries !== void 0) return refuse(`collection "${collection}" is a time-series collection`, `${TIME_SERIES_UPDATES}, so a statement cannot move the values of a field in them. Keep the stored name: name the field ${JSON.stringify(statement.from.field)} in the contract (with @map(${JSON.stringify(statement.from.field)}) in PSL), then run this command again without this statement.`);
659
+ if (schema.collection(collection)?.options?.timeseries !== void 0) return refuse(`collection "${collection}" is a time-series collection`, `${TIME_SERIES_UPDATES}, so a statement cannot move the values of a field in them. Keep the stored name: store the field as ${JSON.stringify(fromStored)} (with @map(${JSON.stringify(fromStored)}) in PSL), then run this command again without this statement.`);
647
660
  const policyRefusal = controlPolicyRefusal(statement, label, input.contract, collection);
648
661
  if (policyRefusal !== void 0) return policyRefusal;
649
662
  const variant = variantFilter(input.fromContract, statement.from);
650
- const fromModel = modelAt(input.fromContract, statement.from);
651
- const renamedTogether = new Set(input.statements.flatMap((other) => other.entity === "field" && other.from.namespaceId === statement.from.namespaceId && other.from.field === statement.from.field && other.to.field === statement.to.field ? [other.from.model] : []));
652
- const others = otherModelsReached(input.fromContract, statement.from, originCollection, variant, fromModel === void 0 ? statement.from.field : storedFieldNameOf(fromModel, statement.from.field)).filter((name) => !renamedTogether.has(name));
653
- if (others.length > 0) return refuse(`model ${others.map((name) => JSON.stringify(name)).join(", ")} stores field ${JSON.stringify(statement.from.field)} in the same collection, ${JSON.stringify(collection)}`, `${sharedCollectionWhy(collection, others, "renaming the field would rename it in the documents")} To change it, ${SEPARATE_THE_MODELS}.`);
654
- const filter = variant ?? rootDocumentsLosing(input.contract, statement.to, statement.from.field)?.filter;
663
+ const renamedTogether = new Set(input.statements.flatMap((other) => other.entity === "field" && other.from.namespaceId === statement.from.namespaceId && storedFieldNameAt(input.fromContract, other.from) === fromStored && storedFieldNameAt(input.contract, other.to) === toStored ? [other.from.model] : []));
664
+ const others = otherModelsReached(input.fromContract, statement.from, originCollection, variant, fromStored).filter((name) => !renamedTogether.has(name));
665
+ if (others.length > 0) return refuse(`model ${others.map((name) => JSON.stringify(name)).join(", ")} stores field ${JSON.stringify(fromStored)} in the same collection, ${JSON.stringify(collection)}`, `${sharedCollectionWhy(collection, others, "renaming the field would rename it in the documents")} To change it, ${SEPARATE_THE_MODELS}.`);
655
666
  return {
656
667
  kind: "renameField",
657
- call: new RenameFieldCall(collection, statement.from.field, statement.to.field, filter)
668
+ call: new RenameFieldCall(collection, fromStored, toStored, variant ?? rootDocumentsLosing(input.contract, statement.to, fromStored)?.filter)
658
669
  };
659
670
  }
660
671
  function collectionChangeAdvice(statement, from, to) {
@@ -697,30 +708,33 @@ function destinationModelOf(origin, input) {
697
708
  function renamedByStatement(input, field) {
698
709
  return input.statements.some((statement) => statement.entity === "field" && sameModel(statement.from, field) && statement.from.field === field.field);
699
710
  }
711
+ /** Whether one of `model`'s own fields or embed relations is stored under `storedName`. */
712
+ function ownStores(model, storedName) {
713
+ return hasOwnFieldStoredAs(model, storedName) || Object.values(ownEmbedStoredNamesOf(model)).includes(storedName);
714
+ }
715
+ /** The stored names of the documents of the model at `coordinate`: its fields and embed relations, its own and those it inherits. */
700
716
  function storedFieldsOf(contract, coordinate) {
701
- const model = modelAt(contract, coordinate);
702
- if (model === void 0) return /* @__PURE__ */ new Set();
703
- const base = model.base === void 0 ? void 0 : modelAt(contract, {
704
- namespaceId: asNamespaceId(model.base.namespace),
705
- model: model.base.model
706
- });
707
- return /* @__PURE__ */ new Set([...Object.keys(model.fields), ...Object.keys(base?.fields ?? {})]);
717
+ const models = mongoModelsOf(contract.domain, coordinate.namespaceId);
718
+ return new Set(modelAndBasesOf(models, coordinate.model).flatMap((model) => [...Object.values(ownStoredNamesOf(model)), ...Object.values(ownEmbedStoredNamesOf(model))]));
708
719
  }
709
720
  /**
710
721
  * The documents of a root model that lose `field`: all of them, or, when some of its destination
711
722
  * variants now store the field themselves, those whose discriminator value is none of theirs.
712
723
  * `undefined` when the root model itself still stores it.
713
724
  */
714
- function rootDocumentsLosing(contract, root, field) {
725
+ function rootDocumentsLosing(contract, root, storedName) {
715
726
  const model = modelAt(contract, root);
716
- if (model === void 0 || Object.hasOwn(model.fields, field)) return void 0;
727
+ if (model === void 0 || ownStores(model, storedName)) return void 0;
717
728
  const discriminator = model.discriminator?.field;
718
- const keeping = Object.entries(model.variants ?? {}).filter(([, variant]) => Object.hasOwn(modelAt(contract, {
719
- namespaceId: variant.namespace,
720
- model: variant.model
721
- })?.fields ?? {}, field)).map(([value]) => value).sort();
729
+ const keeping = Object.entries(model.variants ?? {}).filter(([, variant]) => {
730
+ const variantModel = modelAt(contract, {
731
+ namespaceId: variant.namespace,
732
+ model: variant.model
733
+ });
734
+ return variantModel !== void 0 && ownStores(variantModel, storedName);
735
+ }).map(([value]) => value).sort();
722
736
  if (discriminator === void 0 || keeping.length === 0) return { filter: void 0 };
723
- return { filter: { [discriminator]: { $nin: keeping } } };
737
+ return { filter: { [ownStoredNameOf(model, discriminator)]: { $nin: keeping } } };
724
738
  }
725
739
  /**
726
740
  * Each field an origin model stores that its destination model no longer stores, in a collection
@@ -739,17 +753,17 @@ function planFieldRemovals(input) {
739
753
  const model = modelAt(input.fromContract, origin);
740
754
  if (model === void 0) return [];
741
755
  const variant = variantFilter(input.fromContract, origin);
742
- const losing = (field) => {
743
- if (variant !== void 0) return storedFieldsOf(input.contract, destination).has(field) ? void 0 : { filter: variant };
744
- return rootDocumentsLosing(input.contract, destination, field);
756
+ const losing = (storedName) => {
757
+ if (variant !== void 0) return storedFieldsOf(input.contract, destination).has(storedName) ? void 0 : { filter: variant };
758
+ return rootDocumentsLosing(input.contract, destination, storedName);
745
759
  };
746
- return Object.keys(model.fields).filter((field) => unrewritableFieldNameReason(field) === void 0 && !renamedByStatement(input, {
760
+ return Object.entries(ownStoredNamesOf(model)).filter(([field, storedName]) => unrewritableFieldNameReason(storedName) === void 0 && !renamedByStatement(input, {
747
761
  ...origin,
748
762
  field
749
- })).sort().flatMap((field) => {
750
- const lost = losing(field);
763
+ })).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).flatMap(([field, storedName]) => {
764
+ const lost = losing(storedName);
751
765
  return lost === void 0 ? [] : [{
752
- call: new UnsetFieldCall(collection, field, lost.filter),
766
+ call: new UnsetFieldCall(collection, storedName, lost.filter),
753
767
  subject: {
754
768
  kind: "field",
755
769
  ...origin,
@@ -2360,4 +2374,4 @@ const mongoTargetDescriptor = {
2360
2374
  //#endregion
2361
2375
  export { schemaIndexToCreateIndexOptions as C, schemaCollectionToCreateCollectionOptions as S, deserializeMongoOp as _, DropIndexCall as a, renderCallsToTypeScript as b, MongoMigrationRunner as c, MongoTargetSchemaVerifier as d, MongoTargetUnboundDatabase as f, UnsetFieldCall as g, RenameFieldCall as h, DropCollectionCall as i, MongoTargetContractSerializer as l, RenameCollectionCall as m, CreateCollectionCall as n, FilterEvaluator as o, PlannerProducedMongoMigration as p, CreateIndexCall as r, MongoMigrationPlanner as s, CollModCall as t, MongoTargetDatabase as u, deserializeMongoOps as v, serializeMongoOps as w, renderOps as x, mongoTargetDescriptor as y };
2362
2376
 
2363
- //# sourceMappingURL=control-lAuWLUE_.mjs.map
2377
+ //# sourceMappingURL=control-BkNtJldI.mjs.map