@prisma/orm-target-mysql 8.0.0-rc.22-dev.11 → 8.0.0-rc.22-dev.12
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/README.md +2 -0
- package/dist/adapter.d.mts +4 -4
- package/dist/adapter.mjs +1 -1
- package/dist/adapter__codec-types.d.mts +2 -2
- package/dist/adapter__control.d.mts +1 -1
- package/dist/adapter__control.mjs +1 -1
- package/dist/adapter__runtime.d.mts +1 -1
- package/dist/adapter__runtime.mjs +17 -6
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/{codec-descriptor-Du6DSz-3-ytBCu_mq.mjs → codec-descriptor-3xp1XvVH-yVLnNzZ8.mjs} +5 -3
- package/dist/codec-descriptor-3xp1XvVH-yVLnNzZ8.mjs.map +1 -0
- package/dist/codec-ids-CrR9Xi7r-CarpqbNM.mjs +20 -0
- package/dist/codec-ids-CrR9Xi7r-CarpqbNM.mjs.map +1 -0
- package/dist/codec-ids-Dgh5IpML-76oBMuwK.d.mts +20 -0
- package/dist/codec-ids-Dgh5IpML-76oBMuwK.d.mts.map +1 -0
- package/dist/codec-types-BH5moCD9.d.mts +1 -0
- package/dist/codec-types-Bai_CFkk-Blx2GxCH.d.mts +31 -0
- package/dist/codec-types-Bai_CFkk-Blx2GxCH.d.mts.map +1 -0
- package/dist/codec-types-zzVcrnbk.d.mts +1 -0
- package/dist/codecs-BMidk26M-DsKq6wt5.d.mts +282 -0
- package/dist/codecs-BMidk26M-DsKq6wt5.d.mts.map +1 -0
- package/dist/codecs-BfiB79-5.mjs +750 -0
- package/dist/codecs-BfiB79-5.mjs.map +1 -0
- package/dist/codecs-C_twedMx.d.mts +36 -0
- package/dist/codecs-C_twedMx.d.mts.map +1 -0
- package/dist/{control-CgeXsxCR.mjs → control-5eVF1TXc.mjs} +2 -2
- package/dist/{control-CgeXsxCR.mjs.map → control-5eVF1TXc.mjs.map} +1 -1
- package/dist/{control-H2sjKXXS.mjs → control-BBhWaGnH.mjs} +24 -13
- package/dist/control-BBhWaGnH.mjs.map +1 -0
- package/dist/control-BvSM7mGR.d.mts +396 -0
- package/dist/control-BvSM7mGR.d.mts.map +1 -0
- package/dist/{control-Ez_PtlFI.d.mts → control-MoPFgSaQ.d.mts} +2 -2
- package/dist/{control-Ez_PtlFI.d.mts.map → control-MoPFgSaQ.d.mts.map} +1 -1
- package/dist/data-type-entries-C7VH2IHc-D1d5I8zF.mjs +59 -0
- package/dist/data-type-entries-C7VH2IHc-D1d5I8zF.mjs.map +1 -0
- package/dist/{data-types-SXrh0Lou.d.mts → data-types-C-rfxpgB.d.mts} +2 -2
- package/dist/data-types-C-rfxpgB.d.mts.map +1 -0
- package/dist/data-types-D2HAT-Qf-CRI506c0.d.mts +88 -0
- package/dist/data-types-D2HAT-Qf-CRI506c0.d.mts.map +1 -0
- package/dist/data-types-DOaaPS93-DBkMJyh1.mjs +289 -0
- package/dist/data-types-DOaaPS93-DBkMJyh1.mjs.map +1 -0
- package/dist/date-time-now-generators-DY-8Bodc-DcQ3h4Fg.mjs +72 -0
- package/dist/date-time-now-generators-DY-8Bodc-DcQ3h4Fg.mjs.map +1 -0
- package/dist/{default-normalizer-BDUgHXUn-Xk7HQJuI.mjs → default-normalizer-C8pc7SbL-CKgOEnGl.mjs} +22 -12
- package/dist/default-normalizer-C8pc7SbL-CKgOEnGl.mjs.map +1 -0
- package/dist/{default-normalizer-BBhGpw7r.d.mts → default-normalizer-CGIwQiKB.d.mts} +4 -4
- package/dist/{default-normalizer-BBhGpw7r.d.mts.map → default-normalizer-CGIwQiKB.d.mts.map} +1 -1
- package/dist/descriptor-meta-CsMPRsxp-DhK87vlc.mjs +352 -0
- package/dist/descriptor-meta-CsMPRsxp-DhK87vlc.mjs.map +1 -0
- package/dist/driver.mjs +1 -1
- package/dist/driver__control.mjs +1 -1
- package/dist/driver__runtime.mjs +1 -1
- package/dist/errors-Cng94tYg-D02Eud2d.mjs +87 -0
- package/dist/errors-Cng94tYg-D02Eud2d.mjs.map +1 -0
- package/dist/{errors-BYhjQT7y.d.mts → errors-DfrC_yfG.d.mts} +2 -2
- package/dist/{errors-BYhjQT7y.d.mts.map → errors-DfrC_yfG.d.mts.map} +1 -1
- package/dist/{marker-lock-CmGvN4hw-Com29AtQ.mjs → marker-lock-Bwew7cAs-CZ20Y_tA.mjs} +3 -3
- package/dist/{marker-lock-CmGvN4hw-Com29AtQ.mjs.map → marker-lock-Bwew7cAs-CZ20Y_tA.mjs.map} +1 -1
- package/dist/{marker-read-Cf80LSbG-BZaJ8Ll6.mjs → marker-read-Cf80LSbG-CUp3v1e5.mjs} +3 -3
- package/dist/{marker-read-Cf80LSbG-BZaJ8Ll6.mjs.map → marker-read-Cf80LSbG-CUp3v1e5.mjs.map} +1 -1
- package/dist/mysql-contract-serializer-BnTKRSsN-B2O3EreV.mjs +35 -0
- package/dist/mysql-contract-serializer-BnTKRSsN-B2O3EreV.mjs.map +1 -0
- package/dist/{mysql-contract-serializer-DLv0uW_f-Cg4A43Ry.mjs → mysql-database-CHl9-oSL-CWZLDXt6.mjs} +39 -40
- package/dist/mysql-database-CHl9-oSL-CWZLDXt6.mjs.map +1 -0
- package/dist/now-expression-DVD18CUc-00buJUto.mjs +38 -0
- package/dist/now-expression-DVD18CUc-00buJUto.mjs.map +1 -0
- package/dist/{pack-DXsOvRJn.d.mts → pack-BXvLVBWP.d.mts} +394 -14
- package/dist/{pack-DXsOvRJn.d.mts.map → pack-BXvLVBWP.d.mts.map} +1 -1
- package/dist/require-temporal-DeDQhbTn-Bxc65WbA.mjs +16 -0
- package/dist/require-temporal-DeDQhbTn-Bxc65WbA.mjs.map +1 -0
- package/dist/{runner-BaBQoXiU-C7ln-4b2.mjs → runner-C39AEe6--BVG3xPYw.mjs} +7 -7
- package/dist/{runner-BaBQoXiU-C7ln-4b2.mjs.map → runner-C39AEe6--BVG3xPYw.mjs.map} +1 -1
- package/dist/{runtime-CeuRr9nE.d.mts → runtime-ClRDfPiY.d.mts} +2 -2
- package/dist/{runtime-CeuRr9nE.d.mts.map → runtime-ClRDfPiY.d.mts.map} +1 -1
- package/dist/runtime-CrB5DXx4.d.mts +54 -0
- package/dist/runtime-CrB5DXx4.d.mts.map +1 -0
- package/dist/{sql-utils-Db0IQO_B-PaULnfrE.mjs → sql-utils-Cmv_TVa8-BetrIUcj.mjs} +3 -3
- package/dist/{sql-utils-Db0IQO_B-PaULnfrE.mjs.map → sql-utils-Cmv_TVa8-BetrIUcj.mjs.map} +1 -1
- package/dist/{sql-utils-RW0vJvDl.mjs → sql-utils-bD4SfgX0.mjs} +2 -2
- package/dist/{sql-utils-RW0vJvDl.mjs.map → sql-utils-bD4SfgX0.mjs.map} +1 -1
- package/dist/{statement-DC62oiSx-DTx1JaP7.mjs → statement-DC62oiSx-Buzptbpk.mjs} +5 -5
- package/dist/{statement-DC62oiSx-DTx1JaP7.mjs.map → statement-DC62oiSx-Buzptbpk.mjs.map} +1 -1
- package/dist/target.d.mts +14 -13
- package/dist/target.mjs +17 -13
- package/dist/target__codec-descriptor.mjs +1 -1
- package/dist/target__codec-ids.d.mts +2 -2
- package/dist/target__codec-ids.mjs +2 -2
- package/dist/target__codec-types.d.mts +2 -2
- package/dist/target__codecs.d.mts +3 -3
- package/dist/target__codecs.mjs +3 -2
- package/dist/target__control.d.mts +2 -2
- package/dist/target__control.mjs +38 -32
- package/dist/target__control.mjs.map +1 -1
- package/dist/target__data-types.d.mts +3 -3
- package/dist/target__data-types.mjs +3 -3
- package/dist/target__default-normalizer.d.mts +1 -1
- package/dist/target__default-normalizer.mjs +1 -1
- package/dist/target__errors.d.mts +1 -1
- package/dist/target__errors.mjs +1 -1
- package/dist/target__marker-lock.mjs +1 -1
- package/dist/target__migration.mjs +1 -1
- package/dist/target__pack.d.mts +1 -1
- package/dist/target__pack.mjs +1 -1
- package/dist/target__runtime.d.mts +2 -2
- package/dist/target__runtime.mjs +3 -3
- package/dist/target__runtime.mjs.map +1 -1
- package/dist/target__sql-utils.mjs +2 -2
- package/dist/target__types.d.mts +2 -0
- package/dist/target__types.mjs +2 -0
- package/dist/{control-_4epnrIW.d.mts → types-CgrFHUdk.d.mts} +3 -8
- package/dist/types-CgrFHUdk.d.mts.map +1 -0
- package/package.json +18 -12
- package/dist/codec-descriptor-Du6DSz-3-ytBCu_mq.mjs.map +0 -1
- package/dist/codec-ids-cjxtOcLM-vFeQhgPm.mjs +0 -10
- package/dist/codec-ids-cjxtOcLM-vFeQhgPm.mjs.map +0 -1
- package/dist/codec-ids-sMOU8F-B-BQbCq2dr.d.mts +0 -10
- package/dist/codec-ids-sMOU8F-B-BQbCq2dr.d.mts.map +0 -1
- package/dist/codec-types-Bd7DL1Mr-CZWNfnp9.d.mts +0 -21
- package/dist/codec-types-Bd7DL1Mr-CZWNfnp9.d.mts.map +0 -1
- package/dist/codec-types-Bo3Jfilx.d.mts +0 -1
- package/dist/codec-types-Ja2kLzLS.d.mts +0 -1
- package/dist/codecs-C00kjHgh.mjs +0 -282
- package/dist/codecs-C00kjHgh.mjs.map +0 -1
- package/dist/codecs-CO_VNEYU-CwAnKzRs.d.mts +0 -102
- package/dist/codecs-CO_VNEYU-CwAnKzRs.d.mts.map +0 -1
- package/dist/codecs-DM61agRr.d.mts +0 -21
- package/dist/codecs-DM61agRr.d.mts.map +0 -1
- package/dist/control-H2sjKXXS.mjs.map +0 -1
- package/dist/control-_4epnrIW.d.mts.map +0 -1
- package/dist/data-type-entries-B0AoBozh-f9AEUIUQ.mjs +0 -42
- package/dist/data-type-entries-B0AoBozh-f9AEUIUQ.mjs.map +0 -1
- package/dist/data-types-BpihGKoK-BMW-m4EN.d.mts +0 -52
- package/dist/data-types-BpihGKoK-BMW-m4EN.d.mts.map +0 -1
- package/dist/data-types-Dv9gwVRV-BZPzCWZk.mjs +0 -181
- package/dist/data-types-Dv9gwVRV-BZPzCWZk.mjs.map +0 -1
- package/dist/data-types-SXrh0Lou.d.mts.map +0 -1
- package/dist/default-normalizer-BDUgHXUn-Xk7HQJuI.mjs.map +0 -1
- package/dist/descriptor-meta-D7tc0iue-C4W7o0Av.mjs +0 -82
- package/dist/descriptor-meta-D7tc0iue-C4W7o0Av.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-Cur6umHo-C_4rsCGC.mjs +0 -20
- package/dist/descriptor-meta-runtime-Cur6umHo-C_4rsCGC.mjs.map +0 -1
- package/dist/errors-rvH_F2Yj-BQrO_--u.mjs +0 -20
- package/dist/errors-rvH_F2Yj-BQrO_--u.mjs.map +0 -1
- package/dist/mysql-contract-serializer-DLv0uW_f-Cg4A43Ry.mjs.map +0 -1
- package/dist/runtime-Cl0BbTZq.d.mts +0 -22
- package/dist/runtime-Cl0BbTZq.d.mts.map +0 -1
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import { a as mysqlCodec, n as buildMysqlCodecDescriptorRegistry, r as identityJsonProjection, t as MysqlCodecDescriptor } from "./codec-descriptor-3xp1XvVH-yVLnNzZ8.mjs";
|
|
2
|
+
import { a as MYSQL_DATE_STRING_CODEC_ID, c as MYSQL_ENUM_CODEC_ID, d as MYSQL_TIMESTAMP_DATE_CODEC_ID, f as MYSQL_TIMESTAMP_STRING_CODEC_ID, h as MYSQL_TIME_TEMPORAL_CODEC_ID, i as MYSQL_DATETIME_TEMPORAL_CODEC_ID, l as MYSQL_INT_CODEC_ID, m as MYSQL_TIME_STRING_CODEC_ID, n as MYSQL_DATETIME_CODEC_ID, o as MYSQL_DATE_TEMPORAL_CODEC_ID, p as MYSQL_TIMESTAMP_TEMPORAL_CODEC_ID, r as MYSQL_DATETIME_STRING_CODEC_ID, s as MYSQL_DURATION_STRING_CODEC_ID, t as MYSQL_BIGINT_CODEC_ID, u as MYSQL_TEXT_CODEC_ID } from "./codec-ids-CrR9Xi7r-CarpqbNM.mjs";
|
|
3
|
+
import { c as mysqlQueryNotYetSupported, n as errorDateTimeUnwritable, o as errorTemporalWrongType, r as errorTemporalNonIsoCalendar, s as mysqlError, t as errorDateTimeUnreadable } from "./errors-Cng94tYg-D02Eud2d.mjs";
|
|
4
|
+
import { C as mysqlTimestampText, S as mysqlTimestamp, _ as mysqlInt, b as mysqlTime, c as mysqlDateText, d as mysqlDatetimeText, f as mysqlDuration, g as mysqlEnumParams, h as mysqlEnum, i as mysqlChar, l as mysqlDatetime, m as mysqlDurationText, p as mysqlDurationParams, r as mysqlBigint, s as mysqlDate, u as mysqlDatetimeParams, v as mysqlText, w as mysqlVarchar, x as mysqlTimeText } from "./data-types-DOaaPS93-DBkMJyh1.mjs";
|
|
5
|
+
import { t as requireTemporal } from "./require-temporal-DeDQhbTn-Bxc65WbA.mjs";
|
|
6
|
+
import { CodecImpl, dateTimeStoredText, decimalTextBigintLiteral, refuseJsonValue, renderTsLiteral } from "@prisma/orm-framework/components/codec";
|
|
7
|
+
import { CastExpr, SqlCharCodec, SqlRawCodec, SqlVarcharCodec, sqlCharDescriptor, sqlRawDescriptor, sqlVarcharDescriptor } from "@prisma/orm-family-sql/relational-core/ast";
|
|
8
|
+
import { sqlRawDataType } from "@prisma/orm-family-sql/contract/data-type";
|
|
9
|
+
import { hasDigitsBelow, hasDigitsBelowAMillisecond, isValidDate } from "@prisma/orm-framework/type-implementations/date";
|
|
10
|
+
import { describeValue, temporalFromText, temporalToText, withoutUtcDesignator } from "@prisma/orm-framework/type-implementations/temporal-text";
|
|
11
|
+
import { extractCodecLookup } from "@prisma/orm-framework/components/control";
|
|
12
|
+
import { buildCodecDescriptorRegistry } from "@prisma/orm-family-sql/relational-core/codec-descriptor-registry";
|
|
13
|
+
//#region ../../../3-targets/mysql/1-target/dist/codecs.mjs
|
|
14
|
+
function messageOf(cause) {
|
|
15
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
16
|
+
}
|
|
17
|
+
/** The text MySQL reads for a stored date and time, `2024-01-02 03:04:05.5`. */
|
|
18
|
+
function mysqlWireText(stored) {
|
|
19
|
+
return stored.replace("T", " ");
|
|
20
|
+
}
|
|
21
|
+
/** The UTC date and time without an offset that ISO 8601 text with a UTC offset names, in the form `stored` writes. Throws when the text names no instant, or one `stored` refuses. */
|
|
22
|
+
function utcDateTimeOfInstantText(codecId, text, stored) {
|
|
23
|
+
return stored(withoutUtcDesignator(dateTimeStoredText(text, {
|
|
24
|
+
shape: "instant",
|
|
25
|
+
ownerId: codecId
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
/** The stored form `stored` writes for a value an application wrote; a value it refuses is refused as `RUNTIME.ENCODE_FAILED`. */
|
|
29
|
+
function storedTextForWrite(codecId, value, stored) {
|
|
30
|
+
if (typeof value !== "string") throw errorDateTimeUnwritable({
|
|
31
|
+
codecId,
|
|
32
|
+
received: describeValue(value),
|
|
33
|
+
detail: "It writes ISO 8601 text."
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
return stored(value);
|
|
37
|
+
} catch (cause) {
|
|
38
|
+
throw errorDateTimeUnwritable({
|
|
39
|
+
codecId,
|
|
40
|
+
received: JSON.stringify(value),
|
|
41
|
+
detail: messageOf(cause),
|
|
42
|
+
cause
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The stored form of the text MySQL returned for a row, as `stored` reads it; text `stored` refuses is refused as `RUNTIME.DECODE_FAILED`. */
|
|
47
|
+
function storedTextFromWire(codecId, wire, stored) {
|
|
48
|
+
if (typeof wire !== "string") throw errorDateTimeUnreadable({
|
|
49
|
+
codecId,
|
|
50
|
+
value: String(wire),
|
|
51
|
+
detail: `MySQL returned ${describeValue(wire)}, not text.`
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
return stored(wire);
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
throw errorDateTimeUnreadable({
|
|
57
|
+
codecId,
|
|
58
|
+
value: wire,
|
|
59
|
+
detail: messageOf(cause),
|
|
60
|
+
cause
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The Temporal value that stored text names, read with `parse`. */
|
|
65
|
+
function temporalFromStoredText(identity, text, parse) {
|
|
66
|
+
const read = temporalFromText(requireTemporal({
|
|
67
|
+
codecId: identity.codecId,
|
|
68
|
+
operation: "decode"
|
|
69
|
+
}), text, parse);
|
|
70
|
+
if (read.kind === "unreadable") throw errorDateTimeUnreadable({
|
|
71
|
+
codecId: identity.codecId,
|
|
72
|
+
value: text,
|
|
73
|
+
detail: `${identity.temporalTag} cannot hold it: ${read.detail}. Use ${identity.stringType} to read the column as text.`,
|
|
74
|
+
cause: read.cause
|
|
75
|
+
});
|
|
76
|
+
return read.value;
|
|
77
|
+
}
|
|
78
|
+
/** The stored form of a Temporal value, as `stored` writes its ISO text. A value of another kind, in a calendar other than ISO 8601, or with digits below a microsecond, which MySQL does not hold, is refused. */
|
|
79
|
+
function storedTextOfTemporal(identity, value, stored) {
|
|
80
|
+
const encoded = temporalToText(value, identity.temporalTag);
|
|
81
|
+
switch (encoded.kind) {
|
|
82
|
+
case "wrong-type": throw errorTemporalWrongType(identity.codecId, identity.temporalTag, identity.stringType, encoded.received);
|
|
83
|
+
case "non-iso-calendar": throw errorTemporalNonIsoCalendar(identity.codecId, encoded.calendarId);
|
|
84
|
+
case "text":
|
|
85
|
+
if (hasDigitsBelow(encoded.text, 6)) throw errorDateTimeUnwritable({
|
|
86
|
+
codecId: identity.codecId,
|
|
87
|
+
received: `the ${identity.temporalTag} ${encoded.text}`,
|
|
88
|
+
detail: "It has digits below a microsecond, and MySQL holds microseconds at most. Round it first, as in value.round({ smallestUnit: 'microsecond', roundingMode: 'trunc' })."
|
|
89
|
+
});
|
|
90
|
+
return storedTextForWrite(identity.codecId, encoded.text, stored);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const WIRE_DATE_TIME = /^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2}(?:\.\d+)?)$/;
|
|
94
|
+
/** The instant the text MySQL sends for a `datetime` or a `timestamp` names in UTC: every session runs in UTC, so the text holds no time zone of its own. */
|
|
95
|
+
function dateOfWireText(codecId, wire) {
|
|
96
|
+
const match = WIRE_DATE_TIME.exec(wire);
|
|
97
|
+
const date = match === null ? void 0 : /* @__PURE__ */ new Date(`${match[1]}T${match[2]}Z`);
|
|
98
|
+
if (date === void 0 || !isValidDate(date)) throw mysqlError("RUNTIME.DECODE_FAILED", `${codecId} wire value must be a date and time as MySQL prints it`, { meta: {
|
|
99
|
+
codecId,
|
|
100
|
+
received: String(wire)
|
|
101
|
+
} });
|
|
102
|
+
return date;
|
|
103
|
+
}
|
|
104
|
+
/** The text MySQL reads for a `Date` in UTC, with millisecond digits. An Invalid Date, and an instant `stored` refuses, are refused. */
|
|
105
|
+
function wireTextOfDate(codecId, value, stored) {
|
|
106
|
+
if (!isValidDate(value)) throw mysqlError("RUNTIME.ENCODE_FAILED", `${codecId} value must be a valid Date`, { meta: {
|
|
107
|
+
codecId,
|
|
108
|
+
received: String(value)
|
|
109
|
+
} });
|
|
110
|
+
const text = value.toISOString();
|
|
111
|
+
storedTextForWrite(codecId, text, (instant) => utcDateTimeOfInstantText(codecId, instant, stored));
|
|
112
|
+
return mysqlWireText(withoutUtcDesignator(text));
|
|
113
|
+
}
|
|
114
|
+
/** The fraction digits a column with `params` holds: its `precision`, or 0, which MySQL holds when none is written. */
|
|
115
|
+
function precisionOf(params) {
|
|
116
|
+
const precision = params["precision"];
|
|
117
|
+
return typeof precision === "number" ? precision : 0;
|
|
118
|
+
}
|
|
119
|
+
/** `stored`, a contract value of a column with `params`; a value with more fraction digits than the column holds, which MySQL would round, is refused. */
|
|
120
|
+
function storedWithinPrecision(codecId, stored, params) {
|
|
121
|
+
const precision = precisionOf(params);
|
|
122
|
+
if (!hasDigitsBelow(stored, precision)) return stored;
|
|
123
|
+
return refuseJsonValue(codecId, `a value with at most ${precision} ${precision === 1 ? "fraction digit" : "fraction digits"} of a second, which precision ${precision} holds without rounding`, stored);
|
|
124
|
+
}
|
|
125
|
+
/** Wire text with its fraction cut to the digits the column's `precision` holds: MySQL rounds a value to its column, which could carry it to the next second, day or past the column's range. A codec reference that names no precision, as a raw parameter writes, describes no column, so its value is written whole. */
|
|
126
|
+
function roundedDownToPrecision(text, params) {
|
|
127
|
+
const precision = params["precision"];
|
|
128
|
+
if (typeof precision !== "number") return text;
|
|
129
|
+
return text.replace(/\.(\d+)$/, (_fraction, digits) => precision === 0 ? "" : `.${digits.slice(0, precision)}`);
|
|
130
|
+
}
|
|
131
|
+
/** The stored form of an instant written as ISO 8601 text with a UTC offset: its UTC date and time, in the form `stored` writes. */
|
|
132
|
+
const instantIn = (codecId, stored) => (text) => utcDateTimeOfInstantText(codecId, text, stored);
|
|
133
|
+
/** Reads the text MySQL returns for a row in any year: a column's range is refused on write only. */
|
|
134
|
+
const anyYear = (ownerId, shape) => (text) => dateTimeStoredText(text, {
|
|
135
|
+
shape,
|
|
136
|
+
ownerId
|
|
137
|
+
});
|
|
138
|
+
const datetimeRow = anyYear(mysqlDatetime.id, "dateTime");
|
|
139
|
+
const timestampRow = anyYear(mysqlTimestamp.id, "dateTime");
|
|
140
|
+
const dateRow = anyYear(mysqlDate.id, "date");
|
|
141
|
+
const DATETIME_TEMPORAL = {
|
|
142
|
+
codecId: MYSQL_DATETIME_TEMPORAL_CODEC_ID,
|
|
143
|
+
temporalTag: "Temporal.Instant",
|
|
144
|
+
stringType: "DatetimeString"
|
|
145
|
+
};
|
|
146
|
+
const TIMESTAMP_TEMPORAL = {
|
|
147
|
+
codecId: MYSQL_TIMESTAMP_TEMPORAL_CODEC_ID,
|
|
148
|
+
temporalTag: "Temporal.Instant",
|
|
149
|
+
stringType: "TimestampString"
|
|
150
|
+
};
|
|
151
|
+
const DATE_TEMPORAL = {
|
|
152
|
+
codecId: MYSQL_DATE_TEMPORAL_CODEC_ID,
|
|
153
|
+
temporalTag: "Temporal.PlainDate",
|
|
154
|
+
stringType: "DateString"
|
|
155
|
+
};
|
|
156
|
+
const TIME_TEMPORAL = {
|
|
157
|
+
codecId: MYSQL_TIME_TEMPORAL_CODEC_ID,
|
|
158
|
+
temporalTag: "Temporal.PlainTime",
|
|
159
|
+
stringType: "TimeString"
|
|
160
|
+
};
|
|
161
|
+
const instantOf = (identity, stored) => temporalFromStoredText(identity, `${stored}Z`, (temporal, text) => temporal.Instant.from(text));
|
|
162
|
+
/** A MySQL `timestamp` as a JavaScript `Date`, read and written in UTC. */
|
|
163
|
+
var MysqlTimestampDateCodec = class extends CodecImpl {
|
|
164
|
+
async toWire(value, _ctx) {
|
|
165
|
+
return roundedDownToPrecision(wireTextOfDate(this.id, value, mysqlTimestampText), this.dataTypeParams);
|
|
166
|
+
}
|
|
167
|
+
async fromWire(wire, _ctx) {
|
|
168
|
+
return dateOfWireText(this.id, wire);
|
|
169
|
+
}
|
|
170
|
+
fromDataTypeValue(value) {
|
|
171
|
+
const stored = storedWithinPrecision(this.id, value.value, this.dataTypeParams);
|
|
172
|
+
if (hasDigitsBelowAMillisecond(stored)) return refuseJsonValue(this.id, `a timestamp with no digits below a millisecond, which a Date drops: ${JSON.stringify(value.value)} has them`, value.value);
|
|
173
|
+
return /* @__PURE__ */ new Date(`${stored}Z`);
|
|
174
|
+
}
|
|
175
|
+
toDataTypeValue(input) {
|
|
176
|
+
return this.dataTypeValueOf(input.toISOString().replace("Z", ""));
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var MysqlTimestampDateDescriptor = class extends MysqlCodecDescriptor {
|
|
180
|
+
dataType = mysqlTimestamp.id;
|
|
181
|
+
codecId = MYSQL_TIMESTAMP_DATE_CODEC_ID;
|
|
182
|
+
traits = ["equality", "order"];
|
|
183
|
+
paramsSchema = mysqlDatetimeParams;
|
|
184
|
+
jsonProjection(expression) {
|
|
185
|
+
return identityJsonProjection(expression);
|
|
186
|
+
}
|
|
187
|
+
factory(params) {
|
|
188
|
+
return () => new MysqlTimestampDateCodec(this, mysqlTimestamp, params);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const mysqlTimestampDateDescriptor = new MysqlTimestampDateDescriptor();
|
|
192
|
+
/** An instant read as `Temporal.Instant` from a `datetime` that holds it in UTC. */
|
|
193
|
+
var MysqlDatetimeTemporalCodec = class extends CodecImpl {
|
|
194
|
+
async toWire(value, _ctx) {
|
|
195
|
+
return roundedDownToPrecision(mysqlWireText(this.stored(value)), this.dataTypeParams);
|
|
196
|
+
}
|
|
197
|
+
async fromWire(wire, _ctx) {
|
|
198
|
+
return instantOf(DATETIME_TEMPORAL, storedTextFromWire(this.id, wire, datetimeRow));
|
|
199
|
+
}
|
|
200
|
+
fromDataTypeValue(value) {
|
|
201
|
+
return instantOf(DATETIME_TEMPORAL, storedWithinPrecision(this.id, value.value, this.dataTypeParams));
|
|
202
|
+
}
|
|
203
|
+
toDataTypeValue(input) {
|
|
204
|
+
return this.dataTypeValueOf(this.stored(input));
|
|
205
|
+
}
|
|
206
|
+
stored(value) {
|
|
207
|
+
return storedTextOfTemporal(DATETIME_TEMPORAL, value, instantIn(this.id, mysqlDatetimeText));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var MysqlDatetimeTemporalDescriptor = class extends MysqlCodecDescriptor {
|
|
211
|
+
dataType = mysqlDatetime.id;
|
|
212
|
+
codecId = MYSQL_DATETIME_TEMPORAL_CODEC_ID;
|
|
213
|
+
traits = ["equality", "order"];
|
|
214
|
+
paramsSchema = mysqlDatetimeParams;
|
|
215
|
+
jsonProjection(expression) {
|
|
216
|
+
return identityJsonProjection(expression);
|
|
217
|
+
}
|
|
218
|
+
factory(params) {
|
|
219
|
+
return () => new MysqlDatetimeTemporalCodec(this, mysqlDatetime, params);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const mysqlDatetimeTemporalDescriptor = new MysqlDatetimeTemporalDescriptor();
|
|
223
|
+
/** An instant read as `Temporal.Instant` from a `timestamp`. */
|
|
224
|
+
var MysqlTimestampTemporalCodec = class extends CodecImpl {
|
|
225
|
+
async toWire(value, _ctx) {
|
|
226
|
+
return roundedDownToPrecision(mysqlWireText(this.stored(value)), this.dataTypeParams);
|
|
227
|
+
}
|
|
228
|
+
async fromWire(wire, _ctx) {
|
|
229
|
+
return instantOf(TIMESTAMP_TEMPORAL, storedTextFromWire(this.id, wire, timestampRow));
|
|
230
|
+
}
|
|
231
|
+
fromDataTypeValue(value) {
|
|
232
|
+
return instantOf(TIMESTAMP_TEMPORAL, storedWithinPrecision(this.id, value.value, this.dataTypeParams));
|
|
233
|
+
}
|
|
234
|
+
toDataTypeValue(input) {
|
|
235
|
+
return this.dataTypeValueOf(this.stored(input));
|
|
236
|
+
}
|
|
237
|
+
stored(value) {
|
|
238
|
+
return storedTextOfTemporal(TIMESTAMP_TEMPORAL, value, instantIn(this.id, mysqlTimestampText));
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var MysqlTimestampTemporalDescriptor = class extends MysqlCodecDescriptor {
|
|
242
|
+
dataType = mysqlTimestamp.id;
|
|
243
|
+
codecId = MYSQL_TIMESTAMP_TEMPORAL_CODEC_ID;
|
|
244
|
+
traits = ["equality", "order"];
|
|
245
|
+
paramsSchema = mysqlDatetimeParams;
|
|
246
|
+
jsonProjection(expression) {
|
|
247
|
+
return identityJsonProjection(expression);
|
|
248
|
+
}
|
|
249
|
+
factory(params) {
|
|
250
|
+
return () => new MysqlTimestampTemporalCodec(this, mysqlTimestamp, params);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const mysqlTimestampTemporalDescriptor = new MysqlTimestampTemporalDescriptor();
|
|
254
|
+
/** The literal of the instant text a string codec reads from a stored date and time, which has no offset. */
|
|
255
|
+
function renderInstantTextLiteral(value) {
|
|
256
|
+
return typeof value === "string" ? renderTsLiteral(`${value}Z`) : void 0;
|
|
257
|
+
}
|
|
258
|
+
/** An instant read as ISO 8601 text in UTC, `2024-01-01T00:00:00.5Z`, from a `datetime`. A write takes ISO 8601 text with any UTC offset. */
|
|
259
|
+
var MysqlDatetimeStringCodec = class extends CodecImpl {
|
|
260
|
+
async toWire(value, _ctx) {
|
|
261
|
+
return roundedDownToPrecision(mysqlWireText(storedTextForWrite(this.id, value, instantIn(this.id, mysqlDatetimeText))), this.dataTypeParams);
|
|
262
|
+
}
|
|
263
|
+
async fromWire(wire, _ctx) {
|
|
264
|
+
return `${storedTextFromWire(this.id, wire, datetimeRow)}Z`;
|
|
265
|
+
}
|
|
266
|
+
fromDataTypeValue(value) {
|
|
267
|
+
return `${storedWithinPrecision(this.id, value.value, this.dataTypeParams)}Z`;
|
|
268
|
+
}
|
|
269
|
+
toDataTypeValue(input) {
|
|
270
|
+
return this.dataTypeValueOf(instantIn(this.id, mysqlDatetimeText)(input));
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var MysqlDatetimeStringDescriptor = class extends MysqlCodecDescriptor {
|
|
274
|
+
dataType = mysqlDatetime.id;
|
|
275
|
+
codecId = MYSQL_DATETIME_STRING_CODEC_ID;
|
|
276
|
+
traits = ["equality", "order"];
|
|
277
|
+
paramsSchema = mysqlDatetimeParams;
|
|
278
|
+
renderValueLiteral(value) {
|
|
279
|
+
return renderInstantTextLiteral(value);
|
|
280
|
+
}
|
|
281
|
+
jsonProjection(expression) {
|
|
282
|
+
return identityJsonProjection(expression);
|
|
283
|
+
}
|
|
284
|
+
factory(params) {
|
|
285
|
+
return () => new MysqlDatetimeStringCodec(this, mysqlDatetime, params);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const mysqlDatetimeStringDescriptor = new MysqlDatetimeStringDescriptor();
|
|
289
|
+
/** An instant read as ISO 8601 text in UTC, `2024-01-01T00:00:00.5Z`, from a `timestamp`. A write takes ISO 8601 text with any UTC offset. */
|
|
290
|
+
var MysqlTimestampStringCodec = class extends CodecImpl {
|
|
291
|
+
async toWire(value, _ctx) {
|
|
292
|
+
return roundedDownToPrecision(mysqlWireText(storedTextForWrite(this.id, value, instantIn(this.id, mysqlTimestampText))), this.dataTypeParams);
|
|
293
|
+
}
|
|
294
|
+
async fromWire(wire, _ctx) {
|
|
295
|
+
return `${storedTextFromWire(this.id, wire, timestampRow)}Z`;
|
|
296
|
+
}
|
|
297
|
+
fromDataTypeValue(value) {
|
|
298
|
+
return `${storedWithinPrecision(this.id, value.value, this.dataTypeParams)}Z`;
|
|
299
|
+
}
|
|
300
|
+
toDataTypeValue(input) {
|
|
301
|
+
return this.dataTypeValueOf(instantIn(this.id, mysqlTimestampText)(input));
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var MysqlTimestampStringDescriptor = class extends MysqlCodecDescriptor {
|
|
305
|
+
dataType = mysqlTimestamp.id;
|
|
306
|
+
codecId = MYSQL_TIMESTAMP_STRING_CODEC_ID;
|
|
307
|
+
traits = ["equality", "order"];
|
|
308
|
+
paramsSchema = mysqlDatetimeParams;
|
|
309
|
+
renderValueLiteral(value) {
|
|
310
|
+
return renderInstantTextLiteral(value);
|
|
311
|
+
}
|
|
312
|
+
jsonProjection(expression) {
|
|
313
|
+
return identityJsonProjection(expression);
|
|
314
|
+
}
|
|
315
|
+
factory(params) {
|
|
316
|
+
return () => new MysqlTimestampStringCodec(this, mysqlTimestamp, params);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const mysqlTimestampStringDescriptor = new MysqlTimestampStringDescriptor();
|
|
320
|
+
/** A calendar date read as ISO 8601 text, `2024-02-29`. */
|
|
321
|
+
var MysqlDateStringCodec = class extends CodecImpl {
|
|
322
|
+
async toWire(value, _ctx) {
|
|
323
|
+
return storedTextForWrite(this.id, value, mysqlDateText);
|
|
324
|
+
}
|
|
325
|
+
async fromWire(wire, _ctx) {
|
|
326
|
+
return storedTextFromWire(this.id, wire, dateRow);
|
|
327
|
+
}
|
|
328
|
+
fromDataTypeValue(value) {
|
|
329
|
+
return value.value;
|
|
330
|
+
}
|
|
331
|
+
toDataTypeValue(input) {
|
|
332
|
+
return this.storedDataTypeValueOf(input);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var MysqlDateStringDescriptor = class extends MysqlCodecDescriptor {
|
|
336
|
+
dataType = mysqlDate.id;
|
|
337
|
+
codecId = MYSQL_DATE_STRING_CODEC_ID;
|
|
338
|
+
traits = ["equality", "order"];
|
|
339
|
+
paramsSchema = void 0;
|
|
340
|
+
renderValueLiteral(value) {
|
|
341
|
+
return renderTsLiteral(value);
|
|
342
|
+
}
|
|
343
|
+
jsonProjection(expression) {
|
|
344
|
+
return identityJsonProjection(expression);
|
|
345
|
+
}
|
|
346
|
+
factory() {
|
|
347
|
+
return () => new MysqlDateStringCodec(this, mysqlDate);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const mysqlDateStringDescriptor = new MysqlDateStringDescriptor();
|
|
351
|
+
/** A calendar date read as `Temporal.PlainDate`. */
|
|
352
|
+
var MysqlDateTemporalCodec = class extends CodecImpl {
|
|
353
|
+
async toWire(value, _ctx) {
|
|
354
|
+
return storedTextOfTemporal(DATE_TEMPORAL, value, mysqlDateText);
|
|
355
|
+
}
|
|
356
|
+
async fromWire(wire, _ctx) {
|
|
357
|
+
return this.plainDateOf(storedTextFromWire(this.id, wire, dateRow));
|
|
358
|
+
}
|
|
359
|
+
fromDataTypeValue(value) {
|
|
360
|
+
return this.plainDateOf(value.value);
|
|
361
|
+
}
|
|
362
|
+
toDataTypeValue(input) {
|
|
363
|
+
return this.dataTypeValueOf(storedTextOfTemporal(DATE_TEMPORAL, input, mysqlDateText));
|
|
364
|
+
}
|
|
365
|
+
plainDateOf(stored) {
|
|
366
|
+
return temporalFromStoredText(DATE_TEMPORAL, stored, (temporal, text) => temporal.PlainDate.from(text));
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
var MysqlDateTemporalDescriptor = class extends MysqlCodecDescriptor {
|
|
370
|
+
dataType = mysqlDate.id;
|
|
371
|
+
codecId = MYSQL_DATE_TEMPORAL_CODEC_ID;
|
|
372
|
+
traits = ["equality", "order"];
|
|
373
|
+
paramsSchema = void 0;
|
|
374
|
+
jsonProjection(expression) {
|
|
375
|
+
return identityJsonProjection(expression);
|
|
376
|
+
}
|
|
377
|
+
factory() {
|
|
378
|
+
return () => new MysqlDateTemporalCodec(this, mysqlDate);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
const mysqlDateTemporalDescriptor = new MysqlDateTemporalDescriptor();
|
|
382
|
+
/** A time of day read as ISO 8601 text, `09:30:00.5`. A MySQL `time` outside 00:00:00 to 23:59:59.999999 is no time of day, so it is refused on read and on write. */
|
|
383
|
+
var MysqlTimeStringCodec = class extends CodecImpl {
|
|
384
|
+
async toWire(value, _ctx) {
|
|
385
|
+
return roundedDownToPrecision(storedTextForWrite(this.id, value, mysqlTimeText), this.dataTypeParams);
|
|
386
|
+
}
|
|
387
|
+
async fromWire(wire, _ctx) {
|
|
388
|
+
return storedTextFromWire(this.id, wire, mysqlTimeText);
|
|
389
|
+
}
|
|
390
|
+
fromDataTypeValue(value) {
|
|
391
|
+
return storedWithinPrecision(this.id, value.value, this.dataTypeParams);
|
|
392
|
+
}
|
|
393
|
+
toDataTypeValue(input) {
|
|
394
|
+
return this.storedDataTypeValueOf(input);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var MysqlTimeStringDescriptor = class extends MysqlCodecDescriptor {
|
|
398
|
+
dataType = mysqlTime.id;
|
|
399
|
+
codecId = MYSQL_TIME_STRING_CODEC_ID;
|
|
400
|
+
traits = ["equality", "order"];
|
|
401
|
+
paramsSchema = mysqlDatetimeParams;
|
|
402
|
+
renderValueLiteral(value) {
|
|
403
|
+
return renderTsLiteral(value);
|
|
404
|
+
}
|
|
405
|
+
jsonProjection(expression) {
|
|
406
|
+
return identityJsonProjection(expression);
|
|
407
|
+
}
|
|
408
|
+
factory(params) {
|
|
409
|
+
return () => new MysqlTimeStringCodec(this, mysqlTime, params);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const mysqlTimeStringDescriptor = new MysqlTimeStringDescriptor();
|
|
413
|
+
/** A time of day read as `Temporal.PlainTime`. */
|
|
414
|
+
var MysqlTimeTemporalCodec = class extends CodecImpl {
|
|
415
|
+
async toWire(value, _ctx) {
|
|
416
|
+
return roundedDownToPrecision(storedTextOfTemporal(TIME_TEMPORAL, value, mysqlTimeText), this.dataTypeParams);
|
|
417
|
+
}
|
|
418
|
+
async fromWire(wire, _ctx) {
|
|
419
|
+
return this.plainTimeOf(storedTextFromWire(this.id, wire, mysqlTimeText));
|
|
420
|
+
}
|
|
421
|
+
fromDataTypeValue(value) {
|
|
422
|
+
return this.plainTimeOf(storedWithinPrecision(this.id, value.value, this.dataTypeParams));
|
|
423
|
+
}
|
|
424
|
+
toDataTypeValue(input) {
|
|
425
|
+
return this.dataTypeValueOf(storedTextOfTemporal(TIME_TEMPORAL, input, mysqlTimeText));
|
|
426
|
+
}
|
|
427
|
+
plainTimeOf(stored) {
|
|
428
|
+
return temporalFromStoredText(TIME_TEMPORAL, stored, (temporal, text) => temporal.PlainTime.from(text));
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var MysqlTimeTemporalDescriptor = class extends MysqlCodecDescriptor {
|
|
432
|
+
dataType = mysqlTime.id;
|
|
433
|
+
codecId = MYSQL_TIME_TEMPORAL_CODEC_ID;
|
|
434
|
+
traits = ["equality", "order"];
|
|
435
|
+
paramsSchema = mysqlDatetimeParams;
|
|
436
|
+
jsonProjection(expression) {
|
|
437
|
+
return identityJsonProjection(expression);
|
|
438
|
+
}
|
|
439
|
+
factory(params) {
|
|
440
|
+
return () => new MysqlTimeTemporalCodec(this, mysqlTime, params);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const mysqlTimeTemporalDescriptor = new MysqlTimeTemporalDescriptor();
|
|
444
|
+
/** A length of time read as the ISO 8601 duration it was written as, `PT1H30M`, stored in a `varchar` column. Its text does not sort in the order of the durations, so it offers no order. */
|
|
445
|
+
var MysqlDurationStringCodec = class extends CodecImpl {
|
|
446
|
+
async toWire(value, _ctx) {
|
|
447
|
+
return storedTextForWrite(this.id, value, mysqlDurationText);
|
|
448
|
+
}
|
|
449
|
+
async fromWire(wire, _ctx) {
|
|
450
|
+
return storedTextFromWire(this.id, wire, mysqlDurationText);
|
|
451
|
+
}
|
|
452
|
+
fromDataTypeValue(value) {
|
|
453
|
+
return value.value;
|
|
454
|
+
}
|
|
455
|
+
toDataTypeValue(input) {
|
|
456
|
+
return this.storedDataTypeValueOf(input);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
var MysqlDurationStringDescriptor = class extends MysqlCodecDescriptor {
|
|
460
|
+
dataType = mysqlDuration.id;
|
|
461
|
+
codecId = MYSQL_DURATION_STRING_CODEC_ID;
|
|
462
|
+
traits = ["equality"];
|
|
463
|
+
paramsSchema = mysqlDurationParams;
|
|
464
|
+
renderValueLiteral(value) {
|
|
465
|
+
return renderTsLiteral(value);
|
|
466
|
+
}
|
|
467
|
+
jsonProjection(expression) {
|
|
468
|
+
return identityJsonProjection(expression);
|
|
469
|
+
}
|
|
470
|
+
factory(_params) {
|
|
471
|
+
return () => new MysqlDurationStringCodec(this, mysqlDuration);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
const mysqlDurationStringDescriptor = new MysqlDurationStringDescriptor();
|
|
475
|
+
const DECIMAL_INTEGER = /^-?\d+$/;
|
|
476
|
+
const BIGINT_MIN = -(2n ** 63n);
|
|
477
|
+
const BIGINT_MAX = 2n ** 63n - 1n;
|
|
478
|
+
/** Projects a bigint as its decimal text: a JSON number past 2^53 would lose digits when JavaScript parses the include. */
|
|
479
|
+
const textJsonProjection = (expression) => CastExpr.as(expression, "CHAR");
|
|
480
|
+
function decodeFailed(codecId, expected, received) {
|
|
481
|
+
throw mysqlError("RUNTIME.DECODE_FAILED", `${codecId} wire value must be ${expected}`, { meta: {
|
|
482
|
+
codecId,
|
|
483
|
+
received: String(received)
|
|
484
|
+
} });
|
|
485
|
+
}
|
|
486
|
+
function encodeFailed(codecId, expected, received) {
|
|
487
|
+
throw mysqlError("RUNTIME.ENCODE_FAILED", `${codecId} value must be ${expected}`, { meta: {
|
|
488
|
+
codecId,
|
|
489
|
+
received: String(received)
|
|
490
|
+
} });
|
|
491
|
+
}
|
|
492
|
+
const mysqlSqlCharDescriptor = mysqlCodec(sqlCharDescriptor, {
|
|
493
|
+
dataType: mysqlChar,
|
|
494
|
+
renderValueLiteral: renderTsLiteral,
|
|
495
|
+
jsonProjection: identityJsonProjection,
|
|
496
|
+
factory: (descriptor, dataType, params) => () => new SqlCharCodec(descriptor, dataType, params)
|
|
497
|
+
});
|
|
498
|
+
const mysqlSqlVarcharDescriptor = mysqlCodec(sqlVarcharDescriptor, {
|
|
499
|
+
dataType: mysqlVarchar,
|
|
500
|
+
renderValueLiteral: renderTsLiteral,
|
|
501
|
+
jsonProjection: identityJsonProjection,
|
|
502
|
+
factory: (descriptor, dataType, params) => () => new SqlVarcharCodec(descriptor, dataType, params)
|
|
503
|
+
});
|
|
504
|
+
const mysqlSqlRawDescriptor = mysqlCodec(sqlRawDescriptor, {
|
|
505
|
+
dataType: sqlRawDataType,
|
|
506
|
+
jsonProjection: () => {
|
|
507
|
+
throw mysqlQueryNotYetSupported("Reading a raw column inside an include");
|
|
508
|
+
},
|
|
509
|
+
factory: (descriptor, dataType, params) => () => new SqlRawCodec(descriptor, dataType, params)
|
|
510
|
+
});
|
|
511
|
+
var MysqlTextCodec = class extends CodecImpl {
|
|
512
|
+
async toWire(value, _ctx) {
|
|
513
|
+
return value;
|
|
514
|
+
}
|
|
515
|
+
async fromWire(wire, _ctx) {
|
|
516
|
+
return wire;
|
|
517
|
+
}
|
|
518
|
+
fromDataTypeValue(value) {
|
|
519
|
+
return value.value;
|
|
520
|
+
}
|
|
521
|
+
toDataTypeValue(input) {
|
|
522
|
+
return this.dataTypeValueOf(input);
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var MysqlTextDescriptor = class extends MysqlCodecDescriptor {
|
|
526
|
+
dataType = mysqlText.id;
|
|
527
|
+
codecId = MYSQL_TEXT_CODEC_ID;
|
|
528
|
+
traits = [
|
|
529
|
+
"equality",
|
|
530
|
+
"order",
|
|
531
|
+
"textual"
|
|
532
|
+
];
|
|
533
|
+
paramsSchema = void 0;
|
|
534
|
+
renderValueLiteral(value) {
|
|
535
|
+
return renderTsLiteral(value);
|
|
536
|
+
}
|
|
537
|
+
jsonProjection(expression) {
|
|
538
|
+
return identityJsonProjection(expression);
|
|
539
|
+
}
|
|
540
|
+
factory() {
|
|
541
|
+
return () => new MysqlTextCodec(this, mysqlText);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
const mysqlTextDescriptor = new MysqlTextDescriptor();
|
|
545
|
+
/** A MySQL `int` as a JavaScript number. A row carries it as decimal text, and an include's JSON as a number. */
|
|
546
|
+
var MysqlIntCodec = class extends CodecImpl {
|
|
547
|
+
async toWire(value, _ctx) {
|
|
548
|
+
if (!Number.isSafeInteger(value)) return encodeFailed(MYSQL_INT_CODEC_ID, "an integer", value);
|
|
549
|
+
return value;
|
|
550
|
+
}
|
|
551
|
+
async fromWire(wire, _ctx) {
|
|
552
|
+
if (typeof wire === "number") return wire;
|
|
553
|
+
if (!DECIMAL_INTEGER.test(wire)) return decodeFailed(MYSQL_INT_CODEC_ID, "the decimal text of an integer", wire);
|
|
554
|
+
return Number(wire);
|
|
555
|
+
}
|
|
556
|
+
fromDataTypeValue(value) {
|
|
557
|
+
return value.value;
|
|
558
|
+
}
|
|
559
|
+
toDataTypeValue(input) {
|
|
560
|
+
return this.dataTypeValueOf(input);
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
var MysqlIntDescriptor = class extends MysqlCodecDescriptor {
|
|
564
|
+
dataType = mysqlInt.id;
|
|
565
|
+
codecId = MYSQL_INT_CODEC_ID;
|
|
566
|
+
traits = [
|
|
567
|
+
"equality",
|
|
568
|
+
"order",
|
|
569
|
+
"numeric"
|
|
570
|
+
];
|
|
571
|
+
paramsSchema = void 0;
|
|
572
|
+
renderValueLiteral(value) {
|
|
573
|
+
return renderTsLiteral(value);
|
|
574
|
+
}
|
|
575
|
+
jsonProjection(expression) {
|
|
576
|
+
return identityJsonProjection(expression);
|
|
577
|
+
}
|
|
578
|
+
factory() {
|
|
579
|
+
return () => new MysqlIntCodec(this, mysqlInt);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
const mysqlIntDescriptor = new MysqlIntDescriptor();
|
|
583
|
+
/** A MySQL `bigint` as a JavaScript bigint. A row, an include's JSON and a parameter carry it as decimal text, as the Postgres `int8` codec does; MySQL reads a text parameter beside a `bigint` column exactly. */
|
|
584
|
+
var MysqlBigintCodec = class extends CodecImpl {
|
|
585
|
+
/** The bigint itself: the driver writes it as bare digits, which MySQL reads as an exact integer even beside an expression, where it compares quoted text as a double. */
|
|
586
|
+
async toWire(value, _ctx) {
|
|
587
|
+
if (typeof value !== "bigint" || value < BIGINT_MIN || value > BIGINT_MAX) return encodeFailed(MYSQL_BIGINT_CODEC_ID, `a bigint from ${BIGINT_MIN} to ${BIGINT_MAX}`, value);
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
590
|
+
async fromWire(wire, _ctx) {
|
|
591
|
+
if (typeof wire === "bigint") return wire;
|
|
592
|
+
if (!DECIMAL_INTEGER.test(wire)) return decodeFailed(MYSQL_BIGINT_CODEC_ID, "the decimal text of an integer", wire);
|
|
593
|
+
return BigInt(wire);
|
|
594
|
+
}
|
|
595
|
+
fromDataTypeValue(value) {
|
|
596
|
+
return BigInt(value.value);
|
|
597
|
+
}
|
|
598
|
+
toDataTypeValue(input) {
|
|
599
|
+
return this.dataTypeValueOf(input.toString());
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
var MysqlBigintDescriptor = class extends MysqlCodecDescriptor {
|
|
603
|
+
dataType = mysqlBigint.id;
|
|
604
|
+
codecId = MYSQL_BIGINT_CODEC_ID;
|
|
605
|
+
traits = [
|
|
606
|
+
"equality",
|
|
607
|
+
"order",
|
|
608
|
+
"numeric"
|
|
609
|
+
];
|
|
610
|
+
paramsSchema = void 0;
|
|
611
|
+
renderValueLiteral(value) {
|
|
612
|
+
return decimalTextBigintLiteral(value);
|
|
613
|
+
}
|
|
614
|
+
jsonProjection(expression) {
|
|
615
|
+
return textJsonProjection(expression);
|
|
616
|
+
}
|
|
617
|
+
factory() {
|
|
618
|
+
return () => new MysqlBigintCodec(this, mysqlBigint);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
const mysqlBigintDescriptor = new MysqlBigintDescriptor();
|
|
622
|
+
/**
|
|
623
|
+
* Reads the text MySQL sends for a `datetime` as the instant it names in UTC: the codec writes every value in UTC, so the column holds no time zone of its own.
|
|
624
|
+
*/
|
|
625
|
+
function decodeMysqlDatetime(wire) {
|
|
626
|
+
return dateOfWireText(MYSQL_DATETIME_CODEC_ID, wire);
|
|
627
|
+
}
|
|
628
|
+
/** The text MySQL reads for an instant in UTC, with millisecond digits. A `Date` outside the years a `datetime` holds is refused. */
|
|
629
|
+
function encodeMysqlDatetime(value) {
|
|
630
|
+
return wireTextOfDate(MYSQL_DATETIME_CODEC_ID, value, mysqlDatetimeText);
|
|
631
|
+
}
|
|
632
|
+
/** A MySQL `datetime` as a JavaScript `Date`, read and written in UTC. */
|
|
633
|
+
var MysqlDatetimeCodec = class extends CodecImpl {
|
|
634
|
+
async toWire(value, _ctx) {
|
|
635
|
+
return roundedDownToPrecision(encodeMysqlDatetime(value), this.dataTypeParams);
|
|
636
|
+
}
|
|
637
|
+
async fromWire(wire, _ctx) {
|
|
638
|
+
return decodeMysqlDatetime(wire);
|
|
639
|
+
}
|
|
640
|
+
fromDataTypeValue(value) {
|
|
641
|
+
const stored = storedWithinPrecision(this.id, value.value, this.dataTypeParams);
|
|
642
|
+
if (hasDigitsBelowAMillisecond(stored)) return refuseJsonValue(this.id, `a datetime with no digits below a millisecond, which a Date drops: ${JSON.stringify(value.value)} has them`, value.value);
|
|
643
|
+
return /* @__PURE__ */ new Date(`${stored}Z`);
|
|
644
|
+
}
|
|
645
|
+
toDataTypeValue(input) {
|
|
646
|
+
return this.dataTypeValueOf(input.toISOString().replace("Z", ""));
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
var MysqlDatetimeDescriptor = class extends MysqlCodecDescriptor {
|
|
650
|
+
dataType = mysqlDatetime.id;
|
|
651
|
+
codecId = MYSQL_DATETIME_CODEC_ID;
|
|
652
|
+
traits = ["equality", "order"];
|
|
653
|
+
paramsSchema = mysqlDatetimeParams;
|
|
654
|
+
jsonProjection(expression) {
|
|
655
|
+
return identityJsonProjection(expression);
|
|
656
|
+
}
|
|
657
|
+
factory(params) {
|
|
658
|
+
return () => new MysqlDatetimeCodec(this, mysqlDatetime, params);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
const mysqlDatetimeDescriptor = new MysqlDatetimeDescriptor();
|
|
662
|
+
/** A native MySQL enum column, whose value is the member's text. */
|
|
663
|
+
var MysqlEnumCodec = class extends CodecImpl {
|
|
664
|
+
async toWire(value, _ctx) {
|
|
665
|
+
return value;
|
|
666
|
+
}
|
|
667
|
+
async fromWire(wire, _ctx) {
|
|
668
|
+
return wire;
|
|
669
|
+
}
|
|
670
|
+
fromDataTypeValue(value) {
|
|
671
|
+
return value.value;
|
|
672
|
+
}
|
|
673
|
+
toDataTypeValue(input) {
|
|
674
|
+
return this.dataTypeValueOf(input);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
var MysqlEnumDescriptor = class extends MysqlCodecDescriptor {
|
|
678
|
+
dataType = mysqlEnum.id;
|
|
679
|
+
codecId = MYSQL_ENUM_CODEC_ID;
|
|
680
|
+
traits = [
|
|
681
|
+
"equality",
|
|
682
|
+
"order",
|
|
683
|
+
"textual"
|
|
684
|
+
];
|
|
685
|
+
paramsSchema = mysqlEnumParams;
|
|
686
|
+
renderValueLiteral(value) {
|
|
687
|
+
return renderTsLiteral(value);
|
|
688
|
+
}
|
|
689
|
+
jsonProjection(expression) {
|
|
690
|
+
return identityJsonProjection(expression);
|
|
691
|
+
}
|
|
692
|
+
factory(params) {
|
|
693
|
+
return () => new MysqlEnumCodec(this, mysqlEnum, params);
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
/** Every codec descriptor this target ships. */
|
|
697
|
+
const codecDescriptors = [
|
|
698
|
+
mysqlSqlCharDescriptor,
|
|
699
|
+
mysqlSqlVarcharDescriptor,
|
|
700
|
+
mysqlSqlRawDescriptor,
|
|
701
|
+
mysqlTextDescriptor,
|
|
702
|
+
mysqlIntDescriptor,
|
|
703
|
+
mysqlBigintDescriptor,
|
|
704
|
+
mysqlDatetimeDescriptor,
|
|
705
|
+
mysqlDatetimeTemporalDescriptor,
|
|
706
|
+
mysqlDatetimeStringDescriptor,
|
|
707
|
+
mysqlTimestampDateDescriptor,
|
|
708
|
+
mysqlTimestampTemporalDescriptor,
|
|
709
|
+
mysqlTimestampStringDescriptor,
|
|
710
|
+
mysqlDateStringDescriptor,
|
|
711
|
+
mysqlDateTemporalDescriptor,
|
|
712
|
+
mysqlTimeStringDescriptor,
|
|
713
|
+
mysqlTimeTemporalDescriptor,
|
|
714
|
+
mysqlDurationStringDescriptor,
|
|
715
|
+
new MysqlEnumDescriptor()
|
|
716
|
+
];
|
|
717
|
+
/** Every codec descriptor `@internal/target-mysql` ships, for consumers that enumerate or look up a MySQL codec by id. ADR 208. */
|
|
718
|
+
const mysqlCodecRegistry = buildCodecDescriptorRegistry(codecDescriptors);
|
|
719
|
+
const mysqlCodecDescriptorRegistry = buildMysqlCodecDescriptorRegistry(codecDescriptors);
|
|
720
|
+
function descriptorsFrom(contributors) {
|
|
721
|
+
return contributors.flatMap((contributor) => contributor.types?.codecTypes?.codecDescriptors ?? []);
|
|
722
|
+
}
|
|
723
|
+
function buildMysqlCodecRegistry(descriptors) {
|
|
724
|
+
const descriptorRegistry = buildMysqlCodecDescriptorRegistry(descriptors);
|
|
725
|
+
const registry = {
|
|
726
|
+
...extractCodecLookup([{
|
|
727
|
+
id: "mysql-codecs",
|
|
728
|
+
types: { codecTypes: { codecDescriptors: Array.from(descriptorRegistry.values()) } }
|
|
729
|
+
}]),
|
|
730
|
+
descriptorFor: (codecId) => descriptorRegistry.descriptorFor(codecId),
|
|
731
|
+
values: () => descriptorRegistry.values()
|
|
732
|
+
};
|
|
733
|
+
return Object.freeze(registry);
|
|
734
|
+
}
|
|
735
|
+
/** The codec registry of a MySQL stack: the target's built-in codecs and those its extensions contribute. */
|
|
736
|
+
function assembleMysqlCodecRegistry(target, extensions) {
|
|
737
|
+
return buildMysqlCodecRegistry([
|
|
738
|
+
...descriptorsFrom([target]),
|
|
739
|
+
...mysqlCodecDescriptorRegistry.values(),
|
|
740
|
+
...descriptorsFrom(extensions)
|
|
741
|
+
]);
|
|
742
|
+
}
|
|
743
|
+
/** A codec registry of the MySQL built-in codecs only. */
|
|
744
|
+
function createMysqlBuiltinCodecLookup() {
|
|
745
|
+
return buildMysqlCodecRegistry([...mysqlCodecDescriptorRegistry.values()]);
|
|
746
|
+
}
|
|
747
|
+
//#endregion
|
|
748
|
+
export { mysqlCodecDescriptorRegistry as a, encodeMysqlDatetime as i, createMysqlBuiltinCodecLookup as n, mysqlCodecRegistry as o, decodeMysqlDatetime as r, assembleMysqlCodecRegistry as t };
|
|
749
|
+
|
|
750
|
+
//# sourceMappingURL=codecs-BfiB79-5.mjs.map
|