@prisma/orm-target-mongo 8.0.0-rc.23-dev.9 → 8.0.0-rc.23-dev.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +2 -0
  2. package/dist/adapter.mjs +2 -2
  3. package/dist/adapter__control.mjs +1 -1
  4. package/dist/adapter__runtime.mjs +7 -2
  5. package/dist/adapter__runtime.mjs.map +1 -1
  6. package/dist/codec-ids-B8WIyai-.d.mts +25 -0
  7. package/dist/{codec-ids-BKQbXhZt.d.mts.map → codec-ids-B8WIyai-.d.mts.map} +1 -1
  8. package/dist/codec-ids-DZQsuh80-ywDzfnAg.mjs +25 -0
  9. package/dist/codec-ids-DZQsuh80-ywDzfnAg.mjs.map +1 -0
  10. package/dist/{codec-types-oKxM85p-.d.mts → codec-types-C6UDhw7l.d.mts} +37 -1
  11. package/dist/codec-types-C6UDhw7l.d.mts.map +1 -0
  12. package/dist/codecs-BbX2VMzN-Dm9db3Jz.mjs +620 -0
  13. package/dist/codecs-BbX2VMzN-Dm9db3Jz.mjs.map +1 -0
  14. package/dist/{control-CdHPs2QG.mjs → control-B77seMDK.mjs} +7 -4
  15. package/dist/control-B77seMDK.mjs.map +1 -0
  16. package/dist/{control-DfDVW_9x.mjs → control-CHr0ZjKM.mjs} +2 -2
  17. package/dist/{control-DfDVW_9x.mjs.map → control-CHr0ZjKM.mjs.map} +1 -1
  18. package/dist/{data-types-hoKLBrYZ-h9cAgbOy.mjs → data-types-Cq1kg82y-Vk7z6rnW.mjs} +88 -5
  19. package/dist/data-types-Cq1kg82y-Vk7z6rnW.mjs.map +1 -0
  20. package/dist/data-types-ozSM4YdB.d.mts +39 -0
  21. package/dist/data-types-ozSM4YdB.d.mts.map +1 -0
  22. package/dist/date-time-now-generators-fWUk_--7-BnCnC0d8.mjs +66 -0
  23. package/dist/date-time-now-generators-fWUk_--7-BnCnC0d8.mjs.map +1 -0
  24. package/dist/{descriptor-meta-_vnrMWD4-CXzRuo6u.mjs → descriptor-meta-CFsOxO6g-Ca8valmZ.mjs} +204 -20
  25. package/dist/descriptor-meta-CFsOxO6g-Ca8valmZ.mjs.map +1 -0
  26. package/dist/{descriptor-meta-runtime-M_DCE9pk-BltR3MLY.mjs → descriptor-meta-runtime-CBJIjp5R-DMQ9-3Hd.mjs} +4 -4
  27. package/dist/{descriptor-meta-runtime-M_DCE9pk-BltR3MLY.mjs.map → descriptor-meta-runtime-CBJIjp5R-DMQ9-3Hd.mjs.map} +1 -1
  28. package/dist/driver.mjs +1 -1
  29. package/dist/driver__control.mjs +1 -1
  30. package/dist/driver__runtime.mjs +1 -1
  31. package/dist/driver__runtime.mjs.map +1 -1
  32. package/dist/{migration-factories-CUyEIo5p-CXTwpgxe.mjs → migration-factories-oLRWgLGz-B9fWm8Wc.mjs} +3 -3
  33. package/dist/{migration-factories-CUyEIo5p-CXTwpgxe.mjs.map → migration-factories-oLRWgLGz-B9fWm8Wc.mjs.map} +1 -1
  34. package/dist/{mongo-adapter-RJ_YOxiK-yG_qHDyR.mjs → mongo-adapter-RJ_YOxiK-jlyFS6Wr.mjs} +3 -3
  35. package/dist/{mongo-adapter-RJ_YOxiK-yG_qHDyR.mjs.map → mongo-adapter-RJ_YOxiK-jlyFS6Wr.mjs.map} +1 -1
  36. package/dist/{mongo-driver-DGpvEBcg-DD5q-5iT.mjs → mongo-driver-CSDRQwak-j3pdkDuW.mjs} +3 -3
  37. package/dist/mongo-driver-CSDRQwak-j3pdkDuW.mjs.map +1 -0
  38. package/dist/{pack-BJLQkv5o.d.mts → pack-FzGKNW0Q.d.mts} +358 -38
  39. package/dist/pack-FzGKNW0Q.d.mts.map +1 -0
  40. package/dist/{prisma6-binding-BuMRLaNZ.mjs → prisma6-binding-BjKPGVql.mjs} +3 -3
  41. package/dist/{prisma6-binding-BuMRLaNZ.mjs.map → prisma6-binding-BjKPGVql.mjs.map} +1 -1
  42. package/dist/runtime-C-5ghims.d.mts +42 -0
  43. package/dist/runtime-C-5ghims.d.mts.map +1 -0
  44. package/dist/{runtime-Jc2oA31j.mjs → runtime-DyWNR1FZ.mjs} +2 -2
  45. package/dist/runtime-DyWNR1FZ.mjs.map +1 -0
  46. package/dist/target.d.mts +6 -6
  47. package/dist/target.mjs +8 -7
  48. package/dist/target__codec-ids.d.mts +2 -2
  49. package/dist/target__codec-ids.mjs +2 -2
  50. package/dist/target__codec-types.d.mts +1 -1
  51. package/dist/target__codecs.mjs +1 -1
  52. package/dist/target__control.mjs +1 -1
  53. package/dist/target__data-types.d.mts +2 -2
  54. package/dist/target__data-types.mjs +2 -2
  55. package/dist/target__migration.mjs +1 -1
  56. package/dist/target__pack.d.mts +2 -2
  57. package/dist/target__pack.mjs +1 -1
  58. package/dist/target__pack.mjs.map +1 -1
  59. package/dist/target__prisma6-binding.mjs +1 -1
  60. package/dist/target__runtime.d.mts +2 -2
  61. package/dist/target__runtime.mjs +3 -2
  62. package/package.json +17 -12
  63. package/dist/codec-ids-BKQbXhZt.d.mts +0 -18
  64. package/dist/codec-ids-WdrumsYA-CZVjuKW8.mjs +0 -18
  65. package/dist/codec-ids-WdrumsYA-CZVjuKW8.mjs.map +0 -1
  66. package/dist/codec-types-oKxM85p-.d.mts.map +0 -1
  67. package/dist/codecs-_QYfn0YT-BWZI19N1.mjs +0 -342
  68. package/dist/codecs-_QYfn0YT-BWZI19N1.mjs.map +0 -1
  69. package/dist/control-CdHPs2QG.mjs.map +0 -1
  70. package/dist/data-types-LShlnAUM.d.mts +0 -25
  71. package/dist/data-types-LShlnAUM.d.mts.map +0 -1
  72. package/dist/data-types-hoKLBrYZ-h9cAgbOy.mjs.map +0 -1
  73. package/dist/descriptor-meta-_vnrMWD4-CXzRuo6u.mjs.map +0 -1
  74. package/dist/mongo-driver-DGpvEBcg-DD5q-5iT.mjs.map +0 -1
  75. package/dist/pack-BJLQkv5o.d.mts.map +0 -1
  76. package/dist/runtime-DeUjc8oy.d.mts +0 -11
  77. package/dist/runtime-DeUjc8oy.d.mts.map +0 -1
  78. package/dist/runtime-Jc2oA31j.mjs.map +0 -1
