@prisma/orm-target-mongo 8.0.0-rc.2-dev.3 → 8.0.0-rc.20

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 (122) hide show
  1. package/README.md +1 -5
  2. package/dist/adapter.d.mts +2 -2
  3. package/dist/adapter.d.mts.map +1 -1
  4. package/dist/adapter.mjs +3 -3
  5. package/dist/adapter.mjs.map +1 -1
  6. package/dist/adapter__control.d.mts +204 -3
  7. package/dist/adapter__control.d.mts.map +1 -0
  8. package/dist/adapter__control.mjs +481 -3
  9. package/dist/adapter__control.mjs.map +1 -0
  10. package/dist/adapter__runtime.d.mts +3 -1
  11. package/dist/adapter__runtime.d.mts.map +1 -1
  12. package/dist/adapter__runtime.mjs +5 -3
  13. package/dist/adapter__runtime.mjs.map +1 -1
  14. package/dist/codec-ids-BKQbXhZt.d.mts +18 -0
  15. package/dist/codec-ids-BKQbXhZt.d.mts.map +1 -0
  16. package/dist/codec-ids-WdrumsYA-CZVjuKW8.mjs +18 -0
  17. package/dist/codec-ids-WdrumsYA-CZVjuKW8.mjs.map +1 -0
  18. package/dist/codec-types-oKxM85p-.d.mts +89 -0
  19. package/dist/codec-types-oKxM85p-.d.mts.map +1 -0
  20. package/dist/codecs-B1ab7vfj-QL33tkm2.mjs +392 -0
  21. package/dist/codecs-B1ab7vfj-QL33tkm2.mjs.map +1 -0
  22. package/dist/codecs-Y5GYsLPj.d.mts +36 -0
  23. package/dist/codecs-Y5GYsLPj.d.mts.map +1 -0
  24. package/dist/control-Cq6qWohQ.mjs +2421 -0
  25. package/dist/control-Cq6qWohQ.mjs.map +1 -0
  26. package/dist/{control-CxXmTy_h.d.mts → control-CrFS8bqh.d.mts} +133 -95
  27. package/dist/control-CrFS8bqh.d.mts.map +1 -0
  28. package/dist/data-types-LShlnAUM.d.mts +25 -0
  29. package/dist/data-types-LShlnAUM.d.mts.map +1 -0
  30. package/dist/data-types-hoKLBrYZ-h9cAgbOy.mjs +624 -0
  31. package/dist/data-types-hoKLBrYZ-h9cAgbOy.mjs.map +1 -0
  32. package/dist/descriptor-meta-DTj807jv-CjvK2XDD.mjs +146 -0
  33. package/dist/descriptor-meta-DTj807jv-CjvK2XDD.mjs.map +1 -0
  34. package/dist/descriptor-meta-runtime-BaRbjvD7-D0786_Lv.mjs +20 -0
  35. package/dist/descriptor-meta-runtime-BaRbjvD7-D0786_Lv.mjs.map +1 -0
  36. package/dist/driver.d.mts +1 -1
  37. package/dist/driver.mjs +1 -1
  38. package/dist/driver__control.d.mts +4 -3
  39. package/dist/driver__control.d.mts.map +1 -1
  40. package/dist/driver__control.mjs +5 -2
  41. package/dist/driver__control.mjs.map +1 -1
  42. package/dist/{migration-BkqcE2Uv.d.mts → migration-C4m4Uj8E.d.mts} +15 -7
  43. package/dist/migration-C4m4Uj8E.d.mts.map +1 -0
  44. package/dist/migration-factories-BqROEHRs-CfExMr9r.mjs +406 -0
  45. package/dist/migration-factories-BqROEHRs-CfExMr9r.mjs.map +1 -0
  46. package/dist/{mongo-adapter-B2HEyX0b-CQt2HH_o.mjs → mongo-adapter-Bo6ciURK-DIMJdC7y.mjs} +37 -18
  47. package/dist/mongo-adapter-Bo6ciURK-DIMJdC7y.mjs.map +1 -0
  48. package/dist/{mongo-adapter-CjJU3S9o-BIJruFYW.d.mts → mongo-adapter-wvK2fQOZ-FswLS-PJ.d.mts} +2 -2
  49. package/dist/mongo-adapter-wvK2fQOZ-FswLS-PJ.d.mts.map +1 -0
  50. package/dist/{mongo-driver-D1lEf5Kl-KPfGUVXK.d.mts → mongo-driver-CTyvKDUg-Bm9sBrfs.d.mts} +9 -4
  51. package/dist/mongo-driver-CTyvKDUg-Bm9sBrfs.d.mts.map +1 -0
  52. package/dist/{mongo-driver-Dk7mris6-CMTaUgPD.mjs → mongo-driver-Cu6FP6OU-DhOzFM2D.mjs} +34 -8
  53. package/dist/mongo-driver-Cu6FP6OU-DhOzFM2D.mjs.map +1 -0
  54. package/dist/mongo-target-errors-Btf3ML1w-QOtEG7EX.mjs +9 -0
  55. package/dist/mongo-target-errors-Btf3ML1w-QOtEG7EX.mjs.map +1 -0
  56. package/dist/{op-factory-call-B7EKa4Ri-B2Lb6W68.d.mts → op-factory-call-BoYr7vvM-CjA8nx36.d.mts} +43 -9
  57. package/dist/op-factory-call-BoYr7vvM-CjA8nx36.d.mts.map +1 -0
  58. package/dist/pack-CIfujQmd.d.mts +266 -0
  59. package/dist/pack-CIfujQmd.d.mts.map +1 -0
  60. package/dist/prisma6-binding-DhnqslLT.d.mts +54 -0
  61. package/dist/prisma6-binding-DhnqslLT.d.mts.map +1 -0
  62. package/dist/prisma6-binding-vt4tbT-Z.mjs +45 -0
  63. package/dist/prisma6-binding-vt4tbT-Z.mjs.map +1 -0
  64. package/dist/{runtime-B9_-kjBX.d.mts → runtime-DbFgyDql.d.mts} +2 -2
  65. package/dist/runtime-DbFgyDql.d.mts.map +1 -0
  66. package/dist/target.d.mts +11 -8
  67. package/dist/target.mjs +7 -3
  68. package/dist/target__codec-ids.d.mts +2 -0
  69. package/dist/target__codec-ids.mjs +2 -0
  70. package/dist/target__codec-types.d.mts +2 -2
  71. package/dist/target__codecs.d.mts +2 -0
  72. package/dist/target__codecs.mjs +2 -0
  73. package/dist/target__control.d.mts +3 -4
  74. package/dist/target__control.mjs +2 -2
  75. package/dist/target__data-types.d.mts +2 -0
  76. package/dist/target__data-types.mjs +2 -0
  77. package/dist/target__migration.d.mts +2 -2
  78. package/dist/target__migration.mjs +2 -2
  79. package/dist/target__pack.d.mts +3 -2
  80. package/dist/target__pack.mjs +2 -2
  81. package/dist/target__pack.mjs.map +1 -1
  82. package/dist/target__prisma6-binding.d.mts +2 -0
  83. package/dist/target__prisma6-binding.mjs +2 -0
  84. package/dist/target__runtime.d.mts +1 -1
  85. package/dist/target__runtime.mjs +3 -3
  86. package/dist/target__runtime.mjs.map +1 -1
  87. package/package.json +16 -15
  88. package/dist/adapter__codec-ids.d.mts +0 -12
  89. package/dist/adapter__codec-ids.d.mts.map +0 -1
  90. package/dist/adapter__codec-ids.mjs +0 -2
  91. package/dist/adapter__codec-types.d.mts +0 -38
  92. package/dist/adapter__codec-types.d.mts.map +0 -1
  93. package/dist/adapter__codec-types.mjs +0 -1
  94. package/dist/adapter__codecs.d.mts +0 -14
  95. package/dist/adapter__codecs.d.mts.map +0 -1
  96. package/dist/adapter__codecs.mjs +0 -2
  97. package/dist/codec-ids-BennPcpQ-Btzz3ILV.mjs +0 -12
  98. package/dist/codec-ids-BennPcpQ-Btzz3ILV.mjs.map +0 -1
  99. package/dist/codec-types-Bx2fHyq_.d.mts +0 -35
  100. package/dist/codec-types-Bx2fHyq_.d.mts.map +0 -1
  101. package/dist/codecs-DLWO-Cjc-CWfQj0bY.mjs +0 -170
  102. package/dist/codecs-DLWO-Cjc-CWfQj0bY.mjs.map +0 -1
  103. package/dist/control-CxXmTy_h.d.mts.map +0 -1
  104. package/dist/control-D2-m_BQJ.mjs +0 -1563
  105. package/dist/control-D2-m_BQJ.mjs.map +0 -1
  106. package/dist/control-DQD76x-1.mjs +0 -437
  107. package/dist/control-DQD76x-1.mjs.map +0 -1
  108. package/dist/control-rPM2HNxW.d.mts +0 -170
  109. package/dist/control-rPM2HNxW.d.mts.map +0 -1
  110. package/dist/descriptor-meta-CBiaTwe5-HX742pZh.mjs +0 -17
  111. package/dist/descriptor-meta-CBiaTwe5-HX742pZh.mjs.map +0 -1
  112. package/dist/migration-BkqcE2Uv.d.mts.map +0 -1
  113. package/dist/migration-factories-CCJFG_3e-75oJ8xn2.mjs +0 -201
  114. package/dist/migration-factories-CCJFG_3e-75oJ8xn2.mjs.map +0 -1
  115. package/dist/mongo-adapter-B2HEyX0b-CQt2HH_o.mjs.map +0 -1
  116. package/dist/mongo-adapter-CjJU3S9o-BIJruFYW.d.mts.map +0 -1
  117. package/dist/mongo-driver-D1lEf5Kl-KPfGUVXK.d.mts.map +0 -1
  118. package/dist/mongo-driver-Dk7mris6-CMTaUgPD.mjs.map +0 -1
  119. package/dist/op-factory-call-B7EKa4Ri-B2Lb6W68.d.mts.map +0 -1
  120. package/dist/pack-MK8ZQfrL.d.mts +0 -22
  121. package/dist/pack-MK8ZQfrL.d.mts.map +0 -1
  122. package/dist/runtime-B9_-kjBX.d.mts.map +0 -1
