joist-core 2.3.0-next.65 → 2.3.0-next.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/build/Aliases.cjs +1 -2
  2. package/build/Aliases.cjs.map +1 -1
  3. package/build/Aliases.js +1 -2
  4. package/build/Aliases.js.map +1 -1
  5. package/build/ConditionBuilder.cjs +1 -2
  6. package/build/ConditionBuilder.cjs.map +1 -1
  7. package/build/ConditionBuilder.d.cts +1 -1
  8. package/build/ConditionBuilder.d.mts +1 -1
  9. package/build/ConditionBuilder.js +1 -2
  10. package/build/ConditionBuilder.js.map +1 -1
  11. package/build/EntityManager.cjs +2 -6
  12. package/build/EntityManager.cjs.map +1 -1
  13. package/build/EntityManager.d.cts.map +1 -1
  14. package/build/EntityManager.d.mts.map +1 -1
  15. package/build/EntityManager.js +2 -6
  16. package/build/EntityManager.js.map +1 -1
  17. package/build/EntityMetadata.cjs +1 -1
  18. package/build/EntityMetadata.cjs.map +1 -1
  19. package/build/EntityMetadata.d.cts +5 -6
  20. package/build/EntityMetadata.d.cts.map +1 -1
  21. package/build/EntityMetadata.d.mts +5 -6
  22. package/build/EntityMetadata.d.mts.map +1 -1
  23. package/build/EntityMetadata.js +1 -1
  24. package/build/EntityMetadata.js.map +1 -1
  25. package/build/Expr.cjs +2 -76
  26. package/build/Expr.cjs.map +1 -1
  27. package/build/Expr.d.cts +5 -59
  28. package/build/Expr.d.cts.map +1 -1
  29. package/build/Expr.d.mts +5 -59
  30. package/build/Expr.d.mts.map +1 -1
  31. package/build/Expr.js +2 -74
  32. package/build/Expr.js.map +1 -1
  33. package/build/QueryParser.d.cts +1 -1
  34. package/build/QueryParser.d.mts +1 -1
  35. package/build/Tables.cjs +25 -42
  36. package/build/Tables.cjs.map +1 -1
  37. package/build/Tables.d.cts +5 -7
  38. package/build/Tables.d.cts.map +1 -1
  39. package/build/Tables.d.mts +5 -7
  40. package/build/Tables.d.mts.map +1 -1
  41. package/build/Tables.js +25 -42
  42. package/build/Tables.js.map +1 -1
  43. package/build/TypeInfo.cjs +80 -0
  44. package/build/TypeInfo.cjs.map +1 -0
  45. package/build/TypeInfo.d.cts +57 -0
  46. package/build/TypeInfo.d.cts.map +1 -0
  47. package/build/TypeInfo.d.mts +57 -0
  48. package/build/TypeInfo.d.mts.map +1 -0
  49. package/build/TypeInfo.js +78 -0
  50. package/build/TypeInfo.js.map +1 -0
  51. package/build/columns.cjs +63 -0
  52. package/build/columns.cjs.map +1 -0
  53. package/build/columns.d.cts +38 -0
  54. package/build/columns.d.cts.map +1 -0
  55. package/build/columns.d.mts +38 -0
  56. package/build/columns.d.mts.map +1 -0
  57. package/build/columns.js +62 -0
  58. package/build/columns.js.map +1 -0
  59. package/build/configure.cjs +5 -4
  60. package/build/configure.cjs.map +1 -1
  61. package/build/configure.js +5 -4
  62. package/build/configure.js.map +1 -1
  63. package/build/dataloaders/findByUniqueDataLoader.cjs +0 -1
  64. package/build/dataloaders/findByUniqueDataLoader.cjs.map +1 -1
  65. package/build/dataloaders/findByUniqueDataLoader.js +0 -1
  66. package/build/dataloaders/findByUniqueDataLoader.js.map +1 -1
  67. package/build/dataloaders/findDataLoader.cjs +1 -1
  68. package/build/dataloaders/findDataLoader.js +1 -1
  69. package/build/driverApi.cjs +1 -1
  70. package/build/driverApi.js +1 -1
  71. package/build/drivers/EntityWriter.cjs +5 -5
  72. package/build/drivers/EntityWriter.cjs.map +1 -1
  73. package/build/drivers/EntityWriter.js +1 -1
  74. package/build/drivers/EntityWriter.js.map +1 -1
  75. package/build/drivers/index.cjs +1 -1
  76. package/build/drivers/index.js +1 -1
  77. package/build/execute.cjs +27 -44
  78. package/build/execute.cjs.map +1 -1
  79. package/build/execute.d.cts +3 -5
  80. package/build/execute.d.cts.map +1 -1
  81. package/build/execute.d.mts +3 -5
  82. package/build/execute.d.mts.map +1 -1
  83. package/build/execute.js +27 -44
  84. package/build/execute.js.map +1 -1
  85. package/build/fieldSerde.cjs +188 -0
  86. package/build/fieldSerde.cjs.map +1 -0
  87. package/build/fieldSerde.d.cts +87 -0
  88. package/build/fieldSerde.d.cts.map +1 -0
  89. package/build/fieldSerde.d.mts +87 -0
  90. package/build/fieldSerde.d.mts.map +1 -0
  91. package/build/fieldSerde.js +182 -0
  92. package/build/fieldSerde.js.map +1 -0
  93. package/build/fields.cjs +2 -2
  94. package/build/fields.cjs.map +1 -1
  95. package/build/fields.d.cts.map +1 -1
  96. package/build/fields.d.mts.map +1 -1
  97. package/build/fields.js +2 -2
  98. package/build/fields.js.map +1 -1
  99. package/build/index.cjs +18 -11
  100. package/build/index.cjs.map +1 -1
  101. package/build/index.d.cts +8 -6
  102. package/build/index.d.cts.map +1 -1
  103. package/build/index.d.mts +8 -6
  104. package/build/index.d.mts.map +1 -1
  105. package/build/index.js +12 -10
  106. package/build/index.js.map +1 -1
  107. package/build/newTestInstance.cjs +1 -1
  108. package/build/newTestInstance.js +1 -1
  109. package/build/query.cjs +2 -2
  110. package/build/query.cjs.map +1 -1
  111. package/build/query.d.cts +3 -2
  112. package/build/query.d.cts.map +1 -1
  113. package/build/query.d.mts +3 -2
  114. package/build/query.d.mts.map +1 -1
  115. package/build/query.js +2 -2
  116. package/build/query.js.map +1 -1
  117. package/build/relations/LazyField.cjs +1 -1
  118. package/build/relations/LazyField.cjs.map +1 -1
  119. package/build/relations/LazyField.js +1 -1
  120. package/build/relations/LazyField.js.map +1 -1
  121. package/build/relations/PolymorphicReference.cjs +1 -1
  122. package/build/relations/PolymorphicReference.cjs.map +1 -1
  123. package/build/relations/PolymorphicReference.d.cts.map +1 -1
  124. package/build/relations/PolymorphicReference.d.mts.map +1 -1
  125. package/build/relations/PolymorphicReference.js +1 -1
  126. package/build/relations/PolymorphicReference.js.map +1 -1
  127. package/build/serde.cjs +56 -319
  128. package/build/serde.cjs.map +1 -1
  129. package/build/serde.d.cts +73 -233
  130. package/build/serde.d.cts.map +1 -1
  131. package/build/serde.d.mts +73 -233
  132. package/build/serde.d.mts.map +1 -1
  133. package/build/serde.js +45 -306
  134. package/build/serde.js.map +1 -1
  135. package/build/temporalMappers.cjs +1 -1
  136. package/build/temporalMappers.js +1 -1
  137. package/package.json +2 -2
