@warlock.js/cascade 4.0.30 → 4.0.39
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/cjs/index.js +15 -1
- package/cjs/index.js.map +1 -1
- package/esm/index.js +15 -1
- package/esm/index.js.map +1 -1
- package/package.json +52 -61
- package/cjs/aggregate/DeselectPipeline.d.ts +0 -10
- package/cjs/aggregate/DeselectPipeline.d.ts.map +0 -1
- package/cjs/aggregate/DeselectPipeline.js +0 -17
- package/cjs/aggregate/DeselectPipeline.js.map +0 -1
- package/cjs/aggregate/GeoNearPipeline.d.ts +0 -34
- package/cjs/aggregate/GeoNearPipeline.d.ts.map +0 -1
- package/cjs/aggregate/GeoNearPipeline.js +0 -44
- package/cjs/aggregate/GeoNearPipeline.js.map +0 -1
- package/cjs/aggregate/GroupByPipeline.d.ts +0 -12
- package/cjs/aggregate/GroupByPipeline.d.ts.map +0 -1
- package/cjs/aggregate/GroupByPipeline.js +0 -28
- package/cjs/aggregate/GroupByPipeline.js.map +0 -1
- package/cjs/aggregate/LimitPipeline.d.ts +0 -10
- package/cjs/aggregate/LimitPipeline.d.ts.map +0 -1
- package/cjs/aggregate/LimitPipeline.js +0 -14
- package/cjs/aggregate/LimitPipeline.js.map +0 -1
- package/cjs/aggregate/LookupPipeline.d.ts +0 -19
- package/cjs/aggregate/LookupPipeline.d.ts.map +0 -1
- package/cjs/aggregate/LookupPipeline.js +0 -23
- package/cjs/aggregate/LookupPipeline.js.map +0 -1
- package/cjs/aggregate/OrWherePipeline.d.ts +0 -21
- package/cjs/aggregate/OrWherePipeline.d.ts.map +0 -1
- package/cjs/aggregate/OrWherePipeline.js +0 -63
- package/cjs/aggregate/OrWherePipeline.js.map +0 -1
- package/cjs/aggregate/SelectPipeline.d.ts +0 -10
- package/cjs/aggregate/SelectPipeline.d.ts.map +0 -1
- package/cjs/aggregate/SelectPipeline.js +0 -26
- package/cjs/aggregate/SelectPipeline.js.map +0 -1
- package/cjs/aggregate/SkipPipeline.d.ts +0 -10
- package/cjs/aggregate/SkipPipeline.d.ts.map +0 -1
- package/cjs/aggregate/SkipPipeline.js +0 -14
- package/cjs/aggregate/SkipPipeline.js.map +0 -1
- package/cjs/aggregate/SortByPipeline.d.ts +0 -10
- package/cjs/aggregate/SortByPipeline.d.ts.map +0 -1
- package/cjs/aggregate/SortByPipeline.js +0 -18
- package/cjs/aggregate/SortByPipeline.js.map +0 -1
- package/cjs/aggregate/SortPipeline.d.ts +0 -11
- package/cjs/aggregate/SortPipeline.d.ts.map +0 -1
- package/cjs/aggregate/SortPipeline.js +0 -18
- package/cjs/aggregate/SortPipeline.js.map +0 -1
- package/cjs/aggregate/SortRandomPipeline.d.ts +0 -10
- package/cjs/aggregate/SortRandomPipeline.d.ts.map +0 -1
- package/cjs/aggregate/SortRandomPipeline.js +0 -16
- package/cjs/aggregate/SortRandomPipeline.js.map +0 -1
- package/cjs/aggregate/UnwindPipeline.d.ts +0 -14
- package/cjs/aggregate/UnwindPipeline.d.ts.map +0 -1
- package/cjs/aggregate/UnwindPipeline.js +0 -19
- package/cjs/aggregate/UnwindPipeline.js.map +0 -1
- package/cjs/aggregate/WhereExpression.d.ts +0 -17
- package/cjs/aggregate/WhereExpression.d.ts.map +0 -1
- package/cjs/aggregate/WhereExpression.js +0 -149
- package/cjs/aggregate/WhereExpression.js.map +0 -1
- package/cjs/aggregate/WhereExpressionPipeline.d.ts +0 -10
- package/cjs/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
- package/cjs/aggregate/WhereExpressionPipeline.js +0 -15
- package/cjs/aggregate/WhereExpressionPipeline.js.map +0 -1
- package/cjs/aggregate/WherePipeline.d.ts +0 -13
- package/cjs/aggregate/WherePipeline.d.ts.map +0 -1
- package/cjs/aggregate/WherePipeline.js +0 -12
- package/cjs/aggregate/WherePipeline.js.map +0 -1
- package/cjs/aggregate/aggregate.d.ts +0 -409
- package/cjs/aggregate/aggregate.d.ts.map +0 -1
- package/cjs/aggregate/aggregate.js +0 -911
- package/cjs/aggregate/aggregate.js.map +0 -1
- package/cjs/aggregate/expressions.d.ts +0 -361
- package/cjs/aggregate/expressions.d.ts.map +0 -1
- package/cjs/aggregate/expressions.js +0 -536
- package/cjs/aggregate/expressions.js.map +0 -1
- package/cjs/aggregate/filters/apply-filters.d.ts +0 -3
- package/cjs/aggregate/filters/apply-filters.d.ts.map +0 -1
- package/cjs/aggregate/filters/apply-filters.js +0 -75
- package/cjs/aggregate/filters/apply-filters.js.map +0 -1
- package/cjs/aggregate/filters/boolean-filters.d.ts +0 -3
- package/cjs/aggregate/filters/boolean-filters.d.ts.map +0 -1
- package/cjs/aggregate/filters/boolean-filters.js +0 -33
- package/cjs/aggregate/filters/boolean-filters.js.map +0 -1
- package/cjs/aggregate/filters/date-filters.d.ts +0 -3
- package/cjs/aggregate/filters/date-filters.d.ts.map +0 -1
- package/cjs/aggregate/filters/date-filters.js +0 -128
- package/cjs/aggregate/filters/date-filters.js.map +0 -1
- package/cjs/aggregate/filters/index.d.ts +0 -3
- package/cjs/aggregate/filters/index.d.ts.map +0 -1
- package/cjs/aggregate/filters/numeric-filters.d.ts +0 -3
- package/cjs/aggregate/filters/numeric-filters.d.ts.map +0 -1
- package/cjs/aggregate/filters/numeric-filters.js +0 -99
- package/cjs/aggregate/filters/numeric-filters.js.map +0 -1
- package/cjs/aggregate/filters/types.d.ts +0 -46
- package/cjs/aggregate/filters/types.d.ts.map +0 -1
- package/cjs/aggregate/filters/utils.d.ts +0 -13
- package/cjs/aggregate/filters/utils.d.ts.map +0 -1
- package/cjs/aggregate/filters/utils.js +0 -38
- package/cjs/aggregate/filters/utils.js.map +0 -1
- package/cjs/aggregate/index.d.ts +0 -21
- package/cjs/aggregate/index.d.ts.map +0 -1
- package/cjs/aggregate/parsePipelines.d.ts +0 -5
- package/cjs/aggregate/parsePipelines.d.ts.map +0 -1
- package/cjs/aggregate/parsePipelines.js +0 -6
- package/cjs/aggregate/parsePipelines.js.map +0 -1
- package/cjs/aggregate/pipeline.d.ts +0 -31
- package/cjs/aggregate/pipeline.d.ts.map +0 -1
- package/cjs/aggregate/pipeline.js +0 -42
- package/cjs/aggregate/pipeline.js.map +0 -1
- package/cjs/aggregate/types.d.ts +0 -8
- package/cjs/aggregate/types.d.ts.map +0 -1
- package/cjs/aggregate/types.js +0 -31
- package/cjs/aggregate/types.js.map +0 -1
- package/cjs/blueprint/blueprint-column.d.ts +0 -82
- package/cjs/blueprint/blueprint-column.d.ts.map +0 -1
- package/cjs/blueprint/blueprint.d.ts +0 -162
- package/cjs/blueprint/blueprint.d.ts.map +0 -1
- package/cjs/blueprint/blueprint.js +0 -340
- package/cjs/blueprint/blueprint.js.map +0 -1
- package/cjs/blueprint/index.d.ts +0 -3
- package/cjs/blueprint/index.d.ts.map +0 -1
- package/cjs/blueprint/model-blueprint.d.ts +0 -15
- package/cjs/blueprint/model-blueprint.d.ts.map +0 -1
- package/cjs/blueprint/model-blueprint.js +0 -16
- package/cjs/blueprint/model-blueprint.js.map +0 -1
- package/cjs/casts/arrayOf.d.ts +0 -5
- package/cjs/casts/arrayOf.d.ts.map +0 -1
- package/cjs/casts/arrayOf.js +0 -18
- package/cjs/casts/arrayOf.js.map +0 -1
- package/cjs/casts/cast-email.d.ts +0 -2
- package/cjs/casts/cast-email.d.ts.map +0 -1
- package/cjs/casts/cast-email.js +0 -5
- package/cjs/casts/cast-email.js.map +0 -1
- package/cjs/casts/castModel.d.ts +0 -3
- package/cjs/casts/castModel.d.ts.map +0 -1
- package/cjs/casts/castModel.js +0 -49
- package/cjs/casts/castModel.js.map +0 -1
- package/cjs/casts/expiresAfter.d.ts +0 -3
- package/cjs/casts/expiresAfter.d.ts.map +0 -1
- package/cjs/casts/expiresAfter.js +0 -5
- package/cjs/casts/expiresAfter.js.map +0 -1
- package/cjs/casts/index.d.ts +0 -9
- package/cjs/casts/index.d.ts.map +0 -1
- package/cjs/casts/oneOf.d.ts +0 -3
- package/cjs/casts/oneOf.d.ts.map +0 -1
- package/cjs/casts/oneOf.js +0 -22
- package/cjs/casts/oneOf.js.map +0 -1
- package/cjs/casts/random-string.d.ts +0 -2
- package/cjs/casts/random-string.d.ts.map +0 -1
- package/cjs/casts/random-string.js +0 -5
- package/cjs/casts/random-string.js.map +0 -1
- package/cjs/casts/randomInteger.d.ts +0 -2
- package/cjs/casts/randomInteger.d.ts.map +0 -1
- package/cjs/casts/randomInteger.js +0 -7
- package/cjs/casts/randomInteger.js.map +0 -1
- package/cjs/casts/shapedArray.d.ts +0 -26
- package/cjs/casts/shapedArray.d.ts.map +0 -1
- package/cjs/casts/shapedArray.js +0 -100
- package/cjs/casts/shapedArray.js.map +0 -1
- package/cjs/config.d.ts +0 -6
- package/cjs/config.d.ts.map +0 -1
- package/cjs/config.js +0 -16
- package/cjs/config.js.map +0 -1
- package/cjs/connection.d.ts +0 -49
- package/cjs/connection.d.ts.map +0 -1
- package/cjs/connection.js +0 -108
- package/cjs/connection.js.map +0 -1
- package/cjs/database.d.ts +0 -97
- package/cjs/database.d.ts.map +0 -1
- package/cjs/database.js +0 -164
- package/cjs/database.js.map +0 -1
- package/cjs/index.d.ts +0 -13
- package/cjs/index.d.ts.map +0 -1
- package/cjs/migration/index.d.ts +0 -4
- package/cjs/migration/index.d.ts.map +0 -1
- package/cjs/migration/migrate.d.ts +0 -13
- package/cjs/migration/migrate.d.ts.map +0 -1
- package/cjs/migration/migrate.js +0 -72
- package/cjs/migration/migrate.js.map +0 -1
- package/cjs/migration/migration-office.d.ts +0 -21
- package/cjs/migration/migration-office.d.ts.map +0 -1
- package/cjs/migration/migration-office.js +0 -39
- package/cjs/migration/migration-office.js.map +0 -1
- package/cjs/migration/migration-officer.d.ts +0 -33
- package/cjs/migration/migration-officer.d.ts.map +0 -1
- package/cjs/migration/migration-officer.js +0 -55
- package/cjs/migration/migration-officer.js.map +0 -1
- package/cjs/migration/types.d.ts +0 -34
- package/cjs/migration/types.d.ts.map +0 -1
- package/cjs/model/ModelAggregate.d.ts +0 -114
- package/cjs/model/ModelAggregate.d.ts.map +0 -1
- package/cjs/model/ModelAggregate.js +0 -182
- package/cjs/model/ModelAggregate.js.map +0 -1
- package/cjs/model/ModelSync.d.ts +0 -73
- package/cjs/model/ModelSync.d.ts.map +0 -1
- package/cjs/model/ModelSync.js +0 -215
- package/cjs/model/ModelSync.js.map +0 -1
- package/cjs/model/RelationshipWithMany.d.ts +0 -24
- package/cjs/model/RelationshipWithMany.d.ts.map +0 -1
- package/cjs/model/RelationshipWithMany.js +0 -42
- package/cjs/model/RelationshipWithMany.js.map +0 -1
- package/cjs/model/base-model.d.ts +0 -161
- package/cjs/model/base-model.d.ts.map +0 -1
- package/cjs/model/base-model.js +0 -265
- package/cjs/model/base-model.js.map +0 -1
- package/cjs/model/crud-model.d.ts +0 -122
- package/cjs/model/crud-model.d.ts.map +0 -1
- package/cjs/model/crud-model.js +0 -366
- package/cjs/model/crud-model.js.map +0 -1
- package/cjs/model/index.d.ts +0 -10
- package/cjs/model/index.d.ts.map +0 -1
- package/cjs/model/joinable.d.ts +0 -87
- package/cjs/model/joinable.d.ts.map +0 -1
- package/cjs/model/joinable.js +0 -158
- package/cjs/model/joinable.js.map +0 -1
- package/cjs/model/master-mind.d.ts +0 -44
- package/cjs/model/master-mind.d.ts.map +0 -1
- package/cjs/model/master-mind.js +0 -118
- package/cjs/model/master-mind.js.map +0 -1
- package/cjs/model/model-events.d.ts +0 -57
- package/cjs/model/model-events.d.ts.map +0 -1
- package/cjs/model/model-events.js +0 -102
- package/cjs/model/model-events.js.map +0 -1
- package/cjs/model/model.d.ts +0 -464
- package/cjs/model/model.d.ts.map +0 -1
- package/cjs/model/model.js +0 -1134
- package/cjs/model/model.js.map +0 -1
- package/cjs/model/types.d.ts +0 -149
- package/cjs/model/types.d.ts.map +0 -1
- package/cjs/model/types.js +0 -11
- package/cjs/model/types.js.map +0 -1
- package/cjs/query/index.d.ts +0 -2
- package/cjs/query/index.d.ts.map +0 -1
- package/cjs/query/query.d.ts +0 -218
- package/cjs/query/query.d.ts.map +0 -1
- package/cjs/query/query.js +0 -672
- package/cjs/query/query.js.map +0 -1
- package/cjs/query/types.d.ts +0 -60
- package/cjs/query/types.d.ts.map +0 -1
- package/cjs/types.d.ts +0 -75
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/connectToDatabase.d.ts +0 -3
- package/cjs/utils/connectToDatabase.d.ts.map +0 -1
- package/cjs/utils/connectToDatabase.js +0 -3
- package/cjs/utils/connectToDatabase.js.map +0 -1
- package/cjs/utils/deep-diff.d.ts +0 -9
- package/cjs/utils/deep-diff.d.ts.map +0 -1
- package/cjs/utils/deep-diff.js +0 -44
- package/cjs/utils/deep-diff.js.map +0 -1
- package/cjs/utils/dropAllDatabaseIndexes.d.ts +0 -2
- package/cjs/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
- package/cjs/utils/dropAllDatabaseIndexes.js +0 -10
- package/cjs/utils/dropAllDatabaseIndexes.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -6
- package/cjs/utils/index.d.ts.map +0 -1
- package/cjs/utils/joinable-proxy.d.ts +0 -3
- package/cjs/utils/joinable-proxy.d.ts.map +0 -1
- package/cjs/utils/joinable-proxy.js +0 -14
- package/cjs/utils/joinable-proxy.js.map +0 -1
- package/cjs/utils/listDatabaseIndexes.d.ts +0 -4
- package/cjs/utils/listDatabaseIndexes.d.ts.map +0 -1
- package/cjs/utils/listDatabaseIndexes.js +0 -101
- package/cjs/utils/listDatabaseIndexes.js.map +0 -1
- package/cjs/utils/onceConnected.d.ts +0 -2
- package/cjs/utils/onceConnected.d.ts.map +0 -1
- package/cjs/utils/onceConnected.js +0 -8
- package/cjs/utils/onceConnected.js.map +0 -1
- package/cjs/utils/sync-with.d.ts +0 -27
- package/cjs/utils/sync-with.d.ts.map +0 -1
- package/cjs/utils/sync-with.js +0 -60
- package/cjs/utils/sync-with.js.map +0 -1
- package/esm/aggregate/DeselectPipeline.d.ts +0 -10
- package/esm/aggregate/DeselectPipeline.d.ts.map +0 -1
- package/esm/aggregate/DeselectPipeline.js +0 -17
- package/esm/aggregate/DeselectPipeline.js.map +0 -1
- package/esm/aggregate/GeoNearPipeline.d.ts +0 -34
- package/esm/aggregate/GeoNearPipeline.d.ts.map +0 -1
- package/esm/aggregate/GeoNearPipeline.js +0 -44
- package/esm/aggregate/GeoNearPipeline.js.map +0 -1
- package/esm/aggregate/GroupByPipeline.d.ts +0 -12
- package/esm/aggregate/GroupByPipeline.d.ts.map +0 -1
- package/esm/aggregate/GroupByPipeline.js +0 -28
- package/esm/aggregate/GroupByPipeline.js.map +0 -1
- package/esm/aggregate/LimitPipeline.d.ts +0 -10
- package/esm/aggregate/LimitPipeline.d.ts.map +0 -1
- package/esm/aggregate/LimitPipeline.js +0 -14
- package/esm/aggregate/LimitPipeline.js.map +0 -1
- package/esm/aggregate/LookupPipeline.d.ts +0 -19
- package/esm/aggregate/LookupPipeline.d.ts.map +0 -1
- package/esm/aggregate/LookupPipeline.js +0 -23
- package/esm/aggregate/LookupPipeline.js.map +0 -1
- package/esm/aggregate/OrWherePipeline.d.ts +0 -21
- package/esm/aggregate/OrWherePipeline.d.ts.map +0 -1
- package/esm/aggregate/OrWherePipeline.js +0 -63
- package/esm/aggregate/OrWherePipeline.js.map +0 -1
- package/esm/aggregate/SelectPipeline.d.ts +0 -10
- package/esm/aggregate/SelectPipeline.d.ts.map +0 -1
- package/esm/aggregate/SelectPipeline.js +0 -26
- package/esm/aggregate/SelectPipeline.js.map +0 -1
- package/esm/aggregate/SkipPipeline.d.ts +0 -10
- package/esm/aggregate/SkipPipeline.d.ts.map +0 -1
- package/esm/aggregate/SkipPipeline.js +0 -14
- package/esm/aggregate/SkipPipeline.js.map +0 -1
- package/esm/aggregate/SortByPipeline.d.ts +0 -10
- package/esm/aggregate/SortByPipeline.d.ts.map +0 -1
- package/esm/aggregate/SortByPipeline.js +0 -18
- package/esm/aggregate/SortByPipeline.js.map +0 -1
- package/esm/aggregate/SortPipeline.d.ts +0 -11
- package/esm/aggregate/SortPipeline.d.ts.map +0 -1
- package/esm/aggregate/SortPipeline.js +0 -18
- package/esm/aggregate/SortPipeline.js.map +0 -1
- package/esm/aggregate/SortRandomPipeline.d.ts +0 -10
- package/esm/aggregate/SortRandomPipeline.d.ts.map +0 -1
- package/esm/aggregate/SortRandomPipeline.js +0 -16
- package/esm/aggregate/SortRandomPipeline.js.map +0 -1
- package/esm/aggregate/UnwindPipeline.d.ts +0 -14
- package/esm/aggregate/UnwindPipeline.d.ts.map +0 -1
- package/esm/aggregate/UnwindPipeline.js +0 -19
- package/esm/aggregate/UnwindPipeline.js.map +0 -1
- package/esm/aggregate/WhereExpression.d.ts +0 -17
- package/esm/aggregate/WhereExpression.d.ts.map +0 -1
- package/esm/aggregate/WhereExpression.js +0 -149
- package/esm/aggregate/WhereExpression.js.map +0 -1
- package/esm/aggregate/WhereExpressionPipeline.d.ts +0 -10
- package/esm/aggregate/WhereExpressionPipeline.d.ts.map +0 -1
- package/esm/aggregate/WhereExpressionPipeline.js +0 -15
- package/esm/aggregate/WhereExpressionPipeline.js.map +0 -1
- package/esm/aggregate/WherePipeline.d.ts +0 -13
- package/esm/aggregate/WherePipeline.d.ts.map +0 -1
- package/esm/aggregate/WherePipeline.js +0 -12
- package/esm/aggregate/WherePipeline.js.map +0 -1
- package/esm/aggregate/aggregate.d.ts +0 -409
- package/esm/aggregate/aggregate.d.ts.map +0 -1
- package/esm/aggregate/aggregate.js +0 -911
- package/esm/aggregate/aggregate.js.map +0 -1
- package/esm/aggregate/expressions.d.ts +0 -361
- package/esm/aggregate/expressions.d.ts.map +0 -1
- package/esm/aggregate/expressions.js +0 -536
- package/esm/aggregate/expressions.js.map +0 -1
- package/esm/aggregate/filters/apply-filters.d.ts +0 -3
- package/esm/aggregate/filters/apply-filters.d.ts.map +0 -1
- package/esm/aggregate/filters/apply-filters.js +0 -75
- package/esm/aggregate/filters/apply-filters.js.map +0 -1
- package/esm/aggregate/filters/boolean-filters.d.ts +0 -3
- package/esm/aggregate/filters/boolean-filters.d.ts.map +0 -1
- package/esm/aggregate/filters/boolean-filters.js +0 -33
- package/esm/aggregate/filters/boolean-filters.js.map +0 -1
- package/esm/aggregate/filters/date-filters.d.ts +0 -3
- package/esm/aggregate/filters/date-filters.d.ts.map +0 -1
- package/esm/aggregate/filters/date-filters.js +0 -128
- package/esm/aggregate/filters/date-filters.js.map +0 -1
- package/esm/aggregate/filters/index.d.ts +0 -3
- package/esm/aggregate/filters/index.d.ts.map +0 -1
- package/esm/aggregate/filters/numeric-filters.d.ts +0 -3
- package/esm/aggregate/filters/numeric-filters.d.ts.map +0 -1
- package/esm/aggregate/filters/numeric-filters.js +0 -99
- package/esm/aggregate/filters/numeric-filters.js.map +0 -1
- package/esm/aggregate/filters/types.d.ts +0 -46
- package/esm/aggregate/filters/types.d.ts.map +0 -1
- package/esm/aggregate/filters/utils.d.ts +0 -13
- package/esm/aggregate/filters/utils.d.ts.map +0 -1
- package/esm/aggregate/filters/utils.js +0 -38
- package/esm/aggregate/filters/utils.js.map +0 -1
- package/esm/aggregate/index.d.ts +0 -21
- package/esm/aggregate/index.d.ts.map +0 -1
- package/esm/aggregate/parsePipelines.d.ts +0 -5
- package/esm/aggregate/parsePipelines.d.ts.map +0 -1
- package/esm/aggregate/parsePipelines.js +0 -6
- package/esm/aggregate/parsePipelines.js.map +0 -1
- package/esm/aggregate/pipeline.d.ts +0 -31
- package/esm/aggregate/pipeline.d.ts.map +0 -1
- package/esm/aggregate/pipeline.js +0 -42
- package/esm/aggregate/pipeline.js.map +0 -1
- package/esm/aggregate/types.d.ts +0 -8
- package/esm/aggregate/types.d.ts.map +0 -1
- package/esm/aggregate/types.js +0 -31
- package/esm/aggregate/types.js.map +0 -1
- package/esm/blueprint/blueprint-column.d.ts +0 -82
- package/esm/blueprint/blueprint-column.d.ts.map +0 -1
- package/esm/blueprint/blueprint.d.ts +0 -162
- package/esm/blueprint/blueprint.d.ts.map +0 -1
- package/esm/blueprint/blueprint.js +0 -340
- package/esm/blueprint/blueprint.js.map +0 -1
- package/esm/blueprint/index.d.ts +0 -3
- package/esm/blueprint/index.d.ts.map +0 -1
- package/esm/blueprint/model-blueprint.d.ts +0 -15
- package/esm/blueprint/model-blueprint.d.ts.map +0 -1
- package/esm/blueprint/model-blueprint.js +0 -16
- package/esm/blueprint/model-blueprint.js.map +0 -1
- package/esm/casts/arrayOf.d.ts +0 -5
- package/esm/casts/arrayOf.d.ts.map +0 -1
- package/esm/casts/arrayOf.js +0 -18
- package/esm/casts/arrayOf.js.map +0 -1
- package/esm/casts/cast-email.d.ts +0 -2
- package/esm/casts/cast-email.d.ts.map +0 -1
- package/esm/casts/cast-email.js +0 -5
- package/esm/casts/cast-email.js.map +0 -1
- package/esm/casts/castModel.d.ts +0 -3
- package/esm/casts/castModel.d.ts.map +0 -1
- package/esm/casts/castModel.js +0 -49
- package/esm/casts/castModel.js.map +0 -1
- package/esm/casts/expiresAfter.d.ts +0 -3
- package/esm/casts/expiresAfter.d.ts.map +0 -1
- package/esm/casts/expiresAfter.js +0 -5
- package/esm/casts/expiresAfter.js.map +0 -1
- package/esm/casts/index.d.ts +0 -9
- package/esm/casts/index.d.ts.map +0 -1
- package/esm/casts/oneOf.d.ts +0 -3
- package/esm/casts/oneOf.d.ts.map +0 -1
- package/esm/casts/oneOf.js +0 -22
- package/esm/casts/oneOf.js.map +0 -1
- package/esm/casts/random-string.d.ts +0 -2
- package/esm/casts/random-string.d.ts.map +0 -1
- package/esm/casts/random-string.js +0 -5
- package/esm/casts/random-string.js.map +0 -1
- package/esm/casts/randomInteger.d.ts +0 -2
- package/esm/casts/randomInteger.d.ts.map +0 -1
- package/esm/casts/randomInteger.js +0 -7
- package/esm/casts/randomInteger.js.map +0 -1
- package/esm/casts/shapedArray.d.ts +0 -26
- package/esm/casts/shapedArray.d.ts.map +0 -1
- package/esm/casts/shapedArray.js +0 -100
- package/esm/casts/shapedArray.js.map +0 -1
- package/esm/config.d.ts +0 -6
- package/esm/config.d.ts.map +0 -1
- package/esm/config.js +0 -16
- package/esm/config.js.map +0 -1
- package/esm/connection.d.ts +0 -49
- package/esm/connection.d.ts.map +0 -1
- package/esm/connection.js +0 -108
- package/esm/connection.js.map +0 -1
- package/esm/database.d.ts +0 -97
- package/esm/database.d.ts.map +0 -1
- package/esm/database.js +0 -164
- package/esm/database.js.map +0 -1
- package/esm/index.d.ts +0 -13
- package/esm/index.d.ts.map +0 -1
- package/esm/migration/index.d.ts +0 -4
- package/esm/migration/index.d.ts.map +0 -1
- package/esm/migration/migrate.d.ts +0 -13
- package/esm/migration/migrate.d.ts.map +0 -1
- package/esm/migration/migrate.js +0 -72
- package/esm/migration/migrate.js.map +0 -1
- package/esm/migration/migration-office.d.ts +0 -21
- package/esm/migration/migration-office.d.ts.map +0 -1
- package/esm/migration/migration-office.js +0 -39
- package/esm/migration/migration-office.js.map +0 -1
- package/esm/migration/migration-officer.d.ts +0 -33
- package/esm/migration/migration-officer.d.ts.map +0 -1
- package/esm/migration/migration-officer.js +0 -55
- package/esm/migration/migration-officer.js.map +0 -1
- package/esm/migration/types.d.ts +0 -34
- package/esm/migration/types.d.ts.map +0 -1
- package/esm/model/ModelAggregate.d.ts +0 -114
- package/esm/model/ModelAggregate.d.ts.map +0 -1
- package/esm/model/ModelAggregate.js +0 -182
- package/esm/model/ModelAggregate.js.map +0 -1
- package/esm/model/ModelSync.d.ts +0 -73
- package/esm/model/ModelSync.d.ts.map +0 -1
- package/esm/model/ModelSync.js +0 -215
- package/esm/model/ModelSync.js.map +0 -1
- package/esm/model/RelationshipWithMany.d.ts +0 -24
- package/esm/model/RelationshipWithMany.d.ts.map +0 -1
- package/esm/model/RelationshipWithMany.js +0 -42
- package/esm/model/RelationshipWithMany.js.map +0 -1
- package/esm/model/base-model.d.ts +0 -161
- package/esm/model/base-model.d.ts.map +0 -1
- package/esm/model/base-model.js +0 -265
- package/esm/model/base-model.js.map +0 -1
- package/esm/model/crud-model.d.ts +0 -122
- package/esm/model/crud-model.d.ts.map +0 -1
- package/esm/model/crud-model.js +0 -366
- package/esm/model/crud-model.js.map +0 -1
- package/esm/model/index.d.ts +0 -10
- package/esm/model/index.d.ts.map +0 -1
- package/esm/model/joinable.d.ts +0 -87
- package/esm/model/joinable.d.ts.map +0 -1
- package/esm/model/joinable.js +0 -158
- package/esm/model/joinable.js.map +0 -1
- package/esm/model/master-mind.d.ts +0 -44
- package/esm/model/master-mind.d.ts.map +0 -1
- package/esm/model/master-mind.js +0 -118
- package/esm/model/master-mind.js.map +0 -1
- package/esm/model/model-events.d.ts +0 -57
- package/esm/model/model-events.d.ts.map +0 -1
- package/esm/model/model-events.js +0 -102
- package/esm/model/model-events.js.map +0 -1
- package/esm/model/model.d.ts +0 -464
- package/esm/model/model.d.ts.map +0 -1
- package/esm/model/model.js +0 -1134
- package/esm/model/model.js.map +0 -1
- package/esm/model/types.d.ts +0 -149
- package/esm/model/types.d.ts.map +0 -1
- package/esm/model/types.js +0 -11
- package/esm/model/types.js.map +0 -1
- package/esm/query/index.d.ts +0 -2
- package/esm/query/index.d.ts.map +0 -1
- package/esm/query/query.d.ts +0 -218
- package/esm/query/query.d.ts.map +0 -1
- package/esm/query/query.js +0 -672
- package/esm/query/query.js.map +0 -1
- package/esm/query/types.d.ts +0 -60
- package/esm/query/types.d.ts.map +0 -1
- package/esm/types.d.ts +0 -75
- package/esm/types.d.ts.map +0 -1
- package/esm/utils/connectToDatabase.d.ts +0 -3
- package/esm/utils/connectToDatabase.d.ts.map +0 -1
- package/esm/utils/connectToDatabase.js +0 -3
- package/esm/utils/connectToDatabase.js.map +0 -1
- package/esm/utils/deep-diff.d.ts +0 -9
- package/esm/utils/deep-diff.d.ts.map +0 -1
- package/esm/utils/deep-diff.js +0 -44
- package/esm/utils/deep-diff.js.map +0 -1
- package/esm/utils/dropAllDatabaseIndexes.d.ts +0 -2
- package/esm/utils/dropAllDatabaseIndexes.d.ts.map +0 -1
- package/esm/utils/dropAllDatabaseIndexes.js +0 -10
- package/esm/utils/dropAllDatabaseIndexes.js.map +0 -1
- package/esm/utils/index.d.ts +0 -6
- package/esm/utils/index.d.ts.map +0 -1
- package/esm/utils/joinable-proxy.d.ts +0 -3
- package/esm/utils/joinable-proxy.d.ts.map +0 -1
- package/esm/utils/joinable-proxy.js +0 -14
- package/esm/utils/joinable-proxy.js.map +0 -1
- package/esm/utils/listDatabaseIndexes.d.ts +0 -4
- package/esm/utils/listDatabaseIndexes.d.ts.map +0 -1
- package/esm/utils/listDatabaseIndexes.js +0 -101
- package/esm/utils/listDatabaseIndexes.js.map +0 -1
- package/esm/utils/onceConnected.d.ts +0 -2
- package/esm/utils/onceConnected.d.ts.map +0 -1
- package/esm/utils/onceConnected.js +0 -8
- package/esm/utils/onceConnected.js.map +0 -1
- package/esm/utils/sync-with.d.ts +0 -27
- package/esm/utils/sync-with.d.ts.map +0 -1
- package/esm/utils/sync-with.js +0 -60
- package/esm/utils/sync-with.js.map +0 -1
package/cjs/model/model.js
DELETED
|
@@ -1,1134 +0,0 @@
|
|
|
1
|
-
'use strict';var reinforcements=require('@mongez/reinforcements'),supportiveIs=require('@mongez/supportive-is'),timeWizard=require('@mongez/time-wizard'),dayjs=require('dayjs'),mongodb=require('mongodb'),castModel=require('../casts/castModel.js'),oneOf=require('../casts/oneOf.js'),deepDiff=require('../utils/deep-diff.js'),joinableProxy=require('../utils/joinable-proxy.js'),crudModel=require('./crud-model.js'),joinable=require('./joinable.js'),ModelAggregate=require('./ModelAggregate.js'),ModelSync=require('./ModelSync.js'),RelationshipWithMany=require('./RelationshipWithMany.js'),types=require('./types.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dayjs__default=/*#__PURE__*/_interopDefault(dayjs);class Model
|
|
2
|
-
// <
|
|
3
|
-
// ModelDocument extends Document = any,
|
|
4
|
-
// Schema extends Schema<ModelDocument> = any,
|
|
5
|
-
// >
|
|
6
|
-
extends crudModel.CrudModel {
|
|
7
|
-
/**
|
|
8
|
-
* Model Initial Document data
|
|
9
|
-
*/
|
|
10
|
-
initialData = {};
|
|
11
|
-
/**
|
|
12
|
-
* Model relationships defined using the joinable API.
|
|
13
|
-
*
|
|
14
|
-
* Each key represents a relationship name that can be referenced when running queries.
|
|
15
|
-
* Each value defines how to join another collection to the current model.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* Basic definition:
|
|
19
|
-
* ```ts
|
|
20
|
-
* public static relations = {
|
|
21
|
-
* // Join users collection where local createdBy.id matches user's id
|
|
22
|
-
* author: User.joinable("createdBy.id", "id").single().as("author"),
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
* @usage
|
|
26
|
-
* Example of calling:
|
|
27
|
-
* ```ts
|
|
28
|
-
* Post.aggregate().joining("author").get(); // use `joining` method to join the `author` relationship
|
|
29
|
-
* // Where `author` is the name of the relationship defined in the `relations` property
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
static relations = {};
|
|
33
|
-
/**
|
|
34
|
-
* Model Document data
|
|
35
|
-
*/
|
|
36
|
-
data;
|
|
37
|
-
/**
|
|
38
|
-
* Define Default value data that will be merged with the models' data
|
|
39
|
-
* on the create process
|
|
40
|
-
*/
|
|
41
|
-
defaultValue = {};
|
|
42
|
-
/**
|
|
43
|
-
* A flag to determine if the model is being restored
|
|
44
|
-
*/
|
|
45
|
-
isRestored = false;
|
|
46
|
-
/**
|
|
47
|
-
* Model casts types
|
|
48
|
-
*/
|
|
49
|
-
casts = {};
|
|
50
|
-
/**
|
|
51
|
-
* Sync with list
|
|
52
|
-
*/
|
|
53
|
-
syncWith = [];
|
|
54
|
-
/**
|
|
55
|
-
* Set custom casts that will be used to cast the model's data are not related to the current value of the collection's column
|
|
56
|
-
*
|
|
57
|
-
* For example: `name` is not a column in the given data, but it will be concatenation of `firstName` and `lastName`
|
|
58
|
-
*/
|
|
59
|
-
customCasts = {};
|
|
60
|
-
/**
|
|
61
|
-
* Guarded fields
|
|
62
|
-
*/
|
|
63
|
-
guarded = [];
|
|
64
|
-
/**
|
|
65
|
-
* Fillable fields
|
|
66
|
-
*/
|
|
67
|
-
filled = [];
|
|
68
|
-
/**
|
|
69
|
-
* Embedded columns
|
|
70
|
-
*/
|
|
71
|
-
embedded = [];
|
|
72
|
-
/**
|
|
73
|
-
* Embed all columns except the given columns
|
|
74
|
-
*/
|
|
75
|
-
embedAllExcept = [];
|
|
76
|
-
/**
|
|
77
|
-
* Embed all columns except timestamps and created|updated|deleted by columns
|
|
78
|
-
*/
|
|
79
|
-
embedAllExceptTimestampsAndUserColumns = false;
|
|
80
|
-
/**
|
|
81
|
-
* Created at column
|
|
82
|
-
*/
|
|
83
|
-
createdAtColumn = "createdAt";
|
|
84
|
-
/**
|
|
85
|
-
* Updated at column
|
|
86
|
-
*/
|
|
87
|
-
updatedAtColumn = "updatedAt";
|
|
88
|
-
/**
|
|
89
|
-
* Deleted at column
|
|
90
|
-
*/
|
|
91
|
-
deletedAtColumn = "deletedAt";
|
|
92
|
-
/**
|
|
93
|
-
* Created by column
|
|
94
|
-
*/
|
|
95
|
-
createdByColumn = "createdBy";
|
|
96
|
-
/**
|
|
97
|
-
* Updated by column
|
|
98
|
-
*/
|
|
99
|
-
updatedByColumn = "updatedBy";
|
|
100
|
-
/**
|
|
101
|
-
* Deleted by column
|
|
102
|
-
*/
|
|
103
|
-
deletedByColumn = "deletedBy";
|
|
104
|
-
/**
|
|
105
|
-
* Date format
|
|
106
|
-
*/
|
|
107
|
-
dateFormat = "DD-MM-YYYY";
|
|
108
|
-
/**
|
|
109
|
-
* A flag to determine if the id is auto generated not added manually
|
|
110
|
-
*/
|
|
111
|
-
autoGeneratedId = false;
|
|
112
|
-
/**
|
|
113
|
-
* Is active column
|
|
114
|
-
*/
|
|
115
|
-
isActiveColumn = "isActive";
|
|
116
|
-
/**
|
|
117
|
-
* Original data
|
|
118
|
-
*/
|
|
119
|
-
originalData = {};
|
|
120
|
-
/**
|
|
121
|
-
* List of dirty columns
|
|
122
|
-
*/
|
|
123
|
-
dirtyColumns = {};
|
|
124
|
-
/**
|
|
125
|
-
* Constructor
|
|
126
|
-
*/
|
|
127
|
-
constructor(originalData = {}) {
|
|
128
|
-
super();
|
|
129
|
-
if (originalData instanceof Model) {
|
|
130
|
-
this.originalData = reinforcements.clone(originalData.data);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
this.originalData = reinforcements.clone(originalData);
|
|
134
|
-
}
|
|
135
|
-
if (typeof this.originalData._id === "string") {
|
|
136
|
-
this.originalData._id = new mongodb.ObjectId(this.originalData._id);
|
|
137
|
-
}
|
|
138
|
-
this.data = reinforcements.clone(this.originalData);
|
|
139
|
-
this.initialData = reinforcements.clone(this.originalData);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Get save columns which are the casts keys
|
|
143
|
-
*/
|
|
144
|
-
get castColumns() {
|
|
145
|
-
return Object.keys(this.casts);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Get value from original data
|
|
149
|
-
*/
|
|
150
|
-
original(key, defaultValue) {
|
|
151
|
-
return reinforcements.get(this.originalData, key, defaultValue);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Get all data except the guarded fields
|
|
155
|
-
*/
|
|
156
|
-
get publicData() {
|
|
157
|
-
return reinforcements.except(this.data, this.guarded);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get guarded data
|
|
161
|
-
*/
|
|
162
|
-
get guardedData() {
|
|
163
|
-
return reinforcements.only(this.data, this.guarded);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Get the model's id
|
|
167
|
-
*/
|
|
168
|
-
get id() {
|
|
169
|
-
return this.get("id");
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Check if current model is active
|
|
173
|
-
*/
|
|
174
|
-
get isActive() {
|
|
175
|
-
return this.bool(this.isActiveColumn);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Check if current model created by the given user (user model)
|
|
179
|
-
*/
|
|
180
|
-
isCreatedBy(user) {
|
|
181
|
-
return this.get("createdBy.id") === user.id;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Check if current model last updated by the given user (user model)
|
|
185
|
-
*/
|
|
186
|
-
isUpdatedBy(user) {
|
|
187
|
-
return this.get("updatedBy.id") === user.id;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Get mongodb id
|
|
191
|
-
*/
|
|
192
|
-
get _id() {
|
|
193
|
-
return this.get("_id");
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Mark the current model as being restored
|
|
197
|
-
*/
|
|
198
|
-
markAsRestored() {
|
|
199
|
-
this.isRestored = true;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Set a column in the model data
|
|
203
|
-
*/
|
|
204
|
-
set(column, value) {
|
|
205
|
-
const currentValue = this.get(column);
|
|
206
|
-
this.data = reinforcements.set(this.data, column, value);
|
|
207
|
-
if (currentValue !== value) {
|
|
208
|
-
reinforcements.set(this.dirtyColumns, column, {
|
|
209
|
-
oldValue: currentValue,
|
|
210
|
-
newValue: value,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Increment the given column by the given value
|
|
217
|
-
*/
|
|
218
|
-
increment(column, value = 1) {
|
|
219
|
-
return this.set(column, this.get(column, 0) + value);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Decrement the given column by the given value
|
|
223
|
-
*/
|
|
224
|
-
decrement(column, value = 1) {
|
|
225
|
-
return this.set(column, this.get(column, 0) - value);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Get initial value of the given column
|
|
229
|
-
*/
|
|
230
|
-
getInitial(column, defaultValue) {
|
|
231
|
-
return reinforcements.get(this.initialData, column, defaultValue);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Get value of the given column
|
|
235
|
-
*/
|
|
236
|
-
get(column, defaultValue) {
|
|
237
|
-
return reinforcements.get(this.data, column, defaultValue);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Return the value of the given column as a string
|
|
241
|
-
*/
|
|
242
|
-
string(column, defaultValue) {
|
|
243
|
-
return String(this.get(column, defaultValue));
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Return the value of the given column as an integer
|
|
247
|
-
*/
|
|
248
|
-
int(column, defaultValue) {
|
|
249
|
-
return parseInt(this.get(column, defaultValue));
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Return the value of the given column as a float
|
|
253
|
-
*/
|
|
254
|
-
float(column, defaultValue) {
|
|
255
|
-
return parseFloat(this.get(column, defaultValue));
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Return the value of the given column as a number
|
|
259
|
-
*/
|
|
260
|
-
number(column, defaultValue) {
|
|
261
|
-
return Number(this.get(column, defaultValue));
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Return the value of the given column as a boolean
|
|
265
|
-
*/
|
|
266
|
-
bool(column, defaultValue) {
|
|
267
|
-
return Boolean(this.get(column, defaultValue));
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Determine whether the given column exists in the document
|
|
271
|
-
*/
|
|
272
|
-
has(column) {
|
|
273
|
-
return reinforcements.get(this.data, column) !== undefined;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Get all columns except the given ones
|
|
277
|
-
*/
|
|
278
|
-
except(columns) {
|
|
279
|
-
return reinforcements.except(this.data, columns);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Get only the given columns
|
|
283
|
-
*/
|
|
284
|
-
only(columns) {
|
|
285
|
-
return reinforcements.only(this.data, columns);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Get only id
|
|
289
|
-
*/
|
|
290
|
-
get onlyId() {
|
|
291
|
-
return this.only(["id"]);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Unset or remove the given columns from the data
|
|
295
|
-
*/
|
|
296
|
-
unset(...columns) {
|
|
297
|
-
const currentValues = this.only(columns);
|
|
298
|
-
this.data = reinforcements.except(this.data, columns);
|
|
299
|
-
for (const column in currentValues) {
|
|
300
|
-
reinforcements.set(this.dirtyColumns, column, {
|
|
301
|
-
oldValue: currentValues[column],
|
|
302
|
-
newValue: undefined,
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
return this;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Get the value of the given column and remove it from the data
|
|
309
|
-
*/
|
|
310
|
-
pluck(column) {
|
|
311
|
-
const value = this.get(column);
|
|
312
|
-
this.unset(column);
|
|
313
|
-
return value;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Replace the entire document data with the given new data
|
|
317
|
-
*/
|
|
318
|
-
replaceWith(data) {
|
|
319
|
-
if (!data.id && this.data.id) {
|
|
320
|
-
data.id = this.data.id;
|
|
321
|
-
}
|
|
322
|
-
if (!data._id && this.data._id) {
|
|
323
|
-
data._id = this.data._id;
|
|
324
|
-
}
|
|
325
|
-
const currentData = reinforcements.clone(data);
|
|
326
|
-
this.data = data;
|
|
327
|
-
const dirtyValues = deepDiff.deepDiff(currentData, this.data);
|
|
328
|
-
reinforcements.merge(this.dirtyColumns, dirtyValues);
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Merge the given documents to current document
|
|
333
|
-
*/
|
|
334
|
-
merge(data) {
|
|
335
|
-
const currentData = reinforcements.clone(this.data);
|
|
336
|
-
this.data = reinforcements.merge(this.data, data);
|
|
337
|
-
const dirtyValues = deepDiff.deepDiff(currentData, this.data);
|
|
338
|
-
reinforcements.merge(this.dirtyColumns, dirtyValues);
|
|
339
|
-
for (const column in this.data) {
|
|
340
|
-
if (this.data[column] !== currentData[column]) {
|
|
341
|
-
reinforcements.set(this.dirtyColumns, column, {
|
|
342
|
-
oldValue: currentData[column],
|
|
343
|
-
newValue: this.data[column],
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return this;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Push the given values to the given column
|
|
351
|
-
* If the given column does not exists, it will be created
|
|
352
|
-
* If the given value exists but not an array it will be ignored
|
|
353
|
-
*/
|
|
354
|
-
push(column, ...values) {
|
|
355
|
-
const currentValue = this.get(column);
|
|
356
|
-
if (Array.isArray(currentValue)) {
|
|
357
|
-
this.set(column, [...currentValue, ...values]);
|
|
358
|
-
}
|
|
359
|
-
else if (!currentValue) {
|
|
360
|
-
this.set(column, values);
|
|
361
|
-
}
|
|
362
|
-
return this;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Push the given values to the given column only if not exists
|
|
366
|
-
*/
|
|
367
|
-
pushOnce(column, ...values) {
|
|
368
|
-
const currentValue = this.get(column);
|
|
369
|
-
if (Array.isArray(currentValue)) {
|
|
370
|
-
const newValues = Array.from(new Set([...currentValue, ...values]));
|
|
371
|
-
this.set(column, newValues);
|
|
372
|
-
}
|
|
373
|
-
else if (!currentValue) {
|
|
374
|
-
this.set(column, values);
|
|
375
|
-
}
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Add the given values to the beginning of the given column
|
|
380
|
-
* If the given column does not exists, it will be created
|
|
381
|
-
* If the given value exists but not an array it will be ignored
|
|
382
|
-
*/
|
|
383
|
-
unshift(column, ...values) {
|
|
384
|
-
const currentValue = this.get(column);
|
|
385
|
-
if (Array.isArray(currentValue)) {
|
|
386
|
-
this.set(column, [...values, ...currentValue]);
|
|
387
|
-
}
|
|
388
|
-
else if (!currentValue) {
|
|
389
|
-
this.set(column, values);
|
|
390
|
-
}
|
|
391
|
-
return this;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Add the given values to the beginning of the given column only if not exists
|
|
395
|
-
*/
|
|
396
|
-
unshiftOnce(column, ...values) {
|
|
397
|
-
const currentValue = this.get(column);
|
|
398
|
-
if (Array.isArray(currentValue)) {
|
|
399
|
-
const newValues = Array.from(new Set([...values, ...currentValue]));
|
|
400
|
-
this.set(column, newValues);
|
|
401
|
-
}
|
|
402
|
-
else if (!currentValue) {
|
|
403
|
-
this.set(column, values);
|
|
404
|
-
}
|
|
405
|
-
return this;
|
|
406
|
-
}
|
|
407
|
-
async prepareDataForCreating(cast = true, triggerEvents = true) {
|
|
408
|
-
// await this.getDatabase().startSessionContext(async ({ session }) => {
|
|
409
|
-
// check for default values and merge it with the data
|
|
410
|
-
await this.checkDefaultValues();
|
|
411
|
-
// if the column does not exist, then create it
|
|
412
|
-
if ((!this.data.id || !this.autoGeneratedId) &&
|
|
413
|
-
this.getStaticProperty("autoGenerateId")) {
|
|
414
|
-
this.autoGeneratedId = true;
|
|
415
|
-
await this.generateNextId();
|
|
416
|
-
}
|
|
417
|
-
const now = new Date();
|
|
418
|
-
const createdAtColumn = this.createdAtColumn;
|
|
419
|
-
// if the column does not exist, then create it
|
|
420
|
-
if (createdAtColumn && !this.data[createdAtColumn]) {
|
|
421
|
-
this.data[createdAtColumn] = now;
|
|
422
|
-
}
|
|
423
|
-
// if the column does not exist, then create it
|
|
424
|
-
const updatedAtColumn = this.updatedAtColumn;
|
|
425
|
-
if (updatedAtColumn) {
|
|
426
|
-
this.data[updatedAtColumn] = now;
|
|
427
|
-
}
|
|
428
|
-
if (cast) {
|
|
429
|
-
await this.castData();
|
|
430
|
-
}
|
|
431
|
-
if (triggerEvents) {
|
|
432
|
-
const selfModelEvents = this.getModelEvents();
|
|
433
|
-
const ModelEvents = this.getBaseModelEvents();
|
|
434
|
-
await this.onSaving();
|
|
435
|
-
await this.onCreating();
|
|
436
|
-
await selfModelEvents.trigger("creating", this);
|
|
437
|
-
await selfModelEvents.trigger("saving", this);
|
|
438
|
-
await ModelEvents.trigger("creating", this);
|
|
439
|
-
await ModelEvents.trigger("saving", this);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Perform saving operation either by updating or creating a new record in database
|
|
444
|
-
*/
|
|
445
|
-
async save(mergedData, { triggerEvents = true, cast = true, forceUpdate = false, } = {}) {
|
|
446
|
-
const isNewModel = this.isNewModel();
|
|
447
|
-
try {
|
|
448
|
-
if (mergedData) {
|
|
449
|
-
this.merge(mergedData);
|
|
450
|
-
}
|
|
451
|
-
// const logLevel = getDatabaseDebugLevel();
|
|
452
|
-
let currentModel;
|
|
453
|
-
// check if the data contains the primary id column
|
|
454
|
-
if (!isNewModel) {
|
|
455
|
-
// perform an update operation
|
|
456
|
-
// check if the data has changed
|
|
457
|
-
// if not changed, then do not do anything
|
|
458
|
-
if (cast) {
|
|
459
|
-
// this.logInfo("Casting data before saving");
|
|
460
|
-
await this.castData(forceUpdate);
|
|
461
|
-
// this.logInfo("Data has been casted");
|
|
462
|
-
}
|
|
463
|
-
if (this.shouldUpdate(this.originalData, this.data) === false) {
|
|
464
|
-
return this;
|
|
465
|
-
}
|
|
466
|
-
currentModel = new this.constructor(this.originalData);
|
|
467
|
-
const updatedAtColumn = this.updatedAtColumn;
|
|
468
|
-
if (updatedAtColumn) {
|
|
469
|
-
// updateAtColumn is supposed to be part of the Schema
|
|
470
|
-
this.data[updatedAtColumn] = new Date();
|
|
471
|
-
}
|
|
472
|
-
if (triggerEvents) {
|
|
473
|
-
const selfModelEvents = this.getModelEvents();
|
|
474
|
-
const ModelEvents = this.getBaseModelEvents();
|
|
475
|
-
await this.onSaving();
|
|
476
|
-
await this.onUpdating();
|
|
477
|
-
await selfModelEvents.trigger("updating", this, currentModel);
|
|
478
|
-
await selfModelEvents.trigger("saving", this, currentModel);
|
|
479
|
-
await ModelEvents.trigger("updating", this, currentModel);
|
|
480
|
-
await ModelEvents.trigger("saving", this, currentModel);
|
|
481
|
-
}
|
|
482
|
-
// const data = { ...this.data };
|
|
483
|
-
// if (isPlainObject(data._id)) {
|
|
484
|
-
// delete data._id;
|
|
485
|
-
// }
|
|
486
|
-
const filter = {};
|
|
487
|
-
if (supportiveIs.isEmpty(this._id)) {
|
|
488
|
-
filter._id = this.data._id;
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
filter.id = this.id;
|
|
492
|
-
}
|
|
493
|
-
await this.getQuery().replace(this.getCollection(), filter, this.data);
|
|
494
|
-
if (triggerEvents) {
|
|
495
|
-
this.triggerUpdatedEvents(currentModel);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
let tries = 3;
|
|
500
|
-
while (tries > 0) {
|
|
501
|
-
try {
|
|
502
|
-
await this.prepareDataForCreating(cast, triggerEvents);
|
|
503
|
-
this.data = (await this.getQuery().create(this.getCollection(), this.data));
|
|
504
|
-
if (triggerEvents) {
|
|
505
|
-
this.triggerCreatedEvents();
|
|
506
|
-
}
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
catch (error) {
|
|
510
|
-
console.log(error);
|
|
511
|
-
// Handle duplicate key error
|
|
512
|
-
if (error instanceof mongodb.MongoServerError && error.code === 11000) {
|
|
513
|
-
if (tries < 2) {
|
|
514
|
-
const duplicateField = error.keyValue;
|
|
515
|
-
const fieldName = Object.keys(duplicateField)[0];
|
|
516
|
-
const errorMessage = `A record with the same ${fieldName} already exists.`;
|
|
517
|
-
if (this.autoGeneratedId) {
|
|
518
|
-
this.unset("id");
|
|
519
|
-
}
|
|
520
|
-
throw new Error(errorMessage);
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
tries--;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
throw error;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (!this.data.id)
|
|
531
|
-
return this;
|
|
532
|
-
this.originalData = reinforcements.clone(this.data);
|
|
533
|
-
// @see constructor
|
|
534
|
-
this.originalData._id = this.data._id;
|
|
535
|
-
return this;
|
|
536
|
-
}
|
|
537
|
-
catch (error) {
|
|
538
|
-
console.log("Error in " + this.constructor.name + ".save()");
|
|
539
|
-
console.log(error);
|
|
540
|
-
throw error;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Serialize the model data for storage in database
|
|
545
|
-
*/
|
|
546
|
-
serialize() {
|
|
547
|
-
return {
|
|
548
|
-
...this.data,
|
|
549
|
-
_id: this.data._id ? this.data._id.toString() : undefined,
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
/**
|
|
553
|
-
* Generate and return next id
|
|
554
|
-
*/
|
|
555
|
-
async generateNextId() {
|
|
556
|
-
this.set("id", await this.getStaticProperty("genNextId").bind(this.constructor)());
|
|
557
|
-
return this.id;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Trigger created events
|
|
561
|
-
*/
|
|
562
|
-
triggerCreatedEvents() {
|
|
563
|
-
const selfModelEvents = this.getModelEvents();
|
|
564
|
-
const ModelEvents = this.getBaseModelEvents();
|
|
565
|
-
this.onSaved();
|
|
566
|
-
this.onCreated();
|
|
567
|
-
selfModelEvents.trigger("created", this);
|
|
568
|
-
selfModelEvents.trigger("saved", this);
|
|
569
|
-
ModelEvents.trigger("created", this);
|
|
570
|
-
ModelEvents.trigger("saved", this);
|
|
571
|
-
this.startSyncing("create");
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Trigger updated events
|
|
575
|
-
*/
|
|
576
|
-
triggerUpdatedEvents(oldModel) {
|
|
577
|
-
const selfModelEvents = this.getModelEvents();
|
|
578
|
-
const ModelEvents = this.getBaseModelEvents();
|
|
579
|
-
this.onSaved();
|
|
580
|
-
this.onUpdated();
|
|
581
|
-
selfModelEvents.trigger("updated", this, oldModel);
|
|
582
|
-
selfModelEvents.trigger("saved", this, oldModel);
|
|
583
|
-
ModelEvents.trigger("updated", this, oldModel);
|
|
584
|
-
ModelEvents.trigger("saved", this, oldModel);
|
|
585
|
-
this.startSyncing("update", oldModel);
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Perform saving but without any events triggers
|
|
589
|
-
*/
|
|
590
|
-
async silentSaving(mergedData, options) {
|
|
591
|
-
return await this.save(mergedData, {
|
|
592
|
-
triggerEvents: false,
|
|
593
|
-
...(options || {}),
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Determine whether the model should be updated or not
|
|
598
|
-
*/
|
|
599
|
-
shouldUpdate(originalData, data) {
|
|
600
|
-
return reinforcements.areEqual(originalData, data) === false;
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Triggered before saving the model either by creating or updating
|
|
604
|
-
*/
|
|
605
|
-
async onSaving() {
|
|
606
|
-
//
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Triggered after saving the model either by creating or updating
|
|
610
|
-
*/
|
|
611
|
-
async onSaved() {
|
|
612
|
-
//
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Triggered before creating the model
|
|
616
|
-
*/
|
|
617
|
-
async onCreating() {
|
|
618
|
-
//
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* Triggered after creating the model
|
|
622
|
-
*/
|
|
623
|
-
async onCreated() {
|
|
624
|
-
//
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Triggered before updating the model
|
|
628
|
-
*/
|
|
629
|
-
async onUpdating() {
|
|
630
|
-
//
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Triggered after updating the model
|
|
634
|
-
*/
|
|
635
|
-
async onUpdated() {
|
|
636
|
-
//
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Triggered before deleting the model
|
|
640
|
-
*/
|
|
641
|
-
async onDeleting() {
|
|
642
|
-
//
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* Triggered after deleting the model
|
|
646
|
-
*/
|
|
647
|
-
async onDeleted() {
|
|
648
|
-
//
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Cast data before saving
|
|
652
|
-
*/
|
|
653
|
-
async castData(forceUpdate = false) {
|
|
654
|
-
for (const column in this.casts) {
|
|
655
|
-
if (!forceUpdate && !this.isDirty(column)) {
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
let value = this.get(column);
|
|
659
|
-
if (value === undefined)
|
|
660
|
-
continue;
|
|
661
|
-
const castType = this.casts[column];
|
|
662
|
-
const castValue = async (value) => {
|
|
663
|
-
if (castType.prototype instanceof Model) {
|
|
664
|
-
// if cast type is passed as model class, then get its embedded data
|
|
665
|
-
value = await castModel.castModel(castType)(value);
|
|
666
|
-
}
|
|
667
|
-
else if (castType?.model) {
|
|
668
|
-
// it means the user is passing a custom model embedding i.e Model.embed('embedToProduct') => Product to embed from the getter property
|
|
669
|
-
// embedToProduct
|
|
670
|
-
// @see EmbeddedModel
|
|
671
|
-
value = await castModel.castModel(castType.model, castType.embeddedKey)(value);
|
|
672
|
-
}
|
|
673
|
-
else if (typeof castType === "object") {
|
|
674
|
-
// it means the user is passing an enum object
|
|
675
|
-
value = await oneOf.castEnum(castType)(value);
|
|
676
|
-
}
|
|
677
|
-
else if (value instanceof Model) {
|
|
678
|
-
value = value.embeddedData;
|
|
679
|
-
}
|
|
680
|
-
else if (typeof castType === "function") {
|
|
681
|
-
value = await castType(value, column, this);
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
value = this.castValue(value, castType);
|
|
685
|
-
}
|
|
686
|
-
return value;
|
|
687
|
-
};
|
|
688
|
-
// if the cast type is passed in array
|
|
689
|
-
// it means we just need to pass the value to the first function
|
|
690
|
-
// second argument will be the column name
|
|
691
|
-
// and the third argument will be the model instance
|
|
692
|
-
if (Array.isArray(castType)) {
|
|
693
|
-
value = await castType[0](value, column, this);
|
|
694
|
-
}
|
|
695
|
-
else if (Array.isArray(value) && castType !== "localized") {
|
|
696
|
-
// if cast type is array, then we'll keep the value as it is
|
|
697
|
-
// now we want to add a new validation rule that to check
|
|
698
|
-
// if the value is an array of localized objects
|
|
699
|
-
// if so, then each value in the array should have `localeCode` and `value` keys
|
|
700
|
-
// if so, then it will be cast only to the value key inside each object
|
|
701
|
-
// so the final output will be localeCode and `castValue` of the value key
|
|
702
|
-
if (castType === "array") ;
|
|
703
|
-
else if (value[0]?.localeCode && value[0]?.value) {
|
|
704
|
-
value = await Promise.all(value.map(async (item) => {
|
|
705
|
-
return {
|
|
706
|
-
localeCode: item.localeCode,
|
|
707
|
-
value: await castValue(item.value),
|
|
708
|
-
};
|
|
709
|
-
}));
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
value = await Promise.all(value.map(async (item) => {
|
|
713
|
-
return await castValue(item);
|
|
714
|
-
}));
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
value = await castValue(value);
|
|
719
|
-
}
|
|
720
|
-
if (Array.isArray(value)) {
|
|
721
|
-
value = value.filter(value => value !== null && value !== undefined);
|
|
722
|
-
}
|
|
723
|
-
if (value !== undefined) {
|
|
724
|
-
this.set(column, value);
|
|
725
|
-
}
|
|
726
|
-
else {
|
|
727
|
-
this.unset(column);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
for (const column in this.customCasts) {
|
|
731
|
-
const castType = this.customCasts[column];
|
|
732
|
-
const value = await castType(this, column);
|
|
733
|
-
if (value !== undefined) {
|
|
734
|
-
this.set(column, value);
|
|
735
|
-
}
|
|
736
|
-
else {
|
|
737
|
-
this.unset(column);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Return only the given columns to be used in output
|
|
743
|
-
*/
|
|
744
|
-
outputOnly(columns) {
|
|
745
|
-
return this.clone(this.only(columns));
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Return all columns except the given columns to be used in output
|
|
749
|
-
*/
|
|
750
|
-
outputExcept(columns) {
|
|
751
|
-
return this.clone(this.except(columns));
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Cast the given value based on the given cast type
|
|
755
|
-
*/
|
|
756
|
-
castValue(value, castType) {
|
|
757
|
-
const isEmptyValue = supportiveIs.isEmpty(value);
|
|
758
|
-
if (typeof value === "object") {
|
|
759
|
-
if (value === null)
|
|
760
|
-
return undefined;
|
|
761
|
-
}
|
|
762
|
-
else if (isEmptyValue)
|
|
763
|
-
return undefined;
|
|
764
|
-
switch (castType) {
|
|
765
|
-
case "string":
|
|
766
|
-
return isEmptyValue ? "" : String(value).trim();
|
|
767
|
-
case "localized":
|
|
768
|
-
// if (isEmptyValue) return [];
|
|
769
|
-
// if (!Array.isArray(value)) return [];
|
|
770
|
-
if (!Array.isArray(value))
|
|
771
|
-
return undefined;
|
|
772
|
-
return value
|
|
773
|
-
.filter(value => !supportiveIs.isEmpty(value) && supportiveIs.isPlainObject(value))
|
|
774
|
-
.map(item => {
|
|
775
|
-
return {
|
|
776
|
-
localeCode: item.localeCode,
|
|
777
|
-
value: item.value,
|
|
778
|
-
};
|
|
779
|
-
});
|
|
780
|
-
case "number":
|
|
781
|
-
// return isEmptyValue ? 0 : Number(value);
|
|
782
|
-
return Number(value);
|
|
783
|
-
case "int":
|
|
784
|
-
case "integer":
|
|
785
|
-
// return isEmptyValue ? 0 : parseInt(value);
|
|
786
|
-
return parseInt(value);
|
|
787
|
-
case "float":
|
|
788
|
-
// return isEmptyValue ? 0 : parseFloat(value);
|
|
789
|
-
return parseFloat(value);
|
|
790
|
-
case "bool":
|
|
791
|
-
case "boolean": {
|
|
792
|
-
// if (isEmptyValue) return false;
|
|
793
|
-
if (value === "true")
|
|
794
|
-
return true;
|
|
795
|
-
if (value === "false" || value === "0" || value === 0)
|
|
796
|
-
return false;
|
|
797
|
-
return Boolean(value);
|
|
798
|
-
}
|
|
799
|
-
case "date": {
|
|
800
|
-
if (dayjs__default.default.isDayjs(value)) {
|
|
801
|
-
value = value.toDate();
|
|
802
|
-
}
|
|
803
|
-
if (value instanceof Date) {
|
|
804
|
-
return timeWizard.toUTC(value);
|
|
805
|
-
}
|
|
806
|
-
return timeWizard.toUTC(new Date(value));
|
|
807
|
-
}
|
|
808
|
-
case "location": {
|
|
809
|
-
// if (isEmptyValue) return null;
|
|
810
|
-
const lat = value?.[0] || value?.lat;
|
|
811
|
-
const lng = value?.[1] || value?.lng;
|
|
812
|
-
const address = value?.address || value?.formattedAddress;
|
|
813
|
-
return {
|
|
814
|
-
type: "Point",
|
|
815
|
-
coordinates: [Number(lat), Number(lng)],
|
|
816
|
-
address,
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
case "object": {
|
|
820
|
-
// if (isEmptyValue) return {};
|
|
821
|
-
if (typeof value === "string") {
|
|
822
|
-
try {
|
|
823
|
-
return JSON.parse(value);
|
|
824
|
-
}
|
|
825
|
-
catch (error) {
|
|
826
|
-
return undefined;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return value;
|
|
830
|
-
}
|
|
831
|
-
case "array": {
|
|
832
|
-
// if (isEmptyValue) return [];
|
|
833
|
-
if (typeof value === "string") {
|
|
834
|
-
return JSON.parse(value);
|
|
835
|
-
}
|
|
836
|
-
return value;
|
|
837
|
-
}
|
|
838
|
-
case "mixed":
|
|
839
|
-
case "any":
|
|
840
|
-
default:
|
|
841
|
-
return value;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
/**
|
|
845
|
-
* Check for default values
|
|
846
|
-
*/
|
|
847
|
-
checkDefaultValues() {
|
|
848
|
-
// if default value is empty, then do nothing
|
|
849
|
-
if (supportiveIs.isEmpty(this.defaultValue))
|
|
850
|
-
return;
|
|
851
|
-
const defaultValue = { ...this.defaultValue };
|
|
852
|
-
for (const key in defaultValue) {
|
|
853
|
-
const value = defaultValue[key];
|
|
854
|
-
if (typeof value === "function") {
|
|
855
|
-
defaultValue[key] = value(this);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
// merge the data with default value
|
|
859
|
-
this.data = reinforcements.merge(defaultValue, this.data);
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Destroy the model and delete it from database collection
|
|
863
|
-
*/
|
|
864
|
-
async destroy() {
|
|
865
|
-
if (!this.data._id)
|
|
866
|
-
return;
|
|
867
|
-
if (this.deletedAtColumn) {
|
|
868
|
-
this.set(this.deletedAtColumn, new Date());
|
|
869
|
-
}
|
|
870
|
-
const deleteStrategy = this.getStaticProperty("deleteStrategy");
|
|
871
|
-
if (deleteStrategy === types.ModelDeleteStrategy.moveToTrash) {
|
|
872
|
-
const collectionName = this.getCollection();
|
|
873
|
-
class Trash extends Model {
|
|
874
|
-
static collection = collectionName + "Trash";
|
|
875
|
-
}
|
|
876
|
-
// we need to wrap the trash collection inside a model class so it get a generated timestamps and id
|
|
877
|
-
Trash.create({
|
|
878
|
-
document: this.data,
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
const selfModelEvents = this.getModelEvents();
|
|
882
|
-
const ModelEvents = this.getBaseModelEvents();
|
|
883
|
-
await this.onDeleting();
|
|
884
|
-
await selfModelEvents.trigger("deleting", this);
|
|
885
|
-
await ModelEvents.trigger("deleting", this);
|
|
886
|
-
// the document will be deleted from database collection if the delete strategy is not soft delete
|
|
887
|
-
if (deleteStrategy !== types.ModelDeleteStrategy.softDelete) {
|
|
888
|
-
await this.getQuery().deleteOne(this.getCollection(), {
|
|
889
|
-
_id: this.data._id,
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
else if (deleteStrategy === types.ModelDeleteStrategy.softDelete) {
|
|
893
|
-
await this.getQuery().updateOne(this.getCollection(), {
|
|
894
|
-
_id: this.data._id,
|
|
895
|
-
}, this.data);
|
|
896
|
-
}
|
|
897
|
-
this.onDeleted();
|
|
898
|
-
selfModelEvents.trigger("deleted", this);
|
|
899
|
-
ModelEvents.trigger("deleted", this);
|
|
900
|
-
this.syncDestruction();
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Determine if the given column is dirty column
|
|
904
|
-
*
|
|
905
|
-
* Dirty columns are columns that their values have been changed from the original data
|
|
906
|
-
*/
|
|
907
|
-
isDirty(column) {
|
|
908
|
-
if (!column) {
|
|
909
|
-
return reinforcements.areEqual(reinforcements.clone(this.data), reinforcements.clone(this.originalData)) === false;
|
|
910
|
-
}
|
|
911
|
-
if (this.isNewModel())
|
|
912
|
-
return true;
|
|
913
|
-
const currentValue = reinforcements.get(this.data, column);
|
|
914
|
-
const originalValue = reinforcements.get(this.originalData, column);
|
|
915
|
-
return reinforcements.areEqual(reinforcements.clone(currentValue), reinforcements.clone(originalValue)) === false;
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* Check if current model is a new model
|
|
919
|
-
*/
|
|
920
|
-
isNewModel() {
|
|
921
|
-
// Check initial data instead of current data since it represents
|
|
922
|
-
// the original state when the model was instantiated
|
|
923
|
-
const hasMongoId = Boolean(this.data._id) && !this.isRestored;
|
|
924
|
-
// Check for numeric id in initial data
|
|
925
|
-
// const hasNumericId = Boolean(this.data?.id) && !this.isRestored;
|
|
926
|
-
return !hasMongoId;
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* Get embedded data
|
|
930
|
-
*/
|
|
931
|
-
get embeddedData() {
|
|
932
|
-
if (this.embedAllExcept.length > 0) {
|
|
933
|
-
return reinforcements.except(this.data, this.embedAllExcept);
|
|
934
|
-
}
|
|
935
|
-
if (this.embedAllExceptTimestampsAndUserColumns) {
|
|
936
|
-
return reinforcements.except(this.data, [
|
|
937
|
-
this.createdAtColumn,
|
|
938
|
-
this.updatedAtColumn,
|
|
939
|
-
this.deletedAtColumn,
|
|
940
|
-
this.createdByColumn,
|
|
941
|
-
this.updatedByColumn,
|
|
942
|
-
this.deletedByColumn,
|
|
943
|
-
]);
|
|
944
|
-
}
|
|
945
|
-
return this.embedded.length > 0 ? this.only(this.embedded) : this.data;
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Clone the model
|
|
949
|
-
*/
|
|
950
|
-
clone(data = this.data) {
|
|
951
|
-
return new this.constructor(reinforcements.clone(data));
|
|
952
|
-
}
|
|
953
|
-
/**
|
|
954
|
-
* Get relationship with the given model class
|
|
955
|
-
*/
|
|
956
|
-
hasMany(modelClass, column) {
|
|
957
|
-
return new RelationshipWithMany.RelationshipWithMany(this, modelClass, column);
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Get new aggregate for current model
|
|
961
|
-
*/
|
|
962
|
-
static aggregate() {
|
|
963
|
-
return new ModelAggregate.ModelAggregate(this);
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* @alias aggregate
|
|
967
|
-
*/
|
|
968
|
-
static newQuery() {
|
|
969
|
-
return this.aggregate();
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Get query builder
|
|
973
|
-
* @alias aggregate
|
|
974
|
-
*/
|
|
975
|
-
static queryBuilder() {
|
|
976
|
-
return new ModelAggregate.ModelAggregate(this);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Sync with the given model
|
|
980
|
-
*/
|
|
981
|
-
static sync(columns, embedMethod = "embedData") {
|
|
982
|
-
return new ModelSync.ModelSync(this, columns, embedMethod);
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* Sync data on saving
|
|
986
|
-
*/
|
|
987
|
-
startSyncing(saveMode, oldModel) {
|
|
988
|
-
for (const modelSync of this.syncWith) {
|
|
989
|
-
modelSync.sync(this, saveMode, oldModel);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Sync destruction
|
|
994
|
-
* Called when destroy method is called
|
|
995
|
-
*/
|
|
996
|
-
syncDestruction() {
|
|
997
|
-
for (const modelSync of this.syncWith) {
|
|
998
|
-
modelSync.syncDestruction(this);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* The syncing model (That calls startSyncing) is being embedded in multiple documents of current model
|
|
1003
|
-
* I.e Country.syncMany('cities') while current model is City
|
|
1004
|
-
*/
|
|
1005
|
-
static syncMany(columns, embedMethod = "embedData") {
|
|
1006
|
-
return new ModelSync.ModelSync(this, columns, embedMethod).syncMany();
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Reassociate a model/object/document with the current model
|
|
1010
|
-
* If the model is already associated, it will be updated
|
|
1011
|
-
* If not, it will be associated
|
|
1012
|
-
* the model/document must have an id
|
|
1013
|
-
*
|
|
1014
|
-
* If it is a model, you can set the embed method to use
|
|
1015
|
-
*/
|
|
1016
|
-
reassociate(column, model, embedWith) {
|
|
1017
|
-
const columnValue = model instanceof Model
|
|
1018
|
-
? embedWith
|
|
1019
|
-
? model[embedWith]()
|
|
1020
|
-
: model.embeddedData
|
|
1021
|
-
: model;
|
|
1022
|
-
if (columnValue === undefined)
|
|
1023
|
-
return this;
|
|
1024
|
-
// make a deep copy so when changing the data, it won't affect the original data
|
|
1025
|
-
const documentsList = reinforcements.clone(this.get(column, []));
|
|
1026
|
-
const index = documentsList.findIndex((doc) => (doc?.id || doc) === (columnValue?.id || columnValue));
|
|
1027
|
-
if (index === -1) {
|
|
1028
|
-
documentsList.push(columnValue);
|
|
1029
|
-
}
|
|
1030
|
-
else {
|
|
1031
|
-
documentsList[index] = columnValue;
|
|
1032
|
-
}
|
|
1033
|
-
this.set(column, [...documentsList]);
|
|
1034
|
-
return this;
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Associate a model with the current model
|
|
1038
|
-
*/
|
|
1039
|
-
associate(column, model, embedWith) {
|
|
1040
|
-
const columnValue = model instanceof Model
|
|
1041
|
-
? embedWith
|
|
1042
|
-
? model[embedWith]()
|
|
1043
|
-
: model.embeddedData
|
|
1044
|
-
: model;
|
|
1045
|
-
if (columnValue === undefined)
|
|
1046
|
-
return this;
|
|
1047
|
-
const documentsList = this.get(column, []);
|
|
1048
|
-
documentsList.push(columnValue);
|
|
1049
|
-
this.set(column, documentsList);
|
|
1050
|
-
return this;
|
|
1051
|
-
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Disassociate a model with the current model
|
|
1054
|
-
*/
|
|
1055
|
-
disassociate(column, model) {
|
|
1056
|
-
const columnValue = model instanceof Model ? model.embeddedData : model;
|
|
1057
|
-
if (columnValue === undefined)
|
|
1058
|
-
return this;
|
|
1059
|
-
const documentsList = this.get(column, []);
|
|
1060
|
-
if (!Array.isArray(documentsList))
|
|
1061
|
-
return this;
|
|
1062
|
-
const index = documentsList.findIndex((doc) => (doc?.id || doc) === (columnValue?.id || columnValue));
|
|
1063
|
-
if (index !== -1) {
|
|
1064
|
-
documentsList.splice(index, 1);
|
|
1065
|
-
}
|
|
1066
|
-
this.set(column, documentsList);
|
|
1067
|
-
return this;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Refresh the model with new data from database
|
|
1071
|
-
* This method will update the current data with the new data from database
|
|
1072
|
-
*/
|
|
1073
|
-
async refresh() {
|
|
1074
|
-
const key = this.data._id ? "_id" : "id";
|
|
1075
|
-
const value = this.data._id ?? this.data.id;
|
|
1076
|
-
const data = await this.getQuery().first(this.getCollection(), {
|
|
1077
|
-
[key]: value,
|
|
1078
|
-
});
|
|
1079
|
-
if (!data)
|
|
1080
|
-
return;
|
|
1081
|
-
this.data = data;
|
|
1082
|
-
return this;
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Fetch data from database and return it in a new model
|
|
1086
|
-
*/
|
|
1087
|
-
async reload() {
|
|
1088
|
-
const key = this.data._id ? "_id" : "id";
|
|
1089
|
-
const value = this.data._id ?? this.data.id;
|
|
1090
|
-
if (!value) {
|
|
1091
|
-
throw new Error("Model ID is required to reload the model");
|
|
1092
|
-
}
|
|
1093
|
-
const data = await this.getQuery().first(this.getCollection(), {
|
|
1094
|
-
[key]: value,
|
|
1095
|
-
});
|
|
1096
|
-
return new this.constructor(data);
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Make a wrapper to list when models should be updated when only one of the given columns is updated
|
|
1100
|
-
*/
|
|
1101
|
-
syncUpdateWhenChange(columns, syncModels) {
|
|
1102
|
-
return syncModels.map(syncModel => {
|
|
1103
|
-
syncModel.updateWhenChange(columns);
|
|
1104
|
-
return syncModel;
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
/**
|
|
1108
|
-
* Get a Joinable instance for current model
|
|
1109
|
-
*/
|
|
1110
|
-
static joinable(
|
|
1111
|
-
/**
|
|
1112
|
-
* Local field to the current model
|
|
1113
|
-
*/
|
|
1114
|
-
localField,
|
|
1115
|
-
/**
|
|
1116
|
-
* Foreign field in the joinable model
|
|
1117
|
-
*/
|
|
1118
|
-
foreignField, single, as) {
|
|
1119
|
-
const joinable$1 = new joinable.Joinable(this);
|
|
1120
|
-
if (localField) {
|
|
1121
|
-
joinable$1.localField(localField);
|
|
1122
|
-
}
|
|
1123
|
-
if (foreignField) {
|
|
1124
|
-
joinable$1.foreignField(foreignField);
|
|
1125
|
-
}
|
|
1126
|
-
if (single) {
|
|
1127
|
-
joinable$1.single(single);
|
|
1128
|
-
}
|
|
1129
|
-
if (as) {
|
|
1130
|
-
joinable$1.as(as);
|
|
1131
|
-
}
|
|
1132
|
-
return joinableProxy.joinableProxy(joinable$1);
|
|
1133
|
-
}
|
|
1134
|
-
}exports.Model=Model;//# sourceMappingURL=model.js.map
|