@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,152 @@
|
|
|
1
|
+
import { Database } from '../../database';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
import { makeWatchHost } from 'ts-loader/dist/servicesHost';
|
|
4
|
+
|
|
5
|
+
describe('has many field', () => {
|
|
6
|
+
let db: Database;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
db = mockDatabase();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await db.close();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('association undefined', async () => {
|
|
17
|
+
const collection = db.collection({
|
|
18
|
+
name: 'posts',
|
|
19
|
+
fields: [{ type: 'hasMany', name: 'comments' }],
|
|
20
|
+
});
|
|
21
|
+
await db.sync();
|
|
22
|
+
expect(collection.model.associations['comments']).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('association defined', async () => {
|
|
26
|
+
const { model } = db.collection({
|
|
27
|
+
name: 'posts',
|
|
28
|
+
fields: [{ type: 'hasMany', name: 'comments' }],
|
|
29
|
+
});
|
|
30
|
+
expect(model.associations['comments']).toBeUndefined();
|
|
31
|
+
const comments = db.collection({
|
|
32
|
+
name: 'comments',
|
|
33
|
+
fields: [{ type: 'string', name: 'content' }],
|
|
34
|
+
});
|
|
35
|
+
const association = model.associations.comments;
|
|
36
|
+
expect(association).toBeDefined();
|
|
37
|
+
expect(association.foreignKey).toBe('postId');
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
expect(association.sourceKey).toBe('id');
|
|
40
|
+
expect(comments.model.rawAttributes['postId']).toBeDefined();
|
|
41
|
+
await db.sync();
|
|
42
|
+
const post = await model.create<any>();
|
|
43
|
+
await post.createComment({
|
|
44
|
+
content: 'content111',
|
|
45
|
+
});
|
|
46
|
+
const postComments = await post.getComments();
|
|
47
|
+
expect(postComments.map((comment) => comment.content)).toEqual(['content111']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('custom sourceKey', async () => {
|
|
51
|
+
const collection = db.collection({
|
|
52
|
+
name: 'posts',
|
|
53
|
+
fields: [
|
|
54
|
+
{ type: 'string', name: 'key', unique: true },
|
|
55
|
+
{
|
|
56
|
+
type: 'hasMany',
|
|
57
|
+
name: 'comments',
|
|
58
|
+
sourceKey: 'key',
|
|
59
|
+
// foreignKey: 'postKey',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
const comments = db.collection({
|
|
64
|
+
name: 'comments',
|
|
65
|
+
fields: [],
|
|
66
|
+
});
|
|
67
|
+
const association = collection.model.associations.comments;
|
|
68
|
+
expect(association).toBeDefined();
|
|
69
|
+
expect(association.foreignKey).toBe('postKey');
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
expect(association.sourceKey).toBe('key');
|
|
72
|
+
expect(comments.model.rawAttributes['postKey']).toBeDefined();
|
|
73
|
+
await db.sync();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('custom sourceKey and foreignKey', async () => {
|
|
77
|
+
const collection = db.collection({
|
|
78
|
+
name: 'posts',
|
|
79
|
+
fields: [
|
|
80
|
+
{ type: 'string', name: 'key', unique: true },
|
|
81
|
+
{
|
|
82
|
+
type: 'hasMany',
|
|
83
|
+
name: 'comments',
|
|
84
|
+
sourceKey: 'key',
|
|
85
|
+
foreignKey: 'postKey',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
const comments = db.collection({
|
|
90
|
+
name: 'comments',
|
|
91
|
+
fields: [],
|
|
92
|
+
});
|
|
93
|
+
const association = collection.model.associations.comments;
|
|
94
|
+
expect(association).toBeDefined();
|
|
95
|
+
expect(association.foreignKey).toBe('postKey');
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
expect(association.sourceKey).toBe('key');
|
|
98
|
+
expect(comments.model.rawAttributes['postKey']).toBeDefined();
|
|
99
|
+
await db.sync();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('custom name and target', async () => {
|
|
103
|
+
const collection = db.collection({
|
|
104
|
+
name: 'posts',
|
|
105
|
+
fields: [
|
|
106
|
+
{ type: 'string', name: 'key', unique: true },
|
|
107
|
+
{
|
|
108
|
+
type: 'hasMany',
|
|
109
|
+
name: 'reviews',
|
|
110
|
+
target: 'comments',
|
|
111
|
+
sourceKey: 'key',
|
|
112
|
+
foreignKey: 'postKey',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
db.collection({
|
|
117
|
+
name: 'comments',
|
|
118
|
+
fields: [{ type: 'string', name: 'content' }],
|
|
119
|
+
});
|
|
120
|
+
const association = collection.model.associations.reviews;
|
|
121
|
+
expect(association).toBeDefined();
|
|
122
|
+
expect(association.foreignKey).toBe('postKey');
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
expect(association.sourceKey).toBe('key');
|
|
125
|
+
await db.sync();
|
|
126
|
+
const post = await collection.model.create<any>({
|
|
127
|
+
key: 'key1',
|
|
128
|
+
});
|
|
129
|
+
await post.createReview({
|
|
130
|
+
content: 'content111',
|
|
131
|
+
});
|
|
132
|
+
const postComments = await post.getReviews();
|
|
133
|
+
expect(postComments.map((comment) => comment.content)).toEqual(['content111']);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('schema delete', async () => {
|
|
137
|
+
const Post = db.collection({
|
|
138
|
+
name: 'posts',
|
|
139
|
+
fields: [{ type: 'hasMany', name: 'comments' }],
|
|
140
|
+
});
|
|
141
|
+
const Comment = db.collection({
|
|
142
|
+
name: 'comments',
|
|
143
|
+
fields: [{ type: 'belongsTo', name: 'post' }],
|
|
144
|
+
});
|
|
145
|
+
await db.sync();
|
|
146
|
+
Post.removeField('comments');
|
|
147
|
+
expect(Post.model.associations.comments).toBeUndefined();
|
|
148
|
+
expect(Comment.model.rawAttributes.postId).toBeDefined();
|
|
149
|
+
Comment.removeField('post');
|
|
150
|
+
expect(Comment.model.rawAttributes.postId).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Database } from '../../database';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
|
|
4
|
+
describe('has many field', () => {
|
|
5
|
+
let db: Database;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
db = mockDatabase();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(async () => {
|
|
12
|
+
await db.close();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('association undefined', async () => {
|
|
16
|
+
const User = db.collection({
|
|
17
|
+
name: 'users',
|
|
18
|
+
fields: [{ type: 'hasOne', name: 'profile' }],
|
|
19
|
+
});
|
|
20
|
+
await db.sync();
|
|
21
|
+
expect(User.model.associations.profile).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('association defined', async () => {
|
|
25
|
+
const User = db.collection({
|
|
26
|
+
name: 'users',
|
|
27
|
+
fields: [{ type: 'hasOne', name: 'profile' }],
|
|
28
|
+
});
|
|
29
|
+
expect(User.model.associations.phone).toBeUndefined();
|
|
30
|
+
const Profile = db.collection({
|
|
31
|
+
name: 'profiles',
|
|
32
|
+
fields: [{ type: 'string', name: 'content' }],
|
|
33
|
+
});
|
|
34
|
+
const association = User.model.associations.profile;
|
|
35
|
+
expect(association).toBeDefined();
|
|
36
|
+
expect(association.foreignKey).toBe('userId');
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
expect(association.sourceKey).toBe('id');
|
|
39
|
+
expect(Profile.model.rawAttributes['userId']).toBeDefined();
|
|
40
|
+
await db.sync();
|
|
41
|
+
// const post = await model.create<any>();
|
|
42
|
+
// await post.createComment({
|
|
43
|
+
// content: 'content111',
|
|
44
|
+
// });
|
|
45
|
+
// const postComments = await post.getComments();
|
|
46
|
+
// expect(postComments.map((comment) => comment.content)).toEqual([
|
|
47
|
+
// 'content111',
|
|
48
|
+
// ]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('schema delete', async () => {
|
|
52
|
+
const User = db.collection({
|
|
53
|
+
name: 'users',
|
|
54
|
+
fields: [{ type: 'hasOne', name: 'profile' }],
|
|
55
|
+
});
|
|
56
|
+
const Profile = db.collection({
|
|
57
|
+
name: 'profiles',
|
|
58
|
+
fields: [{ type: 'belongsTo', name: 'user' }],
|
|
59
|
+
});
|
|
60
|
+
await db.sync();
|
|
61
|
+
User.removeField('profile');
|
|
62
|
+
expect(User.model.associations.profile).toBeUndefined();
|
|
63
|
+
expect(Profile.model.rawAttributes.userId).toBeDefined();
|
|
64
|
+
Profile.removeField('user');
|
|
65
|
+
expect(Profile.model.rawAttributes.userId).toBeUndefined();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { mockDatabase } from '../';
|
|
2
|
+
import { Database, PasswordField } from '../../';
|
|
3
|
+
|
|
4
|
+
describe('password field', () => {
|
|
5
|
+
let db: Database;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
db = mockDatabase();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(async () => {
|
|
12
|
+
await db.close();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('case 1', async () => {
|
|
16
|
+
const User = db.collection({
|
|
17
|
+
name: 'users',
|
|
18
|
+
fields: [{ type: 'password', name: 'password' }],
|
|
19
|
+
});
|
|
20
|
+
await db.sync();
|
|
21
|
+
const user = await User.model.create<any>({
|
|
22
|
+
password: '123456',
|
|
23
|
+
});
|
|
24
|
+
const pwd = User.getField<PasswordField>('password');
|
|
25
|
+
expect(await pwd.verify('123456', user.password)).toBeTruthy();
|
|
26
|
+
user.set('password', '654321');
|
|
27
|
+
await user.save();
|
|
28
|
+
expect(await pwd.verify('654321', user.password)).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Database } from '../../database';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
import { SortField } from '../../fields';
|
|
4
|
+
|
|
5
|
+
describe('string field', () => {
|
|
6
|
+
let db: Database;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
db = mockDatabase();
|
|
10
|
+
await db.clean({ drop: true });
|
|
11
|
+
db.registerFieldTypes({
|
|
12
|
+
sort: SortField,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
await db.close();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('sort', async () => {
|
|
21
|
+
const Test = db.collection({
|
|
22
|
+
name: 'tests',
|
|
23
|
+
fields: [{ type: 'sort', name: 'sort' }],
|
|
24
|
+
});
|
|
25
|
+
await db.sync();
|
|
26
|
+
|
|
27
|
+
const test1 = await Test.model.create<any>();
|
|
28
|
+
expect(test1.sort).toBe(1);
|
|
29
|
+
const test2 = await Test.model.create<any>();
|
|
30
|
+
expect(test2.sort).toBe(2);
|
|
31
|
+
const test3 = await Test.model.create<any>();
|
|
32
|
+
expect(test3.sort).toBe(3);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should init sort value on data already exits', async () => {
|
|
36
|
+
const Test = db.collection({
|
|
37
|
+
name: 'tests',
|
|
38
|
+
fields: [
|
|
39
|
+
{
|
|
40
|
+
type: 'string',
|
|
41
|
+
name: 'name',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await db.sync();
|
|
47
|
+
|
|
48
|
+
await db.getRepository('tests').create({
|
|
49
|
+
values: {
|
|
50
|
+
name: 't1',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
await db.getRepository('tests').create({
|
|
54
|
+
values: {
|
|
55
|
+
name: 't2',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
await db.getRepository('tests').create({
|
|
59
|
+
values: {
|
|
60
|
+
name: 't3',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const field = Test.addField('sort', { type: 'sort' });
|
|
65
|
+
|
|
66
|
+
await field.sync({});
|
|
67
|
+
|
|
68
|
+
const items = await db.getRepository('tests').find({
|
|
69
|
+
order: ['id'],
|
|
70
|
+
});
|
|
71
|
+
expect(items.map((item) => item.get('sort'))).toEqual([1, 2, 3]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test.skip('simultaneously create ', async () => {
|
|
75
|
+
const Test = db.collection({
|
|
76
|
+
name: 'tests',
|
|
77
|
+
fields: [{ type: 'sort', name: 'sort' }],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await db.sync();
|
|
81
|
+
|
|
82
|
+
const promise = [];
|
|
83
|
+
for (let i = 0; i < 3; i++) {
|
|
84
|
+
promise.push(Test.model.create());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await Promise.all(promise);
|
|
88
|
+
const tests = await Test.model.findAll();
|
|
89
|
+
const sortValues = tests.map((t) => t.get('sort')).sort();
|
|
90
|
+
expect(sortValues).toEqual([1, 2, 3]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('skip if sort value not empty', async () => {
|
|
94
|
+
const Test = db.collection({
|
|
95
|
+
name: 'tests',
|
|
96
|
+
fields: [{ type: 'sort', name: 'sort' }],
|
|
97
|
+
});
|
|
98
|
+
await db.sync();
|
|
99
|
+
const test1 = await Test.model.create<any>({ sort: 3 });
|
|
100
|
+
expect(test1.sort).toBe(3);
|
|
101
|
+
const test2 = await Test.model.create<any>();
|
|
102
|
+
expect(test2.sort).toBe(4);
|
|
103
|
+
const test3 = await Test.model.create<any>();
|
|
104
|
+
expect(test3.sort).toBe(5);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('scopeKey', async () => {
|
|
108
|
+
const Test = db.collection({
|
|
109
|
+
name: 'tests',
|
|
110
|
+
fields: [
|
|
111
|
+
{ type: 'sort', name: 'sort', scopeKey: 'status' },
|
|
112
|
+
{ type: 'string', name: 'status' },
|
|
113
|
+
],
|
|
114
|
+
});
|
|
115
|
+
await db.sync();
|
|
116
|
+
|
|
117
|
+
const t1 = await Test.model.create({ status: 'publish' });
|
|
118
|
+
const t2 = await Test.model.create({ status: 'publish' });
|
|
119
|
+
const t3 = await Test.model.create({ status: 'draft' });
|
|
120
|
+
const t4 = await Test.model.create({ status: 'draft' });
|
|
121
|
+
|
|
122
|
+
expect(t1.get('sort')).toBe(1);
|
|
123
|
+
expect(t2.get('sort')).toBe(2);
|
|
124
|
+
expect(t3.get('sort')).toBe(1);
|
|
125
|
+
expect(t4.get('sort')).toBe(2);
|
|
126
|
+
|
|
127
|
+
t1.set('status', 'draft');
|
|
128
|
+
await t1.save();
|
|
129
|
+
|
|
130
|
+
await t1.reload();
|
|
131
|
+
expect(t1.get('sort')).toBe(3);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Database } from '../../database';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
|
|
4
|
+
describe('string field', () => {
|
|
5
|
+
let db: Database;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
db = mockDatabase();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(async () => {
|
|
12
|
+
await db.close();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('define', async () => {
|
|
16
|
+
const Test = db.collection({
|
|
17
|
+
name: 'tests',
|
|
18
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
19
|
+
});
|
|
20
|
+
await db.sync();
|
|
21
|
+
expect(Test.model.rawAttributes['name']).toBeDefined();
|
|
22
|
+
const model = await Test.model.create({
|
|
23
|
+
name: 'abc',
|
|
24
|
+
});
|
|
25
|
+
expect(model.toJSON()).toMatchObject({
|
|
26
|
+
name: 'abc',
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('set', async () => {
|
|
31
|
+
const Test = db.collection({
|
|
32
|
+
name: 'tests',
|
|
33
|
+
fields: [{ type: 'string', name: 'name1' }],
|
|
34
|
+
});
|
|
35
|
+
await db.sync();
|
|
36
|
+
Test.addField('name2', { type: 'string' });
|
|
37
|
+
await db.sync({
|
|
38
|
+
alter: true,
|
|
39
|
+
});
|
|
40
|
+
expect(Test.model.rawAttributes['name1']).toBeDefined();
|
|
41
|
+
expect(Test.model.rawAttributes['name2']).toBeDefined();
|
|
42
|
+
const model = await Test.model.create({
|
|
43
|
+
name1: 'a1',
|
|
44
|
+
name2: 'a2',
|
|
45
|
+
});
|
|
46
|
+
expect(model.toJSON()).toMatchObject({
|
|
47
|
+
name1: 'a1',
|
|
48
|
+
name2: 'a2',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('model hook', async () => {
|
|
53
|
+
const collection = db.collection({
|
|
54
|
+
name: 'tests',
|
|
55
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
56
|
+
});
|
|
57
|
+
await db.sync();
|
|
58
|
+
collection.model.beforeCreate((model) => {
|
|
59
|
+
const changed = model.changed();
|
|
60
|
+
for (const name of changed || []) {
|
|
61
|
+
model.set(name, `${model.get(name)}111`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
collection.addField('name2', { type: 'string' });
|
|
65
|
+
await db.sync({
|
|
66
|
+
alter: true,
|
|
67
|
+
});
|
|
68
|
+
const model = await collection.model.create({
|
|
69
|
+
name: 'n1',
|
|
70
|
+
name2: 'n2',
|
|
71
|
+
});
|
|
72
|
+
expect(model.toJSON()).toMatchObject({
|
|
73
|
+
name: 'n1111',
|
|
74
|
+
name2: 'n2111',
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Op } from 'sequelize';
|
|
2
|
+
import { Database } from '../database';
|
|
3
|
+
import FilterParser from '../filter-parser';
|
|
4
|
+
import { mockDatabase } from './index';
|
|
5
|
+
|
|
6
|
+
describe('filter by related', () => {
|
|
7
|
+
let db: Database;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
db = mockDatabase();
|
|
11
|
+
db.collection({
|
|
12
|
+
name: 'users',
|
|
13
|
+
fields: [
|
|
14
|
+
{ type: 'string', name: 'name' },
|
|
15
|
+
{ type: 'hasMany', name: 'posts' },
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
db.collection({
|
|
20
|
+
name: 'posts',
|
|
21
|
+
fields: [
|
|
22
|
+
{ type: 'string', name: 'title' },
|
|
23
|
+
{
|
|
24
|
+
type: 'hasMany',
|
|
25
|
+
name: 'comments',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
db.collection({
|
|
31
|
+
name: 'comments',
|
|
32
|
+
fields: [
|
|
33
|
+
{ type: 'string', name: 'content' },
|
|
34
|
+
{
|
|
35
|
+
type: 'belongsTo',
|
|
36
|
+
name: 'post',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await db.sync();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(async () => {
|
|
45
|
+
await db.close();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('filter item by string', async () => {
|
|
49
|
+
const UserCollection = db.collection({
|
|
50
|
+
name: 'users',
|
|
51
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await db.sync();
|
|
55
|
+
|
|
56
|
+
const filterParser = new FilterParser(
|
|
57
|
+
{
|
|
58
|
+
name: 'hello',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
collection: UserCollection,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const filterParams = filterParser.toSequelizeParams();
|
|
66
|
+
|
|
67
|
+
expect(filterParams).toMatchObject({
|
|
68
|
+
where: {
|
|
69
|
+
name: 'hello',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('hasMany', async () => {
|
|
75
|
+
const filter = {
|
|
76
|
+
'posts.title.$iLike': '%hello%',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const filterParser = new FilterParser(filter, {
|
|
80
|
+
collection: db.getCollection('users'),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const filterParams = filterParser.toSequelizeParams();
|
|
84
|
+
|
|
85
|
+
expect(filterParams.where['$posts.title$'][Op.iLike]).toEqual('%hello%');
|
|
86
|
+
expect(filterParams.include[0]['association']).toEqual('posts');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('belongsTo', async () => {
|
|
90
|
+
const filter = {
|
|
91
|
+
'posts.comments.content.$iLike': '%hello%',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const filterParser = new FilterParser(filter, {
|
|
95
|
+
collection: db.getCollection('users'),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const filterParams = filterParser.toSequelizeParams();
|
|
99
|
+
|
|
100
|
+
expect(filterParams.where['$posts.comments.content$'][Op.iLike]).toEqual('%hello%');
|
|
101
|
+
expect(filterParams.include[0]['association']).toEqual('posts');
|
|
102
|
+
expect(filterParams.include[0]['include'][0]['association']).toEqual('comments');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mockDatabase } from '../mock-database';
|