@rvoh/dream 2.5.7 → 2.6.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 (250) hide show
  1. package/dist/cjs/src/Dream.js +37 -66
  2. package/dist/cjs/src/decorators/class/STI.js +2 -2
  3. package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +16 -10
  4. package/dist/cjs/src/dream/LoadBuilder.js +70 -9
  5. package/dist/cjs/src/dream/Query.js +5 -6
  6. package/dist/cjs/src/dream/constants.js +2 -0
  7. package/dist/cjs/src/dream/internal/buildAssociationPaths.js +33 -0
  8. package/dist/cjs/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
  9. package/dist/cjs/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
  10. package/dist/cjs/src/dream/internal/destroyAssociatedRecords.js +14 -6
  11. package/dist/cjs/src/dream/internal/destroyDream.js +7 -1
  12. package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +35 -0
  13. package/dist/cjs/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
  14. package/dist/cjs/src/serializer/SerializerRenderer.js +1 -1
  15. package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +114 -52
  16. package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
  17. package/dist/cjs/src/types/recursiveSerialization.js +1 -0
  18. package/dist/esm/src/Dream.js +37 -66
  19. package/dist/esm/src/decorators/class/STI.js +2 -2
  20. package/dist/esm/src/dream/LeftJoinLoadBuilder.js +16 -10
  21. package/dist/esm/src/dream/LoadBuilder.js +70 -9
  22. package/dist/esm/src/dream/Query.js +5 -6
  23. package/dist/esm/src/dream/constants.js +2 -0
  24. package/dist/esm/src/dream/internal/buildAssociationPaths.js +33 -0
  25. package/dist/esm/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
  26. package/dist/esm/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
  27. package/dist/esm/src/dream/internal/destroyAssociatedRecords.js +14 -6
  28. package/dist/esm/src/dream/internal/destroyDream.js +7 -1
  29. package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +35 -0
  30. package/dist/esm/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
  31. package/dist/esm/src/serializer/SerializerRenderer.js +1 -1
  32. package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +114 -52
  33. package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
  34. package/dist/esm/src/types/recursiveSerialization.js +1 -0
  35. package/dist/types/src/Dream.d.ts +25 -10
  36. package/dist/types/src/decorators/Decorators.d.ts +8 -0
  37. package/dist/types/src/decorators/class/STI.d.ts +1 -3
  38. package/dist/types/src/decorators/field/sortable/Sortable.d.ts +9 -0
  39. package/dist/types/src/decorators/field/validation/Validates.d.ts +4 -0
  40. package/dist/types/src/decorators/static-method/Scope.d.ts +4 -0
  41. package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +16 -10
  42. package/dist/types/src/dream/LoadBuilder.d.ts +63 -10
  43. package/dist/types/src/dream/Query.d.ts +1 -1
  44. package/dist/types/src/dream/constants.d.ts +2 -0
  45. package/dist/types/src/dream/internal/buildAssociationPaths.d.ts +12 -0
  46. package/dist/types/src/dream/internal/buildDependentDestroyPreloadPaths.d.ts +17 -0
  47. package/dist/types/src/dream/internal/buildSerializerPreloadPaths.d.ts +3 -0
  48. package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +1 -1
  49. package/dist/types/src/dream/internal/destroyAssociatedRecords.d.ts +5 -1
  50. package/dist/types/src/dream/internal/loadDependentDestroyTree.d.ts +17 -0
  51. package/dist/types/src/dream/internal/resolveSerializerAssociationEdges.d.ts +13 -0
  52. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +164 -63
  53. package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +126 -43
  54. package/dist/types/src/types/associations/belongsTo.d.ts +34 -0
  55. package/dist/types/src/types/associations/belongsTo.ts +41 -0
  56. package/dist/types/src/types/associations/hasMany.d.ts +18 -0
  57. package/dist/types/src/types/associations/hasMany.ts +18 -0
  58. package/dist/types/src/types/associations/shared.d.ts +71 -0
  59. package/dist/types/src/types/associations/shared.ts +74 -0
  60. package/dist/types/src/types/dream.d.ts +16 -0
  61. package/dist/types/src/types/dream.ts +18 -0
  62. package/dist/types/src/types/lifecycle.d.ts +18 -0
  63. package/dist/types/src/types/lifecycle.ts +18 -0
  64. package/dist/types/src/types/query.d.ts +3 -0
  65. package/dist/types/src/types/query.ts +3 -0
  66. package/dist/types/src/types/recursiveSerialization.d.ts +8 -0
  67. package/dist/types/src/types/recursiveSerialization.ts +10 -0
  68. package/dist/types/src/types/serializer.d.ts +8 -1
  69. package/dist/types/src/types/serializer.ts +8 -1
  70. package/docs/classes/db.DreamMigrationHelpers.html +9 -9
  71. package/docs/classes/db.KyselyQueryDriver.html +32 -32
  72. package/docs/classes/db.PostgresQueryDriver.html +33 -33
  73. package/docs/classes/db.QueryDriverBase.html +31 -31
  74. package/docs/classes/errors.CheckConstraintViolation.html +3 -3
  75. package/docs/classes/errors.ColumnOverflow.html +3 -3
  76. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  77. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
  78. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
  79. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  80. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  81. package/docs/classes/errors.InvalidClockTime.html +2 -2
  82. package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
  83. package/docs/classes/errors.InvalidDateTime.html +2 -2
  84. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  85. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  86. package/docs/classes/errors.NotNullViolation.html +3 -3
  87. package/docs/classes/errors.RecordNotFound.html +3 -3
  88. package/docs/classes/errors.ValidationError.html +3 -3
  89. package/docs/classes/index.CalendarDate.html +33 -33
  90. package/docs/classes/index.ClockTime.html +32 -32
  91. package/docs/classes/index.ClockTimeTz.html +35 -35
  92. package/docs/classes/index.DateTime.html +86 -86
  93. package/docs/classes/index.Decorators.html +21 -20
  94. package/docs/classes/index.Dream.html +133 -126
  95. package/docs/classes/index.DreamApp.html +5 -5
  96. package/docs/classes/index.DreamTransaction.html +2 -2
  97. package/docs/classes/index.Env.html +2 -2
  98. package/docs/classes/index.Query.html +57 -57
  99. package/docs/classes/system.CliFileWriter.html +4 -4
  100. package/docs/classes/system.DreamBin.html +2 -2
  101. package/docs/classes/system.DreamCLI.html +6 -6
  102. package/docs/classes/system.DreamImporter.html +2 -2
  103. package/docs/classes/system.DreamLogos.html +2 -2
  104. package/docs/classes/system.DreamSerializerBuilder.html +177 -59
  105. package/docs/classes/system.ObjectSerializerBuilder.html +110 -34
  106. package/docs/classes/system.PathHelpers.html +3 -3
  107. package/docs/classes/utils.Encrypt.html +2 -2
  108. package/docs/classes/utils.Range.html +2 -2
  109. package/docs/functions/db.closeAllDbConnections.html +1 -1
  110. package/docs/functions/db.dreamDbConnections.html +1 -1
  111. package/docs/functions/db.untypedDb.html +1 -1
  112. package/docs/functions/db.validateColumn.html +1 -1
  113. package/docs/functions/db.validateTable.html +1 -1
  114. package/docs/functions/errors.pgErrorType.html +1 -1
  115. package/docs/functions/index.DreamSerializer.html +1 -1
  116. package/docs/functions/index.ObjectSerializer.html +1 -1
  117. package/docs/functions/index.ReplicaSafe.html +1 -1
  118. package/docs/functions/index.STI.html +1 -1
  119. package/docs/functions/index.SoftDelete.html +1 -1
  120. package/docs/functions/utils.camelize.html +1 -1
  121. package/docs/functions/utils.capitalize.html +1 -1
  122. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  123. package/docs/functions/utils.compact.html +1 -1
  124. package/docs/functions/utils.groupBy.html +1 -1
  125. package/docs/functions/utils.hyphenize.html +1 -1
  126. package/docs/functions/utils.intersection.html +1 -1
  127. package/docs/functions/utils.isEmpty.html +1 -1
  128. package/docs/functions/utils.normalizeUnicode.html +1 -1
  129. package/docs/functions/utils.pascalize.html +1 -1
  130. package/docs/functions/utils.percent.html +1 -1
  131. package/docs/functions/utils.range.html +1 -1
  132. package/docs/functions/utils.round.html +1 -1
  133. package/docs/functions/utils.sanitizeString.html +1 -1
  134. package/docs/functions/utils.snakeify.html +1 -1
  135. package/docs/functions/utils.sort.html +1 -1
  136. package/docs/functions/utils.sortBy.html +1 -1
  137. package/docs/functions/utils.sortObjectByKey.html +1 -1
  138. package/docs/functions/utils.sortObjectByValue.html +1 -1
  139. package/docs/functions/utils.uncapitalize.html +1 -1
  140. package/docs/functions/utils.uniq.html +1 -1
  141. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  142. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  143. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  144. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  145. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  146. package/docs/interfaces/types.DecoratorContext.html +2 -2
  147. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  148. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  149. package/docs/interfaces/types.DurationObject.html +2 -2
  150. package/docs/interfaces/types.EncryptOptions.html +2 -2
  151. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  152. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  153. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  154. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  155. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  156. package/docs/types/openapi.OpenapiFormats.html +1 -1
  157. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  158. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  159. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  160. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  161. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  163. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  164. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  165. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  166. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  167. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  168. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  169. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  170. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  171. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  172. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  173. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  174. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  175. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  176. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  177. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  178. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  179. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  180. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  181. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  182. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  183. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  184. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  185. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  186. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  187. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  188. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  189. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  190. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  191. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  192. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  193. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  194. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  195. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  196. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  197. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  198. package/docs/types/types.CalendarDateObject.html +1 -1
  199. package/docs/types/types.Camelized.html +1 -1
  200. package/docs/types/types.ClockTimeObject.html +1 -1
  201. package/docs/types/types.DbConnectionType.html +1 -1
  202. package/docs/types/types.DbTypes.html +1 -1
  203. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  204. package/docs/types/types.DreamAttributes.html +1 -1
  205. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  206. package/docs/types/types.DreamClassColumn.html +1 -1
  207. package/docs/types/types.DreamColumn.html +1 -1
  208. package/docs/types/types.DreamColumnNames.html +1 -1
  209. package/docs/types/types.DreamLogLevel.html +1 -1
  210. package/docs/types/types.DreamLogger.html +2 -2
  211. package/docs/types/types.DreamModelSerializerType.html +1 -1
  212. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  213. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  214. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  215. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  216. package/docs/types/types.DreamSerializable.html +1 -1
  217. package/docs/types/types.DreamSerializableArray.html +1 -1
  218. package/docs/types/types.DreamSerializerKey.html +1 -1
  219. package/docs/types/types.DreamSerializers.html +1 -1
  220. package/docs/types/types.DreamVirtualColumns.html +1 -1
  221. package/docs/types/types.DurationUnit.html +1 -1
  222. package/docs/types/types.EncryptAlgorithm.html +1 -1
  223. package/docs/types/types.HasManyStatement.html +1 -1
  224. package/docs/types/types.HasOneStatement.html +1 -1
  225. package/docs/types/types.Hyphenized.html +1 -1
  226. package/docs/types/types.Pascalized.html +1 -1
  227. package/docs/types/types.PrimaryKeyType.html +1 -1
  228. package/docs/types/types.RoundingPrecision.html +1 -1
  229. package/docs/types/types.SerializerCasing.html +1 -1
  230. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  231. package/docs/types/types.Snakeified.html +1 -1
  232. package/docs/types/types.StrictInterface.html +1 -1
  233. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  234. package/docs/types/types.UpdateableProperties.html +1 -1
  235. package/docs/types/types.ValidationType.html +1 -1
  236. package/docs/types/types.ViewModel.html +2 -2
  237. package/docs/types/types.ViewModelClass.html +1 -1
  238. package/docs/types/types.WeekdayName.html +1 -1
  239. package/docs/types/types.WhereStatementForDream.html +1 -1
  240. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  241. package/docs/variables/index.DreamConst.html +1 -1
  242. package/docs/variables/index.ops.html +1 -1
  243. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  244. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  245. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  246. package/docs/variables/system.primaryKeyTypes.html +1 -1
  247. package/package.json +1 -1
  248. package/dist/cjs/src/dream/internal/extractNestedPaths.js +0 -34
  249. package/dist/esm/src/dream/internal/extractNestedPaths.js +0 -34
  250. package/dist/types/src/dream/internal/extractNestedPaths.d.ts +0 -21
