@nocobase/database 0.5.0-alpha.38 → 0.7.0-alpha.10
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/LICENSE +201 -21
- package/esm/collection-importer.d.ts +7 -0
- package/esm/collection-importer.js +49 -0
- package/esm/collection-importer.js.map +1 -0
- package/esm/collection.d.ts +73 -0
- package/esm/collection.js +224 -0
- package/esm/collection.js.map +1 -0
- package/esm/database.d.ts +101 -0
- package/esm/database.js +275 -0
- package/esm/database.js.map +1 -0
- package/esm/fields/array-field.d.ts +11 -0
- package/esm/fields/array-field.js +26 -0
- package/esm/fields/array-field.js.map +1 -0
- package/esm/fields/belongs-to-field.d.ts +12 -0
- package/esm/fields/belongs-to-field.js +57 -0
- package/esm/fields/belongs-to-field.js.map +1 -0
- package/esm/fields/belongs-to-many-field.d.ts +11 -0
- package/esm/fields/belongs-to-many-field.js +55 -0
- package/esm/fields/belongs-to-many-field.js.map +1 -0
- package/esm/fields/boolean-field.d.ts +8 -0
- package/esm/fields/boolean-field.js +8 -0
- package/esm/fields/boolean-field.js.map +1 -0
- package/esm/fields/context-field.d.ts +13 -0
- package/esm/fields/context-field.js +43 -0
- package/esm/fields/context-field.js.map +1 -0
- package/esm/fields/date-field.d.ts +8 -0
- package/esm/fields/date-field.js +8 -0
- package/esm/fields/date-field.js.map +1 -0
- package/esm/fields/field.d.ts +37 -0
- package/esm/fields/field.js +74 -0
- package/esm/fields/field.js.map +1 -0
- package/esm/fields/has-inverse-field.d.ts +4 -0
- package/esm/fields/has-inverse-field.js +2 -0
- package/esm/fields/has-inverse-field.js.map +1 -0
- package/esm/fields/has-many-field.d.ts +64 -0
- package/esm/fields/has-many-field.js +58 -0
- package/esm/fields/has-many-field.js.map +1 -0
- package/esm/fields/has-one-field.d.ts +64 -0
- package/esm/fields/has-one-field.js +57 -0
- package/esm/fields/has-one-field.js.map +1 -0
- package/esm/fields/index.d.ts +40 -0
- package/esm/fields/index.js +21 -0
- package/esm/fields/index.js.map +1 -0
- package/esm/fields/json-field.d.ts +14 -0
- package/esm/fields/json-field.js +17 -0
- package/esm/fields/json-field.js.map +1 -0
- package/esm/fields/number-field.d.ts +32 -0
- package/esm/fields/number-field.js +28 -0
- package/esm/fields/number-field.js.map +1 -0
- package/esm/fields/password-field.d.ts +21 -0
- package/esm/fields/password-field.js +71 -0
- package/esm/fields/password-field.js.map +1 -0
- package/esm/fields/radio-field.d.ts +14 -0
- package/esm/fields/radio-field.js +49 -0
- package/esm/fields/radio-field.js.map +1 -0
- package/esm/fields/relation-field.d.ts +20 -0
- package/esm/fields/relation-field.js +27 -0
- package/esm/fields/relation-field.js.map +1 -0
- package/esm/fields/sort-field.d.ts +16 -0
- package/esm/fields/sort-field.js +90 -0
- package/esm/fields/sort-field.js.map +1 -0
- package/esm/fields/string-field.d.ts +8 -0
- package/esm/fields/string-field.js +8 -0
- package/esm/fields/string-field.js.map +1 -0
- package/esm/fields/text-field.d.ts +8 -0
- package/esm/fields/text-field.js +8 -0
- package/esm/fields/text-field.js.map +1 -0
- package/esm/fields/time-field.d.ts +8 -0
- package/esm/fields/time-field.js +8 -0
- package/esm/fields/time-field.js.map +1 -0
- package/esm/fields/uid-field.d.ts +10 -0
- package/esm/fields/uid-field.js +27 -0
- package/esm/fields/uid-field.js.map +1 -0
- package/esm/fields/virtual-field.d.ts +8 -0
- package/esm/fields/virtual-field.js +8 -0
- package/esm/fields/virtual-field.js.map +1 -0
- package/esm/filter-parser.d.ts +27 -0
- package/esm/filter-parser.js +185 -0
- package/esm/filter-parser.js.map +1 -0
- package/esm/index.d.ts +15 -0
- package/esm/index.js +16 -0
- package/esm/index.js.map +1 -0
- package/esm/magic-attribute-model.d.ts +7 -0
- package/esm/magic-attribute-model.js +70 -0
- package/esm/magic-attribute-model.js.map +1 -0
- package/esm/mock-database.d.ts +22 -0
- package/esm/mock-database.js +34 -0
- package/esm/mock-database.js.map +1 -0
- package/esm/model-hook.d.ts +12 -0
- package/esm/model-hook.js +61 -0
- package/esm/model-hook.js.map +1 -0
- package/esm/model.d.ts +15 -0
- package/esm/model.js +80 -0
- package/esm/model.js.map +1 -0
- package/esm/operators/array.d.ts +26 -0
- package/esm/operators/array.js +105 -0
- package/esm/operators/array.js.map +1 -0
- package/esm/operators/association.d.ts +10 -0
- package/esm/operators/association.js +14 -0
- package/esm/operators/association.js.map +1 -0
- package/esm/operators/date.d.ts +34 -0
- package/esm/operators/date.js +35 -0
- package/esm/operators/date.js.map +1 -0
- package/esm/operators/empty.d.ts +28 -0
- package/esm/operators/empty.js +58 -0
- package/esm/operators/empty.js.map +1 -0
- package/esm/operators/index.d.ts +2 -0
- package/esm/operators/index.js +2 -0
- package/esm/operators/index.js.map +1 -0
- package/esm/operators/ne.d.ts +10 -0
- package/esm/operators/ne.js +12 -0
- package/esm/operators/ne.js.map +1 -0
- package/esm/operators/string.d.ts +21 -0
- package/esm/operators/string.js +35 -0
- package/esm/operators/string.js.map +1 -0
- package/esm/operators/utils.d.ts +4 -0
- package/esm/operators/utils.js +11 -0
- package/esm/operators/utils.js.map +1 -0
- package/esm/options-parser.d.ts +31 -0
- package/esm/options-parser.js +225 -0
- package/esm/options-parser.js.map +1 -0
- package/esm/playground.d.ts +1 -0
- package/esm/playground.js +53 -0
- package/esm/playground.js.map +1 -0
- package/esm/relation-repository/belongs-to-many-repository.d.ts +36 -0
- package/esm/relation-repository/belongs-to-many-repository.js +199 -0
- package/esm/relation-repository/belongs-to-many-repository.js.map +1 -0
- package/esm/relation-repository/belongs-to-repository.d.ts +17 -0
- package/esm/relation-repository/belongs-to-repository.js +4 -0
- package/esm/relation-repository/belongs-to-repository.js.map +1 -0
- package/esm/relation-repository/hasmany-repository.d.ts +23 -0
- package/esm/relation-repository/hasmany-repository.js +125 -0
- package/esm/relation-repository/hasmany-repository.js.map +1 -0
- package/esm/relation-repository/hasone-repository.d.ts +17 -0
- package/esm/relation-repository/hasone-repository.js +4 -0
- package/esm/relation-repository/hasone-repository.js.map +1 -0
- package/esm/relation-repository/multiple-relation-repository.d.ts +23 -0
- package/esm/relation-repository/multiple-relation-repository.js +149 -0
- package/esm/relation-repository/multiple-relation-repository.js.map +1 -0
- package/esm/relation-repository/relation-repository.d.ts +32 -0
- package/esm/relation-repository/relation-repository.js +93 -0
- package/esm/relation-repository/relation-repository.js.map +1 -0
- package/esm/relation-repository/single-relation-repository.d.ts +23 -0
- package/esm/relation-repository/single-relation-repository.js +96 -0
- package/esm/relation-repository/single-relation-repository.js.map +1 -0
- package/esm/relation-repository/types.d.ts +7 -0
- package/esm/relation-repository/types.js +2 -0
- package/esm/relation-repository/types.js.map +1 -0
- package/esm/repository.d.ts +165 -0
- package/esm/repository.js +276 -0
- package/esm/repository.js.map +1 -0
- package/esm/transaction-decorator.d.ts +1 -0
- package/esm/transaction-decorator.js +63 -0
- package/esm/transaction-decorator.js.map +1 -0
- package/esm/update-associations.d.ts +60 -0
- package/esm/update-associations.js +362 -0
- package/esm/update-associations.js.map +1 -0
- package/esm/update-guard.d.ts +26 -0
- package/esm/update-guard.js +122 -0
- package/esm/update-guard.js.map +1 -0
- package/lib/collection-importer.d.ts +7 -0
- package/lib/collection-importer.js +75 -0
- package/lib/collection-importer.js.map +1 -0
- package/lib/collection.d.ts +73 -0
- package/lib/collection.js +231 -0
- package/lib/collection.js.map +1 -0
- package/lib/database.d.ts +93 -43
- package/lib/database.js +277 -471
- package/lib/database.js.map +1 -1
- package/lib/fields/array-field.d.ts +11 -0
- package/lib/fields/array-field.js +30 -0
- package/lib/fields/array-field.js.map +1 -0
- package/lib/fields/belongs-to-field.d.ts +12 -0
- package/lib/fields/belongs-to-field.js +61 -0
- package/lib/fields/belongs-to-field.js.map +1 -0
- package/lib/fields/belongs-to-many-field.d.ts +11 -0
- package/lib/fields/belongs-to-many-field.js +59 -0
- package/lib/fields/belongs-to-many-field.js.map +1 -0
- package/lib/fields/boolean-field.d.ts +8 -0
- package/lib/fields/boolean-field.js +12 -0
- package/lib/fields/boolean-field.js.map +1 -0
- package/lib/fields/context-field.d.ts +13 -0
- package/lib/fields/context-field.js +50 -0
- package/lib/fields/context-field.js.map +1 -0
- package/lib/fields/date-field.d.ts +8 -0
- package/lib/fields/date-field.js +12 -0
- package/lib/fields/date-field.js.map +1 -0
- package/lib/fields/field.d.ts +37 -0
- package/lib/fields/field.js +81 -0
- package/lib/fields/field.js.map +1 -0
- package/lib/fields/has-inverse-field.d.ts +4 -0
- package/lib/fields/has-inverse-field.js +3 -0
- package/lib/fields/has-inverse-field.js.map +1 -0
- package/lib/fields/has-many-field.d.ts +64 -0
- package/lib/fields/has-many-field.js +62 -0
- package/lib/fields/has-many-field.js.map +1 -0
- package/lib/fields/has-one-field.d.ts +64 -0
- package/lib/fields/has-one-field.js +61 -0
- package/lib/fields/has-one-field.js.map +1 -0
- package/lib/fields/index.d.ts +40 -10
- package/lib/fields/index.js +31 -138
- package/lib/fields/index.js.map +1 -1
- package/lib/fields/json-field.d.ts +14 -0
- package/lib/fields/json-field.js +22 -0
- package/lib/fields/json-field.js.map +1 -0
- package/lib/fields/number-field.d.ts +32 -0
- package/lib/fields/number-field.js +36 -0
- package/lib/fields/number-field.js.map +1 -0
- package/lib/fields/password-field.d.ts +21 -0
- package/lib/fields/password-field.js +78 -0
- package/lib/fields/password-field.js.map +1 -0
- package/lib/fields/radio-field.d.ts +14 -0
- package/lib/fields/radio-field.js +53 -0
- package/lib/fields/radio-field.js.map +1 -0
- package/lib/fields/relation-field.d.ts +20 -0
- package/lib/fields/relation-field.js +31 -0
- package/lib/fields/relation-field.js.map +1 -0
- package/lib/fields/sort-field.d.ts +16 -0
- package/lib/fields/sort-field.js +94 -0
- package/lib/fields/sort-field.js.map +1 -0
- package/lib/fields/string-field.d.ts +8 -0
- package/lib/fields/string-field.js +12 -0
- package/lib/fields/string-field.js.map +1 -0
- package/lib/fields/text-field.d.ts +8 -0
- package/lib/fields/text-field.js +12 -0
- package/lib/fields/text-field.js.map +1 -0
- package/lib/fields/time-field.d.ts +8 -0
- package/lib/fields/time-field.js +12 -0
- package/lib/fields/time-field.js.map +1 -0
- package/lib/fields/uid-field.d.ts +10 -0
- package/lib/fields/uid-field.js +31 -0
- package/lib/fields/uid-field.js.map +1 -0
- package/lib/fields/virtual-field.d.ts +8 -0
- package/lib/fields/virtual-field.js +12 -0
- package/lib/fields/virtual-field.js.map +1 -0
- package/lib/filter-parser.d.ts +27 -0
- package/lib/filter-parser.js +191 -0
- package/lib/filter-parser.js.map +1 -0
- package/lib/index.d.ts +13 -6
- package/lib/index.js +27 -60
- package/lib/index.js.map +1 -1
- package/lib/magic-attribute-model.d.ts +7 -0
- package/lib/magic-attribute-model.js +77 -0
- package/lib/magic-attribute-model.js.map +1 -0
- package/lib/mock-database.d.ts +22 -0
- package/lib/mock-database.js +40 -0
- package/lib/mock-database.js.map +1 -0
- package/lib/model-hook.d.ts +12 -0
- package/lib/model-hook.js +68 -0
- package/lib/model-hook.js.map +1 -0
- package/lib/model.d.ts +11 -45
- package/lib/model.js +76 -452
- package/lib/model.js.map +1 -1
- package/lib/operators/array.d.ts +26 -0
- package/lib/operators/array.js +107 -0
- package/lib/operators/array.js.map +1 -0
- package/lib/operators/association.d.ts +10 -0
- package/lib/operators/association.js +16 -0
- package/lib/operators/association.js.map +1 -0
- package/lib/operators/date.d.ts +34 -0
- package/lib/operators/date.js +40 -0
- package/lib/operators/date.js.map +1 -0
- package/lib/operators/empty.d.ts +28 -0
- package/lib/operators/empty.js +82 -0
- package/lib/operators/empty.js.map +1 -0
- package/lib/operators/index.d.ts +2 -0
- package/lib/operators/index.js +4 -0
- package/lib/operators/index.js.map +1 -0
- package/lib/operators/ne.d.ts +10 -0
- package/lib/operators/ne.js +14 -0
- package/lib/operators/ne.js.map +1 -0
- package/lib/operators/string.d.ts +21 -0
- package/lib/operators/string.js +37 -0
- package/lib/operators/string.js.map +1 -0
- package/lib/operators/utils.d.ts +4 -0
- package/lib/operators/utils.js +16 -0
- package/lib/operators/utils.js.map +1 -0
- package/lib/options-parser.d.ts +31 -0
- package/lib/options-parser.js +232 -0
- package/lib/options-parser.js.map +1 -0
- package/lib/playground.d.ts +1 -0
- package/lib/playground.js +55 -0
- package/lib/playground.js.map +1 -0
- package/lib/relation-repository/belongs-to-many-repository.d.ts +36 -0
- package/lib/relation-repository/belongs-to-many-repository.js +206 -0
- package/lib/relation-repository/belongs-to-many-repository.js.map +1 -0
- package/lib/relation-repository/belongs-to-repository.d.ts +17 -0
- package/lib/relation-repository/belongs-to-repository.js +8 -0
- package/lib/relation-repository/belongs-to-repository.js.map +1 -0
- package/lib/relation-repository/hasmany-repository.d.ts +23 -0
- package/lib/relation-repository/hasmany-repository.js +129 -0
- package/lib/relation-repository/hasmany-repository.js.map +1 -0
- package/lib/relation-repository/hasone-repository.d.ts +17 -0
- package/lib/relation-repository/hasone-repository.js +8 -0
- package/lib/relation-repository/hasone-repository.js.map +1 -0
- package/lib/relation-repository/multiple-relation-repository.d.ts +23 -0
- package/lib/relation-repository/multiple-relation-repository.js +153 -0
- package/lib/relation-repository/multiple-relation-repository.js.map +1 -0
- package/lib/relation-repository/relation-repository.d.ts +32 -0
- package/lib/relation-repository/relation-repository.js +100 -0
- package/lib/relation-repository/relation-repository.js.map +1 -0
- package/lib/relation-repository/single-relation-repository.d.ts +23 -0
- package/lib/relation-repository/single-relation-repository.js +103 -0
- package/lib/relation-repository/single-relation-repository.js.map +1 -0
- package/lib/relation-repository/types.d.ts +7 -0
- package/lib/relation-repository/types.js +3 -0
- package/lib/relation-repository/types.js.map +1 -0
- package/lib/repository.d.ts +165 -0
- package/lib/repository.js +302 -0
- package/lib/repository.js.map +1 -0
- package/lib/transaction-decorator.d.ts +1 -0
- package/lib/transaction-decorator.js +70 -0
- package/lib/transaction-decorator.js.map +1 -0
- package/lib/update-associations.d.ts +60 -0
- package/lib/update-associations.js +374 -0
- package/lib/update-associations.js.map +1 -0
- package/lib/update-guard.d.ts +26 -0
- package/lib/update-guard.js +129 -0
- package/lib/update-guard.js.map +1 -0
- package/package.json +17 -5
- package/src/__tests__/collection-importer.test.ts +21 -0
- package/src/__tests__/collection.sortable.test.ts +65 -0
- package/src/__tests__/collection.test.ts +218 -0
- package/src/__tests__/database.import.test.ts +33 -0
- package/src/__tests__/database.test.ts +229 -0
- package/src/__tests__/field-options/hidden.test.ts +302 -0
- package/src/__tests__/field-options/sort-by.test.ts +220 -0
- package/src/__tests__/fields/belongs-to-field.test.ts +162 -0
- package/src/__tests__/fields/belongs-to-many-field.test.ts +61 -0
- package/src/__tests__/fields/context-field.test.ts +140 -0
- package/src/__tests__/fields/has-many-field.test.ts +152 -0
- package/src/__tests__/fields/has-one-field.test.ts +67 -0
- package/src/__tests__/fields/password-field.test.ts +30 -0
- package/src/__tests__/fields/sort-field.test.ts +133 -0
- package/src/__tests__/fields/string-field.test.ts +77 -0
- package/src/__tests__/filter-parser.test.ts +104 -0
- package/src/__tests__/fixtures/c0/a.ts +6 -0
- package/src/__tests__/fixtures/c1/b.ts +6 -0
- package/src/__tests__/fixtures/c2/a.ts +6 -0
- package/src/__tests__/fixtures/collections/delay-extend.ts +6 -0
- package/src/__tests__/fixtures/collections/delay-extend2.ts +6 -0
- package/src/__tests__/fixtures/collections/extend.ts +6 -0
- package/src/__tests__/fixtures/collections/extend2.ts +6 -0
- package/src/__tests__/fixtures/collections/posts.ts +4 -0
- package/src/__tests__/fixtures/collections/tags.js +4 -0
- package/src/__tests__/fixtures/collections/test.jpg +0 -0
- package/src/__tests__/fixtures/collections/user.json +9 -0
- package/src/__tests__/index.ts +1 -0
- package/src/__tests__/magic-attribute-model.test.ts +103 -0
- package/src/__tests__/model.test.ts +60 -0
- package/src/__tests__/operator/array-operator.test.ts +268 -0
- package/src/__tests__/operator/association-operator.test.ts +263 -0
- package/src/__tests__/operator/date-operator.test.ts +165 -0
- package/src/__tests__/operator/empty-operator.test.ts +77 -0
- package/src/__tests__/operator/ne.test.ts +33 -0
- package/src/__tests__/operator/string-operator.test.ts +62 -0
- package/src/__tests__/option-parser.test.ts +185 -0
- package/src/__tests__/relation-repository/belongs-to-many-repository.test.ts +697 -0
- package/src/__tests__/relation-repository/has-many-repository.test.ts +414 -0
- package/src/__tests__/relation-repository/hasone-repository.test.ts +77 -0
- package/src/__tests__/repository/count.test.ts +180 -0
- package/src/__tests__/repository/create.test.ts +163 -0
- package/src/__tests__/repository/destroy.test.ts +196 -0
- package/src/__tests__/repository/find.test.ts +247 -0
- package/src/__tests__/repository/update.test.ts +60 -0
- package/src/__tests__/repository.test.ts +438 -0
- package/src/__tests__/update-associations.test.ts +412 -0
- package/src/__tests__/update-guard.test.ts +376 -0
- package/src/collection-importer.ts +49 -0
- package/src/collection.ts +282 -0
- package/src/database.ts +340 -0
- package/src/fields/array-field.ts +35 -0
- package/src/fields/belongs-to-field.ts +76 -0
- package/src/fields/belongs-to-many-field.ts +77 -0
- package/src/fields/boolean-field.ts +12 -0
- package/src/fields/context-field.ts +45 -0
- package/src/fields/date-field.ts +12 -0
- package/src/fields/field.ts +105 -0
- package/src/fields/has-inverse-field.ts +5 -0
- package/src/fields/has-many-field.ts +143 -0
- package/src/fields/has-one-field.ts +136 -0
- package/src/fields/index.ts +72 -0
- package/src/fields/json-field.ts +25 -0
- package/src/fields/number-field.ts +52 -0
- package/src/fields/password-field.ts +72 -0
- package/src/fields/radio-field.ts +50 -0
- package/src/fields/relation-field.ts +37 -0
- package/src/fields/sort-field.ts +96 -0
- package/src/fields/string-field.ts +12 -0
- package/src/fields/text-field.ts +12 -0
- package/src/fields/time-field.ts +12 -0
- package/src/fields/uid-field.ts +24 -0
- package/src/fields/virtual-field.ts +12 -0
- package/src/filter-parser.ts +243 -0
- package/src/index.ts +16 -0
- package/src/magic-attribute-model.ts +62 -0
- package/src/mock-database.ts +42 -0
- package/src/model-hook.ts +69 -0
- package/src/model.ts +114 -0
- package/src/operators/array.ts +145 -0
- package/src/operators/association.ts +14 -0
- package/src/operators/date.ts +41 -0
- package/src/operators/empty.ts +75 -0
- package/src/operators/index.ts +8 -0
- package/src/operators/ne.ts +12 -0
- package/src/operators/string.ts +40 -0
- package/src/operators/utils.ts +13 -0
- package/src/options-parser.ts +285 -0
- package/src/playground.ts +52 -0
- package/src/relation-repository/belongs-to-many-repository.ts +240 -0
- package/src/relation-repository/belongs-to-repository.ts +23 -0
- package/src/relation-repository/hasmany-repository.ts +145 -0
- package/src/relation-repository/hasone-repository.ts +23 -0
- package/src/relation-repository/multiple-relation-repository.ts +198 -0
- package/src/relation-repository/relation-repository.ts +114 -0
- package/src/relation-repository/single-relation-repository.ts +99 -0
- package/src/relation-repository/types.ts +15 -0
- package/src/repository.ts +478 -0
- package/src/transaction-decorator.ts +58 -0
- package/src/update-associations.ts +478 -0
- package/src/update-guard.ts +167 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +5 -0
- package/examples/index.ts +0 -125
- package/examples/plugins/db-driven/index.ts +0 -25
- package/examples/plugins/db-driven/tables/fields.ts +0 -78
- package/examples/plugins/db-driven/tables/tables.ts +0 -53
- package/examples/tables/bar.js +0 -26
- package/examples/tables/comments.ts +0 -19
- package/examples/tables/foo.json +0 -3
- package/examples/tables/posts.ts +0 -28
- package/examples/tables/profiles.ts +0 -23
- package/examples/tables/tags.ts +0 -15
- package/examples/tables/users.ts +0 -34
- package/lib/database.d.ts.map +0 -1
- package/lib/fields/field-types.d.ts +0 -419
- package/lib/fields/field-types.d.ts.map +0 -1
- package/lib/fields/field-types.js +0 -1222
- package/lib/fields/field-types.js.map +0 -1
- package/lib/fields/index.d.ts.map +0 -1
- package/lib/fields/option-types.d.ts +0 -105
- package/lib/fields/option-types.d.ts.map +0 -1
- package/lib/fields/option-types.js +0 -18
- package/lib/fields/option-types.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/model.d.ts.map +0 -1
- package/lib/op.d.ts +0 -45
- package/lib/op.d.ts.map +0 -1
- package/lib/op.js +0 -225
- package/lib/op.js.map +0 -1
- package/lib/table.d.ts +0 -56
- package/lib/table.d.ts.map +0 -1
- package/lib/table.js +0 -456
- package/lib/table.js.map +0 -1
- package/lib/utils.d.ts +0 -26
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -438
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { omit } from 'lodash';
|
|
17
|
+
import { Op } from 'sequelize';
|
|
18
|
+
import { MultipleRelationRepository } from './multiple-relation-repository';
|
|
19
|
+
import { transaction } from './relation-repository';
|
|
20
|
+
export class HasManyRepository extends MultipleRelationRepository {
|
|
21
|
+
find(options) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const targetRepository = this.targetCollection.repository;
|
|
24
|
+
const addFilter = {
|
|
25
|
+
[this.association.foreignKey]: this.sourceKeyValue,
|
|
26
|
+
};
|
|
27
|
+
if (options === null || options === void 0 ? void 0 : options.filterByTk) {
|
|
28
|
+
addFilter[this.associationField.targetKey] = options.filterByTk;
|
|
29
|
+
}
|
|
30
|
+
return yield targetRepository.find(Object.assign(Object.assign({}, omit(options, ['filterByTk'])), { filter: {
|
|
31
|
+
$and: [options.filter || {}, addFilter],
|
|
32
|
+
} }));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
destroy(options) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const transaction = yield this.getTransaction(options);
|
|
38
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
39
|
+
const where = [
|
|
40
|
+
{
|
|
41
|
+
[this.association.foreignKey]: sourceModel.get(this.association.sourceKey),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
if (options && options['filter']) {
|
|
45
|
+
const filterResult = this.parseFilter(options['filter'], options);
|
|
46
|
+
if (filterResult.include && filterResult.include.length > 0) {
|
|
47
|
+
return yield this.destroyByFilter(options['filter'], transaction);
|
|
48
|
+
}
|
|
49
|
+
where.push(filterResult.where);
|
|
50
|
+
}
|
|
51
|
+
if (options && options['filterByTk']) {
|
|
52
|
+
if (typeof options === 'object' && options['filterByTk']) {
|
|
53
|
+
options = options['filterByTk'];
|
|
54
|
+
}
|
|
55
|
+
where.push({
|
|
56
|
+
[this.targetKey()]: options,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
yield this.targetModel.destroy({
|
|
60
|
+
where: {
|
|
61
|
+
[Op.and]: where,
|
|
62
|
+
},
|
|
63
|
+
individualHooks: true,
|
|
64
|
+
transaction,
|
|
65
|
+
});
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
handleKeyOfAdd(options) {
|
|
70
|
+
let handleKeys;
|
|
71
|
+
if (typeof options !== 'object' && !Array.isArray(options)) {
|
|
72
|
+
handleKeys = [options];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
handleKeys = options['pk'];
|
|
76
|
+
}
|
|
77
|
+
return handleKeys;
|
|
78
|
+
}
|
|
79
|
+
set(options) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const transaction = yield this.getTransaction(options);
|
|
82
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
83
|
+
yield sourceModel[this.accessors().set](this.handleKeyOfAdd(options), {
|
|
84
|
+
transaction,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
add(options) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const transaction = yield this.getTransaction(options);
|
|
91
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
92
|
+
yield sourceModel[this.accessors().add](this.handleKeyOfAdd(options), {
|
|
93
|
+
transaction,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
accessors() {
|
|
98
|
+
return this.association.accessors;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
__decorate([
|
|
102
|
+
transaction((args, transaction) => {
|
|
103
|
+
return {
|
|
104
|
+
filterByTk: args[0],
|
|
105
|
+
transaction,
|
|
106
|
+
};
|
|
107
|
+
})
|
|
108
|
+
], HasManyRepository.prototype, "destroy", null);
|
|
109
|
+
__decorate([
|
|
110
|
+
transaction((args, transaction) => {
|
|
111
|
+
return {
|
|
112
|
+
pk: args[0],
|
|
113
|
+
transaction,
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
], HasManyRepository.prototype, "set", null);
|
|
117
|
+
__decorate([
|
|
118
|
+
transaction((args, transaction) => {
|
|
119
|
+
return {
|
|
120
|
+
pk: args[0],
|
|
121
|
+
transaction,
|
|
122
|
+
};
|
|
123
|
+
})
|
|
124
|
+
], HasManyRepository.prototype, "add", null);
|
|
125
|
+
//# sourceMappingURL=hasmany-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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":["import { omit } from 'lodash';\nimport { HasMany, Op } from 'sequelize';\nimport { Model } from '../model';\nimport { CreateOptions, DestroyOptions, FindOptions, TargetKey, TK, UpdateOptions } from '../repository';\nimport {\n AssociatedOptions,\n FindAndCountOptions,\n FindOneOptions,\n MultipleRelationRepository\n} from './multiple-relation-repository';\nimport { transaction } from './relation-repository';\n\ninterface IHasManyRepository<M extends Model> {\n find(options?: FindOptions): Promise<M>;\n findAndCount(options?: FindAndCountOptions): Promise<[M[], number]>;\n findOne(options?: FindOneOptions): Promise<M>;\n // 新增并关联\n create(options?: CreateOptions): Promise<M>;\n // 更新\n update(options?: UpdateOptions): Promise<M>;\n // 删除\n destroy(options?: TK | DestroyOptions): Promise<Boolean>;\n // 建立关联\n set(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;\n // 附加关联\n add(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;\n // 移除关联\n remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;\n}\n\nexport class HasManyRepository extends MultipleRelationRepository implements IHasManyRepository<any> {\n async find(options?: FindOptions): Promise<any> {\n const targetRepository = this.targetCollection.repository;\n\n const addFilter = {\n [this.association.foreignKey]: this.sourceKeyValue,\n };\n\n if (options?.filterByTk) {\n addFilter[this.associationField.targetKey] = options.filterByTk;\n }\n\n return await targetRepository.find({\n ...omit(options, ['filterByTk']),\n filter: {\n $and: [options.filter || {}, addFilter],\n },\n });\n }\n\n @transaction((args, transaction) => {\n return {\n filterByTk: args[0],\n transaction,\n };\n })\n async destroy(options?: TK | DestroyOptions): Promise<Boolean> {\n const transaction = await this.getTransaction(options);\n\n const sourceModel = await this.getSourceModel(transaction);\n\n const where = [\n {\n [this.association.foreignKey]: sourceModel.get((this.association as any).sourceKey),\n },\n ];\n\n if (options && options['filter']) {\n const filterResult = this.parseFilter(options['filter'], options);\n\n if (filterResult.include && filterResult.include.length > 0) {\n return await this.destroyByFilter(options['filter'], transaction);\n }\n\n where.push(filterResult.where);\n }\n\n if (options && options['filterByTk']) {\n if (typeof options === 'object' && options['filterByTk']) {\n options = options['filterByTk'];\n }\n\n where.push({\n [this.targetKey()]: options,\n });\n }\n\n await this.targetModel.destroy({\n where: {\n [Op.and]: where,\n },\n individualHooks: true,\n transaction,\n });\n\n return true;\n }\n\n handleKeyOfAdd(options) {\n let handleKeys;\n\n if (typeof options !== 'object' && !Array.isArray(options)) {\n handleKeys = [options];\n } else {\n handleKeys = options['pk'];\n }\n return handleKeys;\n }\n\n @transaction((args, transaction) => {\n return {\n pk: args[0],\n transaction,\n };\n })\n async set(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void> {\n const transaction = await this.getTransaction(options);\n\n const sourceModel = await this.getSourceModel(transaction);\n\n await sourceModel[this.accessors().set](this.handleKeyOfAdd(options), {\n transaction,\n });\n }\n\n @transaction((args, transaction) => {\n return {\n pk: args[0],\n transaction,\n };\n })\n async add(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void> {\n const transaction = await this.getTransaction(options);\n\n const sourceModel = await this.getSourceModel(transaction);\n\n await sourceModel[this.accessors().add](this.handleKeyOfAdd(options), {\n transaction,\n });\n }\n\n accessors() {\n return (<HasMany>this.association).accessors;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Model } from '../model';
|
|
2
|
+
import { CreateOptions } from '../repository';
|
|
3
|
+
import { SingleRelationFindOption, SingleRelationRepository } from './single-relation-repository';
|
|
4
|
+
interface HasOneFindOptions extends SingleRelationFindOption {
|
|
5
|
+
}
|
|
6
|
+
interface IHasOneRepository<M extends Model> {
|
|
7
|
+
find(options?: HasOneFindOptions): Promise<M>;
|
|
8
|
+
findOne(options?: HasOneFindOptions): Promise<M>;
|
|
9
|
+
create(options?: CreateOptions): Promise<M>;
|
|
10
|
+
update(options?: any): Promise<M>;
|
|
11
|
+
destroy(): Promise<Boolean>;
|
|
12
|
+
set(primaryKey: any): Promise<void>;
|
|
13
|
+
remove(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare class HasOneRepository extends SingleRelationRepository implements IHasOneRepository<any> {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasone-repository.js","sourceRoot":"","sources":["../../src/relation-repository/hasone-repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAoBlG,MAAM,OAAO,gBAAiB,SAAQ,wBAAwB;CAAqC","sourcesContent":["import { Model } from '../model';\nimport { CreateOptions } from '../repository';\nimport { SingleRelationFindOption, SingleRelationRepository } from './single-relation-repository';\n\ninterface HasOneFindOptions extends SingleRelationFindOption {}\n\ninterface IHasOneRepository<M extends Model> {\n // 不需要 findOne,find 就是 findOne\n find(options?: HasOneFindOptions): Promise<M>;\n findOne(options?: HasOneFindOptions): Promise<M>;\n // 新增并关联,如果存在关联,解除之后,与新数据建立关联\n create(options?: CreateOptions): Promise<M>;\n // 更新\n update(options?): Promise<M>;\n // 删除\n destroy(): Promise<Boolean>;\n // 建立关联\n set(primaryKey: any): Promise<void>;\n // 移除关联\n remove(): Promise<void>;\n}\n\nexport class HasOneRepository extends SingleRelationRepository implements IHasOneRepository<any> {}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MultiAssociationAccessors, Transaction } from 'sequelize';
|
|
2
|
+
import { CommonFindOptions, CountOptions, DestroyOptions, Filter, FilterByTk, FindOptions, TargetKey, TK, TransactionAble, UpdateOptions } from '../repository';
|
|
3
|
+
import { RelationRepository } from './relation-repository';
|
|
4
|
+
export interface FindAndCountOptions extends CommonFindOptions {
|
|
5
|
+
}
|
|
6
|
+
export interface FindOneOptions extends CommonFindOptions, FilterByTk {
|
|
7
|
+
}
|
|
8
|
+
export interface AssociatedOptions extends TransactionAble {
|
|
9
|
+
tk?: TK;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class MultipleRelationRepository extends RelationRepository {
|
|
12
|
+
extendFindOptions(findOptions: any): any;
|
|
13
|
+
find(options?: FindOptions): Promise<any>;
|
|
14
|
+
findAndCount(options?: FindAndCountOptions): Promise<[any[], number]>;
|
|
15
|
+
count(options?: CountOptions): Promise<number>;
|
|
16
|
+
findOne(options?: FindOneOptions): Promise<any>;
|
|
17
|
+
remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void>;
|
|
18
|
+
update(options?: UpdateOptions): Promise<any>;
|
|
19
|
+
destroy(options?: TK | DestroyOptions): Promise<Boolean>;
|
|
20
|
+
protected destroyByFilter(filter: Filter, transaction?: Transaction): Promise<Boolean>;
|
|
21
|
+
protected filterHasInclude(filter: Filter, options?: any): boolean;
|
|
22
|
+
protected accessors(): MultiAssociationAccessors;
|
|
23
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { omit } from 'lodash';
|
|
17
|
+
import { Op, Sequelize } from 'sequelize';
|
|
18
|
+
import { updateModelByValues } from '../update-associations';
|
|
19
|
+
import { UpdateGuard } from '../update-guard';
|
|
20
|
+
import { RelationRepository, transaction } from './relation-repository';
|
|
21
|
+
export class MultipleRelationRepository extends RelationRepository {
|
|
22
|
+
extendFindOptions(findOptions) {
|
|
23
|
+
return findOptions;
|
|
24
|
+
}
|
|
25
|
+
find(options) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const transaction = yield this.getTransaction(options);
|
|
28
|
+
const findOptions = Object.assign(Object.assign({}, this.extendFindOptions(this.buildQueryOptions(Object.assign({}, options)))), { subQuery: false });
|
|
29
|
+
const getAccessor = this.accessors().get;
|
|
30
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
31
|
+
if (findOptions.include && findOptions.include.length > 0) {
|
|
32
|
+
const ids = (yield sourceModel[getAccessor](Object.assign(Object.assign({}, findOptions), { includeIgnoreAttributes: false, attributes: [this.targetKey()], group: `${this.targetModel.name}.${this.targetKey()}`, transaction }))).map((row) => row.get(this.targetKey()));
|
|
33
|
+
return yield sourceModel[getAccessor](Object.assign(Object.assign({}, omit(findOptions, ['limit', 'offset'])), { where: {
|
|
34
|
+
[this.targetKey()]: {
|
|
35
|
+
[Op.in]: ids,
|
|
36
|
+
},
|
|
37
|
+
}, transaction }));
|
|
38
|
+
}
|
|
39
|
+
return yield sourceModel[getAccessor](Object.assign(Object.assign({}, findOptions), { transaction }));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
findAndCount(options) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const transaction = yield this.getTransaction(options, false);
|
|
45
|
+
return [
|
|
46
|
+
yield this.find(Object.assign(Object.assign({}, options), { transaction })),
|
|
47
|
+
yield this.count(Object.assign(Object.assign({}, options), { transaction })),
|
|
48
|
+
];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
count(options) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const transaction = yield this.getTransaction(options);
|
|
54
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
55
|
+
const queryOptions = this.buildQueryOptions(options);
|
|
56
|
+
const count = yield sourceModel[this.accessors().get]({
|
|
57
|
+
where: queryOptions.where,
|
|
58
|
+
include: queryOptions.include,
|
|
59
|
+
includeIgnoreAttributes: false,
|
|
60
|
+
attributes: [
|
|
61
|
+
[
|
|
62
|
+
Sequelize.fn('COUNT', Sequelize.fn('DISTINCT', Sequelize.col(`${this.targetModel.name}.${this.targetKey()}`))),
|
|
63
|
+
'count',
|
|
64
|
+
],
|
|
65
|
+
],
|
|
66
|
+
raw: true,
|
|
67
|
+
plain: true,
|
|
68
|
+
transaction,
|
|
69
|
+
});
|
|
70
|
+
return parseInt(count.count);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
findOne(options) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const transaction = yield this.getTransaction(options, false);
|
|
76
|
+
const rows = yield this.find(Object.assign(Object.assign({}, options), { limit: 1, transaction }));
|
|
77
|
+
return rows.length == 1 ? rows[0] : null;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
remove(options) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const transaction = yield this.getTransaction(options);
|
|
83
|
+
let handleKeys = options['tk'];
|
|
84
|
+
if (!Array.isArray(handleKeys)) {
|
|
85
|
+
handleKeys = [handleKeys];
|
|
86
|
+
}
|
|
87
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
88
|
+
yield sourceModel[this.accessors().removeMultiple](handleKeys, {
|
|
89
|
+
transaction,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
update(options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const transaction = yield this.getTransaction(options);
|
|
97
|
+
const guard = UpdateGuard.fromOptions(this.targetModel, options);
|
|
98
|
+
const values = guard.sanitize(options.values);
|
|
99
|
+
const queryOptions = this.buildQueryOptions(options);
|
|
100
|
+
const instances = yield this.find(queryOptions);
|
|
101
|
+
for (const instance of instances) {
|
|
102
|
+
yield updateModelByValues(instance, values, Object.assign(Object.assign({}, options), { sanitized: true, sourceModel: this.sourceInstance, transaction }));
|
|
103
|
+
}
|
|
104
|
+
for (const instance of instances) {
|
|
105
|
+
if (options.hooks !== false) {
|
|
106
|
+
yield this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, options);
|
|
107
|
+
yield this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, options);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return instances;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
destroy(options) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
return false;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
destroyByFilter(filter, transaction) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const instances = yield this.find({
|
|
121
|
+
filter: filter,
|
|
122
|
+
transaction,
|
|
123
|
+
});
|
|
124
|
+
return yield this.destroy({
|
|
125
|
+
filterByTk: instances.map((instance) => instance.get(this.targetCollection.filterTargetKey)),
|
|
126
|
+
transaction,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
filterHasInclude(filter, options) {
|
|
131
|
+
const filterResult = this.parseFilter(filter, options);
|
|
132
|
+
return filterResult.include && filterResult.include.length > 0;
|
|
133
|
+
}
|
|
134
|
+
accessors() {
|
|
135
|
+
return super.accessors();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
__decorate([
|
|
139
|
+
transaction((args, transaction) => {
|
|
140
|
+
return {
|
|
141
|
+
tk: args[0],
|
|
142
|
+
transaction,
|
|
143
|
+
};
|
|
144
|
+
})
|
|
145
|
+
], MultipleRelationRepository.prototype, "remove", null);
|
|
146
|
+
__decorate([
|
|
147
|
+
transaction()
|
|
148
|
+
], MultipleRelationRepository.prototype, "update", null);
|
|
149
|
+
//# sourceMappingURL=multiple-relation-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple-relation-repository.js","sourceRoot":"","sources":["../../src/relation-repository/multiple-relation-repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAA6B,EAAE,EAAE,SAAS,EAAe,MAAM,WAAW,CAAC;AAalF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAUxE,MAAM,OAAgB,0BAA2B,SAAQ,kBAAkB;IACzE,iBAAiB,CAAC,WAAW;QAC3B,OAAO,WAAW,CAAC;IACrB,CAAC;IAEK,IAAI,CAAC,OAAqB;;YAC9B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAEvD,MAAM,WAAW,mCACZ,IAAI,CAAC,iBAAiB,CACvB,IAAI,CAAC,iBAAiB,mBACjB,OAAO,EACV,CACH,KACD,QAAQ,EAAE,KAAK,GAChB,CAAC;YAEF,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC;YACzC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAE3D,IAAI,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gBACzD,MAA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O,CAAC,OAA6B;;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IAEe,eAAe,CAAC,MAAc,EAAE,WAAyB;;YACvE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBAChC,MAAM,EAAE,MAAM;gBACd,WAAW;aACZ,CAAC,CAAC;YAEH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;gBACxB,UAAU,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;gBAC5F,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;KAAA;IAES,gBAAgB,CAAC,MAAc,EAAE,OAAa;QACtD,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACjE,CAAC;IAES,SAAS;QACjB,OAAkC,KAAK,CAAC,SAAS,EAAE,CAAC;IACtD,CAAC;CACF;AAtEC;IANC,WAAW,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE;QACjC,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;YACX,WAAW;SACZ,CAAC;IACJ,CAAC,CAAC;wDAcD;AAGD;IADC,WAAW,EAAE;wDA6Bb","sourcesContent":["import { omit } from 'lodash';\nimport { MultiAssociationAccessors, Op, Sequelize, Transaction } from 'sequelize';\nimport {\n CommonFindOptions,\n CountOptions,\n DestroyOptions,\n Filter,\n FilterByTk,\n FindOptions,\n TargetKey,\n TK,\n TransactionAble,\n UpdateOptions\n} from '../repository';\nimport { updateModelByValues } from '../update-associations';\nimport { UpdateGuard } from '../update-guard';\nimport { RelationRepository, transaction } from './relation-repository';\n\nexport interface FindAndCountOptions extends CommonFindOptions {}\n\nexport interface FindOneOptions extends CommonFindOptions, FilterByTk {}\n\nexport interface AssociatedOptions extends TransactionAble {\n tk?: TK;\n}\n\nexport abstract class MultipleRelationRepository extends RelationRepository {\n extendFindOptions(findOptions) {\n return findOptions;\n }\n\n async find(options?: FindOptions): Promise<any> {\n const transaction = await this.getTransaction(options);\n\n const findOptions = {\n ...this.extendFindOptions(\n this.buildQueryOptions({\n ...options,\n }),\n ),\n subQuery: false,\n };\n\n const getAccessor = this.accessors().get;\n const sourceModel = await this.getSourceModel(transaction);\n\n if (findOptions.include && findOptions.include.length > 0) {\n const ids = (\n await sourceModel[getAccessor]({\n ...findOptions,\n includeIgnoreAttributes: false,\n attributes: [this.targetKey()],\n group: `${this.targetModel.name}.${this.targetKey()}`,\n transaction,\n })\n ).map((row) => row.get(this.targetKey()));\n\n return await sourceModel[getAccessor]({\n ...omit(findOptions, ['limit', 'offset']),\n where: {\n [this.targetKey()]: {\n [Op.in]: ids,\n },\n },\n transaction,\n });\n }\n\n return await sourceModel[getAccessor]({\n ...findOptions,\n transaction,\n });\n }\n\n async findAndCount(options?: FindAndCountOptions): Promise<[any[], number]> {\n const transaction = await this.getTransaction(options, false);\n return [\n await this.find({\n ...options,\n transaction,\n }),\n await this.count({\n ...options,\n transaction,\n }),\n ];\n }\n\n async count(options?: CountOptions) {\n const transaction = await this.getTransaction(options);\n\n const sourceModel = await this.getSourceModel(transaction);\n const queryOptions = this.buildQueryOptions(options);\n\n const count = await sourceModel[this.accessors().get]({\n where: queryOptions.where,\n include: queryOptions.include,\n includeIgnoreAttributes: false,\n attributes: [\n [\n Sequelize.fn(\n 'COUNT',\n Sequelize.fn('DISTINCT', Sequelize.col(`${this.targetModel.name}.${this.targetKey()}`)),\n ),\n 'count',\n ],\n ],\n raw: true,\n plain: true,\n transaction,\n });\n\n return parseInt(count.count);\n }\n\n async findOne(options?: FindOneOptions): Promise<any> {\n const transaction = await this.getTransaction(options, false);\n const rows = await this.find({ ...options, limit: 1, transaction });\n return rows.length == 1 ? rows[0] : null;\n }\n\n @transaction((args, transaction) => {\n return {\n tk: args[0],\n transaction,\n };\n })\n async remove(options: TargetKey | TargetKey[] | AssociatedOptions): Promise<void> {\n const transaction = await this.getTransaction(options);\n let handleKeys = options['tk'];\n\n if (!Array.isArray(handleKeys)) {\n handleKeys = [handleKeys];\n }\n\n const sourceModel = await this.getSourceModel(transaction);\n await sourceModel[this.accessors().removeMultiple](handleKeys, {\n transaction,\n });\n return;\n }\n\n @transaction()\n async update(options?: UpdateOptions): Promise<any> {\n const transaction = await this.getTransaction(options);\n\n const guard = UpdateGuard.fromOptions(this.targetModel, options);\n\n const values = guard.sanitize(options.values);\n\n const queryOptions = this.buildQueryOptions(options as any);\n\n const instances = await this.find(queryOptions);\n\n for (const instance of instances) {\n await updateModelByValues(instance, values, {\n ...options,\n sanitized: true,\n sourceModel: this.sourceInstance,\n transaction,\n });\n }\n\n for (const instance of instances) {\n if (options.hooks !== false) {\n await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, options);\n await this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, options);\n }\n }\n\n return instances;\n }\n\n async destroy(options?: TK | DestroyOptions): Promise<Boolean> {\n return false;\n }\n\n protected async destroyByFilter(filter: Filter, transaction?: Transaction) {\n const instances = await this.find({\n filter: filter,\n transaction,\n });\n\n return await this.destroy({\n filterByTk: instances.map((instance) => instance.get(this.targetCollection.filterTargetKey)),\n transaction,\n });\n }\n\n protected filterHasInclude(filter: Filter, options?: any) {\n const filterResult = this.parseFilter(filter, options);\n return filterResult.include && filterResult.include.length > 0;\n }\n\n protected accessors() {\n return <MultiAssociationAccessors>super.accessors();\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Association, ModelCtor, Transaction } from 'sequelize';
|
|
2
|
+
import { Collection } from '../collection';
|
|
3
|
+
import Database from '../database';
|
|
4
|
+
import { RelationField } from '../fields/relation-field';
|
|
5
|
+
import { Model } from '../model';
|
|
6
|
+
import { CreateOptions, Filter, FindOptions } from '../repository';
|
|
7
|
+
export declare const transaction: (transactionInjector?: any) => (target: any, name: any, descriptor: any) => any;
|
|
8
|
+
export declare abstract class RelationRepository {
|
|
9
|
+
sourceCollection: Collection;
|
|
10
|
+
association: Association;
|
|
11
|
+
targetModel: ModelCtor<any>;
|
|
12
|
+
targetCollection: Collection;
|
|
13
|
+
associationName: string;
|
|
14
|
+
associationField: RelationField;
|
|
15
|
+
sourceKeyValue: string | number;
|
|
16
|
+
sourceInstance: Model;
|
|
17
|
+
db: Database;
|
|
18
|
+
constructor(sourceCollection: Collection, association: string, sourceKeyValue: string | number);
|
|
19
|
+
targetKey(): any;
|
|
20
|
+
protected accessors(): import("sequelize").SingleAssociationAccessors | import("sequelize").MultiAssociationAccessors;
|
|
21
|
+
create(options?: CreateOptions): Promise<any>;
|
|
22
|
+
getSourceModel(transaction?: any): Promise<Model<any, any>>;
|
|
23
|
+
protected buildQueryOptions(options: FindOptions): any;
|
|
24
|
+
protected parseFilter(filter: Filter, options?: any): {
|
|
25
|
+
where?: undefined;
|
|
26
|
+
include?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
where: {};
|
|
29
|
+
include: any[];
|
|
30
|
+
};
|
|
31
|
+
protected getTransaction(options: any, autoGen?: boolean): Promise<Transaction | null>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import lodash from 'lodash';
|
|
11
|
+
import FilterParser from '../filter-parser';
|
|
12
|
+
import { OptionsParser } from '../options-parser';
|
|
13
|
+
import { transactionWrapperBuilder } from '../transaction-decorator';
|
|
14
|
+
import { updateAssociations } from '../update-associations';
|
|
15
|
+
import { UpdateGuard } from '../update-guard';
|
|
16
|
+
export const transaction = transactionWrapperBuilder(function () {
|
|
17
|
+
return this.sourceCollection.model.sequelize.transaction();
|
|
18
|
+
});
|
|
19
|
+
export class RelationRepository {
|
|
20
|
+
constructor(sourceCollection, association, sourceKeyValue) {
|
|
21
|
+
this.db = sourceCollection.context.database;
|
|
22
|
+
this.sourceCollection = sourceCollection;
|
|
23
|
+
this.sourceKeyValue = sourceKeyValue;
|
|
24
|
+
this.associationName = association;
|
|
25
|
+
this.association = this.sourceCollection.model.associations[association];
|
|
26
|
+
this.associationField = this.sourceCollection.getField(association);
|
|
27
|
+
this.targetModel = this.association.target;
|
|
28
|
+
this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
|
|
29
|
+
}
|
|
30
|
+
targetKey() {
|
|
31
|
+
return this.associationField.targetKey;
|
|
32
|
+
}
|
|
33
|
+
accessors() {
|
|
34
|
+
return this.association.accessors;
|
|
35
|
+
}
|
|
36
|
+
create(options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const createAccessor = this.accessors().create;
|
|
39
|
+
const guard = UpdateGuard.fromOptions(this.targetModel, options);
|
|
40
|
+
const values = options.values;
|
|
41
|
+
const sourceModel = yield this.getSourceModel();
|
|
42
|
+
const instance = yield sourceModel[createAccessor](guard.sanitize(options.values), options);
|
|
43
|
+
yield updateAssociations(instance, values, options);
|
|
44
|
+
if (options.hooks !== false) {
|
|
45
|
+
yield this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, options);
|
|
46
|
+
const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
|
|
47
|
+
yield this.db.emitAsync(eventName, instance, options);
|
|
48
|
+
}
|
|
49
|
+
return instance;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getSourceModel(transaction) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (!this.sourceInstance) {
|
|
55
|
+
this.sourceInstance = yield this.sourceCollection.model.findOne({
|
|
56
|
+
where: {
|
|
57
|
+
[this.associationField.sourceKey]: this.sourceKeyValue,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return this.sourceInstance;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
buildQueryOptions(options) {
|
|
65
|
+
const parser = new OptionsParser(options, {
|
|
66
|
+
collection: this.targetCollection,
|
|
67
|
+
targetKey: this.targetKey(),
|
|
68
|
+
});
|
|
69
|
+
const params = parser.toSequelizeParams();
|
|
70
|
+
return Object.assign(Object.assign({}, options), params);
|
|
71
|
+
}
|
|
72
|
+
parseFilter(filter, options) {
|
|
73
|
+
const parser = new FilterParser(filter, {
|
|
74
|
+
collection: this.targetCollection,
|
|
75
|
+
app: {
|
|
76
|
+
ctx: options === null || options === void 0 ? void 0 : options.context,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
return parser.toSequelizeParams();
|
|
80
|
+
}
|
|
81
|
+
getTransaction(options, autoGen = false) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (lodash.isPlainObject(options) && options.transaction) {
|
|
84
|
+
return options.transaction;
|
|
85
|
+
}
|
|
86
|
+
if (autoGen) {
|
|
87
|
+
return yield this.sourceCollection.model.sequelize.transaction();
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=relation-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation-repository.js","sourceRoot":"","sources":["../../src/relation-repository/relation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;qBACvD;iBACF,CAAC,CAAC;aACJ;YAED,OAAO,IAAI,CAAC,cAAc,CAAC;QAC7B,CAAC;KAAA;IAES,iBAAiB,CAAC,OAAoB;QAC9C,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,OAAO,EAAE;YACxC,UAAU,EAAE,IAAI,CAAC,gBAAgB;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE;SAC5B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC1C,uCAAY,OAAO,GAAK,MAAM,EAAG;IACnC,CAAC;IAES,WAAW,CAAC,MAAc,EAAE,OAAa;QACjD,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE;YACtC,UAAU,EAAE,IAAI,CAAC,gBAAgB;YACjC,GAAG,EAAE;gBACH,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO;aACtB;SACF,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,iBAAiB,EAAE,CAAC;IACpC,CAAC;IAEe,cAAc,CAAC,OAAY,EAAE,OAAO,GAAG,KAAK;;YAC1D,IAAI,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,WAAW,EAAE;gBACxD,OAAO,OAAO,CAAC,WAAW,CAAC;aAC5B;YAED,IAAI,OAAO,EAAE;gBACX,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;aAClE;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF","sourcesContent":["import lodash from 'lodash';\nimport { Association, BelongsTo, BelongsToMany, HasMany, HasOne, ModelCtor, Transaction } from 'sequelize';\nimport { Collection } from '../collection';\nimport Database from '../database';\nimport { RelationField } from '../fields/relation-field';\nimport FilterParser from '../filter-parser';\nimport { Model } from '../model';\nimport { OptionsParser } from '../options-parser';\nimport { CreateOptions, Filter, FindOptions } from '../repository';\nimport { transactionWrapperBuilder } from '../transaction-decorator';\nimport { updateAssociations } from '../update-associations';\nimport { UpdateGuard } from '../update-guard';\n\nexport const transaction = transactionWrapperBuilder(function () {\n return this.sourceCollection.model.sequelize.transaction();\n});\n\nexport abstract class RelationRepository {\n sourceCollection: Collection;\n association: Association;\n targetModel: ModelCtor<any>;\n targetCollection: Collection;\n associationName: string;\n associationField: RelationField;\n sourceKeyValue: string | number;\n sourceInstance: Model;\n db: Database;\n\n constructor(sourceCollection: Collection, association: string, sourceKeyValue: string | number) {\n this.db = sourceCollection.context.database;\n\n this.sourceCollection = sourceCollection;\n this.sourceKeyValue = sourceKeyValue;\n this.associationName = association;\n this.association = this.sourceCollection.model.associations[association];\n\n this.associationField = this.sourceCollection.getField(association);\n\n this.targetModel = this.association.target;\n this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);\n }\n\n targetKey() {\n return this.associationField.targetKey;\n }\n\n protected accessors() {\n return (<BelongsTo | HasOne | HasMany | BelongsToMany>this.association).accessors;\n }\n\n async create(options?: CreateOptions): Promise<any> {\n const createAccessor = this.accessors().create;\n\n const guard = UpdateGuard.fromOptions(this.targetModel, options);\n const values = options.values;\n\n const sourceModel = await this.getSourceModel();\n\n const instance = await sourceModel[createAccessor](guard.sanitize(options.values), options);\n\n await updateAssociations(instance, values, options);\n\n if (options.hooks !== false) {\n await this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, options);\n const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;\n await this.db.emitAsync(eventName, instance, options);\n }\n\n return instance;\n }\n\n async getSourceModel(transaction?: any) {\n if (!this.sourceInstance) {\n this.sourceInstance = await this.sourceCollection.model.findOne({\n where: {\n [this.associationField.sourceKey]: this.sourceKeyValue,\n },\n });\n }\n\n return this.sourceInstance;\n }\n\n protected buildQueryOptions(options: FindOptions) {\n const parser = new OptionsParser(options, {\n collection: this.targetCollection,\n targetKey: this.targetKey(),\n });\n const params = parser.toSequelizeParams();\n return { ...options, ...params };\n }\n\n protected parseFilter(filter: Filter, options?: any) {\n const parser = new FilterParser(filter, {\n collection: this.targetCollection,\n app: {\n ctx: options?.context,\n },\n });\n return parser.toSequelizeParams();\n }\n\n protected async getTransaction(options: any, autoGen = false): Promise<Transaction | null> {\n if (lodash.isPlainObject(options) && options.transaction) {\n return options.transaction;\n }\n\n if (autoGen) {\n return await this.sourceCollection.model.sequelize.transaction();\n }\n\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SingleAssociationAccessors } from 'sequelize';
|
|
2
|
+
import { Model } from '../model';
|
|
3
|
+
import { Appends, Except, Fields, Filter, TargetKey, TransactionAble, UpdateOptions } from '../repository';
|
|
4
|
+
import { RelationRepository } from './relation-repository';
|
|
5
|
+
export interface SingleRelationFindOption extends TransactionAble {
|
|
6
|
+
fields?: Fields;
|
|
7
|
+
except?: Except;
|
|
8
|
+
appends?: Appends;
|
|
9
|
+
filter?: Filter;
|
|
10
|
+
}
|
|
11
|
+
interface SetOption extends TransactionAble {
|
|
12
|
+
tk?: TargetKey;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class SingleRelationRepository extends RelationRepository {
|
|
15
|
+
remove(options?: TransactionAble): Promise<void>;
|
|
16
|
+
set(options: TargetKey | SetOption): Promise<void>;
|
|
17
|
+
find(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
18
|
+
findOne(options?: SingleRelationFindOption): Promise<Model<any>>;
|
|
19
|
+
destroy(options?: TransactionAble): Promise<Boolean>;
|
|
20
|
+
update(options: UpdateOptions): Promise<any>;
|
|
21
|
+
accessors(): SingleAssociationAccessors;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import lodash from 'lodash';
|
|
17
|
+
import { updateModelByValues } from '../update-associations';
|
|
18
|
+
import { RelationRepository, transaction } from './relation-repository';
|
|
19
|
+
export class SingleRelationRepository extends RelationRepository {
|
|
20
|
+
remove(options) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const transaction = yield this.getTransaction(options);
|
|
23
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
24
|
+
return yield sourceModel[this.accessors().set](null, {
|
|
25
|
+
transaction,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
set(options) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const transaction = yield this.getTransaction(options);
|
|
32
|
+
let handleKey = lodash.isPlainObject(options) ? options.tk : options;
|
|
33
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
34
|
+
return yield sourceModel[this.accessors().set](handleKey, {
|
|
35
|
+
transaction,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
find(options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const transaction = yield this.getTransaction(options);
|
|
42
|
+
const findOptions = this.buildQueryOptions(Object.assign({}, options));
|
|
43
|
+
const getAccessor = this.accessors().get;
|
|
44
|
+
const sourceModel = yield this.getSourceModel(transaction);
|
|
45
|
+
return yield sourceModel[getAccessor](Object.assign(Object.assign({}, findOptions), { transaction }));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
findOne(options) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return this.find(options);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
destroy(options) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const transaction = yield this.getTransaction(options);
|
|
56
|
+
const target = yield this.find({
|
|
57
|
+
transaction,
|
|
58
|
+
});
|
|
59
|
+
yield target.destroy({
|
|
60
|
+
transaction,
|
|
61
|
+
});
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
update(options) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const transaction = yield this.getTransaction(options);
|
|
68
|
+
const target = yield this.find({
|
|
69
|
+
transaction,
|
|
70
|
+
});
|
|
71
|
+
yield updateModelByValues(target, options === null || options === void 0 ? void 0 : options.values, Object.assign(Object.assign({}, lodash.omit(options, 'values')), { transaction }));
|
|
72
|
+
return target;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
accessors() {
|
|
76
|
+
return super.accessors();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
__decorate([
|
|
80
|
+
transaction()
|
|
81
|
+
], SingleRelationRepository.prototype, "remove", null);
|
|
82
|
+
__decorate([
|
|
83
|
+
transaction((args, transaction) => {
|
|
84
|
+
return {
|
|
85
|
+
tk: args[0],
|
|
86
|
+
transaction,
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
], SingleRelationRepository.prototype, "set", null);
|
|
90
|
+
__decorate([
|
|
91
|
+
transaction()
|
|
92
|
+
], SingleRelationRepository.prototype, "destroy", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
transaction()
|
|
95
|
+
], SingleRelationRepository.prototype, "update", null);
|
|
96
|
+
//# sourceMappingURL=single-relation-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-relation-repository.js","sourceRoot":"","sources":["../../src/relation-repository/single-relation-repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAaxE,MAAM,OAAgB,wBAAyB,SAAQ,kBAAkB;IAEjE,MAAM,CAAC,OAAyB;;YACpC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACvD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAC3D,OAAO,MAAM,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;gBACnD,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;KAAA;IAQK,GAAG,CAAC,OAA8B;;YACtC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAa,OAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YAElF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAE3D,OAAO,MAAM,WAAW,CAA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C,KACjC,WAAW,IACX,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;IAED,SAAS;QACP,OAAmC,KAAK,CAAC,SAAS,EAAE,CAAC;IACvD,CAAC;CACF;AA9EC;IADC,WAAW,EAAE;sDAOb;AAQD;IANC,WAAW,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE;QACjC,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;YACX,WAAW;SACZ,CAAC;IACJ,CAAC,CAAC;mDAUD;AAsBD;IADC,WAAW,EAAE;uDAab;AAGD;IADC,WAAW,EAAE;sDAcb","sourcesContent":["import lodash from 'lodash';\nimport { SingleAssociationAccessors } from 'sequelize';\nimport { Model } from '../model';\nimport { Appends, Except, Fields, Filter, TargetKey, TransactionAble, UpdateOptions } from '../repository';\nimport { updateModelByValues } from '../update-associations';\nimport { RelationRepository, transaction } from './relation-repository';\n\nexport interface SingleRelationFindOption extends TransactionAble {\n fields?: Fields;\n except?: Except;\n appends?: Appends;\n filter?: Filter;\n}\n\ninterface SetOption extends TransactionAble {\n tk?: TargetKey;\n}\n\nexport abstract class SingleRelationRepository extends RelationRepository {\n @transaction()\n async remove(options?: TransactionAble): Promise<void> {\n const transaction = await this.getTransaction(options);\n const sourceModel = await this.getSourceModel(transaction);\n return await sourceModel[this.accessors().set](null, {\n transaction,\n });\n }\n\n @transaction((args, transaction) => {\n return {\n tk: args[0],\n transaction,\n };\n })\n async set(options: TargetKey | SetOption): Promise<void> {\n const transaction = await this.getTransaction(options);\n let handleKey = lodash.isPlainObject(options) ? (<SetOption>options).tk : options;\n\n const sourceModel = await this.getSourceModel(transaction);\n\n return await sourceModel[this.accessors().set](handleKey, {\n transaction,\n });\n }\n\n async find(options?: SingleRelationFindOption): Promise<Model<any>> {\n const transaction = await this.getTransaction(options);\n const findOptions = this.buildQueryOptions({\n ...options,\n });\n\n const getAccessor = this.accessors().get;\n const sourceModel = await this.getSourceModel(transaction);\n\n return await sourceModel[getAccessor]({\n ...findOptions,\n transaction,\n });\n }\n\n async findOne(options?: SingleRelationFindOption): Promise<Model<any>> {\n return this.find(options);\n }\n\n @transaction()\n async destroy(options?: TransactionAble): Promise<Boolean> {\n const transaction = await this.getTransaction(options);\n\n const target = await this.find({\n transaction,\n });\n\n await target.destroy({\n transaction,\n });\n\n return true;\n }\n\n @transaction()\n async update(options: UpdateOptions): Promise<any> {\n const transaction = await this.getTransaction(options);\n\n const target = await this.find({\n transaction,\n });\n\n await updateModelByValues(target, options?.values, {\n ...lodash.omit(options, 'values'),\n transaction,\n });\n\n return target;\n }\n\n accessors() {\n return <SingleAssociationAccessors>super.accessors();\n }\n}\n"]}
|