@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,220 @@
|
|
|
1
|
+
import { mockDatabase } from '@nocobase/test';
|
|
2
|
+
import { BelongsToManyRepository, Database } from '../../index';
|
|
3
|
+
|
|
4
|
+
describe('associated field order', () => {
|
|
5
|
+
let db: Database;
|
|
6
|
+
|
|
7
|
+
afterEach(async () => {
|
|
8
|
+
await db.close();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
db = mockDatabase();
|
|
13
|
+
await db.clean({ drop: true });
|
|
14
|
+
|
|
15
|
+
db.collection({
|
|
16
|
+
name: 'users',
|
|
17
|
+
fields: [
|
|
18
|
+
{
|
|
19
|
+
type: 'string',
|
|
20
|
+
name: 'name',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'hasMany',
|
|
24
|
+
name: 'posts',
|
|
25
|
+
sortBy: 'title',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'hasMany',
|
|
29
|
+
name: 'records',
|
|
30
|
+
sortBy: 'count',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
db.collection({
|
|
36
|
+
name: 'records',
|
|
37
|
+
fields: [
|
|
38
|
+
{
|
|
39
|
+
type: 'integer',
|
|
40
|
+
name: 'count',
|
|
41
|
+
hidden: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'string',
|
|
45
|
+
name: 'name',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
db.collection({
|
|
51
|
+
name: 'posts',
|
|
52
|
+
fields: [
|
|
53
|
+
{
|
|
54
|
+
type: 'string',
|
|
55
|
+
name: 'title',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: 'belongsTo',
|
|
59
|
+
name: 'user',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'belongsToMany',
|
|
63
|
+
name: 'tags',
|
|
64
|
+
sortBy: 'name',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: 'belongsToMany',
|
|
68
|
+
name: 'images',
|
|
69
|
+
through: 'posts_images',
|
|
70
|
+
sortBy: ['-posts_images.sort'],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
db.collection({
|
|
76
|
+
name: 'tags',
|
|
77
|
+
fields: [
|
|
78
|
+
{ type: 'string', name: 'name' },
|
|
79
|
+
{
|
|
80
|
+
type: 'belongsToMany',
|
|
81
|
+
name: 'posts',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
db.collection({
|
|
87
|
+
name: 'posts_images',
|
|
88
|
+
fields: [{ type: 'integer', name: 'sort' }],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
db.collection({
|
|
92
|
+
name: 'images',
|
|
93
|
+
fields: [
|
|
94
|
+
{
|
|
95
|
+
type: 'belongsToMany',
|
|
96
|
+
name: 'posts',
|
|
97
|
+
through: 'posts_images',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'string',
|
|
101
|
+
name: 'url',
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await db.sync();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should sort hasMany association', async () => {
|
|
110
|
+
await db.getRepository('users').create({
|
|
111
|
+
values: {
|
|
112
|
+
name: 'u1',
|
|
113
|
+
posts: [{ title: 'c' }, { title: 'b' }, { title: 'a' }],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const u1 = await db.getRepository('users').findOne({
|
|
118
|
+
appends: ['posts'],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const u1Json = u1.toJSON();
|
|
122
|
+
|
|
123
|
+
const u1Posts = u1Json['posts'];
|
|
124
|
+
expect(u1Posts.map((p) => p['title'])).toEqual(['a', 'b', 'c']);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should sort belongsToMany association', async () => {
|
|
128
|
+
await db.getRepository('posts').create({
|
|
129
|
+
values: {
|
|
130
|
+
title: 'p1',
|
|
131
|
+
tags: [{ name: 'c' }, { name: 'b' }, { name: 'a' }],
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const p1 = await db.getRepository('posts').findOne({
|
|
136
|
+
appends: ['tags'],
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const p1JSON = p1.toJSON();
|
|
140
|
+
|
|
141
|
+
const p1Tags = p1JSON['tags'];
|
|
142
|
+
expect(p1Tags.map((p) => p['name'])).toEqual(['a', 'b', 'c']);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should sort nested associations', async () => {
|
|
146
|
+
await db.getRepository('users').create({
|
|
147
|
+
values: {
|
|
148
|
+
name: 'u1',
|
|
149
|
+
posts: [{ title: 'c', tags: [{ name: 'c' }, { name: 'b' }, { name: 'a' }] }, { title: 'b' }, { title: 'a' }],
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const u1 = await db.getRepository('users').findOne({
|
|
154
|
+
appends: ['posts.tags'],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const u1Json = u1.toJSON();
|
|
158
|
+
const u1Posts = u1Json['posts'];
|
|
159
|
+
expect(u1Posts.map((p) => p['title'])).toEqual(['a', 'b', 'c']);
|
|
160
|
+
|
|
161
|
+
const postCTags = u1Posts[2]['tags'];
|
|
162
|
+
expect(postCTags.map((p) => p['name'])).toEqual(['a', 'b', 'c']);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should sortBy hidden field', async () => {
|
|
166
|
+
await db.getRepository('users').create({
|
|
167
|
+
values: {
|
|
168
|
+
name: 'u1',
|
|
169
|
+
records: [
|
|
170
|
+
{ count: 3, name: 'c' },
|
|
171
|
+
{ count: 2, name: 'b' },
|
|
172
|
+
{ count: 1, name: 'a' },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const u1 = await db.getRepository('users').findOne({
|
|
178
|
+
appends: ['records'],
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const u1Json = u1.toJSON();
|
|
182
|
+
|
|
183
|
+
const u1Records = u1Json['records'];
|
|
184
|
+
expect(u1Records[0].count).toBeUndefined();
|
|
185
|
+
expect(u1Records.map((p) => p['name'])).toEqual(['a', 'b', 'c']);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should sortBy through table field', async () => {
|
|
189
|
+
const p1 = await db.getRepository('posts').create({
|
|
190
|
+
values: {
|
|
191
|
+
name: 'u1',
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const t1 = await db.getRepository('images').create({
|
|
196
|
+
values: {
|
|
197
|
+
url: 't1',
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const t2 = await db.getRepository('images').create({
|
|
202
|
+
values: {
|
|
203
|
+
url: 't2',
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const postImageRepository = db.getRepository<BelongsToManyRepository>('posts.images', p1.get('id') as string);
|
|
208
|
+
|
|
209
|
+
await postImageRepository.add([[t2.get('id') as string, { sort: 2 }]]);
|
|
210
|
+
await postImageRepository.add([[t1.get('id') as string, { sort: 1 }]]);
|
|
211
|
+
|
|
212
|
+
const p1Result = await db.getRepository('posts').findOne({
|
|
213
|
+
appends: ['images'],
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const p1JSON = p1Result.toJSON();
|
|
217
|
+
const p1Images = p1JSON['images'];
|
|
218
|
+
expect(p1Images.map((i) => i['url'])).toEqual(['t2', 't1']);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Database } from '../../database';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
|
|
4
|
+
describe('belongs to 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 Comment = db.collection({
|
|
17
|
+
name: 'comments',
|
|
18
|
+
fields: [{ type: 'belongsTo', name: 'post' }],
|
|
19
|
+
});
|
|
20
|
+
expect(Comment.model.associations['post']).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('association defined', async () => {
|
|
24
|
+
const Comment = db.collection({
|
|
25
|
+
name: 'comments',
|
|
26
|
+
fields: [
|
|
27
|
+
{ type: 'string', name: 'content' },
|
|
28
|
+
{ type: 'belongsTo', name: 'post' },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
expect(Comment.model.associations.post).toBeUndefined();
|
|
32
|
+
const Post = db.collection({
|
|
33
|
+
name: 'posts',
|
|
34
|
+
fields: [{ type: 'string', name: 'title' }],
|
|
35
|
+
});
|
|
36
|
+
const association = Comment.model.associations.post;
|
|
37
|
+
expect(Comment.model.associations.post).toBeDefined();
|
|
38
|
+
expect(association.foreignKey).toBe('postId');
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
expect(association.targetKey).toBe('id');
|
|
41
|
+
expect(Comment.model.rawAttributes.postId).toBeDefined();
|
|
42
|
+
await db.sync();
|
|
43
|
+
const comment = await Comment.model.create<any>();
|
|
44
|
+
await comment.createPost({
|
|
45
|
+
title: 'title222',
|
|
46
|
+
});
|
|
47
|
+
const post1 = await comment.getPost();
|
|
48
|
+
expect(post1.toJSON()).toMatchObject({
|
|
49
|
+
title: 'title222',
|
|
50
|
+
});
|
|
51
|
+
const post = await Post.model.create<any>({
|
|
52
|
+
title: 'title111',
|
|
53
|
+
});
|
|
54
|
+
await comment.setPost(post);
|
|
55
|
+
const post2 = await comment.getPost();
|
|
56
|
+
expect(post2.toJSON()).toMatchObject({
|
|
57
|
+
title: 'title111',
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('custom targetKey and foreignKey', async () => {
|
|
62
|
+
const Post = db.collection({
|
|
63
|
+
name: 'posts',
|
|
64
|
+
fields: [{ type: 'string', name: 'key', unique: true }],
|
|
65
|
+
});
|
|
66
|
+
const Comment = db.collection({
|
|
67
|
+
name: 'comments',
|
|
68
|
+
fields: [
|
|
69
|
+
{
|
|
70
|
+
type: 'belongsTo',
|
|
71
|
+
name: 'post',
|
|
72
|
+
targetKey: 'key',
|
|
73
|
+
foreignKey: 'postKey',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
const association = Comment.model.associations.post;
|
|
78
|
+
expect(association).toBeDefined();
|
|
79
|
+
expect(association.foreignKey).toBe('postKey');
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
expect(association.targetKey).toBe('key');
|
|
82
|
+
expect(Comment.model.rawAttributes['postKey']).toBeDefined();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('custom name and target', async () => {
|
|
86
|
+
const Comment = db.collection({
|
|
87
|
+
name: 'comments',
|
|
88
|
+
fields: [
|
|
89
|
+
{ type: 'string', name: 'content' },
|
|
90
|
+
{
|
|
91
|
+
type: 'belongsTo',
|
|
92
|
+
name: 'article',
|
|
93
|
+
target: 'posts',
|
|
94
|
+
targetKey: 'key',
|
|
95
|
+
foreignKey: 'postKey',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
expect(Comment.model.associations.article).toBeUndefined();
|
|
100
|
+
const Post = db.collection({
|
|
101
|
+
name: 'posts',
|
|
102
|
+
fields: [{ type: 'string', name: 'key', unique: true }],
|
|
103
|
+
});
|
|
104
|
+
const association = Comment.model.associations.article;
|
|
105
|
+
expect(Comment.model.associations.article).toBeDefined();
|
|
106
|
+
expect(association.foreignKey).toBe('postKey');
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
expect(association.targetKey).toBe('key');
|
|
109
|
+
expect(Comment.model.rawAttributes.postKey).toBeDefined();
|
|
110
|
+
await db.sync();
|
|
111
|
+
const comment = await Comment.model.create<any>();
|
|
112
|
+
await comment.createArticle({
|
|
113
|
+
key: 'title222',
|
|
114
|
+
});
|
|
115
|
+
const post1 = await comment.getArticle();
|
|
116
|
+
expect(post1.toJSON()).toMatchObject({
|
|
117
|
+
key: 'title222',
|
|
118
|
+
});
|
|
119
|
+
const post = await Post.model.create<any>({
|
|
120
|
+
key: 'title111',
|
|
121
|
+
});
|
|
122
|
+
await comment.setArticle(post);
|
|
123
|
+
const post2 = await comment.getArticle();
|
|
124
|
+
expect(post2.toJSON()).toMatchObject({
|
|
125
|
+
key: 'title111',
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('schema delete', async () => {
|
|
130
|
+
const Comment = db.collection({
|
|
131
|
+
name: 'comments',
|
|
132
|
+
fields: [{ type: 'belongsTo', name: 'post' }],
|
|
133
|
+
});
|
|
134
|
+
const Post = db.collection({
|
|
135
|
+
name: 'posts',
|
|
136
|
+
fields: [{ type: 'hasMany', name: 'comments' }],
|
|
137
|
+
});
|
|
138
|
+
// await db.sync();
|
|
139
|
+
Comment.removeField('post');
|
|
140
|
+
expect(Comment.model.associations.post).toBeUndefined();
|
|
141
|
+
expect(Comment.model.rawAttributes.postId).toBeDefined();
|
|
142
|
+
Post.removeField('comments');
|
|
143
|
+
expect(Comment.model.rawAttributes.postId).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('has inverse field', async () => {
|
|
147
|
+
const Post = db.collection({
|
|
148
|
+
name: 'posts',
|
|
149
|
+
fields: [{ type: 'hasMany', name: 'comments' }],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const Comment = db.collection({
|
|
153
|
+
name: 'comments',
|
|
154
|
+
fields: [{ type: 'belongsTo', name: 'post' }],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const belongsToField = Comment.fields.get('post');
|
|
158
|
+
expect(belongsToField).toBeDefined();
|
|
159
|
+
const association = Post.model.associations;
|
|
160
|
+
expect(association['comments']).toBeDefined();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mockDatabase } from '../';
|
|
2
|
+
import { Database } from '../../database';
|
|
3
|
+
|
|
4
|
+
describe('belongs to 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
|
+
test('association undefined', async () => {
|
|
16
|
+
const Post = db.collection({
|
|
17
|
+
name: 'posts',
|
|
18
|
+
fields: [
|
|
19
|
+
{ type: 'string', name: 'name' },
|
|
20
|
+
{ type: 'belongsToMany', name: 'tags' },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(Post.model.associations.tags).toBeUndefined();
|
|
25
|
+
expect(db.getCollection('postsTags')).toBeUndefined();
|
|
26
|
+
|
|
27
|
+
const Tag = db.collection({
|
|
28
|
+
name: 'tags',
|
|
29
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
30
|
+
});
|
|
31
|
+
expect(Post.model.associations.tags).toBeDefined();
|
|
32
|
+
const Through = db.getCollection('postsTags');
|
|
33
|
+
expect(Through).toBeDefined();
|
|
34
|
+
|
|
35
|
+
expect(Through.model.rawAttributes['postId']).toBeDefined();
|
|
36
|
+
expect(Through.model.rawAttributes['tagId']).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('redefine collection', () => {
|
|
40
|
+
const Post = db.collection({
|
|
41
|
+
name: 'posts',
|
|
42
|
+
fields: [
|
|
43
|
+
{ type: 'string', name: 'name' },
|
|
44
|
+
{ type: 'belongsToMany', name: 'tags' },
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(Post.model.associations.tags).toBeUndefined();
|
|
49
|
+
expect(db.getCollection('postsTags')).toBeUndefined();
|
|
50
|
+
|
|
51
|
+
const Tag = db.collection({
|
|
52
|
+
name: 'tags',
|
|
53
|
+
fields: [{ type: 'string', name: 'name' }],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const PostTag = db.collection({ name: 'postsTags' });
|
|
57
|
+
|
|
58
|
+
expect(PostTag.model.rawAttributes['postId']).toBeDefined();
|
|
59
|
+
expect(PostTag.model.rawAttributes['tagId']).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { mockDatabase } from '../';
|
|
3
|
+
import { Database } from '../../';
|
|
4
|
+
|
|
5
|
+
describe('context field', () => {
|
|
6
|
+
let db: Database;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
db = mockDatabase();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(async () => {
|
|
13
|
+
await db.close();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('dataType', () => {
|
|
17
|
+
it('case 1, string', async () => {
|
|
18
|
+
const Test = db.collection({
|
|
19
|
+
name: 'tests',
|
|
20
|
+
fields: [
|
|
21
|
+
{
|
|
22
|
+
type: 'context',
|
|
23
|
+
name: 'clientIp',
|
|
24
|
+
dataIndex: 'request.ip',
|
|
25
|
+
dataType: 'string',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
const attribute = Test.model.rawAttributes['clientIp'];
|
|
30
|
+
expect(attribute.type).toBeInstanceOf(DataTypes.STRING);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('case 2, integer', async () => {
|
|
34
|
+
const Test = db.collection({
|
|
35
|
+
name: 'tests',
|
|
36
|
+
fields: [
|
|
37
|
+
{
|
|
38
|
+
type: 'context',
|
|
39
|
+
name: 'userId',
|
|
40
|
+
dataIndex: 'state.currentUser.id',
|
|
41
|
+
dataType: 'integer',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
const attribute = Test.model.rawAttributes['userId'];
|
|
46
|
+
expect(attribute.type).toBeInstanceOf(DataTypes.INTEGER);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('case 3, json', async () => {
|
|
50
|
+
const Test = db.collection({
|
|
51
|
+
name: 'tests',
|
|
52
|
+
fields: [
|
|
53
|
+
{
|
|
54
|
+
type: 'context',
|
|
55
|
+
name: 'ua',
|
|
56
|
+
dataIndex: 'userAgent',
|
|
57
|
+
dataType: 'json',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
const attribute = Test.model.rawAttributes['ua'];
|
|
62
|
+
expect(attribute.type).toBeInstanceOf(DataTypes.JSON);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('create and update', () => {
|
|
67
|
+
it('case 1', async () => {
|
|
68
|
+
const Test = db.collection({
|
|
69
|
+
name: 'tests',
|
|
70
|
+
fields: [
|
|
71
|
+
{
|
|
72
|
+
type: 'context',
|
|
73
|
+
name: 'clientIp',
|
|
74
|
+
dataIndex: 'request.ip',
|
|
75
|
+
dataType: 'string',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
await db.sync();
|
|
80
|
+
const t1 = await Test.repository.create({
|
|
81
|
+
values: {},
|
|
82
|
+
context: {
|
|
83
|
+
request: {
|
|
84
|
+
ip: '11.22.33.44',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
expect(t1.get('clientIp')).toBe('11.22.33.44');
|
|
89
|
+
const [t2] = await Test.repository.update({
|
|
90
|
+
filterByTk: t1.get('id') as any,
|
|
91
|
+
values: {},
|
|
92
|
+
context: {
|
|
93
|
+
request: {
|
|
94
|
+
ip: '11.22.33.55',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
expect(t2.get('clientIp')).toBe('11.22.33.55');
|
|
99
|
+
const t3 = await Test.repository.findOne();
|
|
100
|
+
expect(t3.get('clientIp')).toBe('11.22.33.55');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('case 2, createOnly = true', async () => {
|
|
104
|
+
const Test = db.collection({
|
|
105
|
+
name: 'tests',
|
|
106
|
+
fields: [
|
|
107
|
+
{
|
|
108
|
+
type: 'context',
|
|
109
|
+
name: 'clientIp',
|
|
110
|
+
dataIndex: 'request.ip',
|
|
111
|
+
dataType: 'string',
|
|
112
|
+
createOnly: true,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
await db.sync();
|
|
117
|
+
const t1 = await Test.repository.create({
|
|
118
|
+
values: {},
|
|
119
|
+
context: {
|
|
120
|
+
request: {
|
|
121
|
+
ip: '11.22.33.44',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
expect(t1.get('clientIp')).toBe('11.22.33.44');
|
|
126
|
+
const [t2] = await Test.repository.update({
|
|
127
|
+
filterByTk: t1.get('id') as any,
|
|
128
|
+
values: {},
|
|
129
|
+
context: {
|
|
130
|
+
request: {
|
|
131
|
+
ip: '11.22.33.55',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
expect(t2.get('clientIp')).toBe('11.22.33.44');
|
|
136
|
+
const t3 = await Test.repository.findOne();
|
|
137
|
+
expect(t3.get('clientIp')).toBe('11.22.33.44');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|