@@ -0,0 +1,406 @@
1
+ import { t as mongoTargetError } from "./mongo-target-errors-Btf3ML1w-QOtEG7EX.mjs";
2
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
3
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
4
+ import { MONGO_INDEX_OPTION_KEYS } from "@prisma/orm-family-mongo/schema-ir";
5
+ import { CollModCommand, DropCollectionCommand, DropIndexCommand, ListCollectionsCommand, ListIndexesCommand, MongoAndExpr, MongoExistsExpr, MongoFieldFilter, MongoNotExpr, RenameCollectionCommand, buildIndexOpId, defaultMongoIndexName, keysToKeySpec } from "@prisma/orm-family-mongo/query-ast/control";
6
+ import { RawAggregateCommand, RawUpdateManyCommand } from "@prisma/orm-family-mongo/query-ast/execution";
7
+ import { createFieldAccessor } from "@prisma/orm-family-mongo/query-builder";
8
+ import { collection } from "@prisma/orm-family-mongo/query-builder/contract-free";
9
+ //#region ../../../3-targets/mongo/1-target/dist/migration-factories-BqROEHRs.mjs
10
+ function isBuildable(value) {
11
+ if (typeof value !== "object" || value === null || !("build" in value)) return false;
12
+ return typeof Reflect.get(value, "build") === "function";
13
+ }
14
+ function resolveQuery(value) {
15
+ return isBuildable(value) ? value.build() : value;
16
+ }
17
+ const MATCH_ALL_FILTER = MongoExistsExpr.exists("_id");
18
+ function dataTransform(name, options) {
19
+ let precheck = [];
20
+ let postcheck = [];
21
+ if (options.check) {
22
+ const source = resolveQuery(options.check.source());
23
+ const filter = options.check.filter ?? MATCH_ALL_FILTER;
24
+ const description = options.check.description ?? `Check for data transform: ${name}`;
25
+ const precheckExpect = options.check.expect ?? "exists";
26
+ const postcheckExpect = precheckExpect === "exists" ? "notExists" : "exists";
27
+ precheck = [{
28
+ description,
29
+ source,
30
+ filter,
31
+ expect: precheckExpect
32
+ }];
33
+ postcheck = [{
34
+ description,
35
+ source,
36
+ filter,
37
+ expect: postcheckExpect
38
+ }];
39
+ }
40
+ const run = [resolveQuery(options.run())];
41
+ return {
42
+ id: `data_transform.${name}`,
43
+ label: `Data transform: ${name}`,
44
+ operationClass: "data",
45
+ name,
46
+ ...ifDefined("invariantId", options.invariantId),
47
+ precheck,
48
+ run,
49
+ postcheck
50
+ };
51
+ }
52
+ const REWRITE_PLAN_META = {
53
+ target: "mongo",
54
+ storageHash: "",
55
+ lane: "mongo-raw"
56
+ };
57
+ function documentsHolding(fields, filter) {
58
+ const conditions = [...filter === void 0 ? [] : [filter], ...fields.map((field) => ({ [field]: { $exists: true } }))];
59
+ const [only] = conditions;
60
+ return conditions.length === 1 && only !== void 0 ? only : { $and: conditions };
61
+ }
62
+ const UNREWRITABLE_FIELD_NAMES = [
63
+ {
64
+ matches: (field) => field === "",
65
+ reason: "it is empty"
66
+ },
67
+ {
68
+ matches: (field) => field === "_id",
69
+ reason: "MongoDB does not let a document change its _id"
70
+ },
71
+ {
72
+ matches: (field) => field.includes("."),
73
+ reason: "MongoDB reads a name containing \".\" as a path into embedded documents"
74
+ },
75
+ {
76
+ matches: (field) => field.startsWith("$"),
77
+ reason: "MongoDB reads a name starting with \"$\" as an operator"
78
+ }
79
+ ];
80
+ /** Why `renameField` and `unsetField` cannot rewrite a field of this name, if they cannot. */
81
+ function unrewritableFieldNameReason(field) {
82
+ return UNREWRITABLE_FIELD_NAMES.find((rule) => rule.matches(field))?.reason;
83
+ }
84
+ function assertRewritableField(collectionName, field) {
85
+ const reason = unrewritableFieldNameReason(field);
86
+ if (reason === void 0) return;
87
+ throw mongoTargetError("MIGRATION.FIELD_NAME_UNSUPPORTED", `Field "${field}" in collection ${collectionName} cannot be rewritten: ${reason}.`, { meta: {
88
+ collection: collectionName,
89
+ field,
90
+ reason
91
+ } });
92
+ }
93
+ function rewritePlan(collectionName, command) {
94
+ return {
95
+ collection: collectionName,
96
+ command,
97
+ meta: { ...REWRITE_PLAN_META }
98
+ };
99
+ }
100
+ function noDocumentHolds(collectionName, fields, filter) {
101
+ return {
102
+ description: `no document in ${collectionName} holds ${fields.length === 1 ? fields[0] : `both ${fields.join(" and ")}`}`,
103
+ source: rewritePlan(collectionName, new RawAggregateCommand(collectionName, [{ $match: documentsHolding(fields, filter) }, { $limit: 1 }])),
104
+ filter: MATCH_ALL_FILTER,
105
+ expect: "notExists"
106
+ };
107
+ }
108
+ function rewriteUpdate(collectionName, field, filter, update) {
109
+ return rewritePlan(collectionName, new RawUpdateManyCommand(collectionName, documentsHolding([field], filter), update, { bypassDocumentValidation: true }));
110
+ }
111
+ function idSuffix(filter) {
112
+ return filter === void 0 ? "" : `.where(${JSON.stringify(filter)})`;
113
+ }
114
+ function valueList(values) {
115
+ return values.map((value) => JSON.stringify(value)).join(", ");
116
+ }
117
+ /** A field condition in words: `type is "bug"`, `type is not "bug"`, `type is none of "bug", "task"`. */
118
+ function conditionInWords(field, condition) {
119
+ const excluded = typeof condition === "object" && condition !== null && !Array.isArray(condition) ? Reflect.get(condition, "$nin") : void 0;
120
+ if (Array.isArray(excluded)) return excluded.length === 1 ? `${field} is not ${valueList(excluded)}` : `${field} is none of ${valueList(excluded)}`;
121
+ return typeof condition === "object" && condition !== null ? void 0 : `${field} is ${JSON.stringify(condition)}`;
122
+ }
123
+ /** The documents a filter selects, in words where the planner wrote it, for an operation's label. */
124
+ function labelSuffix(filter) {
125
+ if (filter === void 0) return "";
126
+ const words = Object.entries(filter).map(([field, condition]) => conditionInWords(field, condition));
127
+ return words.every((word) => word !== void 0) && words.length > 0 ? ` in documents whose ${words.join(" and ")}` : ` in documents matching ${JSON.stringify(filter)}`;
128
+ }
129
+ function renameField(collectionName, from, to, options) {
130
+ assertRewritableField(collectionName, from);
131
+ assertRewritableField(collectionName, to);
132
+ if (from === to) throw mongoTargetError("MIGRATION.INVALID_OPERATION_ENTRY", `renameField renames field "${from}" in collection ${collectionName} to its own name.`, { meta: {
133
+ context: "renameField",
134
+ collection: collectionName,
135
+ field: from,
136
+ reason: "the new name is the old name"
137
+ } });
138
+ const filter = options?.filter;
139
+ const id = `field.${collectionName}.${from}.rename(${to})${idSuffix(filter)}`;
140
+ return {
141
+ id,
142
+ label: `Rename field ${from} to ${to} in collection ${collectionName}${labelSuffix(filter)}`,
143
+ operationClass: "widening",
144
+ name: id,
145
+ precheck: [noDocumentHolds(collectionName, [from, to], filter)],
146
+ run: [rewriteUpdate(collectionName, from, filter, { $rename: { [from]: to } })],
147
+ postcheck: [noDocumentHolds(collectionName, [from], filter)]
148
+ };
149
+ }
150
+ function unsetField(collectionName, field, options) {
151
+ assertRewritableField(collectionName, field);
152
+ const filter = options?.filter;
153
+ const id = `field.${collectionName}.${field}.unset${idSuffix(filter)}`;
154
+ return {
155
+ id,
156
+ label: `Remove field ${field} from collection ${collectionName}${labelSuffix(filter)}`,
157
+ operationClass: "destructive",
158
+ name: id,
159
+ precheck: [],
160
+ run: [rewriteUpdate(collectionName, field, filter, { $unset: { [field]: "" } })],
161
+ postcheck: [noDocumentHolds(collectionName, [field], filter)]
162
+ };
163
+ }
164
+ function formatKeys(keys) {
165
+ return keys.map((k) => `${k.field}:${k.direction}`).join(", ");
166
+ }
167
+ /** What an index check matches, which is the index's keys and collection, not its name. */
168
+ function indexObject(collectionName, keys) {
169
+ if (isTextIndex(keys)) return `a text index in "${collectionName}"`;
170
+ return `an index on { ${keys.map((key) => `${key.field}: ${JSON.stringify(key.direction)}`).join(", ")} } in "${collectionName}"`;
171
+ }
172
+ function isTextIndex(keys) {
173
+ return keys.some((k) => k.direction === "text");
174
+ }
175
+ function keyFilter(keys) {
176
+ const f = createFieldAccessor();
177
+ return isTextIndex(keys) ? f.rawPath("key._fts").eq("text") : f.key.eq(blindCast(keysToKeySpec(keys)));
178
+ }
179
+ function documentValue(document) {
180
+ return blindCast(document);
181
+ }
182
+ /** MongoDB stores a text index's text fields as `_fts` and `_ftsx` in the place of the first one. */
183
+ function textIndexKeySpec(keys) {
184
+ const spec = {};
185
+ for (const key of keys) if (key.direction !== "text") spec[key.field] = key.direction;
186
+ else if (!Object.hasOwn(spec, "_fts")) Object.assign(spec, {
187
+ _fts: "text",
188
+ _ftsx: 1
189
+ });
190
+ return spec;
191
+ }
192
+ /** MongoDB lists every text field's weight, 1 when none is given, ordered by field name. */
193
+ function textIndexWeights(keys, weights) {
194
+ const fields = keys.filter((key) => key.direction === "text").map((key) => key.field);
195
+ return Object.fromEntries(fields.sort().map((field) => [field, weights?.[field] ?? 1]));
196
+ }
197
+ function flagFilter(field, on) {
198
+ const set = MongoFieldFilter.eq(field, true);
199
+ return on ? set : new MongoNotExpr(set);
200
+ }
201
+ function optionFilter(field, value) {
202
+ return value === void 0 ? MongoExistsExpr.notExists(field) : MongoFieldFilter.eq(field, value);
203
+ }
204
+ /**
205
+ * MongoDB completes a collation with its defaults, so only the fields the call gives are compared, as
206
+ * the verifier does. An index with no collation must have none.
207
+ */
208
+ function collationFilters(collation) {
209
+ if (collation === void 0) return [MongoExistsExpr.notExists("collation")];
210
+ return Object.entries(collation).map(([option, value]) => MongoFieldFilter.eq(`collation.${option}`, blindCast(value)));
211
+ }
212
+ const textIndexOnly = (filter) => (options, keys) => isTextIndex(keys) ? filter(options, keys) : [];
213
+ const INDEX_OPTION_FILTERS = {
214
+ unique: (options) => [flagFilter("unique", options?.unique)],
215
+ sparse: (options) => [flagFilter("sparse", options?.sparse)],
216
+ expireAfterSeconds: (options) => [optionFilter("expireAfterSeconds", options?.expireAfterSeconds)],
217
+ partialFilterExpression: (options) => [optionFilter("partialFilterExpression", options?.partialFilterExpression && documentValue(options.partialFilterExpression))],
218
+ wildcardProjection: (options) => [optionFilter("wildcardProjection", options?.wildcardProjection && documentValue(options.wildcardProjection))],
219
+ collation: (options) => collationFilters(options?.collation),
220
+ weights: textIndexOnly((options, keys) => [MongoFieldFilter.eq("weights", documentValue(textIndexWeights(keys, options?.weights)))]),
221
+ default_language: textIndexOnly((options) => [MongoFieldFilter.eq("default_language", options?.default_language ?? TEXT_INDEX_DEFAULT_LANGUAGE)]),
222
+ language_override: textIndexOnly((options) => [MongoFieldFilter.eq("language_override", options?.language_override ?? TEXT_INDEX_DEFAULT_LANGUAGE_OVERRIDE)])
223
+ };
224
+ function indexDefinitionFilter(keys, options) {
225
+ return MongoAndExpr.of([isTextIndex(keys) ? MongoFieldFilter.eq("key", documentValue(textIndexKeySpec(keys))) : keyFilter(keys), ...MONGO_INDEX_OPTION_KEYS.flatMap((option) => INDEX_OPTION_FILTERS[option](options, keys))]);
226
+ }
227
+ const TEXT_INDEX_DEFAULT_LANGUAGE = "english";
228
+ const TEXT_INDEX_DEFAULT_LANGUAGE_OVERRIDE = "language";
229
+ function createIndex(collectionName, keys, options) {
230
+ const name = defaultMongoIndexName(keys);
231
+ const filter = keyFilter(keys);
232
+ return {
233
+ id: buildIndexOpId("create", collectionName, keys),
234
+ label: `Create index on ${collectionName} (${formatKeys(keys)})`,
235
+ operationClass: "additive",
236
+ precheck: [{
237
+ description: `index does not already exist on ${collectionName}`,
238
+ source: new ListIndexesCommand(collectionName),
239
+ filter,
240
+ expect: "notExists",
241
+ object: indexObject(collectionName, keys)
242
+ }],
243
+ execute: [{
244
+ description: `create index on ${collectionName}`,
245
+ command: collection(collectionName).createIndex(keys, {
246
+ ...options,
247
+ name
248
+ })
249
+ }],
250
+ postcheck: [{
251
+ description: `index exists on ${collectionName}`,
252
+ source: new ListIndexesCommand(collectionName),
253
+ filter: indexDefinitionFilter(keys, options),
254
+ expect: "exists"
255
+ }]
256
+ };
257
+ }
258
+ function dropIndex(collectionName, keys) {
259
+ const indexName = defaultMongoIndexName(keys);
260
+ const filter = keyFilter(keys);
261
+ return {
262
+ id: buildIndexOpId("drop", collectionName, keys),
263
+ label: `Drop index on ${collectionName} (${formatKeys(keys)})`,
264
+ operationClass: "widening",
265
+ precheck: [{
266
+ description: `index exists on ${collectionName}`,
267
+ source: new ListIndexesCommand(collectionName),
268
+ filter,
269
+ expect: "exists",
270
+ object: indexObject(collectionName, keys)
271
+ }],
272
+ execute: [{
273
+ description: `drop index on ${collectionName}`,
274
+ command: new DropIndexCommand(collectionName, indexName)
275
+ }],
276
+ postcheck: [{
277
+ description: `index no longer exists on ${collectionName}`,
278
+ source: new ListIndexesCommand(collectionName),
279
+ filter,
280
+ expect: "notExists",
281
+ object: indexObject(collectionName, keys)
282
+ }]
283
+ };
284
+ }
285
+ function createCollection(collectionName, options) {
286
+ const f = createFieldAccessor();
287
+ return {
288
+ id: `collection.${collectionName}.create`,
289
+ label: `Create collection ${collectionName}`,
290
+ operationClass: "additive",
291
+ precheck: [{
292
+ description: `collection ${collectionName} does not exist`,
293
+ source: new ListCollectionsCommand(),
294
+ filter: f.name.eq(collectionName),
295
+ expect: "notExists",
296
+ object: `collection "${collectionName}"`
297
+ }],
298
+ execute: [{
299
+ description: `create collection ${collectionName}`,
300
+ command: collection(collectionName).createCollection(options)
301
+ }],
302
+ postcheck: []
303
+ };
304
+ }
305
+ function dropCollection(collectionName) {
306
+ return {
307
+ id: `collection.${collectionName}.drop`,
308
+ label: `Drop collection ${collectionName}`,
309
+ operationClass: "destructive",
310
+ precheck: [],
311
+ execute: [{
312
+ description: `drop collection ${collectionName}`,
313
+ command: new DropCollectionCommand(collectionName)
314
+ }],
315
+ postcheck: []
316
+ };
317
+ }
318
+ function collectionCheck(name, expect) {
319
+ return {
320
+ description: expect === "exists" ? `collection ${name} exists` : `collection ${name} does not exist`,
321
+ source: new ListCollectionsCommand(),
322
+ filter: MongoFieldFilter.eq("name", name),
323
+ expect,
324
+ object: `collection "${name}"`
325
+ };
326
+ }
327
+ function renameCollection(from, to) {
328
+ return {
329
+ id: `collection.${from}.rename(${to})`,
330
+ label: `Rename collection ${from} to ${to}`,
331
+ operationClass: "widening",
332
+ precheck: [collectionCheck(from, "exists"), collectionCheck(to, "notExists")],
333
+ execute: [{
334
+ description: `rename collection ${from} to ${to}`,
335
+ command: new RenameCollectionCommand(from, to)
336
+ }],
337
+ postcheck: [collectionCheck(to, "exists"), collectionCheck(from, "notExists")]
338
+ };
339
+ }
340
+ function setValidation(collectionName, schema, options) {
341
+ return {
342
+ id: `collection.${collectionName}.setValidation`,
343
+ label: `Set validation on ${collectionName}`,
344
+ operationClass: "widening",
345
+ precheck: [],
346
+ execute: [{
347
+ description: `set validation on ${collectionName}`,
348
+ command: new CollModCommand(collectionName, {
349
+ validator: { $jsonSchema: schema },
350
+ ...ifDefined("validationLevel", options?.validationLevel),
351
+ ...ifDefined("validationAction", options?.validationAction)
352
+ })
353
+ }],
354
+ postcheck: []
355
+ };
356
+ }
357
+ /**
358
+ * Matches the collection's validator body. MongoDB returns the validator through `listCollections`
359
+ * with its keys in the order given, so the order-sensitive comparison holds once the collMod ran; a
360
+ * validator written by hand with another key order only makes the collMod run again.
361
+ */
362
+ function validatorBodyFilter(validator) {
363
+ const { $jsonSchema, ...rest } = validator;
364
+ return $jsonSchema !== void 0 && Object.keys(rest).length === 0 ? MongoFieldFilter.eq("options.validator.$jsonSchema", blindCast($jsonSchema)) : MongoFieldFilter.eq("options.validator", documentValue(validator));
365
+ }
366
+ function collMod(collectionName, options, meta) {
367
+ const hasValidator = options.validator != null && Object.keys(options.validator).length > 0;
368
+ return {
369
+ id: meta?.id ?? `collection.${collectionName}.collMod`,
370
+ label: meta?.label ?? `Modify collection ${collectionName}`,
371
+ operationClass: meta?.operationClass ?? "widening",
372
+ precheck: options.validator != null ? [{
373
+ description: `collection ${collectionName} exists`,
374
+ source: new ListCollectionsCommand(),
375
+ filter: MongoFieldFilter.eq("name", collectionName),
376
+ expect: "exists",
377
+ object: `collection "${collectionName}"`
378
+ }] : [],
379
+ execute: [{
380
+ description: `modify ${collectionName}`,
381
+ command: new CollModCommand(collectionName, options)
382
+ }],
383
+ postcheck: hasValidator ? [{
384
+ description: `validator applied on ${collectionName}`,
385
+ source: new ListCollectionsCommand(),
386
+ filter: MongoAndExpr.of([
387
+ MongoFieldFilter.eq("name", collectionName),
388
+ ...options.validationLevel ? [MongoFieldFilter.eq("options.validationLevel", options.validationLevel)] : [],
389
+ ...options.validationAction ? [MongoFieldFilter.eq("options.validationAction", options.validationAction)] : [],
390
+ validatorBodyFilter(options.validator ?? {})
391
+ ]),
392
+ expect: "exists"
393
+ }] : []
394
+ };
395
+ }
396
+ function validatedCollection(name, schema, indexes) {
397
+ return [createCollection(name, {
398
+ validator: { $jsonSchema: schema },
399
+ validationLevel: "strict",
400
+ validationAction: "error"
401
+ }), ...indexes.map((idx) => createIndex(name, idx.keys, idx.unique !== void 0 ? { unique: idx.unique } : void 0))];
402
+ }
403
+ //#endregion
404
+ export { dropCollection as a, renameField as c, unsetField as d, validatedCollection as f, dataTransform as i, setValidation as l, createCollection as n, dropIndex as o, createIndex as r, renameCollection as s, collMod as t, unrewritableFieldNameReason as u };
405
+
406
+ //# sourceMappingURL=migration-factories-BqROEHRs-CfExMr9r.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-factories-BqROEHRs-CfExMr9r.mjs","names":[],"sources":["../../../../3-targets/mongo/1-target/dist/migration-factories-BqROEHRs.mjs"],"sourcesContent":["import { t as mongoTargetError } from \"./mongo-target-errors-Btf3ML1w.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { MONGO_INDEX_OPTION_KEYS } from \"@internal/mongo-schema-ir\";\nimport { CollModCommand, DropCollectionCommand, DropIndexCommand, ListCollectionsCommand, ListIndexesCommand, MongoAndExpr, MongoExistsExpr, MongoFieldFilter, MongoNotExpr, RenameCollectionCommand, buildIndexOpId, defaultMongoIndexName, keysToKeySpec } from \"@internal/mongo-query-ast/control\";\nimport { RawAggregateCommand, RawUpdateManyCommand } from \"@internal/mongo-query-ast/execution\";\nimport { createFieldAccessor } from \"@internal/mongo-query-builder\";\nimport { collection } from \"@internal/mongo-query-builder/contract-free\";\n//#region src/core/migrations/migration-factories.ts\nfunction isBuildable(value) {\n\tif (typeof value !== \"object\" || value === null || !(\"build\" in value)) return false;\n\treturn typeof Reflect.get(value, \"build\") === \"function\";\n}\nfunction resolveQuery(value) {\n\treturn isBuildable(value) ? value.build() : value;\n}\nconst MATCH_ALL_FILTER = MongoExistsExpr.exists(\"_id\");\nfunction dataTransform(name, options) {\n\tlet precheck = [];\n\tlet postcheck = [];\n\tif (options.check) {\n\t\tconst source = resolveQuery(options.check.source());\n\t\tconst filter = options.check.filter ?? MATCH_ALL_FILTER;\n\t\tconst description = options.check.description ?? `Check for data transform: ${name}`;\n\t\tconst precheckExpect = options.check.expect ?? \"exists\";\n\t\tconst postcheckExpect = precheckExpect === \"exists\" ? \"notExists\" : \"exists\";\n\t\tprecheck = [{\n\t\t\tdescription,\n\t\t\tsource,\n\t\t\tfilter,\n\t\t\texpect: precheckExpect\n\t\t}];\n\t\tpostcheck = [{\n\t\t\tdescription,\n\t\t\tsource,\n\t\t\tfilter,\n\t\t\texpect: postcheckExpect\n\t\t}];\n\t}\n\tconst run = [resolveQuery(options.run())];\n\treturn {\n\t\tid: `data_transform.${name}`,\n\t\tlabel: `Data transform: ${name}`,\n\t\toperationClass: \"data\",\n\t\tname,\n\t\t...ifDefined(\"invariantId\", options.invariantId),\n\t\tprecheck,\n\t\trun,\n\t\tpostcheck\n\t};\n}\nconst REWRITE_PLAN_META = {\n\ttarget: \"mongo\",\n\tstorageHash: \"\",\n\tlane: \"mongo-raw\"\n};\nfunction documentsHolding(fields, filter) {\n\tconst conditions = [...filter === void 0 ? [] : [filter], ...fields.map((field) => ({ [field]: { $exists: true } }))];\n\tconst [only] = conditions;\n\treturn conditions.length === 1 && only !== void 0 ? only : { $and: conditions };\n}\nconst UNREWRITABLE_FIELD_NAMES = [\n\t{\n\t\tmatches: (field) => field === \"\",\n\t\treason: \"it is empty\"\n\t},\n\t{\n\t\tmatches: (field) => field === \"_id\",\n\t\treason: \"MongoDB does not let a document change its _id\"\n\t},\n\t{\n\t\tmatches: (field) => field.includes(\".\"),\n\t\treason: \"MongoDB reads a name containing \\\".\\\" as a path into embedded documents\"\n\t},\n\t{\n\t\tmatches: (field) => field.startsWith(\"$\"),\n\t\treason: \"MongoDB reads a name starting with \\\"$\\\" as an operator\"\n\t}\n];\n/** Why `renameField` and `unsetField` cannot rewrite a field of this name, if they cannot. */\nfunction unrewritableFieldNameReason(field) {\n\treturn UNREWRITABLE_FIELD_NAMES.find((rule) => rule.matches(field))?.reason;\n}\nfunction assertRewritableField(collectionName, field) {\n\tconst reason = unrewritableFieldNameReason(field);\n\tif (reason === void 0) return;\n\tthrow mongoTargetError(\"MIGRATION.FIELD_NAME_UNSUPPORTED\", `Field \"${field}\" in collection ${collectionName} cannot be rewritten: ${reason}.`, { meta: {\n\t\tcollection: collectionName,\n\t\tfield,\n\t\treason\n\t} });\n}\nfunction rewritePlan(collectionName, command) {\n\treturn {\n\t\tcollection: collectionName,\n\t\tcommand,\n\t\tmeta: { ...REWRITE_PLAN_META }\n\t};\n}\nfunction noDocumentHolds(collectionName, fields, filter) {\n\treturn {\n\t\tdescription: `no document in ${collectionName} holds ${fields.length === 1 ? fields[0] : `both ${fields.join(\" and \")}`}`,\n\t\tsource: rewritePlan(collectionName, new RawAggregateCommand(collectionName, [{ $match: documentsHolding(fields, filter) }, { $limit: 1 }])),\n\t\tfilter: MATCH_ALL_FILTER,\n\t\texpect: \"notExists\"\n\t};\n}\nfunction rewriteUpdate(collectionName, field, filter, update) {\n\treturn rewritePlan(collectionName, new RawUpdateManyCommand(collectionName, documentsHolding([field], filter), update, { bypassDocumentValidation: true }));\n}\nfunction idSuffix(filter) {\n\treturn filter === void 0 ? \"\" : `.where(${JSON.stringify(filter)})`;\n}\nfunction valueList(values) {\n\treturn values.map((value) => JSON.stringify(value)).join(\", \");\n}\n/** A field condition in words: `type is \"bug\"`, `type is not \"bug\"`, `type is none of \"bug\", \"task\"`. */\nfunction conditionInWords(field, condition) {\n\tconst excluded = typeof condition === \"object\" && condition !== null && !Array.isArray(condition) ? Reflect.get(condition, \"$nin\") : void 0;\n\tif (Array.isArray(excluded)) return excluded.length === 1 ? `${field} is not ${valueList(excluded)}` : `${field} is none of ${valueList(excluded)}`;\n\treturn typeof condition === \"object\" && condition !== null ? void 0 : `${field} is ${JSON.stringify(condition)}`;\n}\n/** The documents a filter selects, in words where the planner wrote it, for an operation's label. */\nfunction labelSuffix(filter) {\n\tif (filter === void 0) return \"\";\n\tconst words = Object.entries(filter).map(([field, condition]) => conditionInWords(field, condition));\n\treturn words.every((word) => word !== void 0) && words.length > 0 ? ` in documents whose ${words.join(\" and \")}` : ` in documents matching ${JSON.stringify(filter)}`;\n}\nfunction renameField(collectionName, from, to, options) {\n\tassertRewritableField(collectionName, from);\n\tassertRewritableField(collectionName, to);\n\tif (from === to) throw mongoTargetError(\"MIGRATION.INVALID_OPERATION_ENTRY\", `renameField renames field \"${from}\" in collection ${collectionName} to its own name.`, { meta: {\n\t\tcontext: \"renameField\",\n\t\tcollection: collectionName,\n\t\tfield: from,\n\t\treason: \"the new name is the old name\"\n\t} });\n\tconst filter = options?.filter;\n\tconst id = `field.${collectionName}.${from}.rename(${to})${idSuffix(filter)}`;\n\treturn {\n\t\tid,\n\t\tlabel: `Rename field ${from} to ${to} in collection ${collectionName}${labelSuffix(filter)}`,\n\t\toperationClass: \"widening\",\n\t\tname: id,\n\t\tprecheck: [noDocumentHolds(collectionName, [from, to], filter)],\n\t\trun: [rewriteUpdate(collectionName, from, filter, { $rename: { [from]: to } })],\n\t\tpostcheck: [noDocumentHolds(collectionName, [from], filter)]\n\t};\n}\nfunction unsetField(collectionName, field, options) {\n\tassertRewritableField(collectionName, field);\n\tconst filter = options?.filter;\n\tconst id = `field.${collectionName}.${field}.unset${idSuffix(filter)}`;\n\treturn {\n\t\tid,\n\t\tlabel: `Remove field ${field} from collection ${collectionName}${labelSuffix(filter)}`,\n\t\toperationClass: \"destructive\",\n\t\tname: id,\n\t\tprecheck: [],\n\t\trun: [rewriteUpdate(collectionName, field, filter, { $unset: { [field]: \"\" } })],\n\t\tpostcheck: [noDocumentHolds(collectionName, [field], filter)]\n\t};\n}\nfunction formatKeys(keys) {\n\treturn keys.map((k) => `${k.field}:${k.direction}`).join(\", \");\n}\n/** What an index check matches, which is the index's keys and collection, not its name. */\nfunction indexObject(collectionName, keys) {\n\tif (isTextIndex(keys)) return `a text index in \"${collectionName}\"`;\n\treturn `an index on { ${keys.map((key) => `${key.field}: ${JSON.stringify(key.direction)}`).join(\", \")} } in \"${collectionName}\"`;\n}\nfunction isTextIndex(keys) {\n\treturn keys.some((k) => k.direction === \"text\");\n}\nfunction keyFilter(keys) {\n\tconst f = createFieldAccessor();\n\treturn isTextIndex(keys) ? f.rawPath(\"key._fts\").eq(\"text\") : f.key.eq(blindCast(keysToKeySpec(keys)));\n}\nfunction documentValue(document) {\n\treturn blindCast(document);\n}\n/** MongoDB stores a text index's text fields as `_fts` and `_ftsx` in the place of the first one. */\nfunction textIndexKeySpec(keys) {\n\tconst spec = {};\n\tfor (const key of keys) if (key.direction !== \"text\") spec[key.field] = key.direction;\n\telse if (!Object.hasOwn(spec, \"_fts\")) Object.assign(spec, {\n\t\t_fts: \"text\",\n\t\t_ftsx: 1\n\t});\n\treturn spec;\n}\n/** MongoDB lists every text field's weight, 1 when none is given, ordered by field name. */\nfunction textIndexWeights(keys, weights) {\n\tconst fields = keys.filter((key) => key.direction === \"text\").map((key) => key.field);\n\treturn Object.fromEntries(fields.sort().map((field) => [field, weights?.[field] ?? 1]));\n}\nfunction flagFilter(field, on) {\n\tconst set = MongoFieldFilter.eq(field, true);\n\treturn on ? set : new MongoNotExpr(set);\n}\nfunction optionFilter(field, value) {\n\treturn value === void 0 ? MongoExistsExpr.notExists(field) : MongoFieldFilter.eq(field, value);\n}\n/**\n* MongoDB completes a collation with its defaults, so only the fields the call gives are compared, as\n* the verifier does. An index with no collation must have none.\n*/\nfunction collationFilters(collation) {\n\tif (collation === void 0) return [MongoExistsExpr.notExists(\"collation\")];\n\treturn Object.entries(collation).map(([option, value]) => MongoFieldFilter.eq(`collation.${option}`, blindCast(value)));\n}\nconst textIndexOnly = (filter) => (options, keys) => isTextIndex(keys) ? filter(options, keys) : [];\nconst INDEX_OPTION_FILTERS = {\n\tunique: (options) => [flagFilter(\"unique\", options?.unique)],\n\tsparse: (options) => [flagFilter(\"sparse\", options?.sparse)],\n\texpireAfterSeconds: (options) => [optionFilter(\"expireAfterSeconds\", options?.expireAfterSeconds)],\n\tpartialFilterExpression: (options) => [optionFilter(\"partialFilterExpression\", options?.partialFilterExpression && documentValue(options.partialFilterExpression))],\n\twildcardProjection: (options) => [optionFilter(\"wildcardProjection\", options?.wildcardProjection && documentValue(options.wildcardProjection))],\n\tcollation: (options) => collationFilters(options?.collation),\n\tweights: textIndexOnly((options, keys) => [MongoFieldFilter.eq(\"weights\", documentValue(textIndexWeights(keys, options?.weights)))]),\n\tdefault_language: textIndexOnly((options) => [MongoFieldFilter.eq(\"default_language\", options?.default_language ?? TEXT_INDEX_DEFAULT_LANGUAGE)]),\n\tlanguage_override: textIndexOnly((options) => [MongoFieldFilter.eq(\"language_override\", options?.language_override ?? TEXT_INDEX_DEFAULT_LANGUAGE_OVERRIDE)])\n};\nfunction indexDefinitionFilter(keys, options) {\n\treturn MongoAndExpr.of([isTextIndex(keys) ? MongoFieldFilter.eq(\"key\", documentValue(textIndexKeySpec(keys))) : keyFilter(keys), ...MONGO_INDEX_OPTION_KEYS.flatMap((option) => INDEX_OPTION_FILTERS[option](options, keys))]);\n}\nconst TEXT_INDEX_DEFAULT_LANGUAGE = \"english\";\nconst TEXT_INDEX_DEFAULT_LANGUAGE_OVERRIDE = \"language\";\nfunction createIndex(collectionName, keys, options) {\n\tconst name = defaultMongoIndexName(keys);\n\tconst filter = keyFilter(keys);\n\treturn {\n\t\tid: buildIndexOpId(\"create\", collectionName, keys),\n\t\tlabel: `Create index on ${collectionName} (${formatKeys(keys)})`,\n\t\toperationClass: \"additive\",\n\t\tprecheck: [{\n\t\t\tdescription: `index does not already exist on ${collectionName}`,\n\t\t\tsource: new ListIndexesCommand(collectionName),\n\t\t\tfilter,\n\t\t\texpect: \"notExists\",\n\t\t\tobject: indexObject(collectionName, keys)\n\t\t}],\n\t\texecute: [{\n\t\t\tdescription: `create index on ${collectionName}`,\n\t\t\tcommand: collection(collectionName).createIndex(keys, {\n\t\t\t\t...options,\n\t\t\t\tname\n\t\t\t})\n\t\t}],\n\t\tpostcheck: [{\n\t\t\tdescription: `index exists on ${collectionName}`,\n\t\t\tsource: new ListIndexesCommand(collectionName),\n\t\t\tfilter: indexDefinitionFilter(keys, options),\n\t\t\texpect: \"exists\"\n\t\t}]\n\t};\n}\nfunction dropIndex(collectionName, keys) {\n\tconst indexName = defaultMongoIndexName(keys);\n\tconst filter = keyFilter(keys);\n\treturn {\n\t\tid: buildIndexOpId(\"drop\", collectionName, keys),\n\t\tlabel: `Drop index on ${collectionName} (${formatKeys(keys)})`,\n\t\toperationClass: \"widening\",\n\t\tprecheck: [{\n\t\t\tdescription: `index exists on ${collectionName}`,\n\t\t\tsource: new ListIndexesCommand(collectionName),\n\t\t\tfilter,\n\t\t\texpect: \"exists\",\n\t\t\tobject: indexObject(collectionName, keys)\n\t\t}],\n\t\texecute: [{\n\t\t\tdescription: `drop index on ${collectionName}`,\n\t\t\tcommand: new DropIndexCommand(collectionName, indexName)\n\t\t}],\n\t\tpostcheck: [{\n\t\t\tdescription: `index no longer exists on ${collectionName}`,\n\t\t\tsource: new ListIndexesCommand(collectionName),\n\t\t\tfilter,\n\t\t\texpect: \"notExists\",\n\t\t\tobject: indexObject(collectionName, keys)\n\t\t}]\n\t};\n}\nfunction createCollection(collectionName, options) {\n\tconst f = createFieldAccessor();\n\treturn {\n\t\tid: `collection.${collectionName}.create`,\n\t\tlabel: `Create collection ${collectionName}`,\n\t\toperationClass: \"additive\",\n\t\tprecheck: [{\n\t\t\tdescription: `collection ${collectionName} does not exist`,\n\t\t\tsource: new ListCollectionsCommand(),\n\t\t\tfilter: f.name.eq(collectionName),\n\t\t\texpect: \"notExists\",\n\t\t\tobject: `collection \"${collectionName}\"`\n\t\t}],\n\t\texecute: [{\n\t\t\tdescription: `create collection ${collectionName}`,\n\t\t\tcommand: collection(collectionName).createCollection(options)\n\t\t}],\n\t\tpostcheck: []\n\t};\n}\nfunction dropCollection(collectionName) {\n\treturn {\n\t\tid: `collection.${collectionName}.drop`,\n\t\tlabel: `Drop collection ${collectionName}`,\n\t\toperationClass: \"destructive\",\n\t\tprecheck: [],\n\t\texecute: [{\n\t\t\tdescription: `drop collection ${collectionName}`,\n\t\t\tcommand: new DropCollectionCommand(collectionName)\n\t\t}],\n\t\tpostcheck: []\n\t};\n}\nfunction collectionCheck(name, expect) {\n\treturn {\n\t\tdescription: expect === \"exists\" ? `collection ${name} exists` : `collection ${name} does not exist`,\n\t\tsource: new ListCollectionsCommand(),\n\t\tfilter: MongoFieldFilter.eq(\"name\", name),\n\t\texpect,\n\t\tobject: `collection \"${name}\"`\n\t};\n}\nfunction renameCollection(from, to) {\n\treturn {\n\t\tid: `collection.${from}.rename(${to})`,\n\t\tlabel: `Rename collection ${from} to ${to}`,\n\t\toperationClass: \"widening\",\n\t\tprecheck: [collectionCheck(from, \"exists\"), collectionCheck(to, \"notExists\")],\n\t\texecute: [{\n\t\t\tdescription: `rename collection ${from} to ${to}`,\n\t\t\tcommand: new RenameCollectionCommand(from, to)\n\t\t}],\n\t\tpostcheck: [collectionCheck(to, \"exists\"), collectionCheck(from, \"notExists\")]\n\t};\n}\nfunction setValidation(collectionName, schema, options) {\n\treturn {\n\t\tid: `collection.${collectionName}.setValidation`,\n\t\tlabel: `Set validation on ${collectionName}`,\n\t\toperationClass: \"widening\",\n\t\tprecheck: [],\n\t\texecute: [{\n\t\t\tdescription: `set validation on ${collectionName}`,\n\t\t\tcommand: new CollModCommand(collectionName, {\n\t\t\t\tvalidator: { $jsonSchema: schema },\n\t\t\t\t...ifDefined(\"validationLevel\", options?.validationLevel),\n\t\t\t\t...ifDefined(\"validationAction\", options?.validationAction)\n\t\t\t})\n\t\t}],\n\t\tpostcheck: []\n\t};\n}\n/**\n* Matches the collection's validator body. MongoDB returns the validator through `listCollections`\n* with its keys in the order given, so the order-sensitive comparison holds once the collMod ran; a\n* validator written by hand with another key order only makes the collMod run again.\n*/\nfunction validatorBodyFilter(validator) {\n\tconst { $jsonSchema, ...rest } = validator;\n\treturn $jsonSchema !== void 0 && Object.keys(rest).length === 0 ? MongoFieldFilter.eq(\"options.validator.$jsonSchema\", blindCast($jsonSchema)) : MongoFieldFilter.eq(\"options.validator\", documentValue(validator));\n}\nfunction collMod(collectionName, options, meta) {\n\tconst hasValidator = options.validator != null && Object.keys(options.validator).length > 0;\n\treturn {\n\t\tid: meta?.id ?? `collection.${collectionName}.collMod`,\n\t\tlabel: meta?.label ?? `Modify collection ${collectionName}`,\n\t\toperationClass: meta?.operationClass ?? \"widening\",\n\t\tprecheck: options.validator != null ? [{\n\t\t\tdescription: `collection ${collectionName} exists`,\n\t\t\tsource: new ListCollectionsCommand(),\n\t\t\tfilter: MongoFieldFilter.eq(\"name\", collectionName),\n\t\t\texpect: \"exists\",\n\t\t\tobject: `collection \"${collectionName}\"`\n\t\t}] : [],\n\t\texecute: [{\n\t\t\tdescription: `modify ${collectionName}`,\n\t\t\tcommand: new CollModCommand(collectionName, options)\n\t\t}],\n\t\tpostcheck: hasValidator ? [{\n\t\t\tdescription: `validator applied on ${collectionName}`,\n\t\t\tsource: new ListCollectionsCommand(),\n\t\t\tfilter: MongoAndExpr.of([\n\t\t\t\tMongoFieldFilter.eq(\"name\", collectionName),\n\t\t\t\t...options.validationLevel ? [MongoFieldFilter.eq(\"options.validationLevel\", options.validationLevel)] : [],\n\t\t\t\t...options.validationAction ? [MongoFieldFilter.eq(\"options.validationAction\", options.validationAction)] : [],\n\t\t\t\tvalidatorBodyFilter(options.validator ?? {})\n\t\t\t]),\n\t\t\texpect: \"exists\"\n\t\t}] : []\n\t};\n}\nfunction validatedCollection(name, schema, indexes) {\n\treturn [createCollection(name, {\n\t\tvalidator: { $jsonSchema: schema },\n\t\tvalidationLevel: \"strict\",\n\t\tvalidationAction: \"error\"\n\t}), ...indexes.map((idx) => createIndex(name, idx.keys, idx.unique !== void 0 ? { unique: idx.unique } : void 0))];\n}\n//#endregion\nexport { dropCollection as a, renameField as c, unsetField as d, validatedCollection as f, dataTransform as i, setValidation as l, createCollection as n, dropIndex as o, createIndex as r, renameCollection as s, collMod as t, unrewritableFieldNameReason as u };\n\n//# sourceMappingURL=migration-factories-BqROEHRs.mjs.map"],"mappings":";;;;;;;;;AASA,SAAS,YAAY,OAAO;CAC3B,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,WAAW,QAAQ,OAAO;CAC/E,OAAO,OAAO,QAAQ,IAAI,OAAO,OAAO,MAAM;AAC/C;AACA,SAAS,aAAa,OAAO;CAC5B,OAAO,YAAY,KAAK,IAAI,MAAM,MAAM,IAAI;AAC7C;AACA,MAAM,mBAAmB,gBAAgB,OAAO,KAAK;AACrD,SAAS,cAAc,MAAM,SAAS;CACrC,IAAI,WAAW,CAAC;CAChB,IAAI,YAAY,CAAC;CACjB,IAAI,QAAQ,OAAO;EAClB,MAAM,SAAS,aAAa,QAAQ,MAAM,OAAO,CAAC;EAClD,MAAM,SAAS,QAAQ,MAAM,UAAU;EACvC,MAAM,cAAc,QAAQ,MAAM,eAAe,6BAA6B;EAC9E,MAAM,iBAAiB,QAAQ,MAAM,UAAU;EAC/C,MAAM,kBAAkB,mBAAmB,WAAW,cAAc;EACpE,WAAW,CAAC;GACX;GACA;GACA;GACA,QAAQ;EACT,CAAC;EACD,YAAY,CAAC;GACZ;GACA;GACA;GACA,QAAQ;EACT,CAAC;CACF;CACA,MAAM,MAAM,CAAC,aAAa,QAAQ,IAAI,CAAC,CAAC;CACxC,OAAO;EACN,IAAI,kBAAkB;EACtB,OAAO,mBAAmB;EAC1B,gBAAgB;EAChB;EACA,GAAG,UAAU,eAAe,QAAQ,WAAW;EAC/C;EACA;EAC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;GACrC,QAAQ,IAAI,uBAAuB;GACnC,QAAQ,aAAa,GAAG;IACvB,iBAAiB,GAAG,QAAQ,cAAc;IAC1C,GAAG,QAAQ,kBAAkB,CAAC,iBAAiB,GAAG,2BAA2B,QAAQ,eAAe,CAAC,IAAI,CAAC;IAC1G,GAAG,QAAQ,mBAAmB,CAAC,iBAAiB,GAAG,4BAA4B,QAAQ,gBAAgB,CAAC,IAAI,CAAC;IAC7G,oBAAoB,QAAQ,aAAa,CAAC,CAAC;GAC5C,CAAC;GACD,QAAQ;EACT,CAAC,IAAI,CAAC;CACP;AACD;AACA,SAAS,oBAAoB,MAAM,QAAQ,SAAS;CACnD,OAAO,CAAC,iBAAiB,MAAM;EAC9B,WAAW,EAAE,aAAa,OAAO;EACjC,iBAAiB;EACjB,kBAAkB;CACnB,CAAC,GAAG,GAAG,QAAQ,KAAK,QAAQ,YAAY,MAAM,IAAI,MAAM,IAAI,WAAW,KAAK,IAAI,EAAE,QAAQ,IAAI,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;AAClH"}
@@ -1,13 +1,22 @@
1
- import { t as buildStandardCodecRegistry } from "./codecs-DLWO-Cjc-CWfQj0bY.mjs";
1
+ import { t as buildStandardCodecRegistry } from "./codecs-B1ab7vfj-QL33tkm2.mjs";
2
2
  import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
