@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.
- package/dist/cjs/src/Dream.js +37 -66
- 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 +70 -9
- package/dist/cjs/src/dream/Query.js +5 -6
- package/dist/cjs/src/dream/constants.js +2 -0
- package/dist/cjs/src/dream/internal/buildAssociationPaths.js +33 -0
- package/dist/cjs/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
- package/dist/cjs/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
- package/dist/cjs/src/dream/internal/destroyAssociatedRecords.js +14 -6
- package/dist/cjs/src/dream/internal/destroyDream.js +7 -1
- package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +35 -0
- package/dist/cjs/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +1 -1
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +114 -52
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/cjs/src/types/recursiveSerialization.js +1 -0
- package/dist/esm/src/Dream.js +37 -66
- 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 +70 -9
- package/dist/esm/src/dream/Query.js +5 -6
- package/dist/esm/src/dream/constants.js +2 -0
- package/dist/esm/src/dream/internal/buildAssociationPaths.js +33 -0
- package/dist/esm/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
- package/dist/esm/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
- package/dist/esm/src/dream/internal/destroyAssociatedRecords.js +14 -6
- package/dist/esm/src/dream/internal/destroyDream.js +7 -1
- package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +35 -0
- package/dist/esm/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +1 -1
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +114 -52
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/esm/src/types/recursiveSerialization.js +1 -0
- 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 +63 -10
- package/dist/types/src/dream/Query.d.ts +1 -1
- package/dist/types/src/dream/constants.d.ts +2 -0
- package/dist/types/src/dream/internal/buildAssociationPaths.d.ts +12 -0
- package/dist/types/src/dream/internal/buildDependentDestroyPreloadPaths.d.ts +17 -0
- package/dist/types/src/dream/internal/buildSerializerPreloadPaths.d.ts +3 -0
- package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +1 -1
- package/dist/types/src/dream/internal/destroyAssociatedRecords.d.ts +5 -1
- package/dist/types/src/dream/internal/loadDependentDestroyTree.d.ts +17 -0
- package/dist/types/src/dream/internal/resolveSerializerAssociationEdges.d.ts +13 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +164 -63
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +126 -43
- 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/dist/types/src/types/recursiveSerialization.d.ts +8 -0
- package/dist/types/src/types/recursiveSerialization.ts +10 -0
- package/dist/types/src/types/serializer.d.ts +8 -1
- package/dist/types/src/types/serializer.ts +8 -1
- 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 +177 -59
- package/docs/classes/system.ObjectSerializerBuilder.html +110 -34
- 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
- package/dist/cjs/src/dream/internal/extractNestedPaths.js +0 -34
- package/dist/esm/src/dream/internal/extractNestedPaths.js +0 -34
- package/dist/types/src/dream/internal/extractNestedPaths.d.ts +0 -21
|
@@ -2,6 +2,7 @@ import Dream from '../../Dream.js';
|
|
|
2
2
|
import { DreamOrViewModelSerializerKey, DreamVirtualColumns, NonJsonDreamColumnNames, ViewModel, ViewModelClass } from '../../types/dream.js';
|
|
3
3
|
import { AutomaticSerializerAttributeOptions, AutomaticSerializerAttributeOptionsForType, InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerAttributeOptionsForVirtualColumn, SerializerType } from '../../types/serializer.js';
|
|
4
4
|
import { SerializerRendererOpts } from '../SerializerRenderer.js';
|
|
5
|
+
export type DreamPropertiesToExclude = keyof Dream | 'serializers';
|
|
5
6
|
export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dream, MaybeNullDataType extends Dream | null, PassthroughDataType = any, DataType extends Exclude<MaybeNullDataType, null> = Exclude<MaybeNullDataType, null>> {
|
|
6
7
|
protected $typeForOpenapi: DataTypeForOpenapi;
|
|
7
8
|
protected data: MaybeNullDataType;
|
|
@@ -11,11 +12,23 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
11
12
|
/**
|
|
12
13
|
* Includes an attribute from the data object in the serialized output.
|
|
13
14
|
*
|
|
14
|
-
* For DreamSerializer, OpenAPI types
|
|
15
|
-
* For json
|
|
15
|
+
* For DreamSerializer, OpenAPI types are automatically inferred from database columns.
|
|
16
|
+
* For json/jsonb columns and virtual attributes (getters), the `openapi` option is required.
|
|
16
17
|
*
|
|
17
18
|
* @param name - The attribute name from the data object
|
|
18
|
-
* @param options - Configuration options
|
|
19
|
+
* @param options - Configuration options:
|
|
20
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
21
|
+
* - `default` - Value to use when the attribute is undefined (not available for `type` columns)
|
|
22
|
+
* - `openapi` - OpenAPI schema definition; required for json/jsonb columns and non-virtual
|
|
23
|
+
* getters, optional for standard columns (where it can supplement inferred types with a
|
|
24
|
+
* `description`), and optional for `@deco.Virtual()` columns (where the type is inferred
|
|
25
|
+
* from the decorator)
|
|
26
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
27
|
+
* during rendering; does not affect the OpenAPI shape (not available for `type` or
|
|
28
|
+
* virtual columns)
|
|
29
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
30
|
+
* when omitted, attributes are required by default, meaning `undefined` values will
|
|
31
|
+
* serialize as `null` (not available for `type` columns)
|
|
19
32
|
* @returns The serializer builder for method chaining
|
|
20
33
|
*
|
|
21
34
|
* @example
|
|
@@ -23,51 +36,79 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
23
36
|
* // With type inference (database column)
|
|
24
37
|
* .attribute('email')
|
|
25
38
|
*
|
|
26
|
-
* // With explicit OpenAPI type (virtual attribute)
|
|
39
|
+
* // With explicit OpenAPI type (virtual attribute or json column)
|
|
27
40
|
* .attribute('fullName', { openapi: { type: 'string' } })
|
|
28
41
|
*
|
|
29
42
|
* // With default value
|
|
30
|
-
* .attribute('status', { default: '
|
|
43
|
+
* .attribute('status', { default: 'pending' })
|
|
31
44
|
*
|
|
32
45
|
* // Rename output key
|
|
33
46
|
* .attribute('email', { as: 'userEmail' })
|
|
34
|
-
* ```
|
|
35
47
|
*
|
|
36
|
-
*
|
|
48
|
+
* // Round decimal to 2 places
|
|
49
|
+
* .attribute('price', { precision: 2 })
|
|
50
|
+
*
|
|
51
|
+
* // Mark as optional in OpenAPI (omitted from response when undefined)
|
|
52
|
+
* .attribute('deletedAt', { required: false })
|
|
53
|
+
* ```
|
|
37
54
|
*/
|
|
38
55
|
attribute(name: NonJsonDreamColumnNames<DataType> & keyof DataType & 'type', options?: AutomaticSerializerAttributeOptionsForType): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
39
56
|
attribute(name: DreamVirtualColumns<DataType>[number], options?: SerializerAttributeOptionsForVirtualColumn): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
40
|
-
attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType,
|
|
57
|
+
attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType, DreamPropertiesToExclude> & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
41
58
|
attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string>(name: AttributeName, options?: AutomaticSerializerAttributeOptions): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
42
59
|
/**
|
|
43
60
|
* Includes an attribute from a nested object in the serialized output.
|
|
44
61
|
*
|
|
45
|
-
*
|
|
46
|
-
* the delegated attribute is null/undefined, the `default` option value
|
|
62
|
+
* Accesses `targetName.name` on the data object. If the target object
|
|
63
|
+
* or the delegated attribute is null/undefined, the `default` option value
|
|
47
64
|
* will be used if provided.
|
|
48
65
|
*
|
|
49
|
-
*
|
|
66
|
+
* When the target is a Dream model, OpenAPI types may be automatically inferred
|
|
67
|
+
* for standard database columns. For json/jsonb columns or non-Dream targets,
|
|
68
|
+
* the `openapi` option is required.
|
|
69
|
+
*
|
|
70
|
+
* @param targetName - The property name containing the target object (e.g., an association name)
|
|
50
71
|
* @param name - The attribute name within the target object
|
|
51
|
-
* @param options - Configuration options
|
|
72
|
+
* @param options - Configuration options:
|
|
73
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
74
|
+
* (e.g., delegating `'user', 'email'` with `as: 'userEmail'` outputs the value
|
|
75
|
+
* under `userEmail`)
|
|
76
|
+
* - `default` - Value to use when the target object or its attribute is null/undefined
|
|
77
|
+
* - `openapi` - OpenAPI schema definition; required for non-Dream targets and json/jsonb
|
|
78
|
+
* columns, optional for standard Dream columns (where types are inferred)
|
|
79
|
+
* - `optional` - Set to `true` to indicate the value can be null in the OpenAPI schema
|
|
80
|
+
* (wraps the type in `anyOf: [schema, { type: 'null' }]`). For Dream models, this is
|
|
81
|
+
* auto-inferred from optional BelongsTo associations. Use this when delegating through
|
|
82
|
+
* a HasOne or other nullable association.
|
|
83
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
84
|
+
* during rendering; does not affect the OpenAPI shape
|
|
85
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
86
|
+
* when omitted, attributes are required by default
|
|
52
87
|
* @returns The serializer builder for method chaining
|
|
53
88
|
*
|
|
54
89
|
* @example
|
|
55
90
|
* ```typescript
|
|
56
|
-
* // Delegate to
|
|
57
|
-
* .delegatedAttribute('
|
|
58
|
-
* openapi: { type: 'string', format: 'email' }
|
|
59
|
-
* })
|
|
91
|
+
* // Delegate to a Dream association's column (type inferred)
|
|
92
|
+
* .delegatedAttribute('currentLocalizedText', 'title', { openapi: 'string' })
|
|
60
93
|
*
|
|
61
94
|
* // With default value for null target or attribute
|
|
62
95
|
* .delegatedAttribute('user', 'displayName', {
|
|
63
96
|
* openapi: { type: 'string' },
|
|
64
97
|
* default: 'Unknown User'
|
|
65
98
|
* })
|
|
66
|
-
* ```
|
|
67
99
|
*
|
|
68
|
-
*
|
|
100
|
+
* // Rename the output key
|
|
101
|
+
* .delegatedAttribute('profile', 'avatarUrl', {
|
|
102
|
+
* openapi: 'string',
|
|
103
|
+
* as: 'avatar'
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
69
106
|
*/
|
|
70
|
-
delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType,
|
|
107
|
+
delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, DreamPropertiesToExclude> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, DreamPropertiesToExclude> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType & {
|
|
108
|
+
optional?: boolean;
|
|
109
|
+
} : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & string ? (AutomaticSerializerAttributeOptions & {
|
|
110
|
+
optional?: boolean;
|
|
111
|
+
}) | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
|
|
71
112
|
/**
|
|
72
113
|
* Includes a computed value in the serialized output.
|
|
73
114
|
*
|
|
@@ -76,7 +117,17 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
76
117
|
*
|
|
77
118
|
* @param name - The attribute name for the computed value
|
|
78
119
|
* @param fn - Callback function that returns the computed value
|
|
79
|
-
* @param options - Configuration options
|
|
120
|
+
* @param options - Configuration options:
|
|
121
|
+
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
122
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
123
|
+
* - `default` - Value to use when the callback returns undefined
|
|
124
|
+
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
125
|
+
* parent serialized output instead of nesting them under `name`; the `openapi` option
|
|
126
|
+
* should then define each flattened property individually
|
|
127
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
128
|
+
* during rendering; does not affect the OpenAPI shape
|
|
129
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
130
|
+
* when omitted, attributes are required by default
|
|
80
131
|
* @returns The serializer builder for method chaining
|
|
81
132
|
*
|
|
82
133
|
* @example
|
|
@@ -88,16 +139,20 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
88
139
|
* )
|
|
89
140
|
*
|
|
90
141
|
* // Flattened object properties
|
|
91
|
-
* .customAttribute('
|
|
142
|
+
* .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
|
|
92
143
|
* flatten: true,
|
|
93
144
|
* openapi: {
|
|
94
|
-
*
|
|
95
|
-
*
|
|
145
|
+
* lat: { type: 'number' },
|
|
146
|
+
* lng: { type: 'number' }
|
|
96
147
|
* }
|
|
97
148
|
* })
|
|
98
|
-
* ```
|
|
99
149
|
*
|
|
100
|
-
*
|
|
150
|
+
* // With decimal precision
|
|
151
|
+
* .customAttribute('averageRating', () => calculateAverage(ratings), {
|
|
152
|
+
* openapi: 'decimal',
|
|
153
|
+
* precision: 2
|
|
154
|
+
* })
|
|
155
|
+
* ```
|
|
101
156
|
*/
|
|
102
157
|
customAttribute(name: string, fn: () => unknown, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
103
158
|
flatten?: boolean;
|
|
@@ -105,30 +160,52 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
105
160
|
/**
|
|
106
161
|
* Includes a single associated object in the serialized output.
|
|
107
162
|
*
|
|
108
|
-
* When rendering a Dream association, the OpenAPI shape
|
|
109
|
-
* inferred from that associated Dream's
|
|
163
|
+
* When rendering a Dream association, the serializer and OpenAPI shape are automatically
|
|
164
|
+
* inferred from that associated Dream model's registered serializers.
|
|
110
165
|
*
|
|
111
166
|
* @param name - The association property name
|
|
112
|
-
* @param options - Configuration options
|
|
167
|
+
* @param options - Configuration options:
|
|
168
|
+
* - `as` - Rename the association key in the serialized output
|
|
169
|
+
* - `flatten` - When `true`, spreads the rendered association's attributes directly into
|
|
170
|
+
* the parent serialized output instead of nesting them under `name`. Be aware of
|
|
171
|
+
* attribute shadowing: if the parent and flattened association share attribute names
|
|
172
|
+
* (e.g., `id`), the flattened association's values overwrite the parent's
|
|
173
|
+
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
174
|
+
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
175
|
+
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|
|
176
|
+
* `@deco.BelongsTo`). Set this to `true` when the association is genuinely nullable
|
|
177
|
+
* - `serializerKey` - Use a specific serializer key from the associated Dream model's
|
|
178
|
+
* registered serializers (e.g., `'summary'`)
|
|
179
|
+
* - `serializer` - Provide an explicit serializer function instead of using the
|
|
180
|
+
* associated model's registered serializers
|
|
181
|
+
*
|
|
182
|
+
* For ViewModel associations, one of these is required:
|
|
183
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
184
|
+
* - `serializer`
|
|
185
|
+
*
|
|
186
|
+
* For non-Dream/non-ViewModel associations:
|
|
187
|
+
* - `serializer` is required
|
|
113
188
|
* @returns The serializer builder for method chaining
|
|
114
189
|
*
|
|
115
190
|
* @example
|
|
116
191
|
* ```typescript
|
|
117
|
-
* //
|
|
118
|
-
* .rendersOne('
|
|
192
|
+
* // Auto-infer serializer from Dream association
|
|
193
|
+
* .rendersOne('profile')
|
|
119
194
|
*
|
|
120
|
-
* // With specific serializer
|
|
195
|
+
* // With specific serializer key
|
|
121
196
|
* .rendersOne('user', { serializerKey: 'summary' })
|
|
122
197
|
*
|
|
123
|
-
* //
|
|
124
|
-
* .rendersOne('
|
|
125
|
-
* openapi: { $ref: '#/components/schemas/User' }
|
|
126
|
-
* })
|
|
127
|
-
* ```
|
|
198
|
+
* // Allow null association
|
|
199
|
+
* .rendersOne('approver', { optional: true })
|
|
128
200
|
*
|
|
129
|
-
*
|
|
201
|
+
* // Flatten into parent object
|
|
202
|
+
* .rendersOne('candidate', { serializerKey: 'summary', flatten: true })
|
|
203
|
+
*
|
|
204
|
+
* // Explicit serializer function
|
|
205
|
+
* .rendersOne('owner', { serializer: CustomOwnerSerializer })
|
|
206
|
+
* ```
|
|
130
207
|
*/
|
|
131
|
-
rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType,
|
|
208
|
+
rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[AttributeName], null>, SerializerOptions = AssociatedModelType extends Dream ? {
|
|
132
209
|
serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
|
|
133
210
|
} | {
|
|
134
211
|
serializer?: SerializerType;
|
|
@@ -140,40 +217,66 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
140
217
|
} : {
|
|
141
218
|
serializer: SerializerType;
|
|
142
219
|
}, BaseOptions = {
|
|
220
|
+
/**
|
|
221
|
+
* Rename the association key in the serialized output.
|
|
222
|
+
*/
|
|
143
223
|
as?: string;
|
|
224
|
+
/**
|
|
225
|
+
* If `true`, the rendered association's attributes are merged directly into
|
|
226
|
+
* the parent object instead of being nested under the association key.
|
|
227
|
+
*/
|
|
144
228
|
flatten?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* If `true`, the association is treated as nullable in the OpenAPI spec,
|
|
231
|
+
* allowing `null` when the association doesn't resolve. By default,
|
|
232
|
+
* `rendersOne` expects the association to be present. Set this to `true`
|
|
233
|
+
* for associations that may not exist, such as passthrough-conditional
|
|
234
|
+
* HasOne associations.
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* .rendersOne('currentUserFavorite', { optional: true })
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
145
240
|
optional?: boolean;
|
|
146
241
|
}>(name: AttributeName, options?: BaseOptions & SerializerOptions): this;
|
|
147
242
|
/**
|
|
148
243
|
* Includes an array of associated objects in the serialized output.
|
|
149
244
|
*
|
|
150
|
-
* When rendering a Dream association, the OpenAPI shape
|
|
151
|
-
* inferred from that associated Dream's
|
|
245
|
+
* When rendering a Dream association, the serializer and OpenAPI shape are automatically
|
|
246
|
+
* inferred from that associated Dream model's registered serializers.
|
|
152
247
|
*
|
|
153
|
-
* @param name - The association property name (should
|
|
154
|
-
* @param options - Configuration options
|
|
248
|
+
* @param name - The association property name (should resolve to an array)
|
|
249
|
+
* @param options - Configuration options:
|
|
250
|
+
* - `as` - Rename the association key in the serialized output
|
|
251
|
+
* - `serializerKey` - Use a specific serializer key from the associated Dream model's
|
|
252
|
+
* registered serializers (e.g., `'summary'`)
|
|
253
|
+
* - `serializer` - Provide an explicit serializer function instead of using the
|
|
254
|
+
* associated model's registered serializers
|
|
255
|
+
*
|
|
256
|
+
* For ViewModel associations, one of these is required:
|
|
257
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
258
|
+
* - `serializer`
|
|
259
|
+
*
|
|
260
|
+
* For non-Dream/non-ViewModel associations:
|
|
261
|
+
* - `serializer` is required
|
|
155
262
|
* @returns The serializer builder for method chaining
|
|
156
263
|
*
|
|
157
264
|
* @example
|
|
158
265
|
* ```typescript
|
|
159
|
-
* //
|
|
160
|
-
* .rendersMany('
|
|
266
|
+
* // Auto-infer serializer from Dream association
|
|
267
|
+
* .rendersMany('rooms')
|
|
161
268
|
*
|
|
162
|
-
* // With specific serializer
|
|
163
|
-
* .rendersMany('
|
|
269
|
+
* // With specific serializer key
|
|
270
|
+
* .rendersMany('rooms', { serializerKey: 'summary' })
|
|
164
271
|
*
|
|
165
|
-
* //
|
|
166
|
-
* .rendersMany('
|
|
167
|
-
* openapi: {
|
|
168
|
-
* type: 'array',
|
|
169
|
-
* items: { $ref: '#/components/schemas/Article' }
|
|
170
|
-
* }
|
|
171
|
-
* })
|
|
172
|
-
* ```
|
|
272
|
+
* // Explicit serializer function (for non-Dream objects)
|
|
273
|
+
* .rendersMany('bedTypes', { serializer: BedTypeSerializer })
|
|
173
274
|
*
|
|
174
|
-
*
|
|
275
|
+
* // Rename output key
|
|
276
|
+
* .rendersMany('rooms', { serializerKey: 'forGuests', as: 'guestRooms' })
|
|
277
|
+
* ```
|
|
175
278
|
*/
|
|
176
|
-
rendersMany<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType,
|
|
279
|
+
rendersMany<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, DreamPropertiesToExclude>, ActualDataType extends ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType = ProvidedModelType extends undefined ? InstanceType<DataTypeForOpenapi> : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, DreamPropertiesToExclude> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = ActualDataType[AttributeName] extends (Dream | ViewModel)[] ? ActualDataType[AttributeName] extends (infer U)[] ? U : object : object, SerializerOptions = AssociatedModelType extends Dream ? {
|
|
177
280
|
serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
|
|
178
281
|
} | {
|
|
179
282
|
serializer?: SerializerType;
|
|
@@ -190,24 +293,22 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
190
293
|
/**
|
|
191
294
|
* Executes the serializer and returns the serialized output.
|
|
192
295
|
*
|
|
193
|
-
*
|
|
194
|
-
* and associations to produce the final serialized object.
|
|
195
|
-
* JSON.stringify() and API responses.
|
|
296
|
+
* Processes all defined attributes, custom attributes, delegated attributes,
|
|
297
|
+
* and associations to produce the final serialized object.
|
|
196
298
|
*
|
|
197
299
|
* @param passthrough - Additional data to pass through to nested serializers
|
|
300
|
+
* (e.g., locale, current user context)
|
|
198
301
|
* @param opts - Rendering options for customizing the serialization process
|
|
199
|
-
* @returns The serialized object
|
|
302
|
+
* @returns The serialized object, suitable for JSON responses
|
|
200
303
|
*
|
|
201
304
|
* @example
|
|
202
305
|
* ```typescript
|
|
203
306
|
* const result = UserSerializer(user).render()
|
|
204
307
|
* // Returns: { id: 1, email: 'user@example.com', ... }
|
|
205
308
|
*
|
|
206
|
-
* // With passthrough data
|
|
309
|
+
* // With passthrough data for nested serializers
|
|
207
310
|
* const result = UserSerializer(user).render({ currentUserId: 123 })
|
|
208
311
|
* ```
|
|
209
|
-
*
|
|
210
|
-
* See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
|
|
211
312
|
*/
|
|
212
313
|
render(passthrough?: any, opts?: SerializerRendererOpts): Record<string, any> | null;
|
|
213
314
|
}
|