@rvoh/dream 2.35.0 → 2.36.1
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/README.md +2 -2
- package/dist/cjs/src/Dream.js +260 -55
- package/dist/cjs/src/bin/index.js +13 -0
- package/dist/cjs/src/cli/index.js +28 -17
- package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +23 -21
- package/dist/cjs/src/decorators/Decorators.js +26 -4
- package/dist/cjs/src/decorators/field/Encrypted.js +35 -6
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +6 -6
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +63 -27
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/cjs/src/dream/LoadBuilder.js +1 -1
- package/dist/cjs/src/dream/Query.js +542 -167
- package/dist/cjs/src/dream/QueryDriver/Base.js +72 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +216 -50
- package/dist/cjs/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.js +48 -0
- package/dist/cjs/src/dream/internal/associations/associationQuery.js +4 -0
- package/dist/cjs/src/dream/internal/reload.js +6 -1
- package/dist/cjs/src/dream/internal/saveDream.js +8 -2
- package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +2 -0
- package/dist/cjs/src/dream/internal/undestroyDream.js +1 -1
- package/dist/cjs/src/dream-app/index.js +38 -0
- package/dist/cjs/src/encrypt/InternalEncrypt.js +77 -4
- package/dist/cjs/src/encrypt/defaultEncryptedColumnName.js +10 -0
- package/dist/cjs/src/encrypt/index.js +76 -9
- package/dist/cjs/src/errors/DoNotSetEncryptedFieldsDirectly.js +4 -0
- package/dist/cjs/src/errors/associations/UnrecognizedAssociationConditionKeys.js +25 -0
- package/dist/cjs/src/helpers/Env.js +28 -0
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +9 -9
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +21 -8
- package/dist/cjs/src/serializer/SerializerRenderer.js +65 -13
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +54 -38
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +34 -14
- package/dist/cjs/src/serializer/helpers/serializersForAssociatedClass.js +43 -0
- package/dist/esm/src/Dream.js +260 -55
- package/dist/esm/src/bin/index.js +13 -0
- package/dist/esm/src/cli/index.js +28 -17
- package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +23 -21
- package/dist/esm/src/decorators/Decorators.js +26 -4
- package/dist/esm/src/decorators/field/Encrypted.js +35 -6
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +6 -6
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +63 -27
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/esm/src/dream/LoadBuilder.js +1 -1
- package/dist/esm/src/dream/Query.js +542 -167
- package/dist/esm/src/dream/QueryDriver/Base.js +72 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +216 -50
- package/dist/esm/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.js +48 -0
- package/dist/esm/src/dream/internal/associations/associationQuery.js +4 -0
- package/dist/esm/src/dream/internal/reload.js +6 -1
- package/dist/esm/src/dream/internal/saveDream.js +8 -2
- package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +2 -0
- package/dist/esm/src/dream/internal/undestroyDream.js +1 -1
- package/dist/esm/src/dream-app/index.js +38 -0
- package/dist/esm/src/encrypt/InternalEncrypt.js +77 -4
- package/dist/esm/src/encrypt/defaultEncryptedColumnName.js +10 -0
- package/dist/esm/src/encrypt/index.js +76 -9
- package/dist/esm/src/errors/DoNotSetEncryptedFieldsDirectly.js +4 -0
- package/dist/esm/src/errors/associations/UnrecognizedAssociationConditionKeys.js +25 -0
- package/dist/esm/src/helpers/Env.js +28 -0
- package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +9 -9
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +21 -8
- package/dist/esm/src/serializer/SerializerRenderer.js +65 -13
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +54 -38
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +34 -14
- package/dist/esm/src/serializer/helpers/serializersForAssociatedClass.js +43 -0
- package/dist/types/src/Dream.d.ts +208 -42
- package/dist/types/src/bin/index.d.ts +7 -1
- package/dist/types/src/cli/index.d.ts +13 -0
- package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +2 -2
- package/dist/types/src/decorators/Decorators.d.ts +26 -3
- package/dist/types/src/decorators/field/Encrypted.d.ts +6 -1
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +9 -9
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +52 -25
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +4 -4
- package/dist/types/src/dream/LoadBuilder.d.ts +1 -1
- package/dist/types/src/dream/Query.d.ts +272 -33
- package/dist/types/src/dream/QueryDriver/Base.d.ts +63 -1
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +85 -1
- package/dist/types/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.d.ts +29 -0
- package/dist/types/src/dream-app/index.d.ts +56 -2
- package/dist/types/src/encrypt/InternalEncrypt.d.ts +29 -1
- package/dist/types/src/encrypt/defaultEncryptedColumnName.d.ts +7 -0
- package/dist/types/src/encrypt/index.d.ts +75 -6
- package/dist/types/src/errors/associations/UnrecognizedAssociationConditionKeys.d.ts +8 -0
- package/dist/types/src/helpers/Env.d.ts +28 -0
- package/dist/types/src/package-exports/openapi.d.ts +1 -1
- package/dist/types/src/package-exports/types.d.ts +2 -2
- package/dist/types/src/serializer/SerializerRenderer.d.ts +13 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +59 -55
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +40 -19
- package/dist/types/src/serializer/helpers/serializersForAssociatedClass.d.ts +17 -0
- package/dist/types/src/types/lifecycle.d.ts +6 -0
- package/dist/types/src/types/openapi.d.ts +52 -29
- package/dist/types/src/types/serializer.d.ts +43 -2
- package/dist/types/src/types/types/lifecycle.ts +6 -0
- package/dist/types/src/types/types/openapi.ts +51 -37
- package/dist/types/src/types/types/serializer.ts +62 -2
- package/dist/types/src/types/types/variadic.ts +99 -43
- package/dist/types/src/types/variadic.d.ts +29 -3
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/highlight.css +4 -11
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +13 -13
- package/docs/classes/db.KyselyQueryDriver.html +85 -46
- package/docs/classes/db.PostgresQueryDriver.html +86 -47
- package/docs/classes/db.QueryDriverBase.html +84 -45
- package/docs/classes/errors.CannotSaveMissingDream.html +2 -2
- 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.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.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.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.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 +37 -23
- package/docs/classes/index.Dream.html +270 -142
- package/docs/classes/index.DreamApp.html +40 -10
- package/docs/classes/index.DreamTransaction.html +3 -3
- package/docs/classes/index.Env.html +16 -2
- package/docs/classes/index.Query.html +331 -129
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +6 -2
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +52 -34
- package/docs/classes/system.ObjectSerializerBuilder.html +41 -22
- package/docs/classes/system.PathHelpers.html +4 -4
- package/docs/classes/utils.Encrypt.html +54 -10
- 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/hierarchy.html +1 -1
- package/docs/index.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.DecryptCallbacks.html +6 -0
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +6 -6
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.EncryptionLegacyKeyUsedEvent.html +10 -0
- 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/modules/openapi.html +1 -1
- package/docs/modules/types.html +1 -1
- 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.OpenapiSchemaCombinatorFields.html +4 -0
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +5 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -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 +4 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +5 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +2 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.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 +1 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -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/serializer/helpers/serializerForAssociatedClass.js +0 -37
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +0 -37
- package/dist/types/src/serializer/helpers/serializerForAssociatedClass.d.ts +0 -9
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dream from '../../Dream.js';
|
|
2
2
|
import { DreamOrViewModelSerializerKey, DreamVirtualColumns, NonJsonDreamColumnNames, ViewModel, ViewModelClass } from '../../types/dream.js';
|
|
3
|
-
import { AutomaticSerializerAttributeOptions, AutomaticSerializerAttributeOptionsForType, InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerAttributeOptionsForVirtualColumn, SerializerType } from '../../types/serializer.js';
|
|
3
|
+
import { AutomaticSerializerAttributeOptions, AutomaticSerializerAttributeOptionsForType, CustomAttributeOptions, DelegatedAttributeOptionsArgs, InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerAttributeOptionsForVirtualColumn, SerializerType } from '../../types/serializer.js';
|
|
4
4
|
import { SerializerRendererOpts } from '../SerializerRenderer.js';
|
|
5
5
|
export type DreamPropertiesToExclude = keyof Dream | 'serializers';
|
|
6
6
|
export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dream, MaybeNullDataType extends Dream | null, PassthroughDataType = any, DataType extends Exclude<MaybeNullDataType, null> = Exclude<MaybeNullDataType, null>> {
|
|
@@ -54,7 +54,7 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
54
54
|
*/
|
|
55
55
|
attribute(name: NonJsonDreamColumnNames<DataType> & keyof DataType & 'type', options?: AutomaticSerializerAttributeOptionsForType): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
56
56
|
attribute(name: DreamVirtualColumns<DataType>[number], options?: SerializerAttributeOptionsForVirtualColumn): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
57
|
-
attribute<
|
|
57
|
+
attribute<AttributeName extends Exclude<keyof DataType & string, NonJsonDreamColumnNames<DataType> | DreamPropertiesToExclude>>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
58
58
|
attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string>(name: AttributeName, options?: AutomaticSerializerAttributeOptions): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
|
|
59
59
|
/**
|
|
60
60
|
* Includes an attribute from a nested object in the serialized output.
|
|
@@ -65,9 +65,10 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
65
65
|
* 2. `required: false` → omits the key entirely from the rendered output
|
|
66
66
|
* 3. otherwise → renders `null`
|
|
67
67
|
*
|
|
68
|
-
* When the target is a Dream model,
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* When the target is a Dream model, a non-json column's OpenAPI shape is inferred
|
|
69
|
+
* from the column, so its `openapi` option takes only a `description`. json/jsonb
|
|
70
|
+
* columns and non-Dream targets have no shape to infer, so they require a full
|
|
71
|
+
* `openapi` shape.
|
|
71
72
|
*
|
|
72
73
|
* `optional` and `required` are not aliases — they encode different things and can
|
|
73
74
|
* be used together:
|
|
@@ -91,12 +92,14 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
91
92
|
* a discriminator string when the association is actually missing produces a response
|
|
92
93
|
* indistinguishable from "association present with that type," which is misleading)
|
|
93
94
|
* - `openapi` - OpenAPI schema definition; required for non-Dream targets and json/jsonb
|
|
94
|
-
* columns
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
95
|
+
* columns. On a non-json Dream column, whose shape is inferred, it takes only a
|
|
96
|
+
* `description` (and, on the STI `type` column, a `type: 'string'` and `enum`)
|
|
97
|
+
* - `optional` - Set to `true` to mark the value as nullable in the OpenAPI schema:
|
|
98
|
+
* Psychic adds `null` to the rendered schema (e.g., `type: 'string'` becomes
|
|
99
|
+
* `type: ['string', 'null']`, and a `$ref` becomes `anyOf: [{ $ref }, { type: 'null' }]`).
|
|
100
|
+
* OpenAPI-only — the key is still rendered (as `null`). For Dream models, this is
|
|
101
|
+
* auto-inferred from optional BelongsTo associations. Use this when delegating
|
|
102
|
+
* through a HasOne or other nullable association.
|
|
100
103
|
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
101
104
|
* during rendering; does not affect the OpenAPI shape (not available when delegating
|
|
102
105
|
* to a `'type'` STI discriminator column, which is always a string enum)
|
|
@@ -108,52 +111,45 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
108
111
|
* @example
|
|
109
112
|
* ```typescript
|
|
110
113
|
* // Delegate to a Dream association's column (type inferred)
|
|
111
|
-
* .delegatedAttribute('currentLocalizedText', 'title'
|
|
114
|
+
* .delegatedAttribute('currentLocalizedText', 'title')
|
|
112
115
|
*
|
|
113
116
|
* // With default value for null target or attribute
|
|
114
|
-
* .delegatedAttribute('user', 'displayName', {
|
|
115
|
-
* openapi: { type: 'string' },
|
|
116
|
-
* default: 'Unknown User'
|
|
117
|
-
* })
|
|
117
|
+
* .delegatedAttribute('user', 'displayName', { default: 'Unknown User' })
|
|
118
118
|
*
|
|
119
119
|
* // Rename the output key
|
|
120
|
-
* .delegatedAttribute('profile', 'avatarUrl', {
|
|
121
|
-
*
|
|
122
|
-
*
|
|
120
|
+
* .delegatedAttribute('profile', 'avatarUrl', { as: 'avatar' })
|
|
121
|
+
*
|
|
122
|
+
* // A json/jsonb column has no shape to infer, so it declares one
|
|
123
|
+
* .delegatedAttribute('user', 'preferences', {
|
|
124
|
+
* openapi: { type: 'object', properties: { theme: 'string' } }
|
|
123
125
|
* })
|
|
124
126
|
* ```
|
|
125
127
|
*/
|
|
126
|
-
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
|
|
127
|
-
optional?: boolean;
|
|
128
|
-
required?: false;
|
|
129
|
-
} : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn & {
|
|
130
|
-
optional?: boolean;
|
|
131
|
-
} : TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & string ? (AutomaticSerializerAttributeOptions & {
|
|
132
|
-
optional?: boolean;
|
|
133
|
-
}) | (NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
134
|
-
optional?: boolean;
|
|
135
|
-
}) : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
136
|
-
optional?: boolean;
|
|
137
|
-
} : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
138
|
-
optional?: boolean;
|
|
139
|
-
}): this;
|
|
128
|
+
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: DelegatedAttributeOptionsArgs<AssociatedModelType, TargetAttributeName>): this;
|
|
140
129
|
/**
|
|
141
130
|
* Includes a computed value in the serialized output.
|
|
142
131
|
*
|
|
143
132
|
* Executes a callback function to generate a custom attribute value.
|
|
144
133
|
* The `openapi` option is always required since the return type cannot be inferred.
|
|
145
134
|
*
|
|
135
|
+
* The callback's return value renders as is, so any fallback or rounding belongs in the
|
|
136
|
+
* callback.
|
|
137
|
+
*
|
|
146
138
|
* @param name - The attribute name for the computed value
|
|
147
139
|
* @param fn - Callback function that returns the computed value
|
|
148
140
|
* @param options - Configuration options:
|
|
149
141
|
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
150
|
-
* - `as` - Rename the attribute key in the serialized output and OpenAPI shape
|
|
151
|
-
* - `default` - Value to use when the callback returns undefined
|
|
152
142
|
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
153
|
-
* parent serialized output instead of nesting them under `name
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
143
|
+
* parent serialized output instead of nesting them under `name`. The `openapi` option
|
|
144
|
+
* then describes the whole returned object, not each property, because Psychic adds it
|
|
145
|
+
* to the parent's schema as an `allOf` branch: either an object schema with full
|
|
146
|
+
* property bodies (`type: 'object'`, `properties`, and `required` listing the keys that
|
|
147
|
+
* are always present), or `{ $serializer: SomeSerializer }` when the callback returns
|
|
148
|
+
* what that serializer renders. A serializer ref with `many: true` does not type-check
|
|
149
|
+
* here, since a list has no properties to spread. A `null` or `undefined` return adds no
|
|
150
|
+
* keys. Attributes render in declaration order, so a key the returned object shares with
|
|
151
|
+
* another attribute takes the value of whichever is declared later; under the `allOf`,
|
|
152
|
+
* that value must match both schemas
|
|
157
153
|
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
158
154
|
* when omitted, attributes are required by default
|
|
159
155
|
* @returns The serializer builder for method chaining
|
|
@@ -166,25 +162,21 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
166
162
|
* { openapi: { type: 'string' } }
|
|
167
163
|
* )
|
|
168
164
|
*
|
|
169
|
-
* // Flattened object properties
|
|
165
|
+
* // Flattened object properties: `openapi` describes the whole returned object
|
|
170
166
|
* .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
|
|
171
167
|
* flatten: true,
|
|
172
168
|
* openapi: {
|
|
173
|
-
*
|
|
174
|
-
*
|
|
169
|
+
* type: 'object',
|
|
170
|
+
* required: ['lat', 'lng'],
|
|
171
|
+
* properties: {
|
|
172
|
+
* lat: { type: 'number' },
|
|
173
|
+
* lng: { type: 'number' }
|
|
174
|
+
* }
|
|
175
175
|
* }
|
|
176
176
|
* })
|
|
177
|
-
*
|
|
178
|
-
* // With decimal precision
|
|
179
|
-
* .customAttribute('averageRating', () => calculateAverage(ratings), {
|
|
180
|
-
* openapi: 'decimal',
|
|
181
|
-
* precision: 2
|
|
182
|
-
* })
|
|
183
177
|
* ```
|
|
184
178
|
*/
|
|
185
|
-
customAttribute(name: string, fn: () => unknown, options:
|
|
186
|
-
flatten?: boolean;
|
|
187
|
-
}): this;
|
|
179
|
+
customAttribute(name: string, fn: () => unknown, options: CustomAttributeOptions): this;
|
|
188
180
|
/**
|
|
189
181
|
* Includes a single associated object in the serialized output.
|
|
190
182
|
*
|
|
@@ -195,9 +187,18 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
195
187
|
* @param options - Configuration options:
|
|
196
188
|
* - `as` - Rename the association key in the serialized output
|
|
197
189
|
* - `flatten` - When `true`, spreads the rendered association's attributes directly into
|
|
198
|
-
* the parent serialized output instead of nesting them under `name`.
|
|
199
|
-
*
|
|
200
|
-
*
|
|
190
|
+
* the parent serialized output instead of nesting them under `name`. Attributes render in
|
|
191
|
+
* declaration order, so when the parent and the association share a key (e.g., `id`),
|
|
192
|
+
* whichever is declared later wins: the association's value replaces an attribute declared
|
|
193
|
+
* before the `rendersOne`, and an attribute declared after it replaces the association's.
|
|
194
|
+
* When the association is `null`, every key its serializer declares renders as `null`
|
|
195
|
+
* (for a polymorphic `BelongsTo`, every key the serializer of any of its target classes
|
|
196
|
+
* declares, and for an association to an STI base, every key the serializer of any of its
|
|
197
|
+
* STI children declares), in the same order (so an `id` declared before the `rendersOne` becomes
|
|
198
|
+
* `null`); nothing in that serializer is rendered, so its custom attribute callbacks do
|
|
199
|
+
* not run, and a flattened `customAttribute` in it adds no keys. Psychic adds the association's OpenAPI
|
|
200
|
+
* schema to the parent's as an `allOf` branch, so a shared key's value must match both
|
|
201
|
+
* schemas, whichever declaration wins
|
|
201
202
|
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
202
203
|
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
203
204
|
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|
|
@@ -251,7 +252,10 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
|
|
|
251
252
|
as?: string;
|
|
252
253
|
/**
|
|
253
254
|
* If `true`, the rendered association's attributes are merged directly into
|
|
254
|
-
* the parent object instead of being nested under the association key.
|
|
255
|
+
* the parent object instead of being nested under the association key. A key
|
|
256
|
+
* the parent shares with the association takes the value of whichever is
|
|
257
|
+
* declared later, and when the association is `null`, every key its serializer
|
|
258
|
+
* declares renders as `null`. See the `flatten` option of `rendersOne`.
|
|
255
259
|
*/
|
|
256
260
|
flatten?: boolean;
|
|
257
261
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dream from '../../Dream.js';
|
|
2
2
|
import { DreamOrViewModelSerializerKey, ViewModel, ViewModelClass } from '../../types/dream.js';
|
|
3
|
-
import { InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne,
|
|
3
|
+
import { CustomAttributeOptions, InternalAnyTypedSerializerAttribute, InternalAnyTypedSerializerCustomAttribute, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption, SerializerType } from '../../types/serializer.js';
|
|
4
4
|
import { SerializerRendererOpts } from '../SerializerRenderer.js';
|
|
5
5
|
import { DreamPropertiesToExclude } from './DreamSerializerBuilder.js';
|
|
6
6
|
export default class ObjectSerializerBuilder<MaybeNullDataType extends object | null, PassthroughDataType, DataType extends Exclude<MaybeNullDataType, null> = Exclude<MaybeNullDataType, null>> {
|
|
@@ -86,9 +86,10 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
86
86
|
* (e.g., delegating `'profile', 'avatarUrl'` with `as: 'avatar'` outputs the value
|
|
87
87
|
* under `avatar`)
|
|
88
88
|
* - `default` - Value to use when the target object or its attribute is null/undefined
|
|
89
|
-
* - `optional` - Set to `true` to mark the value as nullable in the OpenAPI schema
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* - `optional` - Set to `true` to mark the value as nullable in the OpenAPI schema:
|
|
90
|
+
* Psychic adds `null` to the rendered schema (e.g., `type: 'string'` becomes
|
|
91
|
+
* `type: ['string', 'null']`, and a `$ref` becomes `anyOf: [{ $ref }, { type: 'null' }]`).
|
|
92
|
+
* OpenAPI-only — the key is still rendered (as `null`)
|
|
92
93
|
* - `precision` - Round decimal values to the specified number of decimal places (0–9)
|
|
93
94
|
* during rendering; does not affect the OpenAPI shape
|
|
94
95
|
* - `required` - Set to `false` to omit the key from the rendered output when the
|
|
@@ -125,17 +126,23 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
125
126
|
* Executes a callback function to generate a custom attribute value.
|
|
126
127
|
* The `openapi` option is always required since the return type cannot be inferred.
|
|
127
128
|
*
|
|
128
|
-
*
|
|
129
|
-
* or `precision`.
|
|
129
|
+
* The callback's return value renders as is, so any fallback belongs in the callback.
|
|
130
130
|
*
|
|
131
131
|
* @param name - The attribute name for the computed value
|
|
132
132
|
* @param fn - Callback function that returns the computed value
|
|
133
133
|
* @param options - Configuration options:
|
|
134
134
|
* - `openapi` - (required) OpenAPI schema definition for the computed value
|
|
135
|
-
* - `default` - Value to use when the callback returns undefined
|
|
136
135
|
* - `flatten` - When `true`, spreads the returned object's properties directly into the
|
|
137
|
-
* parent serialized output instead of nesting them under `name
|
|
138
|
-
*
|
|
136
|
+
* parent serialized output instead of nesting them under `name`. The `openapi` option
|
|
137
|
+
* then describes the whole returned object, not each property, because Psychic adds it
|
|
138
|
+
* to the parent's schema as an `allOf` branch: either an object schema with full
|
|
139
|
+
* property bodies (`type: 'object'`, `properties`, and `required` listing the keys that
|
|
140
|
+
* are always present), or `{ $serializer: SomeSerializer }` when the callback returns
|
|
141
|
+
* what that serializer renders. A serializer ref with `many: true` does not type-check
|
|
142
|
+
* here, since a list has no properties to spread. A `null` or `undefined` return adds no
|
|
143
|
+
* keys. Attributes render in declaration order, so a key the returned object shares with
|
|
144
|
+
* another attribute takes the value of whichever is declared later; under the `allOf`,
|
|
145
|
+
* that value must match both schemas
|
|
139
146
|
* - `required` - Set to `false` to mark the attribute as optional in the OpenAPI schema;
|
|
140
147
|
* when omitted, attributes are required by default
|
|
141
148
|
* @returns The serializer builder for method chaining
|
|
@@ -148,19 +155,21 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
148
155
|
* { openapi: { type: 'string' } }
|
|
149
156
|
* )
|
|
150
157
|
*
|
|
151
|
-
* // Flattened object properties
|
|
158
|
+
* // Flattened object properties: `openapi` describes the whole returned object
|
|
152
159
|
* .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
|
|
153
160
|
* flatten: true,
|
|
154
161
|
* openapi: {
|
|
155
|
-
*
|
|
156
|
-
*
|
|
162
|
+
* type: 'object',
|
|
163
|
+
* required: ['lat', 'lng'],
|
|
164
|
+
* properties: {
|
|
165
|
+
* lat: { type: 'number' },
|
|
166
|
+
* lng: { type: 'number' }
|
|
167
|
+
* }
|
|
157
168
|
* }
|
|
158
169
|
* })
|
|
159
170
|
* ```
|
|
160
171
|
*/
|
|
161
|
-
customAttribute(name: string, fn: () => unknown, options:
|
|
162
|
-
flatten?: boolean;
|
|
163
|
-
}): this;
|
|
172
|
+
customAttribute(name: string, fn: () => unknown, options: CustomAttributeOptions): this;
|
|
164
173
|
/**
|
|
165
174
|
* Includes a single associated object in the serialized output.
|
|
166
175
|
*
|
|
@@ -171,9 +180,18 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
171
180
|
* @param options - Configuration options:
|
|
172
181
|
* - `as` - Rename the association key in the serialized output
|
|
173
182
|
* - `flatten` - When `true`, spreads the rendered association's attributes directly into
|
|
174
|
-
* the parent serialized output instead of nesting them under `name`.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
183
|
+
* the parent serialized output instead of nesting them under `name`. Attributes render in
|
|
184
|
+
* declaration order, so when the parent and the association share a key (e.g., `id`),
|
|
185
|
+
* whichever is declared later wins: the association's value replaces an attribute declared
|
|
186
|
+
* before the `rendersOne`, and an attribute declared after it replaces the association's.
|
|
187
|
+
* When the association is `null`, every key its serializer declares renders as `null`
|
|
188
|
+
* (for a polymorphic `BelongsTo`, every key the serializer of any of its target classes
|
|
189
|
+
* declares, and for an association to an STI base, every key the serializer of any of its
|
|
190
|
+
* STI children declares), in the same order (so an `id` declared before the `rendersOne` becomes
|
|
191
|
+
* `null`); nothing in that serializer is rendered, so its custom attribute callbacks do
|
|
192
|
+
* not run, and a flattened `customAttribute` in it adds no keys. Psychic adds the association's OpenAPI
|
|
193
|
+
* schema to the parent's as an `allOf` branch, so a shared key's value must match both
|
|
194
|
+
* schemas, whichever declaration wins
|
|
177
195
|
* - `optional` - When `true`, allows the association to be null/missing without causing
|
|
178
196
|
* an `OpenapiResponseValidationFailure` during Psychic controller unit specs. By default,
|
|
179
197
|
* `rendersOne` expects the association to be present (mirroring the `optional` option on
|
|
@@ -229,7 +247,10 @@ export default class ObjectSerializerBuilder<MaybeNullDataType extends object |
|
|
|
229
247
|
as?: string;
|
|
230
248
|
/**
|
|
231
249
|
* If `true`, the rendered association's attributes are merged directly into
|
|
232
|
-
* the parent object instead of being nested under the association key.
|
|
250
|
+
* the parent object instead of being nested under the association key. A key
|
|
251
|
+
* the parent shares with the association takes the value of whichever is
|
|
252
|
+
* declared later, and when the association is `null`, every key its serializer
|
|
253
|
+
* declares renders as `null`. See the `flatten` option of `rendersOne`.
|
|
233
254
|
*/
|
|
234
255
|
flatten?: boolean;
|
|
235
256
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dream from '../../Dream.js';
|
|
2
|
+
import { DreamModelSerializerType, InternalAnyRendersOneOrManyOpts, SimpleObjectSerializerType } from '../../types/serializer.js';
|
|
3
|
+
/**
|
|
4
|
+
* Only used when flatten: true, and the associated object is null, in which case there is no
|
|
5
|
+
* object to resolve a serializer from, but the renderer still needs the serializers whose keys it
|
|
6
|
+
* renders as null in the parent's payload.
|
|
7
|
+
*
|
|
8
|
+
* Resolves, in order, to the `serializer` option, the serializers of the `dreamClass` or
|
|
9
|
+
* `viewModelClass` option, or the serializers of each class `parentClass` declares the association
|
|
10
|
+
* to: the one class of most associations, or every target class of a polymorphic BelongsTo. A
|
|
11
|
+
* class that is an STI base contributes the serializer of every one of its children, since the
|
|
12
|
+
* association renders with whichever child it holds when present. The renderer renders the union
|
|
13
|
+
* of all their keys, each key once. Returns no serializers when none applies, e.g. a
|
|
14
|
+
* non-association property without a `serializer` option, so the flattened association adds no
|
|
15
|
+
* keys.
|
|
16
|
+
*/
|
|
17
|
+
export declare function serializersForAssociatedClass(parentClass: typeof Dream | null, associationName: string, options: InternalAnyRendersOneOrManyOpts): (DreamModelSerializerType | SimpleObjectSerializerType)[];
|
|
@@ -55,6 +55,12 @@ export interface AfterHookOpts<T extends Dream | null = null> {
|
|
|
55
55
|
* Only run this hook if one of the specified columns was changed in the
|
|
56
56
|
* most recent save operation.
|
|
57
57
|
*
|
|
58
|
+
* On a create, a column counts when, just before the insert, it holds a
|
|
59
|
+
* value other than `undefined` (for an instance from `dup`, other than the
|
|
60
|
+
* copied value), whether the caller or a before hook assigned it; values
|
|
61
|
+
* the insert fills in, such as the primary key, timestamps, database
|
|
62
|
+
* defaults and `null` for a column nobody assigned, do not count.
|
|
63
|
+
*
|
|
58
64
|
* ```ts
|
|
59
65
|
* @deco.AfterUpdate({ ifChanged: ['email'] })
|
|
60
66
|
* public sendEmailVerification() { ... }
|
|
@@ -5,15 +5,15 @@ import { DreamModelSerializerType, SimpleObjectSerializerType } from './serializ
|
|
|
5
5
|
export type OpenapiSchemaBody = OpenapiSchemaBase | OpenapiSchemaPrimitiveGeneric | OpenapiSchemaExpressionAnyOf | OpenapiSchemaExpressionOneOf | OpenapiSchemaExpressionAllOf | OpenapiSchemaObject | OpenapiSchemaArray;
|
|
6
6
|
export type OpenapiSchemaBodyShorthand = OpenapiSchemaBase | OpenapiSchemaShorthandPrimitiveGeneric | OpenapiSchemaShorthandExpressionAnyOf | OpenapiSchemaShorthandExpressionOneOf | OpenapiSchemaShorthandExpressionAllOf | OpenapiSchemaObjectShorthand | OpenapiSchemaArrayShorthand | OpenapiSchemaNull | OpenapiSchemaExpressionRefSchemaShorthand | OpenapiSchemaShorthandExpressionSerializerRef | OpenapiSchemaShorthandExpressionSerializableRef;
|
|
7
7
|
export type OpenapiSchemaBase = OpenapiSchemaString | OpenapiSchemaInteger | OpenapiSchemaNumber | OpenapiSchemaNull | OpenapiSchemaExpressionRef;
|
|
8
|
-
export type OpenapiSchemaShorthandExpressionAnyOf = {
|
|
8
|
+
export type OpenapiSchemaShorthandExpressionAnyOf = OpenapiSchemaCombinatorFields<{
|
|
9
9
|
anyOf: OpenapiSchemaBodyShorthand[];
|
|
10
|
-
}
|
|
11
|
-
export type OpenapiSchemaShorthandExpressionOneOf = {
|
|
10
|
+
}>;
|
|
11
|
+
export type OpenapiSchemaShorthandExpressionOneOf = OpenapiSchemaCombinatorFields<{
|
|
12
12
|
oneOf: OpenapiSchemaBodyShorthand[];
|
|
13
|
-
}
|
|
14
|
-
export type OpenapiSchemaShorthandExpressionAllOf = {
|
|
13
|
+
}>;
|
|
14
|
+
export type OpenapiSchemaShorthandExpressionAllOf = OpenapiSchemaCombinatorFields<{
|
|
15
15
|
allOf: OpenapiSchemaBodyShorthand[];
|
|
16
|
-
}
|
|
16
|
+
}>;
|
|
17
17
|
export type OpenapiSchemaShorthandExpressionSerializerRef = {
|
|
18
18
|
$serializer: DreamModelSerializerType | SimpleObjectSerializerType;
|
|
19
19
|
many?: boolean;
|
|
@@ -32,18 +32,36 @@ export type OpenapiSchemaExpressionRef = {
|
|
|
32
32
|
export type OpenapiSchemaExpressionRefSchemaShorthand = {
|
|
33
33
|
$schema: string;
|
|
34
34
|
};
|
|
35
|
-
export type OpenapiSchemaExpressionAllOf = {
|
|
35
|
+
export type OpenapiSchemaExpressionAllOf = OpenapiSchemaCombinatorFields<{
|
|
36
36
|
allOf: OpenapiSchemaBody[];
|
|
37
|
-
}
|
|
38
|
-
export type OpenapiSchemaExpressionAnyOf = {
|
|
37
|
+
}>;
|
|
38
|
+
export type OpenapiSchemaExpressionAnyOf = OpenapiSchemaCombinatorFields<{
|
|
39
39
|
anyOf: OpenapiSchemaBody[];
|
|
40
|
-
}
|
|
41
|
-
export type OpenapiSchemaExpressionOneOf = {
|
|
40
|
+
}>;
|
|
41
|
+
export type OpenapiSchemaExpressionOneOf = OpenapiSchemaCombinatorFields<{
|
|
42
42
|
oneOf: OpenapiSchemaBody[];
|
|
43
|
-
}
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* The fields of a schema that declares a `type`. `anyOf` and `oneOf` are not
|
|
46
|
+
* among them: they apply to every value, `null` included, so a nullable `type`
|
|
47
|
+
* beside one cannot admit `null`. A schema that may be null lists a
|
|
48
|
+
* `{ type: 'null' }` branch in its `anyOf` or `oneOf` instead.
|
|
49
|
+
*/
|
|
44
50
|
export type OpenapiSchemaCommonFields<T> = T & {
|
|
45
51
|
description?: string;
|
|
46
52
|
summary?: string;
|
|
53
|
+
anyOf?: never;
|
|
54
|
+
oneOf?: never;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The fields of a schema that is an `allOf`, `anyOf` or `oneOf`: the
|
|
58
|
+
* combinator and the fields that describe it, but no `type` (see
|
|
59
|
+
* `OpenapiSchemaCommonFields`).
|
|
60
|
+
*/
|
|
61
|
+
export type OpenapiSchemaCombinatorFields<T> = T & {
|
|
62
|
+
description?: string;
|
|
63
|
+
summary?: string;
|
|
64
|
+
type?: never;
|
|
47
65
|
};
|
|
48
66
|
export type OpenapiSchemaString = OpenapiSchemaCommonFields<{
|
|
49
67
|
type: 'string' | ['string', 'null'] | ['null', 'string'];
|
|
@@ -67,38 +85,43 @@ export type OpenapiSchemaNumber = OpenapiSchemaCommonFields<{
|
|
|
67
85
|
}>;
|
|
68
86
|
export type OpenapiSchemaNull = {
|
|
69
87
|
type: 'null';
|
|
88
|
+
anyOf?: never;
|
|
89
|
+
oneOf?: never;
|
|
70
90
|
};
|
|
71
91
|
export type OpenapiNumberFormats = 'decimal' | 'double';
|
|
72
|
-
export type OpenapiSchemaObject = OpenapiSchemaObjectBase |
|
|
92
|
+
export type OpenapiSchemaObject = OpenapiSchemaObjectBase | OpenapiSchemaObjectAllOf;
|
|
73
93
|
export type OpenapiSchemaObjectBase = CommonOpenapiSchemaObjectFields<{
|
|
74
94
|
minProperties?: number;
|
|
75
95
|
maxProperties?: number;
|
|
76
96
|
properties?: OpenapiSchemaProperties | OpenapiSchemaExpressionOneOf | OpenapiSchemaExpressionAnyOf | OpenapiSchemaExpressionAllOf;
|
|
77
97
|
additionalProperties?: OpenapiSchemaObject | OpenapiSchemaExpressionOneOf | OpenapiSchemaExpressionAnyOf | OpenapiSchemaExpressionAllOf | false;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
98
|
+
allOf?: never;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* An object schema that is also an `allOf`. Its `type` cannot be nullable:
|
|
102
|
+
* `allOf` applies to every value, so `null` would have to match each of its
|
|
103
|
+
* object members. A schema that may be null is an `anyOf` or `oneOf` with a
|
|
104
|
+
* `{ type: 'null' }` branch.
|
|
105
|
+
*/
|
|
106
|
+
export type OpenapiSchemaObjectAllOf = OpenapiSchemaCommonFields<{
|
|
107
|
+
type: 'object';
|
|
108
|
+
required?: string[];
|
|
86
109
|
allOf?: OpenapiSchemaBody[];
|
|
87
110
|
}>;
|
|
88
|
-
export type OpenapiSchemaObjectShorthand = OpenapiSchemaObjectBaseShorthand |
|
|
111
|
+
export type OpenapiSchemaObjectShorthand = OpenapiSchemaObjectBaseShorthand | OpenapiSchemaObjectAllOfShorthand;
|
|
89
112
|
export type OpenapiSchemaObjectBaseShorthand = CommonOpenapiSchemaObjectFields<{
|
|
90
113
|
minProperties?: number;
|
|
91
114
|
maxProperties?: number;
|
|
92
115
|
properties?: OpenapiSchemaPropertiesShorthand | OpenapiSchemaShorthandExpressionOneOf | OpenapiSchemaShorthandExpressionAnyOf | OpenapiSchemaShorthandExpressionAllOf | OpenapiSchemaShorthandExpressionSerializerRef | OpenapiSchemaShorthandExpressionSerializableRef;
|
|
93
116
|
additionalProperties?: OpenapiShorthandPrimitiveTypes | OpenapiSchemaBodyShorthand | OpenapiSchemaShorthandExpressionOneOf | OpenapiSchemaShorthandExpressionAnyOf | OpenapiSchemaShorthandExpressionAllOf | OpenapiSchemaShorthandExpressionSerializerRef | OpenapiSchemaShorthandExpressionSerializableRef | false;
|
|
117
|
+
allOf?: never;
|
|
94
118
|
}>;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export type
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
export type OpenapiSchemaObjectAllOfShorthand = CommonOpenapiSchemaObjectFields<{
|
|
119
|
+
/**
|
|
120
|
+
* The shorthand form of `OpenapiSchemaObjectAllOf`.
|
|
121
|
+
*/
|
|
122
|
+
export type OpenapiSchemaObjectAllOfShorthand = OpenapiSchemaCommonFields<{
|
|
123
|
+
type: 'object';
|
|
124
|
+
required?: string[];
|
|
102
125
|
allOf?: OpenapiSchemaBodyShorthand[];
|
|
103
126
|
}>;
|
|
104
127
|
export type CommonOpenapiSchemaObjectFields<T> = OpenapiSchemaCommonFields<T & {
|
|
@@ -2,7 +2,7 @@ import Dream from '../Dream.js';
|
|
|
2
2
|
import { RoundingPrecision } from '../helpers/round.js';
|
|
3
3
|
import DreamSerializerBuilder from '../serializer/builders/DreamSerializerBuilder.js';
|
|
4
4
|
import ObjectSerializerBuilder from '../serializer/builders/ObjectSerializerBuilder.js';
|
|
5
|
-
import { DreamSerializable, DreamSerializableArray, ViewModelClass } from './dream.js';
|
|
5
|
+
import { DreamSerializable, DreamSerializableArray, DreamVirtualColumns, NonJsonDreamColumnNames, ViewModelClass } from './dream.js';
|
|
6
6
|
import { OpenapiDescription, OpenapiSchemaBodyShorthand, OpenapiShorthandPrimitiveTypes } from './openapi.js';
|
|
7
7
|
export type SerializerCasing = 'camel' | 'snake';
|
|
8
8
|
export type DreamsOrSerializersOrViewModels = DreamSerializable | DreamSerializableArray;
|
|
@@ -28,7 +28,9 @@ export interface InternalAnyTypedSerializerCustomAttribute {
|
|
|
28
28
|
type: 'customAttribute';
|
|
29
29
|
name: string;
|
|
30
30
|
fn: (x?: any, y?: any) => any;
|
|
31
|
-
options:
|
|
31
|
+
options: {
|
|
32
|
+
openapi: CustomAttributeOpenapi;
|
|
33
|
+
required?: false;
|
|
32
34
|
flatten?: boolean;
|
|
33
35
|
};
|
|
34
36
|
}
|
|
@@ -119,6 +121,45 @@ export type NonAutomaticSerializerAttributeOptions = {
|
|
|
119
121
|
export type NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption = NonAutomaticSerializerAttributeOptions & {
|
|
120
122
|
precision?: RoundingPrecision;
|
|
121
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* The options argument of `DreamSerializer#delegatedAttribute`. A Dream model's non-json
|
|
126
|
+
* column infers its OpenAPI shape, so its `openapi` takes only a description and the
|
|
127
|
+
* argument may be left out. A json/jsonb column or a non-Dream target has no shape to
|
|
128
|
+
* infer, so the argument is required and its `openapi` takes a full shape.
|
|
129
|
+
*/
|
|
130
|
+
export type DelegatedAttributeOptionsArgs<AssociatedModelType, TargetAttributeName> = DelegatedAttributeOptions<AssociatedModelType, TargetAttributeName> extends infer Options ? Partial<Options> extends Options ? [options?: Options] : [options: Options] : never;
|
|
131
|
+
type DelegatedAttributeOptions<AssociatedModelType, TargetAttributeName> = AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType & {
|
|
132
|
+
optional?: boolean;
|
|
133
|
+
required?: false;
|
|
134
|
+
} : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn & {
|
|
135
|
+
optional?: boolean;
|
|
136
|
+
} : TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & string ? AutomaticSerializerAttributeOptions & {
|
|
137
|
+
optional?: boolean;
|
|
138
|
+
} : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
139
|
+
optional?: boolean;
|
|
140
|
+
} : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption & {
|
|
141
|
+
optional?: boolean;
|
|
142
|
+
};
|
|
143
|
+
type CustomAttributeOpenapi = OpenapiSchemaBodyShorthand | OpenapiShorthandPrimitiveTypes;
|
|
144
|
+
/**
|
|
145
|
+
* The options of `customAttribute`. The callback's return value renders as is, so there is
|
|
146
|
+
* no `as`, `default` or `precision`. With `flatten: true`, `openapi` may be anything but a
|
|
147
|
+
* serializer ref with `many: true`: flattening spreads one object's properties into the
|
|
148
|
+
* parent, and a list has none to spread.
|
|
149
|
+
*/
|
|
150
|
+
export type CustomAttributeOptions = {
|
|
151
|
+
openapi: CustomAttributeOpenapi;
|
|
152
|
+
required?: false;
|
|
153
|
+
flatten?: false;
|
|
154
|
+
} | {
|
|
155
|
+
openapi: OpenapiForFlattening<CustomAttributeOpenapi>;
|
|
156
|
+
required?: false;
|
|
157
|
+
flatten: true;
|
|
158
|
+
};
|
|
159
|
+
type OpenapiForFlattening<Openapi> = Openapi extends unknown ? 'many' extends keyof Openapi ? Omit<Openapi, 'many'> & {
|
|
160
|
+
many?: false;
|
|
161
|
+
} : Openapi : never;
|
|
122
162
|
export type DreamModelSerializerType = (data: any, passthroughData?: any) => DreamSerializerBuilder<any, any>;
|
|
123
163
|
export type SimpleObjectSerializerType = (data: any, passthroughData?: any) => ObjectSerializerBuilder<any, any>;
|
|
124
164
|
export type SerializerType = DreamModelSerializerType | SimpleObjectSerializerType;
|
|
165
|
+
export {};
|
|
@@ -90,6 +90,12 @@ export interface AfterHookOpts<T extends Dream | null = null> {
|
|
|
90
90
|
* Only run this hook if one of the specified columns was changed in the
|
|
91
91
|
* most recent save operation.
|
|
92
92
|
*
|
|
93
|
+
* On a create, a column counts when, just before the insert, it holds a
|
|
94
|
+
* value other than `undefined` (for an instance from `dup`, other than the
|
|
95
|
+
* copied value), whether the caller or a before hook assigned it; values
|
|
96
|
+
* the insert fills in, such as the primary key, timestamps, database
|
|
97
|
+
* defaults and `null` for a column nobody assigned, do not count.
|
|
98
|
+
*
|
|
93
99
|
* ```ts
|
|
94
100
|
* @deco.AfterUpdate({ ifChanged: ['email'] })
|
|
95
101
|
* public sendEmailVerification() { ... }
|