@midwayjs/core 3.0.0-beta.6 → 3.0.0

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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/dist/baseFramework.d.ts +2 -1
  3. package/dist/baseFramework.js +17 -11
  4. package/dist/common/applicationManager.d.ts +11 -0
  5. package/dist/common/applicationManager.js +70 -0
  6. package/dist/common/dataListener.d.ts +11 -0
  7. package/dist/common/dataListener.js +43 -0
  8. package/dist/common/fileDetector.js +1 -1
  9. package/dist/common/middlewareManager.d.ts +62 -5
  10. package/dist/common/middlewareManager.js +141 -6
  11. package/dist/common/webGenerator.d.ts +3 -14
  12. package/dist/common/webGenerator.js +23 -31
  13. package/dist/common/webRouterCollector.js +7 -3
  14. package/dist/context/container.js +28 -13
  15. package/dist/context/managedResolverFactory.js +12 -5
  16. package/dist/context/requestContainer.js +2 -0
  17. package/dist/definitions/functionDefinition.d.ts +1 -0
  18. package/dist/definitions/functionDefinition.js +1 -0
  19. package/dist/definitions/objectCreator.js +9 -8
  20. package/dist/definitions/objectDefinition.d.ts +1 -0
  21. package/dist/definitions/objectDefinition.js +1 -0
  22. package/dist/error/base.d.ts +22 -3
  23. package/dist/error/base.js +34 -5
  24. package/dist/error/framework.d.ts +30 -2
  25. package/dist/error/framework.js +56 -13
  26. package/dist/error/http.d.ts +146 -41
  27. package/dist/error/http.js +164 -31
  28. package/dist/error/index.d.ts +1 -1
  29. package/dist/error/index.js +4 -1
  30. package/dist/functional/configuration.d.ts +2 -0
  31. package/dist/functional/configuration.js +10 -0
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.js +7 -1
  34. package/dist/interface.d.ts +51 -29
  35. package/dist/service/aspectService.js +1 -1
  36. package/dist/service/configService.d.ts +3 -1
  37. package/dist/service/configService.js +23 -17
  38. package/dist/service/decoratorService.js +11 -5
  39. package/dist/service/environmentService.d.ts +1 -1
  40. package/dist/service/frameworkService.d.ts +3 -2
  41. package/dist/service/frameworkService.js +17 -12
  42. package/dist/service/lifeCycleService.js +5 -5
  43. package/dist/service/loggerService.d.ts +1 -1
  44. package/dist/service/middlewareService.d.ts +3 -4
  45. package/dist/service/middlewareService.js +28 -24
  46. package/dist/setup.js +13 -5
  47. package/dist/util/extend.d.ts +2 -0
  48. package/dist/util/extend.js +55 -0
  49. package/dist/util/index.d.ts +9 -0
  50. package/dist/util/index.js +55 -1
  51. package/dist/util/webRouterParam.js +24 -4
  52. package/package.json +10 -11
  53. package/CHANGELOG.md +0 -2174
  54. package/dist/error/code.d.ts +0 -59
  55. package/dist/error/code.js +0 -64
@@ -64,8 +64,13 @@ class ContainerConfiguration {
64
64
  });
65
65
  }
