@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/database.js
CHANGED
|
@@ -1,498 +1,304 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
30
|
-
function adopt(value) {
|
|
31
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
32
|
-
resolve(value);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
28
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) {
|
|
38
|
-
try {
|
|
39
|
-
step(generator.next(value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function rejected(value) {
|
|
46
|
-
try {
|
|
47
|
-
step(generator["throw"](value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function step(result) {
|
|
54
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
-
});
|
|
59
29
|
};
|
|
60
|
-
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
31
|
+
var t = {};
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
35
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
36
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
37
|
+
t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
70
40
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return mod && mod.__esModule ? mod : {
|
|
74
|
-
"default": mod
|
|
75
|
-
};
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
43
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
exports.extend = exports.Extend = void 0;
|
|
82
|
-
|
|
83
|
-
const sequelize_1 = require("sequelize");
|
|
84
|
-
|
|
85
|
-
const glob_1 = __importDefault(require("glob"));
|
|
86
|
-
|
|
87
|
-
const table_1 = __importDefault(require("./table"));
|
|
88
|
-
|
|
89
|
-
const utils_1 = require("./utils");
|
|
90
|
-
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.extendCollection = exports.defineCollection = exports.extend = exports.Database = void 0;
|
|
46
|
+
const utils_1 = require("@nocobase/utils");
|
|
91
47
|
const events_1 = require("events");
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
exports.Extend = Extend;
|
|
102
|
-
|
|
103
|
-
function extend(tableOptions, mergeOptions = {}) {
|
|
104
|
-
return new Extend(tableOptions, mergeOptions);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
exports.extend = extend;
|
|
108
|
-
|
|
48
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
49
|
+
const sequelize_1 = require("sequelize");
|
|
50
|
+
const collection_1 = require("./collection");
|
|
51
|
+
const collection_importer_1 = require("./collection-importer");
|
|
52
|
+
const FieldTypes = __importStar(require("./fields"));
|
|
53
|
+
const model_hook_1 = require("./model-hook");
|
|
54
|
+
const operators_1 = __importDefault(require("./operators"));
|
|
109
55
|
class Database extends events_1.EventEmitter {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
56
|
+
constructor(options) {
|
|
57
|
+
super();
|
|
58
|
+
this.fieldTypes = new Map();
|
|
59
|
+
this.models = new Map();
|
|
60
|
+
this.repositories = new Map();
|
|
61
|
+
this.operators = new Map();
|
|
62
|
+
this.collections = new Map();
|
|
63
|
+
this.pendingFields = new Map();
|
|
64
|
+
this.modelCollection = new Map();
|
|
65
|
+
this.delayCollectionExtend = new Map();
|
|
66
|
+
if (options instanceof sequelize_1.Sequelize) {
|
|
67
|
+
this.sequelize = options;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.sequelize = new sequelize_1.Sequelize(options);
|
|
71
|
+
this.options = options;
|
|
72
|
+
}
|
|
73
|
+
this.collections = new Map();
|
|
74
|
+
this.modelHook = new model_hook_1.ModelHook(this);
|
|
75
|
+
this.on('afterDefineCollection', (collection) => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
// after collection defined, call bind method on pending fields
|
|
78
|
+
(_a = this.pendingFields.get(collection.name)) === null || _a === void 0 ? void 0 : _a.forEach((field) => field.bind());
|
|
79
|
+
(_b = this.delayCollectionExtend.get(collection.name)) === null || _b === void 0 ? void 0 : _b.forEach((collectionExtend) => {
|
|
80
|
+
collection.updateOptions(collectionExtend.collectionOptions, collectionExtend.mergeOptions);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// register database field types
|
|
84
|
+
for (const [name, field] of Object.entries(FieldTypes)) {
|
|
85
|
+
if (['Field', 'RelationField'].includes(name)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
let key = name.replace(/Field$/g, '');
|
|
89
|
+
key = key.substring(0, 1).toLowerCase() + key.substring(1);
|
|
90
|
+
this.registerFieldTypes({
|
|
91
|
+
[key]: field,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
this.initOperators();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Add collection to database
|
|
98
|
+
* @param options
|
|
99
|
+
*/
|
|
100
|
+
collection(options) {
|
|
101
|
+
this.emit('beforeDefineCollection', options);
|
|
102
|
+
const collection = new collection_1.Collection(options, {
|
|
103
|
+
database: this,
|
|
104
|
+
});
|
|
105
|
+
this.collections.set(collection.name, collection);
|
|
106
|
+
this.modelCollection.set(collection.model, collection);
|
|
107
|
+
this.emit('afterDefineCollection', collection);
|
|
108
|
+
return collection;
|
|
158
109
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return;
|
|
110
|
+
getTablePrefix() {
|
|
111
|
+
return this.options.tablePrefix || '';
|
|
162
112
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
113
|
+
/**
|
|
114
|
+
* get exists collection by its name
|
|
115
|
+
* @param name
|
|
116
|
+
*/
|
|
117
|
+
getCollection(name) {
|
|
118
|
+
return this.collections.get(name);
|
|
168
119
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.sequelize.addHook(hookType, (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
var _a, _b, _c, _d, _e, _f;
|
|
180
|
-
|
|
181
|
-
let modelName;
|
|
182
|
-
|
|
183
|
-
switch (state) {
|
|
184
|
-
case 1:
|
|
185
|
-
modelName = (_b = (_a = args === null || args === void 0 ? void 0 : args[0]) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name;
|
|
186
|
-
break;
|
|
187
|
-
|
|
188
|
-
case 2:
|
|
189
|
-
modelName = (_d = (_c = args === null || args === void 0 ? void 0 : args[1]) === null || _c === void 0 ? void 0 : _c.model) === null || _d === void 0 ? void 0 : _d.name;
|
|
190
|
-
break;
|
|
191
|
-
|
|
192
|
-
case 3:
|
|
193
|
-
modelName = (_f = (_e = args === null || args === void 0 ? void 0 : args[0]) === null || _e === void 0 ? void 0 : _e.model) === null || _f === void 0 ? void 0 : _f.name;
|
|
194
|
-
break;
|
|
120
|
+
hasCollection(name) {
|
|
121
|
+
return this.collections.has(name);
|
|
122
|
+
}
|
|
123
|
+
removeCollection(name) {
|
|
124
|
+
const collection = this.collections.get(name);
|
|
125
|
+
this.emit('beforeRemoveCollection', collection);
|
|
126
|
+
const result = this.collections.delete(name);
|
|
127
|
+
if (result) {
|
|
128
|
+
this.emit('afterRemoveCollection', collection);
|
|
195
129
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
130
|
+
}
|
|
131
|
+
getModel(name) {
|
|
132
|
+
return this.getCollection(name).model;
|
|
133
|
+
}
|
|
134
|
+
getRepository(name, relationId) {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
if (relationId) {
|
|
137
|
+
const [collection, relation] = name.split('.');
|
|
138
|
+
return (_b = (_a = this.getRepository(collection)) === null || _a === void 0 ? void 0 : _a.relation(relation)) === null || _b === void 0 ? void 0 : _b.of(relationId);
|
|
199
139
|
}
|
|
200
|
-
|
|
201
|
-
yield this.emitAsync(hookType, ...args);
|
|
202
|
-
}));
|
|
203
|
-
this.hookTypes.delete(hookType);
|
|
140
|
+
return (_c = this.getCollection(name)) === null || _c === void 0 ? void 0 : _c.repository;
|
|
204
141
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const run = cb => {
|
|
219
|
-
switch (args.length) {
|
|
220
|
-
case 0:
|
|
221
|
-
cb = cb.call(this);
|
|
222
|
-
break;
|
|
223
|
-
|
|
224
|
-
case 1:
|
|
225
|
-
cb = cb.call(this, args[0]);
|
|
226
|
-
break;
|
|
227
|
-
|
|
228
|
-
case 2:
|
|
229
|
-
cb = cb.call(this, args[0], args[1]);
|
|
230
|
-
break;
|
|
231
|
-
|
|
232
|
-
case 3:
|
|
233
|
-
cb = cb.call(this, args[0], args[1], args[2]);
|
|
234
|
-
break;
|
|
235
|
-
|
|
236
|
-
default:
|
|
237
|
-
cb = cb.apply(this, args);
|
|
142
|
+
addPendingField(field) {
|
|
143
|
+
const associating = this.pendingFields;
|
|
144
|
+
const items = this.pendingFields.get(field.target) || [];
|
|
145
|
+
items.push(field);
|
|
146
|
+
associating.set(field.target, items);
|
|
147
|
+
}
|
|
148
|
+
removePendingField(field) {
|
|
149
|
+
const items = this.pendingFields.get(field.target) || [];
|
|
150
|
+
const index = items.indexOf(field);
|
|
151
|
+
if (index !== -1) {
|
|
152
|
+
delete items[index];
|
|
153
|
+
this.pendingFields.set(field.target, items);
|
|
238
154
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
155
|
+
}
|
|
156
|
+
registerFieldTypes(fieldTypes) {
|
|
157
|
+
for (const [type, fieldType] of Object.entries(fieldTypes)) {
|
|
158
|
+
this.fieldTypes.set(type, fieldType);
|
|
242
159
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (typeof callbacks === 'function') {
|
|
248
|
-
yield run(callbacks);
|
|
249
|
-
} else if (typeof callbacks === 'object') {
|
|
250
|
-
callbacks = callbacks.slice().filter(Boolean);
|
|
251
|
-
yield callbacks.reduce((prev, next) => {
|
|
252
|
-
return prev.then(res => {
|
|
253
|
-
return run(next).then(result => Promise.resolve(res.concat(result)));
|
|
254
|
-
});
|
|
255
|
-
}, Promise.resolve([]));
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return true;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
import(options) {
|
|
263
|
-
const _options$extensions = options.extensions,
|
|
264
|
-
extensions = _options$extensions === void 0 ? ['js', 'ts', 'json'] : _options$extensions,
|
|
265
|
-
directory = options.directory;
|
|
266
|
-
const patten = `${directory}/*.{${extensions.join(',')}}`;
|
|
267
|
-
const files = glob_1.default.sync(patten, {
|
|
268
|
-
ignore: ['**/*.d.ts']
|
|
269
|
-
});
|
|
270
|
-
const tables = new Map();
|
|
271
|
-
files.forEach(file => {
|
|
272
|
-
const result = (0, utils_1.requireModule)(file);
|
|
273
|
-
|
|
274
|
-
if (result instanceof Extend) {
|
|
275
|
-
if (!this.tables.has(result.tableOptions.name)) {
|
|
276
|
-
this.extTableOptions.set(result.tableOptions.name, result);
|
|
277
|
-
} else {
|
|
278
|
-
const table = this.extend(result.tableOptions, result.mergeOptions);
|
|
279
|
-
tables.set(table.getName(), table);
|
|
160
|
+
}
|
|
161
|
+
registerModels(models) {
|
|
162
|
+
for (const [type, schemaType] of Object.entries(models)) {
|
|
163
|
+
this.models.set(type, schemaType);
|
|
280
164
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const result = this.extTableOptions.get(table.getName());
|
|
286
|
-
table = this.extend(result.tableOptions, result.mergeOptions);
|
|
287
|
-
this.extTableOptions.delete(table.getName());
|
|
165
|
+
}
|
|
166
|
+
registerRepositories(repositories) {
|
|
167
|
+
for (const [type, schemaType] of Object.entries(repositories)) {
|
|
168
|
+
this.repositories.set(type, schemaType);
|
|
288
169
|
}
|
|
289
|
-
|
|
290
|
-
tables.set(table.getName(), table);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
return tables;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
table(options) {
|
|
297
|
-
const name = options.name;
|
|
298
|
-
const table = new table_1.default(options, {
|
|
299
|
-
database: this
|
|
300
|
-
});
|
|
301
|
-
this.tables.set(name, table);
|
|
302
|
-
|
|
303
|
-
if (this.throughTables.has(name)) {
|
|
304
|
-
const _this$getTables = this.getTables(this.throughTables.get(name)),
|
|
305
|
-
_this$getTables2 = _slicedToArray(_this$getTables, 2),
|
|
306
|
-
sourceTable = _this$getTables2[0],
|
|
307
|
-
targetTable = _this$getTables2[1];
|
|
308
|
-
|
|
309
|
-
sourceTable && sourceTable.modelInit(true);
|
|
310
|
-
targetTable && targetTable.modelInit(true);
|
|
311
170
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
} else {
|
|
324
|
-
table = this.table(options);
|
|
325
|
-
this.tables.set(name, table);
|
|
171
|
+
initOperators() {
|
|
172
|
+
const operators = new Map();
|
|
173
|
+
// Sequelize 内置
|
|
174
|
+
for (const key in sequelize_1.Op) {
|
|
175
|
+
operators.set('$' + key, sequelize_1.Op[key]);
|
|
176
|
+
const val = sequelize_1.Utils.underscoredIf(key, true);
|
|
177
|
+
operators.set('$' + val, sequelize_1.Op[key]);
|
|
178
|
+
operators.set('$' + val.replace(/_/g, ''), sequelize_1.Op[key]);
|
|
179
|
+
}
|
|
180
|
+
this.operators = operators;
|
|
181
|
+
this.registerOperators(Object.assign({}, operators_1.default));
|
|
326
182
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
isDefined(name) {
|
|
332
|
-
return this.sequelize.isDefined(name);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
getModel(name) {
|
|
336
|
-
return this.isDefined(name) ? this.sequelize.model(name) : undefined;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
getModels(names = []) {
|
|
340
|
-
if (names.length === 0) {
|
|
341
|
-
return this.sequelize.models;
|
|
183
|
+
registerOperators(operators) {
|
|
184
|
+
for (const [key, operator] of Object.entries(operators)) {
|
|
185
|
+
this.operators.set(key, operator);
|
|
186
|
+
}
|
|
342
187
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
getTables(names = []) {
|
|
352
|
-
if (names.length === 0) {
|
|
353
|
-
return [...this.tables.values()];
|
|
188
|
+
buildField(options, context) {
|
|
189
|
+
const { type } = options;
|
|
190
|
+
const Field = this.fieldTypes.get(type);
|
|
191
|
+
if (!Field) {
|
|
192
|
+
throw Error(`unsupported field type ${type}`);
|
|
193
|
+
}
|
|
194
|
+
return new Field(options, context);
|
|
354
195
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
Model.associate && Model.associate(this.sequelize.models);
|
|
368
|
-
}
|
|
369
|
-
} catch (err) {
|
|
370
|
-
_iterator.e(err);
|
|
371
|
-
} finally {
|
|
372
|
-
_iterator.f();
|
|
196
|
+
sync(options) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const isMySQL = this.sequelize.getDialect() === 'mysql';
|
|
199
|
+
if (isMySQL) {
|
|
200
|
+
yield this.sequelize.query('SET FOREIGN_KEY_CHECKS = 0', null);
|
|
201
|
+
}
|
|
202
|
+
const result = yield this.sequelize.sync(options);
|
|
203
|
+
if (isMySQL) {
|
|
204
|
+
yield this.sequelize.query('SET FOREIGN_KEY_CHECKS = 1', null);
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
});
|
|
373
208
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
sync(options = {}) {
|
|
383
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
-
const _options$tables = options.tables,
|
|
385
|
-
tables = _options$tables === void 0 ? [] : _options$tables,
|
|
386
|
-
restOptions = __rest(options, ["tables"]);
|
|
387
|
-
|
|
388
|
-
let items;
|
|
389
|
-
|
|
390
|
-
if (tables instanceof Map) {
|
|
391
|
-
items = Array.from(tables.values());
|
|
392
|
-
} else {
|
|
393
|
-
items = tables;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (items.length > 0) {
|
|
397
|
-
const sequelize = new sequelize_1.Sequelize(this.options);
|
|
398
|
-
const names = new Set();
|
|
399
|
-
|
|
400
|
-
for (const key in items) {
|
|
401
|
-
let table = items[key];
|
|
402
|
-
|
|
403
|
-
if (typeof table === 'string') {
|
|
404
|
-
table = this.getTable(table);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
if (table instanceof table_1.default) {
|
|
408
|
-
var _iterator2 = _createForOfIteratorHelper(table.getRelatedTableNames()),
|
|
409
|
-
_step2;
|
|
410
|
-
|
|
411
|
-
try {
|
|
412
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
413
|
-
const name = _step2.value;
|
|
414
|
-
names.add(name);
|
|
415
|
-
}
|
|
416
|
-
} catch (err) {
|
|
417
|
-
_iterator2.e(err);
|
|
418
|
-
} finally {
|
|
419
|
-
_iterator2.f();
|
|
209
|
+
clean(options) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const { drop } = options, others = __rest(options, ["drop"]);
|
|
212
|
+
if (drop) {
|
|
213
|
+
yield this.sequelize.getQueryInterface().dropAllTables(others);
|
|
420
214
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const model = this.getModel(name);
|
|
431
|
-
|
|
432
|
-
if (model) {
|
|
433
|
-
sequelize.modelManager.addModel(model);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
isSqliteMemory() {
|
|
218
|
+
return this.sequelize.getDialect() === 'sqlite' && lodash_1.default.get(this.options, 'storage') == ':memory:';
|
|
219
|
+
}
|
|
220
|
+
reconnect() {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
if (this.isSqliteMemory()) {
|
|
223
|
+
return;
|
|
434
224
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
runHooks(hookType, ...args) {
|
|
464
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
465
|
-
const hooks = this.hooks[hookType] || [];
|
|
466
|
-
|
|
467
|
-
var _iterator4 = _createForOfIteratorHelper(hooks),
|
|
468
|
-
_step4;
|
|
469
|
-
|
|
470
|
-
try {
|
|
471
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
472
|
-
const hook = _step4.value;
|
|
473
|
-
|
|
474
|
-
if (typeof hook === 'function') {
|
|
475
|
-
yield hook(...args);
|
|
476
|
-
}
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
const ConnectionManager = this.sequelize.dialect.connectionManager.constructor;
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
const connectionManager = new ConnectionManager(this.sequelize.dialect, this.sequelize);
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
this.sequelize.dialect.connectionManager = connectionManager;
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
this.sequelize.connectionManager = connectionManager;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
closed() {
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
return this.sequelize.connectionManager.pool._draining;
|
|
238
|
+
}
|
|
239
|
+
close() {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
if (this.isSqliteMemory()) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
return this.sequelize.close();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
on(event, listener) {
|
|
248
|
+
const modelEventName = this.modelHook.isModelHook(event);
|
|
249
|
+
if (modelEventName && !this.modelHook.hasBindEvent(modelEventName)) {
|
|
250
|
+
this.sequelize.addHook(modelEventName, this.modelHook.sequelizeHookBuilder(modelEventName));
|
|
251
|
+
this.modelHook.bindEvent(modelEventName);
|
|
477
252
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
253
|
+
return super.on(event, listener);
|
|
254
|
+
}
|
|
255
|
+
import(options) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const reader = new collection_importer_1.ImporterReader(options.directory, options.extensions);
|
|
258
|
+
const modules = yield reader.read();
|
|
259
|
+
const result = new Map();
|
|
260
|
+
for (const module of modules) {
|
|
261
|
+
if (module.extend) {
|
|
262
|
+
const collectionName = module.collectionOptions.name;
|
|
263
|
+
const existCollection = this.getCollection(collectionName);
|
|
264
|
+
if (existCollection) {
|
|
265
|
+
existCollection.updateOptions(module.collectionOptions, module.mergeOptions);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const existDelayExtends = this.delayCollectionExtend.get(collectionName) || [];
|
|
269
|
+
this.delayCollectionExtend.set(collectionName, [...existDelayExtends, module]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
const collection = this.collection(module);
|
|
274
|
+
result.set(collection.name, collection);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.Database = Database;
|
|
282
|
+
function extend(collectionOptions, mergeOptions) {
|
|
283
|
+
return {
|
|
284
|
+
collectionOptions,
|
|
285
|
+
mergeOptions,
|
|
286
|
+
extend: true,
|
|
287
|
+
};
|
|
495
288
|
}
|
|
496
|
-
|
|
289
|
+
exports.extend = extend;
|
|
290
|
+
const defineCollection = (collectionOptions) => {
|
|
291
|
+
return collectionOptions;
|
|
292
|
+
};
|
|
293
|
+
exports.defineCollection = defineCollection;
|
|
294
|
+
const extendCollection = (collectionOptions, mergeOptions) => {
|
|
295
|
+
return {
|
|
296
|
+
collectionOptions,
|
|
297
|
+
mergeOptions,
|
|
298
|
+
extend: true,
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
exports.extendCollection = extendCollection;
|
|
302
|
+
(0, utils_1.applyMixins)(Database, [utils_1.AsyncEmitter]);
|
|
497
303
|
exports.default = Database;
|
|
498
|
-
//# sourceMappingURL=database.js.map
|
|
304
|
+
//# sourceMappingURL=database.js.map
|