@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, ViewModel, ViewModelClass } from '../../types/dream.js';
3
3
  import { InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptions, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerType } from '../../types/serializer.js';
4
4
  import { SerializerRendererOpts } from '../SerializerRenderer.js';
5
+ import { DreamPropertiesToExclude } from './DreamSerializerBuilder.js';
5
6
  export default class ObjectSerializerBuilder<MaybeNullDataType extends object | null, PassthroughDataType, DataType extends Exclude<MaybeNullDataType, null> = Exclude<MaybeNullDataType, null>> {
6
7
  protected data: MaybeNullDataType;
7
8
  protected passthroughData: PassthroughDataType;
@@ -14,7 +15,15 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
14
15
  * inference is not available for plain objects or ViewModels.
15
16
  *
16
17
  * @param name - The attribute name from the data object
17
- * @param options - Configuration options including required OpenAPI schema, default value, and output customization
18
+ * @param options - Configuration options:
19
+ * - `openapi` - (required) OpenAPI schema definition for the attribute
20
+ * - `as` - Rename the attribute key in the serialized output and OpenAPI shape
21
+ * - `default` - Value to use when the attribute is undefined
22
+ * - `precision` - Round decimal values to the specified number of decimal places (0–9)
23
+ * during rendering; does not affect the OpenAPI shape
24
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
25
+ * when omitted, attributes are required by default, meaning `undefined` values will
26
+ * serialize as `null`
18
27
  * @returns The serializer builder for method chaining
19
28
  *
20
29
  * @example
@@ -35,21 +44,40 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
35
44
  * openapi: { type: 'string' },
36
45
  * as: 'userEmail'
37
46
  * })
38
- * ```
39
47
  *
40
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
48
+ * // Round decimal to 2 places
49
+ * .attribute('price', {
50
+ * openapi: 'decimal',
51
+ * precision: 2
52
+ * })
53
+ *
54
+ * // Mark as optional in OpenAPI (omitted from response when undefined)
55
+ * .attribute('nickname', {
56
+ * openapi: 'string',
57
+ * required: false
58
+ * })
59
+ * ```
41
60
  */
42
61
  attribute<AttributeName extends keyof DataType & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
43
62
  /**
44
63
  * Includes an attribute from a nested object in the serialized output.
45
64
  *
46
- * Pulls up an attribute from a target object property. The `openapi` option
47
- * is always required. If the target object or the delegated attribute
48
- * is null/undefined, the `default` option value will be used if provided.
65
+ * Accesses `targetName.name` on the data object. The `openapi` option is always
66
+ * required. If the target object or the delegated attribute is null/undefined,
67
+ * the `default` option value will be used if provided.
49
68
  *
50
69
  * @param targetName - The property name containing the target object
51
70
  * @param name - The attribute name within the target object
52
- * @param options - Configuration options including required OpenAPI schema, default value, and output customization
71
+ * @param options - Configuration options:
72
+ * - `openapi` - (required) OpenAPI schema definition for the attribute
73
+ * - `as` - Rename the attribute key in the serialized output and OpenAPI shape
74
+ * (e.g., delegating `'profile', 'avatarUrl'` with `as: 'avatar'` outputs the value
75
+ * under `avatar`)
76
+ * - `default` - Value to use when the target object or its attribute is null/undefined
77
+ * - `precision` - Round decimal values to the specified number of decimal places (0–9)
78
+ * during rendering; does not affect the OpenAPI shape
79
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
80
+ * when omitted, attributes are required by default
53
81
  * @returns The serializer builder for method chaining
54
82
  *
55
83
  * @example
@@ -64,20 +92,34 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
64
92
  * openapi: { type: 'string' },
65
93
  * default: 'Anonymous User'
66
94
  * })
67
- * ```
68
95
  *
69
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
96
+ * // Rename the output key
97
+ * .delegatedAttribute('profile', 'avatarUrl', {
98
+ * openapi: 'string',
99
+ * as: 'avatar'
100
+ * })
101
+ * ```
70
102
  */