@@ -0,0 +1,620 @@
1
+ import { _ as MONGO_STRING_CODEC_ID, a as MONGO_DATE_INSTANT_CODEC_ID, b as MONGO_VECTOR_CODEC_ID, c as MONGO_DATE_TEMPORAL_CODEC_ID, d as MONGO_DURATION_STRING_CODEC_ID, f as MONGO_INT32_CODEC_ID, g as MONGO_OBJECTID_CODEC_ID, h as MONGO_JSON_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_DECIMAL128_CODEC_ID, m as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DATE_INSTANT_STRING_CODEC_ID, p as MONGO_INT64_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_DATE_STRING_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_DOUBLE_CODEC_ID, v as MONGO_TIME_STRING_CODEC_ID, y as MONGO_TIME_TEMPORAL_CODEC_ID } from "./codec-ids-DZQsuh80-ywDzfnAg.mjs";
2
+ import { t as mongoTargetError } from "./mongo-target-errors-Btf3ML1w-QOtEG7EX.mjs";
3
+ import { $ as mongoVector, B as mongoDecimal128, C as int64Decode, D as int64NumberFromDigits, E as int64NumberEncode, F as mongoBson, G as mongoInt32, H as mongoDuration, I as mongoCalendarDate, J as mongoObjectId, K as mongoInt64, L as mongoCalendarDateText, M as isPlainObject, N as mongoBinary, O as int64NumberToJson, P as mongoBool, Q as mongoTimeText, S as int32ToJson, T as int64NumberDecode, U as mongoDurationText, V as mongoDouble, W as mongoInstantText, Y as mongoString, Z as mongoTime, _ as decimal128ToJson, a as booleanEncode, at as vectorEncode, b as encodeBsonValue, c as bsonTypeTag, d as dateEncode, f as dateToJson, h as decimal128Encode, i as binaryToBase64, it as stringEncode, j as isPlainArray, k as int64ToJson, l as child, m as decimal128Decode, n as binaryEncode, nt as objectIdToJson, o as bsonClassTag, ot as where, p as dbRefEntries, q as mongoJson, r as binaryFromBase64, rt as readBsonJson, s as bsonToJson, t as binaryDecode, tt as objectIdEncode, u as constructorName, v as decodeBsonValue, w as int64Encode, x as int32Encode, y as doubleEncode, z as mongoDate } from "./data-types-Cq1kg82y-Vk7z6rnW.mjs";
4
+ import { decimalTextBigintLiteral, decimalTextNumberLiteral, floatNumberLiteral, floatToJson, readJsonFloat, renderTsLiteral } from "@prisma/orm-framework/components/codec";
5
+ import { hasDigitsBelowAMillisecond, isValidDate } from "@prisma/orm-framework/type-implementations/date";
6
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
7
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
8
+ import { findTemporal } from "@prisma/orm-framework/type-implementations/temporal";
9
+ import { mongoCodec, mongoCodecDescriptor } from "@prisma/orm-family-mongo/codec";
10
+ import { describeValue, temporalFromText, temporalToText } from "@prisma/orm-framework/type-implementations/temporal-text";
11
+ //#region ../../../3-targets/mongo/1-target/dist/codecs-BbX2VMzN.mjs
12
+ const TEMPORAL_UNAVAILABLE_FIX = "Run on a runtime with Temporal available, install a Temporal polyfill before creating the client, or write the field as a convenience type at its default, which needs no Temporal: `DateTime` reads a JavaScript `Date`, and `Date`, `Time` and `Duration` read ISO 8601 strings.";
13
+ function errorTemporalUnavailable(codecId, operation) {
14
+ return mongoTargetError("RUNTIME.TEMPORAL_UNAVAILABLE", `Codec '${codecId}' cannot ${operation} a value because this runtime has no global Temporal implementation.`, {
15
+ why: "Temporal-backed codecs read and write their values through the global Temporal API, which this runtime does not provide.",
16
+ fix: TEMPORAL_UNAVAILABLE_FIX,
17
+ meta: {
18
+ codecId,
19
+ operation
20
+ }
21
+ });
22
+ }
23
+ function errorTemporalUnavailableForDefault(generatorId) {
24
+ return mongoTargetError("RUNTIME.TEMPORAL_UNAVAILABLE", `Mutation default generator '${generatorId}' cannot produce a value because this runtime has no global Temporal implementation.`, {
25
+ why: "The generator answers a Temporal-backed field, so the value it produces is a Temporal value, which this runtime cannot construct.",
26
+ fix: TEMPORAL_UNAVAILABLE_FIX,
27
+ meta: { generatorId }
28
+ });
29
+ }
30
+ function errorTemporalWrongType(codecId, temporalTag, stringType, received) {
31
+ return mongoTargetError("RUNTIME.ENCODE_FAILED", `Codec '${codecId}' encodes a ${temporalTag}, but received ${received}.`, {
32
+ why: "The codec writes the value a Temporal value names. A value of another type names none the field holds.",
33
+ fix: `Pass a ${temporalTag}, or author the field with its ${stringType} type to write ISO 8601 text.`,
34
+ meta: {
35
+ codecId,
36
+ temporalTag,
37
+ stringType,
38
+ received
39
+ }
40
+ });
41
+ }
42
+ function errorTemporalNonIsoCalendar(codecId, calendarId) {
43
+ return mongoTargetError("RUNTIME.ENCODE_FAILED", `Codec '${codecId}' accepts only the iso8601 calendar, but the value carries '${calendarId}'.`, {
44
+ why: "MongoDB stores no calendar alongside a date, so a non-ISO calendar would be discarded on write and the value would read back as a different date than the one authored.",
45
+ fix: "Convert the value with .withCalendar(\"iso8601\") before writing if the ISO projection is what you mean to store.",
46
+ meta: {
47
+ codecId,
48
+ calendarId
49
+ }
50
+ });
51
+ }
52
+ /** A date or time codec read a value from MongoDB that is not a value of its type, or that `Temporal` cannot hold. */
53
+ function errorDateTimeUnreadable(options) {
54
+ const { codecId, value, detail } = options;
55
+ return mongoTargetError("RUNTIME.DECODE_FAILED", `Codec '${codecId}' cannot read ${value}: ${detail}`, {
56
+ why: "MongoDB checks no form for a BSON date or string beyond its BSON type, so a document written outside Prisma can hold a value that is not a value of the field’s type.",
57
+ fix: "Rewrite the document in the form the field stores, or read the field with a type that holds what it stores, such as DateTime for a BSON date or String for a BSON string.",
58
+ meta: {
59
+ codecId,
60
+ value: value.slice(0, 100)
61
+ },
62
+ ...ifDefined("cause", options.cause)
63
+ });
64
+ }
65
+ /** A date or time codec was given a value that names no value its type stores, such as text with a digit below a millisecond. */
66
+ function errorDateTimeUnwritable(options) {
67
+ const { codecId, received, detail } = options;
68
+ return mongoTargetError("RUNTIME.ENCODE_FAILED", `Codec '${codecId}' cannot write ${received}. ${detail}`, {
69
+ why: "A BSON date holds milliseconds, a calendar date is stored at midnight UTC, and a time of day as a string with three fraction digits. A value that form cannot hold is refused rather than changed.",
70
+ fix: "Write a value the field holds, as the message shows.",
71
+ meta: {
72
+ codecId,
73
+ received: received.slice(0, 100)
74
+ },
75
+ ...ifDefined("cause", options.cause)
76
+ });
77
+ }
78
+ /**
79
+ * The `Temporal` to use: the runtime's own when it has one, else the fallback. Throws
80
+ * `RUNTIME.TEMPORAL_UNAVAILABLE` when there is neither.
81
+ */
82
+ function requireTemporal(meta) {
83
+ const temporal = findTemporal();
84
+ if (temporal !== void 0) return temporal;
85
+ throw "generatorId" in meta ? errorTemporalUnavailableForDefault(meta.generatorId) : errorTemporalUnavailable(meta.codecId, meta.operation);
86
+ }
87
+ const MILLISECONDS_PER_DAY = 864e5;
88
+ function messageOf(cause) {
89
+ return cause instanceof Error ? cause.message : String(cause);
90
+ }
91
+ /** The text a write stores for `value`, in the form `stored` writes; a value `stored` refuses is refused as `RUNTIME.ENCODE_FAILED`. */
92
+ function storedTextForWrite(codecId, value, stored) {
93
+ if (typeof value !== "string") throw errorDateTimeUnwritable({
94
+ codecId,
95
+ received: describeValue(value),
96
+ detail: "It writes ISO 8601 text."
97
+ });
98
+ try {
99
+ return stored(value);
100
+ } catch (cause) {
101
+ throw errorDateTimeUnwritable({
102
+ codecId,
103
+ received: JSON.stringify(value),
104
+ detail: messageOf(cause),
105
+ cause
106
+ });
107
+ }
108
+ }
109
+ /** The stored form of a BSON string MongoDB returned, as `stored` reads it; text `stored` refuses is refused as `RUNTIME.DECODE_FAILED`. */
110
+ function storedTextFromWire(codecId, wire, stored) {
111
+ if (typeof wire !== "string") throw errorDateTimeUnreadable({
112
+ codecId,
113
+ value: String(wire),
114
+ detail: `MongoDB returned ${describeValue(wire)}, not a string.`
115
+ });
116
+ try {
117
+ return stored(wire);
118
+ } catch (cause) {
119
+ throw errorDateTimeUnreadable({
120
+ codecId,
121
+ value: JSON.stringify(wire),
122
+ detail: messageOf(cause),
123
+ cause
124
+ });
125
+ }
126
+ }
127
+ /** The BSON date MongoDB returned, as the `Date` the driver reads it as. */
128
+ function dateFromWire(codecId, wire) {
129
+ if (isValidDate(wire)) return wire;
130
+ throw errorDateTimeUnreadable({
131
+ codecId,
132
+ value: String(wire),
133
+ detail: `MongoDB returned ${describeValue(wire)}, not a BSON date.`
134
+ });
135
+ }
136
+ /** Whether `date` is at midnight UTC, the form a calendar date is stored in. */
137
+ function isAtMidnightUtc(date) {
138
+ return date.getTime() % MILLISECONDS_PER_DAY === 0;
139
+ }
140
+ /** The date part of `date` in UTC, as in `2024-02-29`, for a `Date` at midnight UTC. */
141
+ function calendarDateTextOf(date) {
142
+ const iso = date.toISOString();
143
+ return iso.slice(0, iso.indexOf("T"));
144
+ }
145
+ /** The calendar date a BSON date at midnight UTC holds, as in `2024-02-29`. A BSON date at another time is refused, so a field written as an instant is never read as a date. */
146
+ function calendarDateFromWire(codecId, wire) {
147
+ const date = dateFromWire(codecId, wire);
148
+ if (isAtMidnightUtc(date)) return calendarDateTextOf(date);
149
+ throw errorDateTimeUnreadable({
150
+ codecId,
151
+ value: date.toISOString(),
152
+ detail: "a calendar date is stored as a BSON date at midnight UTC. A field that holds a time of day is a DateTime."
153
+ });
154
+ }
155
+ /** The BSON date at midnight UTC that stores the calendar date `text`, as in `2024-02-29`. */
156
+ function midnightUtcOf(text) {
157
+ return /* @__PURE__ */ new Date(`${text}T00:00:00.000Z`);
158
+ }
159
+ /** The Temporal value that stored text names, read with `parse`. */
160
+ function temporalFromStoredText(identity, text, parse) {
161
+ const read = temporalFromText(requireTemporal({
162
+ codecId: identity.codecId,
163
+ operation: "decode"
164
+ }), text, parse);
165
+ if (read.kind === "unreadable") throw errorDateTimeUnreadable({
166
+ codecId: identity.codecId,
167
+ value: JSON.stringify(text),
168
+ detail: `${identity.temporalTag} cannot hold it: ${read.detail}. Use ${identity.stringType} to read the field as text.`,
169
+ cause: read.cause
170
+ });
171
+ return read.value;
172
+ }
173
+ /** The text a write stores for a Temporal value, in the form `stored` writes. A value of another kind, in a calendar other than ISO 8601, or with digits below a millisecond is refused. */
174
+ function storedTextOfTemporal(identity, value, stored) {
175
+ const encoded = temporalToText(value, identity.temporalTag);
176
+ switch (encoded.kind) {
177
+ case "wrong-type": throw errorTemporalWrongType(identity.codecId, identity.temporalTag, identity.stringType, encoded.received);
178
+ case "non-iso-calendar": throw errorTemporalNonIsoCalendar(identity.codecId, encoded.calendarId);
179
+ case "text":
180
+ if (hasDigitsBelowAMillisecond(encoded.text)) throw errorDateTimeUnwritable({
181
+ codecId: identity.codecId,
182
+ received: `the ${identity.temporalTag} ${encoded.text}`,
183
+ detail: "It has digits below a millisecond, and the field holds milliseconds. Round it first, as in value.round({ smallestUnit: 'millisecond', roundingMode: 'trunc' })."
184
+ });
185
+ return storedTextForWrite(identity.codecId, encoded.text, stored);
186
+ }
187
+ }
188
+ const INSTANT = {
189
+ codecId: MONGO_DATE_INSTANT_CODEC_ID,
190
+ temporalTag: "Temporal.Instant",
191
+ stringType: "DateInstantString"
192
+ };
193
+ const PLAIN_DATE = {
194
+ codecId: MONGO_DATE_TEMPORAL_CODEC_ID,
195
+ temporalTag: "Temporal.PlainDate",
196
+ stringType: "DateString"
197
+ };
198
+ const PLAIN_TIME = {
199
+ codecId: MONGO_TIME_TEMPORAL_CODEC_ID,
200
+ temporalTag: "Temporal.PlainTime",
201
+ stringType: "TimeString"
202
+ };
203
+ const instantText = (value) => storedTextOfTemporal(INSTANT, value, mongoInstantText);
204
+ const plainDateText = (value) => storedTextOfTemporal(PLAIN_DATE, value, mongoCalendarDateText);
205
+ const plainTimeText = (value) => storedTextOfTemporal(PLAIN_TIME, value, mongoTimeText);
206
+ /** An instant, stored as a BSON date and read as `Temporal.Instant`. */
207
+ const mongoDateInstantCodec = mongoCodec({
208
+ typeId: MONGO_DATE_INSTANT_CODEC_ID,
209
+ dataType: mongoDate,
210
+ fromWire: (wire) => temporalFromStoredText(INSTANT, dateFromWire(MONGO_DATE_INSTANT_CODEC_ID, wire).toISOString(), (temporal, text) => temporal.Instant.from(text)),
211
+ toWire: (value) => new Date(instantText(value)),
212
+ toDataTypeValue: (value) => mongoDate.valueFrom(instantText(value), {}),
213
+ fromDataTypeValue: (value) => temporalFromStoredText(INSTANT, value.value, (temporal, text) => temporal.Instant.from(text))
214
+ });
215
+ /** An instant, stored as a BSON date and read as the text `Date.toISOString()` writes, `2024-01-01T00:00:00.000Z`. A write takes ISO 8601 text with any UTC offset. */
216
+ const mongoDateInstantStringCodec = mongoCodec({
217
+ typeId: MONGO_DATE_INSTANT_STRING_CODEC_ID,
218
+ dataType: mongoDate,
219
+ fromWire: (wire) => dateFromWire(MONGO_DATE_INSTANT_STRING_CODEC_ID, wire).toISOString(),
220
+ toWire: (value) => new Date(storedTextForWrite(MONGO_DATE_INSTANT_STRING_CODEC_ID, value, mongoInstantText)),
221
+ toDataTypeValue: (value) => mongoDate.valueFrom(storedTextForWrite(MONGO_DATE_INSTANT_STRING_CODEC_ID, value, mongoInstantText), {}),
222
+ fromDataTypeValue: (value) => value.value
223
+ });
224
+ /** A calendar date, stored as a BSON date at midnight UTC and read as `2024-02-29`. */
225
+ const mongoDateStringCodec = mongoCodec({
226
+ typeId: MONGO_DATE_STRING_CODEC_ID,
227
+ dataType: mongoCalendarDate,
228
+ fromWire: (wire) => calendarDateFromWire(MONGO_DATE_STRING_CODEC_ID, wire),
229
+ toWire: (value) => midnightUtcOf(storedTextForWrite(MONGO_DATE_STRING_CODEC_ID, value, mongoCalendarDateText)),
230
+ toDataTypeValue: (value) => mongoCalendarDate.valueFrom(storedTextForWrite(MONGO_DATE_STRING_CODEC_ID, value, mongoCalendarDateText), {}),
231
+ fromDataTypeValue: (value) => value.value
232
+ });
233
+ /** A calendar date, stored as a BSON date at midnight UTC and read as `Temporal.PlainDate`. */
234
+ const mongoDateTemporalCodec = mongoCodec({
235
+ typeId: MONGO_DATE_TEMPORAL_CODEC_ID,
236
+ dataType: mongoCalendarDate,
237
+ fromWire: (wire) => temporalFromStoredText(PLAIN_DATE, calendarDateFromWire(MONGO_DATE_TEMPORAL_CODEC_ID, wire), (temporal, text) => temporal.PlainDate.from(text)),
238
+ toWire: (value) => midnightUtcOf(plainDateText(value)),
239
+ toDataTypeValue: (value) => mongoCalendarDate.valueFrom(plainDateText(value), {}),
240
+ fromDataTypeValue: (value) => temporalFromStoredText(PLAIN_DATE, value.value, (temporal, text) => temporal.PlainDate.from(text))
241
+ });
242
+ /** A time of day, stored as a BSON string and read as that string, `09:30:00.000`. A write pads a string with fewer fraction digits to three. */
243
+ const mongoTimeStringCodec = mongoCodec({
244
+ typeId: MONGO_TIME_STRING_CODEC_ID,
245
+ dataType: mongoTime,
246
+ fromWire: (wire) => storedTextFromWire(MONGO_TIME_STRING_CODEC_ID, wire, mongoTimeText),
247
+ toWire: (value) => storedTextForWrite(MONGO_TIME_STRING_CODEC_ID, value, mongoTimeText),
248
+ toDataTypeValue: (value) => mongoTime.valueFrom(storedTextForWrite(MONGO_TIME_STRING_CODEC_ID, value, mongoTimeText), {}),
249
+ fromDataTypeValue: (value) => value.value
250
+ });
251
+ /** A time of day, stored as a BSON string, `09:30:00.000`, and read as `Temporal.PlainTime`. */
252
+ const mongoTimeTemporalCodec = mongoCodec({
253
+ typeId: MONGO_TIME_TEMPORAL_CODEC_ID,
254
+ dataType: mongoTime,
255
+ fromWire: (wire) => temporalFromStoredText(PLAIN_TIME, storedTextFromWire(MONGO_TIME_TEMPORAL_CODEC_ID, wire, mongoTimeText), (temporal, text) => temporal.PlainTime.from(text)),
256
+ toWire: (value) => plainTimeText(value),
257
+ toDataTypeValue: (value) => mongoTime.valueFrom(plainTimeText(value), {}),
258
+ fromDataTypeValue: (value) => temporalFromStoredText(PLAIN_TIME, value.value, (temporal, text) => temporal.PlainTime.from(text))
259
+ });
260
+ /** A length of time, stored as a BSON string and read as the ISO 8601 duration it was written as, `PT1H30M`. */
261
+ const mongoDurationStringCodec = mongoCodec({
262
+ typeId: MONGO_DURATION_STRING_CODEC_ID,
263
+ dataType: mongoDuration,
264
+ fromWire: (wire) => storedTextFromWire(MONGO_DURATION_STRING_CODEC_ID, wire, mongoDurationText),
265
+ toWire: (value) => storedTextForWrite(MONGO_DURATION_STRING_CODEC_ID, value, mongoDurationText),
266
+ fromDataTypeValue: (value) => value.value
267
+ });
268
+ const BSON_TYPE_BY_TAG = {
269
+ ObjectId: "objectId",
270
+ Decimal128: "decimal",
271
+ Binary: "binData",
272
+ BSONRegExp: "regex",
273
+ Timestamp: "timestamp",
274
+ BSONSymbol: "symbol",
275
+ Code: "javascript",
276
+ MinKey: "minKey",
277
+ MaxKey: "maxKey"
278
+ };
279
+ const NOT_FINITE_FIX = "JSON has no NaN or Infinity; store null or a string, or declare the field Bson.";
280
+ const BSON_FIX = "Declare the field Bson to store BSON values.";
281
+ const PLAIN_VALUE_FIX = "Convert it to a plain object or array.";
282
+ const ENCODE_FIX_BY_RECEIVED = {
283
+ Date: "Store the date as an ISO 8601 string, or declare the field Bson.",
284
+ bigint: "Store it as a number in the safe-integer range or as decimal text, or declare the field Int64 or Bson.",
285
+ NaN: NOT_FINITE_FIX,
286
+ Infinity: NOT_FINITE_FIX,
287
+ "-Infinity": NOT_FINITE_FIX,
288
+ undefined: "Leave the key out, or store null.",
289
+ Uint8Array: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
290
+ Buffer: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
291
+ Binary: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
292
+ ObjectId: "Store its hex string, or declare the field ObjectId or Bson.",
293
+ Long: "Store a number in the safe-integer range or decimal text, or declare the field Int64 or Bson.",
294
+ Decimal128: "Store the decimal text, or declare the field Decimal128 or Bson.",
295
+ Int32: "Pass a plain number.",
296
+ Double: "Pass a plain number.",
297
+ RegExp: "Store the pattern as a string, or declare the field Bson.",
298
+ BSONRegExp: "Store the pattern as a string, or declare the field Bson.",
299
+ symbol: "Store a string instead.",
300
+ function: "Store data, not a function.",
301
+ "circular reference": "Remove the cycle; a JSON value is a tree.",
302
+ "sparse array hole": "Fill the hole with null.",
303
+ DBRef: "Write it as a { $ref, $id } document instead."
304
+ };
305
+ function encodeFix(received) {
306
+ return ENCODE_FIX_BY_RECEIVED[received] ?? (Object.hasOwn(BSON_TYPE_BY_TAG, received) ? BSON_FIX : PLAIN_VALUE_FIX);
307
+ }
308
+ function encodeRefused(received, path) {
309
+ throw mongoTargetError("RUNTIME.ENCODE_FAILED", `${MONGO_JSON_CODEC_ID} value must be a JSON value; received ${received} at ${where(path)}. ${encodeFix(received)}`, { meta: {
310
+ codecId: MONGO_JSON_CODEC_ID,
311
+ received,
312
+ valuePath: path
313
+ } });
314
+ }
315
+ function describeNonJson(value) {
316
+ if (value === null || typeof value === "string" || typeof value === "boolean") return void 0;
317
+ if (typeof value === "number") return Number.isFinite(value) ? void 0 : String(value);
318
+ if (typeof value !== "object") return typeof value;
319
+ const tag = bsonTypeTag(value);
320
+ if (tag !== void 0) return tag;
321
+ if (value instanceof Date) return "Date";
322
+ if (isPlainArray(value)) return void 0;
323
+ return isPlainObject(value) ? void 0 : constructorName(value);
324
+ }
325
+ function assertJsonValue(value, path, ancestors) {
326
+ const received = describeNonJson(value);
327
+ if (received !== void 0) encodeRefused(received, path);
328
+ if (typeof value !== "object" || value === null) return;
329
+ if (ancestors.has(value)) encodeRefused("circular reference", path);
330
+ ancestors.add(value);
331
+ if (Array.isArray(value)) for (let index = 0; index < value.length; index++) {
332
+ if (!(index in value)) encodeRefused("sparse array hole", child(path, index));
333
+ assertJsonValue(value[index], child(path, index), ancestors);
334
+ }
335
+ else for (const [key, entry] of Object.entries(value)) assertJsonValue(entry, child(path, key), ancestors);
336
+ ancestors.delete(value);
337
+ }
338
+ /**
339
+ * 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.
340
+ */
341
+ function encodeJsonValue(value) {
342
+ assertJsonValue(value, "", /* @__PURE__ */ new Set());
343
+ return value;
344
+ }
345
+ function decodeRefused(bsonType, path) {
346
+ throw mongoTargetError("RUNTIME.DECODE_FAILED", `${MONGO_JSON_CODEC_ID} wire value contains a non-JSON BSON ${bsonType} at ${where(path)}`, { meta: {
347
+ codecId: MONGO_JSON_CODEC_ID,
348
+ received: bsonType,
349
+ valuePath: path
350
+ } });
351
+ }
352
+ function safeLong(value, path) {
353
+ const number = Number(value);
354
+ return Number.isSafeInteger(number) && BigInt(number) === value ? number : decodeRefused("long", path);
355
+ }
356
+ function finiteDouble(value, path) {
357
+ if (Number.isFinite(value)) return value;
358
+ const received = String(value);
359
+ throw mongoTargetError("RUNTIME.DECODE_FAILED", `${MONGO_JSON_CODEC_ID} wire value contains ${received} at ${where(path)}; a JSON number cannot be NaN or Infinity`, { meta: {
360
+ codecId: MONGO_JSON_CODEC_ID,
361
+ received,
362
+ valuePath: path
363
+ } });
364
+ }
365
+ function decodeEntries(entries, path) {
366
+ return Object.fromEntries(entries.map(([key, entry]) => [key, decodeValue(entry, child(path, key))]));
367
+ }
368
+ function decodeTagged(value, tag, path) {
369
+ switch (tag) {
370
+ case "DBRef": return decodeEntries(dbRefEntries(value), path);
371
+ case "Long": return safeLong(blindCast(value).toBigInt(), path);
372
+ case "Int32":
373
+ case "Double": return finiteDouble(Number(value.valueOf()), path);
374
+ }
375
+ return decodeRefused(BSON_TYPE_BY_TAG[tag] ?? tag, path);
376
+ }
377
+ function decodeValue(value, path) {
378
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
379
+ if (typeof value === "number") return finiteDouble(value, path);
380
+ if (typeof value === "bigint") return safeLong(value, path);
381
+ if (typeof value === "undefined") return decodeRefused("undefined", path);
382
+ if (typeof value === "symbol") return decodeRefused("symbol", path);
383
+ if (typeof value === "function") return decodeRefused("javascript", path);
384
+ const tag = bsonClassTag(value);
385
+ if (tag !== void 0) return decodeTagged(value, tag, path);
386
+ if (value instanceof Date) return decodeRefused("date", path);
387
+ if (value instanceof RegExp) return decodeRefused("regex", path);
388
+ if (value instanceof Uint8Array) return decodeRefused("binData", path);
389
+ if (Array.isArray(value)) {
390
+ const decoded = value.map((entry, index) => decodeValue(entry, child(path, index)));
391
+ return decoded.some((entry, index) => entry !== value[index]) ? decoded : value;
392
+ }
393
+ if (!isPlainObject(value)) return decodeRefused(constructorName(value), path);
394
+ const entries = Object.entries(value);
395
+ const decoded = decodeEntries(entries, path);
396
+ return entries.some(([key, entry]) => decoded[key] !== entry) ? decoded : blindCast(value);
397
+ }
398
+ /**
399
+ * 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.
400
+ */
401
+ function decodeJsonValue(wire) {
402
+ return decodeValue(wire, "");
403
+ }
404
+ const mongoObjectIdCodec = mongoCodec({
405
+ typeId: MONGO_OBJECTID_CODEC_ID,
406
+ dataType: mongoObjectId,
407
+ fromWire: (wire) => wire.toHexString(),
408
+ toWire: (value) => objectIdEncode(MONGO_OBJECTID_CODEC_ID, value),
409
+ toDataTypeValue: (value) => mongoObjectId.valueFrom(objectIdToJson(MONGO_OBJECTID_CODEC_ID, value), {}),
410
+ fromDataTypeValue: (value) => value.value
411
+ });
412
+ const mongoStringCodec = mongoCodec({
413
+ typeId: MONGO_STRING_CODEC_ID,
414
+ dataType: mongoString,
415
+ fromWire: (wire) => wire,
416
+ toWire: (value) => stringEncode(MONGO_STRING_CODEC_ID, value),
417
+ fromDataTypeValue: (value) => value.value
418
+ });
419
+ const mongoDoubleCodec = mongoCodec({
420
+ typeId: MONGO_DOUBLE_CODEC_ID,
421
+ dataType: mongoDouble,
422
+ fromWire: (wire) => Number(wire),
423
+ toWire: (value) => doubleEncode(MONGO_DOUBLE_CODEC_ID, value),
424
+ toDataTypeValue: (value) => mongoDouble.valueFrom(floatToJson(value), {}),
425
+ fromDataTypeValue: (value) => readJsonFloat(MONGO_DOUBLE_CODEC_ID, value.value)
426
+ });
427
+ const mongoInt32Codec = mongoCodec({
428
+ typeId: MONGO_INT32_CODEC_ID,
429
+ dataType: mongoInt32,
430
+ fromWire: (wire) => wire,
431
+ toWire: (value) => int32Encode(MONGO_INT32_CODEC_ID, value),
432
+ toDataTypeValue: (value) => mongoInt32.valueFrom(int32ToJson(MONGO_INT32_CODEC_ID, value), {}),
433
+ fromDataTypeValue: (value) => value.value
434
+ });
435
+ const mongoBooleanCodec = mongoCodec({
436
+ typeId: MONGO_BOOLEAN_CODEC_ID,
437
+ dataType: mongoBool,
438
+ fromWire: (wire) => wire,
439
+ toWire: (value) => booleanEncode(MONGO_BOOLEAN_CODEC_ID, value),
440
+ fromDataTypeValue: (value) => value.value
441
+ });
442
+ const mongoDateCodec = mongoCodec({
443
+ typeId: MONGO_DATE_CODEC_ID,
444
+ dataType: mongoDate,
445
+ fromWire: (wire) => wire,
446
+ toWire: (value) => dateEncode(MONGO_DATE_CODEC_ID, value),
447
+ toDataTypeValue: (value) => mongoDate.valueFrom(dateToJson(MONGO_DATE_CODEC_ID, value), {}),
448
+ fromDataTypeValue: (value) => new Date(value.value)
449
+ });
450
+ /** The vector codec for a column of `mongo/vector` with `params`. The dimension reaches only the TypeScript type `Vector<n>`. */
451
+ function vectorCodec(params) {
452
+ return mongoCodec({
453
+ typeId: MONGO_VECTOR_CODEC_ID,
454
+ dataType: mongoVector,
455
+ ...ifDefined("params", params),
456
+ fromWire: (wire) => wire,
457
+ toWire: (value) => vectorEncode(MONGO_VECTOR_CODEC_ID, value),
458
+ fromDataTypeValue: (value) => value.value
459
+ });
460
+ }
461
+ const mongoVectorCodec = vectorCodec();
462
+ /**
463
+ * 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.
464
+ */
465
+ const mongoInt64Codec = mongoCodec({
466
+ typeId: MONGO_INT64_CODEC_ID,
467
+ dataType: mongoInt64,
468
+ fromWire: (wire) => int64Decode(MONGO_INT64_CODEC_ID, wire),
469
+ toWire: (value) => int64Encode(MONGO_INT64_CODEC_ID, value),
470
+ toDataTypeValue: (value) => mongoInt64.valueFrom(int64ToJson(MONGO_INT64_CODEC_ID, value), {}),
471
+ fromDataTypeValue: (value) => BigInt(value.value)
472
+ });
473
+ /**
474
+ * 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.
475
+ */
476
+ const mongoInt64NumberCodec = mongoCodec({
477
+ typeId: MONGO_INT64_NUMBER_CODEC_ID,
478
+ dataType: mongoInt64,
479
+ fromWire: (wire) => int64NumberDecode(MONGO_INT64_NUMBER_CODEC_ID, wire),
480
+ toWire: (value) => int64NumberEncode(MONGO_INT64_NUMBER_CODEC_ID, value),
481
+ toDataTypeValue: (value) => mongoInt64.valueFrom(int64NumberToJson(MONGO_INT64_NUMBER_CODEC_ID, value), {}),
482
+ fromDataTypeValue: (value) => int64NumberFromDigits(MONGO_INT64_NUMBER_CODEC_ID, value.value)
483
+ });
484
+ /**
485
+ * A BSON `decimal`. The application value and its stored form are the same decimal text, written without an exponent.
486
+ */
487
+ const mongoDecimal128Codec = mongoCodec({
488
+ typeId: MONGO_DECIMAL128_CODEC_ID,
489
+ dataType: mongoDecimal128,
490
+ fromWire: (wire) => decimal128Decode(MONGO_DECIMAL128_CODEC_ID, wire),
491
+ toWire: (value) => decimal128Encode(MONGO_DECIMAL128_CODEC_ID, value),
492
+ toDataTypeValue: (value) => mongoDecimal128.valueFrom(decimal128ToJson(MONGO_DECIMAL128_CODEC_ID, value), {}),
493
+ fromDataTypeValue: (value) => value.value
494
+ });
495
+ /**
496
+ * BSON `binData`. The application value is a `Uint8Array`; its stored form is unwrapped base64.
497
+ */
498
+ const mongoBinaryCodec = mongoCodec({
499
+ typeId: MONGO_BINARY_CODEC_ID,
500
+ dataType: mongoBinary,
501
+ fromWire: (wire) => binaryDecode(MONGO_BINARY_CODEC_ID, wire),
502
+ toWire: (value) => binaryEncode(MONGO_BINARY_CODEC_ID, value),
503
+ toDataTypeValue: (value) => mongoBinary.valueFrom(binaryToBase64(value), {}),
504
+ fromDataTypeValue: (value) => binaryFromBase64(value.value)
505
+ });
506
+ /**
507
+ * 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.
508
+ */
509
+ const mongoJsonCodec = mongoCodec({
510
+ typeId: MONGO_JSON_CODEC_ID,
511
+ dataType: mongoJson,
512
+ fromWire: (wire) => decodeJsonValue(wire),
513
+ toWire: (value) => encodeJsonValue(value)
514
+ });
515
+ /**
516
+ * 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`.
517
+ */
518
+ const mongoBsonCodec = mongoCodec({
519
+ typeId: MONGO_BSON_CODEC_ID,
520
+ dataType: mongoBson,
521
+ fromWire: (wire) => decodeBsonValue(wire),
522
+ toWire: (value) => encodeBsonValue(value),
523
+ toDataTypeValue: (value) => mongoBson.valueFrom(bsonToJson(value), {}),
524
+ fromDataTypeValue: (value) => readBsonJson(MONGO_BSON_CODEC_ID, value.value)
525
+ });
526
+ /**
527
+ * 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).
528
+ */
529
+ const mongoCodecDescriptors = [
530
+ mongoCodecDescriptor(mongoObjectIdCodec, { traits: ["equality"] }),
531
+ mongoCodecDescriptor(mongoStringCodec, {
532
+ traits: [
533
+ "equality",
534
+ "order",
535
+ "textual"
536
+ ],
537
+ renderValueLiteral: renderTsLiteral
538
+ }),
539
+ mongoCodecDescriptor(mongoDoubleCodec, {
540
+ traits: [
541
+ "equality",
542
+ "order",
543
+ "numeric"
544
+ ],
545
+ renderValueLiteral: floatNumberLiteral
546
+ }),
547
+ mongoCodecDescriptor(mongoInt32Codec, {
548
+ traits: [
549
+ "equality",
550
+ "order",
551
+ "numeric"
552
+ ],
553
+ renderValueLiteral: renderTsLiteral
554
+ }),
555
+ mongoCodecDescriptor(mongoBooleanCodec, {
556
+ traits: ["equality", "boolean"],
557
+ renderValueLiteral: renderTsLiteral
558
+ }),
559
+ mongoCodecDescriptor(mongoDateCodec, { traits: ["equality", "order"] }),
560
+ mongoCodecDescriptor(mongoVectorCodec, {
561
+ traits: ["equality"],
562
+ withParams: vectorCodec
563
+ }),
564
+ mongoCodecDescriptor(mongoInt64Codec, {
565
+ traits: [
566
+ "equality",
567
+ "order",
568
+ "numeric"
569
+ ],
570
+ renderValueLiteral: decimalTextBigintLiteral
571
+ }),
572
+ mongoCodecDescriptor(mongoInt64NumberCodec, {
573
+ traits: [
574
+ "equality",
575
+ "order",
576
+ "numeric"
577
+ ],
578
+ renderValueLiteral: decimalTextNumberLiteral
579
+ }),
580
+ mongoCodecDescriptor(mongoDecimal128Codec, {
581
+ traits: [
582
+ "equality",
583
+ "order",
584
+ "numeric"
585
+ ],
586
+ keepsWrittenForm: true
587
+ }),
588
+ mongoCodecDescriptor(mongoBinaryCodec, { traits: ["equality"] }),
589
+ mongoCodecDescriptor(mongoJsonCodec, { traits: [] }),
590
+ mongoCodecDescriptor(mongoBsonCodec, { traits: [] }),
591
+ mongoCodecDescriptor(mongoDateInstantCodec, { traits: ["equality", "order"] }),
592
+ mongoCodecDescriptor(mongoDateInstantStringCodec, {
593
+ traits: ["equality", "order"],
594
+ renderValueLiteral: renderTsLiteral
595
+ }),
596
+ mongoCodecDescriptor(mongoDateStringCodec, {
597
+ traits: ["equality", "order"],
598
+ renderValueLiteral: renderTsLiteral
599
+ }),
600
+ mongoCodecDescriptor(mongoDateTemporalCodec, { traits: ["equality", "order"] }),
601
+ mongoCodecDescriptor(mongoTimeStringCodec, {
602
+ traits: ["equality", "order"],
603
+ renderValueLiteral: renderTsLiteral
604
+ }),
605
+ mongoCodecDescriptor(mongoTimeTemporalCodec, { traits: ["equality", "order"] }),
606
+ mongoCodecDescriptor(mongoDurationStringCodec, {
607
+ traits: ["equality"],
608
+ renderValueLiteral: renderTsLiteral
609
+ })
610
+ ];
611
+ /**
612
+ * Lookup descriptor metadata by codec id — used by tests and for descriptor-side reads of static metadata.
613
+ */
614
+ function mongoDescriptorById(codecId) {
615
+ return mongoCodecDescriptors.find((d) => d.codecId === codecId);
616
+ }
617
+ //#endregion
618
+ export { mongoDescriptorById as n, requireTemporal as r, mongoCodecDescriptors as t };
619
+
620
+ //# sourceMappingURL=codecs-BbX2VMzN-Dm9db3Jz.mjs.map