@rvoh/dream 0.42.3 → 0.43.0-beta.2
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 -32
- package/dist/cjs/src/bin/index.js +6 -1
- package/dist/cjs/src/cli/index.js +1 -0
- package/dist/cjs/src/decorators/field/validation/Validates.js +5 -2
- package/dist/cjs/src/dream/Query.js +16 -13
- package/dist/cjs/src/dream/constants.js +7 -9
- package/dist/cjs/src/dream/internal/checkSingleValidation.js +5 -2
- package/dist/cjs/src/dream/internal/findOrCreateBy.js +1 -1
- package/dist/cjs/src/dream/internal/orderByDirection.js +5 -2
- package/dist/cjs/src/dream/internal/updateOrCreateBy.js +1 -1
- package/dist/cjs/src/dream-app/helpers/DreamImporter.js +2 -2
- package/dist/cjs/src/dream-app/helpers/importers/importModels.js +1 -1
- package/dist/cjs/src/dream-app/helpers/importers/importSerializers.js +5 -26
- package/dist/cjs/src/dream-app/index.js +5 -2
- package/dist/cjs/src/encrypt/index.js +20 -8
- package/dist/cjs/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +16 -0
- package/dist/cjs/src/errors/serializers/DelegationTargetDoesNotExist.js +13 -0
- package/dist/cjs/src/errors/serializers/MissingSerializersDefinition.js +26 -0
- package/dist/cjs/src/errors/serializers/MissingSerializersDefinitionForKey.js +29 -0
- package/dist/cjs/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +21 -0
- package/dist/cjs/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.js +16 -0
- package/dist/cjs/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +26 -0
- package/dist/cjs/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.js +16 -0
- package/dist/cjs/src/errors/serializers/NonSerializerSerializerOverrideProvided.js +23 -0
- package/dist/cjs/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.js +19 -0
- package/dist/cjs/src/errors/serializers/RendersManyMustReceiveArray.js +18 -0
- package/dist/cjs/src/errors/serializers/SerializerInsteadOfSerializerCallback.js +49 -0
- package/dist/cjs/src/helpers/cli/generateDream.js +7 -2
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +1 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/cjs/src/helpers/cli/generateSerializer.js +7 -2
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +41 -66
- package/dist/cjs/src/helpers/compact.js +2 -2
- package/dist/cjs/src/helpers/db/primaryKeyType.js +5 -2
- package/dist/cjs/src/helpers/sortObjectByKey.js +11 -0
- package/dist/cjs/src/helpers/sti/expandStiClasses.js +17 -0
- package/dist/cjs/src/index.js +27 -15
- package/dist/cjs/src/openapi/allSerializersFromHandWrittenOpenapi.js +26 -0
- package/dist/cjs/src/openapi/allSerializersToRefsInOpenapi.js +41 -0
- package/dist/cjs/src/openapi/dreamAttributeOpenapiShape.js +138 -0
- package/dist/cjs/src/openapi/isOpenapiShorthand.js +11 -0
- package/dist/cjs/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.js +17 -0
- package/dist/cjs/src/openapi/openapiShorthandToOpenapi.js +106 -0
- package/dist/cjs/src/serializer/DreamSerializer.js +7 -0
- package/dist/cjs/src/serializer/ObjectSerializer.js +7 -0
- package/dist/cjs/src/serializer/SerializerOpenapiRenderer.js +325 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +201 -0
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +69 -0
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +67 -0
- package/dist/cjs/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +38 -0
- package/dist/cjs/src/serializer/helpers/isDreamSerializer.js +19 -0
- package/dist/cjs/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.js +1 -1
- package/dist/cjs/src/serializer/index.js +0 -282
- package/dist/cjs/src/types/serializer.js +2 -0
- package/dist/esm/src/Dream.js +25 -32
- package/dist/esm/src/bin/index.js +6 -1
- package/dist/esm/src/cli/index.js +1 -0
- package/dist/esm/src/decorators/field/validation/Validates.js +5 -2
- package/dist/esm/src/dream/Query.js +13 -10
- package/dist/esm/src/dream/constants.js +7 -9
- package/dist/esm/src/dream/internal/checkSingleValidation.js +5 -2
- package/dist/esm/src/dream/internal/findOrCreateBy.js +1 -1
- package/dist/esm/src/dream/internal/orderByDirection.js +5 -2
- package/dist/esm/src/dream/internal/updateOrCreateBy.js +1 -1
- package/dist/esm/src/dream-app/helpers/DreamImporter.js +2 -2
- package/dist/esm/src/dream-app/helpers/importers/importModels.js +1 -1
- package/dist/esm/src/dream-app/helpers/importers/importSerializers.js +5 -26
- package/dist/esm/src/dream-app/index.js +5 -2
- package/dist/esm/src/encrypt/index.js +20 -8
- package/dist/esm/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +13 -0
- package/dist/esm/src/errors/serializers/DelegationTargetDoesNotExist.js +10 -0
- package/dist/esm/src/errors/serializers/MissingSerializersDefinition.js +23 -0
- package/dist/esm/src/errors/serializers/MissingSerializersDefinitionForKey.js +26 -0
- package/dist/esm/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +18 -0
- package/dist/esm/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.js +13 -0
- package/dist/esm/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +23 -0
- package/dist/esm/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.js +13 -0
- package/dist/esm/src/errors/serializers/NonSerializerSerializerOverrideProvided.js +20 -0
- package/dist/esm/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.js +16 -0
- package/dist/esm/src/errors/serializers/RendersManyMustReceiveArray.js +15 -0
- package/dist/esm/src/errors/serializers/SerializerInsteadOfSerializerCallback.js +46 -0
- package/dist/esm/src/helpers/cli/generateDream.js +7 -2
- package/dist/esm/src/helpers/cli/generateDreamContent.js +1 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/esm/src/helpers/cli/generateSerializer.js +7 -2
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +41 -66
- package/dist/esm/src/helpers/compact.js +2 -2
- package/dist/esm/src/helpers/db/primaryKeyType.js +5 -2
- package/dist/esm/src/helpers/sortObjectByKey.js +8 -0
- package/dist/esm/src/helpers/sti/expandStiClasses.js +14 -0
- package/dist/esm/src/index.js +12 -6
- package/dist/esm/src/openapi/allSerializersFromHandWrittenOpenapi.js +23 -0
- package/dist/esm/src/openapi/allSerializersToRefsInOpenapi.js +38 -0
- package/dist/esm/src/openapi/dreamAttributeOpenapiShape.js +132 -0
- package/dist/esm/src/openapi/isOpenapiShorthand.js +8 -0
- package/dist/esm/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.js +14 -0
- package/dist/esm/src/openapi/openapiShorthandToOpenapi.js +100 -0
- package/dist/esm/src/serializer/DreamSerializer.js +4 -0
- package/dist/esm/src/serializer/ObjectSerializer.js +4 -0
- package/dist/esm/src/serializer/SerializerOpenapiRenderer.js +322 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +198 -0
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +66 -0
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +64 -0
- package/dist/esm/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +33 -0
- package/dist/esm/src/serializer/helpers/isDreamSerializer.js +16 -0
- package/dist/esm/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.js +1 -1
- package/dist/esm/src/serializer/index.js +1 -280
- package/dist/esm/src/types/serializer.js +1 -0
- package/dist/types/src/Dream.d.ts +19 -20
- package/dist/types/src/bin/index.d.ts +1 -0
- package/dist/types/src/decorators/Decorators.d.ts +2 -2
- package/dist/types/src/decorators/field-or-getter/Virtual.d.ts +3 -3
- package/dist/types/src/dream/constants.d.ts +2 -2
- package/dist/types/src/dream-app/helpers/DreamImporter.d.ts +2 -2
- package/dist/types/src/dream-app/helpers/importers/importSerializers.d.ts +5 -5
- package/dist/types/src/dream-app/index.d.ts +2 -2
- package/dist/types/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.d.ts +5 -0
- package/dist/types/src/errors/serializers/DelegationTargetDoesNotExist.d.ts +5 -0
- package/dist/types/src/errors/serializers/FailedToRenderThroughAssociationForSerializer.d.ts +2 -2
- package/dist/types/src/errors/serializers/MissingSerializersDefinition.d.ts +7 -0
- package/dist/types/src/errors/serializers/MissingSerializersDefinitionForKey.d.ts +8 -0
- package/dist/types/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.d.ts +9 -0
- package/dist/types/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.d.ts +5 -0
- package/dist/types/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.d.ts +10 -0
- package/dist/types/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.d.ts +5 -0
- package/dist/types/src/errors/serializers/NonSerializerSerializerOverrideProvided.d.ts +6 -0
- package/dist/types/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.d.ts +5 -0
- package/dist/types/src/errors/serializers/RendersManyMustReceiveArray.d.ts +7 -0
- package/dist/types/src/errors/serializers/SerializerInsteadOfSerializerCallback.d.ts +8 -0
- package/dist/types/src/helpers/cli/generateDream.d.ts +1 -0
- package/dist/types/src/helpers/cli/generateSerializer.d.ts +2 -1
- package/dist/types/src/helpers/cli/generateSerializerContent.d.ts +2 -1
- package/dist/types/src/helpers/sortObjectByKey.d.ts +1 -0
- package/dist/types/src/helpers/sti/expandStiClasses.d.ts +3 -0
- package/dist/types/src/index.d.ts +15 -9
- package/dist/types/src/openapi/allSerializersFromHandWrittenOpenapi.d.ts +3 -0
- package/dist/types/src/openapi/allSerializersToRefsInOpenapi.d.ts +2 -0
- package/dist/types/src/openapi/dreamAttributeOpenapiShape.d.ts +796 -0
- package/dist/types/src/openapi/isOpenapiShorthand.d.ts +1 -0
- package/dist/types/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.d.ts +2 -0
- package/dist/types/src/openapi/openapiShorthandToOpenapi.d.ts +16 -0
- package/dist/types/src/serializer/DreamSerializer.d.ts +3 -0
- package/dist/types/src/serializer/ObjectSerializer.d.ts +3 -0
- package/dist/types/src/serializer/SerializerOpenapiRenderer.d.ts +23 -0
- package/dist/types/src/serializer/SerializerRenderer.d.ts +14 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +54 -0
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +54 -0
- package/dist/types/src/serializer/helpers/inferSerializerFromDreamOrViewModel.d.ts +6 -0
- package/dist/types/src/serializer/helpers/isDreamSerializer.d.ts +1 -0
- package/dist/types/src/serializer/index.d.ts +1 -54
- package/dist/types/src/types/dream.d.ts +2 -5
- package/dist/types/src/types/dream.ts +13 -7
- package/dist/types/src/types/openapi.d.ts +10 -4
- package/dist/types/src/types/openapi.ts +20 -4
- package/dist/types/src/types/serializer.d.ts +66 -0
- package/dist/types/src/types/serializer.ts +112 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +20 -20
- package/docs/classes/Dream.html +214 -213
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializerBuilder.html +18 -0
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/ObjectSerializerBuilder.html +17 -0
- package/docs/classes/Query.html +51 -51
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/SerializerOpenapiRenderer.html +6 -0
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -0
- package/docs/functions/ObjectSerializer.html +1 -0
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -0
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -0
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/isOpenapiShorthand.html +1 -0
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/maybeNullOpenapiShorthandToOpenapiShorthand.html +1 -0
- package/docs/functions/openapiShorthandToOpenapi.html +1 -0
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -0
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/modules.html +17 -10
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -0
- package/docs/types/DreamOrViewModelClassSerializerArrayKeys.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -0
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -0
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -0
- package/docs/types/SimpleObjectSerializerType.html +1 -0
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +3 -4
- package/dist/cjs/src/errors/MissingSerializersDefinition.js +0 -26
- package/dist/cjs/src/helpers/inferSerializerFromDreamOrViewModel.js +0 -16
- package/dist/cjs/src/serializer/decorators/associations/RendersMany.js +0 -84
- package/dist/cjs/src/serializer/decorators/associations/RendersOne.js +0 -87
- package/dist/cjs/src/serializer/decorators/associations/shared.js +0 -10
- package/dist/cjs/src/serializer/decorators/attribute.js +0 -167
- package/dist/cjs/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +0 -74
- package/dist/cjs/src/serializer/decorators/helpers/hasSerializersGetter.js +0 -11
- package/dist/cjs/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +0 -20
- package/dist/esm/src/errors/MissingSerializersDefinition.js +0 -23
- package/dist/esm/src/helpers/inferSerializerFromDreamOrViewModel.js +0 -12
- package/dist/esm/src/serializer/decorators/associations/RendersMany.js +0 -81
- package/dist/esm/src/serializer/decorators/associations/RendersOne.js +0 -84
- package/dist/esm/src/serializer/decorators/associations/shared.js +0 -7
- package/dist/esm/src/serializer/decorators/attribute.js +0 -164
- package/dist/esm/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +0 -69
- package/dist/esm/src/serializer/decorators/helpers/hasSerializersGetter.js +0 -8
- package/dist/esm/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +0 -17
- package/dist/types/src/errors/MissingSerializersDefinition.d.ts +0 -6
- package/dist/types/src/helpers/inferSerializerFromDreamOrViewModel.d.ts +0 -4
- package/dist/types/src/serializer/decorators/associations/RendersMany.d.ts +0 -42
- package/dist/types/src/serializer/decorators/associations/RendersOne.d.ts +0 -46
- package/dist/types/src/serializer/decorators/associations/shared.d.ts +0 -24
- package/dist/types/src/serializer/decorators/attribute.d.ts +0 -28
- package/dist/types/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.d.ts +0 -7
- package/dist/types/src/serializer/decorators/helpers/hasSerializersGetter.d.ts +0 -2
- package/dist/types/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.d.ts +0 -2
- package/docs/classes/DreamSerializer.html +0 -19
- package/docs/functions/Attribute.html +0 -1
- package/docs/functions/RendersMany.html +0 -16
- package/docs/functions/RendersOne.html +0 -16
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +0 -1
- package/docs/interfaces/AttributeStatement.html +0 -6
- package/docs/interfaces/DreamSerializerAssociationStatement.html +0 -11
- package/docs/types/SerializableClassOrSerializerCallback.html +0 -1
- package/docs/types/SerializableTypes.html +0 -1
- /package/dist/types/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.d.ts +0 -0
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -41,14 +41,12 @@ const CreateOrFindByFailedToCreateAndFind_js_1 = require("./errors/CreateOrFindB
|
|
|
41
41
|
const CreateOrUpdateByFailedToCreateAndUpdate_js_1 = require("./errors/CreateOrUpdateByFailedToCreateAndUpdate.js");
|
|
42
42
|
const GlobalNameNotSet_js_1 = require("./errors/dream-app/GlobalNameNotSet.js");
|
|
43
43
|
const DreamMissingRequiredOverride_js_1 = require("./errors/DreamMissingRequiredOverride.js");
|
|
44
|
-
const MissingSerializersDefinition_js_1 = require("./errors/MissingSerializersDefinition.js");
|
|
45
44
|
const NonExistentScopeProvidedToResort_js_1 = require("./errors/NonExistentScopeProvidedToResort.js");
|
|
46
45
|
const CalendarDate_js_1 = require("./helpers/CalendarDate.js");
|
|
47
46
|
const cloneDeepSafe_js_1 = require("./helpers/cloneDeepSafe.js");
|
|
48
47
|
const DateTime_js_1 = require("./helpers/DateTime.js");
|
|
49
48
|
const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
|
|
50
49
|
const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
|
|
51
|
-
const inferSerializerFromDreamOrViewModel_js_1 = require("./helpers/inferSerializerFromDreamOrViewModel.js");
|
|
52
50
|
const notEqual_js_1 = require("./helpers/notEqual.js");
|
|
53
51
|
const typechecks_js_1 = require("./helpers/typechecks.js");
|
|
54
52
|
class Dream {
|
|
@@ -489,6 +487,17 @@ class Dream {
|
|
|
489
487
|
...new Set([...columns, ...this.virtualAttributes.map(attr => attr.property)]),
|
|
490
488
|
];
|
|
491
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* @internal
|
|
492
|
+
*
|
|
493
|
+
* Returns true if the column is a column in the database
|
|
494
|
+
*
|
|
495
|
+
* @param columnName - the name of the property you are checking for
|
|
496
|
+
* @returns boolean
|
|
497
|
+
*/
|
|
498
|
+
static isColumn(columnName) {
|
|
499
|
+
return this.prototype.isColumn(columnName);
|
|
500
|
+
}
|
|
492
501
|
/**
|
|
493
502
|
* @internal
|
|
494
503
|
*
|
|
@@ -720,7 +729,7 @@ class Dream {
|
|
|
720
729
|
try {
|
|
721
730
|
const dreamModel = this.new({
|
|
722
731
|
...attributes,
|
|
723
|
-
...
|
|
732
|
+
...extraOpts?.createWith,
|
|
724
733
|
});
|
|
725
734
|
await dreamModel.save();
|
|
726
735
|
return dreamModel;
|
|
@@ -774,7 +783,7 @@ class Dream {
|
|
|
774
783
|
try {
|
|
775
784
|
return await this.create({
|
|
776
785
|
...attributes,
|
|
777
|
-
...
|
|
786
|
+
...extraOpts?.with,
|
|
778
787
|
}, skipHooks ? { skipHooks } : undefined);
|
|
779
788
|
}
|
|
780
789
|
catch (err) {
|
|
@@ -2142,6 +2151,17 @@ class Dream {
|
|
|
2142
2151
|
*/
|
|
2143
2152
|
this.unshadowColumnPropertyPrototypeAccessors();
|
|
2144
2153
|
}
|
|
2154
|
+
/**
|
|
2155
|
+
* @internal
|
|
2156
|
+
*
|
|
2157
|
+
* Returns true if the column is a column in the database
|
|
2158
|
+
*
|
|
2159
|
+
* @param columnName - the name of the property you are checking for
|
|
2160
|
+
* @returns boolean
|
|
2161
|
+
*/
|
|
2162
|
+
isColumn(columnName) {
|
|
2163
|
+
return this.columns().has(columnName);
|
|
2164
|
+
}
|
|
2145
2165
|
/**
|
|
2146
2166
|
* Returns true if the columnName passed is marked by a
|
|
2147
2167
|
* Virtual attribute decorator
|
|
@@ -2150,9 +2170,7 @@ class Dream {
|
|
|
2150
2170
|
* @returns A boolean
|
|
2151
2171
|
*/
|
|
2152
2172
|
isVirtualColumn(columnName) {
|
|
2153
|
-
return this.constructor.virtualAttributes
|
|
2154
|
-
.map(attr => attr.property)
|
|
2155
|
-
.includes(columnName);
|
|
2173
|
+
return !!this.constructor.virtualAttributes.find(attr => attr.property === columnName);
|
|
2156
2174
|
}
|
|
2157
2175
|
/**
|
|
2158
2176
|
* Returns an object with column names for keys, and an
|
|
@@ -2926,31 +2944,6 @@ class Dream {
|
|
|
2926
2944
|
async reload() {
|
|
2927
2945
|
await (0, reload_js_1.default)(this);
|
|
2928
2946
|
}
|
|
2929
|
-
/**
|
|
2930
|
-
* Serializes an instance. You can specify a serializer key,
|
|
2931
|
-
* or else the default will be used
|
|
2932
|
-
*
|
|
2933
|
-
* ```ts
|
|
2934
|
-
* // uses the default serializer provided in the model's `serializers` getter
|
|
2935
|
-
* await user.serialize()
|
|
2936
|
-
*
|
|
2937
|
-
* // uses the summary serializer provided in the model's `serializers` getter
|
|
2938
|
-
* await user.serialize({ serializerKey: 'summary' })
|
|
2939
|
-
* ```
|
|
2940
|
-
*
|
|
2941
|
-
* @param args.casing - Which casing to use when serializing (camel or snake, default camel)
|
|
2942
|
-
* @param args.serializerKey - The key to use when referencing the object returned by the `serializers` getter on the given model instance (defaults to "default")
|
|
2943
|
-
* @returns A serialized representation of the model
|
|
2944
|
-
*/
|
|
2945
|
-
serialize({ casing = null, serializerKey } = {}) {
|
|
2946
|
-
const serializerClass = (0, inferSerializerFromDreamOrViewModel_js_1.default)(this, serializerKey?.toString());
|
|
2947
|
-
if (!serializerClass)
|
|
2948
|
-
throw new MissingSerializersDefinition_js_1.default(this.constructor);
|
|
2949
|
-
const serializer = new serializerClass(this);
|
|
2950
|
-
if (casing)
|
|
2951
|
-
serializer.casing(casing);
|
|
2952
|
-
return serializer.render();
|
|
2953
|
-
}
|
|
2954
2947
|
/**
|
|
2955
2948
|
* Takes the attributes passed in and sets their values,
|
|
2956
2949
|
* leveraging any custom setters defined for these attributes.
|
|
@@ -81,7 +81,12 @@ class DreamBin {
|
|
|
81
81
|
await (0, generateDream_js_1.default)({ fullyQualifiedModelName, columnsWithTypes, options });
|
|
82
82
|
}
|
|
83
83
|
static async generateStiChild(fullyQualifiedModelName, fullyQualifiedParentName, columnsWithTypes, options) {
|
|
84
|
-
await (0, generateDream_js_1.default)({
|
|
84
|
+
await (0, generateDream_js_1.default)({
|
|
85
|
+
fullyQualifiedModelName,
|
|
86
|
+
columnsWithTypes,
|
|
87
|
+
options: { ...options, stiBaseSerializer: false },
|
|
88
|
+
fullyQualifiedParentName,
|
|
89
|
+
});
|
|
85
90
|
}
|
|
86
91
|
static async generateMigration(migrationName, columnsWithTypes) {
|
|
87
92
|
await (0, generateMigration_js_1.default)({ migrationName, columnsWithTypes });
|
|
@@ -46,6 +46,7 @@ class DreamCLI {
|
|
|
46
46
|
.alias('generate:dream')
|
|
47
47
|
.alias('g:dream')
|
|
48
48
|
.option('--no-serializer')
|
|
49
|
+
.option('--sti-base-serializer', 'Omits the serializer from the dream model, but does create the serializer so it can be extended by STI children')
|
|
49
50
|
.description('create a new Dream model')
|
|
50
51
|
.argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
|
|
51
52
|
.argument('[columnsWithTypes...]', 'properties of the model property1:text/string/enum/etc. property2:text/string/enum/etc. ... propertyN:text/string/enum/etc.')
|
|
@@ -61,8 +61,11 @@ function extractValidationOptionsFromArgs(type, args) {
|
|
|
61
61
|
}
|
|
62
62
|
case 'requiredBelongsTo':
|
|
63
63
|
return {};
|
|
64
|
-
default:
|
|
65
|
-
|
|
64
|
+
default: {
|
|
65
|
+
// protection so that if a new ValidationType is ever added, this will throw a type error at build time
|
|
66
|
+
const _never = type;
|
|
67
|
+
throw new Error(`Unhandled ValidationType: ${_never}`);
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
class ValidationInstantiationError extends Error {
|
|
@@ -5,6 +5,7 @@ const pluralize_esm_1 = require("pluralize-esm");
|
|
|
5
5
|
const ConnectedToDB_js_1 = require("../db/ConnectedToDB.js");
|
|
6
6
|
const SoftDelete_js_1 = require("../decorators/class/SoftDelete.js");
|
|
7
7
|
const associationToGetterSetterProp_js_1 = require("../decorators/field/association/associationToGetterSetterProp.js");
|
|
8
|
+
const index_js_1 = require("../dream-app/index.js");
|
|
8
9
|
const AssociationDeclaredWithoutAssociatedDreamClass_js_1 = require("../errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.js");
|
|
9
10
|
const CannotAssociateThroughPolymorphic_js_1 = require("../errors/associations/CannotAssociateThroughPolymorphic.js");
|
|
10
11
|
const CannotJoinPolymorphicBelongsToError_js_1 = require("../errors/associations/CannotJoinPolymorphicBelongsToError.js");
|
|
@@ -21,6 +22,8 @@ const LeftJoinPreloadIncompatibleWithFindEach_js_1 = require("../errors/LeftJoin
|
|
|
21
22
|
const MissingRequiredCallbackFunctionToPluckEach_js_1 = require("../errors/MissingRequiredCallbackFunctionToPluckEach.js");
|
|
22
23
|
const NoUpdateAllOnJoins_js_1 = require("../errors/NoUpdateAllOnJoins.js");
|
|
23
24
|
const NoUpdateOnAssociationQuery_js_1 = require("../errors/NoUpdateOnAssociationQuery.js");
|
|
25
|
+
const CannotPaginateWithLimit_js_1 = require("../errors/pagination/CannotPaginateWithLimit.js");
|
|
26
|
+
const CannotPaginateWithOffset_js_1 = require("../errors/pagination/CannotPaginateWithOffset.js");
|
|
24
27
|
const RecordNotFound_js_1 = require("../errors/RecordNotFound.js");
|
|
25
28
|
const UnexpectedUndefined_js_1 = require("../errors/UnexpectedUndefined.js");
|
|
26
29
|
const CalendarDate_js_1 = require("../helpers/CalendarDate.js");
|
|
@@ -38,19 +41,16 @@ const snakeify_js_1 = require("../helpers/snakeify.js");
|
|
|
38
41
|
const typechecks_js_1 = require("../helpers/typechecks.js");
|
|
39
42
|
const uniq_js_1 = require("../helpers/uniq.js");
|
|
40
43
|
const curried_ops_statement_js_1 = require("../ops/curried-ops-statement.js");
|
|
41
|
-
const
|
|
44
|
+
const index_js_2 = require("../ops/index.js");
|
|
42
45
|
const ops_statement_js_1 = require("../ops/ops-statement.js");
|
|
43
46
|
const constants_js_1 = require("./constants.js");
|
|
47
|
+
const computedPaginatePage_js_1 = require("./internal/computedPaginatePage.js");
|
|
44
48
|
const executeDatabaseQuery_js_1 = require("./internal/executeDatabaseQuery.js");
|
|
45
49
|
const extractAssociationMetadataFromAssociationName_js_1 = require("./internal/extractAssociationMetadataFromAssociationName.js");
|
|
46
50
|
const orderByDirection_js_1 = require("./internal/orderByDirection.js");
|
|
47
51
|
const shouldBypassDefaultScope_js_1 = require("./internal/shouldBypassDefaultScope.js");
|
|
48
52
|
const SimilarityBuilder_js_1 = require("./internal/similarity/SimilarityBuilder.js");
|
|
49
53
|
const sqlResultToDreamInstance_js_1 = require("./internal/sqlResultToDreamInstance.js");
|
|
50
|
-
const index_js_2 = require("../dream-app/index.js");
|
|
51
|
-
const CannotPaginateWithLimit_js_1 = require("../errors/pagination/CannotPaginateWithLimit.js");
|
|
52
|
-
const CannotPaginateWithOffset_js_1 = require("../errors/pagination/CannotPaginateWithOffset.js");
|
|
53
|
-
const computedPaginatePage_js_1 = require("./internal/computedPaginatePage.js");
|
|
54
54
|
class Query extends ConnectedToDB_js_1.default {
|
|
55
55
|
/**
|
|
56
56
|
* @internal
|
|
@@ -301,7 +301,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
301
301
|
baseSelectQuery: opts.baseSelectQuery || this.baseSelectQuery,
|
|
302
302
|
passthroughOnStatement: {
|
|
303
303
|
...this.passthroughOnStatement,
|
|
304
|
-
...
|
|
304
|
+
...opts.passthroughOnStatement,
|
|
305
305
|
},
|
|
306
306
|
where: opts.where === null ? [] : [...this.whereStatements, ...(opts.where || [])],
|
|
307
307
|
whereNot: opts.whereNot === null ? [] : [...this.whereNotStatements, ...(opts.whereNot || [])],
|
|
@@ -442,13 +442,13 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
442
442
|
let lastId = null;
|
|
443
443
|
do {
|
|
444
444
|
if (lastId)
|
|
445
|
-
records = await query.where({ [this.dreamInstance.primaryKey]:
|
|
445
|
+
records = await query.where({ [this.dreamInstance.primaryKey]: index_js_2.default.greaterThan(lastId) }).all();
|
|
446
446
|
else
|
|
447
447
|
records = await query.all();
|
|
448
448
|
for (const record of records) {
|
|
449
449
|
await cb(record);
|
|
450
450
|
}
|
|
451
|
-
lastId = records
|
|
451
|
+
lastId = records.at(-1)?.primaryKeyValue;
|
|
452
452
|
} while (records.length > 0 && records.length === batchSize);
|
|
453
453
|
}
|
|
454
454
|
/**
|
|
@@ -1003,8 +1003,11 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1003
1003
|
return this.buildUpdate({});
|
|
1004
1004
|
// TODO: in the future, we should support insert type, but don't yet, since inserts are done outside
|
|
1005
1005
|
// the query class for some reason.
|
|
1006
|
-
default:
|
|
1007
|
-
|
|
1006
|
+
default: {
|
|
1007
|
+
// protection so that if a new QueryType is ever added, this will throw a type error at build time
|
|
1008
|
+
const _never = type;
|
|
1009
|
+
throw new Error(`Unhandled QueryType: ${_never}`);
|
|
1010
|
+
}
|
|
1008
1011
|
}
|
|
1009
1012
|
}
|
|
1010
1013
|
/**
|
|
@@ -1452,7 +1455,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1452
1455
|
throw new CannotPaginateWithOffset_js_1.default();
|
|
1453
1456
|
const page = (0, computedPaginatePage_js_1.default)(opts.page);
|
|
1454
1457
|
const recordCount = await this.count();
|
|
1455
|
-
const pageSize = opts.pageSize ||
|
|
1458
|
+
const pageSize = opts.pageSize || index_js_1.default.getOrFail().paginationPageSize;
|
|
1456
1459
|
const pageCount = Math.ceil(recordCount / pageSize);
|
|
1457
1460
|
const results = await this.limit(pageSize)
|
|
1458
1461
|
.offset((page - 1) * pageSize)
|
|
@@ -1974,7 +1977,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1974
1977
|
pluckedData[dreamClassToHydrateColumns.length + index]));
|
|
1975
1978
|
return {
|
|
1976
1979
|
dream: hydratedDream,
|
|
1977
|
-
pointsToPrimaryKey: pluckedData
|
|
1980
|
+
pointsToPrimaryKey: pluckedData.at(-1),
|
|
1978
1981
|
};
|
|
1979
1982
|
});
|
|
1980
1983
|
this.hydrateAssociation(dreams, association, preloadedDreamsAndWhatTheyPointTo);
|
|
@@ -2480,7 +2483,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2480
2483
|
val = val();
|
|
2481
2484
|
}
|
|
2482
2485
|
else if (val === constants_js_1.DreamConst.passthrough) {
|
|
2483
|
-
const column = attr.split('.').
|
|
2486
|
+
const column = attr.split('.').at(-1);
|
|
2484
2487
|
if (this.passthroughOnStatement[column] === undefined)
|
|
2485
2488
|
throw new MissingRequiredPassthroughForAssociationAndClause_js_1.default(column);
|
|
2486
2489
|
val = this.passthroughOnStatement[column];
|
|
@@ -14,25 +14,23 @@ exports.DreamConst = {
|
|
|
14
14
|
required: RequiredAttribute,
|
|
15
15
|
};
|
|
16
16
|
exports.openapiPrimitiveTypes = [
|
|
17
|
-
'string',
|
|
18
17
|
'boolean',
|
|
19
|
-
'number',
|
|
20
|
-
'date',
|
|
21
18
|
'date-time',
|
|
22
|
-
'
|
|
19
|
+
'date',
|
|
23
20
|
'integer',
|
|
24
21
|
'null',
|
|
22
|
+
'number',
|
|
23
|
+
'string',
|
|
25
24
|
];
|
|
26
25
|
exports.openapiShorthandPrimitiveTypes = [
|
|
27
26
|
...exports.openapiPrimitiveTypes,
|
|
28
|
-
'decimal',
|
|
29
|
-
'string[]',
|
|
30
27
|
'boolean[]',
|
|
31
|
-
'number[]',
|
|
32
|
-
'date[]',
|
|
33
28
|
'date-time[]',
|
|
29
|
+
'date[]',
|
|
30
|
+
'decimal',
|
|
34
31
|
'decimal[]',
|
|
35
|
-
'double[]',
|
|
36
32
|
'integer[]',
|
|
37
33
|
'json',
|
|
34
|
+
'number[]',
|
|
35
|
+
'string[]',
|
|
38
36
|
];
|
|
@@ -50,8 +50,11 @@ function checkSingleValidation(dream, validation) {
|
|
|
50
50
|
if (associationMetadata === undefined)
|
|
51
51
|
throw new UnexpectedUndefined_js_1.default();
|
|
52
52
|
return !!(value || dream[associationMetadata.foreignKey()]);
|
|
53
|
-
default:
|
|
54
|
-
|
|
53
|
+
default: {
|
|
54
|
+
// protection so that if a new ValidationType is ever added, this will throw a type error at build time
|
|
55
|
+
const _never = validation.type;
|
|
56
|
+
throw new Error(`Unhandled ValidationType: ${_never}`);
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
function isBlank(value) {
|
|
@@ -9,7 +9,7 @@ async function findOrCreateBy(dreamClass, txn = null, attributes, extraOpts = {}
|
|
|
9
9
|
return existingRecord;
|
|
10
10
|
const dreamModel = dreamClass.new({
|
|
11
11
|
...attributes,
|
|
12
|
-
...
|
|
12
|
+
...extraOpts?.createWith,
|
|
13
13
|
});
|
|
14
14
|
await dreamModel.txn(txn).save();
|
|
15
15
|
return dreamModel;
|
|
@@ -9,7 +9,10 @@ function orderByDirection(dir) {
|
|
|
9
9
|
return (0, kysely_1.sql) `asc nulls first`;
|
|
10
10
|
case 'desc':
|
|
11
11
|
return (0, kysely_1.sql) `desc nulls last`;
|
|
12
|
-
default:
|
|
13
|
-
|
|
12
|
+
default: {
|
|
13
|
+
// protection so that if a new OrderDir is ever added, this will throw a type error at build time
|
|
14
|
+
const _never = dir;
|
|
15
|
+
throw new Error(`Unhandled OrderDir: ${_never}`);
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
}
|
|
@@ -31,11 +31,11 @@ class DreamImporter {
|
|
|
31
31
|
}
|
|
32
32
|
static async importSerializers(pathToSerializers, importCb) {
|
|
33
33
|
const serializerPaths = await DreamImporter.ls(pathToSerializers);
|
|
34
|
-
const
|
|
34
|
+
const pathsNamesAndSerializers = (await Promise.all(serializerPaths.map(serializerPath => importCb(serializerPath).then(serializerClass => [
|
|
35
35
|
serializerPath,
|
|
36
36
|
serializerClass,
|
|
37
37
|
]))));
|
|
38
|
-
return
|
|
38
|
+
return pathsNamesAndSerializers;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.default = DreamImporter;
|
|
@@ -73,7 +73,7 @@ function setCachedModels(models) {
|
|
|
73
73
|
}
|
|
74
74
|
function getModelsOrFail() {
|
|
75
75
|
if (!_models)
|
|
76
|
-
throw new Error('Must call
|
|
76
|
+
throw new Error('Must call importModels before calling getModelsOrFail');
|
|
77
77
|
return _models;
|
|
78
78
|
}
|
|
79
79
|
function getModelsOrBlank() {
|
|
@@ -5,7 +5,7 @@ exports.setCachedSerializers = setCachedSerializers;
|
|
|
5
5
|
exports.getSerializersOrFail = getSerializersOrFail;
|
|
6
6
|
exports.getSerializersOrBlank = getSerializersOrBlank;
|
|
7
7
|
const SerializerNameConflict_js_1 = require("../../../errors/dream-app/SerializerNameConflict.js");
|
|
8
|
-
const
|
|
8
|
+
const isDreamSerializer_js_1 = require("../../../serializer/helpers/isDreamSerializer.js");
|
|
9
9
|
const DreamImporter_js_1 = require("../DreamImporter.js");
|
|
10
10
|
const globalSerializerKeyFromPath_js_1 = require("../globalSerializerKeyFromPath.js");
|
|
11
11
|
let _serializers;
|
|
@@ -13,41 +13,20 @@ async function importSerializers(serializersPath, serializerImportCb) {
|
|
|
13
13
|
if (_serializers)
|
|
14
14
|
return _serializers;
|
|
15
15
|
const serializerClasses = await DreamImporter_js_1.default.importSerializers(serializersPath, serializerImportCb);
|
|
16
|
-
/**
|
|
17
|
-
* Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
|
|
18
|
-
* need static access to things set up by decorators. Stage 3 Decorators change the context that is available
|
|
19
|
-
* at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
|
|
20
|
-
* to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
|
|
21
|
-
*/
|
|
22
|
-
index_js_1.default['globallyInitializingDecorators'] = true;
|
|
23
16
|
_serializers = {};
|
|
24
17
|
for (const [serializerPath, allSerializers] of serializerClasses) {
|
|
25
18
|
Object.keys(allSerializers).forEach(key => {
|
|
26
19
|
const potentialSerializer = allSerializers[key];
|
|
27
|
-
if (potentialSerializer
|
|
20
|
+
if (potentialSerializer && (0, isDreamSerializer_js_1.default)(potentialSerializer)) {
|
|
28
21
|
const serializerKey = (0, globalSerializerKeyFromPath_js_1.default)(serializerPath, serializersPath, key);
|
|
29
22
|
if (_serializers[serializerKey])
|
|
30
23
|
throw new SerializerNameConflict_js_1.default(serializerKey);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
|
|
35
|
-
* need static access to things set up by decorators. Stage 3 Decorators change the context that is available
|
|
36
|
-
* at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
|
|
37
|
-
* to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
|
|
38
|
-
*/
|
|
39
|
-
new serializerClass({});
|
|
24
|
+
const serializer = potentialSerializer;
|
|
25
|
+
serializer['globalName'] = serializerKey;
|
|
40
26
|
_serializers[serializerKey] = potentialSerializer;
|
|
41
27
|
}
|
|
42
28
|
});
|
|
43
29
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
|
|
46
|
-
* need static access to things set up by decorators. Stage 3 Decorators change the context that is available
|
|
47
|
-
* at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
|
|
48
|
-
* to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
|
|
49
|
-
*/
|
|
50
|
-
index_js_1.default['globallyInitializingDecorators'] = false;
|
|
51
30
|
return _serializers;
|
|
52
31
|
}
|
|
53
32
|
function setCachedSerializers(serializers) {
|
|
@@ -55,7 +34,7 @@ function setCachedSerializers(serializers) {
|
|
|
55
34
|
}
|
|
56
35
|
function getSerializersOrFail() {
|
|
57
36
|
if (!_serializers)
|
|
58
|
-
throw new Error('Must call
|
|
37
|
+
throw new Error('Must call importSerializers before calling getSerializersOrFail');
|
|
59
38
|
return _serializers;
|
|
60
39
|
}
|
|
61
40
|
function getSerializersOrBlank() {
|
|
@@ -317,8 +317,11 @@ Try setting it to something valid, like:
|
|
|
317
317
|
case 'paginationPageSize':
|
|
318
318
|
this._paginationPageSize = options;
|
|
319
319
|
break;
|
|
320
|
-
default:
|
|
321
|
-
|
|
320
|
+
default: {
|
|
321
|
+
// protection so that if a new ApplyOpt is ever added, this will throw a type error at build time
|
|
322
|
+
const _never = applyOption;
|
|
323
|
+
throw new Error(`Unhandled ApplyOpt: ${_never}`);
|
|
324
|
+
}
|
|
322
325
|
}
|
|
323
326
|
}
|
|
324
327
|
on(hookEventType, cb) {
|
|
@@ -15,8 +15,11 @@ class Encrypt {
|
|
|
15
15
|
case 'aes-192-gcm':
|
|
16
16
|
case 'aes-128-gcm':
|
|
17
17
|
return (0, encryptAESGCM_js_1.default)(algorithm, data, key);
|
|
18
|
-
default:
|
|
19
|
-
|
|
18
|
+
default: {
|
|
19
|
+
// protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
|
|
20
|
+
const _never = algorithm;
|
|
21
|
+
throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
static decrypt(encrypted, { algorithm, key }, legacyOpts) {
|
|
@@ -36,8 +39,11 @@ class Encrypt {
|
|
|
36
39
|
catch {
|
|
37
40
|
return null;
|
|
38
41
|
}
|
|
39
|
-
default:
|
|
40
|
-
|
|
42
|
+
default: {
|
|
43
|
+
// protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
|
|
44
|
+
const _never = algorithm;
|
|
45
|
+
throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
static attemptDecryptionWithLegacyKeys(encrypted, { algorithm, key }, legacyOpts) {
|
|
@@ -54,8 +60,11 @@ class Encrypt {
|
|
|
54
60
|
return (0, generateKeyAESGCM_js_1.default)(192);
|
|
55
61
|
case 'aes-128-gcm':
|
|
56
62
|
return (0, generateKeyAESGCM_js_1.default)(128);
|
|
57
|
-
default:
|
|
58
|
-
|
|
63
|
+
default: {
|
|
64
|
+
// protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
|
|
65
|
+
const _never = algorithm;
|
|
66
|
+
throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
static validateKey(base64EncodedKey, algorithm) {
|
|
@@ -66,8 +75,11 @@ class Encrypt {
|
|
|
66
75
|
return (0, validateKeyAESGCM_js_1.default)(base64EncodedKey, 192);
|
|
67
76
|
case 'aes-128-gcm':
|
|
68
77
|
return (0, validateKeyAESGCM_js_1.default)(base64EncodedKey, 128);
|
|
69
|
-
default:
|
|
70
|
-
|
|
78
|
+
default: {
|
|
79
|
+
// protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
|
|
80
|
+
const _never = algorithm;
|
|
81
|
+
throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
|
|
82
|
+
}
|
|
71
83
|
}
|
|
72
84
|
}
|
|
73
85
|
}
|
package/dist/cjs/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_util_1 = require("node:util");
|
|
4
|
+
class AttemptedToDeriveDescendentSerializersFromNonSerializer extends Error {
|
|
5
|
+
serializer;
|
|
6
|
+
constructor(serializer) {
|
|
7
|
+
super();
|
|
8
|
+
this.serializer = serializer;
|
|
9
|
+
}
|
|
10
|
+
get message() {
|
|
11
|
+
return `
|
|
12
|
+
Attempted to derive descendent serializers from non serializer:
|
|
13
|
+
${(0, node_util_1.inspect)(this.serializer)}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = AttemptedToDeriveDescendentSerializersFromNonSerializer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class DelegationTargetDoesNotExist extends Error {
|
|
4
|
+
delegationTarget;
|
|
5
|
+
constructor(delegationTarget) {
|
|
6
|
+
super();
|
|
7
|
+
this.delegationTarget = delegationTarget;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
return `Attempted to delegate to \`${this.delegationTarget}\`, but \`${this.delegationTarget}\` does not exist.`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = DelegationTargetDoesNotExist;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class MissingSerializersDefinition extends Error {
|
|
4
|
+
viewModel;
|
|
5
|
+
constructor(viewModel) {
|
|
6
|
+
super();
|
|
7
|
+
this.viewModel = viewModel;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
const className = this.viewModel?.sanitizedConstructorName ?? this.viewModel.constructor.name;
|
|
11
|
+
return `
|
|
12
|
+
Missing serializers definition on class \`${className}\`
|
|
13
|
+
|
|
14
|
+
Try something like this in your ${className}'s serializer getter:
|
|
15
|
+
|
|
16
|
+
class ${className} {
|
|
17
|
+
public get serializers(): DreamSerializers<${className}> {
|
|
18
|
+
return {
|
|
19
|
+
default: '${className}Serializer'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
...
|
|
23
|
+
}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = MissingSerializersDefinition;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class MissingSerializersDefinitionForKey extends Error {
|
|
4
|
+
viewModel;
|
|
5
|
+
serializerKey;
|
|
6
|
+
constructor(viewModel, serializerKey) {
|
|
7
|
+
super();
|
|
8
|
+
this.viewModel = viewModel;
|
|
9
|
+
this.serializerKey = serializerKey;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
const className = this.viewModel?.sanitizedConstructorName ?? this.viewModel.constructor.name;
|
|
13
|
+
return `
|
|
14
|
+
Missing serializers definition for \`${this.serializerKey}\` on class \`${className}\`
|
|
15
|
+
|
|
16
|
+
Try something like this in your ${className}'s serializer getter:
|
|
17
|
+
|
|
18
|
+
class ${className} {
|
|
19
|
+
public get serializers(): DreamSerializers<${className}> {
|
|
20
|
+
return {
|
|
21
|
+
default: '${className}Serializer'
|
|
22
|
+
${this.serializerKey}: '<the_global_name_of_a_serializer>'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
...
|
|
26
|
+
}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = MissingSerializersDefinitionForKey;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class NoGlobalSerializerForSpecifiedKey extends Error {
|
|
4
|
+
viewModel;
|
|
5
|
+
serializerKey;
|
|
6
|
+
globalName;
|
|
7
|
+
constructor(viewModel, serializerKey, globalName) {
|
|
8
|
+
super();
|
|
9
|
+
this.viewModel = viewModel;
|
|
10
|
+
this.serializerKey = serializerKey;
|
|
11
|
+
this.globalName = globalName;
|
|
12
|
+
}
|
|
13
|
+
get message() {
|
|
14
|
+
const className = this.viewModel?.sanitizedConstructorName ?? this.viewModel.constructor.name;
|
|
15
|
+
return `
|
|
16
|
+
${className} specified a global name of "${this.globalName}" for serializer key "${this.serializerKey}",
|
|
17
|
+
but no serializer corresponds to "${this.globalName}".
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = NoGlobalSerializerForSpecifiedKey;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class NoSerializerFoundForRendersOneAndMany extends Error {
|
|
4
|
+
associationName;
|
|
5
|
+
constructor(associationName) {
|
|
6
|
+
super();
|
|
7
|
+
this.associationName = associationName;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
return `
|
|
11
|
+
Attempted to render \`rendersOne\` / \`rendersMany\`
|
|
12
|
+
\`${this.associationName}\`, but could not locate a
|
|
13
|
+
serializer.`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = NoSerializerFoundForRendersOneAndMany;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_util_1 = require("node:util");
|
|
4
|
+
class NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey extends Error {
|
|
5
|
+
viewModel;
|
|
6
|
+
serializerKey;
|
|
7
|
+
globalName;
|
|
8
|
+
serializer;
|
|
9
|
+
constructor(viewModel, serializerKey, globalName, serializer) {
|
|
10
|
+
super();
|
|
11
|
+
this.viewModel = viewModel;
|
|
12
|
+
this.serializerKey = serializerKey;
|
|
13
|
+
this.globalName = globalName;
|
|
14
|
+
this.serializer = serializer;
|
|
15
|
+
}
|
|
16
|
+
get message() {
|
|
17
|
+
const className = this.viewModel?.sanitizedConstructorName ?? this.viewModel.constructor.name;
|
|
18
|
+
return `
|
|
19
|
+
${className} specified a global name of "${this.globalName}" for serializer key "${this.serializerKey}",
|
|
20
|
+
but the derived serializer is not a Dream serializer:
|
|
21
|
+
|
|
22
|
+
${(0, node_util_1.inspect)(this.serializer)}
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey;
|