package/build/serde.js CHANGED
@@ -1,42 +1,21 @@
1
1
  import { keyToNumber, keyToTaggedId, maybeResolveReferenceToId } from "./keys.js";
2
- import "./drivers/EntityWriter.js";
3
- import { arrayOutputType, canonicalDbType } from "./Expr.js";
4
- import { getRuntimeConfig } from "./runtimeConfig.js";
5
2
  import { requireTemporal } from "./temporal.js";
3
+ import { arrayOutputType, canonicalDbType } from "./TypeInfo.js";
4
+ import { getRuntimeConfig } from "./runtimeConfig.js";
6
5
  import { plainDateMapper, plainDateTimeMapper, plainTimeMapper, zonedDateTimeMapper } from "./temporalMappers.js";
7
- import { getBaseMeta, getMetadata } from "./EntityMetadata.js";
8
- import { groupBy } from "./utils.js";
9
6
  import "./index.js";
10
7
  import { isDefined } from "./EntityManager.js";
11
- import { isEntity } from "./Entity.js";
12
- import { getConstructorFromTaggedId } from "./configure.js";
13
8
  import { createRequire } from "node:module";
14
9
  //#region src/serde.ts
15
10
  const runtimeRequire = createRequire(import.meta.url);
16
- function hasSerde(field) {
17
- return !!field.serde;
18
- }
19
11
  var CustomSerdeAdapter = class CustomSerdeAdapter {
20
- fieldName;
21
- columnName;
22
12
  dbType;
23
13
  mapper;
24
- sqlNullable;
25
- hasDefault;
26
- isGenerated;
27
- columns = [this];
28
14
  isArray = false;
29
- isNullableArray = false;
30
- constructor(fieldName, columnName, dbType, mapper, isArray, isNullableArray = false, column) {
31
- this.fieldName = fieldName;
32
- this.columnName = columnName;
15
+ constructor(dbType, mapper, isArray) {
33
16
  this.dbType = dbType;
34
17
  this.mapper = mapper;
35
- this.sqlNullable = column?.sqlNullable;
36
- this.hasDefault = column?.hasDefault;
37
- this.isGenerated = column?.isGenerated;
38
18
  if (isArray !== void 0) this.isArray = isArray;
39
- this.isNullableArray = isNullableArray;
40
19
  }
41
20
  /** Only known adapters share their mapper's identity and elementwise array conversion. */
42
21
  get outputType() {
@@ -59,18 +38,12 @@ var CustomSerdeAdapter = class CustomSerdeAdapter {
59
38
  domain: this.mapper
60
39
  } : void 0;
61
40
  }
62
- setOnEntityFromRowData(data, rowData, rowIndex) {
63
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
64
- }
65
- dbValue(data) {
66
- return this.mapToDbValue(data[this.fieldName]);
67
- }
68
41
  /** Encodes each physical array element once. */
69
42
  mapToDbValue(value) {
70
43
  return value !== void 0 ? this.isArray ? value.map((element) => this.mapper.toDb(element)) : this.mapper.toDb(value) : void 0;
71
44
  }
72
- rowValue(data) {
73
- return this.dbValue(data);
45
+ mapToRow(value) {
46
+ return this.mapToDbValue(value);
74
47
  }
75
48
  mapToDb(value) {
76
49
  return value === null ? value : this.isArray ? value.map((element) => this.mapper.toDb(element)) : this.mapper.toDb(value);
@@ -92,24 +65,11 @@ var CustomSerdeAdapter = class CustomSerdeAdapter {
92
65
  * that will handle converting individual elements.
93
66
  */
94
67
  var PrimitiveSerde = class PrimitiveSerde {
95
- fieldName;
96
- columnName;
97
68
  dbType;
98
69
  isArray;
99
- isNullableArray;
100
- sqlNullable;
101
- hasDefault;
102
- isGenerated;
103
- columns = [this];
104
- constructor(fieldName, columnName, dbType, isArray = false, isNullableArray = false, column) {
105
- this.fieldName = fieldName;
106
- this.columnName = columnName;
70
+ constructor(dbType, isArray = false) {
107
71
  this.dbType = dbType;
108
72
  this.isArray = isArray;
109
- this.isNullableArray = isNullableArray;
110
- this.sqlNullable = column?.sqlNullable;
111
- this.hasDefault = column?.hasDefault;
112
- this.isGenerated = column?.isGenerated;
113
73
  }
114
74
  /** Exact-class checks prevent an unknown subclass's overridden converters from sharing this codec. */
115
75
  get outputType() {
@@ -124,18 +84,12 @@ var PrimitiveSerde = class PrimitiveSerde {
124
84
  };
125
85
  return this.isArray ? arrayOutputType(outputType) : outputType;
126
86
  }
127
- setOnEntityFromRowData(data, rowData, rowIndex) {
128
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
129
- }
130
- dbValue(data) {
131
- return this.mapToDbValue(data[this.fieldName]);
132
- }
133
87
  /** Primitive writes share their scalar/filter conversion, including subclass overrides. */
134
88
  mapToDbValue(value) {
135
89
  return this.mapToDb(value);
136
90
  }
137
- rowValue(data) {
138
- return this.dbValue(data);
91
+ mapToRow(value) {
92
+ return this.mapToDbValue(value);
139
93
  }
140
94
  mapToDb(value) {
141
95
  return value;
@@ -167,12 +121,12 @@ var DateSerde = class DateSerde extends PrimitiveSerde {
167
121
  /**
168
122
  * Returns the `Date` a driver hands back on a read, and not `mapToDb`'s ISO string.
169
123
  *
170
- * Otherwise callers that round-trip a row through `rowValue` and back through `setOnEntity` (i.e.
124
+ * Otherwise callers that round-trip a row through `rowValue` and back through `fromRow` (i.e.
171
125
  * `RunPlugin` mirroring writes into the test em) turn every date into a string, because our
172
- * `setOnEntity` assigns the row value as-is.
126
+ * `mapFromDb` returns the row value as-is.
173
127
  */
174
- rowValue(data) {
175
- return data[this.fieldName];
128
+ mapToRow(value) {
129
+ return value;
176
130
  }
177
131
  mapToDb(value) {
178
132
  return value?.toISOString();
@@ -180,20 +134,20 @@ var DateSerde = class DateSerde extends PrimitiveSerde {
180
134
  };
181
135
  /** Converts `DATE`s `Temporal.PlainDate`s. */
182
136
  var PlainDateSerde = class extends CustomSerdeAdapter {
183
- constructor(fieldName, columnName, dbType, isArray = false, isNullableArray = false, column) {
184
- super(fieldName, columnName, dbType, plainDateMapper, isArray, isNullableArray, column);
137
+ constructor(dbType, isArray = false) {
138
+ super(dbType, plainDateMapper, isArray);
185
139
  }
186
140
  };
187
141
  /** Converts `TIME`s to `Temporal.PlainTime`s. */
188
142
  var PlainTimeSerde = class extends CustomSerdeAdapter {
189
- constructor(fieldName, columnName, dbType, isArray = false, isNullableArray = false, column) {
190
- super(fieldName, columnName, dbType, plainTimeMapper, isArray, isNullableArray, column);
143
+ constructor(dbType, isArray = false) {
144
+ super(dbType, plainTimeMapper, isArray);
191
145
  }
192
146
  };
193
147
  /** Converts `TIMESTAMP`s to `Temporal.PlainDateTime`s. */
194
148
  var PlainDateTimeSerde = class extends CustomSerdeAdapter {
195
- constructor(fieldName, columnName, dbType, isArray = false, isNullableArray = false, column) {
196
- super(fieldName, columnName, dbType, plainDateTimeMapper, isArray, isNullableArray, column);
149
+ constructor(dbType, isArray = false) {
150
+ super(dbType, plainDateTimeMapper, isArray);
197
151
  }
198
152
  mapFromNow(now) {
199
153
  const { timeZone } = getRuntimeConfig().temporal;
@@ -202,8 +156,8 @@ var PlainDateTimeSerde = class extends CustomSerdeAdapter {
202
156
  };
203
157
  /** Converts `TIMESTAMP WITH TIME ZONE`s to `Temporal.ZonedDateTime`s. */
204
158
  var ZonedDateTimeSerde = class extends CustomSerdeAdapter {
205
- constructor(fieldName, columnName, dbType, isArray = false, isNullableArray = false, column) {
206
- super(fieldName, columnName, dbType, zonedDateTimeMapper, isArray, isNullableArray, column);
159
+ constructor(dbType, isArray = false) {
160
+ super(dbType, zonedDateTimeMapper, isArray);
207
161
  }
208
162
  mapFromNow(now) {
209
163
  const { timeZone } = getRuntimeConfig().temporal;
@@ -211,24 +165,11 @@ var ZonedDateTimeSerde = class extends CustomSerdeAdapter {
211
165
  }
212
166
  };
213
167
  var BigIntSerde = class BigIntSerde {
214
- fieldName;
215
- columnName;
216
168
  isArray;
217
- isNullableArray;
218
- sqlNullable;
219
- hasDefault;
220
- isGenerated;
221
- columns = [this];
222
169
  dbType;
223
- constructor(fieldName, columnName, isArray = false, isNullableArray = false, column) {
224
- this.fieldName = fieldName;
225
- this.columnName = columnName;
170
+ constructor(isArray = false) {
226
171
  this.isArray = isArray;
227
- this.isNullableArray = isNullableArray;
228
172
  this.dbType = isArray ? "bigint[]" : "bigint";
229
- this.sqlNullable = column?.sqlNullable;
230
- this.hasDefault = column?.hasDefault;
231
- this.isGenerated = column?.isGenerated;
232
173
  }
233
174
  /** BigInt conversion is distinct from both the driver's int8 value and Number aggregates. */
234
175
  get outputType() {
@@ -240,19 +181,13 @@ var BigIntSerde = class BigIntSerde {
240
181
  };
241
182
  return this.isArray ? arrayOutputType(elementType) : elementType;
242
183
  }
243
- setOnEntityFromRowData(data, rowData, rowIndex) {
244
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
245
- }
246
- dbValue(data) {
247
- return this.mapToDbValue(data[this.fieldName]);
248
- }
249
184
  /** Drivers accept native bigint values without conversion. */
250
185
  mapToDbValue(value) {
251
186
  if (this.isArray) assertFlatNumericArray(value);
252
187
  return value;
253
188
  }
254
- rowValue(data) {
255
- return this.dbValue(data);
189
+ mapToRow(value) {
190
+ return this.mapToDbValue(value);
256
191
  }
257
192
  mapToDb(value) {
258
193
  return value;
@@ -280,24 +215,11 @@ var BigIntSerde = class BigIntSerde {
280
215
  * to handle from-database -> to JS translation.
281
216
  */
282
217
  var DecimalToNumberSerde = class DecimalToNumberSerde {
283
- fieldName;
284
- columnName;
285
218
  isArray;
286
- isNullableArray;
287
- sqlNullable;
288
- hasDefault;
289
- isGenerated;
290
219
  dbType;
291
- columns = [this];
292
- constructor(fieldName, columnName, isArray = false, isNullableArray = false, column) {
293
- this.fieldName = fieldName;
294
- this.columnName = columnName;
220
+ constructor(isArray = false) {
295
221
  this.isArray = isArray;
296
- this.isNullableArray = isNullableArray;
297
222
  this.dbType = isArray ? "numeric[]" : "decimal";
298
- this.sqlNullable = column?.sqlNullable;
299
- this.hasDefault = column?.hasDefault;
300
- this.isGenerated = column?.isGenerated;
301
223
  }
302
224
  /** Numeric aggregates use the same Number conversion and identity binding encoder. */
303
225
  get outputType() {
@@ -309,19 +231,13 @@ var DecimalToNumberSerde = class DecimalToNumberSerde {
309
231
  };
310
232
  return this.isArray ? arrayOutputType(elementType) : elementType;
311
233
  }
312
- setOnEntityFromRowData(data, rowData, rowIndex) {
313
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
314
- }
315
- dbValue(data) {
316
- return this.mapToDbValue(data[this.fieldName]);
317
- }
318
234
  /** Drivers accept decimal numbers without conversion. */
319
235
  mapToDbValue(value) {
320
236
  if (this.isArray) assertFlatNumericArray(value);
321
237
  return value;
322
238
  }
323
- rowValue(data) {
324
- return this.dbValue(data);
239
+ mapToRow(value) {
240
+ return this.mapToDbValue(value);
325
241
  }
326
242
  mapToDb(value) {
327
243
  return value;
@@ -341,23 +257,11 @@ var DecimalToNumberSerde = class DecimalToNumberSerde {
341
257
  };
342
258
  /** Maps physical integer keys to logical string IDs "because GraphQL". */
343
259
  var KeySerde = class KeySerde {
344
- fieldName;
345
- columnName;
346
260
  dbType;
347
- sqlNullable;
348
- hasDefault;
349
- isGenerated;
350
261
  isArray = false;
351
- isNullableArray = false;
352
- columns = [this];
353
262
  meta;
354
- constructor(tagName, fieldName, columnName, dbType, column) {
355
- this.fieldName = fieldName;
356
- this.columnName = columnName;
263
+ constructor(tagName, dbType) {
357
264
  this.dbType = dbType;
358
- this.sqlNullable = column?.sqlNullable;
359
- this.hasDefault = column?.hasDefault;
360
- this.isGenerated = column?.isGenerated;
361
265
  this.meta = {
362
266
  tagName,
363
267
  idDbType: dbType
@@ -371,28 +275,12 @@ var KeySerde = class KeySerde {
371
275
  arrayElementSafe: true
372
276
  } : void 0;
373
277
  }
374
- setOnEntityFromRowData(data, rowData, rowIndex) {
375
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
376
- }
377
- dbValue(data, entity, tableName, fixups) {
378
- const value = data[this.fieldName];
379
- if (fixups && isEntity(value) && value.isNewEntity && getMetadata(value).nonDeferredFkOrder && getMetadata(entity).nonDeferredFkOrder && getMetadata(value).nonDeferredFkOrder >= getMetadata(entity).nonDeferredFkOrder) {
380
- fixups.push({
381
- entity,
382
- tableName,
383
- column: this,
384
- value: this.mapToDbValue(maybeResolveReferenceToId(value))
385
- });
386
- return null;
387
- }
388
- return this.mapToDbValue(maybeResolveReferenceToId(value));
389
- }
390
278
  /** Resolves references and tagged, untagged, or numeric ids using the column's tag and storage type. */
391
279
  mapToDbValue(value) {
392
280
  return keyToNumber(this.meta, typeof value === "number" ? value : maybeResolveReferenceToId(value));
393
281
  }
394
- rowValue(data) {
395
- return this.dbValue(data, void 0, void 0, void 0);
282
+ mapToRow(value) {
283
+ return this.mapToDbValue(value);
396
284
  }
397
285
  mapToDb(value) {
398
286
  if (value === null || typeof value === "number") return value;
@@ -406,82 +294,13 @@ var KeySerde = class KeySerde {
406
294
  return value === null ? value : value;
407
295
  }
408
296
  };
409
- var PolymorphicKeySerde = class {
410
- meta;
411
- fieldName;
412
- storageColumn;
413
- constructor(meta, fieldName, storageColumn) {
414
- this.meta = meta;
415
- this.fieldName = fieldName;
416
- this.storageColumn = storageColumn;
417
- }
418
- setOnEntityFromRowData(data, rowData, rowIndex) {
419
- for (const column of this.columns) {
420
- const value = rowData.get(rowIndex, column.columnName);
421
- if (value) data[this.fieldName] ??= column.mapFromDb(value);
422
- }
423
- }
424
- get columns() {
425
- const { fieldName } = this;
426
- const hasMultipleComponentsWithSameBaseType = [...groupBy(this.field.components, (comp) => getBaseMeta(comp.otherMetadata()).type).values()].some((group) => group.length > 1);
427
- return this.field.components.map((comp) => ({
428
- columnName: comp.columnName,
429
- dbType: comp.otherMetadata().idDbType,
430
- isArray: false,
431
- isNullableArray: false,
432
- otherMetadata: comp.otherMetadata,
433
- dbValue(data) {
434
- return this.mapToDbValue(data[fieldName]);
435
- },
436
- /** Encodes only references belonging to this physical component, preserving subtype selection. */
437
- mapToDbValue(value) {
438
- const id = maybeResolveReferenceToId(value);
439
- const cstr = isEntity(value) ? getMetadata(value).cstr : id ? getConstructorFromTaggedId(id) : void 0;
440
- const otherMeta = comp.otherMetadata();
441
- return (hasMultipleComponentsWithSameBaseType ? cstr === otherMeta.cstr : cstr === otherMeta.cstr || cstr === getBaseMeta(otherMeta).cstr || otherMeta.subTypes.some((subTypeMeta) => cstr === subTypeMeta.cstr)) ? keyToNumber(comp.otherMetadata(), id) : void 0;
442
- },
443
- mapToDb(value) {
444
- return keyToNumber(comp.otherMetadata(), typeof value === "number" ? value : maybeResolveReferenceToId(value));
445
- },
446
- /** Converts this component's foreign key to its target entity's tagged id. */
447
- mapFromDb(value) {
448
- return keyToTaggedId(comp.otherMetadata(), value);
449
- },
450
- mapFromJsonAgg(value) {
451
- return value === null ? value : value;
452
- },
453
- rowValue(data) {
454
- return this.dbValue(data);
455
- }
456
- }));
457
- }
458
- get columnName() {
459
- throw new Error("Unsupported");
460
- }
461
- get field() {
462
- const meta = this.meta();
463
- return this.storageColumn ? meta.columns[this.storageColumn].field : meta.fields[this.fieldName];
464
- }
465
- };
466
297
  var EnumFieldSerde = class EnumFieldSerde {
467
- fieldName;
468
- columnName;
469
298
  dbType;
470
299
  enumObject;
471
- sqlNullable;
472
- hasDefault;
473
- isGenerated;
474
300
  isArray = false;
475
- isNullableArray = false;
476
- columns = [this];
477
- constructor(fieldName, columnName, dbType, enumObject, column) {
478
- this.fieldName = fieldName;
479
- this.columnName = columnName;
301
+ constructor(dbType, enumObject) {
480
302
  this.dbType = dbType;
481
303
  this.enumObject = enumObject;
482
- this.sqlNullable = column?.sqlNullable;
483
- this.hasDefault = column?.hasDefault;
484
- this.isGenerated = column?.isGenerated;
485
304
  }
486
305
  /** Separate fields of the same generated enum share its code/id mapping. */
487
306
  get outputType() {
@@ -491,18 +310,12 @@ var EnumFieldSerde = class EnumFieldSerde {
491
310
  arrayElementSafe: true
492
311
  } : void 0;
493
312
  }
494
- setOnEntityFromRowData(data, rowData, rowIndex) {
495
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
496
- }
497
- dbValue(data) {
498
- return this.mapToDbValue(data[this.fieldName]);
499
- }
500
313
  /** Resolves the enum code to its stored id, leaving an unknown code unset. */
501
314
  mapToDbValue(value) {
502
315
  return this.enumObject.findByCode(value)?.id;
503
316
  }
504
- rowValue(data) {
505
- return this.dbValue(data);
317
+ mapToRow(value) {
318
+ return this.mapToDbValue(value);
506
319
  }
507
320
  mapToDb(value) {
508
321
  return this.enumObject.findByCode(value)?.id;
@@ -516,40 +329,21 @@ var EnumFieldSerde = class EnumFieldSerde {
516
329
  }
517
330
  };
518
331
  var EnumArrayFieldSerde = class {
519
- fieldName;
520
- columnName;
521
332
  dbType;
522
- isNullableArray;
523
333
  enumObject;
524
- sqlNullable;
525
- hasDefault;
526
- isGenerated;
527
334
  isArray = true;
528
- columns = [this];
529
- constructor(fieldName, columnName, dbType, isNullableArray, enumObject, column) {
530
- this.fieldName = fieldName;
531
- this.columnName = columnName;
335
+ constructor(dbType, enumObject) {
532
336
  this.dbType = dbType;
533
- this.isNullableArray = isNullableArray;
534
337
  this.enumObject = enumObject;
535
- this.sqlNullable = column?.sqlNullable;
536
- this.hasDefault = column?.hasDefault;
537
- this.isGenerated = column?.isGenerated;
538
338
  }
539
339
  /** Physical enum arrays reject null elements, unlike scalar enum arrayAgg; leave them unknown. */
540
340
  get outputType() {}
541
- setOnEntityFromRowData(data, rowData, rowIndex) {
542
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
543
- }
544
- dbValue(data) {
545
- return this.mapToDbValue(data[this.fieldName]);
546
- }
547
341
  /** Resolves each enum code to its stored id, retaining the entity's empty-array default. */
548
342
  mapToDbValue(value) {
549
343
  return value?.map((code) => this.enumObject.getByCode(code).id) || [];
550
344
  }
551
- rowValue(data) {
552
- return this.dbValue(data);
345
+ mapToRow(value) {
346
+ return this.mapToDbValue(value);
553
347
  }
554
348
  mapToDb(value) {
555
349
  return !value ? [] : value.map((code) => this.enumObject.getByCode(code).id);
@@ -564,24 +358,12 @@ var EnumArrayFieldSerde = class {
564
358
  };
565
359
  /** Similar to SimpleSerde, but applies the superstruct `assert` function when reading values from the db. */
566
360
  var SuperstructSerde = class SuperstructSerde {
567
- fieldName;
568
- columnName;
569
361
  superstruct;
570
- sqlNullable;
571
- hasDefault;
572
- isGenerated;
573
362
  dbType = "jsonb";
574
363
  isArray = false;
575
- isNullableArray = false;
576
- columns = [this];
577
364
  assert = runtimeRequire("superstruct").assert;
578
- constructor(fieldName, columnName, superstruct, column) {
579
- this.fieldName = fieldName;
580
- this.columnName = columnName;
365
+ constructor(superstruct) {
581
366
  this.superstruct = superstruct;
582
- this.sqlNullable = column?.sqlNullable;
583
- this.hasDefault = column?.hasDefault;
584
- this.isGenerated = column?.isGenerated;
585
367
  }
586
368
  /** JSON schemas describe a jsonb value, even when that value is a JSON array. */
587
369
  get outputType() {
@@ -591,18 +373,12 @@ var SuperstructSerde = class SuperstructSerde {
591
373
  arrayElementSafe: true
592
374
  } : void 0;
593
375
  }
594
- setOnEntityFromRowData(data, rowData, rowIndex) {
595
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
596
- }
597
- dbValue(data) {
598
- return this.mapToDbValue(data[this.fieldName]);
599
- }
600
376
  /** Serializes the domain JSON value without running the read-time schema validation. */
601
377
  mapToDbValue(value) {
602
378
  return JSON.stringify(value);
603
379
  }
604
- rowValue(data) {
605
- return data[this.fieldName];
380
+ mapToRow(value) {
381
+ return value;
606
382
  }
607
383
  mapToDb(value) {
608
384
  return JSON.stringify(value);
@@ -618,22 +394,9 @@ var SuperstructSerde = class SuperstructSerde {
618
394
  }
619
395
  };
620
396
  var JsonSerde = class JsonSerde {
621
- fieldName;
622
- columnName;
623
- sqlNullable;
624
- hasDefault;
625
- isGenerated;
626
397
  dbType = "jsonb";
627
398
  isArray = false;
628
- isNullableArray = false;
629
- columns = [this];
630
- constructor(fieldName, columnName, column) {
631
- this.fieldName = fieldName;
632
- this.columnName = columnName;
633
- this.sqlNullable = column?.sqlNullable;
634
- this.hasDefault = column?.hasDefault;
635
- this.isGenerated = column?.isGenerated;
636
- }
399
+ constructor() {}
637
400
  /** Unvalidated JSON uses its own encoder, not a primitive or schema-specific codec. */
638
401
  get outputType() {
639
402
  return this.constructor === JsonSerde && !this.isArray ? {
@@ -642,18 +405,12 @@ var JsonSerde = class JsonSerde {
642
405
  arrayElementSafe: true
643
406
  } : void 0;
644
407
  }
645
- setOnEntityFromRowData(data, rowData, rowIndex) {
646
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
647
- }
648
- dbValue(data) {
649
- return this.mapToDbValue(data[this.fieldName]);
650
- }
651
408
  /** Serializes the whole JSON value, including JSON arrays and custom toJSON methods. */
652
409
  mapToDbValue(value) {
653
410
  return JSON.stringify(value);
654
411
  }
655
- rowValue(data) {
656
- const json = JSON.stringify(data[this.fieldName]);
412
+ mapToRow(value) {
413
+ const json = JSON.stringify(value);
657
414
  return isDefined(json) ? JSON.parse(json) : void 0;
658
415
  }
659
416
  mapToDb(value) {
@@ -669,23 +426,11 @@ var JsonSerde = class JsonSerde {
669
426
  };
670
427
  /** Similar to SimpleSerde, but applies the zod's `parse` function when reading values from the db. */
671
428
  var ZodSerde = class ZodSerde {
672
- fieldName;
673
- columnName;
674
429
  zodSchema;
675
- sqlNullable;
676
- hasDefault;
677
- isGenerated;
678
430
  dbType = "jsonb";
679
431
  isArray = false;
680
- isNullableArray = false;
681
- columns = [this];
682
- constructor(fieldName, columnName, zodSchema, column) {
683
- this.fieldName = fieldName;
684
- this.columnName = columnName;
432
+ constructor(zodSchema) {
685
433
  this.zodSchema = zodSchema;
686
- this.sqlNullable = column?.sqlNullable;
687
- this.hasDefault = column?.hasDefault;
688
- this.isGenerated = column?.isGenerated;
689
434
  }
690
435
  /** Parsing and transformations are compatible only for the same schema object. */
691
436
  get outputType() {
@@ -695,18 +440,12 @@ var ZodSerde = class ZodSerde {
695
440
  arrayElementSafe: true
696
441
  } : void 0;
697
442
  }
698
- setOnEntityFromRowData(data, rowData, rowIndex) {
699
- data[this.fieldName] = this.mapFromDb(rowData.get(rowIndex, this.columnName));
700
- }
701
- dbValue(data) {
702
- return this.mapToDbValue(data[this.fieldName]);
703
- }
704
443
  /** Serializes the domain JSON value without running the read-time Zod parser or transforms. */
705
444
  mapToDbValue(value) {
706
445
  return JSON.stringify(value);
707
446
  }
708
- rowValue(data) {
709
- return data[this.fieldName];
447
+ mapToRow(value) {
448
+ return value;
710
449
  }
711
450
  mapToDb(value) {
712
451
  return JSON.stringify(value);
@@ -742,6 +481,6 @@ function maybeNullToUndefined(value) {
742
481
  return value === null ? void 0 : value;
743
482
  }
744
483
  //#endregion
745
- export { BigIntSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PolymorphicKeySerde, PrimitiveSerde, SuperstructSerde, ZodSerde, ZonedDateTimeSerde, hasSerde };
484
+ export { BigIntSerde, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, EnumArrayFieldSerde, EnumFieldSerde, JsonSerde, KeySerde, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PrimitiveSerde, SuperstructSerde, ZodSerde, ZonedDateTimeSerde };
746
485
 
747
486
  //# sourceMappingURL=serde.js.map