@minimaltech/node-infra 0.5.8-10 → 0.5.8-12
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/base.helper.d.ts +1 -1
- package/dist/base/base.helper.js +3 -2
- package/dist/base/base.helper.js.map +1 -1
- package/dist/base/repositories/relations/has-many-polymorphic/decorator.d.ts +2 -1
- package/dist/base/repositories/relations/has-many-polymorphic/factory.d.ts +12 -12
- package/dist/base/repositories/relations/has-many-polymorphic/factory.js +41 -41
- package/dist/base/repositories/relations/has-many-polymorphic/factory.js.map +1 -1
- package/dist/common/types.d.ts +3 -4
- package/dist/components/authorize/interceptor.js +16 -16
- package/dist/components/authorize/interceptor.js.map +1 -1
- package/dist/helpers/logger/common/types.d.ts +2 -2
- package/dist/helpers/network/http-request/fetcher/axios-fetcher.d.ts +1 -1
- package/dist/helpers/worker-thread/base.d.ts +43 -1
- package/dist/helpers/worker-thread/base.js +80 -2
- package/dist/helpers/worker-thread/base.js.map +1 -1
- package/dist/helpers/worker-thread/index.d.ts +2 -0
- package/dist/helpers/worker-thread/index.js +2 -0
- package/dist/helpers/worker-thread/index.js.map +1 -1
- package/dist/helpers/worker-thread/types.d.ts +18 -1
- package/dist/helpers/worker-thread/worker-pool.d.ts +26 -0
- package/dist/helpers/worker-thread/worker-pool.js +78 -0
- package/dist/helpers/worker-thread/worker-pool.js.map +1 -0
- package/package.json +28 -28
package/dist/base/base.helper.js
CHANGED
@@ -4,8 +4,9 @@ exports.BaseHelper = void 0;
|
|
4
4
|
const helpers_1 = require("../helpers");
|
5
5
|
class BaseHelper {
|
6
6
|
constructor(opts) {
|
7
|
-
|
8
|
-
this.
|
7
|
+
var _a, _b;
|
8
|
+
this.logger = helpers_1.LoggerFactory.getLogger([opts.scope, (_a = opts.identifier) !== null && _a !== void 0 ? _a : ''].filter(el => el && el.length > 0));
|
9
|
+
this.identifier = (_b = opts.identifier) !== null && _b !== void 0 ? _b : '';
|
9
10
|
}
|
10
11
|
}
|
11
12
|
exports.BaseHelper = BaseHelper;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base.helper.js","sourceRoot":"","sources":["../../src/base/base.helper.ts"],"names":[],"mappings":";;;AAAA,uCAA6D;AAE7D,MAAa,UAAU;IAIrB,YAAY,
|
1
|
+
{"version":3,"file":"base.helper.js","sourceRoot":"","sources":["../../src/base/base.helper.ts"],"names":[],"mappings":";;;AAAA,uCAA6D;AAE7D,MAAa,UAAU;IAIrB,YAAY,IAA4C;;QACtD,IAAI,CAAC,MAAM,GAAG,uBAAa,CAAC,SAAS,CACnC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAA,IAAI,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CACtE,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,MAAA,IAAI,CAAC,UAAU,mCAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AAVD,gCAUC"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Entity } from '@loopback/repository';
|
1
2
|
import { IHasManyPolymorphicDefinition } from './types';
|
2
3
|
import { ValueOptionalExcept } from '../../../../common';
|
3
4
|
/**
|
@@ -8,4 +9,4 @@ import { ValueOptionalExcept } from '../../../../common';
|
|
8
9
|
*
|
9
10
|
* @experimental
|
10
11
|
*/
|
11
|
-
export declare function hasManyPolymorphic(definition: ValueOptionalExcept<IHasManyPolymorphicDefinition, 'target'>): (decoratedTarget:
|
12
|
+
export declare function hasManyPolymorphic(definition: ValueOptionalExcept<IHasManyPolymorphicDefinition, 'target'>): (decoratedTarget: Entity, key: string) => void;
|
@@ -3,6 +3,18 @@ import { IdType } from '../../../../common';
|
|
3
3
|
import { Getter } from '@loopback/core';
|
4
4
|
import { DefaultHasManyRepository, Entity, EntityCrudRepository, HasManyRepositoryFactory, InclusionResolver } from '@loopback/repository';
|
5
5
|
import { IHasManyPolymorphicDefinition, TPolymorphic } from './types';
|
6
|
+
/**
|
7
|
+
* @experimental
|
8
|
+
*/
|
9
|
+
export declare class DefaultHasManyPolymorphicRepository<Target extends BaseEntity, TargetId extends IdType, TargetRepository extends EntityCrudRepository<Target, TargetId>, SourceId> extends DefaultHasManyRepository<Target, TargetId, TargetRepository> {
|
10
|
+
constructor(opts: {
|
11
|
+
targetRepositoryGetter: Getter<TargetRepository>;
|
12
|
+
polymorphic: TPolymorphic & {
|
13
|
+
typeValue: string;
|
14
|
+
idValue: SourceId;
|
15
|
+
};
|
16
|
+
});
|
17
|
+
}
|
6
18
|
/**
|
7
19
|
* @experimental
|
8
20
|
*/
|
@@ -19,15 +31,3 @@ export declare const createHasManyPolymorphicRepositoryFactoryFor: <Target exten
|
|
19
31
|
relationMetadata: IHasManyPolymorphicDefinition;
|
20
32
|
targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetId>>;
|
21
33
|
}) => HasManyRepositoryFactory<Target, SourceId>;
|
22
|
-
/**
|
23
|
-
* @experimental
|
24
|
-
*/
|
25
|
-
export declare class DefaultHasManyPolymorphicRepository<Target extends BaseEntity, TargetId extends IdType, TargetRepository extends EntityCrudRepository<Target, TargetId>, SourceId> extends DefaultHasManyRepository<Target, TargetId, TargetRepository> {
|
26
|
-
constructor(opts: {
|
27
|
-
targetRepositoryGetter: Getter<TargetRepository>;
|
28
|
-
polymorphic: TPolymorphic & {
|
29
|
-
typeValue: string;
|
30
|
-
idValue: SourceId;
|
31
|
-
};
|
32
|
-
});
|
33
|
-
}
|
@@ -12,12 +12,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
15
|
+
exports.createHasManyPolymorphicRepositoryFactoryFor = exports.createHasManyPolymorphicInclusionResolver = exports.DefaultHasManyPolymorphicRepository = void 0;
|
16
16
|
const utilities_1 = require("../../../../utilities");
|
17
17
|
const repository_1 = require("@loopback/repository");
|
18
18
|
const get_1 = __importDefault(require("lodash/get"));
|
19
19
|
const base_repository_1 = require("../../base.repository");
|
20
20
|
// ----------------------------------------------------------------------------------------------------------------------------------------
|
21
|
+
const getPolymorphicFields = (opts) => {
|
22
|
+
const { discriminator } = opts;
|
23
|
+
let typeField = null;
|
24
|
+
let idField = null;
|
25
|
+
switch (typeof discriminator) {
|
26
|
+
case 'string': {
|
27
|
+
typeField = `${discriminator}Type`;
|
28
|
+
idField = `${discriminator}Id`;
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
case 'object': {
|
32
|
+
typeField = discriminator.typeField;
|
33
|
+
idField = discriminator.idField;
|
34
|
+
break;
|
35
|
+
}
|
36
|
+
default: {
|
37
|
+
throw (0, utilities_1.getError)({
|
38
|
+
statusCode: 500,
|
39
|
+
message: `[getFields] discriminator: ${typeof discriminator} | Invalid discriminator type!`,
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return { typeField, idField };
|
44
|
+
};
|
45
|
+
// ----------------------------------------------------------------------------------------------------------------------------------------
|
46
|
+
/**
|
47
|
+
* @experimental
|
48
|
+
*/
|
49
|
+
class DefaultHasManyPolymorphicRepository extends repository_1.DefaultHasManyRepository {
|
50
|
+
constructor(opts) {
|
51
|
+
const { targetRepositoryGetter, polymorphic } = opts;
|
52
|
+
const { typeField, idField } = getPolymorphicFields(polymorphic);
|
53
|
+
super(targetRepositoryGetter, {
|
54
|
+
[typeField]: polymorphic.typeValue,
|
55
|
+
[idField]: polymorphic.idValue,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
exports.DefaultHasManyPolymorphicRepository = DefaultHasManyPolymorphicRepository;
|
60
|
+
// ----------------------------------------------------------------------------------------------------------------------------------------
|
21
61
|
/**
|
22
62
|
* @experimental
|
23
63
|
*/
|
@@ -64,44 +104,4 @@ const createHasManyPolymorphicRepositoryFactoryFor = (opts) => {
|
|
64
104
|
return rs;
|
65
105
|
};
|
66
106
|
exports.createHasManyPolymorphicRepositoryFactoryFor = createHasManyPolymorphicRepositoryFactoryFor;
|
67
|
-
// ----------------------------------------------------------------------------------------------------------------------------------------
|
68
|
-
const getPolymorphicFields = (opts) => {
|
69
|
-
const { discriminator } = opts;
|
70
|
-
let typeField = null;
|
71
|
-
let idField = null;
|
72
|
-
switch (typeof discriminator) {
|
73
|
-
case 'string': {
|
74
|
-
typeField = `${discriminator}Type`;
|
75
|
-
idField = `${discriminator}Id`;
|
76
|
-
break;
|
77
|
-
}
|
78
|
-
case 'object': {
|
79
|
-
typeField = discriminator.typeField;
|
80
|
-
idField = discriminator.idField;
|
81
|
-
break;
|
82
|
-
}
|
83
|
-
default: {
|
84
|
-
throw (0, utilities_1.getError)({
|
85
|
-
statusCode: 500,
|
86
|
-
message: `[getFields] discriminator: ${typeof discriminator} | Invalid discriminator type!`,
|
87
|
-
});
|
88
|
-
}
|
89
|
-
}
|
90
|
-
return { typeField, idField };
|
91
|
-
};
|
92
|
-
// ----------------------------------------------------------------------------------------------------------------------------------------
|
93
|
-
/**
|
94
|
-
* @experimental
|
95
|
-
*/
|
96
|
-
class DefaultHasManyPolymorphicRepository extends repository_1.DefaultHasManyRepository {
|
97
|
-
constructor(opts) {
|
98
|
-
const { targetRepositoryGetter, polymorphic } = opts;
|
99
|
-
const { typeField, idField } = getPolymorphicFields(polymorphic);
|
100
|
-
super(targetRepositoryGetter, {
|
101
|
-
[typeField]: polymorphic.typeValue,
|
102
|
-
[idField]: polymorphic.idValue,
|
103
|
-
});
|
104
|
-
}
|
105
|
-
}
|
106
|
-
exports.DefaultHasManyPolymorphicRepository = DefaultHasManyPolymorphicRepository;
|
107
107
|
//# sourceMappingURL=factory.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/base/repositories/relations/has-many-polymorphic/factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;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CAAC,iBAAiB,CAAC,SAAS,EAAE,aAAa,CAAC;iBAC9C,KAAK,EAAE,GACX,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7D,OAAO,IAAA,8CAAiC,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1E,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,yCAAyC,6CA8CpD;AAEF,2IAA2I;AAC3I;;GAEG;AACI,MAAM,4CAA4C,GAAG,CAI1D,IAID,EAA8C,EAAE;IAC/C,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC;IAEzE,MAAM,EAAE,GAA+C,CAAC,QAAkB,EAAE,EAAE;QAC5E,OAAO,IAAI,mCAAmC,CAK5C;YACA,sBAAsB;YACtB,WAAW,kCAAO,gBAAgB,CAAC,WAAW,KAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,GAAE;SAC9F,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,EAAE,CAAC,iBAAiB,GAAG,IAAA,iDAAyC,EAAC,IAAI,CAAC,CAAC;IACvE,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAzBW,QAAA,4CAA4C,gDAyBvD
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../src/base/repositories/relations/has-many-polymorphic/factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,2CAAuC;AAEvC,qDAY8B;AAC9B,qDAA6B;AAE7B,2DAAqD;AAErD,2IAA2I;AAC3I,MAAM,oBAAoB,GAAG,CAAC,IAE7B,EAAE,EAAE;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAE/B,IAAI,SAAS,GAAkB,IAAI,CAAC;IACpC,IAAI,OAAO,GAAkB,IAAI,CAAC;IAElC,QAAQ,OAAO,aAA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AA4C,GAAG,CAI1D,IAID,EAA8C,EAAE;IAC/C,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC;IAEzE,MAAM,EAAE,GAA+C,CAAC,QAAkB,EAAE,EAAE;QAC5E,OAAO,IAAI,mCAAmC,CAK5C;YACA,sBAAsB;YACtB,WAAW,kCAAO,gBAAgB,CAAC,WAAW,KAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,GAAE;SAC9F,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,EAAE,CAAC,iBAAiB,GAAG,IAAA,iDAAyC,EAAC,IAAI,CAAC,CAAC;IACvE,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAzBW,QAAA,4CAA4C,gDAyBvD"}
|
package/dist/common/types.d.ts
CHANGED
@@ -23,10 +23,9 @@ export type ClassType<T> = Function & {
|
|
23
23
|
prototype: T;
|
24
24
|
};
|
25
25
|
export type TStatusFromClass<T extends ClassType<AnyObject>> = ValueOf<Omit<T, 'prototype' | 'isValid' | 'SCHEME_SET' | 'TYPE_SET'>>;
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
export type TConstValue<T extends ClassType<AnyObject>> = ValueOf<Omit<T, 'prototype' | 'isValid' | 'SCHEME_SET' | 'TYPE_SET'>>;
|
26
|
+
export type TStringConstValue<T extends ClassType<any>> = Extract<ValueOf<T>, string>;
|
27
|
+
export type TNumberConstValue<T extends ClassType<any>> = Extract<ValueOf<T>, number>;
|
28
|
+
export type TConstValue<T extends ClassType<any>> = Extract<ValueOf<T>, string | number>;
|
30
29
|
export type TPrettify<T> = {
|
31
30
|
[K in keyof T]: T[K];
|
32
31
|
} & {};
|
@@ -27,6 +27,22 @@ const core_1 = require("@loopback/core");
|
|
27
27
|
const security_1 = require("@loopback/security");
|
28
28
|
const authorization_1 = require("@loopback/authorization");
|
29
29
|
const helpers_1 = require("../../helpers");
|
30
|
+
function loadAuthorizers(ctx) {
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
32
|
+
const authorizerFunctions = [];
|
33
|
+
const bindings = ctx.findByTag(authorization_1.AuthorizationTags.AUTHORIZER);
|
34
|
+
const authorizers = bindings.map(b => b.key);
|
35
|
+
for (const keyOrFn of authorizers) {
|
36
|
+
if (typeof keyOrFn === 'function') {
|
37
|
+
authorizerFunctions.push(keyOrFn);
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
const fn = yield ctx.get(keyOrFn);
|
41
|
+
authorizerFunctions.push(fn);
|
42
|
+
}
|
43
|
+
return authorizerFunctions;
|
44
|
+
});
|
45
|
+
}
|
30
46
|
let AuthorizateInterceptor = AuthorizateInterceptor_1 = class AuthorizateInterceptor {
|
31
47
|
constructor(options = {}) {
|
32
48
|
this.options = Object.assign({ defaultDecision: authorization_1.AuthorizationDecision.DENY, precedence: authorization_1.AuthorizationDecision.DENY, defaultStatusCodeForDeny: 403 }, options);
|
@@ -104,20 +120,4 @@ exports.AuthorizateInterceptor = AuthorizateInterceptor = AuthorizateInterceptor
|
|
104
120
|
__param(0, (0, core_1.config)({ fromBinding: authorization_1.AuthorizationBindings.COMPONENT })),
|
105
121
|
__metadata("design:paramtypes", [Object])
|
106
122
|
], AuthorizateInterceptor);
|
107
|
-
function loadAuthorizers(ctx) {
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
109
|
-
const authorizerFunctions = [];
|
110
|
-
const bindings = ctx.findByTag(authorization_1.AuthorizationTags.AUTHORIZER);
|
111
|
-
const authorizers = bindings.map(b => b.key);
|
112
|
-
for (const keyOrFn of authorizers) {
|
113
|
-
if (typeof keyOrFn === 'function') {
|
114
|
-
authorizerFunctions.push(keyOrFn);
|
115
|
-
continue;
|
116
|
-
}
|
117
|
-
const fn = yield ctx.get(keyOrFn);
|
118
|
-
authorizerFunctions.push(fn);
|
119
|
-
}
|
120
|
-
return authorizerFunctions;
|
121
|
-
});
|
122
|
-
}
|
123
123
|
//# sourceMappingURL=interceptor.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../../src/components/authorize/interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAWwB;AACxB,iDAA+E;AAC/E,2DASiC;AACjC,uCAA6D;
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../../src/components/authorize/interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAWwB;AACxB,iDAA+E;AAC/E,2DASiC;AACjC,uCAA6D;AAE7D,SAAe,eAAe,CAAC,GAAY;;QACzC,MAAM,mBAAmB,GAAiB,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAa,iCAAiB,CAAC,UAAU,CAAC,CAAC;QACzE,MAAM,WAAW,GAAgD,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE1F,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE,CAAC;YAClC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAClC,SAAS;YACX,CAAC;YAED,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAClC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CAAA;AAGM,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAIjC,YAEE,UAAgC,EAAE;QAElC,IAAI,CAAC,OAAO,mBACV,eAAe,EAAE,qCAAqB,CAAC,IAAI,EAC3C,UAAU,EAAE,qCAAqB,CAAC,IAAI,EACtC,wBAAwB,EAAE,GAAG,IAC1B,OAAO,CACX,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,uBAAa,CAAC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AC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;oBAChD,MAAM;gBACR,CAAC;YACH,CAAC;YAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,aAAa,CAAC,CAAC;YACnE,IAAI,aAAa,KAAK,qCAAqB,CAAC,IAAI,EAAE,CAAC;gBACjD,MAAM,KAAK,GAAG,IAAI,kCAAkB,CAAC,eAAe,CAAC,CAAC;gBACtD,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC;gBACzD,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA;CACF,CAAA;AAnGY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,iBAAU,EAAC,IAAA,0BAAmB,EAAC,eAAe,CAAC,CAAC;IAM5C,WAAA,IAAA,aAAM,EAAC,EAAE,WAAW,EAAE,qCAAqB,CAAC,SAAS,EAAE,CAAC,CAAA;;GALhD,sBAAsB,CAmGlC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { TConstValue } from '../../../common/types';
|
2
2
|
export declare class LogLevels {
|
3
3
|
static readonly ERROR = "error";
|
4
4
|
static readonly ALERT = "alert";
|
@@ -12,4 +12,4 @@ export declare class LogLevels {
|
|
12
12
|
static readonly SCHEME_SET: Set<string>;
|
13
13
|
static isValid(input: string): boolean;
|
14
14
|
}
|
15
|
-
export type TLogLevel =
|
15
|
+
export type TLogLevel = TConstValue<typeof LogLevels>;
|
@@ -15,5 +15,5 @@ export declare class AxiosFetcher extends AbstractNetworkFetchableHelper<'axios'
|
|
15
15
|
defaultConfigs: AxiosRequestConfig;
|
16
16
|
logger?: any;
|
17
17
|
});
|
18
|
-
send<T = any>(opts: IAxiosRequestOptions, logger?: any): Promise<axios.AxiosResponse<T, any>>;
|
18
|
+
send<T = any>(opts: IAxiosRequestOptions, logger?: any): Promise<axios.AxiosResponse<T, any, {}>>;
|
19
19
|
}
|
@@ -1,6 +1,48 @@
|
|
1
|
+
import { Worker, WorkerOptions } from 'node:worker_threads';
|
1
2
|
import { BaseHelper } from '../../base/base.helper';
|
2
3
|
import { AnyType, ValueOrPromise } from '../../common/types';
|
3
|
-
import { IWorkerBus, IWorkerThread } from './types';
|
4
|
+
import { IWorker, IWorkerBus, IWorkerThread } from './types';
|
5
|
+
export declare abstract class AbstractWorkerHelper<MessageType> extends BaseHelper implements IWorker<MessageType> {
|
6
|
+
worker: Worker;
|
7
|
+
options: WorkerOptions;
|
8
|
+
abstract onOnline(): ValueOrPromise<void>;
|
9
|
+
abstract onExit(opts: {
|
10
|
+
code: string | number;
|
11
|
+
}): ValueOrPromise<void>;
|
12
|
+
abstract onError(opts: {
|
13
|
+
error: Error;
|
14
|
+
}): ValueOrPromise<void>;
|
15
|
+
abstract onMessage(opts: {
|
16
|
+
message: MessageType;
|
17
|
+
}): ValueOrPromise<void>;
|
18
|
+
abstract onMessageError(opts: {
|
19
|
+
error: Error;
|
20
|
+
}): ValueOrPromise<void>;
|
21
|
+
}
|
22
|
+
export declare class BaseWorkerHelper<MessageType> extends AbstractWorkerHelper<MessageType> {
|
23
|
+
protected eventHandlers?: Partial<Pick<IWorker<MessageType>, 'onOnline' | 'onExit' | 'onError' | 'onMessage' | 'onMessageError'>>;
|
24
|
+
constructor(opts: {
|
25
|
+
scope?: string;
|
26
|
+
identifier: string;
|
27
|
+
path: string | URL;
|
28
|
+
options: WorkerOptions;
|
29
|
+
eventHandlers?: Partial<Pick<IWorker<MessageType>, 'onOnline' | 'onExit' | 'onError' | 'onMessage' | 'onMessageError'>>;
|
30
|
+
});
|
31
|
+
onOnline(): ValueOrPromise<void>;
|
32
|
+
onExit(opts: {
|
33
|
+
code: string | number;
|
34
|
+
}): ValueOrPromise<void>;
|
35
|
+
onError(opts: {
|
36
|
+
error: Error;
|
37
|
+
}): ValueOrPromise<void>;
|
38
|
+
onMessage(opts: {
|
39
|
+
message: MessageType;
|
40
|
+
}): ValueOrPromise<void>;
|
41
|
+
onMessageError(opts: {
|
42
|
+
error: Error;
|
43
|
+
}): ValueOrPromise<void>;
|
44
|
+
binding(): void;
|
45
|
+
}
|
4
46
|
export declare abstract class AbstractWorkerThreadHelper extends BaseHelper implements IWorkerThread {
|
5
47
|
buses: {
|
6
48
|
[workerKey: string | symbol]: IWorkerBus<AnyType, AnyType>;
|
@@ -1,9 +1,87 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BaseWorkerThreadHelper = exports.AbstractWorkerThreadHelper = void 0;
|
3
|
+
exports.BaseWorkerThreadHelper = exports.AbstractWorkerThreadHelper = exports.BaseWorkerHelper = exports.AbstractWorkerHelper = void 0;
|
4
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
4
5
|
const base_helper_1 = require("../../base/base.helper");
|
5
6
|
const error_utility_1 = require("../../utilities/error.utility");
|
6
|
-
|
7
|
+
// -------------------------------------------------------------------------------------------
|
8
|
+
// WORKER
|
9
|
+
// -------------------------------------------------------------------------------------------
|
10
|
+
class AbstractWorkerHelper extends base_helper_1.BaseHelper {
|
11
|
+
}
|
12
|
+
exports.AbstractWorkerHelper = AbstractWorkerHelper;
|
13
|
+
// -------------------------------------------------------------------------------------------
|
14
|
+
class BaseWorkerHelper extends AbstractWorkerHelper {
|
15
|
+
constructor(opts) {
|
16
|
+
super({ scope: BaseWorkerHelper.name, identifier: opts.identifier });
|
17
|
+
this.worker = new node_worker_threads_1.Worker(opts.path, opts.options);
|
18
|
+
this.eventHandlers = opts.eventHandlers;
|
19
|
+
this.binding();
|
20
|
+
}
|
21
|
+
onOnline() {
|
22
|
+
var _a;
|
23
|
+
if ((_a = this.eventHandlers) === null || _a === void 0 ? void 0 : _a.onOnline) {
|
24
|
+
this.eventHandlers.onOnline();
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
this.logger.info('[online] Worker ONLINE');
|
28
|
+
}
|
29
|
+
onExit(opts) {
|
30
|
+
var _a;
|
31
|
+
if ((_a = this.eventHandlers) === null || _a === void 0 ? void 0 : _a.onExit) {
|
32
|
+
this.eventHandlers.onExit({ code: opts.code });
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
this.logger.warn('[onExit] Worker EXIT | Code: %s', opts.code);
|
36
|
+
}
|
37
|
+
onError(opts) {
|
38
|
+
var _a;
|
39
|
+
if ((_a = this.eventHandlers) === null || _a === void 0 ? void 0 : _a.onError) {
|
40
|
+
this.eventHandlers.onError({ error: opts.error });
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
this.logger.error('[onError] Worker ERROR | Error: %s', opts.error);
|
44
|
+
}
|
45
|
+
onMessage(opts) {
|
46
|
+
var _a;
|
47
|
+
if ((_a = this.eventHandlers) === null || _a === void 0 ? void 0 : _a.onMessage) {
|
48
|
+
this.eventHandlers.onMessage({ message: opts.message });
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
this.logger.error('[onMessage] Worker MESSAGE | message: %j', opts.message);
|
52
|
+
}
|
53
|
+
onMessageError(opts) {
|
54
|
+
var _a;
|
55
|
+
if ((_a = this.eventHandlers) === null || _a === void 0 ? void 0 : _a.onMessageError) {
|
56
|
+
this.eventHandlers.onMessageError({ error: opts.error });
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
this.logger.error('[onMessageError] Worker MESSAGE_ERROR | Error: %s', opts.error);
|
60
|
+
}
|
61
|
+
binding() {
|
62
|
+
if (!this.worker) {
|
63
|
+
throw (0, error_utility_1.getError)({ message: '[binding] Invalid worker instance to bind event handlers' });
|
64
|
+
}
|
65
|
+
this.worker.on('online', () => {
|
66
|
+
this.onOnline();
|
67
|
+
});
|
68
|
+
this.worker.on('exit', code => {
|
69
|
+
this.onExit({ code });
|
70
|
+
});
|
71
|
+
this.worker.on('error', error => {
|
72
|
+
this.onError({ error });
|
73
|
+
});
|
74
|
+
this.worker.on('message', message => {
|
75
|
+
this.onMessage({ message });
|
76
|
+
});
|
77
|
+
this.worker.on('messageerror', error => {
|
78
|
+
this.onMessageError({ error });
|
79
|
+
});
|
80
|
+
}
|
81
|
+
}
|
82
|
+
exports.BaseWorkerHelper = BaseWorkerHelper;
|
83
|
+
// -------------------------------------------------------------------------------------------
|
84
|
+
// WORKER THREAD RUNNER
|
7
85
|
// -------------------------------------------------------------------------------------------
|
8
86
|
class AbstractWorkerThreadHelper extends base_helper_1.BaseHelper {
|
9
87
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/helpers/worker-thread/base.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD,6DAAqD;
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/helpers/worker-thread/base.ts"],"names":[],"mappings":";;;AAAA,6DAA0E;AAE1E,oDAAgD;AAEhD,6DAAqD;AAGrD,8FAA8F;AAC9F,SAAS;AACT,8FAA8F;AAC9F,MAAsB,oBACpB,SAAQ,wBAAU;CAWnB;AAZD,oDAYC;AAED,8FAA8F;AAC9F,MAAa,gBAA8B,SAAQ,oBAAiC;IAKlF,YAAY,IAQX;QACC,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,IAAI,4BAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QAExC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAEQ,QAAQ;;QACf,IAAI,MAAA,IAAI,CAAC,aAAa,0CAAE,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC7C,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AC;gBACb,OAAO,EAAE,8CAA8C,IAAI,CAAC,GAAG,EAAE;aAClE,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAwB,CAAC;IAClC,CAAC;CACF;AArDD,wDAqDC"}
|
@@ -15,5 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./base"), exports);
|
18
|
+
__exportStar(require("./types"), exports);
|
18
19
|
__exportStar(require("./worker-bus"), exports);
|
20
|
+
__exportStar(require("./worker-pool"), exports);
|
19
21
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/worker-thread/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,+CAA6B"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/worker-thread/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,+CAA6B;AAC7B,gDAA8B"}
|
@@ -1,5 +1,22 @@
|
|
1
1
|
import { AnyType, ValueOrPromise } from '../../common/types';
|
2
|
-
import { MessagePort, Transferable } from 'node:worker_threads';
|
2
|
+
import { MessagePort, Transferable, Worker, WorkerOptions } from 'node:worker_threads';
|
3
|
+
export interface IWorker<MessageType> {
|
4
|
+
worker: Worker;
|
5
|
+
options: WorkerOptions;
|
6
|
+
onOnline(): ValueOrPromise<void>;
|
7
|
+
onExit(opts: {
|
8
|
+
code: string | number;
|
9
|
+
}): ValueOrPromise<void>;
|
10
|
+
onError(opts: {
|
11
|
+
error: Error;
|
12
|
+
}): ValueOrPromise<void>;
|
13
|
+
onMessage(opts: {
|
14
|
+
message: MessageType;
|
15
|
+
}): ValueOrPromise<void>;
|
16
|
+
onMessageError(opts: {
|
17
|
+
error: Error;
|
18
|
+
}): ValueOrPromise<void>;
|
19
|
+
}
|
3
20
|
export interface IWorkerThread {
|
4
21
|
buses: {
|
5
22
|
[workerKey: string | symbol]: IWorkerBus<AnyType, AnyType>;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { BaseHelper } from '../../base';
|
2
|
+
import { IWorker } from './types';
|
3
|
+
export declare class WorkerPoolHelper extends BaseHelper {
|
4
|
+
private static instance;
|
5
|
+
protected registry: Map<string | symbol, IWorker<any>>;
|
6
|
+
private numberOfCPUs;
|
7
|
+
private ignoreMaxWarning;
|
8
|
+
constructor(opts?: {
|
9
|
+
ignoreMaxWarning?: boolean;
|
10
|
+
});
|
11
|
+
static getInstance(): WorkerPoolHelper;
|
12
|
+
size(): number;
|
13
|
+
get<MessageType>(opts: {
|
14
|
+
key: string;
|
15
|
+
}): IWorker<MessageType> | undefined;
|
16
|
+
has(opts: {
|
17
|
+
key: string;
|
18
|
+
}): boolean;
|
19
|
+
register<MessageType>(opts: {
|
20
|
+
key: string;
|
21
|
+
worker: IWorker<MessageType>;
|
22
|
+
}): void;
|
23
|
+
unregister(opts: {
|
24
|
+
key: string;
|
25
|
+
}): Promise<void>;
|
26
|
+
}
|
@@ -0,0 +1,78 @@
|
|
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
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.WorkerPoolHelper = void 0;
|
16
|
+
const node_os_1 = __importDefault(require("node:os"));
|
17
|
+
const base_1 = require("../../base");
|
18
|
+
const utilities_1 = require("../../utilities");
|
19
|
+
class WorkerPoolHelper extends base_1.BaseHelper {
|
20
|
+
constructor(opts) {
|
21
|
+
var _a;
|
22
|
+
super({ scope: WorkerPoolHelper.name });
|
23
|
+
this.registry = new Map([]);
|
24
|
+
const cpus = node_os_1.default.cpus();
|
25
|
+
this.numberOfCPUs = cpus.length;
|
26
|
+
this.ignoreMaxWarning = (_a = opts === null || opts === void 0 ? void 0 : opts.ignoreMaxWarning) !== null && _a !== void 0 ? _a : false;
|
27
|
+
}
|
28
|
+
static getInstance() {
|
29
|
+
if (!WorkerPoolHelper.instance) {
|
30
|
+
WorkerPoolHelper.instance = new WorkerPoolHelper({ ignoreMaxWarning: false });
|
31
|
+
}
|
32
|
+
return WorkerPoolHelper.instance;
|
33
|
+
}
|
34
|
+
size() {
|
35
|
+
return this.registry.size;
|
36
|
+
}
|
37
|
+
get(opts) {
|
38
|
+
return this.registry.get(opts.key);
|
39
|
+
}
|
40
|
+
has(opts) {
|
41
|
+
return this.registry.has(opts.key);
|
42
|
+
}
|
43
|
+
register(opts) {
|
44
|
+
if (!this.registry) {
|
45
|
+
throw (0, utilities_1.getError)({
|
46
|
+
message: '[register] Invalid worker registry instance | please init registry before register new worker!',
|
47
|
+
});
|
48
|
+
}
|
49
|
+
if (this.registry.size === this.numberOfCPUs && !this.ignoreMaxWarning) {
|
50
|
+
this.logger.warn('[register] SKIP register worker | Pool size reached maximum number of cores | CPUs: %s | ignoreMaxWarning: %s', this.numberOfCPUs, this.ignoreMaxWarning);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
const { key, worker } = opts;
|
54
|
+
if (this.registry.has(key)) {
|
55
|
+
this.logger.error('[register] SKIP register worker | Worker key existed in pool | key: %s', key);
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.registry.set(key, worker);
|
59
|
+
this.logger.info('[register] Successfully register worker | key: %s | poolSize: %s', key, this.registry.size);
|
60
|
+
}
|
61
|
+
unregister(opts) {
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
63
|
+
const { key } = opts;
|
64
|
+
if (!this.has({ key })) {
|
65
|
+
this.logger.warn('[unregister] SKIP unregister worker | Worker not existed | key: %s', key);
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
const w = this.get({ key });
|
69
|
+
if (w === null || w === void 0 ? void 0 : w.worker) {
|
70
|
+
yield w.worker.terminate();
|
71
|
+
}
|
72
|
+
this.registry.delete(key);
|
73
|
+
this.logger.info('[unregister] Successfully unregister worker | key: %s | poolSize: %s', key, this.registry.size);
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
exports.WorkerPoolHelper = WorkerPoolHelper;
|
78
|
+
//# sourceMappingURL=worker-pool.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../src/helpers/worker-thread/worker-pool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAyB;AAEzB,iCAAoC;AACpC,2CAAuC;AAGvC,MAAa,gBAAiB,SAAQ,iBAAU;IAO9C,YAAY,IAAqC;;QAC/C,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;QAE5B,MAAM,IAAI,GAAG,iBAAE,CAAC,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,gBAAgB,mCAAI,KAAK,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,IAAI,CAA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AAM,CAAC,IAAI,CACd,kEAAkE,EAClE,GAAG,EACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,CAAC;IACJ,CAAC;IAEK,UAAU,CAAC,IAAqB;;YACpC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YAErB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;gBACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oEAAoE,EAAE,GAAG,CAAC,CAAC;gBAC5F,OAAO;YACT,CAAC;YAED,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YAC5B,IAAI,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM,EAAE,CAAC;gBACd,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC7B,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,sEAAsE,EACtE,GAAG,EACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CACnB,CAAC;QACJ,CAAC;KAAA;CACF;AA1FD,4CA0FC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@minimaltech/node-infra",
|
3
|
-
"version": "0.5.8-
|
3
|
+
"version": "0.5.8-12",
|
4
4
|
"description": "Minimal Technology NodeJS Infrastructure - Loopback 4 Framework",
|
5
5
|
"keywords": [
|
6
6
|
"web",
|
@@ -112,40 +112,40 @@
|
|
112
112
|
"access": "public"
|
113
113
|
},
|
114
114
|
"dependencies": {
|
115
|
-
"@grpc/grpc-js": "^1.
|
115
|
+
"@grpc/grpc-js": "^1.14.0",
|
116
116
|
"@grpc/proto-loader": "^0.8.0",
|
117
|
-
"@loopback/authentication": "^12.0.
|
118
|
-
"@loopback/authentication-jwt": "^0.16.
|
119
|
-
"@loopback/authentication-passport": "^8.0.
|
120
|
-
"@loopback/authorization": "^0.16.
|
121
|
-
"@loopback/boot": "^8.0.
|
122
|
-
"@loopback/core": "^7.0.
|
123
|
-
"@loopback/filter": "^6.0.
|
124
|
-
"@loopback/http-server": "^7.0.
|
125
|
-
"@loopback/metadata": "^8.0.
|
126
|
-
"@loopback/repository": "^8.0.
|
127
|
-
"@loopback/rest": "^15.0.
|
128
|
-
"@loopback/rest-crud": "^0.19.
|
129
|
-
"@loopback/rest-explorer": "^8.0.
|
130
|
-
"@loopback/security": "^0.12.
|
131
|
-
"@loopback/service-proxy": "^8.0.
|
117
|
+
"@loopback/authentication": "^12.0.6",
|
118
|
+
"@loopback/authentication-jwt": "^0.16.6",
|
119
|
+
"@loopback/authentication-passport": "^8.0.6",
|
120
|
+
"@loopback/authorization": "^0.16.5",
|
121
|
+
"@loopback/boot": "^8.0.5",
|
122
|
+
"@loopback/core": "^7.0.4",
|
123
|
+
"@loopback/filter": "^6.0.4",
|
124
|
+
"@loopback/http-server": "^7.0.4",
|
125
|
+
"@loopback/metadata": "^8.0.4",
|
126
|
+
"@loopback/repository": "^8.0.4",
|
127
|
+
"@loopback/rest": "^15.0.5",
|
128
|
+
"@loopback/rest-crud": "^0.19.5",
|
129
|
+
"@loopback/rest-explorer": "^8.0.5",
|
130
|
+
"@loopback/security": "^0.12.5",
|
131
|
+
"@loopback/service-proxy": "^8.0.4",
|
132
132
|
"@node-oauth/oauth2-server": "^5.2.1",
|
133
133
|
"@socket.io/redis-adapter": "^8.3.0",
|
134
134
|
"@socket.io/redis-emitter": "^5.1.0",
|
135
|
-
"axios": "^1.
|
136
|
-
"bullmq": "^5.
|
135
|
+
"axios": "^1.12.2",
|
136
|
+
"bullmq": "^5.58.7",
|
137
137
|
"casbin": "^5.38.0",
|
138
138
|
"cron": "^4.3.3",
|
139
|
-
"dayjs": "^1.11.
|
139
|
+
"dayjs": "^1.11.18",
|
140
140
|
"dotenv-flow": "^4.1.0",
|
141
141
|
"ejs": "^3.1.10",
|
142
142
|
"ioredis": "^5.7.0",
|
143
143
|
"jsonwebtoken": "^9.0.2",
|
144
144
|
"knex": "^3.1.0",
|
145
145
|
"lodash": "^4.17.21",
|
146
|
-
"minio": "^8.0.
|
147
|
-
"mocha": "^11.7.
|
148
|
-
"mqtt": "^5.14.
|
146
|
+
"minio": "^8.0.6",
|
147
|
+
"mocha": "^11.7.2",
|
148
|
+
"mqtt": "^5.14.1",
|
149
149
|
"multer": "^2.0.2",
|
150
150
|
"socket.io": "^4.8.1",
|
151
151
|
"socket.io-client": "^4.8.1",
|
@@ -154,16 +154,16 @@
|
|
154
154
|
"winston-transport": "^4.9.0"
|
155
155
|
},
|
156
156
|
"devDependencies": {
|
157
|
-
"@loopback/build": "^12.0.
|
158
|
-
"@loopback/testlab": "^8.0.
|
159
|
-
"@minimaltech/eslint-node": "^0.1
|
157
|
+
"@loopback/build": "^12.0.4",
|
158
|
+
"@loopback/testlab": "^8.0.4",
|
159
|
+
"@minimaltech/eslint-node": "^0.2.1",
|
160
160
|
"@types/express": "4.17.21",
|
161
161
|
"@types/jsonwebtoken": "^9.0.10",
|
162
162
|
"@types/lodash": "^4.17.20",
|
163
163
|
"@types/mocha": "^10.0.10",
|
164
164
|
"@types/multer": "^2.0.0",
|
165
|
-
"@types/node": "^22.
|
166
|
-
"eslint": "
|
165
|
+
"@types/node": "^22.18.6",
|
166
|
+
"eslint": "^9.36.0",
|
167
167
|
"husky": "^9.1.7",
|
168
168
|
"prettier": "^3.6.2",
|
169
169
|
"source-map-support": "^0.5.21",
|