@@ -2,6 +2,7 @@ import Dream from '../../Dream.js';
2
2
  import { DreamOrViewModelSerializerKey, DreamVirtualColumns, NonJsonDreamColumnNames, ViewModel, ViewModelClass } from '../../types/dream.js';
3
3
  import { AutomaticSerializerAttributeOptions, AutomaticSerializerAttributeOptionsForType, InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerAttributeOptionsForVirtualColumn, SerializerType } from '../../types/serializer.js';
4
4
  import { SerializerRendererOpts } from '../SerializerRenderer.js';
5
+ export type DreamPropertiesToExclude = keyof Dream | 'serializers';
5
6
  export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dream, MaybeNullDataType extends Dream | null, PassthroughDataType = any, DataType extends Exclude<MaybeNullDataType, null> = Exclude<MaybeNullDataType, null>> {
6
7
  protected $typeForOpenapi: DataTypeForOpenapi;
7
8
  protected data: MaybeNullDataType;
@@ -11,11 +12,23 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
11
12
  /**
12
13
  * Includes an attribute from the data object in the serialized output.
13
14
  *
14
- * For DreamSerializer, OpenAPI types can often be inferred from database columns.
15
- * For json and jsonb columns and also virtual attributes (getters), the `openapi` option is required.
15
+ * For DreamSerializer, OpenAPI types are automatically inferred from database columns.
16
+ * For json/jsonb columns and virtual attributes (getters), the `openapi` option is required.
16
17
  *
17
18
  * @param name - The attribute name from the data object
18
- * @param options - Configuration options including OpenAPI schema, default value, and output customization
19
+ * @param options - Configuration options:
20
+ * - `as` - Rename the attribute key in the serialized output and OpenAPI shape
21
+ * - `default` - Value to use when the attribute is undefined (not available for `type` columns)
22
+ * - `openapi` - OpenAPI schema definition; required for json/jsonb columns and non-virtual
23
+ * getters, optional for standard columns (where it can supplement inferred types with a
24
+ * `description`), and optional for `@deco.Virtual()` columns (where the type is inferred
25
+ * from the decorator)
26
+ * - `precision` - Round decimal values to the specified number of decimal places (0–9)
27
+ * during rendering; does not affect the OpenAPI shape (not available for `type` or
28
+ * virtual columns)
29
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
30
+ * when omitted, attributes are required by default, meaning `undefined` values will
31
+ * serialize as `null` (not available for `type` columns)
19
32
  * @returns The serializer builder for method chaining
20
33
  *
21
34
  * @example
@@ -23,51 +36,79 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
23
36
  * // With type inference (database column)
24
37
  * .attribute('email')
25
38
  *
26
- * // With explicit OpenAPI type (virtual attribute)
39
+ * // With explicit OpenAPI type (virtual attribute or json column)
27
40
  * .attribute('fullName', { openapi: { type: 'string' } })
28
41
  *
29
42
  * // With default value
30
- * .attribute('status', { default: 'active' })
43
+ * .attribute('status', { default: 'pending' })
31
44
  *
32
45
  * // Rename output key
33
46
  * .attribute('email', { as: 'userEmail' })
34
- * ```
35
47
  *
36
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
48
+ * // Round decimal to 2 places
49
+ * .attribute('price', { precision: 2 })
50
+ *
51
+ * // Mark as optional in OpenAPI (omitted from response when undefined)
52
+ * .attribute('deletedAt', { required: false })
53
+ * ```
37
54
  */
38
55
  attribute(name: NonJsonDreamColumnNames<DataType> & keyof DataType & 'type', options?: AutomaticSerializerAttributeOptionsForType): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
39
56
  attribute(name: DreamVirtualColumns<DataType>[number], options?: SerializerAttributeOptionsForVirtualColumn): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
40
- attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType, keyof Dream> & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
57
+ attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType, DreamPropertiesToExclude> & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
41
58
  attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string>(name: AttributeName, options?: AutomaticSerializerAttributeOptions): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
42
59
  /**
43
60
  * Includes an attribute from a nested object in the serialized output.
44
61
  *
45
- * Serializes an attribute from a target object. If the target object or
46
- * the delegated attribute is null/undefined, the `default` option value
62
+ * Accesses `targetName.name` on the data object. If the target object
63
+ * or the delegated attribute is null/undefined, the `default` option value
47
64
  * will be used if provided.
48
65
  *
49
- * @param targetName - The property name containing the target object
66
+ * When the target is a Dream model, OpenAPI types may be automatically inferred
67
+ * for standard database columns. For json/jsonb columns or non-Dream targets,
68
+ * the `openapi` option is required.
69
+ *
70
+ * @param targetName - The property name containing the target object (e.g., an association name)
50
71
  * @param name - The attribute name within the target object
51
- * @param options - Configuration options including OpenAPI schema, default value, and output customization
72
+ * @param options - Configuration options:
73
+ * - `as` - Rename the attribute key in the serialized output and OpenAPI shape
74
+ * (e.g., delegating `'user', 'email'` with `as: 'userEmail'` outputs the value
75
+ * under `userEmail`)
76
+ * - `default` - Value to use when the target object or its attribute is null/undefined
77
+ * - `openapi` - OpenAPI schema definition; required for non-Dream targets and json/jsonb
78
+ * columns, optional for standard Dream columns (where types are inferred)
79
+ * - `optional` - Set to `true` to indicate the value can be null in the OpenAPI schema
80
+ * (wraps the type in `anyOf: [schema, { type: 'null' }]`). For Dream models, this is
81
+ * auto-inferred from optional BelongsTo associations. Use this when delegating through
82
+ * a HasOne or other nullable association.
83
+ * - `precision` - Round decimal values to the specified number of decimal places (0–9)
84
+ * during rendering; does not affect the OpenAPI shape
85
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
86
+ * when omitted, attributes are required by default
52
87
  * @returns The serializer builder for method chaining
53
88
  *
54
89
  * @example
55
90
  * ```typescript
56
- * // Delegate to user.email
57
- * .delegatedAttribute('user', 'email', {
58
- * openapi: { type: 'string', format: 'email' }
59
- * })
91
+ * // Delegate to a Dream association's column (type inferred)
92
+ * .delegatedAttribute('currentLocalizedText', 'title', { openapi: 'string' })
60
93
  *
61
94
  * // With default value for null target or attribute
62
95
  * .delegatedAttribute('user', 'displayName', {
63
96
  * openapi: { type: 'string' },
64
97
  * default: 'Unknown User'
65
98
  * })
66
- * ```
67
99
  *
68
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
100
+ * // Rename the output key
101
+ * .delegatedAttribute('profile', 'avatarUrl', {
102
+ * openapi: 'string',
103
+ * as: 'avatar'
104
+ * })
105
+ * ```
69
106
  */
70
- delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends AssociatedModelType & keyof AssociatedModelType & string ? AutomaticSerializerAttributeOptions | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
107
+ delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, DreamPropertiesToExclude> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, DreamPropertiesToExclude> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType & {
108
+ optional?: boolean;
109
+ } : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & string ? (AutomaticSerializerAttributeOptions & {
110
+ optional?: boolean;
111
+ }) | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
71
112
  /**
72
113
  * Includes a computed value in the serialized output.
73
114
  *
@@ -76,7 +117,17 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
76
117
  *
77
118
  * @param name - The attribute name for the computed value
78
119
  * @param fn - Callback function that returns the computed value
79
- * @param options - Configuration options including required OpenAPI schema and optional flattening
120
+ * @param options - Configuration options:
121
+ * - `openapi` - (required) OpenAPI schema definition for the computed value
122
+ * - `as` - Rename the attribute key in the serialized output and OpenAPI shape
123
+ * - `default` - Value to use when the callback returns undefined
124
+ * - `flatten` - When `true`, spreads the returned object's properties directly into the
125
+ * parent serialized output instead of nesting them under `name`; the `openapi` option
126
+ * should then define each flattened property individually
127
+ * - `precision` - Round decimal values to the specified number of decimal places (0–9)
128
+ * during rendering; does not affect the OpenAPI shape
129
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
130
+ * when omitted, attributes are required by default
80
131
  * @returns The serializer builder for method chaining
81
132
  *
82
133
  * @example
@@ -88,16 +139,20 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
88
139
  * )
89
140
  *
90
141
  * // Flattened object properties
91
- * .customAttribute('metadata', () => ({ age: 30, city: 'NYC' }), {
142
+ * .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
92
143
  * flatten: true,
93
144
  * openapi: {
94
- * age: { type: 'integer' },
95
- * city: { type: 'string' }
145
+ * lat: { type: 'number' },
146
+ * lng: { type: 'number' }
96
147
  * }
97
148
  * })
98
- * ```
99
149
  *
100
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
150
+ * // With decimal precision
151
+ * .customAttribute('averageRating', () => calculateAverage(ratings), {
152
+ * openapi: 'decimal',
153
+ * precision: 2
154
+ * })
155
+ * ```
101
156
  */
102
157
  customAttribute(name: string, fn: () => unknown, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
103
158
  flatten?: boolean;
@@ -105,30 +160,52 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
105
160
  /**
106
161
  * Includes a single associated object in the serialized output.
107
162
  *
108
- * When rendering a Dream association, the OpenAPI shape is automatically
109
- * inferred from that associated Dream's serializer.
163
+ * When rendering a Dream association, the serializer and OpenAPI shape are automatically
164
+ * inferred from that associated Dream model's registered serializers.
110
165
  *
111
166
  * @param name - The association property name
112
- * @param options - Configuration options for serialization and schema definition
167
+ * @param options - Configuration options:
168
+ * - `as` - Rename the association key in the serialized output
169
+ * - `flatten` - When `true`, spreads the rendered association's attributes directly into
170
+ * the parent serialized output instead of nesting them under `name`. Be aware of
171
+ * attribute shadowing: if the parent and flattened association share attribute names
172
+ * (e.g., `id`), the flattened association's values overwrite the parent's
173
+ * - `optional` - When `true`, allows the association to be null/missing without causing
174
+ * an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
175
+ * `rendersOne` expects the association to be present (mirroring the `optional` option on
176
+ * `@deco.BelongsTo`). Set this to `true` when the association is genuinely nullable
177
+ * - `serializerKey` - Use a specific serializer key from the associated Dream model's
178
+ * registered serializers (e.g., `'summary'`)
179
+ * - `serializer` - Provide an explicit serializer function instead of using the
180
+ * associated model's registered serializers
181
+ *
182
+ * For ViewModel associations, one of these is required:
183
+ * - `viewModelClass` + optional `serializerKey`
184
+ * - `serializer`
185
+ *
186
+ * For non-Dream/non-ViewModel associations:
187
+ * - `serializer` is required
113
188
  * @returns The serializer builder for method chaining
114
189
  *
115
190
  * @example
116
191
  * ```typescript
117
- * // DreamSerializer with inference
118
- * .rendersOne('user') // Infers from Dream association
192
+ * // Auto-infer serializer from Dream association
193
+ * .rendersOne('profile')
119
194
  *
120
- * // With specific serializer
195
+ * // With specific serializer key
121
196
  * .rendersOne('user', { serializerKey: 'summary' })
122
197
  *
123
- * // ObjectSerializer (explicit configuration required)
124
- * .rendersOne('owner', UserSerializer, {
125
- * openapi: { $ref: '#/components/schemas/User' }
126
- * })
127
- * ```
198
+ * // Allow null association
199
+ * .rendersOne('approver', { optional: true })
128
200
  *
129
- * See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
201
+ * // Flatten into parent object
202
+ * .rendersOne('candidate', { serializerKey: 'summary', flatten: true })
203
+ *
204
+ * // Explicit serializer function
205
+ * .rendersOne('owner', { serializer: CustomOwnerSerializer })
206
+ * ```
130
207
  */
131
- rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[AttributeName], null>, SerializerOptions = AssociatedModelType extends Dream ? {
208
+ rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[AttributeName], null>, SerializerOptions = AssociatedModelType extends Dream ? {
132
209
  serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
133
210
  } | {
134
211
  serializer?: SerializerType;
@@ -140,40 +217,66 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
140
217
  } : {
141
218
  serializer: SerializerType;
142
219
  }, BaseOptions = {
220
+ /**
221
+ * Rename the association key in the serialized output.
222
+ */
143
223
  as?: string;
224
+ /**
225
+ * If `true`, the rendered association's attributes are merged directly into
226
+ * the parent object instead of being nested under the association key.
227
+ */
144
228
  flatten?: boolean;
229
+ /**
230
+ * If `true`, the association is treated as nullable in the OpenAPI spec,
231
+ * allowing `null` when the association doesn't resolve. By default,
232
+ * `rendersOne` expects the association to be present. Set this to `true`
233
+ * for associations that may not exist, such as passthrough-conditional
234
+ * HasOne associations.
235
+ *
236
+ * ```ts
237
+ * .rendersOne('currentUserFavorite', { optional: true })
238
+ * ```
239
+ */
145
240
  optional?: boolean;
146
241
  }>(name: AttributeName, options?: BaseOptions & SerializerOptions): this;
147
242
  /**
148
243
  * Includes an array of associated objects in the serialized output.
149
244
  *
150
- * When rendering a Dream association, the OpenAPI shape is automatically
151
- * inferred from that associated Dream's serializer.
245
+ * When rendering a Dream association, the serializer and OpenAPI shape are automatically
246
+ * inferred from that associated Dream model's registered serializers.
152
247
  *
153
- * @param name - The association property name (should be an array)
154
- * @param options - Configuration options for serialization and schema definition
248
+ * @param name - The association property name (should resolve to an array)
249
+ * @param options - Configuration options:
250
+ * - `as` - Rename the association key in the serialized output
251
+ * - `serializerKey` - Use a specific serializer key from the associated Dream model's
252
+ * registered serializers (e.g., `'summary'`)
253
+ * - `serializer` - Provide an explicit serializer function instead of using the
254
+ * associated model's registered serializers
255
+ *
256
+ * For ViewModel associations, one of these is required:
257
+ * - `viewModelClass` + optional `serializerKey`
258
+ * - `serializer`
259
+ *
260
+ * For non-Dream/non-ViewModel associations:
261
+ * - `serializer` is required
155
262
  * @returns The serializer builder for method chaining
156
263
  *
157
264
  * @example
158
265
  * ```typescript
159
- * // DreamSerializer with inference
160
- * .rendersMany('posts') // Infers from Dream association
266
+ * // Auto-infer serializer from Dream association
267
+ * .rendersMany('rooms')
161
268
  *
162
- * // With specific serializer
163
- * .rendersMany('posts', { serializerKey: 'summary' })
269
+ * // With specific serializer key
270
+ * .rendersMany('rooms', { serializerKey: 'summary' })
164
271
  *
165
- * // ObjectSerializer (explicit configuration required)
166
- * .rendersMany('articles', ArticleSerializer, {
167
- * openapi: {
168
- * type: 'array',
169
- * items: { $ref: '#/components/schemas/Article' }
170
- * }
171
- * })
172
- * ```
272
+ * // Explicit serializer function (for non-Dream objects)
273
+ * .rendersMany('bedTypes', { serializer: BedTypeSerializer })
173
274
  *
174
- * See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
275
+ * // Rename output key
276
+ * .rendersMany('rooms', { serializerKey: 'forGuests', as: 'guestRooms' })
277
+ * ```
175
278
  */
176
- rendersMany<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = ActualDataType[AttributeName] extends (Dream | ViewModel)[] ? ActualDataType[AttributeName] extends (infer U)[] ? U : object : object, SerializerOptions = AssociatedModelType extends Dream ? {
279
+ rendersMany<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = ActualDataType[AttributeName] extends (Dream | ViewModel)[] ? ActualDataType[AttributeName] extends (infer U)[] ? U : object : object, SerializerOptions = AssociatedModelType extends Dream ? {
177
280
  serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
178
281
  } | {
179
282
  serializer?: SerializerType;
@@ -190,24 +293,22 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
190
293
  /**
191
294
  * Executes the serializer and returns the serialized output.
192
295
  *
193
- * This method processes all defined attributes, custom attributes, delegated attributes,
194
- * and associations to produce the final serialized object. The result is suitable for
195
- * JSON.stringify() and API responses.
296
+ * Processes all defined attributes, custom attributes, delegated attributes,
297
+ * and associations to produce the final serialized object.
196
298
  *
197
299
  * @param passthrough - Additional data to pass through to nested serializers
300
+ * (e.g., locale, current user context)
198
301
  * @param opts - Rendering options for customizing the serialization process
199
- * @returns The serialized object
302
+ * @returns The serialized object, suitable for JSON responses
200
303
  *
201
304
  * @example
202
305
  * ```typescript
203
306
  * const result = UserSerializer(user).render()
204
307
  * // Returns: { id: 1, email: 'user@example.com', ... }
205
308
  *
206
- * // With passthrough data
309
+ * // With passthrough data for nested serializers
207
310
  * const result = UserSerializer(user).render({ currentUserId: 123 })
208
311
  * ```
209
- *
210
- * See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
211
312
  */
212
313
  render(passthrough?: any, opts?: SerializerRendererOpts): Record<string, any> | null;
213
314
  }