@rvoh/dream 0.42.2 → 0.43.0-beta.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 +1 -1
- package/dist/cjs/src/Dream.js +55 -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/DreamClassTransactionBuilder.js +32 -0
- package/dist/cjs/src/dream/Query.js +61 -8
- 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/computedPaginatePage.js +10 -0
- 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 +12 -2
- package/dist/cjs/src/encrypt/index.js +20 -8
- package/dist/cjs/src/errors/pagination/CannotPaginateWithLimit.js +17 -0
- package/dist/cjs/src/errors/pagination/CannotPaginateWithOffset.js +17 -0
- 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 +29 -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 +194 -0
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +65 -0
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +63 -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 +55 -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/DreamClassTransactionBuilder.js +32 -0
- package/dist/esm/src/dream/Query.js +59 -6
- 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/computedPaginatePage.js +7 -0
- 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 +12 -2
- package/dist/esm/src/encrypt/index.js +20 -8
- package/dist/esm/src/errors/pagination/CannotPaginateWithLimit.js +14 -0
- package/dist/esm/src/errors/pagination/CannotPaginateWithOffset.js +14 -0
- 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 +13 -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 +191 -0
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +62 -0
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +60 -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 +48 -21
- 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/DreamClassTransactionBuilder.d.ts +31 -1
- package/dist/types/src/dream/Query.d.ts +29 -1
- package/dist/types/src/dream/constants.d.ts +2 -2
- package/dist/types/src/dream/internal/computedPaginatePage.d.ts +1 -0
- 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 +6 -4
- package/dist/types/src/errors/pagination/CannotPaginateWithLimit.d.ts +3 -0
- package/dist/types/src/errors/pagination/CannotPaginateWithOffset.d.ts +3 -0
- 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 +18 -11
- 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 +13 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +52 -0
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +52 -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/query.d.ts +28 -0
- package/dist/types/src/types/query.ts +34 -0
- 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 +220 -211
- package/docs/classes/DreamApp.html +5 -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 +17 -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 +16 -0
- package/docs/classes/Query.html +58 -50
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/SerializerOpenapiRenderer.html +6 -0
- package/docs/classes/SerializerRenderer.html +3 -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/index.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 +18 -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/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
> ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of
|
|
1
|
+
> ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of May 21st, 2025. This notice will be removed, and the version of this repo will be bumped to 1.0.0, once all of the repos have been migrated to the new spaces and we can verify that it is all working. This should happen sometime in the next month.
|
|
2
2
|
|
|
3
3
|
Dream is a typescript-driven, esm-first ORM built on top of [kysely](http://kysely.dev). It is built to operate within the [Psychic web framework](https://psychic-docs.netlify.app), but can be brought into other projects and used without the encapsulating framework (though this is theoretical, and we do not encourage it at this time). It is actively being developed to support production-grade applications in use within the [RVOHealth organization](https://www.rvohealth.com), who has kindly sponsored the continued development of this ORM, as well as the Psychic web framework as a whole.
|
|
4
4
|
|
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
|
*
|
|
@@ -596,6 +605,36 @@ class Dream {
|
|
|
596
605
|
static async all(options = {}) {
|
|
597
606
|
return await this.query().all(options);
|
|
598
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Paginates the results of your query, accepting a pageSize and page argument,
|
|
610
|
+
* which it uses to segment your query into pages, leveraging limit and offset
|
|
611
|
+
* to deliver your query to you in pages.
|
|
612
|
+
*
|
|
613
|
+
* ```ts
|
|
614
|
+
* const paginated = await User.paginate({ pageSize: 100, page: 2 })
|
|
615
|
+
* paginated.results
|
|
616
|
+
* // [ { User{id: 101}, User{id: 102}, ...}]
|
|
617
|
+
*
|
|
618
|
+
* paginated.recordCount
|
|
619
|
+
* // 350
|
|
620
|
+
*
|
|
621
|
+
* paginated.pageCount
|
|
622
|
+
* // 4
|
|
623
|
+
*
|
|
624
|
+
* paginated.currentPage
|
|
625
|
+
* // 2
|
|
626
|
+
* ```
|
|
627
|
+
*
|
|
628
|
+
* @param opts.page - the page number that you want to fetch results for
|
|
629
|
+
* @param opts.pageSize - the number of results per page (optional)
|
|
630
|
+
* @returns results.recordCount - A number representing the total number of records matching your query
|
|
631
|
+
* @returns results.pageCount - The number of pages needed to encapsulate all the matching records
|
|
632
|
+
* @returns results.currentPage - The current page (same as what is provided in the paginate args)
|
|
633
|
+
* @returns results.results - An array of records matching the current record
|
|
634
|
+
*/
|
|
635
|
+
static async paginate(opts) {
|
|
636
|
+
return await this.query().paginate(opts);
|
|
637
|
+
}
|
|
599
638
|
/**
|
|
600
639
|
* Forces use of a database connection (e.g. 'primary') during the query.
|
|
601
640
|
*
|
|
@@ -690,7 +729,7 @@ class Dream {
|
|
|
690
729
|
try {
|
|
691
730
|
const dreamModel = this.new({
|
|
692
731
|
...attributes,
|
|
693
|
-
...
|
|
732
|
+
...extraOpts?.createWith,
|
|
694
733
|
});
|
|
695
734
|
await dreamModel.save();
|
|
696
735
|
return dreamModel;
|
|
@@ -744,7 +783,7 @@ class Dream {
|
|
|
744
783
|
try {
|
|
745
784
|
return await this.create({
|
|
746
785
|
...attributes,
|
|
747
|
-
...
|
|
786
|
+
...extraOpts?.with,
|
|
748
787
|
}, skipHooks ? { skipHooks } : undefined);
|
|
749
788
|
}
|
|
750
789
|
catch (err) {
|
|
@@ -2112,6 +2151,17 @@ class Dream {
|
|
|
2112
2151
|
*/
|
|
2113
2152
|
this.unshadowColumnPropertyPrototypeAccessors();
|
|
2114
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
|
+
}
|
|
2115
2165
|
/**
|
|
2116
2166
|
* Returns true if the columnName passed is marked by a
|
|
2117
2167
|
* Virtual attribute decorator
|
|
@@ -2120,9 +2170,7 @@ class Dream {
|
|
|
2120
2170
|
* @returns A boolean
|
|
2121
2171
|
*/
|
|
2122
2172
|
isVirtualColumn(columnName) {
|
|
2123
|
-
return this.constructor.virtualAttributes
|
|
2124
|
-
.map(attr => attr.property)
|
|
2125
|
-
.includes(columnName);
|
|
2173
|
+
return !!this.constructor.virtualAttributes.find(attr => attr.property === columnName);
|
|
2126
2174
|
}
|
|
2127
2175
|
/**
|
|
2128
2176
|
* Returns an object with column names for keys, and an
|
|
@@ -2896,31 +2944,6 @@ class Dream {
|
|
|
2896
2944
|
async reload() {
|
|
2897
2945
|
await (0, reload_js_1.default)(this);
|
|
2898
2946
|
}
|
|
2899
|
-
/**
|
|
2900
|
-
* Serializes an instance. You can specify a serializer key,
|
|
2901
|
-
* or else the default will be used
|
|
2902
|
-
*
|
|
2903
|
-
* ```ts
|
|
2904
|
-
* // uses the default serializer provided in the model's `serializers` getter
|
|
2905
|
-
* await user.serialize()
|
|
2906
|
-
*
|
|
2907
|
-
* // uses the summary serializer provided in the model's `serializers` getter
|
|
2908
|
-
* await user.serialize({ serializerKey: 'summary' })
|
|
2909
|
-
* ```
|
|
2910
|
-
*
|
|
2911
|
-
* @param args.casing - Which casing to use when serializing (camel or snake, default camel)
|
|
2912
|
-
* @param args.serializerKey - The key to use when referencing the object returned by the `serializers` getter on the given model instance (defaults to "default")
|
|
2913
|
-
* @returns A serialized representation of the model
|
|
2914
|
-
*/
|
|
2915
|
-
serialize({ casing = null, serializerKey } = {}) {
|
|
2916
|
-
const serializerClass = (0, inferSerializerFromDreamOrViewModel_js_1.default)(this, serializerKey?.toString());
|
|
2917
|
-
if (!serializerClass)
|
|
2918
|
-
throw new MissingSerializersDefinition_js_1.default(this.constructor);
|
|
2919
|
-
const serializer = new serializerClass(this);
|
|
2920
|
-
if (casing)
|
|
2921
|
-
serializer.casing(casing);
|
|
2922
|
-
return serializer.render();
|
|
2923
|
-
}
|
|
2924
2947
|
/**
|
|
2925
2948
|
* Takes the attributes passed in and sets their values,
|
|
2926
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 {
|
|
@@ -38,6 +38,38 @@ class DreamClassTransactionBuilder {
|
|
|
38
38
|
async all(options = {}) {
|
|
39
39
|
return this.queryInstance().all(options);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Paginates the results of your query, accepting a pageSize and page argument,
|
|
43
|
+
* which it uses to segment your query into pages, leveraging limit and offset
|
|
44
|
+
* to deliver your query to you in pages.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* await ApplicationModel.transaction(async txn => {
|
|
48
|
+
* const paginated = await User.txn(txn).paginate({ pageSize: 100, page: 2 })
|
|
49
|
+
* paginated.results
|
|
50
|
+
* // [ { User{id: 101}, User{id: 102}, ...}]
|
|
51
|
+
*
|
|
52
|
+
* paginated.recordCount
|
|
53
|
+
* // 350
|
|
54
|
+
*
|
|
55
|
+
* paginated.pageCount
|
|
56
|
+
* // 4
|
|
57
|
+
*
|
|
58
|
+
* paginated.currentPage
|
|
59
|
+
* // 2
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @param opts.page - the page number that you want to fetch results for
|
|
64
|
+
* @param opts.pageSize - the number of results per page (optional)
|
|
65
|
+
* @returns results.recordCount - A number representing the total number of records matching your query
|
|
66
|
+
* @returns results.pageCount - The number of pages needed to encapsulate all the matching records
|
|
67
|
+
* @returns results.currentPage - The current page (same as what is provided in the paginate args)
|
|
68
|
+
* @returns results.results - An array of records matching the current record
|
|
69
|
+
*/
|
|
70
|
+
async paginate(opts) {
|
|
71
|
+
return await this.queryInstance().paginate(opts);
|
|
72
|
+
}
|
|
41
73
|
/**
|
|
42
74
|
* Retrieves the number of records corresponding
|
|
43
75
|
* to this model.
|
|
@@ -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,9 +41,10 @@ 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");
|
|
@@ -297,7 +301,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
297
301
|
baseSelectQuery: opts.baseSelectQuery || this.baseSelectQuery,
|
|
298
302
|
passthroughOnStatement: {
|
|
299
303
|
...this.passthroughOnStatement,
|
|
300
|
-
...
|
|
304
|
+
...opts.passthroughOnStatement,
|
|
301
305
|
},
|
|
302
306
|
where: opts.where === null ? [] : [...this.whereStatements, ...(opts.where || [])],
|
|
303
307
|
whereNot: opts.whereNot === null ? [] : [...this.whereNotStatements, ...(opts.whereNot || [])],
|
|
@@ -438,13 +442,13 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
438
442
|
let lastId = null;
|
|
439
443
|
do {
|
|
440
444
|
if (lastId)
|
|
441
|
-
records = await query.where({ [this.dreamInstance.primaryKey]:
|
|
445
|
+
records = await query.where({ [this.dreamInstance.primaryKey]: index_js_2.default.greaterThan(lastId) }).all();
|
|
442
446
|
else
|
|
443
447
|
records = await query.all();
|
|
444
448
|
for (const record of records) {
|
|
445
449
|
await cb(record);
|
|
446
450
|
}
|
|
447
|
-
lastId = records
|
|
451
|
+
lastId = records.at(-1)?.primaryKeyValue;
|
|
448
452
|
} while (records.length > 0 && records.length === batchSize);
|
|
449
453
|
}
|
|
450
454
|
/**
|
|
@@ -999,8 +1003,11 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
999
1003
|
return this.buildUpdate({});
|
|
1000
1004
|
// TODO: in the future, we should support insert type, but don't yet, since inserts are done outside
|
|
1001
1005
|
// the query class for some reason.
|
|
1002
|
-
default:
|
|
1003
|
-
|
|
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
|
+
}
|
|
1004
1011
|
}
|
|
1005
1012
|
}
|
|
1006
1013
|
/**
|
|
@@ -1414,6 +1421,52 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1414
1421
|
await this.applyPreload(this.preloadStatements, this.preloadOnStatements, theAll);
|
|
1415
1422
|
return theAll;
|
|
1416
1423
|
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Paginates the results of your query, accepting a pageSize and page argument,
|
|
1426
|
+
* which it uses to segment your query into pages, leveraging limit and offset
|
|
1427
|
+
* to deliver your query to you in pages.
|
|
1428
|
+
*
|
|
1429
|
+
* ```ts
|
|
1430
|
+
* const paginated = await User.order('email').paginate({ pageSize: 100, page: 2 })
|
|
1431
|
+
* paginated.results
|
|
1432
|
+
* // [ { User{id: 101}, User{id: 102}, ...}]
|
|
1433
|
+
*
|
|
1434
|
+
* paginated.recordCount
|
|
1435
|
+
* // 350
|
|
1436
|
+
*
|
|
1437
|
+
* paginated.pageCount
|
|
1438
|
+
* // 4
|
|
1439
|
+
*
|
|
1440
|
+
* paginated.currentPage
|
|
1441
|
+
* // 2
|
|
1442
|
+
* ```
|
|
1443
|
+
*
|
|
1444
|
+
* @param opts.page - the page number that you want to fetch results for
|
|
1445
|
+
* @param opts.pageSize - the number of results per page (optional)
|
|
1446
|
+
* @returns results.recordCount - A number representing the total number of records matching your query
|
|
1447
|
+
* @returns results.pageCount - The number of pages needed to encapsulate all the matching records
|
|
1448
|
+
* @returns results.currentPage - The current page (same as what is provided in the paginate args)
|
|
1449
|
+
* @returns results.results - An array of records matching the current record
|
|
1450
|
+
*/
|
|
1451
|
+
async paginate(opts) {
|
|
1452
|
+
if (this.limitStatement)
|
|
1453
|
+
throw new CannotPaginateWithLimit_js_1.default();
|
|
1454
|
+
if (this.offsetStatement)
|
|
1455
|
+
throw new CannotPaginateWithOffset_js_1.default();
|
|
1456
|
+
const page = (0, computedPaginatePage_js_1.default)(opts.page);
|
|
1457
|
+
const recordCount = await this.count();
|
|
1458
|
+
const pageSize = opts.pageSize || index_js_1.default.getOrFail().paginationPageSize;
|
|
1459
|
+
const pageCount = Math.ceil(recordCount / pageSize);
|
|
1460
|
+
const results = await this.limit(pageSize)
|
|
1461
|
+
.offset((page - 1) * pageSize)
|
|
1462
|
+
.all();
|
|
1463
|
+
return {
|
|
1464
|
+
recordCount,
|
|
1465
|
+
pageCount,
|
|
1466
|
+
currentPage: page,
|
|
1467
|
+
results,
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1417
1470
|
/**
|
|
1418
1471
|
* Forces use of a database connection (e.g. 'primary') during the query.
|
|
1419
1472
|
*
|
|
@@ -1924,7 +1977,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1924
1977
|
pluckedData[dreamClassToHydrateColumns.length + index]));
|
|
1925
1978
|
return {
|
|
1926
1979
|
dream: hydratedDream,
|
|
1927
|
-
pointsToPrimaryKey: pluckedData
|
|
1980
|
+
pointsToPrimaryKey: pluckedData.at(-1),
|
|
1928
1981
|
};
|
|
1929
1982
|
});
|
|
1930
1983
|
this.hydrateAssociation(dreams, association, preloadedDreamsAndWhatTheyPointTo);
|
|
@@ -2430,7 +2483,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2430
2483
|
val = val();
|
|
2431
2484
|
}
|
|
2432
2485
|
else if (val === constants_js_1.DreamConst.passthrough) {
|
|
2433
|
-
const column = attr.split('.').
|
|
2486
|
+
const column = attr.split('.').at(-1);
|
|
2434
2487
|
if (this.passthroughOnStatement[column] === undefined)
|
|
2435
2488
|
throw new MissingRequiredPassthroughForAssociationAndClause_js_1.default(column);
|
|
2436
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) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = computedPaginatePage;
|
|
4
|
+
function computedPaginatePage(page) {
|
|
5
|
+
if (page === null)
|
|
6
|
+
return 1;
|
|
7
|
+
if (page === undefined)
|
|
8
|
+
return 1;
|
|
9
|
+
return page <= 1 ? 1 : Math.floor(page);
|
|
10
|
+
}
|
|
@@ -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() {
|
|
@@ -179,6 +179,10 @@ Try setting it to something valid, like:
|
|
|
179
179
|
get unicodeNormalization() {
|
|
180
180
|
return this._unicodeNormalization;
|
|
181
181
|
}
|
|
182
|
+
_paginationPageSize = 25;
|
|
183
|
+
get paginationPageSize() {
|
|
184
|
+
return this._paginationPageSize;
|
|
185
|
+
}
|
|
182
186
|
_primaryKeyType = 'bigserial';
|
|
183
187
|
get primaryKeyType() {
|
|
184
188
|
return this._primaryKeyType;
|
|
@@ -310,8 +314,14 @@ Try setting it to something valid, like:
|
|
|
310
314
|
case 'unicodeNormalization':
|
|
311
315
|
this._unicodeNormalization = options;
|
|
312
316
|
break;
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
case 'paginationPageSize':
|
|
318
|
+
this._paginationPageSize = options;
|
|
319
|
+
break;
|
|
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
|
+
}
|
|
315
325
|
}
|
|
316
326
|
}
|
|
317
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
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CannotPaginateWithLimit extends Error {
|
|
4
|
+
get message() {
|
|
5
|
+
return `\
|
|
6
|
+
Cannot call paginate on a query which has a limit applied.
|
|
7
|
+
|
|
8
|
+
Limit statements are automatically generated by the paginate method,
|
|
9
|
+
and adding custom limits interferes with paginate's ability to provide
|
|
10
|
+
a total count.
|
|
11
|
+
|
|
12
|
+
fix:
|
|
13
|
+
remove the limit statement from your query
|
|
14
|
+
`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = CannotPaginateWithLimit;
|