@prisma/orm-target-mongo 8.0.0-rc.18-dev.16 → 8.0.0-rc.18-dev.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.mjs +1 -1
- package/dist/adapter.mjs.map +1 -1
- package/dist/adapter__control.mjs +2 -2
- package/dist/adapter__control.mjs.map +1 -1
- package/dist/adapter__runtime.mjs +2 -2
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/{codecs-CXPz3PFI.d.mts → codecs-6K6jAnDf.d.mts} +3 -3
- package/dist/{codecs-CXPz3PFI.d.mts.map → codecs-6K6jAnDf.d.mts.map} +1 -1
- package/dist/codecs-C2G2gCgE-BF_laFUO.mjs +401 -0
- package/dist/codecs-C2G2gCgE-BF_laFUO.mjs.map +1 -0
- package/dist/{control-L7CfVM6Q.mjs → control-BmURXF7w.mjs} +3 -3
- package/dist/{control-L7CfVM6Q.mjs.map → control-BmURXF7w.mjs.map} +1 -1
- package/dist/{data-types-CcyIYfyC.d.mts → data-types-BS2Wy4k-.d.mts} +2 -2
- package/dist/{data-types-CcyIYfyC.d.mts.map → data-types-BS2Wy4k-.d.mts.map} +1 -1
- package/dist/data-types-CfdzqGSQ-NIDeT9x3.mjs +561 -0
- package/dist/data-types-CfdzqGSQ-NIDeT9x3.mjs.map +1 -0
- package/dist/{descriptor-meta-BtglG_aY-DhbxL8Gw.mjs → descriptor-meta-Da1K6eGI-CuPZuUef.mjs} +3 -3
- package/dist/{descriptor-meta-BtglG_aY-DhbxL8Gw.mjs.map → descriptor-meta-Da1K6eGI-CuPZuUef.mjs.map} +1 -1
- package/dist/{descriptor-meta-runtime-CwIqqZ8J-C3UNM2K8.mjs → descriptor-meta-runtime-CVlbbuVd-CECirMWv.mjs} +4 -4
- package/dist/{descriptor-meta-runtime-CwIqqZ8J-C3UNM2K8.mjs.map → descriptor-meta-runtime-CVlbbuVd-CECirMWv.mjs.map} +1 -1
- package/dist/driver.mjs +1 -1
- package/dist/driver__control.mjs +1 -1
- package/dist/driver__control.mjs.map +1 -1
- package/dist/{mongo-adapter-DWNaz2UT-HiI8mJ7J.mjs → mongo-adapter-Bo6ciURK-CtwxEEEl.mjs} +6 -6
- package/dist/{mongo-adapter-DWNaz2UT-HiI8mJ7J.mjs.map → mongo-adapter-Bo6ciURK-CtwxEEEl.mjs.map} +1 -1
- package/dist/{mongo-driver-1sSQfkdk-D4ft_SLH.mjs → mongo-driver-X3390_vm-Dh9WXgAd.mjs} +3 -3
- package/dist/{mongo-driver-1sSQfkdk-D4ft_SLH.mjs.map → mongo-driver-X3390_vm-Dh9WXgAd.mjs.map} +1 -1
- package/dist/{prisma6-binding-i6ORtPD9.mjs → prisma6-binding-svUHPAct.mjs} +2 -2
- package/dist/{prisma6-binding-i6ORtPD9.mjs.map → prisma6-binding-svUHPAct.mjs.map} +1 -1
- package/dist/target.d.mts +2 -2
- package/dist/target.mjs +4 -4
- package/dist/target__codecs.d.mts +1 -1
- package/dist/target__codecs.mjs +1 -1
- package/dist/target__control.mjs +1 -1
- package/dist/target__data-types.d.mts +1 -1
- package/dist/target__data-types.mjs +1 -1
- package/dist/target__pack.mjs +1 -1
- package/dist/target__pack.mjs.map +1 -1
- package/dist/target__prisma6-binding.mjs +1 -1
- package/dist/target__runtime.mjs +1 -1
- package/dist/target__runtime.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/codecs-D6yLMoD2-Bn8-UhA5.mjs +0 -854
- package/dist/codecs-D6yLMoD2-Bn8-UhA5.mjs.map +0 -1
- package/dist/data-types-D7u1m_Jl-C5XUZspA.mjs +0 -47
- package/dist/data-types-D7u1m_Jl-C5XUZspA.mjs.map +0 -1
|
@@ -1,854 +0,0 @@
|
|
|
1
|
-
import { a as MONGO_DECIMAL128_CODEC_ID, c as MONGO_INT64_CODEC_ID, d as MONGO_OBJECTID_CODEC_ID, f as MONGO_STRING_CODEC_ID, i as MONGO_DATE_CODEC_ID, l as MONGO_INT64_NUMBER_CODEC_ID, n as MONGO_BOOLEAN_CODEC_ID, o as MONGO_DOUBLE_CODEC_ID, p as MONGO_VECTOR_CODEC_ID, r as MONGO_BSON_CODEC_ID, s as MONGO_INT32_CODEC_ID, t as MONGO_BINARY_CODEC_ID, u as MONGO_JSON_CODEC_ID } from "./codec-ids-WdrumsYA-BkQfspmL.mjs";
|
|
2
|
-
import { t as mongoTargetError } from "./mongo-target-errors-Btf3ML1w-B5EMYbz1.mjs";
|
|
3
|
-
import { a as mongoDate, c as mongoInt32, d as mongoObjectId, f as mongoString, l as mongoInt64, n as mongoBool, o as mongoDecimal128, p as mongoVector, r as mongoBson, s as mongoDouble, t as mongoBinary, u as mongoJson } from "./data-types-D7u1m_Jl-C5XUZspA.mjs";
|
|
4
|
-
import { INT32_RANGE, INT64_RANGE, SAFE_INTEGER_BIGINT_RANGE, SAFE_INTEGER_RANGE, decodeJsonBoolean, decodeJsonFloat, decodeJsonInteger, decodeJsonIntegerText, decodeJsonMatching, decodeJsonString, encodeJsonFloat, isIntegerIn, refuseJsonValue, renderTsLiteral } from "@prisma/orm-framework/components/codec";
|
|
5
|
-
import { mongoCodec, newMongoCodecRegistry } from "@prisma/orm-family-mongo/codec";
|
|
6
|
-
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
7
|
-
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
8
|
-
import { isDeepStrictEqual } from "node:util";
|
|
9
|
-
import { Binary, Code, Decimal128, Double, EJSON, Long, MinKey, ObjectId } from "bson";
|
|
10
|
-
//#region ../../../3-mongo-target/1-mongo-target/dist/codecs-D6yLMoD2.mjs
|
|
11
|
-
function where(path) {
|
|
12
|
-
return path === "" ? "the root" : path;
|
|
13
|
-
}
|
|
14
|
-
function child(path, key) {
|
|
15
|
-
return path === "" ? String(key) : `${path}.${key}`;
|
|
16
|
-
}
|
|
17
|
-
function isPlainObject(value) {
|
|
18
|
-
const prototype = Object.getPrototypeOf(value);
|
|
19
|
-
return prototype === Object.prototype || prototype === null;
|
|
20
|
-
}
|
|
21
|
-
function isPlainArray(value) {
|
|
22
|
-
return Array.isArray(value) && Object.getPrototypeOf(value) === Array.prototype;
|
|
23
|
-
}
|
|
24
|
-
const BSON_VERSION = Symbol.for("@@mdb.bson.version");
|
|
25
|
-
/** The major version of the `bson` this package loads, which every `bson` class instance it can serialise carries. */
|
|
26
|
-
const BSON_MAJOR = Reflect.get(new MinKey(), BSON_VERSION);
|
|
27
|
-
/** Whether a `bson` class instance comes from the same major version of `bson`, rather than being a look-alike or from another version. */
|
|
28
|
-
function createdByBsonMajor(value) {
|
|
29
|
-
return Reflect.get(value, BSON_VERSION) === BSON_MAJOR;
|
|
30
|
-
}
|
|
31
|
-
function bsonTypeTag(value) {
|
|
32
|
-
const tag = Reflect.get(value, "_bsontype");
|
|
33
|
-
return typeof tag === "string" ? tag : void 0;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The `_bsontype` tag of a `bson` class instance. A stored subdocument is read as a plain object even when it has a `_bsontype` key, so a plain object has no tag.
|
|
37
|
-
*/
|
|
38
|
-
function bsonClassTag(value) {
|
|
39
|
-
return isPlainObject(value) ? void 0 : bsonTypeTag(value);
|
|
40
|
-
}
|
|
41
|
-
function constructorName(value) {
|
|
42
|
-
const name = Reflect.get(value, "constructor")?.name;
|
|
43
|
-
return typeof name === "string" && name !== "" ? name : "object";
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The `bson` library reads any subdocument with a string `$ref` and an `$id` as a `DBRef`. It was stored as a plain object; these are its entries in stored order, `$ref`, `$id`, `$db` when present, then the other fields.
|
|
47
|
-
*/
|
|
48
|
-
function dbRefEntries(value) {
|
|
49
|
-
const ref = blindCast(value);
|
|
50
|
-
const entries = [["$ref", ref.collection], ["$id", ref.oid]];
|
|
51
|
-
if (ref.db !== void 0) entries.push(["$db", ref.db]);
|
|
52
|
-
entries.push(...Object.entries(ref.fields));
|
|
53
|
-
return entries;
|
|
54
|
-
}
|
|
55
|
-
const BSON_VALUE_TAGS = /* @__PURE__ */ new Set([
|
|
56
|
-
"ObjectId",
|
|
57
|
-
"Long",
|
|
58
|
-
"Decimal128",
|
|
59
|
-
"Binary",
|
|
60
|
-
"BSONRegExp",
|
|
61
|
-
"Timestamp",
|
|
62
|
-
"Int32",
|
|
63
|
-
"Double",
|
|
64
|
-
"Code",
|
|
65
|
-
"MinKey",
|
|
66
|
-
"MaxKey",
|
|
67
|
-
"BSONSymbol"
|
|
68
|
-
]);
|
|
69
|
-
const ENCODE_FIX_BY_RECEIVED$1 = { DBRef: "Write it as a { $ref, $id } document instead." };
|
|
70
|
-
function encodeRefused$1(received, path) {
|
|
71
|
-
const fix = ENCODE_FIX_BY_RECEIVED$1[received];
|
|
72
|
-
throw mongoTargetError("RUNTIME.ENCODE_FAILED", `${MONGO_BSON_CODEC_ID} value must be a BSON value; received ${received} at ${where(path)}${fix === void 0 ? "" : `. ${fix}`}`, { meta: {
|
|
73
|
-
codecId: MONGO_BSON_CODEC_ID,
|
|
74
|
-
received,
|
|
75
|
-
valuePath: path
|
|
76
|
-
} });
|
|
77
|
-
}
|
|
78
|
-
function assertBsonValue(value, path, ancestors) {
|
|
79
|
-
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number") return;
|
|
80
|
-
if (typeof value !== "object") {
|
|
81
|
-
encodeRefused$1(typeof value, path);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const tag = bsonTypeTag(value);
|
|
85
|
-
if (tag !== void 0) {
|
|
86
|
-
if (!BSON_VALUE_TAGS.has(tag)) encodeRefused$1(tag, path);
|
|
87
|
-
if (!createdByBsonMajor(value)) encodeRefused$1(`${tag} not created by bson ${String(BSON_MAJOR)}`, path);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (value instanceof Date || value instanceof RegExp || value instanceof Uint8Array) return;
|
|
91
|
-
if (!isPlainArray(value) && !isPlainObject(value)) {
|
|
92
|
-
encodeRefused$1(constructorName(value), path);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (ancestors.has(value)) encodeRefused$1("circular reference", path);
|
|
96
|
-
ancestors.add(value);
|
|
97
|
-
if (Array.isArray(value)) for (let index = 0; index < value.length; index++) {
|
|
98
|
-
if (!(index in value)) encodeRefused$1("sparse array hole", child(path, index));
|
|
99
|
-
assertBsonValue(value[index], child(path, index), ancestors);
|
|
100
|
-
}
|
|
101
|
-
else for (const [key, entry] of Object.entries(value)) assertBsonValue(entry, child(path, key), ancestors);
|
|
102
|
-
ancestors.delete(value);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns `value` unchanged when it is a BSON value at every depth, and throws `RUNTIME.ENCODE_FAILED` naming the first value that is not, with its path.
|
|
106
|
-
*/
|
|
107
|
-
function encodeBsonValue(value) {
|
|
108
|
-
assertBsonValue(value, "", /* @__PURE__ */ new Set());
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* A `Code` value with a scope, recognised by its tag: the driver reads with its own load of `bson`, so its `Code` is not an instance of the class imported here.
|
|
113
|
-
*/
|
|
114
|
-
function codeWithScope(value) {
|
|
115
|
-
if (bsonClassTag(value) !== "Code") return void 0;
|
|
116
|
-
const code = Reflect.get(value, "code");
|
|
117
|
-
const scope = Reflect.get(value, "scope");
|
|
118
|
-
return typeof code === "string" && typeof scope === "object" && scope !== null ? {
|
|
119
|
-
code,
|
|
120
|
-
scope
|
|
121
|
-
} : void 0;
|
|
122
|
-
}
|
|
123
|
-
function decodeEntries$1(entries) {
|
|
124
|
-
return Object.fromEntries(entries.map(([key, entry]) => [key, decodeValue$1(entry)]));
|
|
125
|
-
}
|
|
126
|
-
function decodeValue$1(value) {
|
|
127
|
-
if (typeof value !== "object" || value === null) return value;
|
|
128
|
-
if (bsonClassTag(value) === "DBRef") return decodeEntries$1(dbRefEntries(value));
|
|
129
|
-
if (Array.isArray(value)) {
|
|
130
|
-
const decoded = value.map(decodeValue$1);
|
|
131
|
-
return decoded.some((entry, index) => entry !== value[index]) ? decoded : value;
|
|
132
|
-
}
|
|
133
|
-
const code = codeWithScope(value);
|
|
134
|
-
if (code !== void 0) {
|
|
135
|
-
const scope = decodeValue$1(code.scope);
|
|
136
|
-
return scope === code.scope ? value : new Code(code.code, blindCast(scope));
|
|
137
|
-
}
|
|
138
|
-
if (!isPlainObject(value)) return value;
|
|
139
|
-
const entries = Object.entries(value);
|
|
140
|
-
const decoded = decodeEntries$1(entries);
|
|
141
|
-
return entries.some(([key, entry]) => decoded[key] !== entry) ? decoded : value;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Returns the wire value as the driver produced it, except that a `DBRef` the `bson` library read from a `{ $ref, $id }` subdocument becomes that document again, `{ $ref, $id[, $db], ...fields }`, with its members' BSON types kept, at any depth and inside a `Code` scope. A value holding no `DBRef` is returned as the same object.
|
|
145
|
-
*/
|
|
146
|
-
function decodeBsonValue(wire) {
|
|
147
|
-
return blindCast(decodeValue$1(wire));
|
|
148
|
-
}
|
|
149
|
-
function asDriverWrites(value) {
|
|
150
|
-
if (typeof value === "number") return Number.isInteger(value) && (value < INT32_RANGE.min || value > INT32_RANGE.max) ? new Double(value) : value;
|
|
151
|
-
if (typeof value !== "object" || value === null) return value;
|
|
152
|
-
if (value instanceof Uint8Array) return new Binary(value);
|
|
153
|
-
if (Array.isArray(value)) return value.map(asDriverWrites);
|
|
154
|
-
if (isPlainObject(value)) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, asDriverWrites(entry)]));
|
|
155
|
-
const code = codeWithScope(value);
|
|
156
|
-
if (code !== void 0) return new Code(code.code, blindCast(asDriverWrites(code.scope)));
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Canonical Extended JSON for a BSON value, recording each JavaScript number and `Uint8Array` as the BSON type the driver writes for it: an integer outside the int32 range as a `double`, and bytes as `binData`.
|
|
161
|
-
*/
|
|
162
|
-
function encodeBsonJson(value) {
|
|
163
|
-
return blindCast(EJSON.serialize(asDriverWrites(value), { relaxed: false }));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Reads the canonical Extended JSON `encodeBsonJson` writes. The `bson` reader also takes forms that are not canonical, some of them silently wrong (`{ "$numberInt": "abc" }` reads as 0), so a value that does not write back to the same JSON is refused.
|
|
167
|
-
*/
|
|
168
|
-
function decodeBsonJson(json) {
|
|
169
|
-
let value;
|
|
170
|
-
try {
|
|
171
|
-
value = EJSON.deserialize(blindCast(json), { relaxed: false });
|
|
172
|
-
} catch {
|
|
173
|
-
return refuseJsonValue(MONGO_BSON_CODEC_ID, "canonical Extended JSON", json);
|
|
174
|
-
}
|
|
175
|
-
if (!isDeepStrictEqual(EJSON.serialize(value, { relaxed: false }), json)) return refuseJsonValue(MONGO_BSON_CODEC_ID, "canonical Extended JSON", json);
|
|
176
|
-
return value;
|
|
177
|
-
}
|
|
178
|
-
const DECIMAL_INTEGER = /^-?\d+$/;
|
|
179
|
-
const CANONICAL_DECIMAL_TEXT = /^(?:-?\d+(?:\.\d+)?|NaN|-?Infinity)$/;
|
|
180
|
-
const DECIMAL128_TEXT = /^(-?)(\d+)(?:\.(\d+))?(?:E([+-]\d+))?$/;
|
|
181
|
-
const BASE64_TEXT = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
182
|
-
/**
|
|
183
|
-
* Checks the BSON type tag rather than `instanceof`: the driver deserialises with its own load of `bson` (CommonJS, where this module may be loaded as ESM), so a value read from the database need not be an instance of the class imported here.
|
|
184
|
-
*/
|
|
185
|
-
function hasBsonTypeTag(value, tag) {
|
|
186
|
-
return typeof value === "object" && value !== null && "_bsontype" in value && value._bsontype === tag;
|
|
187
|
-
}
|
|
188
|
-
function isLong(value) {
|
|
189
|
-
return hasBsonTypeTag(value, "Long");
|
|
190
|
-
}
|
|
191
|
-
function isDecimal128(value) {
|
|
192
|
-
return hasBsonTypeTag(value, "Decimal128");
|
|
193
|
-
}
|
|
194
|
-
function isBinary(value) {
|
|
195
|
-
return hasBsonTypeTag(value, "Binary");
|
|
196
|
-
}
|
|
197
|
-
function decodeFailed(codecId, message, received) {
|
|
198
|
-
throw mongoTargetError("RUNTIME.DECODE_FAILED", `${codecId} ${message}`, { meta: {
|
|
199
|
-
codecId,
|
|
200
|
-
received: typeof received
|
|
201
|
-
} });
|
|
202
|
-
}
|
|
203
|
-
const RECEIVED_PREVIEW_LIMIT = 100;
|
|
204
|
-
function encodeFailed(codecId, message, received) {
|
|
205
|
-
throw mongoTargetError("RUNTIME.ENCODE_FAILED", `${codecId} ${message}`, { meta: {
|
|
206
|
-
codecId,
|
|
207
|
-
received: String(received).slice(0, RECEIVED_PREVIEW_LIMIT)
|
|
208
|
-
} });
|
|
209
|
-
}
|
|
210
|
-
function describeReceived(value) {
|
|
211
|
-
if (typeof value === "number") return String(value);
|
|
212
|
-
if (typeof value === "bigint") return `${value}n`;
|
|
213
|
-
if (typeof value === "string") return `string ${JSON.stringify(value.slice(0, RECEIVED_PREVIEW_LIMIT))}`;
|
|
214
|
-
if (value === null) return "null";
|
|
215
|
-
if (value instanceof Date) return Number.isNaN(value.getTime()) ? "an invalid Date" : "a Date";
|
|
216
|
-
if (Array.isArray(value)) return "an array";
|
|
217
|
-
return typeof value;
|
|
218
|
-
}
|
|
219
|
-
function refuseType(codecId, expected, value, received = describeReceived(value)) {
|
|
220
|
-
return encodeFailed(codecId, `value must be ${expected}; received ${received}`, value);
|
|
221
|
-
}
|
|
222
|
-
function stringEncode(codecId, value) {
|
|
223
|
-
if (typeof value !== "string") refuseType(codecId, "a string", value);
|
|
224
|
-
return value;
|
|
225
|
-
}
|
|
226
|
-
function booleanEncode(codecId, value) {
|
|
227
|
-
if (typeof value !== "boolean") refuseType(codecId, "a boolean", value);
|
|
228
|
-
return value;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* The driver writes an invalid `Date` as the epoch, so one is refused with any other non-`Date` value.
|
|
232
|
-
*/
|
|
233
|
-
function dateEncode(codecId, value) {
|
|
234
|
-
if (!(value instanceof Date) || Number.isNaN(value.getTime())) refuseType(codecId, "a valid Date", value);
|
|
235
|
-
return value;
|
|
236
|
-
}
|
|
237
|
-
const OBJECT_ID_TEXT = /^[0-9a-fA-F]{24}$/;
|
|
238
|
-
function hexStringOf(value) {
|
|
239
|
-
const toHexString = Reflect.get(value, "toHexString");
|
|
240
|
-
if (typeof toHexString !== "function") return void 0;
|
|
241
|
-
const hex = Reflect.apply(toHexString, value, []);
|
|
242
|
-
return typeof hex === "string" && OBJECT_ID_TEXT.test(hex) ? hex : void 0;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* `new ObjectId(...)` makes a fresh id from `null` or `undefined` and reads a number as a timestamp, so only a string, which the constructor accepts only as 24 hex digits, or an `ObjectId` is passed to it. An `ObjectId` is rebuilt from its hex string, so one from any major version of `bson` works.
|
|
246
|
-
*/
|
|
247
|
-
function objectIdEncode(codecId, value) {
|
|
248
|
-
const expected = "a 24-digit hex string or an ObjectId";
|
|
249
|
-
if (typeof value === "string") try {
|
|
250
|
-
return new ObjectId(value);
|
|
251
|
-
} catch {
|
|
252
|
-
return refuseType(codecId, expected, value);
|
|
253
|
-
}
|
|
254
|
-
if (typeof value !== "object" || value === null || !hasBsonTypeTag(value, "ObjectId")) return refuseType(codecId, expected, value);
|
|
255
|
-
const hex = hexStringOf(value);
|
|
256
|
-
if (hex === void 0) return refuseType(codecId, expected, value, "an object tagged ObjectId whose toHexString() does not return 24 hex digits");
|
|
257
|
-
return new ObjectId(hex);
|
|
258
|
-
}
|
|
259
|
-
function vectorEncode(codecId, value) {
|
|
260
|
-
if (!Array.isArray(value) || !value.every((element) => typeof element === "number")) refuseType(codecId, "an array of numbers", value);
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Wraps the number in the driver's `Double`, because the driver writes a whole JavaScript number in the int32 range as a BSON `int`, which a `double` validator refuses.
|
|
265
|
-
*/
|
|
266
|
-
function doubleEncode(codecId, value) {
|
|
267
|
-
if (typeof value !== "number") encodeFailed(codecId, `value must be a number; received ${describeReceived(value)}`, value);
|
|
268
|
-
return new Double(value);
|
|
269
|
-
}
|
|
270
|
-
function int32Encode(codecId, value) {
|
|
271
|
-
if (!isIntegerIn(value, INT32_RANGE)) encodeFailed(codecId, `value must be an integer from ${INT32_RANGE.min} to ${INT32_RANGE.max}; received ${describeReceived(value)}`, value);
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
function objectIdEncodeJson(codecId, value) {
|
|
275
|
-
if (typeof value !== "string" || !OBJECT_ID_TEXT.test(value)) encodeFailed(codecId, "value must be 24 hexadecimal digits", value);
|
|
276
|
-
return value;
|
|
277
|
-
}
|
|
278
|
-
function objectIdDecodeJson(codecId, json) {
|
|
279
|
-
return decodeJsonMatching(codecId, json, OBJECT_ID_TEXT, "24 hexadecimal digits");
|
|
280
|
-
}
|
|
281
|
-
function int32EncodeJson(codecId, value) {
|
|
282
|
-
if (!isIntegerIn(value, INT32_RANGE)) encodeFailed(codecId, `value must be an integer from ${INT32_RANGE.min} to ${INT32_RANGE.max}`, value);
|
|
283
|
-
return value;
|
|
284
|
-
}
|
|
285
|
-
function int32DecodeJson(codecId, json) {
|
|
286
|
-
return decodeJsonInteger(codecId, json, INT32_RANGE);
|
|
287
|
-
}
|
|
288
|
-
function dateEncodeJson(codecId, value) {
|
|
289
|
-
if (!(value instanceof Date) || Number.isNaN(value.getTime())) encodeFailed(codecId, "value must be a valid Date", value);
|
|
290
|
-
return value.toISOString();
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* The JSON form is the text `Date.toISOString()` writes, so a string that does not read back to that same text is refused.
|
|
294
|
-
*/
|
|
295
|
-
function dateDecodeJson(codecId, json) {
|
|
296
|
-
const date = typeof json === "string" ? new Date(json) : void 0;
|
|
297
|
-
if (date === void 0 || Number.isNaN(date.getTime()) || date.toISOString() !== json) return refuseJsonValue(codecId, "a date and time in UTC as Date.toISOString writes it", json);
|
|
298
|
-
return date;
|
|
299
|
-
}
|
|
300
|
-
function vectorDecodeJson(codecId, json) {
|
|
301
|
-
if (!Array.isArray(json)) return refuseJsonValue(codecId, "an array of numbers", json);
|
|
302
|
-
const numbers = [];
|
|
303
|
-
for (const element of json) {
|
|
304
|
-
if (typeof element !== "number") return refuseJsonValue(codecId, "an array of numbers", element);
|
|
305
|
-
numbers.push(element);
|
|
306
|
-
}
|
|
307
|
-
return numbers;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* `Long.fromBigInt` keeps the low 64 bits of any bigint, so an out-of-range value would be stored as a different number without error.
|
|
311
|
-
*/
|
|
312
|
-
function isInt64(value) {
|
|
313
|
-
return value >= INT64_RANGE.min && value <= INT64_RANGE.max;
|
|
314
|
-
}
|
|
315
|
-
function requireInt64(codecId, value) {
|
|
316
|
-
if (!isInt64(value)) encodeFailed(codecId, "value is outside the signed 64-bit range", value);
|
|
317
|
-
return value;
|
|
318
|
-
}
|
|
319
|
-
function int64Encode(codecId, value) {
|
|
320
|
-
if (typeof value !== "bigint") encodeFailed(codecId, "value must be a bigint", value);
|
|
321
|
-
return Long.fromBigInt(requireInt64(codecId, value));
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* A stored double with a fraction, which a 64-bit integer codec cannot read. Such values were written through a Prisma 6 `Int` while its contract used the 32-bit codec, which took any number.
|
|
325
|
-
*/
|
|
326
|
-
function refuseFractionalDouble(codecId, wire) {
|
|
327
|
-
return decodeFailed(codecId, `wire value is the fractional double ${wire}, and a 64-bit integer holds whole numbers only. Rewrite each such stored value as a long, rounded or cut off ({ $toLong: { $round: [<value>, 0] } }, or $trunc in place of $round), mapping over the list when the value sits in one. The upgrade guide step prisma6-int-written-as-long has the queries for a plain field, a list and a list of composite values.`, wire);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* The driver promotes a stored `long` that fits in 53 bits to a `number`, and hands larger ones over as `Long`, so both arrive here.
|
|
331
|
-
*/
|
|
332
|
-
function int64Decode(codecId, wire) {
|
|
333
|
-
if (typeof wire === "bigint") return wire;
|
|
334
|
-
if (isLong(wire)) return wire.toBigInt();
|
|
335
|
-
if (typeof wire === "number" && Number.isSafeInteger(wire)) return BigInt(wire);
|
|
336
|
-
if (typeof wire === "number" && Number.isFinite(wire) && !Number.isInteger(wire)) return refuseFractionalDouble(codecId, wire);
|
|
337
|
-
return decodeFailed(codecId, "wire value must be a Long or a safe integer", wire);
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* A schema-written default arrives as a `number`; one that is a safe integer names its value exactly, so it is accepted like `pg/int8@1` accepts it.
|
|
341
|
-
*/
|
|
342
|
-
function int64EncodeJson(codecId, value) {
|
|
343
|
-
if (typeof value === "bigint") return requireInt64(codecId, value).toString();
|
|
344
|
-
if (typeof value === "number" && Number.isSafeInteger(value)) return BigInt(value).toString();
|
|
345
|
-
return encodeFailed(codecId, "value must be a bigint or a safe integer", value);
|
|
346
|
-
}
|
|
347
|
-
function int64DecodeJson(codecId, json) {
|
|
348
|
-
return decodeJsonIntegerText(codecId, json, INT64_RANGE);
|
|
349
|
-
}
|
|
350
|
-
const SAFE_INTEGERS = `from ${SAFE_INTEGER_RANGE.min} to ${SAFE_INTEGER_RANGE.max}`;
|
|
351
|
-
function int64NumberEncode(codecId, value) {
|
|
352
|
-
if (!isIntegerIn(value, SAFE_INTEGER_RANGE)) encodeFailed(codecId, `value must be an integer ${SAFE_INTEGERS}; received ${describeReceived(value)}`, value);
|
|
353
|
-
return Long.fromNumber(value);
|
|
354
|
-
}
|
|
355
|
-
function safeIntegerOf(codecId, value) {
|
|
356
|
-
if (value < SAFE_INTEGER_BIGINT_RANGE.min || value > SAFE_INTEGER_BIGINT_RANGE.max) decodeFailed(codecId, `wire value must be a whole number ${SAFE_INTEGERS}; received ${value}`, value);
|
|
357
|
-
return Number(value);
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* The driver hands a stored `long` over as a `number` when it fits in 53 bits (the default `promoteLongs`), as a `Long` otherwise or with `promoteLongs: false`, and as a `bigint` with `useBigInt64`.
|
|
361
|
-
*/
|
|
362
|
-
function int64NumberDecode(codecId, wire) {
|
|
363
|
-
if (typeof wire === "bigint") return safeIntegerOf(codecId, wire);
|
|
364
|
-
if (isLong(wire)) return safeIntegerOf(codecId, wire.toBigInt());
|
|
365
|
-
if (isIntegerIn(wire, SAFE_INTEGER_RANGE)) return wire;
|
|
366
|
-
if (typeof wire === "number" && Number.isFinite(wire) && !Number.isInteger(wire)) return refuseFractionalDouble(codecId, wire);
|
|
367
|
-
return decodeFailed(codecId, `wire value must be a whole number ${SAFE_INTEGERS}; received ${describeReceived(wire)}`, wire);
|
|
368
|
-
}
|
|
369
|
-
function int64NumberEncodeJson(codecId, value) {
|
|
370
|
-
return int64NumberEncode(codecId, value).toString();
|
|
371
|
-
}
|
|
372
|
-
function int64NumberDecodeJson(codecId, json) {
|
|
373
|
-
return Number(decodeJsonIntegerText(codecId, json, SAFE_INTEGER_BIGINT_RANGE));
|
|
374
|
-
}
|
|
375
|
-
function decimalTextNumberLiteral(value) {
|
|
376
|
-
return typeof value === "string" && DECIMAL_INTEGER.test(value) ? value : void 0;
|
|
377
|
-
}
|
|
378
|
-
function decimalTextBigintLiteral(value) {
|
|
379
|
-
return typeof value === "string" && DECIMAL_INTEGER.test(value) ? `${value}n` : void 0;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* `Decimal128.toString()` writes some values with an exponent (`1E+3`, `1.23E+40`). The application value is decimal text without one, as for Postgres `numeric`: the point moves to where the exponent puts it, trailing zeros stay, and the sign of zero goes.
|
|
383
|
-
*/
|
|
384
|
-
function canonicalDecimalText(text) {
|
|
385
|
-
if (text === "NaN" || text === "Infinity" || text === "-Infinity") return text;
|
|
386
|
-
const match = DECIMAL128_TEXT.exec(text);
|
|
387
|
-
if (match === null) return void 0;
|
|
388
|
-
const [, sign = "", whole = "", fraction = "", exponent = "0"] = match;
|
|
389
|
-
const digits = `${whole}${fraction}`;
|
|
390
|
-
const point = whole.length + Number(exponent);
|
|
391
|
-
let integerPart;
|
|
392
|
-
let fractionPart;
|
|
393
|
-
if (point <= 0) {
|
|
394
|
-
integerPart = "0";
|
|
395
|
-
fractionPart = `${"0".repeat(-point)}${digits}`;
|
|
396
|
-
} else if (point >= digits.length) {
|
|
397
|
-
integerPart = `${digits}${"0".repeat(point - digits.length)}`;
|
|
398
|
-
fractionPart = "";
|
|
399
|
-
} else {
|
|
400
|
-
integerPart = digits.slice(0, point);
|
|
401
|
-
fractionPart = digits.slice(point);
|
|
402
|
-
}
|
|
403
|
-
const trimmedInteger = integerPart.replace(/^0+(?=\d)/, "");
|
|
404
|
-
const unsigned = fractionPart === "" ? trimmedInteger : `${trimmedInteger}.${fractionPart}`;
|
|
405
|
-
return /^[0.]+$/.test(unsigned) ? unsigned : `${sign}${unsigned}`;
|
|
406
|
-
}
|
|
407
|
-
function requireCanonicalDecimalText(codecId, value) {
|
|
408
|
-
if (typeof value !== "string" || !CANONICAL_DECIMAL_TEXT.test(value)) encodeFailed(codecId, "value must be decimal text without an exponent, or NaN, Infinity or -Infinity", value);
|
|
409
|
-
return value;
|
|
410
|
-
}
|
|
411
|
-
function decimal128Encode(codecId, value) {
|
|
412
|
-
requireCanonicalDecimalText(codecId, value);
|
|
413
|
-
try {
|
|
414
|
-
return Decimal128.fromString(value);
|
|
415
|
-
} catch (error) {
|
|
416
|
-
return encodeFailed(codecId, `value cannot be stored as a Decimal128 exactly: ${error instanceof Error ? error.message : String(error)}`, value);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
function decimal128Decode(codecId, wire) {
|
|
420
|
-
if (!isDecimal128(wire)) return decodeFailed(codecId, "wire value must be a Decimal128", wire);
|
|
421
|
-
const text = canonicalDecimalText(wire.toString());
|
|
422
|
-
if (text === void 0) return decodeFailed(codecId, "wire value is not decimal text", wire);
|
|
423
|
-
return text;
|
|
424
|
-
}
|
|
425
|
-
function decimal128EncodeJson(codecId, value) {
|
|
426
|
-
return requireCanonicalDecimalText(codecId, value);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* The JSON form is what `encodeJson` writes, so it follows the encode rule: canonical decimal text (no exponent), or `NaN`, `Infinity` or `-Infinity`, that a Decimal128 holds exactly.
|
|
430
|
-
*/
|
|
431
|
-
function decimal128DecodeJson(codecId, json) {
|
|
432
|
-
const expected = "decimal text without an exponent that a Decimal128 holds exactly, or NaN, Infinity or -Infinity";
|
|
433
|
-
const text = decodeJsonMatching(codecId, json, CANONICAL_DECIMAL_TEXT, expected);
|
|
434
|
-
try {
|
|
435
|
-
Decimal128.fromString(text);
|
|
436
|
-
} catch {
|
|
437
|
-
return refuseJsonValue(codecId, expected, json);
|
|
438
|
-
}
|
|
439
|
-
return text;
|
|
440
|
-
}
|
|
441
|
-
function binaryEncode(codecId, value) {
|
|
442
|
-
if (!(value instanceof Uint8Array)) encodeFailed(codecId, "value must be a Uint8Array", value);
|
|
443
|
-
return new Binary(value);
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* The driver reads binData as a `Binary`, or as a `Buffer` with `promoteBuffers: true`; either becomes a plain `Uint8Array` copy of the bytes.
|
|
447
|
-
*/
|
|
448
|
-
function binaryDecode(codecId, wire) {
|
|
449
|
-
if (wire instanceof Uint8Array) return new Uint8Array(wire);
|
|
450
|
-
if (!isBinary(wire)) return decodeFailed(codecId, "wire value must be a Binary or a Uint8Array", wire);
|
|
451
|
-
return new Uint8Array(wire.value());
|
|
452
|
-
}
|
|
453
|
-
function binaryEncodeJson(value) {
|
|
454
|
-
return Buffer.from(value).toString("base64");
|
|
455
|
-
}
|
|
456
|
-
function binaryDecodeJson(codecId, json) {
|
|
457
|
-
return new Uint8Array(Buffer.from(decodeJsonMatching(codecId, json, BASE64_TEXT, "base64 text"), "base64"));
|
|
458
|
-
}
|
|
459
|
-
const BSON_TYPE_BY_TAG = {
|
|
460
|
-
ObjectId: "objectId",
|
|
461
|
-
Decimal128: "decimal",
|
|
462
|
-
Binary: "binData",
|
|
463
|
-
BSONRegExp: "regex",
|
|
464
|
-
Timestamp: "timestamp",
|
|
465
|
-
BSONSymbol: "symbol",
|
|
466
|
-
Code: "javascript",
|
|
467
|
-
MinKey: "minKey",
|
|
468
|
-
MaxKey: "maxKey"
|
|
469
|
-
};
|
|
470
|
-
const NOT_FINITE_FIX = "JSON has no NaN or Infinity; store null or a string, or declare the field Bson.";
|
|
471
|
-
const BSON_FIX = "Declare the field Bson to store BSON values.";
|
|
472
|
-
const PLAIN_VALUE_FIX = "Convert it to a plain object or array.";
|
|
473
|
-
const ENCODE_FIX_BY_RECEIVED = {
|
|
474
|
-
Date: "Store the date as an ISO 8601 string, or declare the field Bson.",
|
|
475
|
-
bigint: "Store it as a number in the safe-integer range or as decimal text, or declare the field Int64 or Bson.",
|
|
476
|
-
NaN: NOT_FINITE_FIX,
|
|
477
|
-
Infinity: NOT_FINITE_FIX,
|
|
478
|
-
"-Infinity": NOT_FINITE_FIX,
|
|
479
|
-
undefined: "Leave the key out, or store null.",
|
|
480
|
-
Uint8Array: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
|
|
481
|
-
Buffer: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
|
|
482
|
-
Binary: "Store the bytes as a base64 string, or declare the field Binary or Bson.",
|
|
483
|
-
ObjectId: "Store its hex string, or declare the field ObjectId or Bson.",
|
|
484
|
-
Long: "Store a number in the safe-integer range or decimal text, or declare the field Int64 or Bson.",
|
|
485
|
-
Decimal128: "Store the decimal text, or declare the field Decimal128 or Bson.",
|
|
486
|
-
Int32: "Pass a plain number.",
|
|
487
|
-
Double: "Pass a plain number.",
|
|
488
|
-
RegExp: "Store the pattern as a string, or declare the field Bson.",
|
|
489
|
-
BSONRegExp: "Store the pattern as a string, or declare the field Bson.",
|
|
490
|
-
symbol: "Store a string instead.",
|
|
491
|
-
function: "Store data, not a function.",
|
|
492
|
-
"circular reference": "Remove the cycle; a JSON value is a tree.",
|
|
493
|
-
"sparse array hole": "Fill the hole with null.",
|
|
494
|
-
DBRef: "Write it as a { $ref, $id } document instead."
|
|
495
|
-
};
|
|
496
|
-
function encodeFix(received) {
|
|
497
|
-
return ENCODE_FIX_BY_RECEIVED[received] ?? (Object.hasOwn(BSON_TYPE_BY_TAG, received) ? BSON_FIX : PLAIN_VALUE_FIX);
|
|
498
|
-
}
|
|
499
|
-
function encodeRefused(received, path) {
|
|
500
|
-
throw mongoTargetError("RUNTIME.ENCODE_FAILED", `${MONGO_JSON_CODEC_ID} value must be a JSON value; received ${received} at ${where(path)}. ${encodeFix(received)}`, { meta: {
|
|
501
|
-
codecId: MONGO_JSON_CODEC_ID,
|
|
502
|
-
received,
|
|
503
|
-
valuePath: path
|
|
504
|
-
} });
|
|
505
|
-
}
|
|
506
|
-
function describeNonJson(value) {
|
|
507
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return void 0;
|
|
508
|
-
if (typeof value === "number") return Number.isFinite(value) ? void 0 : String(value);
|
|
509
|
-
if (typeof value !== "object") return typeof value;
|
|
510
|
-
const tag = bsonTypeTag(value);
|
|
511
|
-
if (tag !== void 0) return tag;
|
|
512
|
-
if (value instanceof Date) return "Date";
|
|
513
|
-
if (isPlainArray(value)) return void 0;
|
|
514
|
-
return isPlainObject(value) ? void 0 : constructorName(value);
|
|
515
|
-
}
|
|
516
|
-
function assertJsonValue(value, path, ancestors) {
|
|
517
|
-
const received = describeNonJson(value);
|
|
518
|
-
if (received !== void 0) encodeRefused(received, path);
|
|
519
|
-
if (typeof value !== "object" || value === null) return;
|
|
520
|
-
if (ancestors.has(value)) encodeRefused("circular reference", path);
|
|
521
|
-
ancestors.add(value);
|
|
522
|
-
if (Array.isArray(value)) for (let index = 0; index < value.length; index++) {
|
|
523
|
-
if (!(index in value)) encodeRefused("sparse array hole", child(path, index));
|
|
524
|
-
assertJsonValue(value[index], child(path, index), ancestors);
|
|
525
|
-
}
|
|
526
|
-
else for (const [key, entry] of Object.entries(value)) assertJsonValue(entry, child(path, key), ancestors);
|
|
527
|
-
ancestors.delete(value);
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* 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.
|
|
531
|
-
*/
|
|
532
|
-
function encodeJsonValue(value) {
|
|
533
|
-
assertJsonValue(value, "", /* @__PURE__ */ new Set());
|
|
534
|
-
return value;
|
|
535
|
-
}
|
|
536
|
-
function decodeRefused(bsonType, path) {
|
|
537
|
-
throw mongoTargetError("RUNTIME.DECODE_FAILED", `${MONGO_JSON_CODEC_ID} wire value contains a non-JSON BSON ${bsonType} at ${where(path)}`, { meta: {
|
|
538
|
-
codecId: MONGO_JSON_CODEC_ID,
|
|
539
|
-
received: bsonType,
|
|
540
|
-
valuePath: path
|
|
541
|
-
} });
|
|
542
|
-
}
|
|
543
|
-
function safeLong(value, path) {
|
|
544
|
-
const number = Number(value);
|
|
545
|
-
return Number.isSafeInteger(number) && BigInt(number) === value ? number : decodeRefused("long", path);
|
|
546
|
-
}
|
|
547
|
-
function finiteDouble(value, path) {
|
|
548
|
-
if (Number.isFinite(value)) return value;
|
|
549
|
-
const received = String(value);
|
|
550
|
-
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: {
|
|
551
|
-
codecId: MONGO_JSON_CODEC_ID,
|
|
552
|
-
received,
|
|
553
|
-
valuePath: path
|
|
554
|
-
} });
|
|
555
|
-
}
|
|
556
|
-
function decodeEntries(entries, path) {
|
|
557
|
-
return Object.fromEntries(entries.map(([key, entry]) => [key, decodeValue(entry, child(path, key))]));
|
|
558
|
-
}
|
|
559
|
-
function decodeTagged(value, tag, path) {
|
|
560
|
-
switch (tag) {
|
|
561
|
-
case "DBRef": return decodeEntries(dbRefEntries(value), path);
|
|
562
|
-
case "Long": return safeLong(blindCast(value).toBigInt(), path);
|
|
563
|
-
case "Int32":
|
|
564
|
-
case "Double": return finiteDouble(Number(value.valueOf()), path);
|
|
565
|
-
}
|
|
566
|
-
return decodeRefused(BSON_TYPE_BY_TAG[tag] ?? tag, path);
|
|
567
|
-
}
|
|
568
|
-
function decodeValue(value, path) {
|
|
569
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
570
|
-
if (typeof value === "number") return finiteDouble(value, path);
|
|
571
|
-
if (typeof value === "bigint") return safeLong(value, path);
|
|
572
|
-
if (typeof value === "undefined") return decodeRefused("undefined", path);
|
|
573
|
-
if (typeof value === "symbol") return decodeRefused("symbol", path);
|
|
574
|
-
if (typeof value === "function") return decodeRefused("javascript", path);
|
|
575
|
-
const tag = bsonClassTag(value);
|
|
576
|
-
if (tag !== void 0) return decodeTagged(value, tag, path);
|
|
577
|
-
if (value instanceof Date) return decodeRefused("date", path);
|
|
578
|
-
if (value instanceof RegExp) return decodeRefused("regex", path);
|
|
579
|
-
if (value instanceof Uint8Array) return decodeRefused("binData", path);
|
|
580
|
-
if (Array.isArray(value)) {
|
|
581
|
-
const decoded = value.map((entry, index) => decodeValue(entry, child(path, index)));
|
|
582
|
-
return decoded.some((entry, index) => entry !== value[index]) ? decoded : value;
|
|
583
|
-
}
|
|
584
|
-
if (!isPlainObject(value)) return decodeRefused(constructorName(value), path);
|
|
585
|
-
const entries = Object.entries(value);
|
|
586
|
-
const decoded = decodeEntries(entries, path);
|
|
587
|
-
return entries.some(([key, entry]) => decoded[key] !== entry) ? decoded : blindCast(value);
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* 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.
|
|
591
|
-
*/
|
|
592
|
-
function decodeJsonValue(wire) {
|
|
593
|
-
return decodeValue(wire, "");
|
|
594
|
-
}
|
|
595
|
-
const mongoObjectIdCodec = mongoCodec({
|
|
596
|
-
typeId: MONGO_OBJECTID_CODEC_ID,
|
|
597
|
-
decode: (wire) => wire.toHexString(),
|
|
598
|
-
encode: (value) => objectIdEncode(MONGO_OBJECTID_CODEC_ID, value),
|
|
599
|
-
encodeJson: (value) => objectIdEncodeJson(MONGO_OBJECTID_CODEC_ID, value),
|
|
600
|
-
decodeJson: (json) => objectIdDecodeJson(MONGO_OBJECTID_CODEC_ID, json)
|
|
601
|
-
});
|
|
602
|
-
const mongoStringCodec = mongoCodec({
|
|
603
|
-
typeId: MONGO_STRING_CODEC_ID,
|
|
604
|
-
decode: (wire) => wire,
|
|
605
|
-
encode: (value) => stringEncode(MONGO_STRING_CODEC_ID, value),
|
|
606
|
-
decodeJson: (json) => decodeJsonString(MONGO_STRING_CODEC_ID, json)
|
|
607
|
-
});
|
|
608
|
-
const mongoDoubleCodec = mongoCodec({
|
|
609
|
-
typeId: MONGO_DOUBLE_CODEC_ID,
|
|
610
|
-
decode: (wire) => Number(wire),
|
|
611
|
-
encode: (value) => doubleEncode(MONGO_DOUBLE_CODEC_ID, value),
|
|
612
|
-
encodeJson: encodeJsonFloat,
|
|
613
|
-
decodeJson: (json) => decodeJsonFloat(MONGO_DOUBLE_CODEC_ID, json)
|
|
614
|
-
});
|
|
615
|
-
const mongoInt32Codec = mongoCodec({
|
|
616
|
-
typeId: MONGO_INT32_CODEC_ID,
|
|
617
|
-
decode: (wire) => wire,
|
|
618
|
-
encode: (value) => int32Encode(MONGO_INT32_CODEC_ID, value),
|
|
619
|
-
encodeJson: (value) => int32EncodeJson(MONGO_INT32_CODEC_ID, value),
|
|
620
|
-
decodeJson: (json) => int32DecodeJson(MONGO_INT32_CODEC_ID, json)
|
|
621
|
-
});
|
|
622
|
-
const mongoBooleanCodec = mongoCodec({
|
|
623
|
-
typeId: MONGO_BOOLEAN_CODEC_ID,
|
|
624
|
-
decode: (wire) => wire,
|
|
625
|
-
encode: (value) => booleanEncode(MONGO_BOOLEAN_CODEC_ID, value),
|
|
626
|
-
decodeJson: (json) => decodeJsonBoolean(MONGO_BOOLEAN_CODEC_ID, json)
|
|
627
|
-
});
|
|
628
|
-
const mongoDateCodec = mongoCodec({
|
|
629
|
-
typeId: MONGO_DATE_CODEC_ID,
|
|
630
|
-
decode: (wire) => wire,
|
|
631
|
-
encode: (value) => dateEncode(MONGO_DATE_CODEC_ID, value),
|
|
632
|
-
encodeJson: (value) => dateEncodeJson(MONGO_DATE_CODEC_ID, value),
|
|
633
|
-
decodeJson: (json) => dateDecodeJson(MONGO_DATE_CODEC_ID, json)
|
|
634
|
-
});
|
|
635
|
-
const mongoVectorCodec = mongoCodec({
|
|
636
|
-
typeId: MONGO_VECTOR_CODEC_ID,
|
|
637
|
-
decode: (wire) => wire,
|
|
638
|
-
encode: (value) => vectorEncode(MONGO_VECTOR_CODEC_ID, value),
|
|
639
|
-
decodeJson: (json) => vectorDecodeJson(MONGO_VECTOR_CODEC_ID, json)
|
|
640
|
-
});
|
|
641
|
-
/**
|
|
642
|
-
* A BSON `long`. The application value is a `bigint`, because a `number` cannot hold the full 64-bit range; its JSON form is decimal text.
|
|
643
|
-
*/
|
|
644
|
-
const mongoInt64Codec = mongoCodec({
|
|
645
|
-
typeId: MONGO_INT64_CODEC_ID,
|
|
646
|
-
decode: (wire) => int64Decode(MONGO_INT64_CODEC_ID, wire),
|
|
647
|
-
encode: (value) => int64Encode(MONGO_INT64_CODEC_ID, value),
|
|
648
|
-
encodeJson: (value) => int64EncodeJson(MONGO_INT64_CODEC_ID, value),
|
|
649
|
-
decodeJson: (json) => int64DecodeJson(MONGO_INT64_CODEC_ID, json)
|
|
650
|
-
});
|
|
651
|
-
/**
|
|
652
|
-
* 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.
|
|
653
|
-
*/
|
|
654
|
-
const mongoInt64NumberCodec = mongoCodec({
|
|
655
|
-
typeId: MONGO_INT64_NUMBER_CODEC_ID,
|
|
656
|
-
decode: (wire) => int64NumberDecode(MONGO_INT64_NUMBER_CODEC_ID, wire),
|
|
657
|
-
encode: (value) => int64NumberEncode(MONGO_INT64_NUMBER_CODEC_ID, value),
|
|
658
|
-
encodeJson: (value) => int64NumberEncodeJson(MONGO_INT64_NUMBER_CODEC_ID, value),
|
|
659
|
-
decodeJson: (json) => int64NumberDecodeJson(MONGO_INT64_NUMBER_CODEC_ID, json)
|
|
660
|
-
});
|
|
661
|
-
/**
|
|
662
|
-
* A BSON `decimal`. The application value and its JSON form are the same decimal text, written without an exponent.
|
|
663
|
-
*/
|
|
664
|
-
const mongoDecimal128Codec = mongoCodec({
|
|
665
|
-
typeId: MONGO_DECIMAL128_CODEC_ID,
|
|
666
|
-
decode: (wire) => decimal128Decode(MONGO_DECIMAL128_CODEC_ID, wire),
|
|
667
|
-
encode: (value) => decimal128Encode(MONGO_DECIMAL128_CODEC_ID, value),
|
|
668
|
-
encodeJson: (value) => decimal128EncodeJson(MONGO_DECIMAL128_CODEC_ID, value),
|
|
669
|
-
decodeJson: (json) => decimal128DecodeJson(MONGO_DECIMAL128_CODEC_ID, json)
|
|
670
|
-
});
|
|
671
|
-
/**
|
|
672
|
-
* BSON `binData`. The application value is a `Uint8Array`; its JSON form is unwrapped base64.
|
|
673
|
-
*/
|
|
674
|
-
const mongoBinaryCodec = mongoCodec({
|
|
675
|
-
typeId: MONGO_BINARY_CODEC_ID,
|
|
676
|
-
decode: (wire) => binaryDecode(MONGO_BINARY_CODEC_ID, wire),
|
|
677
|
-
encode: (value) => binaryEncode(MONGO_BINARY_CODEC_ID, value),
|
|
678
|
-
encodeJson: binaryEncodeJson,
|
|
679
|
-
decodeJson: (json) => binaryDecodeJson(MONGO_BINARY_CODEC_ID, json)
|
|
680
|
-
});
|
|
681
|
-
/**
|
|
682
|
-
* 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.
|
|
683
|
-
*/
|
|
684
|
-
const mongoJsonCodec = mongoCodec({
|
|
685
|
-
typeId: MONGO_JSON_CODEC_ID,
|
|
686
|
-
decode: (wire) => decodeJsonValue(wire),
|
|
687
|
-
encode: (value) => encodeJsonValue(value)
|
|
688
|
-
});
|
|
689
|
-
/**
|
|
690
|
-
* 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 JSON 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`.
|
|
691
|
-
*/
|
|
692
|
-
const mongoBsonCodec = mongoCodec({
|
|
693
|
-
typeId: MONGO_BSON_CODEC_ID,
|
|
694
|
-
decode: (wire) => decodeBsonValue(wire),
|
|
695
|
-
encode: (value) => encodeBsonValue(value),
|
|
696
|
-
encodeJson: encodeBsonJson,
|
|
697
|
-
decodeJson: decodeBsonJson
|
|
698
|
-
});
|
|
699
|
-
/**
|
|
700
|
-
* The canonical set of Mongo wire-type codecs.
|
|
701
|
-
*
|
|
702
|
-
* Single source of truth for both control- and runtime-plane adapter descriptors. Don't duplicate this list — import it.
|
|
703
|
-
*/
|
|
704
|
-
const mongoStandardCodecs = [
|
|
705
|
-
mongoObjectIdCodec,
|
|
706
|
-
mongoStringCodec,
|
|
707
|
-
mongoDoubleCodec,
|
|
708
|
-
mongoInt32Codec,
|
|
709
|
-
mongoBooleanCodec,
|
|
710
|
-
mongoDateCodec,
|
|
711
|
-
mongoVectorCodec,
|
|
712
|
-
mongoInt64Codec,
|
|
713
|
-
mongoInt64NumberCodec,
|
|
714
|
-
mongoDecimal128Codec,
|
|
715
|
-
mongoBinaryCodec,
|
|
716
|
-
mongoJsonCodec,
|
|
717
|
-
mongoBsonCodec
|
|
718
|
-
];
|
|
719
|
-
/**
|
|
720
|
-
* Build a {@link CodecDescriptor} for a Mongo wire-type codec.
|
|
721
|
-
*
|
|
722
|
-
* Wraps an existing {@link MongoCodec} instance into a descriptor whose factory hands out the same shared codec. Mongo's full migration to descriptor-first authoring is tracked under TML-2324; for now the descriptor view is composed from the existing `mongoCodec()` outputs.
|
|
723
|
-
*/
|
|
724
|
-
function descriptorFor(codec, metadata) {
|
|
725
|
-
const renderOutputType = blindCast(metadata.renderOutputType);
|
|
726
|
-
return {
|
|
727
|
-
codecId: codec.id,
|
|
728
|
-
dataType: metadata.dataType.id,
|
|
729
|
-
traits: metadata.traits,
|
|
730
|
-
paramsSchema: blindCast(metadata.dataType.params),
|
|
731
|
-
isParameterized: metadata.dataType.params !== void 0,
|
|
732
|
-
factory: blindCast(() => () => codec),
|
|
733
|
-
...ifDefined("renderOutputType", renderOutputType),
|
|
734
|
-
...ifDefined("renderValueLiteral", metadata.renderValueLiteral)
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
const renderVectorOutputType = (typeParams) => {
|
|
738
|
-
const length = typeParams["length"];
|
|
739
|
-
if (length === void 0) return void 0;
|
|
740
|
-
if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length) || length <= 0) throw mongoTargetError("RUNTIME.TYPE_PARAMS_INVALID", "renderOutputType: expected positive integer \"length\" for Vector", { meta: {
|
|
741
|
-
typeName: "Vector",
|
|
742
|
-
param: "length",
|
|
743
|
-
received: length
|
|
744
|
-
} });
|
|
745
|
-
return `Vector<${length}>`;
|
|
746
|
-
};
|
|
747
|
-
/**
|
|
748
|
-
* Mongo wire-type codec descriptors. Static metadata for `traits` and `renderOutputType` lives here (the descriptor shape) — `MongoCodec` itself is narrow and only carries the four conversion methods (TML-2357).
|
|
749
|
-
*/
|
|
750
|
-
const mongoCodecDescriptors = [
|
|
751
|
-
descriptorFor(mongoObjectIdCodec, {
|
|
752
|
-
dataType: mongoObjectId,
|
|
753
|
-
traits: ["equality"]
|
|
754
|
-
}),
|
|
755
|
-
descriptorFor(mongoStringCodec, {
|
|
756
|
-
dataType: mongoString,
|
|
757
|
-
traits: [
|
|
758
|
-
"equality",
|
|
759
|
-
"order",
|
|
760
|
-
"textual"
|
|
761
|
-
],
|
|
762
|
-
renderValueLiteral: renderTsLiteral
|
|
763
|
-
}),
|
|
764
|
-
descriptorFor(mongoDoubleCodec, {
|
|
765
|
-
dataType: mongoDouble,
|
|
766
|
-
traits: [
|
|
767
|
-
"equality",
|
|
768
|
-
"order",
|
|
769
|
-
"numeric"
|
|
770
|
-
],
|
|
771
|
-
renderValueLiteral: (value) => typeof value === "number" ? String(value) : void 0
|
|
772
|
-
}),
|
|
773
|
-
descriptorFor(mongoInt32Codec, {
|
|
774
|
-
dataType: mongoInt32,
|
|
775
|
-
traits: [
|
|
776
|
-
"equality",
|
|
777
|
-
"order",
|
|
778
|
-
"numeric"
|
|
779
|
-
],
|
|
780
|
-
renderValueLiteral: renderTsLiteral
|
|
781
|
-
}),
|
|
782
|
-
descriptorFor(mongoBooleanCodec, {
|
|
783
|
-
dataType: mongoBool,
|
|
784
|
-
traits: ["equality", "boolean"],
|
|
785
|
-
renderValueLiteral: renderTsLiteral
|
|
786
|
-
}),
|
|
787
|
-
descriptorFor(mongoDateCodec, {
|
|
788
|
-
dataType: mongoDate,
|
|
789
|
-
traits: ["equality", "order"]
|
|
790
|
-
}),
|
|
791
|
-
descriptorFor(mongoVectorCodec, {
|
|
792
|
-
dataType: mongoVector,
|
|
793
|
-
traits: ["equality"],
|
|
794
|
-
renderOutputType: renderVectorOutputType
|
|
795
|
-
}),
|
|
796
|
-
descriptorFor(mongoInt64Codec, {
|
|
797
|
-
dataType: mongoInt64,
|
|
798
|
-
traits: [
|
|
799
|
-
"equality",
|
|
800
|
-
"order",
|
|
801
|
-
"numeric"
|
|
802
|
-
],
|
|
803
|
-
renderValueLiteral: decimalTextBigintLiteral
|
|
804
|
-
}),
|
|
805
|
-
descriptorFor(mongoInt64NumberCodec, {
|
|
806
|
-
dataType: mongoInt64,
|
|
807
|
-
traits: [
|
|
808
|
-
"equality",
|
|
809
|
-
"order",
|
|
810
|
-
"numeric"
|
|
811
|
-
],
|
|
812
|
-
renderValueLiteral: decimalTextNumberLiteral
|
|
813
|
-
}),
|
|
814
|
-
descriptorFor(mongoDecimal128Codec, {
|
|
815
|
-
dataType: mongoDecimal128,
|
|
816
|
-
traits: [
|
|
817
|
-
"equality",
|
|
818
|
-
"order",
|
|
819
|
-
"numeric"
|
|
820
|
-
]
|
|
821
|
-
}),
|
|
822
|
-
descriptorFor(mongoBinaryCodec, {
|
|
823
|
-
dataType: mongoBinary,
|
|
824
|
-
traits: ["equality"]
|
|
825
|
-
}),
|
|
826
|
-
descriptorFor(mongoJsonCodec, {
|
|
827
|
-
dataType: mongoJson,
|
|
828
|
-
traits: []
|
|
829
|
-
}),
|
|
830
|
-
descriptorFor(mongoBsonCodec, {
|
|
831
|
-
dataType: mongoBson,
|
|
832
|
-
traits: []
|
|
833
|
-
})
|
|
834
|
-
];
|
|
835
|
-
/**
|
|
836
|
-
* Lookup descriptor metadata by codec id — used by tests and for descriptor-side reads of static metadata.
|
|
837
|
-
*/
|
|
838
|
-
function mongoDescriptorById(codecId) {
|
|
839
|
-
return mongoCodecDescriptors.find((d) => d.codecId === codecId);
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Build a {@link MongoCodecRegistry} preloaded with the standard Mongo wire-type codecs.
|
|
843
|
-
*
|
|
844
|
-
* Single point of truth for adapter-side codec construction: used by the legacy synchronous `createMongoAdapter()` factory and by the runtime adapter descriptor's `codecs()` getter. Userland code obtains a registry via the framework's execution-stack composition (see `createMongoExecutionContext`) instead of calling this directly.
|
|
845
|
-
*/
|
|
846
|
-
function buildStandardCodecRegistry() {
|
|
847
|
-
const registry = newMongoCodecRegistry();
|
|
848
|
-
for (const codec of mongoStandardCodecs) registry.register(codec);
|
|
849
|
-
return registry;
|
|
850
|
-
}
|
|
851
|
-
//#endregion
|
|
852
|
-
export { mongoStandardCodecs as i, mongoCodecDescriptors as n, mongoDescriptorById as r, buildStandardCodecRegistry as t };
|
|
853
|
-
|
|
854
|
-
//# sourceMappingURL=codecs-D6yLMoD2-Bn8-UhA5.mjs.map
|