@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
package/lib/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAG3C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,OAAO,KAAK,CAAC;IAChD,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,GAAE,cAAmB,OAiFjE;AAED,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,OAAO,KAAK,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,CA8BvE;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,GAAE,gBAAqB,OA+KrE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,CAEpD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,OAQxC;AAED,wBAAgB,QAAQ,CAAC,GAAG,KAAA,WAQ3B;AAMD,wBAAgB,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,UAK/B","file":"utils.d.ts","sourcesContent":["import { Utils, Sequelize, Op } from 'sequelize';\nimport Model, { ModelCtor } from './model';\nimport _ from 'lodash';\nimport op from './op';\nimport Database from './database';\n\ninterface ToWhereContext {\n model?: ModelCtor<Model> | Model | typeof Model;\n associations?: any;\n dialect?: string;\n database?: Database;\n ctx?: any;\n prefix?: any;\n}\n\nexport function toWhere(options: any, context: ToWhereContext = {}) {\n if (options === null || typeof options !== 'object') {\n return options;\n }\n if (Array.isArray(options)) {\n return options.map((item) => toWhere(item, context));\n }\n const { prefix, model, associations = {}, ctx, dialect, database } = context;\n const items = {};\n // 先处理「点号」的问题\n for (const key in options) {\n _.set(items, key, options[key]);\n }\n let values = {};\n for (const key in items) {\n const childPreifx = prefix ? `${prefix}.${key}` : key;\n if (associations[key]) {\n values['$__include'] = values['$__include'] || {}\n values['$__include'][key] = toWhere(items[key], {\n ...context,\n prefix: childPreifx,\n model: associations[key].target,\n associations: associations[key].target.associations,\n });\n }\n else if (model && model.options.scopes && model.options.scopes[key]) {\n values['$__scopes'] = values['$__scopes'] || [];\n const scope = model.options.scopes[key];\n if (typeof scope === 'function') {\n values['$__scopes'].push({ method: [key, items[key], ctx] });\n } else {\n values['$__scopes'].push(key);\n }\n }\n else {\n // TODO: to fix same op key as field name\n const opKey = op.get(key);\n let k;\n switch (typeof opKey) {\n case 'function':\n const name = model ? model.name : '';\n const result = opKey(items[key], {\n ctx,\n model,\n database,\n dialect: database.sequelize.getDialect(),\n fieldPath: name ? `${name}.${prefix}` : prefix,\n });\n if (result.constructor.name === 'Literal') {\n values['$__literals'] = values['$__literals'] || [];\n values['$__literals'].push(result);\n } else {\n Object.assign(values, result);\n }\n // console.log(result.constructor.name === 'Literal');\n continue;\n case 'undefined':\n k = key;\n break;\n default:\n k = opKey;\n break;\n }\n values[k] = toWhere(items[key], {\n ...context,\n prefix: op.has(key) ? prefix : childPreifx,\n });\n }\n }\n if (values['$__literals']) {\n const $__literals = _.cloneDeep(values['$__literals']);\n delete values['$__literals'];\n console.log(Object.keys(values));\n return {\n [Op.and]: [\n ...$__literals,\n values,\n ],\n }\n }\n return values;\n}\n\ninterface ToIncludeContext {\n model?: ModelCtor<Model> | Model | typeof Model;\n sourceAlias?: string;\n associations?: any;\n dialect?: string;\n database?: Database;\n ctx?: any\n}\n\nexport function toOrder(sort: string | string[], model: any): string[][] {\n if (sort && typeof sort === 'string') {\n sort = sort.split(',');\n }\n\n const order = [];\n\n if (Array.isArray(sort) && sort.length > 0) {\n sort.forEach(key => {\n if (Array.isArray(key)) {\n order.push(key);\n } else {\n const direction = key[0] === '-' ? 'DESC' : 'ASC';\n const keys = key.replace(/^-/, '').split('.');\n const field = keys.pop();\n const by = [];\n let associationModel = model;\n for (let i = 0; i < keys.length; i++) {\n const association = model.associations[keys[i]];\n if (association && association.target) {\n associationModel = association.target;\n by.push(associationModel);\n }\n }\n order.push([...by, field, direction]);\n }\n });\n }\n\n return order;\n}\n\nexport function toInclude(options: any, context: ToIncludeContext = {}) {\n function makeFields(key: string) {\n if (!Array.isArray(items[key])) {\n return;\n }\n items[key].forEach(field => {\n // 按点分隔转化为数组\n const [col, ...arr]: string[] = Array.isArray(field) ? Utils.cloneDeep(field) : field.split('.');\n // 内嵌的情况\n if (arr.length > 0) {\n if (!children.has(col)) {\n children.set(col, {\n fields: {\n only: [],\n except: [],\n appends: [],\n },\n });\n }\n children.get(col).fields[key].push(arr);\n return;\n }\n if (key !== 'except') {\n // 关系字段\n if (associations[col]) {\n const includeItem: any = {\n association: col,\n };\n if (includeWhere[col]) {\n includeItem.where = includeWhere[col];\n }\n include.set(col, includeItem);\n return;\n }\n // 计数字段\n const matches: Array<any> = col.match(/(.+)_count$/);\n if (matches && associations[matches[1]]) {\n attributes[key].push(model.withCountAttribute({\n association: matches[1],\n sourceAlias: sourceAlias\n }));\n return;\n }\n } else {\n if (!attributes.except) {\n attributes.except = [];\n }\n }\n attributes[key].push(col);\n });\n }\n\n const { fields = [], filter } = options;\n const { model, sourceAlias, associations = {}, ctx, database, dialect } = context;\n\n let where = options.where || {};\n\n if (filter) {\n where = toWhere(filter, {\n model,\n associations,\n ctx,\n database,\n }) || {};\n }\n\n const includeWhere = Utils.cloneDeep(where.$__include || {});\n const scopes = Utils.cloneDeep(where.$__scopes || []);\n\n delete where.$__include;\n delete where.$__scopes;\n\n const attributes = {\n only: [],\n except: [],\n appends: [],\n };\n\n const include = new Map();\n const children = new Map();\n\n const items = Array.isArray(fields) ? { only: fields } : fields;\n items.appends = items.appends || [];\n\n makeFields('only');\n makeFields('appends');\n makeFields('except');\n\n for (const whereKey in includeWhere) {\n if (children.has(whereKey)) {\n children.get(whereKey).where = includeWhere[whereKey];\n } else {\n children.set(whereKey, {\n association: whereKey,\n fields: [],\n where: includeWhere[whereKey],\n });\n }\n }\n\n for (const [key, child] of children) {\n const result = toInclude(child, {\n ...context,\n model: associations[key].target,\n sourceAlias: key,\n associations: associations[key].target.associations,\n });\n const item: any = {\n association: key,\n }\n if (result.attributes) {\n item.attributes = result.attributes;\n }\n if (result.include) {\n item.include = result.include;\n }\n if (result.where) {\n item.where = result.where;\n }\n if (result.scopes) {\n item.model = associations[key].target.scope(result.scopes);\n }\n // 解决同时有关联和关联的子级关联时,关联的 attribute 被设置为空数组的问题\n // ['user.profile.age', 'user.status', 'user', 'title', 'status']\n if (include.has(key) && Array.isArray(item.attributes) && !item.attributes.length) {\n delete item.attributes;\n }\n include.set(key, item);\n }\n\n const data: any = {};\n\n // 存在黑名单时\n if (attributes.except.length) {\n data.attributes = {\n exclude: attributes.except,\n };\n if (attributes.appends.length) {\n data.attributes.include = attributes.appends;\n }\n }\n // 存在白名单时\n else if (attributes.only.length) {\n data.attributes = [...attributes.only, ...attributes.appends];\n }\n // 只有附加字段时\n else if (attributes.appends.length) {\n data.attributes = {\n include: attributes.appends,\n };\n }\n\n if (include.size) {\n if (!data.attributes) {\n data.attributes = [];\n }\n data.include = Array.from(include.values());\n data.distinct = true;\n }\n\n if (Reflect.ownKeys(where).length) {\n data.where = where;\n }\n\n if (scopes.length) {\n data.scopes = scopes;\n }\n\n const order = toOrder(options.sort, model);\n\n if (order.length) {\n data.order = order;\n }\n\n return data;\n}\n\nexport function whereCompare(a: any, b: any): boolean {\n return _.isEqual(a, b);\n}\n\nexport function requireModule(module: any) {\n if (typeof module === 'string') {\n module = require(module);\n }\n if (typeof module !== 'object') {\n return module;\n }\n return module.__esModule ? module.default : module;\n}\n\nexport function isNumber(num) {\n if (typeof num === 'number') {\n return num - num === 0;\n }\n if (typeof num === 'string' && num.trim() !== '') {\n return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);\n }\n return false;\n};\n\nlet IDX = 36,\n HEX = ''\nwhile (IDX--) HEX += IDX.toString(36)\n\nexport function uid(len?: number) {\n let str = '',\n num = len || 11\n while (num--) str += HEX[(Math.random() * 36) | 0]\n return str\n}\n"]}
|
package/lib/utils.js
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _react() {
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
-
|
|
17
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
18
|
-
|
|
19
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
20
|
-
|
|
21
|
-
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
22
|
-
|
|
23
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
-
|
|
25
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
26
|
-
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
-
|
|
29
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
30
|
-
|
|
31
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
32
|
-
|
|
33
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
34
|
-
return mod && mod.__esModule ? mod : {
|
|
35
|
-
"default": mod
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
Object.defineProperty(exports, "__esModule", {
|
|
40
|
-
value: true
|
|
41
|
-
});
|
|
42
|
-
exports.uid = exports.isNumber = exports.requireModule = exports.whereCompare = exports.toInclude = exports.toOrder = exports.toWhere = void 0;
|
|
43
|
-
|
|
44
|
-
const sequelize_1 = require("sequelize");
|
|
45
|
-
|
|
46
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
47
|
-
|
|
48
|
-
const op_1 = __importDefault(require("./op"));
|
|
49
|
-
|
|
50
|
-
function toWhere(options, context = {}) {
|
|
51
|
-
if (options === null || typeof options !== 'object') {
|
|
52
|
-
return options;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (Array.isArray(options)) {
|
|
56
|
-
return options.map(item => toWhere(item, context));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const prefix = context.prefix,
|
|
60
|
-
model = context.model,
|
|
61
|
-
_context$associations = context.associations,
|
|
62
|
-
associations = _context$associations === void 0 ? {} : _context$associations,
|
|
63
|
-
ctx = context.ctx,
|
|
64
|
-
dialect = context.dialect,
|
|
65
|
-
database = context.database;
|
|
66
|
-
const items = {};
|
|
67
|
-
|
|
68
|
-
for (const key in options) {
|
|
69
|
-
lodash_1.default.set(items, key, options[key]);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let values = {};
|
|
73
|
-
|
|
74
|
-
for (const key in items) {
|
|
75
|
-
const childPreifx = prefix ? `${prefix}.${key}` : key;
|
|
76
|
-
|
|
77
|
-
if (associations[key]) {
|
|
78
|
-
values['$__include'] = values['$__include'] || {};
|
|
79
|
-
values['$__include'][key] = toWhere(items[key], Object.assign(Object.assign({}, context), {
|
|
80
|
-
prefix: childPreifx,
|
|
81
|
-
model: associations[key].target,
|
|
82
|
-
associations: associations[key].target.associations
|
|
83
|
-
}));
|
|
84
|
-
} else if (model && model.options.scopes && model.options.scopes[key]) {
|
|
85
|
-
values['$__scopes'] = values['$__scopes'] || [];
|
|
86
|
-
const scope = model.options.scopes[key];
|
|
87
|
-
|
|
88
|
-
if (typeof scope === 'function') {
|
|
89
|
-
values['$__scopes'].push({
|
|
90
|
-
method: [key, items[key], ctx]
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
values['$__scopes'].push(key);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
const opKey = op_1.default.get(key);
|
|
97
|
-
let k;
|
|
98
|
-
|
|
99
|
-
switch (typeof opKey) {
|
|
100
|
-
case 'function':
|
|
101
|
-
const name = model ? model.name : '';
|
|
102
|
-
const result = opKey(items[key], {
|
|
103
|
-
ctx,
|
|
104
|
-
model,
|
|
105
|
-
database,
|
|
106
|
-
dialect: database.sequelize.getDialect(),
|
|
107
|
-
fieldPath: name ? `${name}.${prefix}` : prefix
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
if (result.constructor.name === 'Literal') {
|
|
111
|
-
values['$__literals'] = values['$__literals'] || [];
|
|
112
|
-
values['$__literals'].push(result);
|
|
113
|
-
} else {
|
|
114
|
-
Object.assign(values, result);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
continue;
|
|
118
|
-
|
|
119
|
-
case 'undefined':
|
|
120
|
-
k = key;
|
|
121
|
-
break;
|
|
122
|
-
|
|
123
|
-
default:
|
|
124
|
-
k = opKey;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
values[k] = toWhere(items[key], Object.assign(Object.assign({}, context), {
|
|
129
|
-
prefix: op_1.default.has(key) ? prefix : childPreifx
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (values['$__literals']) {
|
|
135
|
-
const $__literals = lodash_1.default.cloneDeep(values['$__literals']);
|
|
136
|
-
delete values['$__literals'];
|
|
137
|
-
console.log(Object.keys(values));
|
|
138
|
-
return {
|
|
139
|
-
[sequelize_1.Op.and]: [...$__literals, values]
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return values;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
exports.toWhere = toWhere;
|
|
147
|
-
|
|
148
|
-
function toOrder(sort, model) {
|
|
149
|
-
if (sort && typeof sort === 'string') {
|
|
150
|
-
sort = sort.split(',');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const order = [];
|
|
154
|
-
|
|
155
|
-
if (Array.isArray(sort) && sort.length > 0) {
|
|
156
|
-
sort.forEach(key => {
|
|
157
|
-
if (Array.isArray(key)) {
|
|
158
|
-
order.push(key);
|
|
159
|
-
} else {
|
|
160
|
-
const direction = key[0] === '-' ? 'DESC' : 'ASC';
|
|
161
|
-
const keys = key.replace(/^-/, '').split('.');
|
|
162
|
-
const field = keys.pop();
|
|
163
|
-
const by = [];
|
|
164
|
-
let associationModel = model;
|
|
165
|
-
|
|
166
|
-
for (let i = 0; i < keys.length; i++) {
|
|
167
|
-
const association = model.associations[keys[i]];
|
|
168
|
-
|
|
169
|
-
if (association && association.target) {
|
|
170
|
-
associationModel = association.target;
|
|
171
|
-
by.push(associationModel);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
order.push([...by, field, direction]);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return order;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
exports.toOrder = toOrder;
|
|
184
|
-
|
|
185
|
-
function toInclude(options, context = {}) {
|
|
186
|
-
function makeFields(key) {
|
|
187
|
-
if (!Array.isArray(items[key])) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
items[key].forEach(field => {
|
|
192
|
-
const _ref = Array.isArray(field) ? sequelize_1.Utils.cloneDeep(field) : field.split('.'),
|
|
193
|
-
_ref2 = _toArray(_ref),
|
|
194
|
-
col = _ref2[0],
|
|
195
|
-
arr = _ref2.slice(1);
|
|
196
|
-
|
|
197
|
-
if (arr.length > 0) {
|
|
198
|
-
if (!children.has(col)) {
|
|
199
|
-
children.set(col, {
|
|
200
|
-
fields: {
|
|
201
|
-
only: [],
|
|
202
|
-
except: [],
|
|
203
|
-
appends: []
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
children.get(col).fields[key].push(arr);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (key !== 'except') {
|
|
213
|
-
if (associations[col]) {
|
|
214
|
-
const includeItem = {
|
|
215
|
-
association: col
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
if (includeWhere[col]) {
|
|
219
|
-
includeItem.where = includeWhere[col];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
include.set(col, includeItem);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const matches = col.match(/(.+)_count$/);
|
|
227
|
-
|
|
228
|
-
if (matches && associations[matches[1]]) {
|
|
229
|
-
attributes[key].push(model.withCountAttribute({
|
|
230
|
-
association: matches[1],
|
|
231
|
-
sourceAlias: sourceAlias
|
|
232
|
-
}));
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
if (!attributes.except) {
|
|
237
|
-
attributes.except = [];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
attributes[key].push(col);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const _options$fields = options.fields,
|
|
246
|
-
fields = _options$fields === void 0 ? [] : _options$fields,
|
|
247
|
-
filter = options.filter;
|
|
248
|
-
const model = context.model,
|
|
249
|
-
sourceAlias = context.sourceAlias,
|
|
250
|
-
_context$associations2 = context.associations,
|
|
251
|
-
associations = _context$associations2 === void 0 ? {} : _context$associations2,
|
|
252
|
-
ctx = context.ctx,
|
|
253
|
-
database = context.database,
|
|
254
|
-
dialect = context.dialect;
|
|
255
|
-
let where = options.where || {};
|
|
256
|
-
|
|
257
|
-
if (filter) {
|
|
258
|
-
where = toWhere(filter, {
|
|
259
|
-
model,
|
|
260
|
-
associations,
|
|
261
|
-
ctx,
|
|
262
|
-
database
|
|
263
|
-
}) || {};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const includeWhere = sequelize_1.Utils.cloneDeep(where.$__include || {});
|
|
267
|
-
const scopes = sequelize_1.Utils.cloneDeep(where.$__scopes || []);
|
|
268
|
-
delete where.$__include;
|
|
269
|
-
delete where.$__scopes;
|
|
270
|
-
const attributes = {
|
|
271
|
-
only: [],
|
|
272
|
-
except: [],
|
|
273
|
-
appends: []
|
|
274
|
-
};
|
|
275
|
-
const include = new Map();
|
|
276
|
-
const children = new Map();
|
|
277
|
-
const items = Array.isArray(fields) ? {
|
|
278
|
-
only: fields
|
|
279
|
-
} : fields;
|
|
280
|
-
items.appends = items.appends || [];
|
|
281
|
-
makeFields('only');
|
|
282
|
-
makeFields('appends');
|
|
283
|
-
makeFields('except');
|
|
284
|
-
|
|
285
|
-
for (const whereKey in includeWhere) {
|
|
286
|
-
if (children.has(whereKey)) {
|
|
287
|
-
children.get(whereKey).where = includeWhere[whereKey];
|
|
288
|
-
} else {
|
|
289
|
-
children.set(whereKey, {
|
|
290
|
-
association: whereKey,
|
|
291
|
-
fields: [],
|
|
292
|
-
where: includeWhere[whereKey]
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
var _iterator = _createForOfIteratorHelper(children),
|
|
298
|
-
_step;
|
|
299
|
-
|
|
300
|
-
try {
|
|
301
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
302
|
-
const _step$value = _slicedToArray(_step.value, 2),
|
|
303
|
-
key = _step$value[0],
|
|
304
|
-
child = _step$value[1];
|
|
305
|
-
|
|
306
|
-
const result = toInclude(child, Object.assign(Object.assign({}, context), {
|
|
307
|
-
model: associations[key].target,
|
|
308
|
-
sourceAlias: key,
|
|
309
|
-
associations: associations[key].target.associations
|
|
310
|
-
}));
|
|
311
|
-
const item = {
|
|
312
|
-
association: key
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
if (result.attributes) {
|
|
316
|
-
item.attributes = result.attributes;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (result.include) {
|
|
320
|
-
item.include = result.include;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (result.where) {
|
|
324
|
-
item.where = result.where;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (result.scopes) {
|
|
328
|
-
item.model = associations[key].target.scope(result.scopes);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (include.has(key) && Array.isArray(item.attributes) && !item.attributes.length) {
|
|
332
|
-
delete item.attributes;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
include.set(key, item);
|
|
336
|
-
}
|
|
337
|
-
} catch (err) {
|
|
338
|
-
_iterator.e(err);
|
|
339
|
-
} finally {
|
|
340
|
-
_iterator.f();
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const data = {};
|
|
344
|
-
|
|
345
|
-
if (attributes.except.length) {
|
|
346
|
-
data.attributes = {
|
|
347
|
-
exclude: attributes.except
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
if (attributes.appends.length) {
|
|
351
|
-
data.attributes.include = attributes.appends;
|
|
352
|
-
}
|
|
353
|
-
} else if (attributes.only.length) {
|
|
354
|
-
data.attributes = [...attributes.only, ...attributes.appends];
|
|
355
|
-
} else if (attributes.appends.length) {
|
|
356
|
-
data.attributes = {
|
|
357
|
-
include: attributes.appends
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (include.size) {
|
|
362
|
-
if (!data.attributes) {
|
|
363
|
-
data.attributes = [];
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
data.include = Array.from(include.values());
|
|
367
|
-
data.distinct = true;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (Reflect.ownKeys(where).length) {
|
|
371
|
-
data.where = where;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (scopes.length) {
|
|
375
|
-
data.scopes = scopes;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const order = toOrder(options.sort, model);
|
|
379
|
-
|
|
380
|
-
if (order.length) {
|
|
381
|
-
data.order = order;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return data;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
exports.toInclude = toInclude;
|
|
388
|
-
|
|
389
|
-
function whereCompare(a, b) {
|
|
390
|
-
return lodash_1.default.isEqual(a, b);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
exports.whereCompare = whereCompare;
|
|
394
|
-
|
|
395
|
-
function requireModule(module) {
|
|
396
|
-
if (typeof module === 'string') {
|
|
397
|
-
module = require(module);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (typeof module !== 'object') {
|
|
401
|
-
return module;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
return module.__esModule ? module.default : module;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
exports.requireModule = requireModule;
|
|
408
|
-
|
|
409
|
-
function isNumber(num) {
|
|
410
|
-
if (typeof num === 'number') {
|
|
411
|
-
return num - num === 0;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (typeof num === 'string' && num.trim() !== '') {
|
|
415
|
-
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return false;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
exports.isNumber = isNumber;
|
|
422
|
-
;
|
|
423
|
-
let IDX = 36,
|
|
424
|
-
HEX = '';
|
|
425
|
-
|
|
426
|
-
while (IDX--) HEX += IDX.toString(36);
|
|
427
|
-
|
|
428
|
-
function uid(len) {
|
|
429
|
-
let str = '',
|
|
430
|
-
num = len || 11;
|
|
431
|
-
|
|
432
|
-
while (num--) str += HEX[Math.random() * 36 | 0];
|
|
433
|
-
|
|
434
|
-
return str;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
exports.uid = uid;
|
|
438
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAiD;AAEjD,oDAAuB;AACvB,8CAAsB;AAYtB,SAAgB,OAAO,CAAC,OAAY,EAAE,UAA0B,EAAE;IAChE,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QACnD,OAAO,OAAO,CAAC;KAChB;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;KACtD;IACD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7E,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,gBAAC,CAAC,GAAG,CA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Q,EAAE;QAC9B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;KAC1B;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,MAAM,CAAC;KACf;IACD,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AACrD,CAAC;AARD,sCAQC;AAED,SAAgB,QAAQ,CAAC,GAAG;IAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC;KACxB;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;KACjE;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AARD,4BAQC;AAAA,CAAC;AAEF,IAAI,GAAG,GAAG,EAAE,EACV,GAAG,GAAG,EAAE,CAAA;AACV,OAAO,GAAG,EAAE;IAAE,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AAErC,SAAgB,GAAG,CAAC,GAAY;IAC9B,IAAI,GAAG,GAAG,EAAE,EACV,GAAG,GAAG,GAAG,IAAI,EAAE,CAAA;IACjB,OAAO,GAAG,EAAE;QAAE,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAClD,OAAO,GAAG,CAAA;AACZ,CAAC;AALD,kBAKC","file":"utils.js","sourcesContent":["import { Utils, Sequelize, Op } from 'sequelize';\nimport Model, { ModelCtor } from './model';\nimport _ from 'lodash';\nimport op from './op';\nimport Database from './database';\n\ninterface ToWhereContext {\n model?: ModelCtor<Model> | Model | typeof Model;\n associations?: any;\n dialect?: string;\n database?: Database;\n ctx?: any;\n prefix?: any;\n}\n\nexport function toWhere(options: any, context: ToWhereContext = {}) {\n if (options === null || typeof options !== 'object') {\n return options;\n }\n if (Array.isArray(options)) {\n return options.map((item) => toWhere(item, context));\n }\n const { prefix, model, associations = {}, ctx, dialect, database } = context;\n const items = {};\n // 先处理「点号」的问题\n for (const key in options) {\n _.set(items, key, options[key]);\n }\n let values = {};\n for (const key in items) {\n const childPreifx = prefix ? `${prefix}.${key}` : key;\n if (associations[key]) {\n values['$__include'] = values['$__include'] || {}\n values['$__include'][key] = toWhere(items[key], {\n ...context,\n prefix: childPreifx,\n model: associations[key].target,\n associations: associations[key].target.associations,\n });\n }\n else if (model && model.options.scopes && model.options.scopes[key]) {\n values['$__scopes'] = values['$__scopes'] || [];\n const scope = model.options.scopes[key];\n if (typeof scope === 'function') {\n values['$__scopes'].push({ method: [key, items[key], ctx] });\n } else {\n values['$__scopes'].push(key);\n }\n }\n else {\n // TODO: to fix same op key as field name\n const opKey = op.get(key);\n let k;\n switch (typeof opKey) {\n case 'function':\n const name = model ? model.name : '';\n const result = opKey(items[key], {\n ctx,\n model,\n database,\n dialect: database.sequelize.getDialect(),\n fieldPath: name ? `${name}.${prefix}` : prefix,\n });\n if (result.constructor.name === 'Literal') {\n values['$__literals'] = values['$__literals'] || [];\n values['$__literals'].push(result);\n } else {\n Object.assign(values, result);\n }\n // console.log(result.constructor.name === 'Literal');\n continue;\n case 'undefined':\n k = key;\n break;\n default:\n k = opKey;\n break;\n }\n values[k] = toWhere(items[key], {\n ...context,\n prefix: op.has(key) ? prefix : childPreifx,\n });\n }\n }\n if (values['$__literals']) {\n const $__literals = _.cloneDeep(values['$__literals']);\n delete values['$__literals'];\n console.log(Object.keys(values));\n return {\n [Op.and]: [\n ...$__literals,\n values,\n ],\n }\n }\n return values;\n}\n\ninterface ToIncludeContext {\n model?: ModelCtor<Model> | Model | typeof Model;\n sourceAlias?: string;\n associations?: any;\n dialect?: string;\n database?: Database;\n ctx?: any\n}\n\nexport function toOrder(sort: string | string[], model: any): string[][] {\n if (sort && typeof sort === 'string') {\n sort = sort.split(',');\n }\n\n const order = [];\n\n if (Array.isArray(sort) && sort.length > 0) {\n sort.forEach(key => {\n if (Array.isArray(key)) {\n order.push(key);\n } else {\n const direction = key[0] === '-' ? 'DESC' : 'ASC';\n const keys = key.replace(/^-/, '').split('.');\n const field = keys.pop();\n const by = [];\n let associationModel = model;\n for (let i = 0; i < keys.length; i++) {\n const association = model.associations[keys[i]];\n if (association && association.target) {\n associationModel = association.target;\n by.push(associationModel);\n }\n }\n order.push([...by, field, direction]);\n }\n });\n }\n\n return order;\n}\n\nexport function toInclude(options: any, context: ToIncludeContext = {}) {\n function makeFields(key: string) {\n if (!Array.isArray(items[key])) {\n return;\n }\n items[key].forEach(field => {\n // 按点分隔转化为数组\n const [col, ...arr]: string[] = Array.isArray(field) ? Utils.cloneDeep(field) : field.split('.');\n // 内嵌的情况\n if (arr.length > 0) {\n if (!children.has(col)) {\n children.set(col, {\n fields: {\n only: [],\n except: [],\n appends: [],\n },\n });\n }\n children.get(col).fields[key].push(arr);\n return;\n }\n if (key !== 'except') {\n // 关系字段\n if (associations[col]) {\n const includeItem: any = {\n association: col,\n };\n if (includeWhere[col]) {\n includeItem.where = includeWhere[col];\n }\n include.set(col, includeItem);\n return;\n }\n // 计数字段\n const matches: Array<any> = col.match(/(.+)_count$/);\n if (matches && associations[matches[1]]) {\n attributes[key].push(model.withCountAttribute({\n association: matches[1],\n sourceAlias: sourceAlias\n }));\n return;\n }\n } else {\n if (!attributes.except) {\n attributes.except = [];\n }\n }\n attributes[key].push(col);\n });\n }\n\n const { fields = [], filter } = options;\n const { model, sourceAlias, associations = {}, ctx, database, dialect } = context;\n\n let where = options.where || {};\n\n if (filter) {\n where = toWhere(filter, {\n model,\n associations,\n ctx,\n database,\n }) || {};\n }\n\n const includeWhere = Utils.cloneDeep(where.$__include || {});\n const scopes = Utils.cloneDeep(where.$__scopes || []);\n\n delete where.$__include;\n delete where.$__scopes;\n\n const attributes = {\n only: [],\n except: [],\n appends: [],\n };\n\n const include = new Map();\n const children = new Map();\n\n const items = Array.isArray(fields) ? { only: fields } : fields;\n items.appends = items.appends || [];\n\n makeFields('only');\n makeFields('appends');\n makeFields('except');\n\n for (const whereKey in includeWhere) {\n if (children.has(whereKey)) {\n children.get(whereKey).where = includeWhere[whereKey];\n } else {\n children.set(whereKey, {\n association: whereKey,\n fields: [],\n where: includeWhere[whereKey],\n });\n }\n }\n\n for (const [key, child] of children) {\n const result = toInclude(child, {\n ...context,\n model: associations[key].target,\n sourceAlias: key,\n associations: associations[key].target.associations,\n });\n const item: any = {\n association: key,\n }\n if (result.attributes) {\n item.attributes = result.attributes;\n }\n if (result.include) {\n item.include = result.include;\n }\n if (result.where) {\n item.where = result.where;\n }\n if (result.scopes) {\n item.model = associations[key].target.scope(result.scopes);\n }\n // 解决同时有关联和关联的子级关联时,关联的 attribute 被设置为空数组的问题\n // ['user.profile.age', 'user.status', 'user', 'title', 'status']\n if (include.has(key) && Array.isArray(item.attributes) && !item.attributes.length) {\n delete item.attributes;\n }\n include.set(key, item);\n }\n\n const data: any = {};\n\n // 存在黑名单时\n if (attributes.except.length) {\n data.attributes = {\n exclude: attributes.except,\n };\n if (attributes.appends.length) {\n data.attributes.include = attributes.appends;\n }\n }\n // 存在白名单时\n else if (attributes.only.length) {\n data.attributes = [...attributes.only, ...attributes.appends];\n }\n // 只有附加字段时\n else if (attributes.appends.length) {\n data.attributes = {\n include: attributes.appends,\n };\n }\n\n if (include.size) {\n if (!data.attributes) {\n data.attributes = [];\n }\n data.include = Array.from(include.values());\n data.distinct = true;\n }\n\n if (Reflect.ownKeys(where).length) {\n data.where = where;\n }\n\n if (scopes.length) {\n data.scopes = scopes;\n }\n\n const order = toOrder(options.sort, model);\n\n if (order.length) {\n data.order = order;\n }\n\n return data;\n}\n\nexport function whereCompare(a: any, b: any): boolean {\n return _.isEqual(a, b);\n}\n\nexport function requireModule(module: any) {\n if (typeof module === 'string') {\n module = require(module);\n }\n if (typeof module !== 'object') {\n return module;\n }\n return module.__esModule ? module.default : module;\n}\n\nexport function isNumber(num) {\n if (typeof num === 'number') {\n return num - num === 0;\n }\n if (typeof num === 'string' && num.trim() !== '') {\n return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);\n }\n return false;\n};\n\nlet IDX = 36,\n HEX = ''\nwhile (IDX--) HEX += IDX.toString(36)\n\nexport function uid(len?: number) {\n let str = '',\n num = len || 11\n while (num--) str += HEX[(Math.random() * 36) | 0]\n return str\n}\n"]}
|