@rvoh/dream 2.25.0 → 2.27.0

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 (249) hide show
  1. package/dist/cjs/src/Dream.js +10 -18
  2. package/dist/cjs/src/cli/index.js +31 -5
  3. package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +127 -6
  4. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +0 -18
  5. package/dist/cjs/src/dream/Query.js +0 -23
  6. package/dist/cjs/src/dream/QueryDriver/Kysely.js +8 -8
  7. package/dist/cjs/src/dream/internal/printSerializerHierarchyLevel.js +4 -3
  8. package/dist/cjs/src/dream/internal/resolveSerializerAssociationEdges.js +14 -1
  9. package/dist/cjs/src/errors/DropEnumValueRetypeFailed.js +208 -0
  10. package/dist/cjs/src/errors/serializers/MissingSerializersDefinition.js +16 -2
  11. package/dist/cjs/src/errors/serializers/MissingSerializersDefinitionForKey.js +5 -2
  12. package/dist/cjs/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +5 -3
  13. package/dist/cjs/src/errors/serializers/NoSerializersResolvedForKey.js +5 -2
  14. package/dist/cjs/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +5 -3
  15. package/dist/cjs/src/errors/serializers/serializerResolutionContextMessage.js +46 -0
  16. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +7 -1
  17. package/dist/cjs/src/helpers/cli/generateMigrationContent.js +80 -13
  18. package/dist/cjs/src/helpers/cli/syncWithFailureContext.js +41 -0
  19. package/dist/cjs/src/serializer/SerializerRenderer.js +32 -4
  20. package/dist/cjs/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +28 -10
  21. package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +6 -1
  22. package/dist/cjs/src/serializer/helpers/serializerGlobalName.js +16 -0
  23. package/dist/esm/src/Dream.js +10 -18
  24. package/dist/esm/src/cli/index.js +31 -5
  25. package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +127 -6
  26. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +0 -18
  27. package/dist/esm/src/dream/Query.js +0 -23
  28. package/dist/esm/src/dream/QueryDriver/Kysely.js +8 -8
  29. package/dist/esm/src/dream/internal/printSerializerHierarchyLevel.js +4 -3
  30. package/dist/esm/src/dream/internal/resolveSerializerAssociationEdges.js +14 -1
  31. package/dist/esm/src/errors/DropEnumValueRetypeFailed.js +208 -0
  32. package/dist/esm/src/errors/serializers/MissingSerializersDefinition.js +16 -2
  33. package/dist/esm/src/errors/serializers/MissingSerializersDefinitionForKey.js +5 -2
  34. package/dist/esm/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +5 -3
  35. package/dist/esm/src/errors/serializers/NoSerializersResolvedForKey.js +5 -2
  36. package/dist/esm/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +5 -3
  37. package/dist/esm/src/errors/serializers/serializerResolutionContextMessage.js +46 -0
  38. package/dist/esm/src/helpers/cli/generateFactoryContent.js +7 -1
  39. package/dist/esm/src/helpers/cli/generateMigrationContent.js +80 -13
  40. package/dist/esm/src/helpers/cli/syncWithFailureContext.js +41 -0
  41. package/dist/esm/src/serializer/SerializerRenderer.js +32 -4
  42. package/dist/esm/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +28 -10
  43. package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +6 -1
  44. package/dist/esm/src/serializer/helpers/serializerGlobalName.js +16 -0
  45. package/dist/types/src/Dream.d.ts +10 -3
  46. package/dist/types/src/cli/index.d.ts +1 -1
  47. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +3 -2
  48. package/dist/types/src/dream/Query.d.ts +3 -2
  49. package/dist/types/src/errors/DropEnumValueRetypeFailed.d.ts +89 -0
  50. package/dist/types/src/errors/serializers/MissingSerializersDefinition.d.ts +3 -1
  51. package/dist/types/src/errors/serializers/MissingSerializersDefinitionForKey.d.ts +3 -1
  52. package/dist/types/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.d.ts +3 -1
  53. package/dist/types/src/errors/serializers/NoSerializersResolvedForKey.d.ts +3 -1
  54. package/dist/types/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.d.ts +3 -1
  55. package/dist/types/src/errors/serializers/serializerResolutionContextMessage.d.ts +20 -0
  56. package/dist/types/src/helpers/cli/syncWithFailureContext.d.ts +58 -0
  57. package/dist/types/src/serializer/helpers/inferSerializerFromDreamOrViewModel.d.ts +11 -4
  58. package/dist/types/src/serializer/helpers/serializerGlobalName.d.ts +15 -0
  59. package/dist/types/src/types/associations/shared.d.ts +1 -1
  60. package/dist/types/src/types/dream.d.ts +3 -0
  61. package/dist/types/src/types/query.d.ts +1 -1
  62. package/dist/types/src/types/serializer.d.ts +38 -0
  63. package/dist/types/src/types/types/associations/shared.ts +8 -6
  64. package/dist/types/src/types/types/dream.ts +6 -0
  65. package/dist/types/src/types/types/query.ts +1 -1
  66. package/dist/types/src/types/types/serializer.ts +40 -0
  67. package/docs/assets/search.js +1 -1
  68. package/docs/classes/db.DreamMigrationHelpers.html +11 -11
  69. package/docs/classes/db.KyselyQueryDriver.html +40 -40
  70. package/docs/classes/db.PostgresQueryDriver.html +41 -41
  71. package/docs/classes/db.QueryDriverBase.html +39 -39
  72. package/docs/classes/errors.CheckConstraintViolation.html +3 -3
  73. package/docs/classes/errors.ColumnOverflow.html +3 -3
  74. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  75. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
  76. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
  77. package/docs/classes/errors.DecryptionError.html +2 -2
  78. package/docs/classes/errors.DecryptionParseError.html +2 -2
  79. package/docs/classes/errors.DecryptionRotationError.html +3 -3
  80. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  81. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  82. package/docs/classes/errors.InvalidClockTime.html +2 -2
  83. package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
  84. package/docs/classes/errors.InvalidDateTime.html +2 -2
  85. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  86. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  87. package/docs/classes/errors.NotNullViolation.html +3 -3
  88. package/docs/classes/errors.RecordNotFound.html +3 -3
  89. package/docs/classes/errors.ValidationError.html +3 -3
  90. package/docs/classes/index.CalendarDate.html +33 -33
  91. package/docs/classes/index.ClockTime.html +32 -32
  92. package/docs/classes/index.ClockTimeTz.html +35 -35
  93. package/docs/classes/index.DateTime.html +86 -86
  94. package/docs/classes/index.Decorators.html +19 -19
  95. package/docs/classes/index.Dream.html +132 -138
  96. package/docs/classes/index.DreamApp.html +10 -10
  97. package/docs/classes/index.DreamTransaction.html +2 -2
  98. package/docs/classes/index.Env.html +2 -2
  99. package/docs/classes/index.Query.html +93 -80
  100. package/docs/classes/system.CliFileWriter.html +4 -4
  101. package/docs/classes/system.DreamBin.html +2 -2
  102. package/docs/classes/system.DreamCLI.html +7 -7
  103. package/docs/classes/system.DreamImporter.html +2 -2
  104. package/docs/classes/system.DreamLogos.html +2 -2
  105. package/docs/classes/system.DreamSerializerBuilder.html +11 -11
  106. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  107. package/docs/classes/system.PathHelpers.html +3 -3
  108. package/docs/classes/utils.Encrypt.html +3 -3
  109. package/docs/classes/utils.Range.html +2 -2
  110. package/docs/functions/db.closeAllDbConnections.html +1 -1
  111. package/docs/functions/db.dreamDbConnections.html +1 -1
  112. package/docs/functions/db.untypedDb.html +1 -1
  113. package/docs/functions/db.validateColumn.html +1 -1
  114. package/docs/functions/db.validateTable.html +1 -1
  115. package/docs/functions/errors.pgErrorType.html +1 -1
  116. package/docs/functions/index.DreamSerializer.html +1 -1
  117. package/docs/functions/index.ObjectSerializer.html +1 -1
  118. package/docs/functions/index.ReplicaSafe.html +1 -1
  119. package/docs/functions/index.STI.html +1 -1
  120. package/docs/functions/index.SoftDelete.html +1 -1
  121. package/docs/functions/utils.camelize.html +1 -1
  122. package/docs/functions/utils.capitalize.html +1 -1
  123. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  124. package/docs/functions/utils.compact.html +1 -1
  125. package/docs/functions/utils.groupBy.html +1 -1
  126. package/docs/functions/utils.hyphenize.html +1 -1
  127. package/docs/functions/utils.intersection.html +1 -1
  128. package/docs/functions/utils.isEmpty.html +1 -1
  129. package/docs/functions/utils.normalizeUnicode.html +1 -1
  130. package/docs/functions/utils.pascalize.html +1 -1
  131. package/docs/functions/utils.percent.html +1 -1
  132. package/docs/functions/utils.range.html +1 -1
  133. package/docs/functions/utils.round.html +1 -1
  134. package/docs/functions/utils.sanitizeString.html +1 -1
  135. package/docs/functions/utils.snakeify.html +1 -1
  136. package/docs/functions/utils.sort.html +1 -1
  137. package/docs/functions/utils.sortBy.html +1 -1
  138. package/docs/functions/utils.sortObjectByKey.html +1 -1
  139. package/docs/functions/utils.sortObjectByValue.html +1 -1
  140. package/docs/functions/utils.uncapitalize.html +1 -1
  141. package/docs/functions/utils.uniq.html +1 -1
  142. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  143. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  144. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  145. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  146. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  147. package/docs/interfaces/types.DecoratorContext.html +2 -2
  148. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  149. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  150. package/docs/interfaces/types.DreamDbConfig.html +5 -5
  151. package/docs/interfaces/types.DurationObject.html +2 -2
  152. package/docs/interfaces/types.EncryptOptions.html +2 -2
  153. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  154. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  155. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  156. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  157. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  158. package/docs/types/openapi.OpenapiFormats.html +1 -1
  159. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  160. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  161. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  163. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  164. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  165. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  166. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  167. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  168. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  169. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  170. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  171. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  172. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  173. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  174. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  175. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  176. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  177. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  178. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  179. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  180. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  181. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  182. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  183. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  184. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  185. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  186. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  187. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  188. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  189. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  190. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  191. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  192. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  193. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  194. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  195. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  196. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  197. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  198. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  199. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  200. package/docs/types/types.CalendarDateObject.html +1 -1
  201. package/docs/types/types.Camelized.html +1 -1
  202. package/docs/types/types.ClockTimeObject.html +1 -1
  203. package/docs/types/types.DbConnectionType.html +1 -1
  204. package/docs/types/types.DbTypes.html +1 -1
  205. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  206. package/docs/types/types.DreamAttributes.html +1 -1
  207. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  208. package/docs/types/types.DreamClassColumn.html +1 -1
  209. package/docs/types/types.DreamColumn.html +1 -1
  210. package/docs/types/types.DreamColumnNames.html +1 -1
  211. package/docs/types/types.DreamLogLevel.html +1 -1
  212. package/docs/types/types.DreamLogger.html +2 -2
  213. package/docs/types/types.DreamModelSerializerType.html +1 -1
  214. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  215. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  216. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  217. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  218. package/docs/types/types.DreamSerializable.html +1 -1
  219. package/docs/types/types.DreamSerializableArray.html +1 -1
  220. package/docs/types/types.DreamSerializerKey.html +1 -1
  221. package/docs/types/types.DreamSerializers.html +1 -1
  222. package/docs/types/types.DreamVirtualColumns.html +1 -1
  223. package/docs/types/types.DurationUnit.html +1 -1
  224. package/docs/types/types.EncryptAlgorithm.html +1 -1
  225. package/docs/types/types.HasManyStatement.html +1 -1
  226. package/docs/types/types.HasOneStatement.html +1 -1
  227. package/docs/types/types.Hyphenized.html +1 -1
  228. package/docs/types/types.Pascalized.html +1 -1
  229. package/docs/types/types.PrimaryKeyType.html +1 -1
  230. package/docs/types/types.RoundingPrecision.html +1 -1
  231. package/docs/types/types.SerializerCasing.html +1 -1
  232. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  233. package/docs/types/types.Snakeified.html +1 -1
  234. package/docs/types/types.StrictInterface.html +1 -1
  235. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  236. package/docs/types/types.UpdateableProperties.html +1 -1
  237. package/docs/types/types.ValidationType.html +1 -1
  238. package/docs/types/types.ViewModel.html +2 -2
  239. package/docs/types/types.ViewModelClass.html +1 -1
  240. package/docs/types/types.WeekdayName.html +1 -1
  241. package/docs/types/types.WhereStatementForDream.html +1 -1
  242. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  243. package/docs/variables/index.DreamConst.html +1 -1
  244. package/docs/variables/index.ops.html +1 -1
  245. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  246. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  247. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  248. package/docs/variables/system.primaryKeyTypes.html +1 -1
  249. package/package.json +1 -1
