@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,75 @@
|
|
|
1
|
+
"use strict";
|
|
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());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.ImporterReader = void 0;
|
|
35
|
+
const fs = __importStar(require("fs"));
|
|
36
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
37
|
+
const path_1 = __importDefault(require("path"));
|
|
38
|
+
function requireModule(module) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (typeof module === 'string') {
|
|
41
|
+
module = require(module);
|
|
42
|
+
}
|
|
43
|
+
if (typeof module !== 'object') {
|
|
44
|
+
return module;
|
|
45
|
+
}
|
|
46
|
+
return module.__esModule ? module.default : module;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
class ImporterReader {
|
|
50
|
+
constructor(directory, extensions) {
|
|
51
|
+
this.directory = directory;
|
|
52
|
+
if (!extensions) {
|
|
53
|
+
extensions = ['js', 'ts', 'json'];
|
|
54
|
+
}
|
|
55
|
+
this.extensions = new Set(extensions);
|
|
56
|
+
}
|
|
57
|
+
read() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const modules = (yield fs.promises.readdir(this.directory, {
|
|
60
|
+
encoding: 'utf-8',
|
|
61
|
+
}))
|
|
62
|
+
.filter((fileName) => {
|
|
63
|
+
if (fileName.endsWith('.d.ts')) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const ext = path_1.default.parse(fileName).ext.replace('.', '');
|
|
67
|
+
return this.extensions.has(ext);
|
|
68
|
+
})
|
|
69
|
+
.map((fileName) => __awaiter(this, void 0, void 0, function* () { return yield requireModule(path_1.default.join(this.directory, fileName)); }));
|
|
70
|
+
return (yield Promise.all(modules)).filter((module) => lodash_1.default.isPlainObject(module));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ImporterReader = ImporterReader;
|
|
75
|
+
//# sourceMappingURL=collection-importer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-importer.js","sourceRoot":"","sources":["../src/collection-importer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,oDAA4B;AAC5B,gDAAwB;AAIxB,SAAe,aAAa,CAAC,MAAW;;QACtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC1B;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO,MAAM,CAAC;SACf;QACD,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACrD,CAAC;CAAA;AAED,MAAa,cAAc;IAIzB,YAAY,SAAiB,EAAE,UAAkC;QAC/D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,CAAC,UAAU,EAAE;YACf,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SACnC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAEK,IAAI;;YACR,MAAM,OAAO,GAAG,CACd,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE;gBACxC,QAAQ,EAAE,OAAO;aAClB,CAAC,CACH;iBACE,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACnB,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;oBAC9B,OAAO,KAAK,CAAC;iBACd;gBACD,MAAM,GAAG,GAAG,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBACtD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC,CAAC;iBACD,GAAG,CAAC,CAAO,QAAQ,EAAE,EAAE,gDAAC,OAAA,MAAM,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA,GAAA,CAAC,CAAC;YAErF,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CACF;AA/BD,wCA+BC","sourcesContent":["import * as fs from 'fs';\nimport lodash from 'lodash';\nimport path from 'path';\n\nexport type ImportFileExtension = 'js' | 'ts' | 'json';\n\nasync function requireModule(module: any) {\n if (typeof module === 'string') {\n module = require(module);\n }\n\n if (typeof module !== 'object') {\n return module;\n }\n return module.__esModule ? module.default : module;\n}\n\nexport class ImporterReader {\n directory: string;\n extensions: Set<string>;\n\n constructor(directory: string, extensions?: ImportFileExtension[]) {\n this.directory = directory;\n\n if (!extensions) {\n extensions = ['js', 'ts', 'json'];\n }\n\n this.extensions = new Set(extensions);\n }\n\n async read() {\n const modules = (\n await fs.promises.readdir(this.directory, {\n encoding: 'utf-8',\n })\n )\n .filter((fileName) => {\n if (fileName.endsWith('.d.ts')) {\n return false;\n }\n const ext = path.parse(fileName).ext.replace('.', '');\n return this.extensions.has(ext);\n })\n .map(async (fileName) => await requireModule(path.join(this.directory, fileName)));\n\n return (await Promise.all(modules)).filter((module) => lodash.isPlainObject(module));\n }\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ModelCtor, ModelOptions, SyncOptions } from 'sequelize';
|
|
4
|
+
import { Database } from './database';
|
|
5
|
+
import { Field, FieldOptions } from './fields';
|
|
6
|
+
import { Model } from './model';
|
|
7
|
+
import { Repository } from './repository';
|
|
8
|
+
export declare type RepositoryType = typeof Repository;
|
|
9
|
+
export declare type CollectionSortable = string | boolean | {
|
|
10
|
+
name?: string;
|
|
11
|
+
scopeKey?: string;
|
|
12
|
+
};
|
|
13
|
+
export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {
|
|
14
|
+
name: string;
|
|
15
|
+
tableName?: string;
|
|
16
|
+
filterTargetKey?: string;
|
|
17
|
+
fields?: FieldOptions[];
|
|
18
|
+
model?: string | ModelCtor<Model>;
|
|
19
|
+
repository?: string | RepositoryType;
|
|
20
|
+
sortable?: CollectionSortable;
|
|
21
|
+
/**
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
autoGenId?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @default 'options'
|
|
27
|
+
*/
|
|
28
|
+
magicAttribute?: string;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export interface CollectionContext {
|
|
32
|
+
database: Database;
|
|
33
|
+
}
|
|
34
|
+
export declare class Collection<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> extends EventEmitter {
|
|
35
|
+
options: CollectionOptions;
|
|
36
|
+
context: CollectionContext;
|
|
37
|
+
isThrough?: boolean;
|
|
38
|
+
fields: Map<string, any>;
|
|
39
|
+
model: ModelCtor<Model>;
|
|
40
|
+
repository: Repository<TModelAttributes, TCreationAttributes>;
|
|
41
|
+
get filterTargetKey(): string;
|
|
42
|
+
get name(): string;
|
|
43
|
+
constructor(options: CollectionOptions, context?: CollectionContext);
|
|
44
|
+
private sequelizeModelOptions;
|
|
45
|
+
/**
|
|
46
|
+
* TODO
|
|
47
|
+
*/
|
|
48
|
+
modelInit(): void;
|
|
49
|
+
setRepository(repository?: RepositoryType | string): void;
|
|
50
|
+
private bindFieldEventListener;
|
|
51
|
+
forEachField(callback: (field: Field) => void): void;
|
|
52
|
+
findField(callback: (field: Field) => boolean): any;
|
|
53
|
+
hasField(name: string): boolean;
|
|
54
|
+
getField<F extends Field>(name: string): F;
|
|
55
|
+
addField(name: string, options: FieldOptions): Field;
|
|
56
|
+
setField(name: string, options: FieldOptions): Field;
|
|
57
|
+
setFields(fields: FieldOptions[], resetFields?: boolean): void;
|
|
58
|
+
resetFields(): void;
|
|
59
|
+
removeField(name: any): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* TODO
|
|
62
|
+
*/
|
|
63
|
+
updateOptions(options: CollectionOptions, mergeOptions?: any): this;
|
|
64
|
+
setSortable(sortable: any): void;
|
|
65
|
+
/**
|
|
66
|
+
* TODO
|
|
67
|
+
*
|
|
68
|
+
* @param name
|
|
69
|
+
* @param options
|
|
70
|
+
*/
|
|
71
|
+
updateField(name: string, options: FieldOptions): void;
|
|
72
|
+
sync(syncOptions?: SyncOptions): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Collection = void 0;
|
|
27
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
28
|
+
const events_1 = require("events");
|
|
29
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
30
|
+
const model_1 = require("./model");
|
|
31
|
+
const repository_1 = require("./repository");
|
|
32
|
+
class Collection extends events_1.EventEmitter {
|
|
33
|
+
constructor(options, context) {
|
|
34
|
+
super();
|
|
35
|
+
this.fields = new Map();
|
|
36
|
+
this.context = context;
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.bindFieldEventListener();
|
|
39
|
+
this.modelInit();
|
|
40
|
+
this.setFields(options.fields);
|
|
41
|
+
this.setRepository(options.repository);
|
|
42
|
+
this.setSortable(options.sortable);
|
|
43
|
+
}
|
|
44
|
+
get filterTargetKey() {
|
|
45
|
+
return lodash_1.default.get(this.options, 'filterTargetKey', this.model.primaryKeyAttribute);
|
|
46
|
+
}
|
|
47
|
+
get name() {
|
|
48
|
+
return this.options.name;
|
|
49
|
+
}
|
|
50
|
+
sequelizeModelOptions() {
|
|
51
|
+
const { name, tableName } = this.options;
|
|
52
|
+
return Object.assign(Object.assign({}, lodash_1.default.omit(this.options, ['name', 'fields', 'model', 'targetKey'])), { modelName: name, sequelize: this.context.database.sequelize, tableName: tableName || name });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* TODO
|
|
56
|
+
*/
|
|
57
|
+
modelInit() {
|
|
58
|
+
if (this.model) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const { name, model, autoGenId = true } = this.options;
|
|
62
|
+
let M = model_1.Model;
|
|
63
|
+
if (this.context.database.sequelize.isDefined(name)) {
|
|
64
|
+
const m = this.context.database.sequelize.model(name);
|
|
65
|
+
if (m.isThrough) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
this.model = m;
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
this.model.database = this.context.database;
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
this.model.collection = this;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (typeof model === 'string') {
|
|
76
|
+
M = this.context.database.models.get(model) || model_1.Model;
|
|
77
|
+
}
|
|
78
|
+
else if (model) {
|
|
79
|
+
M = model;
|
|
80
|
+
}
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
this.model = class extends M {
|
|
83
|
+
};
|
|
84
|
+
this.model.init(null, this.sequelizeModelOptions());
|
|
85
|
+
if (!autoGenId) {
|
|
86
|
+
this.model.removeAttribute('id');
|
|
87
|
+
}
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
this.model.database = this.context.database;
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
this.model.collection = this;
|
|
92
|
+
}
|
|
93
|
+
setRepository(repository) {
|
|
94
|
+
let repo = repository_1.Repository;
|
|
95
|
+
if (typeof repository === 'string') {
|
|
96
|
+
repo = this.context.database.repositories.get(repository) || repository_1.Repository;
|
|
97
|
+
}
|
|
98
|
+
this.repository = new repo(this);
|
|
99
|
+
}
|
|
100
|
+
bindFieldEventListener() {
|
|
101
|
+
this.on('field.afterAdd', (field) => {
|
|
102
|
+
field.bind();
|
|
103
|
+
});
|
|
104
|
+
this.on('field.afterRemove', (field) => field.unbind());
|
|
105
|
+
}
|
|
106
|
+
forEachField(callback) {
|
|
107
|
+
return [...this.fields.values()].forEach(callback);
|
|
108
|
+
}
|
|
109
|
+
findField(callback) {
|
|
110
|
+
return [...this.fields.values()].find(callback);
|
|
111
|
+
}
|
|
112
|
+
hasField(name) {
|
|
113
|
+
return this.fields.has(name);
|
|
114
|
+
}
|
|
115
|
+
getField(name) {
|
|
116
|
+
return this.fields.get(name);
|
|
117
|
+
}
|
|
118
|
+
addField(name, options) {
|
|
119
|
+
return this.setField(name, options);
|
|
120
|
+
}
|
|
121
|
+
setField(name, options) {
|
|
122
|
+
const { database } = this.context;
|
|
123
|
+
const field = database.buildField(Object.assign({ name }, options), Object.assign(Object.assign({}, this.context), { collection: this }));
|
|
124
|
+
this.removeField(name);
|
|
125
|
+
this.fields.set(name, field);
|
|
126
|
+
this.emit('field.afterAdd', field);
|
|
127
|
+
return field;
|
|
128
|
+
}
|
|
129
|
+
setFields(fields, resetFields = true) {
|
|
130
|
+
if (!Array.isArray(fields)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (resetFields) {
|
|
134
|
+
this.resetFields();
|
|
135
|
+
}
|
|
136
|
+
for (let _a of fields) {
|
|
137
|
+
const { name } = _a, options = __rest(_a, ["name"]);
|
|
138
|
+
this.addField(name, options);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
resetFields() {
|
|
142
|
+
const fieldNames = this.fields.keys();
|
|
143
|
+
for (const fieldName of fieldNames) {
|
|
144
|
+
this.removeField(fieldName);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
removeField(name) {
|
|
148
|
+
if (!this.fields.has(name)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const field = this.fields.get(name);
|
|
152
|
+
const bool = this.fields.delete(name);
|
|
153
|
+
if (bool) {
|
|
154
|
+
this.emit('field.afterRemove', field);
|
|
155
|
+
}
|
|
156
|
+
return bool;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* TODO
|
|
160
|
+
*/
|
|
161
|
+
updateOptions(options, mergeOptions) {
|
|
162
|
+
let newOptions = lodash_1.default.cloneDeep(options);
|
|
163
|
+
newOptions = (0, deepmerge_1.default)(this.options, newOptions, mergeOptions);
|
|
164
|
+
this.context.database.emit('beforeUpdateCollection', this, newOptions);
|
|
165
|
+
this.setFields(options.fields, false);
|
|
166
|
+
this.setRepository(options.repository);
|
|
167
|
+
this.context.database.emit('afterUpdateCollection', this);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
setSortable(sortable) {
|
|
171
|
+
if (!sortable) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (sortable === true) {
|
|
175
|
+
this.setField('sort', {
|
|
176
|
+
type: 'sort',
|
|
177
|
+
hidden: true,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (typeof sortable === 'string') {
|
|
181
|
+
this.setField(sortable, {
|
|
182
|
+
type: 'sort',
|
|
183
|
+
hidden: true,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (typeof sortable === 'object') {
|
|
187
|
+
const { name } = sortable, opts = __rest(sortable, ["name"]);
|
|
188
|
+
this.setField(name || 'sort', Object.assign({ type: 'sort', hidden: true }, opts));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* TODO
|
|
193
|
+
*
|
|
194
|
+
* @param name
|
|
195
|
+
* @param options
|
|
196
|
+
*/
|
|
197
|
+
updateField(name, options) {
|
|
198
|
+
if (!this.hasField(name)) {
|
|
199
|
+
throw new Error(`field ${name} not exists`);
|
|
200
|
+
}
|
|
201
|
+
if (options.name && options.name !== name) {
|
|
202
|
+
this.removeField(name);
|
|
203
|
+
}
|
|
204
|
+
this.setField(options.name || name, options);
|
|
205
|
+
}
|
|
206
|
+
sync(syncOptions) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const modelNames = [this.model.name];
|
|
209
|
+
const associations = this.model.associations;
|
|
210
|
+
for (const associationKey in associations) {
|
|
211
|
+
const association = associations[associationKey];
|
|
212
|
+
modelNames.push(association.target.name);
|
|
213
|
+
if (association.through) {
|
|
214
|
+
modelNames.push(association.through.model.name);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const models = [];
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
this.context.database.sequelize.modelManager.forEachModel((model) => {
|
|
220
|
+
if (modelNames.includes(model.name)) {
|
|
221
|
+
models.push(model);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
for (const model of models) {
|
|
225
|
+
yield model.sync(syncOptions);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.Collection = Collection;
|
|
231
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA8B;AAC9B,mCAAsC;AACtC,oDAAyD;AAIzD,mCAAgC;AAChC,6CAA0C;AA6B1C,MAAa,UAGX,SAAQ,qBAAY;IAgBpB,YAAY,OAA0B,EAAE,OAA2B;QACjE,KAAK,EAAE,CAAC;QAbV,WAAM,GAAqB,IAAI,GAAG,EAAe,CAAC;QAchD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IAjBD,IAAI,eAAe;QACjB,OAAO,gBAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CA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MAAM,cAAc,IAAI,YAAY,EAAE;gBACzC,MAAM,WAAW,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;gBACjD,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACzC,IAAU,WAAY,CAAC,OAAO,EAAE;oBAC9B,UAAU,CAAC,IAAI,CAAO,WAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;iBACxD;aACF;YAED,MAAM,MAAM,GAAuB,EAAE,CAAC;YACtC,aAAa;YACb,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClE,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;oBACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAC1B,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/B;QACH,CAAC;KAAA;CACF;AArPD,gCAqPC","sourcesContent":["import merge from 'deepmerge';\nimport { EventEmitter } from 'events';\nimport { default as lodash, default as _ } from 'lodash';\nimport { col, ModelCtor, ModelOptions, SyncOptions } from 'sequelize';\nimport { Database } from './database';\nimport { Field, FieldOptions } from './fields';\nimport { Model } from './model';\nimport { Repository } from './repository';\n\nexport type RepositoryType = typeof Repository;\n\nexport type CollectionSortable = string | boolean | { name?: string; scopeKey?: string };\n\nexport interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {\n name: string;\n tableName?: string;\n filterTargetKey?: string;\n fields?: FieldOptions[];\n model?: string | ModelCtor<Model>;\n repository?: string | RepositoryType;\n sortable?: CollectionSortable;\n /**\n * @default true\n */\n autoGenId?: boolean;\n /**\n * @default 'options'\n */\n magicAttribute?: string;\n [key: string]: any;\n}\n\nexport interface CollectionContext {\n database: Database;\n}\n\nexport class Collection<\n TModelAttributes extends {} = any,\n TCreationAttributes extends {} = TModelAttributes,\n> extends EventEmitter {\n options: CollectionOptions;\n context: CollectionContext;\n isThrough?: boolean;\n fields: Map<string, any> = new Map<string, any>();\n model: ModelCtor<Model>;\n repository: Repository<TModelAttributes, TCreationAttributes>;\n\n get filterTargetKey() {\n return lodash.get(this.options, 'filterTargetKey', this.model.primaryKeyAttribute);\n }\n\n get name() {\n return this.options.name;\n }\n\n constructor(options: CollectionOptions, context?: CollectionContext) {\n super();\n this.context = context;\n this.options = options;\n this.bindFieldEventListener();\n this.modelInit();\n this.setFields(options.fields);\n this.setRepository(options.repository);\n this.setSortable(options.sortable);\n }\n\n private sequelizeModelOptions() {\n const { name, tableName } = this.options;\n return {\n ..._.omit(this.options, ['name', 'fields', 'model', 'targetKey']),\n modelName: name,\n sequelize: this.context.database.sequelize,\n tableName: tableName || name,\n };\n }\n\n /**\n * TODO\n */\n modelInit() {\n if (this.model) {\n return;\n }\n const { name, model, autoGenId = true } = this.options;\n let M: ModelCtor<Model> = Model;\n if (this.context.database.sequelize.isDefined(name)) {\n const m = this.context.database.sequelize.model(name);\n if ((m as any).isThrough) {\n // @ts-ignore\n this.model = m;\n // @ts-ignore\n this.model.database = this.context.database;\n // @ts-ignore\n this.model.collection = this;\n return;\n }\n }\n if (typeof model === 'string') {\n M = this.context.database.models.get(model) || Model;\n } else if (model) {\n M = model;\n }\n // @ts-ignore\n this.model = class extends M {};\n this.model.init(null, this.sequelizeModelOptions());\n\n if (!autoGenId) {\n this.model.removeAttribute('id');\n }\n\n // @ts-ignore\n this.model.database = this.context.database;\n // @ts-ignore\n this.model.collection = this;\n }\n\n setRepository(repository?: RepositoryType | string) {\n let repo = Repository;\n if (typeof repository === 'string') {\n repo = this.context.database.repositories.get(repository) || Repository;\n }\n this.repository = new repo(this);\n }\n\n private bindFieldEventListener() {\n this.on('field.afterAdd', (field: Field) => {\n field.bind();\n });\n this.on('field.afterRemove', (field) => field.unbind());\n }\n\n forEachField(callback: (field: Field) => void) {\n return [...this.fields.values()].forEach(callback);\n }\n\n findField(callback: (field: Field) => boolean) {\n return [...this.fields.values()].find(callback);\n }\n\n hasField(name: string) {\n return this.fields.has(name);\n }\n\n getField<F extends Field>(name: string): F {\n return this.fields.get(name);\n }\n\n addField(name: string, options: FieldOptions): Field {\n return this.setField(name, options);\n }\n\n setField(name: string, options: FieldOptions): Field {\n const { database } = this.context;\n\n const field = database.buildField(\n { name, ...options },\n {\n ...this.context,\n collection: this,\n },\n );\n this.removeField(name);\n this.fields.set(name, field);\n this.emit('field.afterAdd', field);\n return field;\n }\n\n setFields(fields: FieldOptions[], resetFields = true) {\n if (!Array.isArray(fields)) {\n return;\n }\n\n if (resetFields) {\n this.resetFields();\n }\n\n for (const { name, ...options } of fields) {\n this.addField(name, options);\n }\n }\n\n resetFields() {\n const fieldNames = this.fields.keys();\n for (const fieldName of fieldNames) {\n this.removeField(fieldName);\n }\n }\n\n removeField(name) {\n if (!this.fields.has(name)) {\n return;\n }\n const field = this.fields.get(name);\n const bool = this.fields.delete(name);\n if (bool) {\n this.emit('field.afterRemove', field);\n }\n return bool;\n }\n\n /**\n * TODO\n */\n updateOptions(options: CollectionOptions, mergeOptions?: any) {\n let newOptions = lodash.cloneDeep(options);\n newOptions = merge(this.options, newOptions, mergeOptions);\n\n this.context.database.emit('beforeUpdateCollection', this, newOptions);\n\n this.setFields(options.fields, false);\n this.setRepository(options.repository);\n\n this.context.database.emit('afterUpdateCollection', this);\n\n return this;\n }\n\n setSortable(sortable) {\n if (!sortable) {\n return;\n }\n if (sortable === true) {\n this.setField('sort', {\n type: 'sort',\n hidden: true,\n });\n }\n if (typeof sortable === 'string') {\n this.setField(sortable, {\n type: 'sort',\n hidden: true,\n });\n } else if (typeof sortable === 'object') {\n const { name, ...opts } = sortable;\n this.setField(name || 'sort', { type: 'sort', hidden: true, ...opts });\n }\n }\n\n /**\n * TODO\n *\n * @param name\n * @param options\n */\n updateField(name: string, options: FieldOptions) {\n if (!this.hasField(name)) {\n throw new Error(`field ${name} not exists`);\n }\n\n if (options.name && options.name !== name) {\n this.removeField(name);\n }\n\n this.setField(options.name || name, options);\n }\n\n async sync(syncOptions?: SyncOptions) {\n const modelNames = [this.model.name];\n\n const associations = this.model.associations;\n\n for (const associationKey in associations) {\n const association = associations[associationKey];\n modelNames.push(association.target.name);\n if ((<any>association).through) {\n modelNames.push((<any>association).through.model.name);\n }\n }\n\n const models: ModelCtor<Model>[] = [];\n // @ts-ignore\n this.context.database.sequelize.modelManager.forEachModel((model) => {\n if (modelNames.includes(model.name)) {\n models.push(model);\n }\n });\n\n for (const model of models) {\n await model.sync(syncOptions);\n }\n }\n}\n"]}
|
package/lib/database.d.ts
CHANGED
|
@@ -1,51 +1,101 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { Model, ModelCtor } from './model';
|
|
2
|
+
import { AsyncEmitter } from '@nocobase/utils';
|
|
3
|
+
import merge from 'deepmerge';
|
|
5
4
|
import { EventEmitter } from 'events';
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { ModelCtor, Options, QueryInterfaceDropAllTablesOptions, Sequelize, SyncOptions } from 'sequelize';
|
|
6
|
+
import { Collection, CollectionOptions, RepositoryType } from './collection';
|
|
7
|
+
import { ImportFileExtension } from './collection-importer';
|
|
8
|
+
import * as FieldTypes from './fields';
|
|
9
|
+
import { Field, FieldContext, RelationField } from './fields';
|
|
10
|
+
import { Model } from './model';
|
|
11
|
+
import { ModelHook } from './model-hook';
|
|
12
|
+
import { RelationRepository } from './relation-repository/relation-repository';
|
|
13
|
+
import { Repository } from './repository';
|
|
14
|
+
export interface MergeOptions extends merge.Options {
|
|
8
15
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
export interface PendingOptions {
|
|
17
|
+
field: RelationField;
|
|
18
|
+
model: ModelCtor<Model>;
|
|
12
19
|
}
|
|
13
|
-
|
|
20
|
+
interface MapOf<T> {
|
|
21
|
+
[key: string]: T;
|
|
14
22
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
export interface IDatabaseOptions extends Options {
|
|
24
|
+
tablePrefix?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare type DatabaseOptions = IDatabaseOptions | Sequelize;
|
|
27
|
+
interface RegisterOperatorsContext {
|
|
28
|
+
db?: Database;
|
|
29
|
+
path?: string;
|
|
30
|
+
field?: Field;
|
|
31
|
+
app?: any;
|
|
32
|
+
}
|
|
33
|
+
export interface CleanOptions extends QueryInterfaceDropAllTablesOptions {
|
|
34
|
+
drop?: boolean;
|
|
19
35
|
}
|
|
20
|
-
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
declare type OperatorFunc = (value: any, ctx?: RegisterOperatorsContext) => any;
|
|
37
|
+
export declare class Database extends EventEmitter implements AsyncEmitter {
|
|
38
|
+
sequelize: Sequelize;
|
|
39
|
+
fieldTypes: Map<any, any>;
|
|
40
|
+
options: IDatabaseOptions;
|
|
41
|
+
models: Map<string, ModelCtor<Model<any, any>>>;
|
|
42
|
+
repositories: Map<string, typeof Repository>;
|
|
43
|
+
operators: Map<any, any>;
|
|
44
|
+
collections: Map<string, Collection<any, any>>;
|
|
45
|
+
pendingFields: Map<string, FieldTypes.RelationField[]>;
|
|
46
|
+
modelCollection: Map<ModelCtor<any>, Collection<any, any>>;
|
|
47
|
+
modelHook: ModelHook;
|
|
48
|
+
delayCollectionExtend: Map<string, {
|
|
49
|
+
collectionOptions: CollectionOptions;
|
|
50
|
+
mergeOptions?: any;
|
|
51
|
+
}[]>;
|
|
52
|
+
constructor(options: DatabaseOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Add collection to database
|
|
55
|
+
* @param options
|
|
56
|
+
*/
|
|
57
|
+
collection<Attributes = any, CreateAttributes = Attributes>(options: CollectionOptions): Collection<Attributes, CreateAttributes>;
|
|
58
|
+
getTablePrefix(): string;
|
|
59
|
+
/**
|
|
60
|
+
* get exists collection by its name
|
|
61
|
+
* @param name
|
|
62
|
+
*/
|
|
63
|
+
getCollection(name: string): Collection;
|
|
64
|
+
hasCollection(name: string): boolean;
|
|
65
|
+
removeCollection(name: string): void;
|
|
66
|
+
getModel<M extends Model>(name: string): ModelCtor<M>;
|
|
67
|
+
getRepository<R extends Repository>(name: string): R;
|
|
68
|
+
getRepository<R extends RelationRepository>(name: string, relationId: string | number): R;
|
|
69
|
+
addPendingField(field: RelationField): void;
|
|
70
|
+
removePendingField(field: RelationField): void;
|
|
71
|
+
registerFieldTypes(fieldTypes: MapOf<typeof Field>): void;
|
|
72
|
+
registerModels(models: MapOf<ModelCtor<any>>): void;
|
|
73
|
+
registerRepositories(repositories: MapOf<RepositoryType>): void;
|
|
74
|
+
initOperators(): void;
|
|
75
|
+
registerOperators(operators: MapOf<OperatorFunc>): void;
|
|
76
|
+
buildField(options: any, context: FieldContext): any;
|
|
77
|
+
sync(options?: SyncOptions): Promise<Sequelize>;
|
|
78
|
+
clean(options: CleanOptions): Promise<void>;
|
|
79
|
+
isSqliteMemory(): boolean;
|
|
80
|
+
reconnect(): Promise<void>;
|
|
81
|
+
closed(): any;
|
|
46
82
|
close(): Promise<void>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
84
|
+
import(options: {
|
|
85
|
+
directory: string;
|
|
86
|
+
extensions?: ImportFileExtension[];
|
|
87
|
+
}): Promise<Map<string, Collection>>;
|
|
88
|
+
emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
|
50
89
|
}
|
|
51
|
-
export {
|
|
90
|
+
export declare function extend(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): {
|
|
91
|
+
collectionOptions: CollectionOptions;
|
|
92
|
+
mergeOptions: MergeOptions;
|
|
93
|
+
extend: boolean;
|
|
94
|
+
};
|
|
95
|
+
export declare const defineCollection: (collectionOptions: CollectionOptions) => CollectionOptions;
|
|
96
|
+
export declare const extendCollection: (collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) => {
|
|
97
|
+
collectionOptions: CollectionOptions;
|
|
98
|
+
mergeOptions: MergeOptions;
|
|
99
|
+
extend: boolean;
|
|
100
|
+
};
|
|
101
|
+
export default Database;
|