@nocobase/database 0.7.0-alpha.6 → 0.7.0-alpha.62
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/lib/collection-importer.js +101 -67
- package/lib/collection.js +339 -210
- package/lib/database.d.ts +4 -1
- package/lib/database.js +489 -275
- package/lib/fields/array-field.js +45 -25
- package/lib/fields/belongs-to-field.js +101 -54
- package/lib/fields/belongs-to-many-field.js +98 -53
- package/lib/fields/boolean-field.js +24 -9
- package/lib/fields/context-field.js +77 -42
- package/lib/fields/date-field.js +24 -9
- package/lib/fields/field.js +114 -75
- package/lib/fields/has-inverse-field.js +4 -2
- package/lib/fields/has-many-field.js +105 -56
- package/lib/fields/has-one-field.js +105 -54
- package/lib/fields/index.d.ts +3 -1
- package/lib/fields/index.js +277 -32
- package/lib/fields/json-field.js +36 -16
- package/lib/fields/number-field.js +53 -26
- package/lib/fields/password-field.js +118 -73
- package/lib/fields/radio-field.js +75 -47
- package/lib/fields/relation-field.js +41 -28
- package/lib/fields/sort-field.js +165 -89
- package/lib/fields/string-field.js +24 -9
- package/lib/fields/text-field.js +24 -9
- package/lib/fields/time-field.js +24 -9
- package/lib/fields/uid-field.js +57 -28
- package/lib/fields/uuid-field.d.ts +9 -0
- package/lib/fields/uuid-field.js +39 -0
- package/lib/fields/virtual-field.js +24 -9
- package/lib/filter-parser.js +288 -179
- package/lib/index.js +210 -29
- package/lib/magic-attribute-model.js +123 -71
- package/lib/mock-database.js +68 -34
- package/lib/model-hook.js +101 -60
- package/lib/model.js +116 -81
- package/lib/operators/array.js +136 -96
- package/lib/operators/association.js +30 -14
- package/lib/operators/boolean.d.ts +13 -0
- package/lib/operators/boolean.js +35 -0
- package/lib/operators/date.js +78 -34
- package/lib/operators/empty.js +113 -75
- package/lib/operators/index.js +15 -3
- package/lib/operators/ne.js +27 -12
- package/{esm/operators/ne.d.ts → lib/operators/notIn.d.ts} +2 -2
- package/lib/operators/notIn.js +29 -0
- package/lib/operators/string.js +56 -35
- package/lib/operators/utils.js +18 -10
- package/lib/options-parser.js +323 -215
- package/lib/playground.js +66 -53
- package/lib/relation-repository/belongs-to-many-repository.js +281 -198
- package/lib/relation-repository/belongs-to-repository.js +10 -6
- package/lib/relation-repository/hasmany-repository.js +168 -121
- package/lib/relation-repository/hasone-repository.js +10 -6
- package/lib/relation-repository/multiple-relation-repository.d.ts +3 -3
- package/lib/relation-repository/multiple-relation-repository.js +263 -148
- package/lib/relation-repository/relation-repository.d.ts +1 -1
- package/lib/relation-repository/relation-repository.js +155 -95
- package/lib/relation-repository/single-relation-repository.d.ts +6 -6
- package/lib/relation-repository/single-relation-repository.js +138 -99
- package/lib/relation-repository/types.js +4 -2
- package/lib/repository.d.ts +4 -7
- package/lib/repository.js +465 -291
- package/lib/transaction-decorator.js +80 -67
- package/lib/update-associations.d.ts +1 -2
- package/lib/update-associations.js +525 -321
- package/lib/update-guard.js +160 -117
- package/package.json +3 -8
- package/src/__tests__/fields/uuid-field.test.ts +30 -0
- package/src/__tests__/operator/notIn.test.ts +33 -0
- package/src/__tests__/option-parser.test.ts +20 -0
- package/src/database.ts +51 -4
- package/src/fields/context-field.ts +1 -1
- package/src/fields/index.ts +3 -0
- package/src/fields/uuid-field.ts +21 -0
- package/src/mock-database.ts +1 -1
- package/src/model-hook.ts +1 -1
- package/src/operators/boolean.ts +18 -0
- package/src/operators/index.ts +2 -0
- package/src/operators/notIn.ts +12 -0
- package/src/options-parser.ts +1 -1
- package/src/relation-repository/multiple-relation-repository.ts +8 -6
- package/src/relation-repository/relation-repository.ts +11 -6
- package/src/relation-repository/single-relation-repository.ts +6 -6
- package/src/repository.ts +4 -6
- package/src/update-associations.ts +1 -2
- package/esm/collection-importer.d.ts +0 -7
- package/esm/collection-importer.js +0 -49
- package/esm/collection-importer.js.map +0 -1
- package/esm/collection.d.ts +0 -73
- package/esm/collection.js +0 -224
- package/esm/collection.js.map +0 -1
- package/esm/database.d.ts +0 -101
- package/esm/database.js +0 -275
- package/esm/database.js.map +0 -1
- package/esm/fields/array-field.d.ts +0 -11
- package/esm/fields/array-field.js +0 -26
- package/esm/fields/array-field.js.map +0 -1
- package/esm/fields/belongs-to-field.d.ts +0 -12
- package/esm/fields/belongs-to-field.js +0 -57
- package/esm/fields/belongs-to-field.js.map +0 -1
- package/esm/fields/belongs-to-many-field.d.ts +0 -11
- package/esm/fields/belongs-to-many-field.js +0 -55
- package/esm/fields/belongs-to-many-field.js.map +0 -1
- package/esm/fields/boolean-field.d.ts +0 -8
- package/esm/fields/boolean-field.js +0 -8
- package/esm/fields/boolean-field.js.map +0 -1
- package/esm/fields/context-field.d.ts +0 -13
- package/esm/fields/context-field.js +0 -43
- package/esm/fields/context-field.js.map +0 -1
- package/esm/fields/date-field.d.ts +0 -8
- package/esm/fields/date-field.js +0 -8
- package/esm/fields/date-field.js.map +0 -1
- package/esm/fields/field.d.ts +0 -37
- package/esm/fields/field.js +0 -74
- package/esm/fields/field.js.map +0 -1
- package/esm/fields/has-inverse-field.d.ts +0 -4
- package/esm/fields/has-inverse-field.js +0 -2
- package/esm/fields/has-inverse-field.js.map +0 -1
- package/esm/fields/has-many-field.d.ts +0 -64
- package/esm/fields/has-many-field.js +0 -58
- package/esm/fields/has-many-field.js.map +0 -1
- package/esm/fields/has-one-field.d.ts +0 -64
- package/esm/fields/has-one-field.js +0 -57
- package/esm/fields/has-one-field.js.map +0 -1
- package/esm/fields/index.d.ts +0 -40
- package/esm/fields/index.js +0 -21
- package/esm/fields/index.js.map +0 -1
- package/esm/fields/json-field.d.ts +0 -14
- package/esm/fields/json-field.js +0 -17
- package/esm/fields/json-field.js.map +0 -1
- package/esm/fields/number-field.d.ts +0 -32
- package/esm/fields/number-field.js +0 -28
- package/esm/fields/number-field.js.map +0 -1
- package/esm/fields/password-field.d.ts +0 -21
- package/esm/fields/password-field.js +0 -71
- package/esm/fields/password-field.js.map +0 -1
- package/esm/fields/radio-field.d.ts +0 -14
- package/esm/fields/radio-field.js +0 -49
- package/esm/fields/radio-field.js.map +0 -1
- package/esm/fields/relation-field.d.ts +0 -20
- package/esm/fields/relation-field.js +0 -27
- package/esm/fields/relation-field.js.map +0 -1
- package/esm/fields/sort-field.d.ts +0 -16
- package/esm/fields/sort-field.js +0 -90
- package/esm/fields/sort-field.js.map +0 -1
- package/esm/fields/string-field.d.ts +0 -8
- package/esm/fields/string-field.js +0 -8
- package/esm/fields/string-field.js.map +0 -1
- package/esm/fields/text-field.d.ts +0 -8
- package/esm/fields/text-field.js +0 -8
- package/esm/fields/text-field.js.map +0 -1
- package/esm/fields/time-field.d.ts +0 -8
- package/esm/fields/time-field.js +0 -8
- package/esm/fields/time-field.js.map +0 -1
- package/esm/fields/uid-field.d.ts +0 -10
- package/esm/fields/uid-field.js +0 -27
- package/esm/fields/uid-field.js.map +0 -1
- package/esm/fields/virtual-field.d.ts +0 -8
- package/esm/fields/virtual-field.js +0 -8
- package/esm/fields/virtual-field.js.map +0 -1
- package/esm/filter-parser.d.ts +0 -27
- package/esm/filter-parser.js +0 -185
- package/esm/filter-parser.js.map +0 -1
- package/esm/index.d.ts +0 -15
- package/esm/index.js +0 -16
- package/esm/index.js.map +0 -1
- package/esm/magic-attribute-model.d.ts +0 -7
- package/esm/magic-attribute-model.js +0 -70
- package/esm/magic-attribute-model.js.map +0 -1
- package/esm/mock-database.d.ts +0 -22
- package/esm/mock-database.js +0 -34
- package/esm/mock-database.js.map +0 -1
- package/esm/model-hook.d.ts +0 -12
- package/esm/model-hook.js +0 -61
- package/esm/model-hook.js.map +0 -1
- package/esm/model.d.ts +0 -15
- package/esm/model.js +0 -80
- package/esm/model.js.map +0 -1
- package/esm/operators/array.d.ts +0 -26
- package/esm/operators/array.js +0 -105
- package/esm/operators/array.js.map +0 -1
- package/esm/operators/association.d.ts +0 -10
- package/esm/operators/association.js +0 -14
- package/esm/operators/association.js.map +0 -1
- package/esm/operators/date.d.ts +0 -34
- package/esm/operators/date.js +0 -35
- package/esm/operators/date.js.map +0 -1
- package/esm/operators/empty.d.ts +0 -28
- package/esm/operators/empty.js +0 -58
- package/esm/operators/empty.js.map +0 -1
- package/esm/operators/index.d.ts +0 -2
- package/esm/operators/index.js +0 -2
- package/esm/operators/index.js.map +0 -1
- package/esm/operators/ne.js +0 -12
- package/esm/operators/ne.js.map +0 -1
- package/esm/operators/string.d.ts +0 -21
- package/esm/operators/string.js +0 -35
- package/esm/operators/string.js.map +0 -1
- package/esm/operators/utils.d.ts +0 -4
- package/esm/operators/utils.js +0 -11
- package/esm/operators/utils.js.map +0 -1
- package/esm/options-parser.d.ts +0 -31
- package/esm/options-parser.js +0 -225
- package/esm/options-parser.js.map +0 -1
- package/esm/playground.d.ts +0 -1
- package/esm/playground.js +0 -53
- package/esm/playground.js.map +0 -1
- package/esm/relation-repository/belongs-to-many-repository.d.ts +0 -36
- package/esm/relation-repository/belongs-to-many-repository.js +0 -199
- package/esm/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/esm/relation-repository/belongs-to-repository.d.ts +0 -17
- package/esm/relation-repository/belongs-to-repository.js +0 -4
- package/esm/relation-repository/belongs-to-repository.js.map +0 -1
- package/esm/relation-repository/hasmany-repository.d.ts +0 -23
- package/esm/relation-repository/hasmany-repository.js +0 -125
- package/esm/relation-repository/hasmany-repository.js.map +0 -1
- package/esm/relation-repository/hasone-repository.d.ts +0 -17
- package/esm/relation-repository/hasone-repository.js +0 -4
- package/esm/relation-repository/hasone-repository.js.map +0 -1
- package/esm/relation-repository/multiple-relation-repository.d.ts +0 -23
- package/esm/relation-repository/multiple-relation-repository.js +0 -149
- package/esm/relation-repository/multiple-relation-repository.js.map +0 -1
- package/esm/relation-repository/relation-repository.d.ts +0 -32
- package/esm/relation-repository/relation-repository.js +0 -93
- package/esm/relation-repository/relation-repository.js.map +0 -1
- package/esm/relation-repository/single-relation-repository.d.ts +0 -23
- package/esm/relation-repository/single-relation-repository.js +0 -96
- package/esm/relation-repository/single-relation-repository.js.map +0 -1
- package/esm/relation-repository/types.d.ts +0 -7
- package/esm/relation-repository/types.js +0 -2
- package/esm/relation-repository/types.js.map +0 -1
- package/esm/repository.d.ts +0 -165
- package/esm/repository.js +0 -276
- package/esm/repository.js.map +0 -1
- package/esm/transaction-decorator.d.ts +0 -1
- package/esm/transaction-decorator.js +0 -63
- package/esm/transaction-decorator.js.map +0 -1
- package/esm/update-associations.d.ts +0 -60
- package/esm/update-associations.js +0 -362
- package/esm/update-associations.js.map +0 -1
- package/esm/update-guard.d.ts +0 -26
- package/esm/update-guard.js +0 -122
- package/esm/update-guard.js.map +0 -1
- package/lib/collection-importer.js.map +0 -1
- package/lib/collection.js.map +0 -1
- package/lib/database.js.map +0 -1
- package/lib/fields/array-field.js.map +0 -1
- package/lib/fields/belongs-to-field.js.map +0 -1
- package/lib/fields/belongs-to-many-field.js.map +0 -1
- package/lib/fields/boolean-field.js.map +0 -1
- package/lib/fields/context-field.js.map +0 -1
- package/lib/fields/date-field.js.map +0 -1
- package/lib/fields/field.js.map +0 -1
- package/lib/fields/has-inverse-field.js.map +0 -1
- package/lib/fields/has-many-field.js.map +0 -1
- package/lib/fields/has-one-field.js.map +0 -1
- package/lib/fields/index.js.map +0 -1
- package/lib/fields/json-field.js.map +0 -1
- package/lib/fields/number-field.js.map +0 -1
- package/lib/fields/password-field.js.map +0 -1
- package/lib/fields/radio-field.js.map +0 -1
- package/lib/fields/relation-field.js.map +0 -1
- package/lib/fields/sort-field.js.map +0 -1
- package/lib/fields/string-field.js.map +0 -1
- package/lib/fields/text-field.js.map +0 -1
- package/lib/fields/time-field.js.map +0 -1
- package/lib/fields/uid-field.js.map +0 -1
- package/lib/fields/virtual-field.js.map +0 -1
- package/lib/filter-parser.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/magic-attribute-model.js.map +0 -1
- package/lib/mock-database.js.map +0 -1
- package/lib/model-hook.js.map +0 -1
- package/lib/model.js.map +0 -1
- package/lib/operators/array.js.map +0 -1
- package/lib/operators/association.js.map +0 -1
- package/lib/operators/date.js.map +0 -1
- package/lib/operators/empty.js.map +0 -1
- package/lib/operators/index.js.map +0 -1
- package/lib/operators/ne.js.map +0 -1
- package/lib/operators/string.js.map +0 -1
- package/lib/operators/utils.js.map +0 -1
- package/lib/options-parser.js.map +0 -1
- package/lib/playground.js.map +0 -1
- package/lib/relation-repository/belongs-to-many-repository.js.map +0 -1
- package/lib/relation-repository/belongs-to-repository.js.map +0 -1
- package/lib/relation-repository/hasmany-repository.js.map +0 -1
- package/lib/relation-repository/hasone-repository.js.map +0 -1
- package/lib/relation-repository/multiple-relation-repository.js.map +0 -1
- package/lib/relation-repository/relation-repository.js.map +0 -1
- package/lib/relation-repository/single-relation-repository.js.map +0 -1
- package/lib/relation-repository/types.js.map +0 -1
- package/lib/repository.js.map +0 -1
- package/lib/transaction-decorator.js.map +0 -1
- package/lib/update-associations.js.map +0 -1
- package/lib/update-guard.js.map +0 -1
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
|
@@ -53,28 +53,33 @@ export abstract class RelationRepository {
|
|
|
53
53
|
|
|
54
54
|
const guard = UpdateGuard.fromOptions(this.targetModel, options);
|
|
55
55
|
const values = options.values;
|
|
56
|
+
const transaction = await this.getTransaction(options);
|
|
56
57
|
|
|
57
|
-
const sourceModel = await this.getSourceModel();
|
|
58
|
+
const sourceModel = await this.getSourceModel(transaction);
|
|
58
59
|
|
|
59
|
-
const instance = await sourceModel[createAccessor](guard.sanitize(options.values), options);
|
|
60
|
+
const instance = await sourceModel[createAccessor](guard.sanitize(options.values), { ...options, transaction });
|
|
60
61
|
|
|
61
|
-
await updateAssociations(instance, values, options);
|
|
62
|
+
await updateAssociations(instance, values, { ...options, transaction });
|
|
62
63
|
|
|
63
64
|
if (options.hooks !== false) {
|
|
64
|
-
await this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance,
|
|
65
|
+
await this.db.emitAsync(`${this.targetCollection.name}.afterCreateWithAssociations`, instance, {
|
|
66
|
+
...options,
|
|
67
|
+
transaction,
|
|
68
|
+
});
|
|
65
69
|
const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;
|
|
66
|
-
await this.db.emitAsync(eventName, instance, options);
|
|
70
|
+
await this.db.emitAsync(eventName, instance, { ...options, transaction });
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
return instance;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
async getSourceModel(transaction?:
|
|
76
|
+
async getSourceModel(transaction?: Transaction) {
|
|
73
77
|
if (!this.sourceInstance) {
|
|
74
78
|
this.sourceInstance = await this.sourceCollection.model.findOne({
|
|
75
79
|
where: {
|
|
76
80
|
[this.associationField.sourceKey]: this.sourceKeyValue,
|
|
77
81
|
},
|
|
82
|
+
transaction,
|
|
78
83
|
});
|
|
79
84
|
}
|
|
80
85
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import lodash from 'lodash';
|
|
2
|
-
import { SingleAssociationAccessors } from 'sequelize';
|
|
2
|
+
import { SingleAssociationAccessors, Transactionable } from 'sequelize';
|
|
3
3
|
import { Model } from '../model';
|
|
4
|
-
import { Appends, Except, Fields, Filter, TargetKey,
|
|
4
|
+
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
|
|
5
5
|
import { updateModelByValues } from '../update-associations';
|
|
6
6
|
import { RelationRepository, transaction } from './relation-repository';
|
|
7
7
|
|
|
8
|
-
export interface SingleRelationFindOption extends
|
|
8
|
+
export interface SingleRelationFindOption extends Transactionable {
|
|
9
9
|
fields?: Fields;
|
|
10
10
|
except?: Except;
|
|
11
11
|
appends?: Appends;
|
|
12
12
|
filter?: Filter;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
interface SetOption extends
|
|
15
|
+
interface SetOption extends Transactionable {
|
|
16
16
|
tk?: TargetKey;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export abstract class SingleRelationRepository extends RelationRepository {
|
|
20
20
|
@transaction()
|
|
21
|
-
async remove(options?:
|
|
21
|
+
async remove(options?: Transactionable): Promise<void> {
|
|
22
22
|
const transaction = await this.getTransaction(options);
|
|
23
23
|
const sourceModel = await this.getSourceModel(transaction);
|
|
24
24
|
return await sourceModel[this.accessors().set](null, {
|
|
@@ -63,7 +63,7 @@ export abstract class SingleRelationRepository extends RelationRepository {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
@transaction()
|
|
66
|
-
async destroy(options?:
|
|
66
|
+
async destroy(options?: Transactionable): Promise<Boolean> {
|
|
67
67
|
const transaction = await this.getTransaction(options);
|
|
68
68
|
|
|
69
69
|
const target = await this.find({
|
package/src/repository.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
FindOptions as SequelizeFindOptions,
|
|
9
9
|
ModelCtor,
|
|
10
10
|
Op,
|
|
11
|
-
|
|
11
|
+
Transactionable,
|
|
12
12
|
UpdateOptions as SequelizeUpdateOptions
|
|
13
13
|
} from 'sequelize';
|
|
14
14
|
import { Collection } from './collection';
|
|
@@ -34,9 +34,7 @@ interface CreateManyOptions extends BulkCreateOptions {
|
|
|
34
34
|
records: Values[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export
|
|
38
|
-
transaction?: Transaction;
|
|
39
|
-
}
|
|
37
|
+
export { Transactionable } from 'sequelize';
|
|
40
38
|
|
|
41
39
|
export interface FilterAble {
|
|
42
40
|
filter: Filter;
|
|
@@ -57,7 +55,7 @@ export type AssociationKeysToBeUpdate = string[];
|
|
|
57
55
|
|
|
58
56
|
export type Values = any;
|
|
59
57
|
|
|
60
|
-
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>,
|
|
58
|
+
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>, Transactionable {
|
|
61
59
|
fields?: Fields;
|
|
62
60
|
filter?: Filter;
|
|
63
61
|
}
|
|
@@ -68,7 +66,7 @@ export interface FilterByTk {
|
|
|
68
66
|
|
|
69
67
|
export interface FindOptions extends SequelizeFindOptions, CommonFindOptions, FilterByTk {}
|
|
70
68
|
|
|
71
|
-
export interface CommonFindOptions {
|
|
69
|
+
export interface CommonFindOptions extends Transactionable {
|
|
72
70
|
filter?: Filter;
|
|
73
71
|
fields?: Fields;
|
|
74
72
|
appends?: Appends;
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
Transactionable,
|
|
10
10
|
} from 'sequelize';
|
|
11
11
|
import { Model } from './model';
|
|
12
|
-
import { TransactionAble } from './repository';
|
|
13
12
|
import { UpdateGuard } from './update-guard';
|
|
14
13
|
|
|
15
14
|
function isUndefinedOrNull(value: any) {
|
|
@@ -46,7 +45,7 @@ export function modelAssociationByKey(instance: Model, key: string): Association
|
|
|
46
45
|
|
|
47
46
|
type UpdateValue = { [key: string]: any };
|
|
48
47
|
|
|
49
|
-
interface UpdateOptions extends
|
|
48
|
+
interface UpdateOptions extends Transactionable {
|
|
50
49
|
filter?: any;
|
|
51
50
|
filterByTk?: number | string;
|
|
52
51
|
// 字段白名单
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import lodash from 'lodash';
|
|
12
|
-
import path from 'path';
|
|
13
|
-
function requireModule(module) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
if (typeof module === 'string') {
|
|
16
|
-
module = require(module);
|
|
17
|
-
}
|
|
18
|
-
if (typeof module !== 'object') {
|
|
19
|
-
return module;
|
|
20
|
-
}
|
|
21
|
-
return module.__esModule ? module.default : module;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export class ImporterReader {
|
|
25
|
-
constructor(directory, extensions) {
|
|
26
|
-
this.directory = directory;
|
|
27
|
-
if (!extensions) {
|
|
28
|
-
extensions = ['js', 'ts', 'json'];
|
|
29
|
-
}
|
|
30
|
-
this.extensions = new Set(extensions);
|
|
31
|
-
}
|
|
32
|
-
read() {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const modules = (yield fs.promises.readdir(this.directory, {
|
|
35
|
-
encoding: 'utf-8',
|
|
36
|
-
}))
|
|
37
|
-
.filter((fileName) => {
|
|
38
|
-
if (fileName.endsWith('.d.ts')) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
const ext = path.parse(fileName).ext.replace('.', '');
|
|
42
|
-
return this.extensions.has(ext);
|
|
43
|
-
})
|
|
44
|
-
.map((fileName) => __awaiter(this, void 0, void 0, function* () { return yield requireModule(path.join(this.directory, fileName)); }));
|
|
45
|
-
return (yield Promise.all(modules)).filter((module) => lodash.isPlainObject(module));
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=collection-importer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection-importer.js","sourceRoot":"","sources":["../src/collection-importer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,SAAe,aAAa,CAAC,MAAW;;QACtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC1B;QAED,IAAI,OAAO,MAAM,KAAK,Q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AAM,CAAC,CAAC,CAAC;QACvF,CAAC;KAAA;CACF","sourcesContent":["import * as fs from 'fs';\nimport lodash from 'lodash';\nimport path from 'path';\n\nexport type ImportFileExtension = 'js' | 'ts' | 'json';\n\nasync function requireModule(module: any) {\n if (typeof module === 'string') {\n module = require(module);\n }\n\n if (typeof module !== 'object') {\n return module;\n }\n return module.__esModule ? module.default : module;\n}\n\nexport class ImporterReader {\n directory: string;\n extensions: Set<string>;\n\n constructor(directory: string, extensions?: ImportFileExtension[]) {\n this.directory = directory;\n\n if (!extensions) {\n extensions = ['js', 'ts', 'json'];\n }\n\n this.extensions = new Set(extensions);\n }\n\n async read() {\n const modules = (\n await fs.promises.readdir(this.directory, {\n encoding: 'utf-8',\n })\n )\n .filter((fileName) => {\n if (fileName.endsWith('.d.ts')) {\n return false;\n }\n const ext = path.parse(fileName).ext.replace('.', '');\n return this.extensions.has(ext);\n })\n .map(async (fileName) => await requireModule(path.join(this.directory, fileName)));\n\n return (await Promise.all(modules)).filter((module) => lodash.isPlainObject(module));\n }\n}\n"]}
|
package/esm/collection.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import { ModelCtor, ModelOptions, SyncOptions } from 'sequelize';
|
|
4
|
-
import { Database } from './database';
|
|
5
|
-
import { Field, FieldOptions } from './fields';
|
|
6
|
-
import { Model } from './model';
|
|
7
|
-
import { Repository } from './repository';
|
|
8
|
-
export declare type RepositoryType = typeof Repository;
|
|
9
|
-
export declare type CollectionSortable = string | boolean | {
|
|
10
|
-
name?: string;
|
|
11
|
-
scopeKey?: string;
|
|
12
|
-
};
|
|
13
|
-
export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {
|
|
14
|
-
name: string;
|
|
15
|
-
tableName?: string;
|
|
16
|
-
filterTargetKey?: string;
|
|
17
|
-
fields?: FieldOptions[];
|
|
18
|
-
model?: string | ModelCtor<Model>;
|
|
19
|
-
repository?: string | RepositoryType;
|
|
20
|
-
sortable?: CollectionSortable;
|
|
21
|
-
/**
|
|
22
|
-
* @default true
|
|
23
|
-
*/
|
|
24
|
-
autoGenId?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* @default 'options'
|
|
27
|
-
*/
|
|
28
|
-
magicAttribute?: string;
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
}
|
|
31
|
-
export interface CollectionContext {
|
|
32
|
-
database: Database;
|
|
33
|
-
}
|
|
34
|
-
export declare class Collection<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> extends EventEmitter {
|
|
35
|
-
options: CollectionOptions;
|
|
36
|
-
context: CollectionContext;
|
|
37
|
-
isThrough?: boolean;
|
|
38
|
-
fields: Map<string, any>;
|
|
39
|
-
model: ModelCtor<Model>;
|
|
40
|
-
repository: Repository<TModelAttributes, TCreationAttributes>;
|
|
41
|
-
get filterTargetKey(): string;
|
|
42
|
-
get name(): string;
|
|
43
|
-
constructor(options: CollectionOptions, context?: CollectionContext);
|
|
44
|
-
private sequelizeModelOptions;
|
|
45
|
-
/**
|
|
46
|
-
* TODO
|
|
47
|
-
*/
|
|
48
|
-
modelInit(): void;
|
|
49
|
-
setRepository(repository?: RepositoryType | string): void;
|
|
50
|
-
private bindFieldEventListener;
|
|
51
|
-
forEachField(callback: (field: Field) => void): void;
|
|
52
|
-
findField(callback: (field: Field) => boolean): any;
|
|
53
|
-
hasField(name: string): boolean;
|
|
54
|
-
getField<F extends Field>(name: string): F;
|
|
55
|
-
addField(name: string, options: FieldOptions): Field;
|
|
56
|
-
setField(name: string, options: FieldOptions): Field;
|
|
57
|
-
setFields(fields: FieldOptions[], resetFields?: boolean): void;
|
|
58
|
-
resetFields(): void;
|
|
59
|
-
removeField(name: any): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* TODO
|
|
62
|
-
*/
|
|
63
|
-
updateOptions(options: CollectionOptions, mergeOptions?: any): this;
|
|
64
|
-
setSortable(sortable: any): void;
|
|
65
|
-
/**
|
|
66
|
-
* TODO
|
|
67
|
-
*
|
|
68
|
-
* @param name
|
|
69
|
-
* @param options
|
|
70
|
-
*/
|
|
71
|
-
updateField(name: string, options: FieldOptions): void;
|
|
72
|
-
sync(syncOptions?: SyncOptions): Promise<void>;
|
|
73
|
-
}
|
package/esm/collection.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
-
var t = {};
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
-
t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
import merge from 'deepmerge';
|
|
22
|
-
import { EventEmitter } from 'events';
|
|
23
|
-
import { default as lodash, default as _ } from 'lodash';
|
|
24
|
-
import { Model } from './model';
|
|
25
|
-
import { Repository } from './repository';
|
|
26
|
-
export class Collection extends EventEmitter {
|
|
27
|
-
constructor(options, context) {
|
|
28
|
-
super();
|
|
29
|
-
this.fields = new Map();
|
|
30
|
-
this.context = context;
|
|
31
|
-
this.options = options;
|
|
32
|
-
this.bindFieldEventListener();
|
|
33
|
-
this.modelInit();
|
|
34
|
-
this.setFields(options.fields);
|
|
35
|
-
this.setRepository(options.repository);
|
|
36
|
-
this.setSortable(options.sortable);
|
|
37
|
-
}
|
|
38
|
-
get filterTargetKey() {
|
|
39
|
-
return lodash.get(this.options, 'filterTargetKey', this.model.primaryKeyAttribute);
|
|
40
|
-
}
|
|
41
|
-
get name() {
|
|
42
|
-
return this.options.name;
|
|
43
|
-
}
|
|
44
|
-
sequelizeModelOptions() {
|
|
45
|
-
const { name, tableName } = this.options;
|
|
46
|
-
return Object.assign(Object.assign({}, _.omit(this.options, ['name', 'fields', 'model', 'targetKey'])), { modelName: name, sequelize: this.context.database.sequelize, tableName: tableName || name });
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* TODO
|
|
50
|
-
*/
|
|
51
|
-
modelInit() {
|
|
52
|
-
if (this.model) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const { name, model, autoGenId = true } = this.options;
|
|
56
|
-
let M = Model;
|
|
57
|
-
if (this.context.database.sequelize.isDefined(name)) {
|
|
58
|
-
const m = this.context.database.sequelize.model(name);
|
|
59
|
-
if (m.isThrough) {
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
this.model = m;
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
this.model.database = this.context.database;
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
this.model.collection = this;
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (typeof model === 'string') {
|
|
70
|
-
M = this.context.database.models.get(model) || Model;
|
|
71
|
-
}
|
|
72
|
-
else if (model) {
|
|
73
|
-
M = model;
|
|
74
|
-
}
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
this.model = class extends M {
|
|
77
|
-
};
|
|
78
|
-
this.model.init(null, this.sequelizeModelOptions());
|
|
79
|
-
if (!autoGenId) {
|
|
80
|
-
this.model.removeAttribute('id');
|
|
81
|
-
}
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
this.model.database = this.context.database;
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
this.model.collection = this;
|
|
86
|
-
}
|
|
87
|
-
setRepository(repository) {
|
|
88
|
-
let repo = Repository;
|
|
89
|
-
if (typeof repository === 'string') {
|
|
90
|
-
repo = this.context.database.repositories.get(repository) || Repository;
|
|
91
|
-
}
|
|
92
|
-
this.repository = new repo(this);
|
|
93
|
-
}
|
|
94
|
-
bindFieldEventListener() {
|
|
95
|
-
this.on('field.afterAdd', (field) => {
|
|
96
|
-
field.bind();
|
|
97
|
-
});
|
|
98
|
-
this.on('field.afterRemove', (field) => field.unbind());
|
|
99
|
-
}
|
|
100
|
-
forEachField(callback) {
|
|
101
|
-
return [...this.fields.values()].forEach(callback);
|
|
102
|
-
}
|
|
103
|
-
findField(callback) {
|
|
104
|
-
return [...this.fields.values()].find(callback);
|
|
105
|
-
}
|
|
106
|
-
hasField(name) {
|
|
107
|
-
return this.fields.has(name);
|
|
108
|
-
}
|
|
109
|
-
getField(name) {
|
|
110
|
-
return this.fields.get(name);
|
|
111
|
-
}
|
|
112
|
-
addField(name, options) {
|
|
113
|
-
return this.setField(name, options);
|
|
114
|
-
}
|
|
115
|
-
setField(name, options) {
|
|
116
|
-
const { database } = this.context;
|
|
117
|
-
const field = database.buildField(Object.assign({ name }, options), Object.assign(Object.assign({}, this.context), { collection: this }));
|
|
118
|
-
this.removeField(name);
|
|
119
|
-
this.fields.set(name, field);
|
|
120
|
-
this.emit('field.afterAdd', field);
|
|
121
|
-
return field;
|
|
122
|
-
}
|
|
123
|
-
setFields(fields, resetFields = true) {
|
|
124
|
-
if (!Array.isArray(fields)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (resetFields) {
|
|
128
|
-
this.resetFields();
|
|
129
|
-
}
|
|
130
|
-
for (let _a of fields) {
|
|
131
|
-
const { name } = _a, options = __rest(_a, ["name"]);
|
|
132
|
-
this.addField(name, options);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
resetFields() {
|
|
136
|
-
const fieldNames = this.fields.keys();
|
|
137
|
-
for (const fieldName of fieldNames) {
|
|
138
|
-
this.removeField(fieldName);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
removeField(name) {
|
|
142
|
-
if (!this.fields.has(name)) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const field = this.fields.get(name);
|
|
146
|
-
const bool = this.fields.delete(name);
|
|
147
|
-
if (bool) {
|
|
148
|
-
this.emit('field.afterRemove', field);
|
|
149
|
-
}
|
|
150
|
-
return bool;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* TODO
|
|
154
|
-
*/
|
|
155
|
-
updateOptions(options, mergeOptions) {
|
|
156
|
-
let newOptions = lodash.cloneDeep(options);
|
|
157
|
-
newOptions = merge(this.options, newOptions, mergeOptions);
|
|
158
|
-
this.context.database.emit('beforeUpdateCollection', this, newOptions);
|
|
159
|
-
this.setFields(options.fields, false);
|
|
160
|
-
this.setRepository(options.repository);
|
|
161
|
-
this.context.database.emit('afterUpdateCollection', this);
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
setSortable(sortable) {
|
|
165
|
-
if (!sortable) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (sortable === true) {
|
|
169
|
-
this.setField('sort', {
|
|
170
|
-
type: 'sort',
|
|
171
|
-
hidden: true,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
if (typeof sortable === 'string') {
|
|
175
|
-
this.setField(sortable, {
|
|
176
|
-
type: 'sort',
|
|
177
|
-
hidden: true,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else if (typeof sortable === 'object') {
|
|
181
|
-
const { name } = sortable, opts = __rest(sortable, ["name"]);
|
|
182
|
-
this.setField(name || 'sort', Object.assign({ type: 'sort', hidden: true }, opts));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* TODO
|
|
187
|
-
*
|
|
188
|
-
* @param name
|
|
189
|
-
* @param options
|
|
190
|
-
*/
|
|
191
|
-
updateField(name, options) {
|
|
192
|
-
if (!this.hasField(name)) {
|
|
193
|
-
throw new Error(`field ${name} not exists`);
|
|
194
|
-
}
|
|
195
|
-
if (options.name && options.name !== name) {
|
|
196
|
-
this.removeField(name);
|
|
197
|
-
}
|
|
198
|
-
this.setField(options.name || name, options);
|
|
199
|
-
}
|
|
200
|
-
sync(syncOptions) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
const modelNames = [this.model.name];
|
|
203
|
-
const associations = this.model.associations;
|
|
204
|
-
for (const associationKey in associations) {
|
|
205
|
-
const association = associations[associationKey];
|
|
206
|
-
modelNames.push(association.target.name);
|
|
207
|
-
if (association.through) {
|
|
208
|
-
modelNames.push(association.through.model.name);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const models = [];
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
this.context.database.sequelize.modelManager.forEachModel((model) => {
|
|
214
|
-
if (modelNames.includes(model.name)) {
|
|
215
|
-
models.push(model);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
for (const model of models) {
|
|
219
|
-
yield model.sync(syncOptions);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
//# sourceMappingURL=collection.js.map
|
package/esm/collection.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAA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,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;oBACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAC1B,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/B;QACH,CAAC;KAAA;CACF","sourcesContent":["import merge from 'deepmerge';\nimport { EventEmitter } from 'events';\nimport { default as lodash, default as _ } from 'lodash';\nimport { col, ModelCtor, ModelOptions, SyncOptions } from 'sequelize';\nimport { Database } from './database';\nimport { Field, FieldOptions } from './fields';\nimport { Model } from './model';\nimport { Repository } from './repository';\n\nexport type RepositoryType = typeof Repository;\n\nexport type CollectionSortable = string | boolean | { name?: string; scopeKey?: string };\n\nexport interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'> {\n name: string;\n tableName?: string;\n filterTargetKey?: string;\n fields?: FieldOptions[];\n model?: string | ModelCtor<Model>;\n repository?: string | RepositoryType;\n sortable?: CollectionSortable;\n /**\n * @default true\n */\n autoGenId?: boolean;\n /**\n * @default 'options'\n */\n magicAttribute?: string;\n [key: string]: any;\n}\n\nexport interface CollectionContext {\n database: Database;\n}\n\nexport class Collection<\n TModelAttributes extends {} = any,\n TCreationAttributes extends {} = TModelAttributes,\n> extends EventEmitter {\n options: CollectionOptions;\n context: CollectionContext;\n isThrough?: boolean;\n fields: Map<string, any> = new Map<string, any>();\n model: ModelCtor<Model>;\n repository: Repository<TModelAttributes, TCreationAttributes>;\n\n get filterTargetKey() {\n return lodash.get(this.options, 'filterTargetKey', this.model.primaryKeyAttribute);\n }\n\n get name() {\n return this.options.name;\n }\n\n constructor(options: CollectionOptions, context?: CollectionContext) {\n super();\n this.context = context;\n this.options = options;\n this.bindFieldEventListener();\n this.modelInit();\n this.setFields(options.fields);\n this.setRepository(options.repository);\n this.setSortable(options.sortable);\n }\n\n private sequelizeModelOptions() {\n const { name, tableName } = this.options;\n return {\n ..._.omit(this.options, ['name', 'fields', 'model', 'targetKey']),\n modelName: name,\n sequelize: this.context.database.sequelize,\n tableName: tableName || name,\n };\n }\n\n /**\n * TODO\n */\n modelInit() {\n if (this.model) {\n return;\n }\n const { name, model, autoGenId = true } = this.options;\n let M: ModelCtor<Model> = Model;\n if (this.context.database.sequelize.isDefined(name)) {\n const m = this.context.database.sequelize.model(name);\n if ((m as any).isThrough) {\n // @ts-ignore\n this.model = m;\n // @ts-ignore\n this.model.database = this.context.database;\n // @ts-ignore\n this.model.collection = this;\n return;\n }\n }\n if (typeof model === 'string') {\n M = this.context.database.models.get(model) || Model;\n } else if (model) {\n M = model;\n }\n // @ts-ignore\n this.model = class extends M {};\n this.model.init(null, this.sequelizeModelOptions());\n\n if (!autoGenId) {\n this.model.removeAttribute('id');\n }\n\n // @ts-ignore\n this.model.database = this.context.database;\n // @ts-ignore\n this.model.collection = this;\n }\n\n setRepository(repository?: RepositoryType | string) {\n let repo = Repository;\n if (typeof repository === 'string') {\n repo = this.context.database.repositories.get(repository) || Repository;\n }\n this.repository = new repo(this);\n }\n\n private bindFieldEventListener() {\n this.on('field.afterAdd', (field: Field) => {\n field.bind();\n });\n this.on('field.afterRemove', (field) => field.unbind());\n }\n\n forEachField(callback: (field: Field) => void) {\n return [...this.fields.values()].forEach(callback);\n }\n\n findField(callback: (field: Field) => boolean) {\n return [...this.fields.values()].find(callback);\n }\n\n hasField(name: string) {\n return this.fields.has(name);\n }\n\n getField<F extends Field>(name: string): F {\n return this.fields.get(name);\n }\n\n addField(name: string, options: FieldOptions): Field {\n return this.setField(name, options);\n }\n\n setField(name: string, options: FieldOptions): Field {\n const { database } = this.context;\n\n const field = database.buildField(\n { name, ...options },\n {\n ...this.context,\n collection: this,\n },\n );\n this.removeField(name);\n this.fields.set(name, field);\n this.emit('field.afterAdd', field);\n return field;\n }\n\n setFields(fields: FieldOptions[], resetFields = true) {\n if (!Array.isArray(fields)) {\n return;\n }\n\n if (resetFields) {\n this.resetFields();\n }\n\n for (const { name, ...options } of fields) {\n this.addField(name, options);\n }\n }\n\n resetFields() {\n const fieldNames = this.fields.keys();\n for (const fieldName of fieldNames) {\n this.removeField(fieldName);\n }\n }\n\n removeField(name) {\n if (!this.fields.has(name)) {\n return;\n }\n const field = this.fields.get(name);\n const bool = this.fields.delete(name);\n if (bool) {\n this.emit('field.afterRemove', field);\n }\n return bool;\n }\n\n /**\n * TODO\n */\n updateOptions(options: CollectionOptions, mergeOptions?: any) {\n let newOptions = lodash.cloneDeep(options);\n newOptions = merge(this.options, newOptions, mergeOptions);\n\n this.context.database.emit('beforeUpdateCollection', this, newOptions);\n\n this.setFields(options.fields, false);\n this.setRepository(options.repository);\n\n this.context.database.emit('afterUpdateCollection', this);\n\n return this;\n }\n\n setSortable(sortable) {\n if (!sortable) {\n return;\n }\n if (sortable === true) {\n this.setField('sort', {\n type: 'sort',\n hidden: true,\n });\n }\n if (typeof sortable === 'string') {\n this.setField(sortable, {\n type: 'sort',\n hidden: true,\n });\n } else if (typeof sortable === 'object') {\n const { name, ...opts } = sortable;\n this.setField(name || 'sort', { type: 'sort', hidden: true, ...opts });\n }\n }\n\n /**\n * TODO\n *\n * @param name\n * @param options\n */\n updateField(name: string, options: FieldOptions) {\n if (!this.hasField(name)) {\n throw new Error(`field ${name} not exists`);\n }\n\n if (options.name && options.name !== name) {\n this.removeField(name);\n }\n\n this.setField(options.name || name, options);\n }\n\n async sync(syncOptions?: SyncOptions) {\n const modelNames = [this.model.name];\n\n const associations = this.model.associations;\n\n for (const associationKey in associations) {\n const association = associations[associationKey];\n modelNames.push(association.target.name);\n if ((<any>association).through) {\n modelNames.push((<any>association).through.model.name);\n }\n }\n\n const models: ModelCtor<Model>[] = [];\n // @ts-ignore\n this.context.database.sequelize.modelManager.forEachModel((model) => {\n if (modelNames.includes(model.name)) {\n models.push(model);\n }\n });\n\n for (const model of models) {\n await model.sync(syncOptions);\n }\n }\n}\n"]}
|
package/esm/database.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { AsyncEmitter } from '@nocobase/utils';
|
|
3
|
-
import merge from 'deepmerge';
|
|
4
|
-
import { EventEmitter } from 'events';
|
|
5
|
-
import { ModelCtor, Options, QueryInterfaceDropAllTablesOptions, Sequelize, SyncOptions } from 'sequelize';
|
|
6
|
-
import { Collection, CollectionOptions, RepositoryType } from './collection';
|
|
7
|
-
import { ImportFileExtension } from './collection-importer';
|
|
8
|
-
import * as FieldTypes from './fields';
|
|
9
|
-
import { Field, FieldContext, RelationField } from './fields';
|
|
10
|
-
import { Model } from './model';
|
|
11
|
-
import { ModelHook } from './model-hook';
|
|
12
|
-
import { RelationRepository } from './relation-repository/relation-repository';
|
|
13
|
-
import { Repository } from './repository';
|
|
14
|
-
export interface MergeOptions extends merge.Options {
|
|
15
|
-
}
|
|
16
|
-
export interface PendingOptions {
|
|
17
|
-
field: RelationField;
|
|
18
|
-
model: ModelCtor<Model>;
|
|
19
|
-
}
|
|
20
|
-
interface MapOf<T> {
|
|
21
|
-
[key: string]: T;
|
|
22
|
-
}
|
|
23
|
-
export interface IDatabaseOptions extends Options {
|
|
24
|
-
tablePrefix?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare type DatabaseOptions = IDatabaseOptions | Sequelize;
|
|
27
|
-
interface RegisterOperatorsContext {
|
|
28
|
-
db?: Database;
|
|
29
|
-
path?: string;
|
|
30
|
-
field?: Field;
|
|
31
|
-
app?: any;
|
|
32
|
-
}
|
|
33
|
-
export interface CleanOptions extends QueryInterfaceDropAllTablesOptions {
|
|
34
|
-
drop?: boolean;
|
|
35
|
-
}
|
|
36
|
-
declare type OperatorFunc = (value: any, ctx?: RegisterOperatorsContext) => any;
|
|
37
|
-
export declare class Database extends EventEmitter implements AsyncEmitter {
|
|
38
|
-
sequelize: Sequelize;
|
|
39
|
-
fieldTypes: Map<any, any>;
|
|
40
|
-
options: IDatabaseOptions;
|
|
41
|
-
models: Map<string, ModelCtor<Model<any, any>>>;
|
|
42
|
-
repositories: Map<string, typeof Repository>;
|
|
43
|
-
operators: Map<any, any>;
|
|
44
|
-
collections: Map<string, Collection<any, any>>;
|
|
45
|
-
pendingFields: Map<string, FieldTypes.RelationField[]>;
|
|
46
|
-
modelCollection: Map<ModelCtor<any>, Collection<any, any>>;
|
|
47
|
-
modelHook: ModelHook;
|
|
48
|
-
delayCollectionExtend: Map<string, {
|
|
49
|
-
collectionOptions: CollectionOptions;
|
|
50
|
-
mergeOptions?: any;
|
|
51
|
-
}[]>;
|
|
52
|
-
constructor(options: DatabaseOptions);
|
|
53
|
-
/**
|
|
54
|
-
* Add collection to database
|
|
55
|
-
* @param options
|
|
56
|
-
*/
|
|
57
|
-
collection<Attributes = any, CreateAttributes = Attributes>(options: CollectionOptions): Collection<Attributes, CreateAttributes>;
|
|
58
|
-
getTablePrefix(): string;
|
|
59
|
-
/**
|
|
60
|
-
* get exists collection by its name
|
|
61
|
-
* @param name
|
|
62
|
-
*/
|
|
63
|
-
getCollection(name: string): Collection;
|
|
64
|
-
hasCollection(name: string): boolean;
|
|
65
|
-
removeCollection(name: string): void;
|
|
66
|
-
getModel<M extends Model>(name: string): ModelCtor<M>;
|
|
67
|
-
getRepository<R extends Repository>(name: string): R;
|
|
68
|
-
getRepository<R extends RelationRepository>(name: string, relationId: string | number): R;
|
|
69
|
-
addPendingField(field: RelationField): void;
|
|
70
|
-
removePendingField(field: RelationField): void;
|
|
71
|
-
registerFieldTypes(fieldTypes: MapOf<typeof Field>): void;
|
|
72
|
-
registerModels(models: MapOf<ModelCtor<any>>): void;
|
|
73
|
-
registerRepositories(repositories: MapOf<RepositoryType>): void;
|
|
74
|
-
initOperators(): void;
|
|
75
|
-
registerOperators(operators: MapOf<OperatorFunc>): void;
|
|
76
|
-
buildField(options: any, context: FieldContext): any;
|
|
77
|
-
sync(options?: SyncOptions): Promise<Sequelize>;
|
|
78
|
-
clean(options: CleanOptions): Promise<void>;
|
|
79
|
-
isSqliteMemory(): boolean;
|
|
80
|
-
reconnect(): Promise<void>;
|
|
81
|
-
closed(): any;
|
|
82
|
-
close(): Promise<void>;
|
|
83
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
84
|
-
import(options: {
|
|
85
|
-
directory: string;
|
|
86
|
-
extensions?: ImportFileExtension[];
|
|
87
|
-
}): Promise<Map<string, Collection>>;
|
|
88
|
-
emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
|
89
|
-
}
|
|
90
|
-
export declare function extend(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions): {
|
|
91
|
-
collectionOptions: CollectionOptions;
|
|
92
|
-
mergeOptions: MergeOptions;
|
|
93
|
-
extend: boolean;
|
|
94
|
-
};
|
|
95
|
-
export declare const defineCollection: (collectionOptions: CollectionOptions) => CollectionOptions;
|
|
96
|
-
export declare const extendCollection: (collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) => {
|
|
97
|
-
collectionOptions: CollectionOptions;
|
|
98
|
-
mergeOptions: MergeOptions;
|
|
99
|
-
extend: boolean;
|
|
100
|
-
};
|
|
101
|
-
export default Database;
|