@@ -9,33 +9,51 @@ import expandStiClasses from '../../helpers/sti/expandStiClasses.js';
9
9
  import uniq from '../../helpers/uniq.js';
10
10
  import isDreamSerializer from './isDreamSerializer.js';
11
11
  export const DEFAULT_SERIALIZER_KEY = 'default';
12
- export default function inferSerializerFromDreamOrViewModel(obj, serializerKey = DEFAULT_SERIALIZER_KEY) {
12
+ /**
13
+ * `resolutionContext` says how resolution reached `obj` — the `rendersOne`/`rendersMany` edge that
14
+ * led here, and the STI base it was expanded from. It is threaded down purely so that the errors
15
+ * below can name the route instead of only the class, and it is optional so that a caller with no
16
+ * route to describe (and every existing caller outside this repo) is unaffected. See
17
+ * `SerializerResolutionContext`.
18
+ */
19
+ export default function inferSerializerFromDreamOrViewModel(obj, serializerKey = DEFAULT_SERIALIZER_KEY, resolutionContext) {
13
20
  if (!obj)
14
21
  return null;
15
22
  const serializers = obj.serializers;
16
23
  if (!serializers)
17
- throw new MissingSerializersDefinition(obj);
24
+ throw new MissingSerializersDefinition(obj, serializerKey, resolutionContext);
18
25
  const serializerOrGlobalName = serializers[serializerKey];
19
26
  if (!serializerOrGlobalName)
20
- throw new MissingSerializersDefinitionForKey(obj, serializerKey);
27
+ throw new MissingSerializersDefinitionForKey(obj, serializerKey, resolutionContext);
21
28
  if (isDreamSerializer(serializerOrGlobalName))
22
29
  return serializerOrGlobalName;
23
30
  const globalName = serializerOrGlobalName;
24
31
  const dreamApp = DreamApp.getOrFail();
25
32
  const serializer = dreamApp.serializers[globalName];
26
33
  if (!serializer)
27
- throw new NoGlobalSerializerForSpecifiedKey(obj, serializerKey, globalName);
34
+ throw new NoGlobalSerializerForSpecifiedKey(obj, serializerKey, globalName, resolutionContext);
28
35
  if (!isDreamSerializer(serializer))
29
- throw new NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey(obj, serializerKey, globalName, serializer);
36
+ throw new NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey(obj, serializerKey, globalName, serializer, resolutionContext);
30
37
  return serializer;
31
38
  }
32
- export function inferSerializersFromDreamClassOrViewModelClass(classDef, serializerKey = undefined) {
39
+ export function inferSerializersFromDreamClassOrViewModelClass(classDef, serializerKey = undefined, resolutionContext) {
33
40
  if (!classDef)
34
41
  return [];
35
42
  const classes = expandStiClasses(classDef);
36
- const serializers = classes.map(classDef => inferSerializerFromDreamOrViewModel(classDef.prototype, serializerKey));
43
+ // This is the one place that knows *whether* the class an error ends up naming came from STI
44
+ // expansion: below this line the class the caller passed is gone, replaced by one child per
45
+ // iteration, and every downstream error names a child. Identity rather than `isSTIBase` because
46
+ // `classDef` may be a ViewModelClass, which `expandStiClasses` hands straight back.
47
+ const expandedFromStiBase = classes.length !== 1 || classes[0] !== classDef;
48
+ const childResolutionContext = expandedFromStiBase
49
+ ? { ...resolutionContext, stiBase: stiBaseName(classDef) }
50
+ : resolutionContext;
51
+ const serializers = classes.map(classDef => inferSerializerFromDreamOrViewModel(classDef.prototype, serializerKey, childResolutionContext));
37
52
  return uniq(compact(serializers));
38
53
  }
54
+ function stiBaseName(classDef) {
55
+ return classDef.sanitizedName ?? classDef.name;
56
+ }
39
57
  /**
40
58
  * As `inferSerializersFromDreamClassOrViewModelClass`, but guarantees a non-empty result.
41
59
  *
@@ -51,9 +69,9 @@ export function inferSerializersFromDreamClassOrViewModelClass(classDef, seriali
51
69
  * preload-path building and serialization display — so that they raise one typed error between
52
70
  * them.
53
71
  */
54
- export function inferSerializersFromDreamClassOrViewModelClassOrFail(classDef, serializerKey) {
55
- const serializers = inferSerializersFromDreamClassOrViewModelClass(classDef, serializerKey);
72
+ export function inferSerializersFromDreamClassOrViewModelClassOrFail(classDef, serializerKey, resolutionContext) {
73
+ const serializers = inferSerializersFromDreamClassOrViewModelClass(classDef, serializerKey, resolutionContext);
56
74
  if (serializers.length === 0)
57
- throw new NoSerializersResolvedForKey(classDef, serializerKey);
75
+ throw new NoSerializersResolvedForKey(classDef, serializerKey, resolutionContext);
58
76
  return serializers;
59
77
  }
@@ -28,5 +28,10 @@ export function serializerForAssociatedClass(object, associationName, options) {
28
28
  // would flatten. Unioning every child's serializer here — which is what buildSerializerPreloadPaths
29
29
  // does for preload paths — is meaningless: exactly one set of keys can be flattened into the
30
30
  // payload.
31
- return inferSerializersFromDreamClassOrViewModelClass(associatedClass, options.serializerKey)[0] ?? null;
31
+ return (inferSerializersFromDreamClassOrViewModelClass(associatedClass, options.serializerKey, {
32
+ // Reached only from SerializerRenderer's rendersOne branch, so the edge type is fixed. No
33
+ // declaring serializer: the renderer holds the rendered attribute, not the serializer that
34
+ // declared it.
35
+ edge: { type: 'rendersOne', associationName },
36
+ })[0] ?? null);
32
37
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @internal
3
+ *
4
+ * The single reader of a serializer's `globalName`.
5
+ *
6
+ * Serializers are plain functions; `globalName` is stamped onto them by `importSerializers` when the
7
+ * app loads them, so the property is not on any serializer type and every reader would otherwise
8
+ * have to invent its own cast — three different spellings of it existed before this helper.
9
+ *
10
+ * `undefined` is a legitimate answer: a serializer built inline (a spec, or a `{ serializer }`
11
+ * option) is never stamped. Callers decide what that means for them — the resolution-context message
12
+ * simply drops the declarer.
13
+ */
14
+ export default function serializerGlobalName(serializer) {
15
+ return serializer.globalName;
16
+ }
@@ -8,7 +8,7 @@ import LoadBuilder from './dream/LoadBuilder.js';
8
8
  import Query from './dream/Query.js';
9
9
  import { OnStatementForSpecificColumns, PassthroughOnClause, WhereStatement } from './types/associations/shared.js';
10
10
  import { AssociationTableNames, DbConnectionType } from './types/db.js';
11
- import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, CreateOrFindByExtraOpts, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAssociationNamesWithPassthroughOnClauses, DreamAssociationNamesWithRequiredOnClauses, DreamAttributes, DreamBelongsToAssociationNames, DreamColumnNames, DreamHasManyAssociationNames, DreamHasOneAssociationNames, DreamModelAssociationNames, DreamParamSafeColumnNames, DreamPrimaryKeyType, DreamSerializerKey, FindablePropertiesForClass, GlobalModelNames, GlobalSerializerName, JoinAndStatements, OrderDir, PassthroughColumnNames, PassthroughOnClauseKeys, PluckEachArgs, PrimaryKeyForFind, RequiredOnClauseKeys, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from './types/dream.js';
11
+ import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, CreateOrFindByExtraOpts, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAssociationNamesWithPassthroughOnClauses, DreamAssociationNamesWithRequiredOnClauses, DreamAttributes, DreamBelongsToAssociationNames, DreamColumnNames, DreamHasManyAssociationNames, DreamHasOneAssociationNames, DreamModelAssociationNames, DreamPrimaryKeyType, DreamSerializerKey, FindablePropertiesForClass, GlobalModelNames, GlobalSerializerName, JoinAndStatements, OrderDir, PassthroughColumnNames, PassthroughOnClauseKeys, PluckEachArgs, PrimaryKeyForFind, RequiredOnClauseKeys, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts, ValidatedPluckEachColumnNames } from './types/dream.js';
12
12
  import { BaseModelColumnTypes, CursorPaginatedDreamQueryOptions, CursorPaginatedDreamQueryResult, DefaultQueryTypeOptions, FindEachOpts, LoadForModifierFn, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from './types/query.js';
13
13
  import { DreamModelSerializerType, SimpleObjectSerializerType } from './types/serializer.js';
14
14
  import { ValidationType } from './types/validation.js';
@@ -458,9 +458,15 @@ export default class Dream {
458
458
  * * foreign key fields for belongs to associations (these should usually be verified before being set)
459
459
  * * type fields corresponding to polymorphic associations
460
460
  *
461
+ * @internal
462
+ *
463
+ * Not part of the public API. Psychic reaches it through the bracketed
464
+ * back-door (`dreamClass['paramSafeColumnsOrFallback']()`), the same escape
465
+ * hatch used for other Dream internals such as `virtualAttributes`.
466
+ *
461
467
  * @returns A subset of columns for the given dream class
462
468
  */
463
- static paramSafeColumnsOrFallback<T extends typeof Dream, I extends InstanceType<T>, ParamSafeColumnsOverride extends InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] extends never ? undefined : InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] & string[], ReturnVal extends ParamSafeColumnsOverride extends string[] ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[]>(this: T): ReturnVal;
469
+ private static paramSafeColumnsOrFallback;
464
470
  private static defaultParamSafeColumns;
465
471
  /**
466
472
  * @internal
@@ -1439,7 +1445,8 @@ export default class Dream {
1439
1445
  * @param args - a list of fields to pluck, followed by a callback function to call for each set of found fields
1440
1446
  * @returns void
1441
1447
  */
1442
- static pluckEach<T extends typeof Dream, I extends InstanceType<T>, ColumnNames extends TableColumnNames<I['DB'], I['table']>[], CbArgTypes extends BaseModelColumnTypes<ColumnNames, I>>(this: T, ...args: PluckEachArgs<ColumnNames, CbArgTypes>): Promise<void>;
1448
+ static pluckEach<T extends typeof Dream, I extends InstanceType<T>, const ColumnNames extends unknown[]>(this: T, ...args: PluckEachArgs<ValidatedPluckEachColumnNames<ColumnNames, TableColumnNames<I['DB'], I['table']>>, BaseModelColumnTypes<ValidatedPluckEachColumnNames<ColumnNames, TableColumnNames<I['DB'], I['table']>>, I>>): Promise<void>;
1449
+ static pluckEach<T extends typeof Dream, I extends InstanceType<T>, const ColumnNames extends TableColumnNames<I['DB'], I['table']>[]>(this: T, ...args: PluckEachArgs<ColumnNames, BaseModelColumnTypes<ColumnNames, I>>): Promise<void>;
1443
1450
  /**
1444
1451
  * Used in conjunction with the Sortable decorator, `resort`
1445
1452
  * takes a list of sortable fields, and for each one, finds and
@@ -23,7 +23,7 @@ export declare const columnsWithTypesDescriptionForStiChild: string;
23
23
  * example that drifts from what the generator actually produces then fails the
24
24
  * suite instead of shipping.
25
25
  */
26
- export declare const migrationNameArgumentDescription = "Kebab-case name describing the change. A -to-<table_name>\n anywhere in the name \u2014 not just at the end \u2014 auto-generates\n an add-columns alterTable scaffold for that table;\n -from-<table_name> generates a remove-columns scaffold, but\n only when the name contains no -to- at all. The text after\n the marker's first occurrence is snake-cased and pluralized\n into the table name, so add-a-to-b-to-cs targets b_to_cs. A\n hand-written migration must avoid both strings anywhere in\n its name.\n \n Examples:\n add-phone-to-users phone:encrypted # scaffolds alterTable('users', ...)\n remove-status-from-posts status:string # scaffolds alterTable('posts', ...)\n create-many-to-many-posts-users # WRONG: selects 'many_posts_users'\n # -to- inside \"many-to-many\" matches: with no columns\n # this errors; with columns it silently scaffolds it\n create-posts-users-join-table # correct: no marker match\n # scaffolds alterTable('<table-name>') to hand-edit";
26
+ export declare const migrationNameArgumentDescription = "Kebab-case name describing the change. A -to-<table_name>\n anywhere in the name \u2014 not just at the end \u2014 auto-generates\n an add-columns alterTable scaffold for that table;\n -from-<table_name> generates a remove-columns scaffold, but\n only when the name contains no -to- at all. The text after\n the marker's first occurrence is snake-cased and pluralized\n into the table name, so add-a-to-b-to-cs targets b_to_cs. A\n hand-written migration must avoid both strings anywhere in\n its name.\n \n Examples:\n add-phone-to-users phone:encrypted # scaffolds alterTable('users', ...)\n remove-status-from-posts status:string # scaffolds alterTable('posts', ...)\n create-many-to-many-posts-users # WRONG: selects 'many_posts_users'\n # -to- inside \"many-to-many\" matches: with no columns\n # this errors; with columns it silently scaffolds it\n create-posts-users-join-table # correct: no marker match\n # with no columns, generates empty up/down methods to\n # write by hand; with columns, scaffolds\n # alterTable('<table-name>') to hand-edit";
27
27
  export default class DreamCLI {
28
28
  /**
29
29
  * Starts the Dream console
@@ -1,7 +1,7 @@
1
1
  import { SelectArg, SelectExpression } from 'kysely';
2
2
  import Dream from '../Dream.js';
3
3
  import { PassthroughOnClause, WhereStatement } from '../types/associations/shared.js';
4
- import { CreateOrFindByExtraOpts, DefaultScopeName, DreamColumnNames, DreamSerializerKey, FindablePropertiesForClass, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateOrCreateByExtraOpts } from '../types/dream.js';
4
+ import { CreateOrFindByExtraOpts, DefaultScopeName, DreamColumnNames, DreamSerializerKey, FindablePropertiesForClass, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateOrCreateByExtraOpts, ValidatedPluckEachColumnNames } from '../types/dream.js';
5
5
  import { BaseModelColumnTypes, FindEachOpts, LoadForModifierFn, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from '../types/query.js';
6
6
  import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
7
7
  import DreamTransaction from './DreamTransaction.js';
@@ -730,7 +730,8 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
730
730
  * @param fields - A list of fields to pluck, followed by a callback function to call for each set of found fields
731
731
  * @returns void
732
732
  */
733
- pluckEach<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, ColumnName extends keyof UpdateableProperties<DreamInstance>, ColumnNames extends ColumnName[], CbArgTypes extends BaseModelColumnTypes<ColumnNames, DreamInstance>>(this: I, ...args: PluckEachArgs<ColumnNames, CbArgTypes>): Promise<void>;
733
+ pluckEach<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, const ColumnNames extends unknown[]>(this: I, ...args: PluckEachArgs<ValidatedPluckEachColumnNames<ColumnNames, keyof UpdateableProperties<DreamInstance>>, BaseModelColumnTypes<ValidatedPluckEachColumnNames<ColumnNames, keyof UpdateableProperties<DreamInstance>>, DreamInstance>>): Promise<void>;
734
+ pluckEach<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, const ColumnNames extends (keyof UpdateableProperties<DreamInstance>)[]>(this: I, ...args: PluckEachArgs<ColumnNames, BaseModelColumnTypes<ColumnNames, DreamInstance>>): Promise<void>;
734
735
  /**
735
736
  * Sends data through for use as passthrough data
736
737
  * for the associations that require it.
@@ -2,7 +2,7 @@ import { DeleteQueryBuilder, SelectQueryBuilder, UpdateQueryBuilder } from 'kyse
2
2
  import Dream from '../Dream.js';
3
3
  import { ColumnNamesAccountingForJoinedAssociations, InternalWhereStatement, LimitStatement, OffsetStatement, OrderQueryStatement, PassthroughOnClause, WhereStatement, WhereStatementForJoinedAssociation } from '../types/associations/shared.js';
4
4
  import { DbConnectionType } from '../types/db.js';
5
- import { AllDefaultScopeNames, DefaultScopeName, DreamColumnNames, DreamConstructorType, DreamSerializerKey, DreamTableSchema, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, RelaxedJoinAndStatement, RelaxedJoinStatement, RelaxedPreloadOnStatement, RelaxedPreloadStatement, TableColumnNames, TableOrAssociationName, UpdateableProperties } from '../types/dream.js';
5
+ import { AllDefaultScopeNames, DefaultScopeName, DreamColumnNames, DreamConstructorType, DreamSerializerKey, DreamTableSchema, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, RelaxedJoinAndStatement, RelaxedJoinStatement, RelaxedPreloadOnStatement, RelaxedPreloadStatement, TableColumnNames, TableOrAssociationName, UpdateableProperties, ValidatedPluckEachColumnNames } from '../types/dream.js';
6
6
  import { CursorPaginatedDreamQueryOptions, CursorPaginatedDreamQueryResult, DefaultQueryTypeOptions, ExtendQueryType, LoadForModifierFn, NamespacedOrBaseModelColumnTypes, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../types/query.js';
7
7
  import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, QueryTypeOptions, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
8
8
  import DreamTransaction from './DreamTransaction.js';
@@ -1006,7 +1006,8 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
1006
1006
  * @returns void
1007
1007
  * @throws BatchingIncompatibleWithLimitOrOffset if the query carries a `limit` or `offset`
1008
1008
  */
1009
- pluckEach<Q extends Query<DreamInstance, QueryTypeOpts>, DB extends DreamInstance['DB'], const ColumnNames extends ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DB, QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>[], CbArgTypes extends NamespacedOrBaseModelColumnTypes<ColumnNames, Q, DreamInstance>>(this: Q, ...args: PluckEachArgs<ColumnNames, CbArgTypes>): Promise<void>;
1009
+ pluckEach<Q extends Query<DreamInstance, QueryTypeOpts>, const ColumnNames extends unknown[]>(this: Q, ...args: PluckEachArgs<ValidatedPluckEachColumnNames<ColumnNames, ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DreamInstance['DB'], QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>>, NamespacedOrBaseModelColumnTypes<ValidatedPluckEachColumnNames<ColumnNames, ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DreamInstance['DB'], QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>>, Q, DreamInstance>>): Promise<void>;
1010
+ pluckEach<Q extends Query<DreamInstance, QueryTypeOpts>, const ColumnNames extends ColumnNamesAccountingForJoinedAssociations<Q['queryTypeOpts']['joinedAssociations'], DreamInstance['DB'], QueryTypeOpts['rootTableName'], QueryTypeOpts['rootTableAlias']>[]>(this: Q, ...args: PluckEachArgs<ColumnNames, NamespacedOrBaseModelColumnTypes<ColumnNames, Q, DreamInstance>>): Promise<void>;
1010
1011
  /**
1011
1012
  * Retrieves an array containing all records matching the Query.
1012
1013
  * Be careful using this, since it will attempt to pull every
@@ -0,0 +1,89 @@
1
+ /**
2
+ * A check constraint discovered on the column `dropEnumValue` was retyping.
3
+ */
4
+ export interface DropEnumValueCheckConstraint {
5
+ /** the constraint's name in `pg_constraint`, e.g. `pets_species_check` */
6
+ name: string;
7
+ /** the constraint as Postgres renders it, e.g. `CHECK (((species)::text <> 'forg'::text))` */
8
+ definition: string;
9
+ }
10
+ export interface DropEnumValueRetypeFailedOpts {
11
+ enumName: string;
12
+ value: string;
13
+ table: string;
14
+ column: string;
15
+ /**
16
+ * `toText` for the widen step that runs before the enum type is dropped and
17
+ * recreated; `toEnum` for the restore step that runs after it.
18
+ */
19
+ retypeDirection: 'toText' | 'toEnum';
20
+ /**
21
+ * Whether the pre-flight catalog read resolved `table` to a real relation. When it did
22
+ * not, `checkConstraints` being empty means "not read", not "none defined", and the
23
+ * message says so instead of asserting a negative it cannot support.
24
+ */
25
+ relationResolved: boolean;
26
+ checkConstraints: DropEnumValueCheckConstraint[];
27
+ originalError: Error;
28
+ }
29
+ /**
30
+ * Quote every segment of a possibly schema-qualified table name the way Kysely quotes the
31
+ * identifiers it emits, so a `to_regclass` argument resolves exactly the relation the retype
32
+ * targeted. Exported because `DreamMigrationHelpers`' catalog read and the diagnostic query in
33
+ * this message must name the relation identically; it lives here because that helper already
34
+ * imports this module, and the reverse import would be a cycle.
35
+ */
36
+ export declare function quotedRelationName(table: string): string;
37
+ /**
38
+ * Raised when one of the two column retypes inside
39
+ * `DreamMigrationHelpers.dropEnumValue` fails.
40
+ *
41
+ * The raw Postgres error for the common cause of this - a check constraint on the
42
+ * column that references the enum - is `operator does not exist: text <> my_enum`.
43
+ * It names no table, no column and no constraint, and the `text` in it comes from
44
+ * `dropEnumValue`'s own internal widen step, so it appears nowhere in the
45
+ * migration the developer wrote. This error supplies all of that, and keeps the
46
+ * original error reachable through both `originalError` and `cause`.
47
+ *
48
+ * It never claims a check constraint caused a failure it cannot tie to one. The SQLSTATE gate
49
+ * separates "a stored expression could not be re-derived" from "a bad value" — but it cannot
50
+ * say *which* expression, because an index predicate raises the identical code, so even on the
51
+ * gated path the constraints stay context and the message names the other candidates.
52
+ */
53
+ export default class DropEnumValueRetypeFailed extends Error {
54
+ readonly enumName: string;
55
+ readonly value: string;
56
+ readonly table: string;
57
+ readonly column: string;
58
+ readonly retypeDirection: 'toText' | 'toEnum';
59
+ readonly relationResolved: boolean;
60
+ readonly checkConstraints: DropEnumValueCheckConstraint[];
61
+ readonly originalError: Error;
62
+ constructor({ enumName, value, table, column, retypeDirection, relationResolved, checkConstraints, originalError, }: DropEnumValueRetypeFailedOpts);
63
+ get message(): string;
64
+ private get failingStepDescription();
65
+ private get stepExplanation();
66
+ /**
67
+ * True when the original error is one Postgres raises because a stored expression on the
68
+ * column could not be re-derived against its new type. A blocking check constraint is one
69
+ * source of that; a partial index predicate, an expression index and an uncastable column
70
+ * default are others. Anything else (a bad value, a missing relation, a permission error) is
71
+ * not evidence that any stored expression was involved.
72
+ */
73
+ private get originalErrorBlockedAnExpression();
74
+ private get checkConstraintsSection();
75
+ private get guidanceSection();
76
+ /**
77
+ * What the SQLSTATE does and does not establish, and every expression that raises it. The
78
+ * candidates are listed rather than diagnosed on purpose: `dropEnumValue` reads the column's
79
+ * check constraints and nothing else, so naming one of them as the cause would be a guess
80
+ * that sends the caller to drop a constraint that changes nothing.
81
+ */
82
+ private get expressionBlockerSection();
83
+ private get checkConstraintCandidateNote();
84
+ /**
85
+ * The copy-pasteable remedy, offered only when there is a constraint to drop and phrased as
86
+ * conditional on that constraint actually being the blocker — which this error cannot know.
87
+ */
88
+ private get constraintRemedySection();
89
+ }
@@ -1,7 +1,9 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModel } from '../../types/dream.js';
3
+ import { SerializerResolutionContext } from '../../types/serializer.js';
3
4
  export default class MissingSerializersDefinition extends Error {
5
+ #private;
4
6
  private viewModel;
5
- constructor(viewModel: Dream | ViewModel);
7
+ constructor(viewModel: Dream | ViewModel, serializerKey?: string, resolutionContext?: SerializerResolutionContext);
6
8
  get message(): string;
7
9
  }
@@ -1,8 +1,10 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModel } from '../../types/dream.js';
3
+ import { SerializerResolutionContext } from '../../types/serializer.js';
3
4
  export default class MissingSerializersDefinitionForKey extends Error {
4
5
  private viewModel;
5
6
  private serializerKey;
6
- constructor(viewModel: Dream | ViewModel, serializerKey: string);
7
+ private resolutionContext?;
8
+ constructor(viewModel: Dream | ViewModel, serializerKey: string, resolutionContext?: SerializerResolutionContext | undefined);
7
9
  get message(): string;
8
10
  }
@@ -1,9 +1,11 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModel } from '../../types/dream.js';
3
+ import { SerializerResolutionContext } from '../../types/serializer.js';
3
4
  export default class NoGlobalSerializerForSpecifiedKey extends Error {
4
5
  private viewModel;
5
6
  private serializerKey;
6
7
  private globalName;
7
- constructor(viewModel: Dream | ViewModel, serializerKey: string, globalName: string);
8
+ private resolutionContext?;
9
+ constructor(viewModel: Dream | ViewModel, serializerKey: string, globalName: string, resolutionContext?: SerializerResolutionContext | undefined);
8
10
  get message(): string;
9
11
  }
@@ -1,5 +1,6 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModelClass } from '../../types/dream.js';
3
+ import { SerializerResolutionContext } from '../../types/serializer.js';
3
4
  /**
4
5
  * Raised when resolving a serializer key against a class yields an empty set of serializers.
5
6
  *
@@ -13,6 +14,7 @@ import { ViewModelClass } from '../../types/dream.js';
13
14
  export default class NoSerializersResolvedForKey extends Error {
14
15
  private classDef;
15
16
  private serializerKey;
16
- constructor(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey: string);
17
+ private resolutionContext?;
18
+ constructor(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey: string, resolutionContext?: SerializerResolutionContext | undefined);
17
19
  get message(): string;
18
20
  }
@@ -1,10 +1,12 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModel } from '../../types/dream.js';
3
+ import { SerializerResolutionContext } from '../../types/serializer.js';
3
4
  export default class NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey extends Error {
4
5
  private viewModel;
5
6
  private serializerKey;
6
7
  private globalName;
7
8
  private serializer;
8
- constructor(viewModel: Dream | ViewModel, serializerKey: string, globalName: string, serializer: any);
9
+ private resolutionContext?;
10
+ constructor(viewModel: Dream | ViewModel, serializerKey: string, globalName: string, serializer: any, resolutionContext?: SerializerResolutionContext | undefined);
9
11
  get message(): string;
10
12
  }
@@ -0,0 +1,20 @@
1
+ import { SerializerResolutionContext } from '../../types/serializer.js';
2
+ /**
3
+ * @internal
4
+ *
5
+ * Renders the trailing "how did resolution reach this class" block shared by the five
6
+ * serializer-resolution errors.
7
+ *
8
+ * Every line is independently well-formed and a line is omitted entirely — no placeholder, no empty
9
+ * slot — when the path that raised the error does not have that fact. The paths differ, and
10
+ * deliberately so:
11
+ *
12
+ * - the serializer key is on every path, since it is an argument of resolution itself;
13
+ * - the render edge is present only when a `rendersOne`/`rendersMany` led to the failing class. The
14
+ * three root entry points (`Dream.serializationMap`, `Dream.displaySerialization` and
15
+ * `buildSerializerPreloadPaths`) resolve a class the caller named directly, so nothing led there;
16
+ * - the declaring serializer is present only while preload paths and serialization maps are built.
17
+ * `SerializerRenderer` holds the rendered attribute but not the serializer that declared it;
18
+ * - the STI base is present only where expanding one produced the class the error names.
19
+ */
20
+ export default function serializerResolutionContextMessage(serializerKey: string | undefined, context: SerializerResolutionContext | undefined): string;
@@ -0,0 +1,58 @@
1
+ export interface SyncFailureContext {
2
+ /**
3
+ * The command the sync is running on behalf of, e.g. `db:rollback`.
4
+ */
5
+ commandName: string;
6
+ /**
7
+ * What the command finished before the sync ran, written as a sentence with
8
+ * no trailing period, e.g. `The rollback completed successfully`. It must
9
+ * only claim the steps that genuinely ran to completion — for a command
10
+ * whose sync sits in the middle of a sequence, name those steps rather than
11
+ * the command as a whole.
12
+ */
13
+ completedWork: string;
14
+ /**
15
+ * What the sync failure prevented from running, written as a clause with no
16
+ * trailing period, e.g. `db:seed did not run`. Omit it when the sync is the
17
+ * last thing the command does, in which case nothing was skipped.
18
+ */
19
+ didNotRun?: string | undefined;
20
+ /**
21
+ * What the operator should do once the underlying sync error is fixed,
22
+ * written as an imperative clause with no trailing period, e.g.
23
+ * ``run `sync` on its own``. It is rendered as
24
+ * `Once it is resolved, ${recoveryAdvice}.`
25
+ *
26
+ * This is deliberately per-command rather than templated off `commandName`,
27
+ * because "re-run the command" is only correct for commands that are safe to
28
+ * repeat. `db:rollback` is the counter-example that motivates the field: its
29
+ * work is already committed by the time the sync runs, so re-running it rolls
30
+ * back a *further* migration rather than retrying the step that failed.
31
+ *
32
+ * Defaults to ``run `sync` on its own`` — the retry that is safe after any of
33
+ * these commands, since it repeats only the step that actually failed.
34
+ */
35
+ recoveryAdvice?: string | undefined;
36
+ }
37
+ /**
38
+ * Runs the type/schema sync a command performs after its own work has already
39
+ * succeeded, and — when that sync fails — logs a message naming what completed
40
+ * and naming the sync as the step that failed, before re-raising the original
41
+ * error untouched.
42
+ *
43
+ * Without this, a failing sync surfaces a bare sync error immediately after
44
+ * e.g. `db:rollback`, which reads as a failed rollback even though the
45
+ * rollback itself is already committed.
46
+ *
47
+ * The original error is re-thrown rather than wrapped, so the error a caller
48
+ * sees, and the command's non-zero exit status, are exactly what they were
49
+ * before. Callers keep their own `EnvInternal.isTest` / `--skip-sync` guards:
50
+ * this wrapper takes the sync call, not the decision to make it.
51
+ */
52
+ export default function syncWithFailureContext({ commandName, completedWork, didNotRun, recoveryAdvice }: SyncFailureContext, sync: () => Promise<void>): Promise<void>;
53
+ /**
54
+ * @internal
55
+ *
56
+ * Builds the explanatory message logged when a post-work sync fails.
57
+ */
58
+ export declare function syncFailureMessage({ commandName, completedWork, didNotRun, recoveryAdvice, }: SyncFailureContext): string;
@@ -1,9 +1,16 @@
1
1
  import Dream from '../../Dream.js';