3
3
  import { blindCast } from "@prisma/orm-framework/utils/casts";
4
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
4
5
  import { keysToKeySpec } from "@prisma/orm-family-mongo/query-ast/control";
5
6
  import { isExprArray, isRecordArgs } from "@prisma/orm-family-mongo/query-ast/execution";
6
- import { InternalError, assertNever } from "@prisma/orm-framework/utils/internal-error";
7
- import { checkAborted, raceAgainstAbort, runtimeError } from "@prisma/orm-framework/components/runtime";
7
+ import { InternalError, assertNever, isInternalError } from "@prisma/orm-framework/utils/internal-error";
8
8
  import { MongoParamRef } from "@prisma/orm-family-mongo/value";
9
- import { AggregateWireCommand, CollModWireCommand, CreateCollectionWireCommand, CreateIndexWireCommand, DeleteManyWireCommand, DeleteOneWireCommand, DropCollectionWireCommand, DropIndexWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyWireCommand, InsertOneWireCommand, UpdateManyWireCommand, UpdateOneWireCommand } from "@prisma/orm-family-mongo/wire";
10
- //#region ../../../3-mongo-target/2-mongo-adapter/dist/mongo-adapter-B2HEyX0b.mjs
9
+ import { checkAborted, raceAgainstAbort, runtimeError } from "@prisma/orm-framework/components/runtime";
10
+ import { AggregateWireCommand, CollModWireCommand, CreateCollectionWireCommand, CreateIndexWireCommand, DeleteManyWireCommand, DeleteOneWireCommand, DropCollectionWireCommand, DropIndexWireCommand, FindOneAndDeleteWireCommand, FindOneAndUpdateWireCommand, InsertManyWireCommand, InsertOneWireCommand, RenameCollectionWireCommand, UpdateManyWireCommand, UpdateOneWireCommand } from "@prisma/orm-family-mongo/wire";
11
+ //#region ../../../3-targets/mongo/2-adapter/dist/mongo-adapter-Bo6ciURK.mjs
12
+ /**
13
+ * A value the driver serializes as one BSON value rather than a document: a `Date`, `RegExp` or `Uint8Array`, or an instance of a `bson` class, recognised by its `_bsontype` tag because the driver's classes come from its own load of `bson`. A plain object carrying a `_bsontype` key is a stored subdocument, not a class.
14
+ */
15
+ function isWireScalar(value) {
16
+ if (value instanceof Date || value instanceof RegExp || value instanceof Uint8Array) return true;
17
+ const prototype = Object.getPrototypeOf(value);
18
+ return prototype !== Object.prototype && prototype !== null && typeof Reflect.get(value, "_bsontype") === "string";
19
+ }
11
20
  /**
12
21
  * Resolves a `MongoValue` (which may contain `MongoParamRef` leaves) into the
13
22
  * driver-ready wire shape. When a leaf has a `codecId` and the registry has a
@@ -21,10 +30,11 @@ import { AggregateWireCommand, CollModWireCommand, CreateCollectionWireCommand,
21
30
  * (mirroring SQL's `wrapEncodeFailure` shape) with `{ label, codec }` details
22
31
  * and the original error attached on `cause`. A structured envelope (any error
23
32
  * with a dotted `code`, per `isStructuredError`) is re-thrown verbatim so
24
- * codec-raised envelopes and nested resolvers don't get double-wrapped.
33
+ * codec-raised envelopes and nested resolvers don't get double-wrapped, and
34
+ * so is an `InternalError`.
25
35
  *
26
36
  * `ctx: CodecCallContext` is forwarded verbatim to every
27
- * `codec.encode(value, ctx)` call. The same `ctx` reference is also passed
37
+ * `codec.toWire(value, ctx)` call. The same `ctx` reference is also passed
28
38
  * to nested `resolveValue` invocations so codec authors observe **signal
29
39
  * identity** across the entire recursive walk for one `runtime.query()`.
30
40
  *
@@ -47,16 +57,15 @@ async function resolveValue(value, codecs, ctx) {
47
57
  if (value instanceof MongoParamRef) {
48
58
  if (value.codecId) {
49
59
  const codec = codecs.get(value.codecId);
50
- if (codec?.encode) try {
51
- return await raceAgainstAbort(codec.encode(value.value, ctx), signal, "encode");
60
+ if (codec?.toWire) try {
61
+ return await raceAgainstAbort(codec.toWire(value.value, ctx), signal, "encode");
52
62
  } catch (error) {
53
63
  wrapEncodeFailure(error, value, codec.id);
54
64
  }
55
65
  }
56
66
  return value.value;
57
67
  }
58
- if (value === null || typeof value !== "object") return value;
59
- if (value instanceof Date) return value;
68
+ if (value === null || typeof value !== "object" || isWireScalar(value)) return value;
60
69
  if (Array.isArray(value)) return raceAgainstAbort(Promise.all(value.map((v) => resolveValue(v, codecs, ctx))), signal, "encode");
61
70
  const entries = Object.entries(value);
62
71
  const resolved = await raceAgainstAbort(Promise.all(entries.map(([, val]) => resolveValue(val, codecs, ctx))), signal, "encode");
@@ -76,8 +85,7 @@ async function resolveValue(value, codecs, ctx) {
76
85
  */
