@rvoh/dream 2.5.6 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/Dream.js +25 -10
- package/dist/cjs/src/decorators/class/STI.js +2 -2
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +16 -10
- package/dist/cjs/src/dream/LoadBuilder.js +15 -9
- package/dist/cjs/src/dream/Query.js +1 -1
- package/dist/cjs/src/dream/internal/similarity/SimilarityBuilder.js +3 -1
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +110 -52
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/esm/src/Dream.js +25 -10
- package/dist/esm/src/decorators/class/STI.js +2 -2
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +16 -10
- package/dist/esm/src/dream/LoadBuilder.js +15 -9
- package/dist/esm/src/dream/Query.js +1 -1
- package/dist/esm/src/dream/internal/similarity/SimilarityBuilder.js +3 -1
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +110 -52
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/types/src/Dream.d.ts +25 -10
- package/dist/types/src/decorators/Decorators.d.ts +8 -0
- package/dist/types/src/decorators/class/STI.d.ts +1 -3
- package/dist/types/src/decorators/field/sortable/Sortable.d.ts +9 -0
- package/dist/types/src/decorators/field/validation/Validates.d.ts +4 -0
- package/dist/types/src/decorators/static-method/Scope.d.ts +4 -0
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +16 -10
- package/dist/types/src/dream/LoadBuilder.d.ts +15 -9
- package/dist/types/src/dream/Query.d.ts +1 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +151 -59
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +123 -41
- package/dist/types/src/types/associations/belongsTo.d.ts +34 -0
- package/dist/types/src/types/associations/belongsTo.ts +41 -0
- package/dist/types/src/types/associations/hasMany.d.ts +18 -0
- package/dist/types/src/types/associations/hasMany.ts +18 -0
- package/dist/types/src/types/associations/shared.d.ts +71 -0
- package/dist/types/src/types/associations/shared.ts +74 -0
- package/dist/types/src/types/dream.d.ts +16 -0
- package/dist/types/src/types/dream.ts +18 -0
- package/dist/types/src/types/lifecycle.d.ts +18 -0
- package/dist/types/src/types/lifecycle.ts +18 -0
- package/dist/types/src/types/query.d.ts +3 -0
- package/dist/types/src/types/query.ts +3 -0
- package/docs/classes/db.DreamMigrationHelpers.html +9 -9
- package/docs/classes/db.KyselyQueryDriver.html +32 -32
- package/docs/classes/db.PostgresQueryDriver.html +33 -33
- package/docs/classes/db.QueryDriverBase.html +31 -31
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +21 -20
- package/docs/classes/index.Dream.html +133 -126
- package/docs/classes/index.DreamApp.html +5 -5
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +57 -57
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +6 -6
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +172 -58
- package/docs/classes/system.ObjectSerializerBuilder.html +109 -33
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +2 -2
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
|
@@ -14,7 +14,15 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
14
14
|
* inference is not available for plain objects or ViewModels.
|
|
15
15
|
*
|
|
16
16
|
* @param name - The attribute name from the data object
|
|
17
|
-
* @param options - Configuration options
|
|
17
|
+
* @param options - Configuration options:
|
|
18
|
+
* - `openapi` - (required) OpenAPI schema definition for the attribute
|
|
19
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
20
|
+
* - `default` - Value to use when the attribute is undefined
|
|
21
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
22
|
+
* during rendering; does not affect the OpenAPI shape
|
|
23
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
24
|
+
* when omitted, attributes are required by default, meaning `undefined` values will
|
|
25
|
+
* serialize as `null`
|
|
18
26
|
* @returns The serializer builder for method chaining
|
|
19
27
|
*
|
|
20
28
|
* @example
|
|
@@ -35,21 +43,40 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
35
43
|
* openapi: { type: 'string' },
|
|
36
44
|
* as: 'userEmail'
|
|
37
45
|
* })
|
|
38
|
-
* ```
|
|
39
46
|
*
|
|
40
|
-
*
|
|
47
|
+
* // Round decimal to 2 places
|
|
48
|
+
* .attribute('price', {
|
|
49
|
+
* openapi: 'decimal',
|
|
50
|
+
* precision: 2
|
|
51
|
+
* })
|
|
52
|
+
*
|
|
53
|
+
* // Mark as optional in OpenAPI (omitted from response when undefined)
|
|
54
|
+
* .attribute('nickname', {
|
|
55
|
+
* openapi: 'string',
|
|
56
|
+
* required: false
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
41
59
|
*/
|
|
42
60
|
attribute<AttributeName extends keyof DataType & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
|
|
43
61
|
/**
|
|
44
62
|
* Includes an attribute from a nested object in the serialized output.
|
|
45
63
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
64
|
+
* Accesses `targetName.name` on the data object. The `openapi` option is always
|
|
65
|
+
* required. If the target object or the delegated attribute is null/undefined,
|
|
66
|
+
* the `default` option value will be used if provided.
|
|
49
67
|
*
|
|
50
68
|
* @param targetName - The property name containing the target object
|
|
51
69
|
* @param name - The attribute name within the target object
|
|
52
|
-
* @param options - Configuration options
|
|
70
|
+
* @param options - Configuration options:
|
|
71
|
+
* - `openapi` - (required) OpenAPI schema definition for the attribute
|
|
72
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
73
|
+
* (e.g., delegating `'profile', 'avatarUrl'` with `as: 'avatar'` outputs the value
|
|
74
|
+
* under `avatar`)
|
|
75
|
+
* - `default` - Value to use when the target object or its attribute is null/undefined
|
|
76
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
77
|
+
* during rendering; does not affect the OpenAPI shape
|
|
78
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
79
|
+
* when omitted, attributes are required by default
|
|
53
80
|
* @returns The serializer builder for method chaining
|
|
54
81
|
*
|
|
55
82
|
* @example
|
|
@@ -64,9 +91,13 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
64
91
|
* openapi: { type: 'string' },
|
|
65
92
|
* default: 'Anonymous User'
|
|
66
93
|
* })
|
|
67
|
-
* ```
|
|
68
94
|
*
|
|
69
|
-
*
|
|
95
|
+
* // Rename the output key
|
|
96
|
+
* .delegatedAttribute('profile', 'avatarUrl', {
|
|
97
|
+
* openapi: 'string',
|
|
98
|
+
* as: 'avatar'
|
|
99
|
+
* })
|
|
100
|
+
* ```
|
|
70
101
|
*/
|
|
71
102
|
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;
|
|
72
103
|
/**
|
|
@@ -75,9 +106,19 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
75
106
|
* Executes a callback function to generate a custom attribute value.
|
|
76
107
|
* The `openapi` option is always required since the return type cannot be inferred.
|
|
77
108
|
*
|
|
109
|
+
* Unlike DreamSerializerBuilder's `customAttribute`, this version does not support `as`
|
|
110
|
+
* or `precision`.
|
|
111
|
+
*
|
|
78
112
|
* @param name - The attribute name for the computed value
|
|
79
113
|
* @param fn - Callback function that returns the computed value
|
|
80
|
-
* @param options - Configuration options
|
|
114
|
+
* @param options - Configuration options:
|
|
115
|
+
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
116
|
+
* - `default` - Value to use when the callback returns undefined
|
|
117
|
+
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
118
|
+
* parent serialized output instead of nesting them under `name`; the `openapi` option
|
|
119
|
+
* should then define each flattened property individually
|
|
120
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
121
|
+
* when omitted, attributes are required by default
|
|
81
122
|
* @returns The serializer builder for method chaining
|
|
82
123
|
*
|
|
83
124
|
* @example
|
|
@@ -97,8 +138,6 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
97
138
|
* }
|
|
98
139
|
* })
|
|
99
140
|
* ```
|
|
100
|
-
*
|
|
101
|
-
* See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
|
|
102
141
|
*/
|
|
103
142
|
customAttribute(name: string, fn: () => unknown, options: Omit<NonAutomaticSerializerAttributeOptions, 'as'> & {
|
|
104
143
|
flatten?: boolean;
|
|
@@ -110,25 +149,47 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
110
149
|
* since association schemas cannot be inferred from plain objects.
|
|
111
150
|
*
|
|
112
151
|
* @param name - The association property name
|
|
113
|
-
* @param options - Configuration options
|
|
152
|
+
* @param options - Configuration options:
|
|
153
|
+
* - `as` - Rename the association key in the serialized output
|
|
154
|
+
* - `flatten` - When `true`, spreads the rendered association's attributes directly into
|
|
155
|
+
* the parent serialized output instead of nesting them under `name`. Be aware of
|
|
156
|
+
* attribute shadowing: if the parent and flattened association share attribute names
|
|
157
|
+
* (e.g., `id`), the flattened association's values overwrite the parent's
|
|
158
|
+
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
159
|
+
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
160
|
+
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|
|
161
|
+
* `@deco.BelongsTo`). Set this to `true` when the association is genuinely nullable
|
|
162
|
+
*
|
|
163
|
+
* For Dream associations:
|
|
164
|
+
* - `dreamClass` - The Dream model class, enabling serializer inference; when specified,
|
|
165
|
+
* `serializerKey` may also be provided to select a specific registered serializer
|
|
166
|
+
* - `serializer` - Provide an explicit serializer function
|
|
167
|
+
*
|
|
168
|
+
* For ViewModel associations:
|
|
169
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
170
|
+
* - `serializer`
|
|
171
|
+
*
|
|
172
|
+
* For non-Dream/non-ViewModel associations:
|
|
173
|
+
* - `serializer` is required
|
|
114
174
|
* @returns The serializer builder for method chaining
|
|
115
175
|
*
|
|
116
176
|
* @example
|
|
117
177
|
* ```typescript
|
|
118
178
|
* // With explicit serializer function
|
|
119
|
-
* .rendersOne('owner',
|
|
120
|
-
* openapi: { $ref: '#/components/schemas/User' }
|
|
121
|
-
* })
|
|
179
|
+
* .rendersOne('owner', { serializer: CustomOwnerSerializer })
|
|
122
180
|
*
|
|
123
|
-
* // With Dream class reference
|
|
181
|
+
* // With Dream class reference and serializer key
|
|
124
182
|
* .rendersOne('creator', {
|
|
125
183
|
* dreamClass: User,
|
|
126
|
-
* serializerKey: 'summary'
|
|
127
|
-
* openapi: { $ref: '#/components/schemas/UserSummary' }
|
|
184
|
+
* serializerKey: 'summary'
|
|
128
185
|
* })
|
|
129
|
-
* ```
|
|
130
186
|
*
|
|
131
|
-
*
|
|
187
|
+
* // Allow null association
|
|
188
|
+
* .rendersOne('approver', { serializer: UserSerializer, optional: true })
|
|
189
|
+
*
|
|
190
|
+
* // Flatten into parent object
|
|
191
|
+
* .rendersOne('profile', { serializer: ProfileSerializer, flatten: true })
|
|
192
|
+
* ```
|
|
132
193
|
*/
|
|
133
194
|
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
195
|
dreamClass: typeof Dream;
|
|
@@ -143,8 +204,20 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
143
204
|
} : {
|
|
144
205
|
serializer: SerializerType;
|
|
145
206
|
}>(name: AttributeName, options: {
|
|
207
|
+
/**
|
|
208
|
+
* Rename the association key in the serialized output.
|
|
209
|
+
*/
|
|
146
210
|
as?: string;
|
|
211
|
+
/**
|
|
212
|
+
* If `true`, the rendered association's attributes are merged directly into
|
|
213
|
+
* the parent object instead of being nested under the association key.
|
|
214
|
+
*/
|
|
147
215
|
flatten?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* If `true`, the association is treated as nullable in the OpenAPI spec,
|
|
218
|
+
* allowing `null` when the association doesn't resolve. Set this for
|
|
219
|
+
* associations that may not exist.
|
|
220
|
+
*/
|
|
148
221
|
optional?: boolean;
|
|
149
222
|
} & SerializerOptions): this;
|
|
150
223
|
/**
|
|
@@ -153,32 +226,43 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
153
226
|
* For ObjectSerializer, explicit serializer configuration is always required
|
|
154
227
|
* since association schemas cannot be inferred from plain objects.
|
|
155
228
|
*
|
|
156
|
-
* @param name - The association property name (should
|
|
157
|
-
* @param options - Configuration options
|
|
229
|
+
* @param name - The association property name (should resolve to an array)
|
|
230
|
+
* @param options - Configuration options:
|
|
231
|
+
* - `as` - Rename the association key in the serialized output
|
|
232
|
+
*
|
|
233
|
+
* For Dream associations:
|
|
234
|
+
* - `dreamClass` - The Dream model class, enabling serializer inference; when specified,
|
|
235
|
+
* `serializerKey` may also be provided to select a specific registered serializer
|
|
236
|
+
* - `serializer` - Provide an explicit serializer function
|
|
237
|
+
*
|
|
238
|
+
* For ViewModel associations:
|
|
239
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
240
|
+
* - `serializer`
|
|
241
|
+
*
|
|
242
|
+
* For non-Dream/non-ViewModel associations:
|
|
243
|
+
* - `serializer` is required
|
|
158
244
|
* @returns The serializer builder for method chaining
|
|
159
245
|
*
|
|
160
246
|
* @example
|
|
161
247
|
* ```typescript
|
|
162
248
|
* // With explicit serializer function
|
|
163
|
-
* .rendersMany('articles', ArticleSerializer
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
249
|
+
* .rendersMany('articles', { serializer: ArticleSerializer })
|
|
250
|
+
*
|
|
251
|
+
* // With Dream class reference and serializer key
|
|
252
|
+
* .rendersMany('posts', {
|
|
253
|
+
* dreamClass: Post,
|
|
254
|
+
* serializerKey: 'summary'
|
|
168
255
|
* })
|
|
169
256
|
*
|
|
170
257
|
* // With ViewModel class reference
|
|
171
258
|
* .rendersMany('comments', {
|
|
172
259
|
* viewModelClass: CommentViewModel,
|
|
173
|
-
* serializer: CommentViewModelSerializer
|
|
174
|
-
* openapi: {
|
|
175
|
-
* type: 'array',
|
|
176
|
-
* items: { $ref: '#/components/schemas/Comment' }
|
|
177
|
-
* }
|
|
260
|
+
* serializer: CommentViewModelSerializer
|
|
178
261
|
* })
|
|
179
|
-
* ```
|
|
180
262
|
*
|
|
181
|
-
*
|
|
263
|
+
* // Rename output key
|
|
264
|
+
* .rendersMany('articles', { serializer: ArticleSerializer, as: 'posts' })
|
|
265
|
+
* ```
|
|
182
266
|
*/
|
|
183
267
|
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 ? {
|
|
184
268
|
dreamClass: typeof Dream;
|
|
@@ -198,13 +282,13 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
198
282
|
/**
|
|
199
283
|
* Executes the serializer and returns the serialized output.
|
|
200
284
|
*
|
|
201
|
-
*
|
|
202
|
-
* and associations to produce the final serialized object.
|
|
203
|
-
* JSON.stringify() and API responses.
|
|
285
|
+
* Processes all defined attributes, custom attributes, delegated attributes,
|
|
286
|
+
* and associations to produce the final serialized object.
|
|
204
287
|
*
|
|
205
288
|
* @param passthrough - Additional data to pass through to nested serializers
|
|
289
|
+
* (e.g., locale, current user context)
|
|
206
290
|
* @param opts - Rendering options for customizing the serialization process
|
|
207
|
-
* @returns The serialized object
|
|
291
|
+
* @returns The serialized object, suitable for JSON responses
|
|
208
292
|
*
|
|
209
293
|
* @example
|
|
210
294
|
* ```typescript
|
|
@@ -214,8 +298,6 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
214
298
|
* // With passthrough data for nested serializers
|
|
215
299
|
* const result = UserViewModelSerializer(userVm).render({ currentUserId: '456' })
|
|
216
300
|
* ```
|
|
217
|
-
*
|
|
218
|
-
* See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
|
|
219
301
|
*/
|
|
220
302
|
render(passthrough?: any, opts?: SerializerRendererOpts): Record<string, any> | null;
|
|
221
303
|
}
|
|
@@ -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';
|
|
@@ -399,9 +399,26 @@ interface HasOptionsBase<
|
|
|
399
399
|
AssociationGlobalName & keyof GlobalModelNameTableMap<BaseInstance>
|
|
400
400
|
>,
|
|
401
401
|
> {
|
|
402
|
+
/**
|
|
403
|
+
* If `'destroy'`, associated records will be cascade-deleted when the base model is destroyed.
|
|
404
|
+
*/
|
|
402
405
|
dependent?: DependentOptions
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* A custom column on the associated model to use as the foreign key for this association,
|
|
409
|
+
* overriding the default convention-based foreign key.
|
|
410
|
+
*/
|
|
403
411
|
on?: TableColumnNames<BaseInstance['DB'], AssociationTableName & keyof BaseInstance['DB']>
|
|
404
412
|
|
|
413
|
+
/**
|
|
414
|
+
* A where clause applied whenever this association is loaded, scoping the association
|
|
415
|
+
* to only records matching the given conditions.
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* @deco.HasMany('Collar', { and: { lost: false } })
|
|
419
|
+
* public currentCollars: Collar[]
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
405
422
|
and?: OnStatementForAssociationDefinition<
|
|
406
423
|
BaseInstance['DB'],
|
|
407
424
|
BaseInstance['schema'],
|
|
@@ -410,6 +427,15 @@ interface HasOptionsBase<
|
|
|
410
427
|
keyof BaseInstance['DB']
|
|
411
428
|
>
|
|
412
429
|
|
|
430
|
+
/**
|
|
431
|
+
* A negated where clause applied whenever this association is loaded, excluding
|
|
432
|
+
* records matching the given conditions.
|
|
433
|
+
*
|
|
434
|
+
* ```ts
|
|
435
|
+
* @deco.HasOne('Collar', { andNot: { lost: true } })
|
|
436
|
+
* public notLostCollar: Collar
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
413
439
|
andNot?: InternalWhereStatement<
|
|
414
440
|
BaseInstance,
|
|
415
441
|
BaseInstance['DB'],
|
|
@@ -419,6 +445,15 @@ interface HasOptionsBase<
|
|
|
419
445
|
keyof BaseInstance['DB']
|
|
420
446
|
>
|
|
421
447
|
|
|
448
|
+
/**
|
|
449
|
+
* An array of where clauses combined with OR logic, applied whenever this association
|
|
450
|
+
* is loaded. At least one of the clauses must match.
|
|
451
|
+
*
|
|
452
|
+
* ```ts
|
|
453
|
+
* @deco.HasMany('Balloon', { andAny: [{ color: 'red' }, { color: 'blue' }] })
|
|
454
|
+
* public redOrBlueBalloons: Balloon[]
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
422
457
|
andAny?: InternalWhereStatement<
|
|
423
458
|
BaseInstance,
|
|
424
459
|
BaseInstance['DB'],
|
|
@@ -428,9 +463,27 @@ interface HasOptionsBase<
|
|
|
428
463
|
keyof BaseInstance['DB']
|
|
429
464
|
>[]
|
|
430
465
|
|
|
466
|
+
/**
|
|
467
|
+
* Marks this as a polymorphic association, where the foreign key and a type column
|
|
468
|
+
* together identify the associated record across multiple tables.
|
|
469
|
+
*/
|
|
431
470
|
polymorphic?: boolean
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* A custom column on this model to use as the primary key for this association,
|
|
474
|
+
* instead of the default primary key (e.g., `'uuid'` instead of `'id'`).
|
|
475
|
+
*/
|
|
432
476
|
primaryKeyOverride?: DreamColumnNames<BaseInstance> | null
|
|
433
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Adds a join condition between a column on the associated model and a column on this model,
|
|
480
|
+
* so the association is scoped by matching column values across both models.
|
|
481
|
+
*
|
|
482
|
+
* ```ts
|
|
483
|
+
* @deco.HasMany('Post', { selfAnd: { species: 'targetSpecies' } })
|
|
484
|
+
* public postsMatchingSpecies: Post[]
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
434
487
|
selfAnd?: SelfOnStatement<
|
|
435
488
|
BaseInstance,
|
|
436
489
|
BaseInstance['DB'],
|
|
@@ -440,6 +493,10 @@ interface HasOptionsBase<
|
|
|
440
493
|
keyof BaseInstance['DB']
|
|
441
494
|
>
|
|
442
495
|
|
|
496
|
+
/**
|
|
497
|
+
* Adds a negated join condition between a column on the associated model and a column
|
|
498
|
+
* on this model, excluding records where the columns match.
|
|
499
|
+
*/
|
|
443
500
|
selfAndNot?: SelfOnStatement<
|
|
444
501
|
BaseInstance,
|
|
445
502
|
BaseInstance['DB'],
|
|
@@ -449,9 +506,26 @@ interface HasOptionsBase<
|
|
|
449
506
|
keyof BaseInstance['DB']
|
|
450
507
|
>
|
|
451
508
|
|
|
509
|
+
/**
|
|
510
|
+
* Used in conjunction with `through` to specify which association on the intermediate model
|
|
511
|
+
* should be used to reach the target model.
|
|
512
|
+
*/
|
|
452
513
|
source?: keyof BaseInstance['schema'][ForeignTableName]['associations']
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Loads this association through an intermediate association, similar to a SQL join
|
|
517
|
+
* through a join table.
|
|
518
|
+
*
|
|
519
|
+
* ```ts
|
|
520
|
+
* @deco.HasMany('Rating', { through: 'posts' })
|
|
521
|
+
* public ratings: Rating[]
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
453
524
|
through?: ThroughAssociationName
|
|
454
525
|
|
|
526
|
+
/**
|
|
527
|
+
* A list of default scopes to bypass when loading this association.
|
|
528
|
+
*/
|
|
455
529
|
withoutDefaultScopes?: DefaultScopeNameForTable<
|
|
456
530
|
BaseInstance['schema'],
|
|
457
531
|
AssociationTableName & keyof BaseInstance['DB']
|