@nocobase/database 0.5.0-alpha.37 → 0.7.0-alpha.1
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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UpdateGuard = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const model_1 = require("./model");
|
|
9
|
+
class UpdateGuard {
|
|
10
|
+
setAction(action) {
|
|
11
|
+
this.action = action;
|
|
12
|
+
}
|
|
13
|
+
setModel(model) {
|
|
14
|
+
this.model = model;
|
|
15
|
+
}
|
|
16
|
+
setAssociationKeysToBeUpdate(associationKeysToBeUpdate) {
|
|
17
|
+
if (this.action == 'create') {
|
|
18
|
+
this.associationKeysToBeUpdate = Object.keys(this.model.associations);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.associationKeysToBeUpdate = associationKeysToBeUpdate;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
setWhiteList(whiteList) {
|
|
25
|
+
this.whiteList = whiteList;
|
|
26
|
+
}
|
|
27
|
+
setBlackList(blackList) {
|
|
28
|
+
this.blackList = blackList;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sanitize values by whitelist blacklist
|
|
32
|
+
* @param values
|
|
33
|
+
*/
|
|
34
|
+
sanitize(values) {
|
|
35
|
+
values = lodash_1.default.clone(values);
|
|
36
|
+
if (!this.model) {
|
|
37
|
+
throw new Error('please set model first');
|
|
38
|
+
}
|
|
39
|
+
const associations = this.model.associations;
|
|
40
|
+
const associationsValues = lodash_1.default.pick(values, Object.keys(associations));
|
|
41
|
+
// build params of association update guard
|
|
42
|
+
const listOfAssociation = (list, association) => {
|
|
43
|
+
if (list) {
|
|
44
|
+
list = list
|
|
45
|
+
.filter((whiteListKey) => whiteListKey.startsWith(`${association}.`))
|
|
46
|
+
.map((whiteListKey) => whiteListKey.replace(`${association}.`, ''));
|
|
47
|
+
if (list.length == 0) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
// sanitize association values
|
|
55
|
+
Object.keys(associationsValues).forEach((association) => {
|
|
56
|
+
let associationValues = associationsValues[association];
|
|
57
|
+
const filterAssociationToBeUpdate = (value) => {
|
|
58
|
+
const associationKeysToBeUpdate = this.associationKeysToBeUpdate || [];
|
|
59
|
+
if (associationKeysToBeUpdate.includes(association)) {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
const associationObj = associations[association];
|
|
63
|
+
const associationKeyName = associationObj.associationType == 'BelongsTo' || associationObj.associationType == 'HasOne'
|
|
64
|
+
? associationObj.targetKey
|
|
65
|
+
: associationObj.target.primaryKeyAttribute;
|
|
66
|
+
if (value[associationKeyName]) {
|
|
67
|
+
return lodash_1.default.pick(value, [associationKeyName, ...Object.keys(associationObj.target.associations)]);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
const sanitizeValue = (value) => {
|
|
72
|
+
const associationUpdateGuard = new UpdateGuard();
|
|
73
|
+
associationUpdateGuard.setModel(associations[association].target);
|
|
74
|
+
['whiteList', 'blackList', 'associationKeysToBeUpdate'].forEach((optionKey) => {
|
|
75
|
+
associationUpdateGuard[`set${lodash_1.default.upperFirst(optionKey)}`](listOfAssociation(this[optionKey], association));
|
|
76
|
+
});
|
|
77
|
+
return associationUpdateGuard.sanitize(filterAssociationToBeUpdate(value));
|
|
78
|
+
};
|
|
79
|
+
if (Array.isArray(associationValues)) {
|
|
80
|
+
associationValues = associationValues.map((value) => {
|
|
81
|
+
if (typeof value == 'string' || typeof value == 'number') {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return sanitizeValue(value);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
else if (typeof associationValues === 'object' && associationValues !== null) {
|
|
90
|
+
associationValues = sanitizeValue(associationValues);
|
|
91
|
+
}
|
|
92
|
+
// set association values to sanitized value
|
|
93
|
+
values[association] = associationValues;
|
|
94
|
+
});
|
|
95
|
+
if (values instanceof model_1.Model) {
|
|
96
|
+
return values;
|
|
97
|
+
}
|
|
98
|
+
let valuesKeys = Object.keys(values || {});
|
|
99
|
+
// handle whitelist
|
|
100
|
+
if (this.whiteList) {
|
|
101
|
+
valuesKeys = valuesKeys.filter((valueKey) => {
|
|
102
|
+
return (this.whiteList.findIndex((whiteKey) => {
|
|
103
|
+
const keyPaths = whiteKey.split('.');
|
|
104
|
+
return keyPaths[0] === valueKey;
|
|
105
|
+
}) !== -1);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// handle blacklist
|
|
109
|
+
if (this.blackList) {
|
|
110
|
+
valuesKeys = valuesKeys.filter((valueKey) => !this.blackList.includes(valueKey));
|
|
111
|
+
}
|
|
112
|
+
const result = valuesKeys.reduce((obj, key) => {
|
|
113
|
+
lodash_1.default.set(obj, key, values[key]);
|
|
114
|
+
return obj;
|
|
115
|
+
}, {});
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
static fromOptions(model, options) {
|
|
119
|
+
const guard = new UpdateGuard();
|
|
120
|
+
guard.setModel(model);
|
|
121
|
+
guard.setWhiteList(options.whitelist);
|
|
122
|
+
guard.setBlackList(options.blacklist);
|
|
123
|
+
guard.setAction(lodash_1.default.get(options, 'action', 'update'));
|
|
124
|
+
guard.setAssociationKeysToBeUpdate(options.updateAssociationValues);
|
|
125
|
+
return guard;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.UpdateGuard = UpdateGuard;
|
|
129
|
+
//# sourceMappingURL=update-guard.js.map
|
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,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;QACzD,KAAK,CAAC,4BAA4B,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1JD,kCA0JC","sourcesContent":["import lodash from 'lodash';\nimport { ModelCtor } from 'sequelize';\nimport { Model } from './model';\nimport { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository';\n\ntype UpdateValueItem = string | number | UpdateValues;\n\ntype UpdateValues = {\n [key: string]: UpdateValueItem | Array<UpdateValueItem>;\n};\n\ntype UpdateAction = 'create' | 'update';\nexport class UpdateGuard {\n model: ModelCtor<any>;\n action: UpdateAction;\n private associationKeysToBeUpdate: AssociationKeysToBeUpdate;\n private blackList: BlackList;\n private whiteList: WhiteList;\n\n setAction(action: UpdateAction) {\n this.action = action;\n }\n\n setModel(model: ModelCtor<any>) {\n this.model = model;\n }\n\n setAssociationKeysToBeUpdate(associationKeysToBeUpdate: AssociationKeysToBeUpdate) {\n if (this.action == 'create') {\n this.associationKeysToBeUpdate = Object.keys(this.model.associations);\n } else {\n this.associationKeysToBeUpdate = associationKeysToBeUpdate;\n }\n }\n\n setWhiteList(whiteList: WhiteList) {\n this.whiteList = whiteList;\n }\n\n setBlackList(blackList: BlackList) {\n this.blackList = blackList;\n }\n\n /**\n * Sanitize values by whitelist blacklist\n * @param values\n */\n sanitize(values: UpdateValues) {\n values = lodash.clone(values);\n\n if (!this.model) {\n throw new Error('please set model first');\n }\n\n const associations = this.model.associations;\n const associationsValues = lodash.pick(values, Object.keys(associations));\n\n // build params of association update guard\n const listOfAssociation = (list, association) => {\n if (list) {\n list = list\n .filter((whiteListKey) => whiteListKey.startsWith(`${association}.`))\n .map((whiteListKey) => whiteListKey.replace(`${association}.`, ''));\n\n if (list.length == 0) {\n return undefined;\n }\n\n return list;\n }\n\n return undefined;\n };\n\n // sanitize association values\n Object.keys(associationsValues).forEach((association) => {\n let associationValues = associationsValues[association];\n\n const filterAssociationToBeUpdate = (value) => {\n const associationKeysToBeUpdate = this.associationKeysToBeUpdate || [];\n\n if (associationKeysToBeUpdate.includes(association)) {\n return value;\n }\n\n const associationObj = associations[association];\n\n const associationKeyName =\n associationObj.associationType == 'BelongsTo' || associationObj.associationType == 'HasOne'\n ? (<any>associationObj).targetKey\n : associationObj.target.primaryKeyAttribute;\n\n if (value[associationKeyName]) {\n return lodash.pick(value, [associationKeyName, ...Object.keys(associationObj.target.associations)]);\n }\n\n return value;\n };\n\n const sanitizeValue = (value) => {\n const associationUpdateGuard = new UpdateGuard();\n associationUpdateGuard.setModel(associations[association].target);\n\n ['whiteList', 'blackList', 'associationKeysToBeUpdate'].forEach((optionKey) => {\n associationUpdateGuard[`set${lodash.upperFirst(optionKey)}`](listOfAssociation(this[optionKey], association));\n });\n\n return associationUpdateGuard.sanitize(filterAssociationToBeUpdate(value));\n };\n\n if (Array.isArray(associationValues)) {\n associationValues = associationValues.map((value) => {\n if (typeof value == 'string' || typeof value == 'number') {\n return value;\n } else {\n return sanitizeValue(value);\n }\n });\n } else if (typeof associationValues === 'object' && associationValues !== null) {\n associationValues = sanitizeValue(associationValues);\n }\n\n // set association values to sanitized value\n values[association] = associationValues;\n });\n\n if (values instanceof Model) {\n return values;\n }\n\n let valuesKeys = Object.keys(values || {});\n\n // handle whitelist\n if (this.whiteList) {\n valuesKeys = valuesKeys.filter((valueKey) => {\n return (\n this.whiteList.findIndex((whiteKey) => {\n const keyPaths = whiteKey.split('.');\n return keyPaths[0] === valueKey;\n }) !== -1\n );\n });\n }\n\n // handle blacklist\n if (this.blackList) {\n valuesKeys = valuesKeys.filter((valueKey) => !this.blackList.includes(valueKey));\n }\n\n const result = valuesKeys.reduce((obj, key) => {\n lodash.set(obj, key, values[key]);\n return obj;\n }, {});\n\n return result;\n }\n\n static fromOptions(model, options) {\n const guard = new UpdateGuard();\n guard.setModel(model);\n guard.setWhiteList(options.whitelist);\n guard.setBlackList(options.blacklist);\n guard.setAction(lodash.get(options, 'action', 'update'));\n guard.setAssociationKeysToBeUpdate(options.updateAssociationValues);\n return guard;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"license": "
|
|
8
|
-
"
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"licenses": [
|
|
9
|
+
{
|
|
10
|
+
"type": "Apache-2.0",
|
|
11
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
|
|
16
|
+
"build:cjs": "tsc --project tsconfig.build.json",
|
|
17
|
+
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
|
|
18
|
+
},
|
|
9
19
|
"dependencies": {
|
|
10
|
-
"
|
|
20
|
+
"@nocobase/utils": "0.7.0-alpha.1",
|
|
21
|
+
"async-mutex": "^0.3.2",
|
|
11
22
|
"deepmerge": "^4.2.2",
|
|
23
|
+
"flat": "^5.0.2",
|
|
12
24
|
"glob": "^7.1.6",
|
|
13
25
|
"sequelize": "^6.9.0"
|
|
14
26
|
},
|
|
@@ -17,5 +29,5 @@
|
|
|
17
29
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
18
30
|
"directory": "packages/database"
|
|
19
31
|
},
|
|
20
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e7293ad7aadbdf2084042f7800a232af6e0b7a8a"
|
|
21
33
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ImporterReader } from '../collection-importer';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { extend } from '../database';
|
|
4
|
+
|
|
5
|
+
describe('collection importer', () => {
|
|
6
|
+
test('import reader', async () => {
|
|
7
|
+
const reader = new ImporterReader(path.resolve(__dirname, './fixtures/collections'));
|
|
8
|
+
|
|
9
|
+
const modules = await reader.read();
|
|
10
|
+
expect(modules).toBeDefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('extend', async () => {
|
|
14
|
+
const extendObject = extend({
|
|
15
|
+
name: 'tags',
|
|
16
|
+
fields: [{ type: 'string', name: 'title' }],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(extendObject).toHaveProperty('extend');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { mockDatabase } from './index';
|
|
2
|
+
import { Database } from '../database';
|
|
3
|
+
|
|
4
|
+
describe('collection sortable options', () => {
|
|
5
|
+
let db: Database;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
db = mockDatabase();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(async () => {
|
|
12
|
+
await db.close();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('sortable=true', async () => {
|
|
16
|
+
const Test = db.collection({
|
|
17
|
+
name: 'test',
|
|
18
|
+
sortable: true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const model = Test.model;
|
|
22
|
+
|
|
23
|
+
await db.sync();
|
|
24
|
+
const instance = await model.create();
|
|
25
|
+
expect(model.rawAttributes['sort']).toBeDefined();
|
|
26
|
+
expect(instance.get('sort')).toBe(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('sortable=string', async () => {
|
|
30
|
+
const Test = db.collection({
|
|
31
|
+
name: 'test',
|
|
32
|
+
sortable: 'order',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const model = Test.model;
|
|
36
|
+
|
|
37
|
+
await db.sync();
|
|
38
|
+
const instance = await model.create();
|
|
39
|
+
expect(model.rawAttributes['order']).toBeDefined();
|
|
40
|
+
expect(instance.get('order')).toBe(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('sortable=object', async () => {
|
|
44
|
+
const Test = db.collection({
|
|
45
|
+
name: 'test',
|
|
46
|
+
sortable: {
|
|
47
|
+
name: 'sort',
|
|
48
|
+
scopeKey: 'status',
|
|
49
|
+
},
|
|
50
|
+
fields: [{ type: 'string', name: 'status' }],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
await db.sync();
|
|
54
|
+
|
|
55
|
+
const t1 = await Test.model.create({ status: 'publish' });
|
|
56
|
+
const t2 = await Test.model.create({ status: 'publish' });
|
|
57
|
+
const t3 = await Test.model.create({ status: 'draft' });
|
|
58
|
+
const t4 = await Test.model.create({ status: 'draft' });
|
|
59
|
+
|
|
60
|
+
expect(t1.get('sort')).toBe(1);
|
|
61
|
+
expect(t2.get('sort')).toBe(2);
|
|
62
|
+
expect(t3.get('sort')).toBe(1);
|
|
63
|
+
expect(t4.get('sort')).toBe(2);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Collection } from '../collection';
|
|
2
|
+
import { Database } from '../database';
|
|
3
|
+
import { mockDatabase } from './index';
|
|
4
|
+
|
|
5
|
+
describe('collection', () => {
|
|
6
|
+
let db: Database;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
db = mockDatabase();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await db.close();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('collection disable authGenId', async () => {
|
|
17
|
+
const Test = db.collection({
|
|
18
|
+
name: 'test',
|
|
19
|
+
autoGenId: false,
|
|
20
|
+
fields: [{ type: 'string', name: 'uid', primaryKey: true }],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const model = Test.model;
|
|
24
|
+
|
|
25
|
+
await db.sync();
|
|
26
|
+
expect(model.rawAttributes['id']).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('new collection', async () => {
|
|
30
|
+
const collection = new Collection(
|
|
31
|
+
{
|
|
32
|
+
name: 'test',
|
|
33
|
+
},
|
|
34
|
+
{ database: db },
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(collection.name).toEqual('test');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('collection create field', async () => {
|
|
41
|
+
const collection = new Collection(
|
|
42
|
+
{
|
|
43
|
+
name: 'user',
|
|
44
|
+
},
|
|
45
|
+
{ database: db },
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
collection.addField('age', {
|
|
49
|
+
type: 'integer',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const ageField = collection.getField('age');
|
|
53
|
+
expect(ageField).toBeDefined();
|
|
54
|
+
expect(collection.hasField('age')).toBeTruthy();
|
|
55
|
+
expect(collection.hasField('test')).toBeFalsy();
|
|
56
|
+
|
|
57
|
+
collection.removeField('age');
|
|
58
|
+
expect(collection.hasField('age')).toBeFalsy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('collection set fields', () => {
|
|
62
|
+
const collection = new Collection(
|
|
63
|
+
{
|
|
64
|
+
name: 'user',
|
|
65
|
+
},
|
|
66
|
+
{ database: db },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
collection.setFields([{ type: 'string', name: 'firstName' }]);
|
|
70
|
+
expect(collection.hasField('firstName')).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('update collection field', async () => {
|
|
74
|
+
const collection = new Collection(
|
|
75
|
+
{
|
|
76
|
+
name: 'posts',
|
|
77
|
+
fields: [{ type: 'string', name: 'title' }],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
database: db,
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
expect(collection.hasField('title')).toBeTruthy();
|
|
84
|
+
|
|
85
|
+
collection.updateField('title', {
|
|
86
|
+
type: 'string',
|
|
87
|
+
name: 'content',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(collection.hasField('title')).toBeFalsy();
|
|
91
|
+
expect(collection.hasField('content')).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('collection with association', async () => {
|
|
95
|
+
const User = db.collection({
|
|
96
|
+
name: 'users',
|
|
97
|
+
fields: [
|
|
98
|
+
{ type: 'string', name: 'name' },
|
|
99
|
+
{ type: 'integer', name: 'age' },
|
|
100
|
+
{ type: 'hasMany', name: 'posts' },
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const Post = db.collection({
|
|
105
|
+
name: 'posts',
|
|
106
|
+
fields: [
|
|
107
|
+
{ type: 'string', name: 'title' },
|
|
108
|
+
{ type: 'string', name: 'content' },
|
|
109
|
+
{
|
|
110
|
+
type: 'belongsTo',
|
|
111
|
+
name: 'user',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: 'hasMany',
|
|
115
|
+
name: 'comments',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const Comment = db.collection({
|
|
121
|
+
name: 'comments',
|
|
122
|
+
fields: [
|
|
123
|
+
{ type: 'string', name: 'content' },
|
|
124
|
+
{ type: 'string', name: 'comment_as' },
|
|
125
|
+
{ type: 'belongsTo', name: 'post' },
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(User.model.associations['posts']).toBeDefined();
|
|
130
|
+
expect(Post.model.associations['comments']).toBeDefined();
|
|
131
|
+
|
|
132
|
+
expect(User.model.associations['posts'].target.associations['comments']).toBeDefined();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('collection sync', () => {
|
|
137
|
+
let db: Database;
|
|
138
|
+
|
|
139
|
+
beforeEach(async () => {
|
|
140
|
+
db = mockDatabase();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
afterEach(async () => {
|
|
144
|
+
await db.close();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('sync fields', async () => {
|
|
148
|
+
const collection = new Collection(
|
|
149
|
+
{
|
|
150
|
+
name: 'users',
|
|
151
|
+
},
|
|
152
|
+
{ database: db },
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
collection.setFields([
|
|
156
|
+
{ type: 'string', name: 'firstName' },
|
|
157
|
+
{ type: 'string', name: 'lastName' },
|
|
158
|
+
{ type: 'integer', name: 'age' },
|
|
159
|
+
]);
|
|
160
|
+
|
|
161
|
+
await collection.sync();
|
|
162
|
+
const tableFields = await (<any>collection.model).queryInterface.describeTable(`${db.getTablePrefix()}users`);
|
|
163
|
+
|
|
164
|
+
expect(tableFields).toHaveProperty('firstName');
|
|
165
|
+
expect(tableFields).toHaveProperty('lastName');
|
|
166
|
+
expect(tableFields).toHaveProperty('age');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('sync with association not exists', async () => {
|
|
170
|
+
const collection = new Collection(
|
|
171
|
+
{
|
|
172
|
+
name: 'posts',
|
|
173
|
+
fields: [
|
|
174
|
+
{ type: 'string', name: 'title' },
|
|
175
|
+
{ type: 'belongsTo', name: 'users' },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
{ database: db },
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
await collection.sync();
|
|
182
|
+
|
|
183
|
+
const model = collection.model;
|
|
184
|
+
|
|
185
|
+
const tableFields = await (<any>model).queryInterface.describeTable(`${db.getTablePrefix()}posts`);
|
|
186
|
+
|
|
187
|
+
expect(tableFields['userId']).toBeUndefined();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('sync with association', async () => {
|
|
191
|
+
new Collection(
|
|
192
|
+
{
|
|
193
|
+
name: 'tags',
|
|
194
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
195
|
+
},
|
|
196
|
+
{ database: db },
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const collection = new Collection(
|
|
200
|
+
{
|
|
201
|
+
name: 'posts',
|
|
202
|
+
fields: [
|
|
203
|
+
{ type: 'string', name: 'title' },
|
|
204
|
+
{ type: 'belongsToMany', name: 'tags' },
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
database: db,
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const model = collection.model;
|
|
213
|
+
await collection.sync();
|
|
214
|
+
const tableFields = await (<any>model).queryInterface.describeTable(`${db.getTablePrefix()}postsTags`);
|
|
215
|
+
expect(tableFields['postId']).toBeDefined();
|
|
216
|
+
expect(tableFields['tagId']).toBeDefined();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mockDatabase } from './index';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import Database from '../database';
|
|
4
|
+
|
|
5
|
+
describe('database', () => {
|
|
6
|
+
let db: Database;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
db = mockDatabase();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await db.close();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('import', async () => {
|
|
17
|
+
await db.import({
|
|
18
|
+
directory: path.resolve(__dirname, './fixtures/c0'),
|
|
19
|
+
});
|
|
20
|
+
await db.import({
|
|
21
|
+
directory: path.resolve(__dirname, './fixtures/c1'),
|
|
22
|
+
});
|
|
23
|
+
await db.import({
|
|
24
|
+
directory: path.resolve(__dirname, './fixtures/c2'),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const test = db.getCollection('tests');
|
|
28
|
+
|
|
29
|
+
expect(test.getField('n0')).toBeDefined();
|
|
30
|
+
expect(test.getField('n1')).toBeDefined();
|
|
31
|
+
expect(test.getField('n2')).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
});
|