@nocobase/database 0.5.0-alpha.38 → 0.7.0-alpha.0
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 +47 -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
package/lib/model.d.ts
CHANGED
|
@@ -1,49 +1,15 @@
|
|
|
1
|
-
import { Model as SequelizeModel
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
only?: string[];
|
|
6
|
-
appends?: string[];
|
|
7
|
-
} | {
|
|
8
|
-
except?: string[];
|
|
9
|
-
appends?: string[];
|
|
10
|
-
};
|
|
11
|
-
filter?: any;
|
|
12
|
-
sort?: any;
|
|
13
|
-
page?: number;
|
|
14
|
-
perPage?: number;
|
|
15
|
-
context?: any;
|
|
1
|
+
import { Model as SequelizeModel } from 'sequelize';
|
|
2
|
+
import { Collection } from './collection';
|
|
3
|
+
import { Database } from './database';
|
|
4
|
+
interface IModel {
|
|
16
5
|
[key: string]: any;
|
|
17
6
|
}
|
|
18
|
-
export
|
|
19
|
-
association: string;
|
|
20
|
-
sourceAlias?: string;
|
|
21
|
-
where?: any;
|
|
22
|
-
alias?: string;
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
}
|
|
25
|
-
export declare const DEFAULT_OFFSET = 0;
|
|
26
|
-
export declare const DEFAULT_LIMIT = 100;
|
|
27
|
-
export declare const MAX_LIMIT = 500;
|
|
28
|
-
export interface UpdateAssociationOptions extends SaveOptions {
|
|
29
|
-
context?: any;
|
|
30
|
-
}
|
|
31
|
-
export declare abstract class Model extends SequelizeModel {
|
|
32
|
-
[key: string]: any;
|
|
7
|
+
export declare class Model<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> extends SequelizeModel<TModelAttributes, TCreationAttributes> implements IModel {
|
|
33
8
|
static database: Database;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
updateSingleAssociation(key: string, data: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
40
|
-
updateMultipleAssociation(associationName: string, data: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
41
|
-
updateAssociation(key: string, data: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
42
|
-
updateAssociations(data: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
9
|
+
static collection: Collection;
|
|
10
|
+
toJSON<T extends TModelAttributes>(): T;
|
|
11
|
+
private hiddenObjKey;
|
|
12
|
+
private sortAssociations;
|
|
13
|
+
private sortArray;
|
|
43
14
|
}
|
|
44
|
-
export
|
|
45
|
-
new (): M;
|
|
46
|
-
} & {
|
|
47
|
-
[key: string]: any;
|
|
48
|
-
};
|
|
49
|
-
export default Model;
|
|
15
|
+
export {};
|
package/lib/model.js
CHANGED
|
@@ -1,463 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
-
|
|
17
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
-
|
|
19
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
20
|
-
|
|
21
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) {
|
|
23
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
24
|
-
resolve(value);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
-
function fulfilled(value) {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.next(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function rejected(value) {
|
|
38
|
-
try {
|
|
39
|
-
step(generator["throw"](value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function step(result) {
|
|
46
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
54
|
-
var t = {};
|
|
55
|
-
|
|
56
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
57
|
-
|
|
58
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
60
|
-
}
|
|
61
|
-
return t;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
4
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value: true
|
|
66
|
-
});
|
|
67
|
-
exports.Model = exports.MAX_LIMIT = exports.DEFAULT_LIMIT = exports.DEFAULT_OFFSET = void 0;
|
|
68
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Model = void 0;
|
|
69
7
|
const sequelize_1 = require("sequelize");
|
|
70
|
-
|
|
71
|
-
const fields_1 = require("./fields");
|
|
72
|
-
|
|
73
|
-
const utils_1 = require("./utils");
|
|
74
|
-
|
|
75
|
-
exports.DEFAULT_OFFSET = 0;
|
|
76
|
-
exports.DEFAULT_LIMIT = 100;
|
|
77
|
-
exports.MAX_LIMIT = 500;
|
|
78
|
-
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
79
9
|
class Model extends sequelize_1.Model {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
10
|
+
toJSON() {
|
|
11
|
+
const handleObj = (obj, options) => {
|
|
12
|
+
const handles = [
|
|
13
|
+
(data) => {
|
|
14
|
+
if (data instanceof Model) {
|
|
15
|
+
return data.toJSON();
|
|
16
|
+
}
|
|
17
|
+
return data;
|
|
18
|
+
},
|
|
19
|
+
this.hiddenObjKey,
|
|
20
|
+
];
|
|
21
|
+
return handles.reduce((carry, fn) => fn.apply(this, [carry, options]), obj);
|
|
22
|
+
};
|
|
23
|
+
const handleArray = (arrayOfObj, options) => {
|
|
24
|
+
const handles = [this.sortAssociations];
|
|
25
|
+
return handles.reduce((carry, fn) => fn.apply(this, [carry, options]), arrayOfObj || []);
|
|
26
|
+
};
|
|
27
|
+
const opts = {
|
|
28
|
+
model: this.constructor,
|
|
29
|
+
collection: this.constructor.collection,
|
|
30
|
+
db: this.constructor.database,
|
|
31
|
+
};
|
|
32
|
+
const traverseJSON = (data, options) => {
|
|
33
|
+
const { model, db, collection } = options;
|
|
34
|
+
// handle Object
|
|
35
|
+
data = handleObj(data, options);
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const key of Object.keys(data)) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
if (model.hasAlias(key)) {
|
|
40
|
+
const association = model.associations[key];
|
|
41
|
+
const opts = {
|
|
42
|
+
model: association.target,
|
|
43
|
+
collection: db.getCollection(association.target.name),
|
|
44
|
+
db,
|
|
45
|
+
key,
|
|
46
|
+
field: collection.getField(key),
|
|
47
|
+
};
|
|
48
|
+
if (['HasMany', 'BelongsToMany'].includes(association.associationType)) {
|
|
49
|
+
result[key] = handleArray(data[key], opts).map((item) => traverseJSON(item, opts));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
result[key] = data[key] ? traverseJSON(data[key], opts) : null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result[key] = data[key];
|
|
57
|
+
}
|
|
119
58
|
}
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let countLiteral = 'count(*)';
|
|
126
|
-
|
|
127
|
-
if (this.database.sequelize.getDialect() === 'postgres') {
|
|
128
|
-
countLiteral = 'cast(count(*) as integer)';
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
return traverseJSON(super.toJSON(), opts);
|
|
129
62
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return attribute;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
static selectQuery(options = {}) {
|
|
139
|
-
return this.queryGenerator.selectQuery(this.getTableName(), options, this).replace(/;$/, '');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
static parseApiJson(options) {
|
|
143
|
-
const fields = options.fields,
|
|
144
|
-
filter = options.filter,
|
|
145
|
-
sort = options.sort,
|
|
146
|
-
context = options.context,
|
|
147
|
-
page = options.page,
|
|
148
|
-
perPage = options.perPage;
|
|
149
|
-
const data = (0, utils_1.toInclude)({
|
|
150
|
-
fields,
|
|
151
|
-
filter,
|
|
152
|
-
sort
|
|
153
|
-
}, {
|
|
154
|
-
model: this,
|
|
155
|
-
associations: this.associations,
|
|
156
|
-
dialect: this.sequelize.getDialect(),
|
|
157
|
-
ctx: context,
|
|
158
|
-
database: this.database
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (page || perPage) {
|
|
162
|
-
data.limit = perPage === -1 ? exports.MAX_LIMIT : Math.min(perPage || exports.DEFAULT_LIMIT, exports.MAX_LIMIT);
|
|
163
|
-
data.offset = data.limit * (page > 0 ? page - 1 : exports.DEFAULT_OFFSET);
|
|
63
|
+
hiddenObjKey(obj, options) {
|
|
64
|
+
const hiddenFields = Array.from(options.collection.fields.values())
|
|
65
|
+
.filter((field) => field.options.hidden)
|
|
66
|
+
.map((field) => field.options.name);
|
|
67
|
+
return lodash_1.default.omit(obj, hiddenFields);
|
|
164
68
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
69
|
+
sortAssociations(data, { field }) {
|
|
70
|
+
const sortBy = field.options.sortBy;
|
|
71
|
+
return sortBy ? this.sortArray(data, sortBy) : data;
|
|
168
72
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
getValuesByFieldNames(scope = []) {
|
|
174
|
-
const table = this.database.getTable(this.constructor.name);
|
|
175
|
-
const Model = table.getModel();
|
|
176
|
-
const associations = table.getAssociations();
|
|
177
|
-
const where = {};
|
|
178
|
-
scope.forEach(col => {
|
|
179
|
-
const association = associations.get(col);
|
|
180
|
-
const dataKey = association && association instanceof fields_1.BELONGSTO ? association.options.foreignKey : col;
|
|
181
|
-
|
|
182
|
-
if (!Model.rawAttributes[dataKey]) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const value = this.getDataValue(dataKey);
|
|
187
|
-
|
|
188
|
-
if (typeof value !== 'undefined') {
|
|
189
|
-
where[dataKey] = value;
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
return where;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
updateSingleAssociation(key, data, options = {}) {
|
|
196
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
const fields = options.fields,
|
|
198
|
-
_options$transaction = options.transaction,
|
|
199
|
-
transaction = _options$transaction === void 0 ? yield this.sequelize.transaction() : _options$transaction,
|
|
200
|
-
opts = __rest(options, ["fields", "transaction"]);
|
|
201
|
-
|
|
202
|
-
Object.assign(opts, {
|
|
203
|
-
transaction
|
|
204
|
-
});
|
|
205
|
-
const table = this.database.getTable(this.constructor.name);
|
|
206
|
-
const association = table.getAssociations().get(key);
|
|
207
|
-
const accessors = association.getAccessors();
|
|
208
|
-
|
|
209
|
-
if (data == null) {
|
|
210
|
-
yield this[accessors.set](null, opts);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (typeof data === 'number' || typeof data === 'string' || data instanceof sequelize_1.Model) {
|
|
215
|
-
yield this[accessors.set](data, opts);
|
|
216
|
-
} else if (typeof data === 'object') {
|
|
217
|
-
const Target = association.getTargetModel();
|
|
218
|
-
const targetAttribute = association instanceof fields_1.BELONGSTO ? association.options.targetKey : association.options.sourceKey;
|
|
219
|
-
|
|
220
|
-
if (data[targetAttribute]) {
|
|
221
|
-
if (Object.keys(data).length > 0) {
|
|
222
|
-
const target = yield Target.findOne({
|
|
223
|
-
where: {
|
|
224
|
-
[targetAttribute]: data[targetAttribute]
|
|
225
|
-
},
|
|
226
|
-
transaction
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
if (target) {
|
|
230
|
-
yield this[accessors.set](data[targetAttribute], opts);
|
|
231
|
-
yield target.update(data, opts);
|
|
232
|
-
yield target.updateAssociations(data, opts);
|
|
233
|
-
} else {
|
|
234
|
-
const t = yield this[accessors.create](data, opts);
|
|
235
|
-
yield t.updateAssociations(data, opts);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
const t = yield this[accessors.create](data, opts);
|
|
240
|
-
yield t.updateAssociations(data, opts);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (!options.transaction) {
|
|
245
|
-
yield transaction.commit();
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
updateMultipleAssociation(associationName, data, options = {}) {
|
|
251
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
-
const items = Array.isArray(data) ? data : data == null ? [] : [data];
|
|
253
|
-
|
|
254
|
-
const fields = options.fields,
|
|
255
|
-
_options$transaction2 = options.transaction,
|
|
256
|
-
transaction = _options$transaction2 === void 0 ? yield this.sequelize.transaction() : _options$transaction2,
|
|
257
|
-
opts = __rest(options, ["fields", "transaction"]);
|
|
258
|
-
|
|
259
|
-
Object.assign(opts, {
|
|
260
|
-
transaction
|
|
261
|
-
});
|
|
262
|
-
const table = this.database.getTable(this.constructor.name);
|
|
263
|
-
const association = table.getAssociations().get(associationName);
|
|
264
|
-
const accessors = association.getAccessors();
|
|
265
|
-
|
|
266
|
-
if (!items.length) {
|
|
267
|
-
yield this[accessors.set](null, opts);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const Target = association.getTargetModel();
|
|
272
|
-
const _association$options$ = association.options.targetKey,
|
|
273
|
-
targetKey = _association$options$ === void 0 ? Target.primaryKeyAttribute : _association$options$;
|
|
274
|
-
const targetPk = Target.primaryKeyAttribute;
|
|
275
|
-
const targetKeyIsPk = targetKey === targetPk;
|
|
276
|
-
const toSetPks = new Set();
|
|
277
|
-
const toSetUks = new Set();
|
|
278
|
-
const toSetItems = new Set();
|
|
279
|
-
const toUpsertObjects = [];
|
|
280
|
-
items.forEach(item => {
|
|
281
|
-
if (item instanceof sequelize_1.Model) {
|
|
282
|
-
if (targetKeyIsPk) {
|
|
283
|
-
toSetPks.add(item.getDataValue(targetPk));
|
|
284
|
-
} else {
|
|
285
|
-
toSetUks.add(item.getDataValue(targetKey));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return;
|
|
73
|
+
sortArray(data, sortBy) {
|
|
74
|
+
if (!lodash_1.default.isArray(sortBy)) {
|
|
75
|
+
sortBy = [sortBy];
|
|
289
76
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (typeof item !== targetKeyType) {
|
|
299
|
-
throw new Error(`target key type [${typeof item}] does not match to [${targetKeyType}]`);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (targetKeyIsPk) {
|
|
303
|
-
toSetPks.add(item);
|
|
304
|
-
} else {
|
|
305
|
-
toSetUks.add(item);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (typeof item === 'object') {
|
|
312
|
-
toUpsertObjects.push(item);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
const byPkExistItems = toSetPks.size ? yield Target.findAll(Object.assign(Object.assign({}, opts), {
|
|
316
|
-
where: {
|
|
317
|
-
[targetPk]: {
|
|
318
|
-
[sequelize_1.Op.in]: Array.from(toSetPks)
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
attributes: [targetPk]
|
|
322
|
-
})) : [];
|
|
323
|
-
byPkExistItems.forEach(item => {
|
|
324
|
-
toSetItems.add(item);
|
|
325
|
-
});
|
|
326
|
-
const byUkExistItems = toSetUks.size ? yield Target.findAll(Object.assign(Object.assign({}, opts), {
|
|
327
|
-
where: {
|
|
328
|
-
[targetKey]: {
|
|
329
|
-
[sequelize_1.Op.in]: Array.from(toSetUks)
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
attributes: [targetPk, targetKey]
|
|
333
|
-
})) : [];
|
|
334
|
-
byUkExistItems.forEach(item => {
|
|
335
|
-
toSetItems.add(item);
|
|
336
|
-
});
|
|
337
|
-
const belongsToManyList = [];
|
|
338
|
-
|
|
339
|
-
for (var _i = 0, _toUpsertObjects = toUpsertObjects; _i < _toUpsertObjects.length; _i++) {
|
|
340
|
-
const item = _toUpsertObjects[_i];
|
|
341
|
-
let target;
|
|
342
|
-
|
|
343
|
-
if (typeof item[targetKey] === 'undefined') {
|
|
344
|
-
target = yield this[accessors.create](item, opts);
|
|
345
|
-
} else {
|
|
346
|
-
target = yield Target.findOne(Object.assign(Object.assign({}, opts), {
|
|
347
|
-
where: {
|
|
348
|
-
[targetKey]: item[targetKey]
|
|
349
|
-
}
|
|
350
|
-
}));
|
|
351
|
-
|
|
352
|
-
if (!target) {
|
|
353
|
-
target = yield this[accessors.create](item, opts);
|
|
354
|
-
} else {
|
|
355
|
-
yield target.update(item, opts);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
toSetItems.add(target);
|
|
360
|
-
|
|
361
|
-
if (association instanceof fields_1.BELONGSTOMANY) {
|
|
362
|
-
belongsToManyList.push({
|
|
363
|
-
item,
|
|
364
|
-
target
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
yield target.updateAssociations(item, opts);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
yield this[accessors.set](Array.from(toSetItems), opts);
|
|
372
|
-
|
|
373
|
-
if (belongsToManyList.length) {
|
|
374
|
-
const ThroughModel = association.getThroughModel();
|
|
375
|
-
const throughName = association.getThroughName();
|
|
376
|
-
|
|
377
|
-
var _iterator = _createForOfIteratorHelper(belongsToManyList),
|
|
378
|
-
_step;
|
|
379
|
-
|
|
380
|
-
try {
|
|
381
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
382
|
-
const _step$value = _step.value,
|
|
383
|
-
item = _step$value.item,
|
|
384
|
-
target = _step$value.target;
|
|
385
|
-
const throughValues = item[throughName];
|
|
386
|
-
|
|
387
|
-
if (throughValues && typeof throughValues === 'object') {
|
|
388
|
-
const _association$options = association.options,
|
|
389
|
-
foreignKey = _association$options.foreignKey,
|
|
390
|
-
sourceKey = _association$options.sourceKey,
|
|
391
|
-
otherKey = _association$options.otherKey;
|
|
392
|
-
const through = yield ThroughModel.findOne({
|
|
393
|
-
where: {
|
|
394
|
-
[foreignKey]: this.get(sourceKey),
|
|
395
|
-
[otherKey]: target.get(targetKey)
|
|
396
|
-
},
|
|
397
|
-
transaction
|
|
398
|
-
});
|
|
399
|
-
yield through.update(throughValues, opts);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
} catch (err) {
|
|
403
|
-
_iterator.e(err);
|
|
404
|
-
} finally {
|
|
405
|
-
_iterator.f();
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (!options.transaction) {
|
|
410
|
-
yield transaction.commit();
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
updateAssociation(key, data, options = {}) {
|
|
416
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
417
|
-
const table = this.database.getTable(this.constructor.name);
|
|
418
|
-
const association = table.getAssociations().get(key);
|
|
419
|
-
|
|
420
|
-
switch (true) {
|
|
421
|
-
case association instanceof fields_1.BELONGSTO:
|
|
422
|
-
case association instanceof fields_1.HASONE:
|
|
423
|
-
return this.updateSingleAssociation(key, data, options);
|
|
424
|
-
|
|
425
|
-
case association instanceof fields_1.HASMANY:
|
|
426
|
-
case association instanceof fields_1.BELONGSTOMANY:
|
|
427
|
-
return this.updateMultipleAssociation(key, data, options);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
updateAssociations(data, options = {}) {
|
|
433
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
434
|
-
const _options$transaction3 = options.transaction,
|
|
435
|
-
transaction = _options$transaction3 === void 0 ? yield this.sequelize.transaction() : _options$transaction3;
|
|
436
|
-
|
|
437
|
-
for (var _i2 = 0, _Object$keys = Object.keys(this.constructor.associations); _i2 < _Object$keys.length; _i2++) {
|
|
438
|
-
const key = _Object$keys[_i2];
|
|
439
|
-
|
|
440
|
-
if (!Object.keys(data).includes(key)) {
|
|
441
|
-
continue;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
yield this.updateAssociation(key, data[key], Object.assign(Object.assign({}, options), {
|
|
445
|
-
transaction
|
|
446
|
-
}));
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
yield this.database.emitAsync('afterUpdateAssociations', this, Object.assign(Object.assign({}, options), {
|
|
450
|
-
transaction
|
|
451
|
-
}));
|
|
452
|
-
|
|
453
|
-
if (!options.transaction) {
|
|
454
|
-
yield transaction.commit();
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
|
|
77
|
+
const orderItems = [];
|
|
78
|
+
const orderDirections = [];
|
|
79
|
+
sortBy.forEach((sortItem) => {
|
|
80
|
+
orderDirections.push(sortItem.startsWith('-') ? 'desc' : 'asc');
|
|
81
|
+
orderItems.push(sortItem.replace('-', ''));
|
|
82
|
+
});
|
|
83
|
+
return lodash_1.default.orderBy(data, orderItems, orderDirections);
|
|
84
|
+
}
|
|
459
85
|
}
|
|
460
|
-
|
|
461
86
|
exports.Model = Model;
|
|
462
|
-
|
|
463
|
-
//# sourceMappingURL=model.js.map
|
|
87
|
+
//# sourceMappingURL=model.js.map
|