71
- delegatedAttribute<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, TargetName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType, TargetObject extends ActualDataType[TargetName] = ActualDataType[TargetName], AttributeName extends TargetObject extends object ? Exclude<keyof TargetObject, keyof Dream> & string : never = TargetObject extends object ? Exclude<keyof TargetObject, keyof Dream> & string : never>(targetName: TargetName, name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
103
+ delegatedAttribute<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 ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, TargetName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType, TargetObject extends ActualDataType[TargetName] = ActualDataType[TargetName], AttributeName extends TargetObject extends object ? Exclude<keyof TargetObject, DreamPropertiesToExclude> & string : never = TargetObject extends object ? Exclude<keyof TargetObject, DreamPropertiesToExclude> & string : never>(targetName: TargetName, name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
72
104
  /**
73
105
  * Includes a computed value in the serialized output.
74
106
  *
75
107
  * Executes a callback function to generate a custom attribute value.
76
108
  * The `openapi` option is always required since the return type cannot be inferred.
77
109
  *
110
+ * Unlike DreamSerializerBuilder's `customAttribute`, this version does not support `as`
111
+ * or `precision`.
112
+ *
78
113
  * @param name - The attribute name for the computed value
79
114
  * @param fn - Callback function that returns the computed value
80
- * @param options - Configuration options including required OpenAPI schema and optional flattening
115
+ * @param options - Configuration options:
116
+ * - `openapi` - (required) OpenAPI schema definition for the computed value
117
+ * - `default` - Value to use when the callback returns undefined
118
+ * - `flatten` - When `true`, spreads the returned object's properties directly into the
119
+ * parent serialized output instead of nesting them under `name`; the `openapi` option
120
+ * should then define each flattened property individually
121
+ * - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
122
+ * when omitted, attributes are required by default
81
123
  * @returns The serializer builder for method chaining
82
124
  *
83
125
  * @example
@@ -97,8 +139,6 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
97
139
  * }
98
140
  * })
99
141
  * ```
100
- *
101
- * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
102
142
  */
103
143
  customAttribute(name: string, fn: () => unknown, options: Omit<NonAutomaticSerializerAttributeOptions, 'as'> & {
104
144
  flatten?: boolean;
@@ -110,25 +150,47 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
110
150
  * since association schemas cannot be inferred from plain objects.
111
151
  *
112
152
  * @param name - The association property name
113
- * @param options - Configuration options including required serializer and OpenAPI schema
153
+ * @param options - Configuration options:
154
+ * - `as` - Rename the association key in the serialized output
155
+ * - `flatten` - When `true`, spreads the rendered association's attributes directly into
156
+ * the parent serialized output instead of nesting them under `name`. Be aware of
157
+ * attribute shadowing: if the parent and flattened association share attribute names
158
+ * (e.g., `id`), the flattened association's values overwrite the parent's
159
+ * - `optional` - When `true`, allows the association to be null/missing without causing
160
+ * an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
161
+ * `rendersOne` expects the association to be present (mirroring the `optional` option on
162
+ * `@deco.BelongsTo`). Set this to `true` when the association is genuinely nullable
163
+ *
164
+ * For Dream associations:
165
+ * - `dreamClass` - The Dream model class, enabling serializer inference; when specified,
166
+ * `serializerKey` may also be provided to select a specific registered serializer
167
+ * - `serializer` - Provide an explicit serializer function
168
+ *
169
+ * For ViewModel associations:
170
+ * - `viewModelClass` + optional `serializerKey`
171
+ * - `serializer`
172
+ *
173
+ * For non-Dream/non-ViewModel associations:
174
+ * - `serializer` is required
114
175
  * @returns The serializer builder for method chaining
115
176
  *
116
177
  * @example
117
178
  * ```typescript
118
179
  * // With explicit serializer function
119
- * .rendersOne('owner', UserSerializer, {
120
- * openapi: { $ref: '#/components/schemas/User' }
121
- * })
180
+ * .rendersOne('owner', { serializer: CustomOwnerSerializer })
122
181
  *
123
- * // With Dream class reference
182
+ * // With Dream class reference and serializer key
124
183
  * .rendersOne('creator', {
125
184
  * dreamClass: User,
126
- * serializerKey: 'summary',
127
- * openapi: { $ref: '#/components/schemas/UserSummary' }
185
+ * serializerKey: 'summary'
128
186
  * })
129
- * ```
130
187
  *
131
- * See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
188
+ * // Allow null association
189
+ * .rendersOne('approver', { serializer: UserSerializer, optional: true })
190
+ *
191
+ * // Flatten into parent object
192
+ * .rendersOne('profile', { serializer: ProfileSerializer, flatten: true })
193
+ * ```
132
194
  */
133
195
  rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : keyof ProvidedModelType = ProvidedModelType extends undefined ? undefined : keyof ProvidedModelType, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? keyof ActualDataType : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? keyof ActualDataType : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[AttributeName], null>, SerializerOptions = AssociatedModelType extends Dream ? {
134
196
  dreamClass: typeof Dream;
@@ -143,8 +205,20 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
143
205
  } : {
144
206
  serializer: SerializerType;
145
207
  }>(name: AttributeName, options: {
208
+ /**
209
+ * Rename the association key in the serialized output.
210
+ */
146
211
  as?: string;
212
+ /**
213
+ * If `true`, the rendered association's attributes are merged directly into
214
+ * the parent object instead of being nested under the association key.
215
+ */
147
216
  flatten?: boolean;
217
+ /**
218
+ * If `true`, the association is treated as nullable in the OpenAPI spec,
219
+ * allowing `null` when the association doesn't resolve. Set this for
220
+ * associations that may not exist.
221
+ */
148
222
  optional?: boolean;
149
223
  } & SerializerOptions): this;
150
224
  /**
@@ -153,34 +227,45 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
153
227
  * For ObjectSerializer, explicit serializer configuration is always required
154
228
  * since association schemas cannot be inferred from plain objects.
155
229
  *
156
- * @param name - The association property name (should be an array)
157
- * @param options - Configuration options including required serializer and OpenAPI schema
230
+ * @param name - The association property name (should resolve to an array)
231
+ * @param options - Configuration options:
232
+ * - `as` - Rename the association key in the serialized output
233
+ *
234
+ * For Dream associations:
235
+ * - `dreamClass` - The Dream model class, enabling serializer inference; when specified,
236
+ * `serializerKey` may also be provided to select a specific registered serializer
237
+ * - `serializer` - Provide an explicit serializer function
238
+ *
239
+ * For ViewModel associations:
240
+ * - `viewModelClass` + optional `serializerKey`
241
+ * - `serializer`
242
+ *
243
+ * For non-Dream/non-ViewModel associations:
244
+ * - `serializer` is required
158
245
  * @returns The serializer builder for method chaining
159
246
  *
160
247
  * @example
161
248
  * ```typescript
162
249
  * // With explicit serializer function
163
- * .rendersMany('articles', ArticleSerializer, {
164
- * openapi: {
165
- * type: 'array',
166
- * items: { $ref: '#/components/schemas/Article' }
167
- * }
250
+ * .rendersMany('articles', { serializer: ArticleSerializer })
251
+ *
252
+ * // With Dream class reference and serializer key
253
+ * .rendersMany('posts', {
254
+ * dreamClass: Post,
255
+ * serializerKey: 'summary'
168
256
  * })
169
257
  *
170
258
  * // With ViewModel class reference
171
259
  * .rendersMany('comments', {
172
260
  * viewModelClass: CommentViewModel,
173
- * serializer: CommentViewModelSerializer,
174
- * openapi: {
175
- * type: 'array',
176
- * items: { $ref: '#/components/schemas/Comment' }
177
- * }
261
+ * serializer: CommentViewModelSerializer
178
262
  * })
179
- * ```
180
263
  *
181
- * See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
264
+ * // Rename output key
265
+ * .rendersMany('articles', { serializer: ArticleSerializer, as: 'posts' })
266
+ * ```
182
267
  */
183
- 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 ? {
268
+ 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 ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : 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 ? {
184
269
  dreamClass: typeof Dream;
185
270
  serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
186
271
  } | {
@@ -198,13 +283,13 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
198
283
  /**
199
284
  * Executes the serializer and returns the serialized output.
200
285
  *
201
- * This method processes all defined attributes, custom attributes, delegated attributes,
202
- * and associations to produce the final serialized object. The result is suitable for
203
- * JSON.stringify() and API responses.
286
+ * Processes all defined attributes, custom attributes, delegated attributes,
287
+ * and associations to produce the final serialized object.
204
288
  *
205
289
  * @param passthrough - Additional data to pass through to nested serializers
290
+ * (e.g., locale, current user context)
206
291
  * @param opts - Rendering options for customizing the serialization process
207
- * @returns The serialized object
292
+ * @returns The serialized object, suitable for JSON responses
208
293
  *
209
294
  * @example
210
295
  * ```typescript
@@ -214,8 +299,6 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
214
299
  * // With passthrough data for nested serializers
215
300
  * const result = UserViewModelSerializer(userVm).render({ currentUserId: '456' })
216
301
  * ```
217
- *
218
- * See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
219
302
  */
220
303
  render(passthrough?: any, opts?: SerializerRendererOpts): Record<string, any> | null;
221
304
  }
@@ -19,15 +19,49 @@ export interface BelongsToStatement<BaseInstance extends Dream, DB, Schema, Tabl
19
19
  withoutDefaultScopes?: DefaultScopeName<BaseInstance>[];
20
20
  }
21
21
  export interface NonPolymorphicBelongsToOptions<BaseInstance extends Dream, AssociationGlobalNameOrNames extends GlobalModelNames<BaseInstance> | readonly GlobalModelNames<BaseInstance>[], AssociationGlobalName = AssociationGlobalNameOrNames extends Readonly<any[]> ? AssociationGlobalNameOrNames[0] & string : AssociationGlobalNameOrNames & string, AssociationTableName extends AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB'] = TableNameForGlobalModelName<BaseInstance, AssociationGlobalName & GlobalModelNames<BaseInstance>> & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']> {
22
+ /**
23
+ * A custom column name on this model to use as the foreign key for this association,
24
+ * overriding the default convention-based foreign key.
25
+ */
22
26
  on?: DreamColumnNames<BaseInstance>;
27
+ /**
28
+ * A custom column on the associated model to use as the primary key for this association,
29
+ * instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
30
+ */
23
31
  primaryKeyOverride?: TableColumnNames<BaseInstance['DB'], AssociationTableName> | null;
32
+ /**
33
+ * Whether or not this association is optional. Defaults to `false`.
34
+ * When `false`, a validation is added requiring the foreign key to be present.
35
+ */
24
36
  optional?: boolean;
37
+ /**
38
+ * A list of default scopes to bypass when loading this association.
39
+ */
25
40
  withoutDefaultScopes?: DefaultScopeNameForTable<BaseInstance['schema'], AssociationTableName>[];
26
41
  }
27
42
  export interface PolymorphicBelongsToOptions<BaseInstance extends Dream, AssociationGlobalNameOrNames extends GlobalModelNames<BaseInstance> | readonly GlobalModelNames<BaseInstance>[], AssociationGlobalName = AssociationGlobalNameOrNames extends Readonly<any[]> ? AssociationGlobalNameOrNames[0] & string : AssociationGlobalNameOrNames & string, AssociationTableName extends AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB'] = TableNameForGlobalModelName<BaseInstance, AssociationGlobalName & GlobalModelNames<BaseInstance>> & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']> {
43
+ /**
44
+ * A custom column name on this model to use as the foreign key for this association.
45
+ * Required for polymorphic BelongsTo associations.
46
+ */
28
47
  on: DreamColumnNames<BaseInstance>;
48
+ /**
49
+ * A custom column on the associated model to use as the primary key for this association,
50
+ * instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
51
+ */
29
52
  primaryKeyOverride?: TableColumnNames<BaseInstance['DB'], AssociationTableName> | null;
53
+ /**
54
+ * Whether or not this association is optional. Defaults to `false`.
55
+ * When `false`, a validation is added requiring the foreign key to be present.
56
+ */
30
57
  optional?: boolean;
58
+ /**
59
+ * Marks this as a polymorphic association, where the foreign key and a type column
60
+ * together identify the associated record across multiple tables.
61
+ */
31
62
  polymorphic: boolean;
63
+ /**
64
+ * A list of default scopes to bypass when loading this association.
65
+ */
32
66
  withoutDefaultScopes?: DefaultScopeNameForTable<BaseInstance['schema'], AssociationTableName>[];
33
67
  }
@@ -49,9 +49,27 @@ export interface NonPolymorphicBelongsToOptions<
49
49
  AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> &
50
50
  keyof BaseInstance['DB'],
51
51
  > {
52
+ /**
53
+ * A custom column name on this model to use as the foreign key for this association,
54
+ * overriding the default convention-based foreign key.
55
+ */
52
56
  on?: DreamColumnNames<BaseInstance>
57
+
58
+ /**
59
+ * A custom column on the associated model to use as the primary key for this association,
60
+ * instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
61
+ */
53
62
  primaryKeyOverride?: TableColumnNames<BaseInstance['DB'], AssociationTableName> | null
63
+
64
+ /**
65
+ * Whether or not this association is optional. Defaults to `false`.
66
+ * When `false`, a validation is added requiring the foreign key to be present.
67
+ */
54
68
  optional?: boolean
69
+
70
+ /**
71
+ * A list of default scopes to bypass when loading this association.
72
+ */
55
73
  withoutDefaultScopes?: DefaultScopeNameForTable<BaseInstance['schema'], AssociationTableName>[]
56
74
  }
57
75
 
@@ -71,9 +89,32 @@ export interface PolymorphicBelongsToOptions<
71
89
  AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> &
72
90
  keyof BaseInstance['DB'],
73
91
  > {
92
+ /**
93
+ * A custom column name on this model to use as the foreign key for this association.
94
+ * Required for polymorphic BelongsTo associations.
95
+ */
74
96
  on: DreamColumnNames<BaseInstance>
97
+
98
+ /**
99
+ * A custom column on the associated model to use as the primary key for this association,
100
+ * instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
101
+ */
75
102
  primaryKeyOverride?: TableColumnNames<BaseInstance['DB'], AssociationTableName> | null
103
+
104
+ /**
105
+ * Whether or not this association is optional. Defaults to `false`.
106
+ * When `false`, a validation is added requiring the foreign key to be present.
107
+ */
76
108
  optional?: boolean
109
+
110
+ /**
111
+ * Marks this as a polymorphic association, where the foreign key and a type column
112
+ * together identify the associated record across multiple tables.
113
+ */
77
114
  polymorphic: boolean
115
+
116
+ /**
117
+ * A list of default scopes to bypass when loading this association.
118
+ */
78
119
  withoutDefaultScopes?: DefaultScopeNameForTable<BaseInstance['schema'], AssociationTableName>[]
79
120
  }
@@ -7,7 +7,25 @@ export type HasManyStatement<BaseInstance extends Dream, DB, Schema, ForeignTabl
7
7
  order?: OrderStatement<DB, Schema, ForeignTableName>;
8
8
  };
9
9
  interface HasManyOnlyOptions<BaseInstance extends Dream, AssociationGlobalNameOrNames extends GlobalModelNames<BaseInstance> | readonly GlobalModelNames<BaseInstance>[], AssociationGlobalName = AssociationGlobalNameOrNames extends any[] ? AssociationGlobalNameOrNames[0] & string : AssociationGlobalNameOrNames & string, AssociationTableName = TableNameForGlobalModelName<BaseInstance, AssociationGlobalName & GlobalModelNames<BaseInstance>>> {
10
+ /**
11
+ * Applies a DISTINCT clause to this association. If a column name is provided, the distinct
12
+ * clause is applied to that column. If `true`, the distinct clause is applied to the primary key.
13
+ *
14
+ * ```ts
15
+ * @deco.HasMany('Collar', { distinct: 'tagName' })
16
+ * public uniqueCollars: Collar[]
17
+ * ```
18
+ */
10
19
  distinct?: TableColumnNames<BaseInstance['DB'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']> | boolean;
20
+ /**
21
+ * A custom order to apply when loading this association. Can be a single order statement
22
+ * or an array of order statements.
23
+ *
24
+ * ```ts
25
+ * @deco.HasMany('Post', { order: { createdAt: 'desc' } })
26
+ * public recentPosts: Post[]
27
+ * ```
28
+ */
11
29
  order?: OrderStatement<BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']> | OrderStatement<BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>[];
12
30
  }
13
31
  export type HasManyOptions<BaseInstance extends Dream, AssociationGlobalName extends keyof GlobalModelNameTableMap<BaseInstance>, ThroughAssociationName extends keyof BaseInstance['schema'][BaseInstance['table']]['associations']> = HasOptions<BaseInstance, AssociationGlobalName, ThroughAssociationName> & HasManyOnlyOptions<BaseInstance, AssociationGlobalName>;
@@ -36,6 +36,15 @@ interface HasManyOnlyOptions<
36
36
  AssociationGlobalName & GlobalModelNames<BaseInstance>
37
37
  >,
38
38
  > {
39
+ /**
40
+ * Applies a DISTINCT clause to this association. If a column name is provided, the distinct
41
+ * clause is applied to that column. If `true`, the distinct clause is applied to the primary key.
42
+ *
43
+ * ```ts
44
+ * @deco.HasMany('Collar', { distinct: 'tagName' })
45
+ * public uniqueCollars: Collar[]
46
+ * ```
47
+ */
39
48
  distinct?:
40
49
  | TableColumnNames<
41
50
  BaseInstance['DB'],
@@ -45,6 +54,15 @@ interface HasManyOnlyOptions<
45
54
  >
46
55
  | boolean
47
56
 
57
+ /**
58
+ * A custom order to apply when loading this association. Can be a single order statement
59
+ * or an array of order statements.
60
+ *
61
+ * ```ts
62
+ * @deco.HasMany('Post', { order: { createdAt: 'desc' } })
63
+ * public recentPosts: Post[]
64
+ * ```
65
+ */
48
66
  order?:
49
67
  | OrderStatement<
50
68
  BaseInstance['DB'],
@@ -75,17 +75,88 @@ export interface HasStatement<BaseInstance extends Dream, DB, Schema, ForeignTab
75
75
  withoutDefaultScopes?: DefaultScopeName<BaseInstance>[];
76
76
  }
77
77
  interface HasOptionsBase<BaseInstance extends Dream, AssociationGlobalName extends keyof GlobalModelNameTableMap<BaseInstance>, ThroughAssociationName extends keyof BaseInstance['schema'][BaseInstance['table']]['associations'], ForeignTableName extends BaseInstance['schema'][BaseInstance['table']]['associations'][ThroughAssociationName]['tables'][number] = BaseInstance['schema'][BaseInstance['table']]['associations'][ThroughAssociationName]['tables'][number], AssociationTableName = TableNameForGlobalModelName<BaseInstance, AssociationGlobalName & keyof GlobalModelNameTableMap<BaseInstance>>> {
78
+ /**
79
+ * If `'destroy'`, associated records will be cascade-deleted when the base model is destroyed.
80
+ */
78
81
  dependent?: DependentOptions;
82
+ /**
83
+ * A custom column on the associated model to use as the foreign key for this association,
84
+ * overriding the default convention-based foreign key.
85
+ */
79
86
  on?: TableColumnNames<BaseInstance['DB'], AssociationTableName & keyof BaseInstance['DB']>;
87
+ /**
88
+ * A where clause applied whenever this association is loaded, scoping the association
89
+ * to only records matching the given conditions.
90
+ *
91
+ * ```ts
92
+ * @deco.HasMany('Collar', { and: { lost: false } })
93
+ * public currentCollars: Collar[]
94
+ * ```
95
+ */
80
96
  and?: OnStatementForAssociationDefinition<BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>;
97
+ /**
98
+ * A negated where clause applied whenever this association is loaded, excluding
99
+ * records matching the given conditions.
100
+ *
101
+ * ```ts
102
+ * @deco.HasOne('Collar', { andNot: { lost: true } })
103
+ * public notLostCollar: Collar
104
+ * ```
105
+ */
81
106
  andNot?: InternalWhereStatement<BaseInstance, BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>;
107
+ /**
108
+ * An array of where clauses combined with OR logic, applied whenever this association
109
+ * is loaded. At least one of the clauses must match.
110
+ *
111
+ * ```ts
112
+ * @deco.HasMany('Balloon', { andAny: [{ color: 'red' }, { color: 'blue' }] })
113
+ * public redOrBlueBalloons: Balloon[]
114
+ * ```
115
+ */
82
116
  andAny?: InternalWhereStatement<BaseInstance, BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>[];
117
+ /**
118
+ * Marks this as a polymorphic association, where the foreign key and a type column
119
+ * together identify the associated record across multiple tables.
120
+ */
83
121
  polymorphic?: boolean;
122
+ /**
123
+ * A custom column on this model to use as the primary key for this association,
124
+ * instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
125
+ */
84
126
  primaryKeyOverride?: DreamColumnNames<BaseInstance> | null;
127
+ /**
128
+ * Adds a join condition between a column on the associated model and a column on this model,
129
+ * so the association is scoped by matching column values across both models.
130
+ *
131
+ * ```ts
132
+ * @deco.HasMany('Post', { selfAnd: { species: 'targetSpecies' } })
133
+ * public postsMatchingSpecies: Post[]
134
+ * ```
135
+ */
85
136
  selfAnd?: SelfOnStatement<BaseInstance, BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>;
137
+ /**
138
+ * Adds a negated join condition between a column on the associated model and a column
139
+ * on this model, excluding records where the columns match.
140
+ */
86
141
  selfAndNot?: SelfOnStatement<BaseInstance, BaseInstance['DB'], BaseInstance['schema'], AssociationTableName & AssociationTableNames<BaseInstance['DB'], BaseInstance['schema']> & keyof BaseInstance['DB']>;
142
+ /**
143
+ * Used in conjunction with `through` to specify which association on the intermediate model
144
+ * should be used to reach the target model.
145
+ */
87
146
  source?: keyof BaseInstance['schema'][ForeignTableName]['associations'];
147
+ /**
148
+ * Loads this association through an intermediate association, similar to a SQL join
149
+ * through a join table.
150
+ *
151
+ * ```ts
152
+ * @deco.HasMany('Rating', { through: 'posts' })
153
+ * public ratings: Rating[]
154
+ * ```
155
+ */
88
156
  through?: ThroughAssociationName;
157
+ /**
158
+ * A list of default scopes to bypass when loading this association.
159
+ */
89
160
  withoutDefaultScopes?: DefaultScopeNameForTable<BaseInstance['schema'], AssociationTableName & keyof BaseInstance['DB']>[];
90
161
  }
91
162
  export type PolymorphicOption = 'polymorphic';