77
86
  async function resolveDraftSlot(value, codecs, ctx) {
78
87
  if (value instanceof MongoParamRef) return resolveValue(value, codecs, ctx);
79
- if (value === null || typeof value !== "object") return value;
80
- if (value instanceof Date) return value;
88
+ if (value === null || typeof value !== "object" || isWireScalar(value)) return value;
81
89
  if (Array.isArray(value)) return raceAgainstAbort(Promise.all(value.map((v) => resolveDraftSlot(v, codecs, ctx))), ctx.signal, "encode");
82
90
  return resolveDraftDoc(blindCast(value), codecs, ctx);
83
91
  }
@@ -102,11 +110,19 @@ async function resolveDraftDoc(doc, codecs, ctx) {
102
110
  function paramRefLabel(ref, codecId) {
103
111
  return ref.name ?? codecId;
104
112
  }
113
+ /**
114
+ * Every encode failure names the parameter, or the field and collection when the ORM supplied them. A codec's own `RUNTIME.ENCODE_FAILED` keeps its code and details, with the label added; any other structured envelope and an `InternalError` pass through unchanged; everything else is wrapped in a `RUNTIME.ENCODE_FAILED` envelope. The original error is the `cause`.
115
+ */
105
116
  function wrapEncodeFailure(error, ref, codecId) {
106
- if (isStructuredError(error)) throw error;
117
+ if (isInternalError(error)) throw error;
118
+ const codecDetails = isStructuredError(error) ? error.meta : void 0;
119
+ if (isStructuredError(error) && error.code !== "RUNTIME.ENCODE_FAILED") throw error;
107
120
  const label = paramRefLabel(ref, codecId);
108
- const wrapped = runtimeError("RUNTIME.ENCODE_FAILED", `Failed to encode parameter ${label} with codec '${codecId}': ${error instanceof Error ? error.message : String(error)}`, {
121
+ const message = error instanceof Error ? error.message : String(error);
122
+ const wrapped = runtimeError("RUNTIME.ENCODE_FAILED", `Failed to encode ${ref.name !== void 0 && ref.collection !== void 0 ? `field ${ref.name} in collection '${ref.collection}'` : `parameter ${label}`} with codec '${codecId}': ${message}`, {
123
+ ...codecDetails,
109
124
  label,
125
+ ...ifDefined("collection", ref.collection),
110
126
  codec: codecId
111
127
  });
112
128
  wrapped.cause = error;
@@ -181,6 +197,7 @@ const aggExprLoweringVisitor = {
181
197
  }
182
198
  };
183
199
  function needsLiteralWrap(value) {
200
+ if (value instanceof MongoParamRef) return true;
184
201
  if (typeof value === "string" && value.startsWith("$")) return true;
185
202
  if (Array.isArray(value)) return value.some((v) => needsLiteralWrap(v));
186
203
  if (value !== null && typeof value === "object") return Object.entries(value).some(([k, v]) => k.startsWith("$") || needsLiteralWrap(v));
@@ -618,6 +635,7 @@ function lowerDdlCommand(command) {
618
635
  case "createCollection": return new CreateCollectionWireCommand(command.collection, command);
619
636
  case "createIndex": return new CreateIndexWireCommand(command.collection, keysToKeySpec(command.keys), command);
620
637
  case "dropCollection": return new DropCollectionWireCommand(command.collection);
638
+ case "renameCollection": return new RenameCollectionWireCommand(command.collection, command.to);
621
639
  case "dropIndex": return new DropIndexWireCommand(command.collection, command.name);
622
640
  case "collMod": return new CollModWireCommand(command.collection, command);
623
641
  // v8 ignore next 4
@@ -714,7 +732,8 @@ var MongoAdapterImpl = class {
714
732
  kind: "rawUpdateMany",
715
733
  collection: command.collection,
716
734
  filter: command.filter,
717
- update: command.update
735
+ update: command.update,
736
+ bypassDocumentValidation: command.bypassDocumentValidation ?? false
718
737
  };
719
738
  case "rawDeleteOne": return {
720
739
  kind: "rawDeleteOne",
@@ -772,7 +791,7 @@ var MongoAdapterImpl = class {
772
791
  case "rawInsertOne": return new InsertOneWireCommand(draft.collection, draft.document);
773
792
  case "rawInsertMany": return new InsertManyWireCommand(draft.collection, draft.documents);
774
793
  case "rawUpdateOne": return new UpdateOneWireCommand(draft.collection, draft.filter, draft.update);
775
- case "rawUpdateMany": return new UpdateManyWireCommand(draft.collection, draft.filter, draft.update);
794
+ case "rawUpdateMany": return new UpdateManyWireCommand(draft.collection, draft.filter, draft.update, false, draft.bypassDocumentValidation);
776
795
  case "rawDeleteOne": return new DeleteOneWireCommand(draft.collection, draft.filter);
777
796
  case "rawDeleteMany": return new DeleteManyWireCommand(draft.collection, draft.filter);
778
797
  case "rawFindOneAndUpdate": return new FindOneAndUpdateWireCommand(draft.collection, draft.filter, draft.update, draft.upsert, draft.sort, draft.returnDocument);
@@ -804,4 +823,4 @@ function createMongoAdapter() {
804
823
  //#endregion
805
824
  export { lowerStage as a, lowerPipeline as i, lowerAggExpr as n, lowerFilter as r, createMongoAdapter as t };
806
825
 
807
- //# sourceMappingURL=mongo-adapter-B2HEyX0b-CQt2HH_o.mjs.map
826
+ //# sourceMappingURL=mongo-adapter-Bo6ciURK-DIMJdC7y.mjs.map