2
2
  import { ViewModel, ViewModelClass } from '../../types/dream.js';
3
- import { DreamModelSerializerType, SerializerType, SimpleObjectSerializerType } from '../../types/serializer.js';
3
+ import { DreamModelSerializerType, SerializerResolutionContext, SerializerType, SimpleObjectSerializerType } from '../../types/serializer.js';
4
4
  export declare const DEFAULT_SERIALIZER_KEY = "default";
5
- export default function inferSerializerFromDreamOrViewModel<T extends Dream | ViewModel | null | undefined, ReturnType extends T extends null | undefined ? null : T extends Dream | ViewModel ? SerializerType : never>(obj: T, serializerKey?: string | undefined): ReturnType;
6
- export declare function inferSerializersFromDreamClassOrViewModelClass(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey?: string | undefined): (DreamModelSerializerType | SimpleObjectSerializerType)[];
5
+ /**
6
+ * `resolutionContext` says how resolution reached `obj` — the `rendersOne`/`rendersMany` edge that
7
+ * led here, and the STI base it was expanded from. It is threaded down purely so that the errors
8
+ * below can name the route instead of only the class, and it is optional so that a caller with no
9
+ * route to describe (and every existing caller outside this repo) is unaffected. See
10
+ * `SerializerResolutionContext`.
11
+ */
12
+ export default function inferSerializerFromDreamOrViewModel<T extends Dream | ViewModel | null | undefined, ReturnType extends T extends null | undefined ? null : T extends Dream | ViewModel ? SerializerType : never>(obj: T, serializerKey?: string | undefined, resolutionContext?: SerializerResolutionContext): ReturnType;
13
+ export declare function inferSerializersFromDreamClassOrViewModelClass(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey?: string | undefined, resolutionContext?: SerializerResolutionContext): (DreamModelSerializerType | SimpleObjectSerializerType)[];
7
14
  /**
8
15
  * As `inferSerializersFromDreamClassOrViewModelClass`, but guarantees a non-empty result.
9
16
  *
@@ -19,4 +26,4 @@ export declare function inferSerializersFromDreamClassOrViewModelClass(classDef:
19
26
  * preload-path building and serialization display — so that they raise one typed error between
20
27
  * them.
21
28
  */
