@rvoh/dream 2.5.7 → 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/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/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
|
@@ -8,13 +8,16 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
|
8
8
|
private dream;
|
|
9
9
|
private query;
|
|
10
10
|
/**
|
|
11
|
-
* An intermediate
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* An intermediate builder for loading associations onto a Dream model
|
|
12
|
+
* via a single left-join SQL query. Accessed via `#leftJoinLoad`.
|
|
13
|
+
*
|
|
14
|
+
* **Note:** The LeftJoinLoadBuilder works on a clone of the original model.
|
|
15
|
+
* Call `.execute()` to get the clone with associations loaded.
|
|
14
16
|
*
|
|
15
17
|
* ```ts
|
|
16
18
|
* const user = await User.firstOrFail()
|
|
17
|
-
* await user.
|
|
19
|
+
* const loaded = await user.leftJoinLoad('settings').execute()
|
|
20
|
+
* loaded.settings // association is loaded on the returned clone
|
|
18
21
|
* ```
|
|
19
22
|
*/
|
|
20
23
|
constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
|
|
@@ -32,17 +35,20 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
|
32
35
|
*/
|
|
33
36
|
leftJoinLoad<I extends LeftJoinLoadBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[], const LastArg extends VariadicLeftJoinLoadArgs<DreamInstance, DB, Schema, TableName, Arr>>(this: I, ...args: [...Arr, LastArg]): I;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
* all associations
|
|
37
|
-
* instances.
|
|
38
|
+
* Executes the left-join load query, returning a **clone** of the original model
|
|
39
|
+
* with all requested associations loaded. The original instance is not modified.
|
|
38
40
|
*
|
|
39
41
|
* ```ts
|
|
40
42
|
* const user = await User.firstOrFail()
|
|
41
|
-
* await user
|
|
42
|
-
* .
|
|
43
|
-
* .
|
|
43
|
+
* const loaded = await user
|
|
44
|
+
* .leftJoinLoad('settings')
|
|
45
|
+
* .leftJoinLoad('posts', 'comments', 'replies')
|
|
44
46
|
* .execute()
|
|
47
|
+
*
|
|
48
|
+
* loaded.settings // works — associations are on the returned clone
|
|
45
49
|
* ```
|
|
50
|
+
*
|
|
51
|
+
* @returns A clone of the Dream instance with all requested associations loaded
|
|
46
52
|
*/
|
|
47
53
|
execute(): Promise<DreamInstance>;
|
|
48
54
|
private associationToPreloadedDreamsAndWhatTheyPointTo;
|
|
@@ -9,13 +9,16 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
9
9
|
private dream;
|
|
10
10
|
private query;
|
|
11
11
|
/**
|
|
12
|
-
* An intermediate
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* An intermediate builder for loading associations onto a Dream model.
|
|
13
|
+
* Accessed via the `#load` method on a Dream instance.
|
|
14
|
+
*
|
|
15
|
+
* **Note:** The LoadBuilder works on a clone of the original model.
|
|
16
|
+
* Call `.execute()` to get the clone with associations loaded.
|
|
15
17
|
*
|
|
16
18
|
* ```ts
|
|
17
19
|
* const user = await User.firstOrFail()
|
|
18
|
-
* await user.load('settings').execute()
|
|
20
|
+
* const loaded = await user.load('settings').execute()
|
|
21
|
+
* loaded.settings // association is loaded on the returned clone
|
|
19
22
|
* ```
|
|
20
23
|
*/
|
|
21
24
|
constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
|
|
@@ -82,19 +85,22 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
82
85
|
*/
|
|
83
86
|
loadFor<I extends LoadBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): I;
|
|
84
87
|
/**
|
|
85
|
-
* Executes
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
+
* Executes the load query, binding all associations to a **clone** of the
|
|
89
|
+
* original model instance. The original instance is not modified.
|
|
90
|
+
*
|
|
91
|
+
* You must use the returned value to access the loaded associations:
|
|
88
92
|
*
|
|
89
93
|
* ```ts
|
|
90
94
|
* const user = await User.firstOrFail()
|
|
91
|
-
* await user
|
|
95
|
+
* const loaded = await user
|
|
92
96
|
* .load('settings')
|
|
93
97
|
* .load('posts', 'comments', 'replies', ['image', 'localizedText'])
|
|
94
98
|
* .execute()
|
|
99
|
+
*
|
|
100
|
+
* loaded.settings // works — associations are on the returned clone
|
|
95
101
|
* ```
|
|
96
102
|
*
|
|
97
|
-
* @returns
|
|
103
|
+
* @returns A clone of the Dream instance with all requested associations loaded
|
|
98
104
|
*/
|
|
99
105
|
execute(): Promise<DreamInstance>;
|
|
100
106
|
}
|
|
@@ -1146,7 +1146,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
1146
1146
|
* Updates all records matching the Query
|
|
1147
1147
|
*
|
|
1148
1148
|
* ```ts
|
|
1149
|
-
* await User.where({ email: ops.ilike('%burpcollaborator%') }).
|
|
1149
|
+
* await User.where({ email: ops.ilike('%burpcollaborator%') }).update({ email: null })
|
|
1150
1150
|
* // 12
|
|
1151
1151
|
* ```
|
|
1152
1152
|
* @param attributes - The attributes used to update the records
|
|
@@ -11,11 +11,23 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
11
11
|
/**
|
|
12
12
|
* Includes an attribute from the data object in the serialized output.
|
|
13
13
|
*
|
|
14
|
-
* For DreamSerializer, OpenAPI types
|
|
15
|
-
* For json
|
|
14
|
+
* For DreamSerializer, OpenAPI types are automatically inferred from database columns.
|
|
15
|
+
* For json/jsonb columns and virtual attributes (getters), the `openapi` option is required.
|
|
16
16
|
*
|
|
17
17
|
* @param name - The attribute name from the data object
|
|
18
|
-
* @param options - Configuration options
|
|
18
|
+
* @param options - Configuration options:
|
|
19
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
20
|
+
* - `default` - Value to use when the attribute is undefined (not available for `type` columns)
|
|
21
|
+
* - `openapi` - OpenAPI schema definition; required for json/jsonb columns and non-virtual
|
|
22
|
+
* getters, optional for standard columns (where it can supplement inferred types with a
|
|
23
|
+
* `description`), and optional for `@deco.Virtual()` columns (where the type is inferred
|
|
24
|
+
* from the decorator)
|
|
25
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
26
|
+
* during rendering; does not affect the OpenAPI shape (not available for `type` or
|
|
27
|
+
* virtual columns)
|
|
28
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
29
|
+
* when omitted, attributes are required by default, meaning `undefined` values will
|
|
30
|
+
* serialize as `null` (not available for `type` columns)
|
|
19
31
|
* @returns The serializer builder for method chaining
|
|
20
32
|
*
|
|
21
33
|
* @example
|
|
@@ -23,17 +35,21 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
23
35
|
* // With type inference (database column)
|
|
24
36
|
* .attribute('email')
|
|
25
37
|
*
|
|
26
|
-
* // With explicit OpenAPI type (virtual attribute)
|
|
38
|
+
* // With explicit OpenAPI type (virtual attribute or json column)
|
|
27
39
|
* .attribute('fullName', { openapi: { type: 'string' } })
|
|
28
40
|
*
|
|
29
41
|
* // With default value
|
|
30
|
-
* .attribute('status', { default: '
|
|
42
|
+
* .attribute('status', { default: 'pending' })
|
|
31
43
|
*
|
|
32
44
|
* // Rename output key
|
|
33
45
|
* .attribute('email', { as: 'userEmail' })
|
|
34
|
-
* ```
|
|
35
46
|
*
|
|
36
|
-
*
|
|
47
|
+
* // Round decimal to 2 places
|
|
48
|
+
* .attribute('price', { precision: 2 })
|
|
49
|
+
*
|
|
50
|
+
* // Mark as optional in OpenAPI (omitted from response when undefined)
|
|
51
|
+
* .attribute('deletedAt', { required: false })
|
|
52
|
+
* ```
|
|
37
53
|
*/
|
|
38
54
|
attribute(name: NonJsonDreamColumnNames<DataType> & keyof DataType & 'type', options?: AutomaticSerializerAttributeOptionsForType): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
39
55
|
attribute(name: DreamVirtualColumns<DataType>[number], options?: SerializerAttributeOptionsForVirtualColumn): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
@@ -42,30 +58,46 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
42
58
|
/**
|
|
43
59
|
* Includes an attribute from a nested object in the serialized output.
|
|
44
60
|
*
|
|
45
|
-
*
|
|
46
|
-
* the delegated attribute is null/undefined, the `default` option value
|
|
61
|
+
* Accesses `targetName.name` on the data object. If the target object
|
|
62
|
+
* or the delegated attribute is null/undefined, the `default` option value
|
|
47
63
|
* will be used if provided.
|
|
48
64
|
*
|
|
49
|
-
*
|
|
65
|
+
* When the target is a Dream model, OpenAPI types may be automatically inferred
|
|
66
|
+
* for standard database columns. For json/jsonb columns or non-Dream targets,
|
|
67
|
+
* the `openapi` option is required.
|
|
68
|
+
*
|
|
69
|
+
* @param targetName - The property name containing the target object (e.g., an association name)
|
|
50
70
|
* @param name - The attribute name within the target object
|
|
51
|
-
* @param options - Configuration options
|
|
71
|
+
* @param options - Configuration options:
|
|
72
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
73
|
+
* (e.g., delegating `'user', 'email'` with `as: 'userEmail'` outputs the value
|
|
74
|
+
* under `userEmail`)
|
|
75
|
+
* - `default` - Value to use when the target object or its attribute is null/undefined
|
|
76
|
+
* - `openapi` - OpenAPI schema definition; required for non-Dream targets and json/jsonb
|
|
77
|
+
* columns, optional for standard Dream columns (where types are inferred)
|
|
78
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
79
|
+
* during rendering; does not affect the OpenAPI shape
|
|
80
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
81
|
+
* when omitted, attributes are required by default
|
|
52
82
|
* @returns The serializer builder for method chaining
|
|
53
83
|
*
|
|
54
84
|
* @example
|
|
55
85
|
* ```typescript
|
|
56
|
-
* // Delegate to
|
|
57
|
-
* .delegatedAttribute('
|
|
58
|
-
* openapi: { type: 'string', format: 'email' }
|
|
59
|
-
* })
|
|
86
|
+
* // Delegate to a Dream association's column (type inferred)
|
|
87
|
+
* .delegatedAttribute('currentLocalizedText', 'title', { openapi: 'string' })
|
|
60
88
|
*
|
|
61
89
|
* // With default value for null target or attribute
|
|
62
90
|
* .delegatedAttribute('user', 'displayName', {
|
|
63
91
|
* openapi: { type: 'string' },
|
|
64
92
|
* default: 'Unknown User'
|
|
65
93
|
* })
|
|
66
|
-
* ```
|
|
67
94
|
*
|
|
68
|
-
*
|
|
95
|
+
* // Rename the output key
|
|
96
|
+
* .delegatedAttribute('profile', 'avatarUrl', {
|
|
97
|
+
* openapi: 'string',
|
|
98
|
+
* as: 'avatar'
|
|
99
|
+
* })
|
|
100
|
+
* ```
|
|
69
101
|
*/
|
|
70
102
|
delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends AssociatedModelType & keyof AssociatedModelType & string ? AutomaticSerializerAttributeOptions | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
|
|
71
103
|
/**
|
|
@@ -76,7 +108,17 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
76
108
|
*
|
|
77
109
|
* @param name - The attribute name for the computed value
|
|
78
110
|
* @param fn - Callback function that returns the computed value
|
|
79
|
-
* @param options - Configuration options
|
|
111
|
+
* @param options - Configuration options:
|
|
112
|
+
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
113
|
+
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
114
|
+
* - `default` - Value to use when the callback returns undefined
|
|
115
|
+
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
116
|
+
* parent serialized output instead of nesting them under `name`; the `openapi` option
|
|
117
|
+
* should then define each flattened property individually
|
|
118
|
+
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
119
|
+
* during rendering; does not affect the OpenAPI shape
|
|
120
|
+
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
121
|
+
* when omitted, attributes are required by default
|
|
80
122
|
* @returns The serializer builder for method chaining
|
|
81
123
|
*
|
|
82
124
|
* @example
|
|
@@ -88,16 +130,20 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
88
130
|
* )
|
|
89
131
|
*
|
|
90
132
|
* // Flattened object properties
|
|
91
|
-
* .customAttribute('
|
|
133
|
+
* .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
|
|
92
134
|
* flatten: true,
|
|
93
135
|
* openapi: {
|
|
94
|
-
*
|
|
95
|
-
*
|
|
136
|
+
* lat: { type: 'number' },
|
|
137
|
+
* lng: { type: 'number' }
|
|
96
138
|
* }
|
|
97
139
|
* })
|
|
98
|
-
* ```
|
|
99
140
|
*
|
|
100
|
-
*
|
|
141
|
+
* // With decimal precision
|
|
142
|
+
* .customAttribute('averageRating', () => calculateAverage(ratings), {
|
|
143
|
+
* openapi: 'decimal',
|
|
144
|
+
* precision: 2
|
|
145
|
+
* })
|
|
146
|
+
* ```
|
|
101
147
|
*/
|
|
102
148
|
customAttribute(name: string, fn: () => unknown, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
103
149
|
flatten?: boolean;
|
|
@@ -105,28 +151,50 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
105
151
|
/**
|
|
106
152
|
* Includes a single associated object in the serialized output.
|
|
107
153
|
*
|
|
108
|
-
* When rendering a Dream association, the OpenAPI shape
|
|
109
|
-
* inferred from that associated Dream's
|
|
154
|
+
* When rendering a Dream association, the serializer and OpenAPI shape are automatically
|
|
155
|
+
* inferred from that associated Dream model's registered serializers.
|
|
110
156
|
*
|
|
111
157
|
* @param name - The association property name
|
|
112
|
-
* @param options - Configuration options
|
|
158
|
+
* @param options - Configuration options:
|
|
159
|
+
* - `as` - Rename the association key in the serialized output
|
|
160
|
+
* - `flatten` - When `true`, spreads the rendered association's attributes directly into
|
|
161
|
+
* the parent serialized output instead of nesting them under `name`. Be aware of
|
|
162
|
+
* attribute shadowing: if the parent and flattened association share attribute names
|
|
163
|
+
* (e.g., `id`), the flattened association's values overwrite the parent's
|
|
164
|
+
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
165
|
+
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
166
|
+
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|
|
167
|
+
* `@deco.BelongsTo`). Set this to `true` when the association is genuinely nullable
|
|
168
|
+
* - `serializerKey` - Use a specific serializer key from the associated Dream model's
|
|
169
|
+
* registered serializers (e.g., `'summary'`)
|
|
170
|
+
* - `serializer` - Provide an explicit serializer function instead of using the
|
|
171
|
+
* associated model's registered serializers
|
|
172
|
+
*
|
|
173
|
+
* For ViewModel associations, one of these is required:
|
|
174
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
175
|
+
* - `serializer`
|
|
176
|
+
*
|
|
177
|
+
* For non-Dream/non-ViewModel associations:
|
|
178
|
+
* - `serializer` is required
|
|
113
179
|
* @returns The serializer builder for method chaining
|
|
114
180
|
*
|
|
115
181
|
* @example
|
|
116
182
|
* ```typescript
|
|
117
|
-
* //
|
|
118
|
-
* .rendersOne('
|
|
183
|
+
* // Auto-infer serializer from Dream association
|
|
184
|
+
* .rendersOne('profile')
|
|
119
185
|
*
|
|
120
|
-
* // With specific serializer
|
|
186
|
+
* // With specific serializer key
|
|
121
187
|
* .rendersOne('user', { serializerKey: 'summary' })
|
|
122
188
|
*
|
|
123
|
-
* //
|
|
124
|
-
* .rendersOne('
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
189
|
+
* // Allow null association
|
|
190
|
+
* .rendersOne('approver', { optional: true })
|
|
191
|
+
*
|
|
192
|
+
* // Flatten into parent object
|
|
193
|
+
* .rendersOne('candidate', { serializerKey: 'summary', flatten: true })
|
|
128
194
|
*
|
|
129
|
-
*
|
|
195
|
+
* // Explicit serializer function
|
|
196
|
+
* .rendersOne('owner', { serializer: CustomOwnerSerializer })
|
|
197
|
+
* ```
|
|
130
198
|
*/
|
|
131
199
|
rendersOne<ProvidedModelType = undefined, ProvidedAttributeName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, AttributeName extends ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType = ProvidedAttributeName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedAttributeName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[AttributeName], null>, SerializerOptions = AssociatedModelType extends Dream ? {
|
|
132
200
|
serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
|
|
@@ -140,38 +208,64 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
140
208
|
} : {
|
|
141
209
|
serializer: SerializerType;
|
|
142
210
|
}, BaseOptions = {
|
|
211
|
+
/**
|
|
212
|
+
* Rename the association key in the serialized output.
|
|
213
|
+
*/
|
|
143
214
|
as?: string;
|
|
215
|
+
/**
|
|
216
|
+
* If `true`, the rendered association's attributes are merged directly into
|
|
217
|
+
* the parent object instead of being nested under the association key.
|
|
218
|
+
*/
|
|
144
219
|
flatten?: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* If `true`, the association is treated as nullable in the OpenAPI spec,
|
|
222
|
+
* allowing `null` when the association doesn't resolve. By default,
|
|
223
|
+
* `rendersOne` expects the association to be present. Set this to `true`
|
|
224
|
+
* for associations that may not exist, such as passthrough-conditional
|
|
225
|
+
* HasOne associations.
|
|
226
|
+
*
|
|
227
|
+
* ```ts
|
|
228
|
+
* .rendersOne('currentUserFavorite', { optional: true })
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
145
231
|
optional?: boolean;
|
|
146
232
|
}>(name: AttributeName, options?: BaseOptions & SerializerOptions): this;
|
|
147
233
|
/**
|
|
148
234
|
* Includes an array of associated objects in the serialized output.
|
|
149
235
|
*
|
|
150
|
-
* When rendering a Dream association, the OpenAPI shape
|
|
151
|
-
* inferred from that associated Dream's
|
|
236
|
+
* When rendering a Dream association, the serializer and OpenAPI shape are automatically
|
|
237
|
+
* inferred from that associated Dream model's registered serializers.
|
|
152
238
|
*
|
|
153
|
-
* @param name - The association property name (should
|
|
154
|
-
* @param options - Configuration options
|
|
239
|
+
* @param name - The association property name (should resolve to an array)
|
|
240
|
+
* @param options - Configuration options:
|
|
241
|
+
* - `as` - Rename the association key in the serialized output
|
|
242
|
+
* - `serializerKey` - Use a specific serializer key from the associated Dream model's
|
|
243
|
+
* registered serializers (e.g., `'summary'`)
|
|
244
|
+
* - `serializer` - Provide an explicit serializer function instead of using the
|
|
245
|
+
* associated model's registered serializers
|
|
246
|
+
*
|
|
247
|
+
* For ViewModel associations, one of these is required:
|
|
248
|
+
* - `viewModelClass` + optional `serializerKey`
|
|
249
|
+
* - `serializer`
|
|
250
|
+
*
|
|
251
|
+
* For non-Dream/non-ViewModel associations:
|
|
252
|
+
* - `serializer` is required
|
|
155
253
|
* @returns The serializer builder for method chaining
|
|
156
254
|
*
|
|
157
255
|
* @example
|
|
158
256
|
* ```typescript
|
|
159
|
-
* //
|
|
160
|
-
* .rendersMany('
|
|
257
|
+
* // Auto-infer serializer from Dream association
|
|
258
|
+
* .rendersMany('rooms')
|
|
161
259
|
*
|
|
162
|
-
* // With specific serializer
|
|
163
|
-
* .rendersMany('
|
|
260
|
+
* // With specific serializer key
|
|
261
|
+
* .rendersMany('rooms', { serializerKey: 'summary' })
|
|
164
262
|
*
|
|
165
|
-
* //
|
|
166
|
-
* .rendersMany('
|
|
167
|
-
* openapi: {
|
|
168
|
-
* type: 'array',
|
|
169
|
-
* items: { $ref: '#/components/schemas/Article' }
|
|
170
|
-
* }
|
|
171
|
-
* })
|
|
172
|
-
* ```
|
|
263
|
+
* // Explicit serializer function (for non-Dream objects)
|
|
264
|
+
* .rendersMany('bedTypes', { serializer: BedTypeSerializer })
|
|
173
265
|
*
|
|
174
|
-
*
|
|
266
|
+
* // Rename output key
|
|
267
|
+
* .rendersMany('rooms', { serializerKey: 'forGuests', as: 'guestRooms' })
|
|
268
|
+
* ```
|
|
175
269
|
*/
|
|
176
270
|
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 ? {
|
|
177
271
|
serializerKey?: DreamOrViewModelSerializerKey<AssociatedModelType>;
|
|
@@ -190,24 +284,22 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
190
284
|
/**
|
|
191
285
|
* Executes the serializer and returns the serialized output.
|
|
192
286
|
*
|
|
193
|
-
*
|
|
194
|
-
* and associations to produce the final serialized object.
|
|
195
|
-
* JSON.stringify() and API responses.
|
|
287
|
+
* Processes all defined attributes, custom attributes, delegated attributes,
|
|
288
|
+
* and associations to produce the final serialized object.
|
|
196
289
|
*
|
|
197
290
|
* @param passthrough - Additional data to pass through to nested serializers
|
|
291
|
+
* (e.g., locale, current user context)
|
|
198
292
|
* @param opts - Rendering options for customizing the serialization process
|
|
199
|
-
* @returns The serialized object
|
|
293
|
+
* @returns The serialized object, suitable for JSON responses
|
|
200
294
|
*
|
|
201
295
|
* @example
|
|
202
296
|
* ```typescript
|
|
203
297
|
* const result = UserSerializer(user).render()
|
|
204
298
|
* // Returns: { id: 1, email: 'user@example.com', ... }
|
|
205
299
|
*
|
|
206
|
-
* // With passthrough data
|
|
300
|
+
* // With passthrough data for nested serializers
|
|
207
301
|
* const result = UserSerializer(user).render({ currentUserId: 123 })
|
|
208
302
|
* ```
|
|
209
|
-
*
|
|
210
|
-
* See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
|
|
211
303
|
*/
|
|
212
304
|
render(passthrough?: any, opts?: SerializerRendererOpts): Record<string, any> | null;
|
|
213
305
|
}
|