66
66
  addImportConfigs(importConfigs) {
67
- if (importConfigs && importConfigs.length) {
68
- this.container.get(configService_1.MidwayConfigService).add(importConfigs);
67
+ if (importConfigs) {
68
+ if (Array.isArray(importConfigs)) {
69
+ this.container.get(configService_1.MidwayConfigService).add(importConfigs);
70
+ }
71
+ else {
72
+ this.container.get(configService_1.MidwayConfigService).addObject(importConfigs);
73
+ }
69
74
  }
70
75
  }
71
76
  addImports(imports = []) {
@@ -139,16 +144,16 @@ class ContainerConfiguration {
139
144
  }
140
145
  getConfigurationExport(exports) {
141
146
  const mods = [];
142
- if ((0, decorator_1.isClass)(exports) ||
143
- (0, decorator_1.isFunction)(exports) ||
147
+ if (decorator_1.Types.isClass(exports) ||
148
+ decorator_1.Types.isFunction(exports) ||
144
149
  exports instanceof configuration_1.FunctionalConfiguration) {
145
150
  mods.push(exports);
146
151
  }
147
152
  else {
148
153
  for (const m in exports) {
149
154
  const module = exports[m];
150
- if ((0, decorator_1.isClass)(module) ||
151
- (0, decorator_1.isFunction)(module) ||
155
+ if (decorator_1.Types.isClass(module) ||
156
+ decorator_1.Types.isFunction(module) ||
152
157
  module instanceof configuration_1.FunctionalConfiguration) {
153
158
  mods.push(module);
154
159
  }
@@ -235,13 +240,13 @@ class MidwayContainer {
235
240
  (_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.run(this);
236
241
  }
237
242
  bindClass(exports, options) {
238
- if ((0, decorator_1.isClass)(exports) || (0, decorator_1.isFunction)(exports)) {
243
+ if (decorator_1.Types.isClass(exports) || decorator_1.Types.isFunction(exports)) {
239
244
  this.bindModule(exports, options);
240
245
  }
241
246
  else {
242
247
  for (const m in exports) {
243
248
  const module = exports[m];
244
- if ((0, decorator_1.isClass)(module) || (0, decorator_1.isFunction)(module)) {
249
+ if (decorator_1.Types.isClass(module) || decorator_1.Types.isFunction(module)) {
245
250
  this.bindModule(module, options);
246
251
  }
247
252
  }
@@ -249,7 +254,7 @@ class MidwayContainer {
249
254
  }
250
255
  bind(identifier, target, options) {
251
256
  var _a;
252
- if ((0, decorator_1.isClass)(identifier) || (0, decorator_1.isFunction)(identifier)) {
257
+ if (decorator_1.Types.isClass(identifier) || decorator_1.Types.isFunction(identifier)) {
253
258
  return this.bindModule(identifier, target);
254
259
  }
255
260
  if (this.registry.hasDefinition(identifier)) {
@@ -257,13 +262,13 @@ class MidwayContainer {
257
262
  return;
258
263
  }
259
264
  let definition;
260
- if ((0, decorator_1.isClass)(target)) {
265
+ if (decorator_1.Types.isClass(target)) {
261
266
  definition = new objectDefinition_1.ObjectDefinition();
262
267
  definition.name = (0, decorator_1.getProviderName)(target);
263
268
  }
264
269
  else {
265
270
  definition = new functionDefinition_1.FunctionDefinition();
266
- if (!(0, decorator_1.isAsyncFunction)(target)) {
271
+ if (!decorator_1.Types.isAsyncFunction(target)) {
267
272
  definition.asynchronous = false;
268
273
  }
269
274
  definition.name = definition.id;
@@ -310,6 +315,10 @@ class MidwayContainer {
310
315
  debugBind(` register scope = ${objDefOptions.scope}`);
311
316
  definition.scope = objDefOptions.scope;
312
317
  }
318
+ if (objDefOptions.allowDowngrade) {
319
+ debugBind(` register allowDowngrade = ${objDefOptions.allowDowngrade}`);
320
+ definition.allowDowngrade = objDefOptions.allowDowngrade;
321
+ }
313
322
  this.objectCreateEventTarget.emit(interface_1.ObjectLifeCycleEvent.BEFORE_BIND, target, {
314
323
  context: this,
315
324
  definition,
@@ -322,7 +331,7 @@ class MidwayContainer {
322
331
  }
323
332
  }
324
333
  bindModule(module, options) {
325
- if ((0, decorator_1.isClass)(module)) {
334
+ if (decorator_1.Types.isClass(module)) {
326
335
  const providerId = (0, decorator_1.getProviderUUId)(module);
327
336
  if (providerId) {
328
337
  this.identifierMapping.saveClassRelation(module, options === null || options === void 0 ? void 0 : options.namespace);
@@ -338,7 +347,7 @@ class MidwayContainer {
338
347
  if (!info.scope) {
339
348
  info.scope = decorator_1.ScopeEnum.Request;
340
349
  }
341
- const uuid = (0, decorator_1.generateRandomId)();
350
+ const uuid = decorator_1.Utils.generateRandomId();
342
351
  this.identifierMapping.saveFunctionRelation(info.id, uuid);
343
352
  this.bind(uuid, module, {
344
353
  scope: info.scope,
@@ -379,7 +388,10 @@ class MidwayContainer {
379
388
  }
380
389
  get(identifier, args, objectContext) {
381
390
  var _a;
391
+ args = args !== null && args !== void 0 ? args : [];
392
+ objectContext = objectContext !== null && objectContext !== void 0 ? objectContext : { originName: identifier };
382
393
  if (typeof identifier !== 'string') {
394
+ objectContext.originName = identifier.name;
383
395
  identifier = this.getIdentifier(identifier);
384
396
  }
385
397
  if (this.registry.hasObject(identifier)) {
@@ -396,7 +408,10 @@ class MidwayContainer {
396
408
  }
397
409
  async getAsync(identifier, args, objectContext) {
398
410
  var _a;
411
+ args = args !== null && args !== void 0 ? args : [];
412
+ objectContext = objectContext !== null && objectContext !== void 0 ? objectContext : { originName: identifier };
399
413
  if (typeof identifier !== 'string') {
414
+ objectContext.originName = identifier.name;
400
415
  identifier = this.getIdentifier(identifier);
401
416
  }
402
417
  if (this.registry.hasObject(identifier)) {
@@ -56,14 +56,14 @@ class ManagedResolverFactory {
56
56
  resolveManaged(managed, originPropertyName) {
57
57
  const resolver = this.resolvers[managed.type];
58
58
  if (!resolver || resolver.type !== managed.type) {
59
- throw new Error(`${managed.type} resolver is not exists!`);
59
+ throw new error_1.MidwayResolverMissingError(managed.type);
60
60
  }
61
61
  return resolver.resolve(managed, originPropertyName);
62
62
  }
63
63
  async resolveManagedAsync(managed, originPropertyName) {
64
64
  const resolver = this.resolvers[managed.type];
65
65
  if (!resolver || resolver.type !== managed.type) {
66
- throw new Error(`${managed.type} resolver is not exists!`);
66
+ throw new error_1.MidwayResolverMissingError(managed.type);
67
67
  }
68
68
  return resolver.resolveAsync(managed, originPropertyName);
69
69
  }
@@ -89,7 +89,7 @@ class ManagedResolverFactory {
89
89
  this.context.get(dep, args);
90
90
  }
91
91
  }
92
- debugLog(`[core:container]: Create id = "${definition.name}" ${definition.id}.`);
92
+ debugLog(`[core]: Create id = "${definition.name}" ${definition.id}.`);
93
93
  const Clzz = definition.creator.load();
94
94
  let constructorArgs = [];
95
95
  if (args && Array.isArray(args) && args.length > 0) {
@@ -174,7 +174,7 @@ class ManagedResolverFactory {
174
174
  await this.context.getAsync(dep, args);
175
175
  }
176
176
  }
177
- debugLog(`[core:container]: Create id = "${definition.name}" ${definition.id}.`);
177
+ debugLog(`[core]: Create id = "${definition.name}" ${definition.id}.`);
178
178
  const Clzz = definition.creator.load();
179
179
  let constructorArgs = [];
180
180
  if (args && Array.isArray(args) && args.length > 0) {
@@ -187,7 +187,7 @@ class ManagedResolverFactory {
187
187
  inst = await definition.creator.doConstructAsync(Clzz, constructorArgs, this.context);
188
188
  if (!inst) {
189
189
  this.removeCreateStatus(definition, false);
190
- throw new Error(`${definition.id} construct return undefined`);
190
+ throw new error_1.MidwayCommonError(`${definition.id} construct return undefined`);
191
191
  }
192
192
  // binding ctx object
193
193
  if (definition.isRequestScope() &&
@@ -202,6 +202,13 @@ class ManagedResolverFactory {
202
202
  if (definition.properties) {
203
203
  const keys = definition.properties.propertyKeys();
204
204
  for (const key of keys) {
205
+ if (definition.isSingletonScope() && this.context.hasDefinition(key)) {
206
+ const propertyDefinition = this.context.registry.getDefinition(key);
207
+ if (propertyDefinition.isRequestScope() &&
208
+ !propertyDefinition.allowDowngrade) {
209
+ throw new error_1.MidwaySingletonInjectRequestError(definition.path.name, propertyDefinition.path.name);
210
+ }
211
+ }
205
212
  try {
206
213
  inst[key] = await this.resolveManagedAsync(definition.properties.get(key), key);
207
214
  }
@@ -13,6 +13,8 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
13
13
  this.ctx = ctx;
14
14
  // register ctx
15
15
  this.registerObject(interface_1.REQUEST_CTX_KEY, ctx);
16
+ // register res
17
+ this.registerObject('res', {});
16
18
  if (ctx.logger) {
17
19
  // register contextLogger
18
20
  this.registerObject('logger', ctx.logger);
@@ -18,6 +18,7 @@ export declare class FunctionDefinition implements IObjectDefinition {
18
18
  asynchronous: boolean;
19
19
  handlerProps: any[];
20
20
  createFrom: any;
21
+ allowDowngrade: boolean;
21
22
  protected innerAutowire: boolean;
22
23
  protected innerScope: ScopeEnum;
23
24
  getAttr(key: ObjectIdentifier): any;
@@ -23,6 +23,7 @@ class FunctionDefinition {
23
23
  this.namespace = '';
24
24
  this.asynchronous = true;
25
25
  this.handlerProps = [];
26
+ this.allowDowngrade = false;
26
27
  // 函数工厂创建的对象默认不需要自动装配
27
28
  this.innerAutowire = false;
28
29
  this.innerScope = decorator_1.ScopeEnum.Singleton;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectCreator = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
+ const error_1 = require("../error");
5
6
  class ObjectCreator {
6
7
  constructor(definition) {
7
8
  this.definition = definition;
@@ -64,7 +65,7 @@ class ObjectCreator {
64
65
  let inst;
65
66
  if (this.definition.constructMethod) {
66
67
  const fn = Clzz[this.definition.constructMethod];
67
- if ((0, decorator_1.isAsyncFunction)(fn)) {
68
+ if (decorator_1.Types.isAsyncFunction(fn)) {
68
69
  inst = await fn.apply(Clzz, args);
69
70
  }
70
71
  else {
@@ -85,14 +86,14 @@ class ObjectCreator {
85
86
  const inst = obj;
86
87
  // after properties set then do init
87
88
  if (this.definition.initMethod && inst[this.definition.initMethod]) {
88
- if ((0, decorator_1.isGeneratorFunction)(inst[this.definition.initMethod]) ||
89
- (0, decorator_1.isAsyncFunction)(inst[this.definition.initMethod])) {
90
- throw new Error(`${this.definition.id} not valid by context.get, Use context.getAsync instead!`);
89
+ if (decorator_1.Types.isGeneratorFunction(inst[this.definition.initMethod]) ||
90
+ decorator_1.Types.isAsyncFunction(inst[this.definition.initMethod])) {
91
+ throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
91
92
  }
92
93
  else {
93
94
  const rt = inst[this.definition.initMethod].call(inst);
94
- if ((0, decorator_1.isPromise)(rt)) {
95
- throw new Error(`${this.definition.id} not valid by context.get, Use context.getAsync instead!`);
95
+ if (decorator_1.Types.isPromise(rt)) {
96
+ throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
96
97
  }
97
98
  }
98
99
  }
@@ -106,7 +107,7 @@ class ObjectCreator {
106
107
  const inst = obj;
107
108
  if (this.definition.initMethod && inst[this.definition.initMethod]) {
108
109
  const initFn = inst[this.definition.initMethod];
109
- if ((0, decorator_1.isAsyncFunction)(initFn)) {
110
+ if (decorator_1.Types.isAsyncFunction(initFn)) {
110
111
  await initFn.call(inst);
111
112
  }
112
113
  else {
@@ -139,7 +140,7 @@ class ObjectCreator {
139
140
  async doDestroyAsync(obj) {
140
141
  if (this.definition.destroyMethod && obj[this.definition.destroyMethod]) {
141
142
  const fn = obj[this.definition.destroyMethod];
142
- if ((0, decorator_1.isAsyncFunction)(fn)) {
143
+ if (decorator_1.Types.isAsyncFunction(fn)) {
143
144
  await fn.call(obj);
144
145
  }
145
146
  else {
@@ -20,6 +20,7 @@ export declare class ObjectDefinition implements IObjectDefinition {
20
20
  namespace: string;
21
21
  handlerProps: any[];
22
22
  createFrom: any;
23
+ allowDowngrade: boolean;
23
24
  constructor();
24
25
  set asynchronous(asynchronous: boolean);
25
26
  isAsync(): boolean;
@@ -23,6 +23,7 @@ class ObjectDefinition {
23
23
  this.properties = new properties_1.ObjectProperties();
24
24
  this.namespace = '';
25
25
  this.handlerProps = [];
26
+ this.allowDowngrade = false;
26
27
  this.creator = new objectCreator_1.ObjectCreator(this);
27
28
  }
28
29
  set asynchronous(asynchronous) {
@@ -2,12 +2,31 @@ interface ErrorOption {
2
2
  cause?: Error;
3
3
  status?: number;
4
4
  }
5
+ interface Convertable {
6
+ [key: string]: string | number;
7
+ }
8
+ declare type ConvertString<T extends Convertable, Group extends string> = {
9
+ [P in keyof T]: P extends string ? T[P] extends number ? `${Uppercase<Group>}_${T[P]}` : never : never;
10
+ };
11
+ /**
12
+ * Register error group and code, return the standard ErrorCode
13
+ * @param errorGroup
14
+ * @param errorCodeMapping
15
+ */
16
+ export declare function registerErrorCode<T extends Convertable, G extends string>(errorGroup: G, errorCodeMapping: T): ConvertString<T, G>;
5
17
  export declare class MidwayError extends Error {
6
- code: number;
7
- status: number;
18
+ code: number | string;
8
19
  cause: Error;
9
20
  constructor(message: string, options?: ErrorOption);
10
- constructor(message: string, code: number, options?: ErrorOption);
21
+ constructor(message: string, code: string, options?: ErrorOption);
22
+ }
23
+ export declare type ResOrMessage = string | {
24
+ message: string;
25
+ };
26
+ export declare class MidwayHttpError extends MidwayError {
27
+ status: number;
28
+ constructor(resOrMessage: ResOrMessage, status: number);
29
+ constructor(resOrMessage: ResOrMessage, status: number, code: string, options?: ErrorOption);
11
30
  }
12
31
  export {};
13
32
  //# sourceMappingURL=base.d.ts.map
@@ -1,19 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayError = void 0;
4
- const code_1 = require("./code");
3
+ exports.MidwayHttpError = exports.MidwayError = exports.registerErrorCode = void 0;
4
+ const codeGroup = new Set();
5
+ /**
6
+ * Register error group and code, return the standard ErrorCode
7
+ * @param errorGroup
8
+ * @param errorCodeMapping
9
+ */
10
+ function registerErrorCode(errorGroup, errorCodeMapping) {
11
+ if (codeGroup.has(errorGroup)) {
12
+ throw new MidwayError(`Error group ${errorGroup} is duplicated, please check before adding.`);
13
+ }
14
+ else {
15
+ codeGroup.add(errorGroup);
16
+ }
17
+ const newCodeEnum = {};
18
+ // ERROR => GROUP_10000
19
+ for (const errKey in errorCodeMapping) {
20
+ newCodeEnum[errKey] =
21
+ errorGroup.toUpperCase() +
22
+ '_' +
23
+ String(errorCodeMapping[errKey]).toUpperCase();
24
+ }
25
+ return newCodeEnum;
26
+ }
27
+ exports.registerErrorCode = registerErrorCode;
5
28
  class MidwayError extends Error {
6
29
  constructor(message, code, options) {
7
30
  super(message);
8
- if (typeof code !== 'number') {
31
+ if (!code || typeof code === 'object') {
9
32
  options = code;
10
- code = code_1.FrameworkErrorEnum.UNKNOWN;
33
+ code = 'MIDWAY_10000';
11
34
  }
12
35
  this.name = this.constructor.name;
13
36
  this.code = code;
14
37
  this.cause = options === null || options === void 0 ? void 0 : options.cause;
15
- this.status = options === null || options === void 0 ? void 0 : options.status;
16
38
  }
17
39
  }
18
40
  exports.MidwayError = MidwayError;
41
+ class MidwayHttpError extends MidwayError {
42
+ constructor(resOrMessage, status, code, options) {
43
+ super(typeof resOrMessage === 'string' ? resOrMessage : resOrMessage.message, code !== null && code !== void 0 ? code : String(status), options);
44
+ this.status = status;
45
+ }
46
+ }
47
+ exports.MidwayHttpError = MidwayHttpError;
19
48
  //# sourceMappingURL=base.js.map
@@ -1,5 +1,18 @@
1
1
  import { MidwayError } from './base';
2
2
  import { ObjectIdentifier } from '@midwayjs/decorator';
3
+ export declare const FrameworkErrorEnum: {
4
+ readonly UNKNOWN: "MIDWAY_10000";
5
+ readonly COMMON: "MIDWAY_10001";
6
+ readonly PARAM_TYPE: "MIDWAY_10002";
7
+ readonly DEFINITION_NOT_FOUND: "MIDWAY_10003";
8
+ readonly FEATURE_NO_LONGER_SUPPORTED: "MIDWAY_10004";
9
+ readonly FEATURE_NOT_IMPLEMENTED: "MIDWAY_10004";
10
+ readonly MISSING_CONFIG: "MIDWAY_10006";
11
+ readonly MISSING_RESOLVER: "MIDWAY_10007";
12
+ readonly DUPLICATE_ROUTER: "MIDWAY_10008";
13
+ readonly USE_WRONG_METHOD: "MIDWAY_10009";
14
+ readonly SINGLETON_INJECT_REQUEST: "MIDWAY_10010";
15
+ };
3
16
  export declare class MidwayCommonError extends MidwayError {
4
17
  constructor(message: string);
5
18
  }
@@ -15,7 +28,22 @@ export declare class MidwayDefinitionNotFoundError extends MidwayError {
15
28
  export declare class MidwayFeatureNoLongerSupportedError extends MidwayError {
16
29
  constructor(message?: string);
17
30
  }
18
- export declare class MidwayValidationError extends MidwayError {
19
- constructor(message: any, status: any, cause: any);
31
+ export declare class MidwayFeatureNotImplementedError extends MidwayError {
32
+ constructor(message?: string);
33
+ }
34
+ export declare class MidwayConfigMissingError extends MidwayError {
35
+ constructor(configKey: string);
36
+ }
37
+ export declare class MidwayResolverMissingError extends MidwayError {
38
+ constructor(type: string);
39
+ }
40
+ export declare class MidwayDuplicateRouteError extends MidwayError {
41
+ constructor(routerUrl: string, existPos: string, existPosOther: string);
42
+ }
43
+ export declare class MidwayUseWrongMethodError extends MidwayError {
44
+ constructor(wrongMethod: string, replacedMethod: string, describeKey?: string);
45
+ }
46
+ export declare class MidwaySingletonInjectRequestError extends MidwayError {
47
+ constructor(singletonScopeName: string, requestScopeName: string);
20
48
  }
21
49
  //# sourceMappingURL=framework.d.ts.map
@@ -1,23 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayValidationError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = void 0;
3
+ exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
4
4
  const base_1 = require("./base");
5
- const code_1 = require("./code");
5
+ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
6
+ UNKNOWN: 10000,
7
+ COMMON: 10001,
8
+ PARAM_TYPE: 10002,
9
+ DEFINITION_NOT_FOUND: 10003,
10
+ FEATURE_NO_LONGER_SUPPORTED: 10004,
11
+ FEATURE_NOT_IMPLEMENTED: 10004,
12
+ MISSING_CONFIG: 10006,
13
+ MISSING_RESOLVER: 10007,
14
+ DUPLICATE_ROUTER: 10008,
15
+ USE_WRONG_METHOD: 10009,
16
+ SINGLETON_INJECT_REQUEST: 10010,
17
+ });
6
18
  class MidwayCommonError extends base_1.MidwayError {
7
19
  constructor(message) {
8
- super(message, code_1.FrameworkErrorEnum.COMMON);
20
+ super(message, exports.FrameworkErrorEnum.COMMON);
9
21
  }
10
22
  }
11
23
  exports.MidwayCommonError = MidwayCommonError;
12
24
  class MidwayParameterError extends base_1.MidwayError {
13
25
  constructor(message) {
14
- super(message !== null && message !== void 0 ? message : 'Parameter type not match', code_1.FrameworkErrorEnum.PARAM_TYPE);
26
+ super(message !== null && message !== void 0 ? message : 'Parameter type not match', exports.FrameworkErrorEnum.PARAM_TYPE);
15
27
  }
16
28
  }
17
29
  exports.MidwayParameterError = MidwayParameterError;
18
30
  class MidwayDefinitionNotFoundError extends base_1.MidwayError {
19
31
  constructor(identifier) {
20
- super(`${identifier} is not valid in current context`, code_1.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
32
+ super(`${identifier} is not valid in current context`, exports.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
21
33
  this[MidwayDefinitionNotFoundError.type] =
22
34
  MidwayDefinitionNotFoundError.type;
23
35
  }
@@ -36,17 +48,48 @@ exports.MidwayDefinitionNotFoundError = MidwayDefinitionNotFoundError;
36
48
  MidwayDefinitionNotFoundError.type = Symbol.for('#NotFoundError');
37
49
  class MidwayFeatureNoLongerSupportedError extends base_1.MidwayError {
38
50
  constructor(message) {
39
- super('This feature no longer supported \n' + message, code_1.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
51
+ super('This feature no longer supported \n' + message, exports.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
40
52
  }
41
53
  }
42
54
  exports.MidwayFeatureNoLongerSupportedError = MidwayFeatureNoLongerSupportedError;
43
- class MidwayValidationError extends base_1.MidwayError {
44
- constructor(message, status, cause) {
45
- super(message, code_1.FrameworkErrorEnum.VALIDATE_FAIL, {
46
- status,
47
- cause,
48
- });
55
+ class MidwayFeatureNotImplementedError extends base_1.MidwayError {
56
+ constructor(message) {
57
+ super('This feature not implemented \n' + message, exports.FrameworkErrorEnum.FEATURE_NOT_IMPLEMENTED);
58
+ }
59
+ }
60
+ exports.MidwayFeatureNotImplementedError = MidwayFeatureNotImplementedError;
61
+ class MidwayConfigMissingError extends base_1.MidwayError {
62
+ constructor(configKey) {
63
+ super(`Can't found config key "${configKey}" in your config, please set it first`, exports.FrameworkErrorEnum.MISSING_CONFIG);
64
+ }
65
+ }
66
+ exports.MidwayConfigMissingError = MidwayConfigMissingError;
67
+ class MidwayResolverMissingError extends base_1.MidwayError {
68
+ constructor(type) {
69
+ super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
70
+ }
71
+ }
72
+ exports.MidwayResolverMissingError = MidwayResolverMissingError;
73
+ class MidwayDuplicateRouteError extends base_1.MidwayError {
74
+ constructor(routerUrl, existPos, existPosOther) {
75
+ super(`Duplicate router "${routerUrl}" at "${existPos}" and "${existPosOther}"`, exports.FrameworkErrorEnum.DUPLICATE_ROUTER);
76
+ }
77
+ }
78
+ exports.MidwayDuplicateRouteError = MidwayDuplicateRouteError;
79
+ class MidwayUseWrongMethodError extends base_1.MidwayError {
80
+ constructor(wrongMethod, replacedMethod, describeKey) {
81
+ const text = describeKey
82
+ ? `${describeKey} not valid by ${wrongMethod}, Use ${replacedMethod} instead!`
83
+ : `You should not invoked by ${wrongMethod}, Use ${replacedMethod} instead!`;
84
+ super(text, exports.FrameworkErrorEnum.USE_WRONG_METHOD);
85
+ }
86
+ }
87
+ exports.MidwayUseWrongMethodError = MidwayUseWrongMethodError;
88
+ class MidwaySingletonInjectRequestError extends base_1.MidwayError {
89
+ constructor(singletonScopeName, requestScopeName) {
90
+ const text = `${singletonScopeName} with singleton scope can't implicitly inject ${requestScopeName} with request scope directly, please add @Scope(ScopeEnum.Request, { allowDowngrade: true }) in ${requestScopeName}.`;
91
+ super(text, exports.FrameworkErrorEnum.SINGLETON_INJECT_REQUEST);
49
92
  }
50
93
  }
51
- exports.MidwayValidationError = MidwayValidationError;
94
+ exports.MidwaySingletonInjectRequestError = MidwaySingletonInjectRequestError;
52
95
  //# sourceMappingURL=framework.js.map