22
- export declare function inferSerializersFromDreamClassOrViewModelClassOrFail(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey: string): (DreamModelSerializerType | SimpleObjectSerializerType)[];
29
+ export declare function inferSerializersFromDreamClassOrViewModelClassOrFail(classDef: typeof Dream | ViewModelClass | null | undefined, serializerKey: string, resolutionContext?: SerializerResolutionContext): (DreamModelSerializerType | SimpleObjectSerializerType)[];
@@ -0,0 +1,15 @@
1
+ import { SerializerType } from '../../types/serializer.js';
2
+ /**
3
+ * @internal
4
+ *
5
+ * The single reader of a serializer's `globalName`.
6
+ *
7
+ * Serializers are plain functions; `globalName` is stamped onto them by `importSerializers` when the
8
+ * app loads them, so the property is not on any serializer type and every reader would otherwise
9
+ * have to invent its own cast — three different spellings of it existed before this helper.
10
+ *
11
+ * `undefined` is a legitimate answer: a serializer built inline (a spec, or a `{ serializer }`
12
+ * option) is never stamped. Callers decide what that means for them — the resolution-context message
13
+ * simply drops the declarer.
14
+ */
15
+ export default function serializerGlobalName(serializer: SerializerType): string | undefined;
@@ -29,7 +29,7 @@ type NonKyselySupportedSupplementalWhereClauseValues<DB, Schema, TableName, Colu
29
29
  export type WhereStatementForDreamClass<DreamClass extends typeof Dream> = WhereStatement<InstanceType<DreamClass>>;
