@minimaltech/node-infra 0.5.9-22 → 0.5.9-24
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/dist/base/applications/base.application.js +40 -28
- package/dist/base/applications/default.application.js +8 -2
- package/dist/base/base.component.js +2 -2
- package/dist/base/base.helper.js +3 -4
- package/dist/base/base.provider.js +2 -2
- package/dist/base/base.sequence.js +26 -17
- package/dist/base/controllers/common.js +9 -8
- package/dist/base/controllers/crud.controller.js +67 -55
- package/dist/base/controllers/express-request-handler.js +0 -2
- package/dist/base/controllers/kv.controller.js +18 -7
- package/dist/base/controllers/relational.controller.d.ts +3 -1
- package/dist/base/controllers/relational.controller.js +57 -40
- package/dist/base/controllers/service-crud.controller.js +46 -46
- package/dist/base/datasources/base.datasource.js +0 -1
- package/dist/base/loopback/@lb/core/index.js +1 -0
- package/dist/base/loopback/@lb/repository/index.js +1 -0
- package/dist/base/loopback/authentication/index.js +2 -0
- package/dist/base/loopback/filter/index.js +2 -0
- package/dist/base/loopback/http-server/index.js +2 -0
- package/dist/base/models/base.model.d.ts +7 -0
- package/dist/base/models/base.model.js +23 -5
- package/dist/base/repositories/base.repository.d.ts +3 -0
- package/dist/base/repositories/base.repository.js +24 -5
- package/dist/base/repositories/relations/has-many-polymorphic/decorator.d.ts +8 -0
- package/dist/base/repositories/relations/has-many-polymorphic/decorator.js +10 -11
- package/dist/base/repositories/relations/has-many-polymorphic/factory.d.ts +9 -0
- package/dist/base/repositories/relations/has-many-polymorphic/factory.js +30 -12
- package/dist/base/repositories/searchable-tz-crud.repository.js +160 -129
- package/dist/base/repositories/tz-crud.repository.js +58 -23
- package/dist/base/services/base-crud.service.js +9 -6
- package/dist/base/services/base.service.js +2 -2
- package/dist/common/constants.js +89 -81
- package/dist/common/environments.js +25 -25
- package/dist/common/keys.js +2 -2
- package/dist/common/statuses.js +31 -28
- package/dist/common/types.d.ts +3 -0
- package/dist/components/authenticate/common/constants.js +13 -11
- package/dist/components/authenticate/common/keys.js +7 -7
- package/dist/components/authenticate/common/types.js +3 -11
- package/dist/components/authenticate/component.js +28 -20
- package/dist/components/authenticate/controllers/auth.controller.js +11 -13
- package/dist/components/authenticate/controllers/oauth2.controller.js +20 -18
- package/dist/components/authenticate/middleware.js +35 -25
- package/dist/components/authenticate/models/oauth2-client.model.js +3 -8
- package/dist/components/authenticate/models/oauth2-scope.model.js +0 -4
- package/dist/components/authenticate/models/oauth2-token.model.js +0 -7
- package/dist/components/authenticate/oauth2-handlers/authorization-code.handler.js +5 -4
- package/dist/components/authenticate/oauth2-handlers/base.js +110 -95
- package/dist/components/authenticate/oauth2-handlers/client-credential.handler.js +3 -2
- package/dist/components/authenticate/oauth2-handlers/oauth2.js +2 -3
- package/dist/components/authenticate/repositories/oauth2.repository.js +0 -2
- package/dist/components/authenticate/services/basic-token.service.js +29 -18
- package/dist/components/authenticate/services/basic.strategy.js +17 -7
- package/dist/components/authenticate/services/jwt-token.service.js +40 -27
- package/dist/components/authenticate/services/jwt.strategy.js +1 -2
- package/dist/components/authenticate/services/oauth2.service.js +110 -98
- package/dist/components/authenticate/services/oauth2.strategy.js +31 -19
- package/dist/components/authorize/adapters/adapter-builder.js +0 -1
- package/dist/components/authorize/adapters/base.adapter.js +9 -2
- package/dist/components/authorize/adapters/casbin-postgres-adapter.helper.js +55 -37
- package/dist/components/authorize/adapters/casbin-redis-adapter.helper.js +1 -0
- package/dist/components/authorize/common/constants.js +12 -10
- package/dist/components/authorize/common/keys.js +15 -15
- package/dist/components/authorize/common/types.js +2 -2
- package/dist/components/authorize/component.js +59 -44
- package/dist/components/authorize/decorators/index.d.ts +11 -0
- package/dist/components/authorize/decorators/index.js +14 -1
- package/dist/components/authorize/interceptor.js +80 -76
- package/dist/components/authorize/migrations/0000-create-view-policy.js +14 -3
- package/dist/components/authorize/models/defs.js +5 -24
- package/dist/components/authorize/models/role.model.js +1 -1
- package/dist/components/authorize/models/user-role.model.js +1 -0
- package/dist/components/authorize/models/view-authorize-policy.model.js +1 -4
- package/dist/components/authorize/provider.js +96 -81
- package/dist/components/authorize/repositories/authorize.repository.js +6 -3
- package/dist/components/authorize/services/enforcer.service.js +27 -20
- package/dist/components/authorize/services/generator.service.d.ts +20 -0
- package/dist/components/authorize/services/generator.service.js +96 -62
- package/dist/components/crash-report/common/keys.js +10 -8
- package/dist/components/crash-report/component.js +44 -31
- package/dist/components/crash-report/providers/provider.js +0 -1
- package/dist/components/crash-report/providers/third-parties/base.js +2 -2
- package/dist/components/crash-report/services/mt-crash-report.service.js +5 -5
- package/dist/components/grpc/common/keys.js +4 -4
- package/dist/components/grpc/components/server.component.js +8 -8
- package/dist/components/grpc/controllers/base.js +0 -1
- package/dist/components/grpc/helpers/grpc-client.js +3 -9
- package/dist/components/grpc/helpers/grpc-server.js +17 -14
- package/dist/components/grpc/persistents/grpc.connector.js +2 -8
- package/dist/components/grpc/persistents/grpc.datasource.js +3 -2
- package/dist/components/grpc/persistents/grpc.repository.js +2 -3
- package/dist/components/health-check/component.js +0 -1
- package/dist/components/migration/common/keys.js +3 -3
- package/dist/components/migration/component.js +8 -5
- package/dist/components/migration/models/migration.model.js +0 -2
- package/dist/components/socket-io/common/constants.js +10 -10
- package/dist/components/socket-io/common/keys.js +6 -6
- package/dist/components/socket-io/component.js +8 -9
- package/dist/components/socket-io/helpers/socket-io-client.helper.js +11 -7
- package/dist/components/socket-io/helpers/socket-io-server.helper.js +41 -26
- package/dist/components/static-asset/common/keys.js +4 -4
- package/dist/components/static-asset/component.js +8 -9
- package/dist/components/static-asset/controllers/asset.controller.d.ts +8 -0
- package/dist/components/static-asset/controllers/asset.controller.js +93 -71
- package/dist/components/static-asset/controllers/resource.controller.js +9 -8
- package/dist/datasources/memory/datasource.js +3 -3
- package/dist/datasources/postgres/datasource.js +10 -10
- package/dist/datasources/redis/connector.js +7 -18
- package/dist/datasources/redis/datasource.js +7 -7
- package/dist/helpers/application-environment.helper.js +3 -3
- package/dist/helpers/cron.helper.js +14 -9
- package/dist/helpers/crypto/algorithms/aes.algorithm.js +7 -8
- package/dist/helpers/crypto/algorithms/base.algorithm.js +4 -3
- package/dist/helpers/crypto/algorithms/rsa.algorithm.js +5 -4
- package/dist/helpers/database/query-builder.helper.js +5 -2
- package/dist/helpers/logger/application-logger.js +17 -7
- package/dist/helpers/logger/common/types.js +22 -20
- package/dist/helpers/logger/default-logger.js +12 -2
- package/dist/helpers/logger/factory.js +1 -1
- package/dist/helpers/logger/transports/dgram.transport.js +25 -16
- package/dist/helpers/network/http-request/base-network-request.helper.js +34 -36
- package/dist/helpers/network/http-request/fetcher/axios-fetcher.js +22 -10
- package/dist/helpers/network/http-request/fetcher/base-fetcher.js +36 -13
- package/dist/helpers/network/http-request/fetcher/node-fetcher.js +59 -37
- package/dist/helpers/network/tcp-socket/base-tcp-client.helper.js +27 -30
- package/dist/helpers/network/tcp-socket/base-tcp-server.helper.js +19 -21
- package/dist/helpers/network/tcp-socket/network-tcp-client.helper.js +1 -5
- package/dist/helpers/network/tcp-socket/network-tcp-server.helper.js +1 -5
- package/dist/helpers/network/tcp-socket/network-tls-tcp-client.helper.js +1 -5
- package/dist/helpers/network/tcp-socket/network-tls-tcp-server.helper.js +1 -5
- package/dist/helpers/network/udp-socket/network-udp-client.helper.js +18 -21
- package/dist/helpers/queue/bullmq.helper.js +22 -21
- package/dist/helpers/queue/mqtt.helper.js +17 -15
- package/dist/helpers/queue/queue.helper.js +145 -74
- package/dist/helpers/redis/default.helper.js +162 -117
- package/dist/helpers/redis/redis-cluster.helper.js +2 -7
- package/dist/helpers/redis/redis.helper.js +5 -8
- package/dist/helpers/storage/di-container.helper.js +0 -2
- package/dist/helpers/storage/minio.helper.js +128 -88
- package/dist/helpers/testing/common.js +3 -3
- package/dist/helpers/testing/describe.js +21 -14
- package/dist/helpers/testing/test-case.js +0 -5
- package/dist/helpers/testing/test-handler.js +30 -23
- package/dist/helpers/testing/test-plan/base.js +6 -9
- package/dist/helpers/worker-thread/base.js +20 -10
- package/dist/helpers/worker-thread/worker-bus.js +12 -11
- package/dist/helpers/worker-thread/worker-pool.js +25 -17
- package/dist/interceptors/content-range.interceptor.js +132 -115
- package/dist/middlewares/request-body-parser.middleware.js +16 -4
- package/dist/middlewares/request-spy.middleware.js +5 -4
- package/dist/migrations/handler.js +22 -13
- package/dist/mixins/data-type.mixin.js +0 -5
- package/dist/mixins/deprecated/user-audit.mixin.d.ts +3 -0
- package/dist/mixins/deprecated/user-audit.mixin.js +5 -2
- package/dist/mixins/duplicatable.mixin.js +0 -1
- package/dist/mixins/object-search.mixin.js +0 -1
- package/dist/mixins/principal.mixin.js +0 -2
- package/dist/mixins/soft-delete.mixin.js +0 -1
- package/dist/mixins/soft-persistent.mixin.js +0 -1
- package/dist/mixins/text-search.mixin.js +0 -1
- package/dist/mixins/tz.mixin.js +0 -2
- package/dist/mixins/user-audit.mixin.js +3 -5
- package/dist/mixins/vector.mixin.js +6 -9
- package/dist/tsconfig.base.json +6 -5
- package/dist/utilities/date.utility.js +23 -5
- package/dist/utilities/error.utility.js +0 -2
- package/dist/utilities/model.utility.js +6 -2
- package/dist/utilities/parse.utility.d.ts +16 -0
- package/dist/utilities/parse.utility.js +41 -6
- package/dist/utilities/performance.utility.js +2 -1
- package/dist/utilities/promise.utility.d.ts +17 -0
- package/dist/utilities/promise.utility.js +31 -5
- package/dist/utilities/query.utility.js +16 -8
- package/dist/utilities/request.utility.js +8 -2
- package/package.json +2 -3
|
@@ -8,6 +8,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
11
20
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
21
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
22
|
};
|
|
@@ -21,129 +30,143 @@ const utilities_1 = require("../../utilities");
|
|
|
21
30
|
const get_1 = __importDefault(require("lodash/get"));
|
|
22
31
|
const set_1 = __importDefault(require("lodash/set"));
|
|
23
32
|
let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class SearchableTzCrudRepository extends tz_crud_repository_1.TzCrudRepository {
|
|
24
|
-
searchableInclusions;
|
|
25
|
-
isInclusionRelations;
|
|
26
33
|
constructor(entityClass, dataSource, opts, scope) {
|
|
27
|
-
|
|
34
|
+
var _a;
|
|
35
|
+
super(entityClass, dataSource, scope !== null && scope !== void 0 ? scope : SearchableTzCrudRepository_1.name);
|
|
28
36
|
this.isInclusionRelations = opts.isInclusionRelations;
|
|
29
|
-
this.searchableInclusions = opts.searchableInclusions
|
|
37
|
+
this.searchableInclusions = (_a = opts.searchableInclusions) !== null && _a !== void 0 ? _a : [];
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
entities
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
// ----------------------------------------------------------------------------------------------------
|
|
40
|
+
registerOnInclusionChanged(relation, relationRepositoryGetter) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const relationRepository = yield relationRepositoryGetter();
|
|
43
|
+
relationRepository.modelClass.observe('after save', (context) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const { isNewInstance, where, instance, options } = context;
|
|
45
|
+
let entities = [];
|
|
46
|
+
if (isNewInstance) {
|
|
47
|
+
entities.push(instance);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
entities = yield relationRepository.find({ where }, options);
|
|
51
|
+
}
|
|
52
|
+
yield this.onInclusionChanged({ relation, relationRepository, entities, options });
|
|
53
|
+
}));
|
|
54
|
+
relationRepository.modelClass.observe('after deleteWithReturn', (context) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const { data } = context;
|
|
56
|
+
yield this.onInclusionChanged({
|
|
57
|
+
relation,
|
|
58
|
+
relationRepository,
|
|
59
|
+
entities: data,
|
|
60
|
+
});
|
|
61
|
+
}));
|
|
51
62
|
});
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
continue;
|
|
64
|
+
// ----------------------------------------------------------------------------------------------------
|
|
65
|
+
handleInclusionChanged(opts) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a;
|
|
68
|
+
const { relationName, relationType, entities, relationRepository, options } = opts;
|
|
69
|
+
const resolved = yield ((_a = relationRepository.inclusionResolvers.get(relationName)) === null || _a === void 0 ? void 0 : _a(entities, {
|
|
70
|
+
relation: relationName,
|
|
71
|
+
scope: {
|
|
72
|
+
include: this.searchableInclusions,
|
|
73
|
+
},
|
|
74
|
+
}, options));
|
|
75
|
+
const promises = [];
|
|
76
|
+
switch (relationType) {
|
|
77
|
+
case 'belongsTo': {
|
|
78
|
+
const rs = resolved;
|
|
79
|
+
if (!(rs === null || rs === void 0 ? void 0 : rs.length)) {
|
|
80
|
+
break;
|
|
71
81
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
for (const r1 of rs) {
|
|
83
|
+
if (!r1) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
promises.push(this.updateById(r1.id,
|
|
87
|
+
// TODO: handle type
|
|
88
|
+
{
|
|
89
|
+
objectSearch: this.renderObjectSearch({ entity: r1 }),
|
|
90
|
+
}, { ignoreMixSearchFields: true, options }));
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
75
93
|
}
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
case 'hasOne': {
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
case 'hasMany':
|
|
82
|
-
case 'hasManyThrough': {
|
|
83
|
-
const rs = resolved;
|
|
84
|
-
if (!rs?.length) {
|
|
94
|
+
case 'hasOne': {
|
|
85
95
|
break;
|
|
86
96
|
}
|
|
87
|
-
|
|
88
|
-
|
|
97
|
+
case 'hasMany':
|
|
98
|
+
case 'hasManyThrough': {
|
|
99
|
+
const rs = resolved;
|
|
100
|
+
if (!(rs === null || rs === void 0 ? void 0 : rs.length)) {
|
|
89
101
|
break;
|
|
90
102
|
}
|
|
91
|
-
for (const
|
|
92
|
-
if (!
|
|
93
|
-
|
|
103
|
+
for (const r1 of rs) {
|
|
104
|
+
if (!(r1 === null || r1 === void 0 ? void 0 : r1.length)) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
for (const r2 of r1) {
|
|
108
|
+
if (!rs) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
promises.push(this.updateById(r2.id,
|
|
112
|
+
// TODO: handle type
|
|
113
|
+
{
|
|
114
|
+
objectSearch: this.renderObjectSearch({ entity: r2 }),
|
|
115
|
+
}, { ignoreMixSearchFields: true, options }));
|
|
94
116
|
}
|
|
95
|
-
promises.push(this.updateById(r2.id, {
|
|
96
|
-
objectSearch: this.renderObjectSearch({ entity: r2 }),
|
|
97
|
-
}, { ignoreMixSearchFields: true, options }));
|
|
98
117
|
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
121
|
+
break;
|
|
99
122
|
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
default: {
|
|
103
|
-
break;
|
|
104
123
|
}
|
|
105
|
-
|
|
106
|
-
|
|
124
|
+
yield Promise.all(promises);
|
|
125
|
+
});
|
|
107
126
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (this.isInclusionRelations && this.searchableInclusions.length) {
|
|
116
|
-
resolved = await this.includeRelatedModels([data], this.searchableInclusions, options);
|
|
117
|
-
}
|
|
118
|
-
switch (field) {
|
|
119
|
-
case 'textSearch': {
|
|
120
|
-
return this.renderTextSearch({ data, entity: resolved?.[0] });
|
|
127
|
+
// ----------------------------------------------------------------------------------------------------
|
|
128
|
+
renderSearchable(field, data, options) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const where = (0, get_1.default)(options, 'where');
|
|
131
|
+
const isSearchable = (0, get_1.default)(this.modelClass.definition.properties, field, null) !== null;
|
|
132
|
+
if (!isSearchable) {
|
|
133
|
+
return null;
|
|
121
134
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
let resolved = [data];
|
|
136
|
+
if (this.isInclusionRelations && this.searchableInclusions.length) {
|
|
137
|
+
resolved = yield this.includeRelatedModels([data], this.searchableInclusions, options);
|
|
138
|
+
}
|
|
139
|
+
switch (field) {
|
|
140
|
+
case 'textSearch': {
|
|
141
|
+
return this.renderTextSearch({ data, entity: resolved === null || resolved === void 0 ? void 0 : resolved[0] });
|
|
142
|
+
}
|
|
143
|
+
case 'objectSearch': {
|
|
144
|
+
let currentObjectSearch = {};
|
|
145
|
+
if (where) {
|
|
146
|
+
const found = yield this.findOne({
|
|
147
|
+
where,
|
|
148
|
+
include: this.searchableInclusions,
|
|
133
149
|
});
|
|
150
|
+
if (found) {
|
|
151
|
+
currentObjectSearch = this.renderObjectSearch({
|
|
152
|
+
data,
|
|
153
|
+
entity: found,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
134
156
|
}
|
|
157
|
+
const newObjectSearch = this.renderObjectSearch({
|
|
158
|
+
data,
|
|
159
|
+
entity: resolved === null || resolved === void 0 ? void 0 : resolved[0],
|
|
160
|
+
});
|
|
161
|
+
return Object.assign(Object.assign({}, currentObjectSearch), newObjectSearch);
|
|
162
|
+
}
|
|
163
|
+
default: {
|
|
164
|
+
return null;
|
|
135
165
|
}
|
|
136
|
-
const newObjectSearch = this.renderObjectSearch({
|
|
137
|
-
data,
|
|
138
|
-
entity: resolved?.[0],
|
|
139
|
-
});
|
|
140
|
-
return { ...currentObjectSearch, ...newObjectSearch };
|
|
141
|
-
}
|
|
142
|
-
default: {
|
|
143
|
-
return null;
|
|
144
166
|
}
|
|
145
|
-
}
|
|
167
|
+
});
|
|
146
168
|
}
|
|
169
|
+
// ----------------------------------------------------------------------------------------------------
|
|
147
170
|
mixSearchFields(data, options) {
|
|
148
171
|
return new Promise((resolve, reject) => {
|
|
149
172
|
const ignoreMixSearchFields = (0, get_1.default)(options, 'ignoreMixSearchFields');
|
|
@@ -166,8 +189,9 @@ let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class Searchable
|
|
|
166
189
|
.catch(reject);
|
|
167
190
|
});
|
|
168
191
|
}
|
|
192
|
+
// ----------------------------------------------------------------------------------------------------
|
|
169
193
|
create(data, options) {
|
|
170
|
-
const tmp = this.mixUserAudit(data, { newInstance: true, authorId: options
|
|
194
|
+
const tmp = this.mixUserAudit(data, { newInstance: true, authorId: options === null || options === void 0 ? void 0 : options.authorId });
|
|
171
195
|
return new Promise((resolve, reject) => {
|
|
172
196
|
this.mixSearchFields(tmp, options)
|
|
173
197
|
.then(enriched => {
|
|
@@ -176,10 +200,11 @@ let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class Searchable
|
|
|
176
200
|
.catch(reject);
|
|
177
201
|
});
|
|
178
202
|
}
|
|
203
|
+
// ----------------------------------------------------------------------------------------------------
|
|
179
204
|
createAll(data, options) {
|
|
180
205
|
return new Promise((resolve, reject) => {
|
|
181
206
|
Promise.all(data.map(el => {
|
|
182
|
-
const tmp = this.mixUserAudit(el, { newInstance: true, authorId: options
|
|
207
|
+
const tmp = this.mixUserAudit(el, { newInstance: true, authorId: options === null || options === void 0 ? void 0 : options.authorId });
|
|
183
208
|
return this.mixSearchFields(tmp, options);
|
|
184
209
|
}))
|
|
185
210
|
.then(enriched => {
|
|
@@ -188,18 +213,20 @@ let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class Searchable
|
|
|
188
213
|
.catch(reject);
|
|
189
214
|
});
|
|
190
215
|
}
|
|
216
|
+
// ----------------------------------------------------------------------------------------------------
|
|
191
217
|
updateById(id, data, options) {
|
|
192
|
-
const tmp = this.mixUserAudit(data, { newInstance: false, authorId: options
|
|
218
|
+
const tmp = this.mixUserAudit(data, { newInstance: false, authorId: options === null || options === void 0 ? void 0 : options.authorId });
|
|
193
219
|
return new Promise((resolve, reject) => {
|
|
194
|
-
this.mixSearchFields(tmp, {
|
|
220
|
+
this.mixSearchFields(tmp, Object.assign(Object.assign({}, options), { where: { id } }))
|
|
195
221
|
.then(enriched => {
|
|
196
222
|
resolve(super.updateById(id, enriched, options));
|
|
197
223
|
})
|
|
198
224
|
.catch(reject);
|
|
199
225
|
});
|
|
200
226
|
}
|
|
227
|
+
// ----------------------------------------------------------------------------------------------------
|
|
201
228
|
replaceById(id, data, options) {
|
|
202
|
-
const tmp = this.mixUserAudit(data, { newInstance: false, authorId: options
|
|
229
|
+
const tmp = this.mixUserAudit(data, { newInstance: false, authorId: options === null || options === void 0 ? void 0 : options.authorId });
|
|
203
230
|
return new Promise((resolve, reject) => {
|
|
204
231
|
this.mixSearchFields(tmp, options)
|
|
205
232
|
.then(enriched => {
|
|
@@ -208,6 +235,7 @@ let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class Searchable
|
|
|
208
235
|
.catch(reject);
|
|
209
236
|
});
|
|
210
237
|
}
|
|
238
|
+
// ----------------------------------------------------------------------------------------------------
|
|
211
239
|
_syncSearchFields(entities, options) {
|
|
212
240
|
const { table, columns } = (0, utilities_1.getTableDefinition)({ model: this.entityClass });
|
|
213
241
|
const data = entities.map(e => {
|
|
@@ -236,30 +264,33 @@ let SearchableTzCrudRepository = SearchableTzCrudRepository_1 = class Searchable
|
|
|
236
264
|
});
|
|
237
265
|
return this.execute(query, undefined, options);
|
|
238
266
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
267
|
+
// ----------------------------------------------------------------------------------------------------
|
|
268
|
+
syncSearchFields(where, options) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
const t = performance.now();
|
|
271
|
+
const pagingLimit = (0, get_1.default)(options, 'pagingLimit', 50);
|
|
272
|
+
let pagingOffset = 0;
|
|
273
|
+
this.logger.info('[syncSearchFields] Start sync searchable fields');
|
|
274
|
+
const tasks = [];
|
|
275
|
+
while (true) {
|
|
276
|
+
const entities = yield this.find({ where, include: this.searchableInclusions, limit: pagingLimit, offset: pagingOffset }, options);
|
|
277
|
+
this.logger.info('[syncSearchFields] Where: %j | Found: %d', where, entities.length);
|
|
278
|
+
tasks.push(() => this._syncSearchFields(entities, options)
|
|
279
|
+
.then(() => {
|
|
280
|
+
this.logger.info(`[syncSearchFields] Sucess sync %d rows`, entities.length);
|
|
281
|
+
})
|
|
282
|
+
.catch(e => {
|
|
283
|
+
this.logger.error(`[syncSearchFields] Error: %j`, e);
|
|
284
|
+
}));
|
|
285
|
+
pagingOffset += pagingLimit;
|
|
286
|
+
if (entities.length < pagingLimit) {
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
258
289
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
290
|
+
yield (0, utilities_1.executePromiseWithLimit)({ tasks, limit: 5 });
|
|
291
|
+
this.logger.info('[syncSearchFields] End sync searchable fields | Took: %d (ms)', performance.now() - t);
|
|
292
|
+
return;
|
|
293
|
+
});
|
|
263
294
|
}
|
|
264
295
|
};
|
|
265
296
|
exports.SearchableTzCrudRepository = SearchableTzCrudRepository;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -8,10 +17,12 @@ const helpers_1 = require("../../helpers");
|
|
|
8
17
|
const utilities_1 = require("../../utilities");
|
|
9
18
|
const base_repository_1 = require("./base.repository");
|
|
10
19
|
const get_1 = __importDefault(require("lodash/get"));
|
|
20
|
+
// ----------------------------------------------------------------------------------------------------------------------------------------
|
|
11
21
|
class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
12
22
|
constructor(entityClass, dataSource, scope) {
|
|
13
23
|
super(entityClass, dataSource, scope);
|
|
14
24
|
}
|
|
25
|
+
// ----------------------------------------------------------------------------------------------------
|
|
15
26
|
existsWith(where, options) {
|
|
16
27
|
return new Promise((resolve, reject) => {
|
|
17
28
|
this.findOne({ where }, options)
|
|
@@ -21,44 +32,54 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
21
32
|
.catch(reject);
|
|
22
33
|
});
|
|
23
34
|
}
|
|
35
|
+
// ----------------------------------------------------------------------------------------------------
|
|
24
36
|
create(data, options) {
|
|
37
|
+
var _a;
|
|
25
38
|
let enriched = this.mixTimestamp(data, {
|
|
26
39
|
newInstance: true,
|
|
27
|
-
ignoreModified: options
|
|
40
|
+
ignoreModified: (_a = options === null || options === void 0 ? void 0 : options.ignoreModified) !== null && _a !== void 0 ? _a : false,
|
|
28
41
|
});
|
|
29
42
|
enriched = this.mixUserAudit(enriched, {
|
|
30
43
|
newInstance: true,
|
|
31
|
-
authorId: options
|
|
44
|
+
authorId: options === null || options === void 0 ? void 0 : options.authorId,
|
|
32
45
|
});
|
|
33
46
|
return super.create(enriched, options);
|
|
34
47
|
}
|
|
48
|
+
// ----------------------------------------------------------------------------------------------------
|
|
35
49
|
createAll(datum, options) {
|
|
36
50
|
const enriched = datum.map(data => {
|
|
51
|
+
var _a;
|
|
37
52
|
const tmp = this.mixTimestamp(data, {
|
|
38
53
|
newInstance: true,
|
|
39
|
-
ignoreModified: options
|
|
54
|
+
ignoreModified: (_a = options === null || options === void 0 ? void 0 : options.ignoreModified) !== null && _a !== void 0 ? _a : false,
|
|
40
55
|
});
|
|
41
56
|
return this.mixUserAudit(tmp, {
|
|
42
57
|
newInstance: true,
|
|
43
|
-
authorId: options
|
|
58
|
+
authorId: options === null || options === void 0 ? void 0 : options.authorId,
|
|
44
59
|
});
|
|
45
60
|
});
|
|
46
61
|
return super.createAll(enriched, options);
|
|
47
62
|
}
|
|
63
|
+
/*
|
|
64
|
+
* @deprecated | Redundant | Please .create
|
|
65
|
+
*/
|
|
48
66
|
createWithReturn(data, options) {
|
|
49
67
|
return this.create(data, options);
|
|
50
68
|
}
|
|
69
|
+
// ----------------------------------------------------------------------------------------------------
|
|
51
70
|
updateById(id, data, options) {
|
|
71
|
+
var _a;
|
|
52
72
|
let enriched = this.mixTimestamp(data, {
|
|
53
73
|
newInstance: false,
|
|
54
|
-
ignoreModified: options
|
|
74
|
+
ignoreModified: (_a = options === null || options === void 0 ? void 0 : options.ignoreModified) !== null && _a !== void 0 ? _a : false,
|
|
55
75
|
});
|
|
56
76
|
enriched = this.mixUserAudit(enriched, {
|
|
57
77
|
newInstance: false,
|
|
58
|
-
authorId: options
|
|
78
|
+
authorId: options === null || options === void 0 ? void 0 : options.authorId,
|
|
59
79
|
});
|
|
60
80
|
return super.updateById(id, enriched, options);
|
|
61
81
|
}
|
|
82
|
+
// ----------------------------------------------------------------------------------------------------
|
|
62
83
|
updateWithReturn(id, data, options) {
|
|
63
84
|
return new Promise((resolve, reject) => {
|
|
64
85
|
this.updateById(id, data, options)
|
|
@@ -72,45 +93,55 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
72
93
|
.catch(reject);
|
|
73
94
|
});
|
|
74
95
|
}
|
|
96
|
+
// ----------------------------------------------------------------------------------------------------
|
|
75
97
|
updateAll(data, where, options) {
|
|
98
|
+
var _a;
|
|
76
99
|
let enriched = this.mixTimestamp(data, {
|
|
77
100
|
newInstance: false,
|
|
78
|
-
ignoreModified: options
|
|
101
|
+
ignoreModified: (_a = options === null || options === void 0 ? void 0 : options.ignoreModified) !== null && _a !== void 0 ? _a : false,
|
|
79
102
|
});
|
|
80
103
|
enriched = this.mixUserAudit(enriched, {
|
|
81
104
|
newInstance: false,
|
|
82
|
-
authorId: options
|
|
105
|
+
authorId: options === null || options === void 0 ? void 0 : options.authorId,
|
|
83
106
|
});
|
|
84
107
|
return super.updateAll(enriched, where, options);
|
|
85
108
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
109
|
+
// ----------------------------------------------------------------------------------------------------
|
|
110
|
+
upsertWith(data, where, options) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const isExisted = yield this.existsWith(where, options);
|
|
113
|
+
if (isExisted) {
|
|
114
|
+
yield this.updateAll(data, where, options);
|
|
115
|
+
const rs = yield this.findOne({ where }, options);
|
|
116
|
+
return rs;
|
|
117
|
+
}
|
|
118
|
+
const rs = yield this.create(data, options);
|
|
91
119
|
return rs;
|
|
92
|
-
}
|
|
93
|
-
const rs = await this.create(data, options);
|
|
94
|
-
return rs;
|
|
120
|
+
});
|
|
95
121
|
}
|
|
122
|
+
// ----------------------------------------------------------------------------------------------------
|
|
96
123
|
replaceById(id, data, options) {
|
|
124
|
+
var _a;
|
|
97
125
|
let enriched = this.mixTimestamp(data, {
|
|
98
126
|
newInstance: false,
|
|
99
|
-
ignoreModified: options
|
|
127
|
+
ignoreModified: (_a = options === null || options === void 0 ? void 0 : options.ignoreModified) !== null && _a !== void 0 ? _a : false,
|
|
100
128
|
});
|
|
101
129
|
enriched = this.mixUserAudit(enriched, {
|
|
102
130
|
newInstance: false,
|
|
103
|
-
authorId: options
|
|
131
|
+
authorId: options === null || options === void 0 ? void 0 : options.authorId,
|
|
104
132
|
});
|
|
105
133
|
return super.replaceById(id, enriched, options);
|
|
106
134
|
}
|
|
135
|
+
// ----------------------------------------------------------------------------------------------------
|
|
107
136
|
_softDelete(where, options) {
|
|
108
137
|
return new Promise((resolve, reject) => {
|
|
109
|
-
const { databaseSchema, connectorType = 'postgresql', softDeleteField = 'isDeleted', useIgnoreModified = false, authorId, } = options
|
|
138
|
+
const { databaseSchema, connectorType = 'postgresql', softDeleteField = 'isDeleted', useIgnoreModified = false, authorId, } = options !== null && options !== void 0 ? options : {};
|
|
110
139
|
const tableName = this.modelClass.definition.tableName(connectorType);
|
|
111
140
|
const softDeleteColumnName = this.modelClass.definition.columnName(connectorType, softDeleteField);
|
|
141
|
+
// Mix Timestamp
|
|
112
142
|
const mixTimestampColumnName = this.modelClass.definition.columnName(connectorType, 'modifiedAt');
|
|
113
143
|
const schema = (0, get_1.default)(this.modelClass.definition.settings, `${connectorType}.schema`, 'public');
|
|
144
|
+
// Mix User Audit
|
|
114
145
|
const mixUserAuditColumnName = this.modelClass.definition.columnName(connectorType, 'modifiedBy');
|
|
115
146
|
const isSoftDeleteFieldExist = (0, get_1.default)(this.modelClass.definition.rawProperties, softDeleteField);
|
|
116
147
|
if (!isSoftDeleteFieldExist) {
|
|
@@ -121,8 +152,9 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
121
152
|
const now = new Date();
|
|
122
153
|
this.find({ fields: { id: true }, where })
|
|
123
154
|
.then(rs => {
|
|
155
|
+
var _a;
|
|
124
156
|
const sqlBuilder = helpers_1.QueryBuilderHelper.getPostgresQueryBuilder()
|
|
125
|
-
.withSchema(databaseSchema
|
|
157
|
+
.withSchema((_a = databaseSchema !== null && databaseSchema !== void 0 ? databaseSchema : schema) !== null && _a !== void 0 ? _a : 'public')
|
|
126
158
|
.from(tableName)
|
|
127
159
|
.update({ [softDeleteColumnName]: true })
|
|
128
160
|
.whereIn('id', rs.map(el => el.id));
|
|
@@ -164,11 +196,12 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
164
196
|
});
|
|
165
197
|
});
|
|
166
198
|
}
|
|
199
|
+
// ----------------------------------------------------------------------------------------------------
|
|
167
200
|
mixTimestamp(entity, options = {
|
|
168
201
|
newInstance: false,
|
|
169
202
|
ignoreModified: false,
|
|
170
203
|
}) {
|
|
171
|
-
if (options
|
|
204
|
+
if (options === null || options === void 0 ? void 0 : options.newInstance) {
|
|
172
205
|
entity.createdAt = new Date();
|
|
173
206
|
}
|
|
174
207
|
if (!options.ignoreModified) {
|
|
@@ -177,15 +210,16 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
177
210
|
return entity;
|
|
178
211
|
}
|
|
179
212
|
mixUserAudit(entity, options) {
|
|
180
|
-
if (!options
|
|
213
|
+
if (!(options === null || options === void 0 ? void 0 : options.authorId)) {
|
|
181
214
|
return entity;
|
|
182
215
|
}
|
|
183
|
-
if (options
|
|
216
|
+
if (options === null || options === void 0 ? void 0 : options.newInstance) {
|
|
184
217
|
entity.createdBy = options.authorId;
|
|
185
218
|
}
|
|
186
219
|
entity.modifiedBy = options.authorId;
|
|
187
220
|
return entity;
|
|
188
221
|
}
|
|
222
|
+
// ----------------------------------------------------------------------------------------------------
|
|
189
223
|
_deleteWithReturn(where, options) {
|
|
190
224
|
return new Promise((resolve, reject) => {
|
|
191
225
|
this.find({ where })
|
|
@@ -220,6 +254,7 @@ class TzCrudRepository extends base_repository_1.AbstractTzRepository {
|
|
|
220
254
|
});
|
|
221
255
|
});
|
|
222
256
|
}
|
|
257
|
+
// ----------------------------------------------------------------------------------------------------
|
|
223
258
|
batchUpdate(opts) {
|
|
224
259
|
const { data, keys, setKeys, whereKeys, whereRaws = [], options } = opts;
|
|
225
260
|
const query = (0, utilities_1.buildBatchUpdateQuery)({
|
|
@@ -4,7 +4,6 @@ exports.BaseCrudService = void 0;
|
|
|
4
4
|
const common_1 = require("../controllers/common");
|
|
5
5
|
const base_service_1 = require("./base.service");
|
|
6
6
|
class BaseCrudService extends base_service_1.BaseService {
|
|
7
|
-
repository;
|
|
8
7
|
constructor(opts) {
|
|
9
8
|
const { scope, repository } = opts;
|
|
10
9
|
super({ scope });
|
|
@@ -23,28 +22,32 @@ class BaseCrudService extends base_service_1.BaseService {
|
|
|
23
22
|
return this.repository.count(where);
|
|
24
23
|
}
|
|
25
24
|
create(data, options) {
|
|
25
|
+
var _a;
|
|
26
26
|
return this.repository.create(data, {
|
|
27
|
-
authorId: options.currentUser
|
|
27
|
+
authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
updateAll(data, where, options) {
|
|
31
|
+
var _a;
|
|
31
32
|
return this.repository.updateAll(data, where, {
|
|
32
|
-
authorId: options.currentUser
|
|
33
|
+
authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
updateWithReturn(id, data, options) {
|
|
37
|
+
var _a;
|
|
36
38
|
return this.repository.updateWithReturn(id, data, {
|
|
37
|
-
authorId: options.currentUser
|
|
39
|
+
authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId,
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
replaceById(id, data, options) {
|
|
41
43
|
return new Promise((resolve, reject) => {
|
|
44
|
+
var _a;
|
|
42
45
|
this.repository
|
|
43
46
|
.replaceById(id, data, {
|
|
44
|
-
authorId: options.currentUser
|
|
47
|
+
authorId: (_a = options.currentUser) === null || _a === void 0 ? void 0 : _a.userId,
|
|
45
48
|
})
|
|
46
49
|
.then(() => {
|
|
47
|
-
resolve({
|
|
50
|
+
resolve(Object.assign(Object.assign({}, data), { id }));
|
|
48
51
|
})
|
|
49
52
|
.catch(reject);
|
|
50
53
|
});
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseService = void 0;
|
|
4
4
|
const helpers_1 = require("../../helpers");
|
|
5
5
|
class BaseService {
|
|
6
|
-
logger;
|
|
7
6
|
constructor(opts) {
|
|
8
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
this.logger = helpers_1.LoggerFactory.getLogger([(_a = opts === null || opts === void 0 ? void 0 : opts.scope) !== null && _a !== void 0 ? _a : BaseService.name]);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
exports.BaseService = BaseService;
|