30
30
  export type WhereStatementForDream<DreamInstance extends Dream> = WhereStatement<DreamInstance>;
31
31
  type AssociationNameToDotReferencedColumns<DB, TableName extends keyof DB, AssociationName> = `${AssociationName & string}.${TableColumnNames<DB, TableName>}`;
32
- export type ColumnNamesAccountingForJoinedAssociations<JoinedAssociations extends Readonly<JoinedAssociation[]>, DB, RootTableName extends keyof DB, RootTableAlias extends string> = JoinedAssociations['length'] extends 0 ? TableColumnNames<DB, RootTableName> : JoinedAssociationColumnNames<JoinedAssociations, DB, AssociationNameToDotReferencedColumns<DB, RootTableName & keyof DB, RootTableAlias>>;
32
+ export type ColumnNamesAccountingForJoinedAssociations<JoinedAssociations extends Readonly<JoinedAssociation[]>, DB, RootTableName extends keyof DB, RootTableAlias extends string> = JoinedAssociations['length'] extends 0 ? TableColumnNames<DB, RootTableName> : TableColumnNames<DB, RootTableName> | JoinedAssociationColumnNames<JoinedAssociations, DB, AssociationNameToDotReferencedColumns<DB, RootTableName & keyof DB, RootTableAlias>>;
33
33
  type JoinedAssociationColumnNames<JoinedAssociations extends Readonly<JoinedAssociation[]>, DB, AllColumnNames, Depth extends number = 0, CurrentJoinedAssociation = Readonly<JoinedAssociations[0]>, NextTableName = CurrentJoinedAssociation extends Readonly<JoinedAssociation> ? CurrentJoinedAssociation['table'] : never, NextAssociationName = CurrentJoinedAssociation extends Readonly<JoinedAssociation> ? CurrentJoinedAssociation['alias'] : never> = JoinedAssociations['length'] extends 0 ? AllColumnNames : Depth extends MAX_JOINED_TABLES_DEPTH ? AllColumnNames : JoinedAssociationColumnNames<ReadonlyTail<JoinedAssociations>, DB, AllColumnNames | AssociationNameToDotReferencedColumns<DB, NextTableName & keyof DB, NextAssociationName>, Inc<Depth>>;
34
34
  type Whereable<R> = {
35
35
  [K in keyof Selectable<R>]?: Selectable<R>[K] | Selectable<R>[K][];
@@ -265,4 +265,7 @@ export type AllDefaultScopeNames<DreamConf, ConnectionTypeConfig = DreamConf['co
265
265
  export type NamedScopeName<DreamInstance extends Dream, Schema = DreamInstance['schema'], SchemaTable = Schema[DreamInstance['table'] & keyof Schema], SchemaNamedScopes extends string[] = SchemaTable['scopes' & keyof SchemaTable]['named' & keyof SchemaTable['scopes' & keyof SchemaTable]] & string[]> = SchemaNamedScopes[number];
266
266
  export type DefaultOrNamedScopeName<DreamInstance extends Dream> = DefaultScopeName<DreamInstance> | NamedScopeName<DreamInstance>;
267
267
  export type PluckEachArgs<ColumnNames extends unknown[], CbArgTypes extends unknown[]> = [...fields: ColumnNames] | [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>] | [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>, opts: FindEachOpts];
268
+ export type ValidatedPluckEachColumnNames<ColumnNames extends unknown[], AllowedColumnName> = {
269
+ [Index in keyof ColumnNames]: ColumnNames[Index] extends AllowedColumnName ? ColumnNames[Index] : AllowedColumnName;
270
+ };
268
271
  export {};
@@ -46,7 +46,7 @@ export type ExtendQueryType<OriginalOpts extends Readonly<QueryTypeOptions>, Opt
46
46
  allowOffset: Opts['allowOffset'] extends false ? false : OriginalOpts['allowOffset'];
47
47
  allowPaginate: Opts['allowPaginate'] extends false ? false : OriginalOpts['allowPaginate'];
48
48
  }>;
49
- export type NamespacedColumnType<ColumnName, Q extends Query<any, any>, DreamInstance extends Dream, JoinedAssociationsArr = Q['queryTypeOpts']['joinedAssociations'], AssociationName = ColumnName extends `${infer Name extends string}.${string}` ? Name : never, RealColumnName = ColumnName extends `${string}.${infer Col extends string}` ? Col : never, JoinedAssociation extends FindInterfaceWithValue<JoinedAssociationsArr, 'alias', AssociationName> = FindInterfaceWithValue<JoinedAssociationsArr, 'alias', AssociationName>, JoinedTable = JoinedAssociation['table'] extends never ? DreamInstance['table'] : JoinedAssociation['table'], ReturnType = ModelColumnType<DreamInstance['schema'], JoinedTable, RealColumnName>> = ReturnType;
49
+ export type NamespacedColumnType<ColumnName, Q extends Query<any, any>, DreamInstance extends Dream, JoinedAssociationsArr = Q['queryTypeOpts']['joinedAssociations'], AssociationName = ColumnName extends `${infer Name extends string}.${string}` ? Name : never, RealColumnName = ColumnName extends `${string}.${infer Col extends string}` ? Col : ColumnName, JoinedAssociation extends FindInterfaceWithValue<JoinedAssociationsArr, 'alias', AssociationName> = FindInterfaceWithValue<JoinedAssociationsArr, 'alias', AssociationName>, JoinedTable = JoinedAssociation['table'] extends never ? DreamInstance['table'] : JoinedAssociation['table'], ReturnType = ModelColumnType<DreamInstance['schema'], JoinedTable, RealColumnName>> = ReturnType;
50
50
  type NamespacedColumnTypes<ColumnNames, Q extends Query<any, any>, DreamInstance extends Dream> = ColumnNames extends Readonly<[infer First, ...infer Rest]> ? [
51
51
  NamespacedColumnType<First, Q, DreamInstance>,
52
52
  ...NamespacedColumnTypes<Readonly<Rest>, Q, DreamInstance>
@@ -39,6 +39,44 @@ export interface InternalAnyRendersOneOrManyOpts {
39
39
  serializer?: DreamModelSerializerType | SimpleObjectSerializerType;
40
40
  serializerKey?: string;
41
41
  }
42
+ /**
43
+ * @internal
44
+ *
45
+ * How serializer resolution arrived at the class it is resolving against, threaded down to the
46
+ * errors raised when that resolution fails so the message can say *how* it got there rather than
47
+ * only which class it landed on.
48
+ *
49
+ * Every field is optional because the paths that resolve serializers do not all know the same
50
+ * things, and a message prints only what its own path has: the three root entry points
51
+ * (`Dream.serializationMap`, `Dream.displaySerialization`, `buildSerializerPreloadPaths`) resolve
52
+ * with no edge at all, `SerializerRenderer` has no serializer object in scope to name as the
53
+ * declarer, and an STI base is only recorded where expanding one produced the class the error
54
+ * names. The serializer key is not here because it is already an argument of resolution, so every
55
+ * error that renders this context has it in hand.
56
+ */
57
+ export interface SerializerResolutionContext {
58
+ edge?: SerializerResolutionEdge;
59
+ /**
60
+ * The STI base whose expansion produced the class the error names. Absent when the class was
61
+ * resolved directly rather than reached through `expandStiClasses`.
62
+ */
63
+ stiBase?: string;
64
+ }
65
+ /**
66
+ * @internal
67
+ *
68
+ * The `rendersOne`/`rendersMany` that led resolution to the failing class.
69
+ */
70
+ export interface SerializerResolutionEdge {
71
+ type: 'rendersOne' | 'rendersMany';
72
+ associationName: string;
73
+ /**
74
+ * The global name of the serializer that declares the edge. In scope while preload paths and
75
+ * serialization maps are built, and absent at render time, where the renderer holds the rendered
76
+ * attribute but not the serializer that declared it.
77
+ */
78
+ declaredBy?: string | undefined;
79
+ }
42
80
  export interface InternalAnyTypedSerializerRendersOne<DataType, AttributeName extends keyof DataType & string = keyof DataType & string> {
43
81
  type: 'rendersOne';
44
82
  name: AttributeName;
@@ -216,12 +216,14 @@ export type ColumnNamesAccountingForJoinedAssociations<
216
216
  RootTableAlias extends string,
217
217
  > = JoinedAssociations['length'] extends 0
218
218
  ? TableColumnNames<DB, RootTableName> // no associations; simply return the un-namespaced columns for the root table
219
- : JoinedAssociationColumnNames<
220
- JoinedAssociations,
221
- DB,
222
- // namespace columns for the root table
223
- AssociationNameToDotReferencedColumns<DB, RootTableName & keyof DB, RootTableAlias>
224
- >
219
+ :
220
+ | TableColumnNames<DB, RootTableName>
221
+ | JoinedAssociationColumnNames<
222
+ JoinedAssociations,
223
+ DB,
224
+ // namespace columns for the root table
225
+ AssociationNameToDotReferencedColumns<DB, RootTableName & keyof DB, RootTableAlias>
226
+ >
225
227
  type JoinedAssociationColumnNames<
226
228
  JoinedAssociations extends Readonly<JoinedAssociation[]>,
227
229
  DB,
@@ -925,3 +925,9 @@ export type PluckEachArgs<ColumnNames extends unknown[], CbArgTypes extends unkn
925
925
  | [...fields: ColumnNames]
926
926
  | [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>]
927
927
  | [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>, opts: FindEachOpts]
928
+
929
+ export type ValidatedPluckEachColumnNames<ColumnNames extends unknown[], AllowedColumnName> = {
930
+ [Index in keyof ColumnNames]: ColumnNames[Index] extends AllowedColumnName
931
+ ? ColumnNames[Index]
932
+ : AllowedColumnName
933
+ }
@@ -101,7 +101,7 @@ export type NamespacedColumnType<
101
101
  // begin: inferred types
102
102
  JoinedAssociationsArr = Q['queryTypeOpts']['joinedAssociations'],
103
103
  AssociationName = ColumnName extends `${infer Name extends string}.${string}` ? Name : never,
104
- RealColumnName = ColumnName extends `${string}.${infer Col extends string}` ? Col : never,
104
+ RealColumnName = ColumnName extends `${string}.${infer Col extends string}` ? Col : ColumnName,
105
105
  JoinedAssociation extends FindInterfaceWithValue<
106
106
  JoinedAssociationsArr,
107
107
  'alias',