@midwayjs/core 3.0.0-beta.12 → 3.0.0-beta.16

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.
@@ -0,0 +1,11 @@
1
+ export declare abstract class DataListener<T> {
2
+ private innerData;
3
+ protected init(): Promise<void>;
4
+ abstract initData(): T;
5
+ abstract onData(callback: (data: T) => void): any;
6
+ protected setData(data: T): void;
7
+ getData(): T;
8
+ stop(): Promise<void>;
9
+ protected destroyListener(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=dataListener.d.ts.map
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DataListener = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ class DataListener {
15
+ async init() {
16
+ this.innerData = await this.initData();
17
+ await this.onData(this.setData.bind(this));
18
+ }
19
+ setData(data) {
20
+ this.innerData = data;
21
+ }
22
+ getData() {
23
+ return this.innerData;
24
+ }
25
+ async stop() {
26
+ await this.destroyListener();
27
+ }
28
+ async destroyListener() { }
29
+ }
30
+ __decorate([
31
+ (0, decorator_1.Init)(),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", []),
34
+ __metadata("design:returntype", Promise)
35
+ ], DataListener.prototype, "init", null);
36
+ __decorate([
37
+ (0, decorator_1.Destroy)(),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", []),
40
+ __metadata("design:returntype", Promise)
41
+ ], DataListener.prototype, "stop", null);
42
+ exports.DataListener = DataListener;
43
+ //# sourceMappingURL=dataListener.js.map
@@ -47,7 +47,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
47
47
  continue;
48
48
  }
49
49
  }
50
- else if ((0, decorator_1.isRegExp)(resolveFilter.pattern)) {
50
+ else if (decorator_1.TYPES.isRegExp(resolveFilter.pattern)) {
51
51
  if (resolveFilter.pattern.test(file)) {
52
52
  const exports = resolveFilter.ignoreRequire
53
53
  ? undefined
@@ -232,7 +232,7 @@ class WebRouterCollector {
232
232
  return urlMatchList
233
233
  .map(item => {
234
234
  const urlString = item.url.toString();
235
- const weightArr = (0, decorator_1.isRegExp)(item.url)
235
+ const weightArr = decorator_1.TYPES.isRegExp(item.url)
236
236
  ? urlString.split('\\/')
237
237
  : urlString.split('/');
238
238
  let weight = 0;
@@ -144,16 +144,16 @@ class ContainerConfiguration {
144
144
  }
145
145
  getConfigurationExport(exports) {
146
146
  const mods = [];
147
- if ((0, decorator_1.isClass)(exports) ||
148
- (0, decorator_1.isFunction)(exports) ||
147
+ if (decorator_1.TYPES.isClass(exports) ||
148
+ decorator_1.TYPES.isFunction(exports) ||
149
149
  exports instanceof configuration_1.FunctionalConfiguration) {
150
150
  mods.push(exports);
151
151
  }
152
152
  else {
153
153
  for (const m in exports) {
154
154
  const module = exports[m];
155
- if ((0, decorator_1.isClass)(module) ||
156
- (0, decorator_1.isFunction)(module) ||
155
+ if (decorator_1.TYPES.isClass(module) ||
156
+ decorator_1.TYPES.isFunction(module) ||
157
157
  module instanceof configuration_1.FunctionalConfiguration) {
158
158
  mods.push(module);
159
159
  }
@@ -240,13 +240,13 @@ class MidwayContainer {
240
240
  (_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.run(this);
241
241
  }
242
242
  bindClass(exports, options) {
243
- if ((0, decorator_1.isClass)(exports) || (0, decorator_1.isFunction)(exports)) {
243
+ if (decorator_1.TYPES.isClass(exports) || decorator_1.TYPES.isFunction(exports)) {
244
244
  this.bindModule(exports, options);
245
245
  }
246
246
  else {
247
247
  for (const m in exports) {
248
248
  const module = exports[m];
249
- if ((0, decorator_1.isClass)(module) || (0, decorator_1.isFunction)(module)) {
249
+ if (decorator_1.TYPES.isClass(module) || decorator_1.TYPES.isFunction(module)) {
250
250
  this.bindModule(module, options);
251
251
  }
252
252
  }
@@ -254,7 +254,7 @@ class MidwayContainer {
254
254
  }
255
255
  bind(identifier, target, options) {
256
256
  var _a;
257
- if ((0, decorator_1.isClass)(identifier) || (0, decorator_1.isFunction)(identifier)) {
257
+ if (decorator_1.TYPES.isClass(identifier) || decorator_1.TYPES.isFunction(identifier)) {
258
258
  return this.bindModule(identifier, target);
259
259
  }
260
260
  if (this.registry.hasDefinition(identifier)) {
@@ -262,13 +262,13 @@ class MidwayContainer {
262
262
  return;
263
263
  }
264
264
  let definition;
265
- if ((0, decorator_1.isClass)(target)) {
265
+ if (decorator_1.TYPES.isClass(target)) {
266
266
  definition = new objectDefinition_1.ObjectDefinition();
267
267
  definition.name = (0, decorator_1.getProviderName)(target);
268
268
  }
269
269
  else {
270
270
  definition = new functionDefinition_1.FunctionDefinition();
271
- if (!(0, decorator_1.isAsyncFunction)(target)) {
271
+ if (!decorator_1.TYPES.isAsyncFunction(target)) {
272
272
  definition.asynchronous = false;
273
273
  }
274
274
  definition.name = definition.id;
@@ -327,7 +327,7 @@ class MidwayContainer {
327
327
  }
328
328
  }
329
329
  bindModule(module, options) {
330
- if ((0, decorator_1.isClass)(module)) {
330
+ if (decorator_1.TYPES.isClass(module)) {
331
331
  const providerId = (0, decorator_1.getProviderUUId)(module);
332
332
  if (providerId) {
333
333
  this.identifierMapping.saveClassRelation(module, options === null || options === void 0 ? void 0 : options.namespace);
@@ -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);
@@ -65,7 +65,7 @@ class ObjectCreator {
65
65
  let inst;
66
66
  if (this.definition.constructMethod) {
67
67
  const fn = Clzz[this.definition.constructMethod];
68
- if ((0, decorator_1.isAsyncFunction)(fn)) {
68
+ if (decorator_1.TYPES.isAsyncFunction(fn)) {
69
69
  inst = await fn.apply(Clzz, args);
70
70
  }
71
71
  else {
@@ -86,13 +86,13 @@ class ObjectCreator {
86
86
  const inst = obj;
87
87
  // after properties set then do init
88
88
  if (this.definition.initMethod && inst[this.definition.initMethod]) {
89
- if ((0, decorator_1.isGeneratorFunction)(inst[this.definition.initMethod]) ||
90
- (0, decorator_1.isAsyncFunction)(inst[this.definition.initMethod])) {
89
+ if (decorator_1.TYPES.isGeneratorFunction(inst[this.definition.initMethod]) ||
90
+ decorator_1.TYPES.isAsyncFunction(inst[this.definition.initMethod])) {
91
91
  throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
92
92
  }
93
93
  else {
94
94
  const rt = inst[this.definition.initMethod].call(inst);
95
- if ((0, decorator_1.isPromise)(rt)) {
95
+ if (decorator_1.TYPES.isPromise(rt)) {
96
96
  throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
97
97
  }
98
98
  }
@@ -107,7 +107,7 @@ class ObjectCreator {
107
107
  const inst = obj;
108
108
  if (this.definition.initMethod && inst[this.definition.initMethod]) {
109
109
  const initFn = inst[this.definition.initMethod];
110
- if ((0, decorator_1.isAsyncFunction)(initFn)) {
110
+ if (decorator_1.TYPES.isAsyncFunction(initFn)) {
111
111
  await initFn.call(inst);
112
112
  }
113
113
  else {
@@ -140,7 +140,7 @@ class ObjectCreator {
140
140
  async doDestroyAsync(obj) {
141
141
  if (this.definition.destroyMethod && obj[this.definition.destroyMethod]) {
142
142
  const fn = obj[this.definition.destroyMethod];
143
- if ((0, decorator_1.isAsyncFunction)(fn)) {
143
+ if (decorator_1.TYPES.isAsyncFunction(fn)) {
144
144
  await fn.call(obj);
145
145
  }
146
146
  else {
@@ -49,53 +49,98 @@ export declare enum HttpStatus {
49
49
  GATEWAY_TIMEOUT = 504,
50
50
  HTTP_VERSION_NOT_SUPPORTED = 505
51
51
  }
52
+ /**
53
+ * 400 http error, Means that the request can be fulfilled because of the bad syntax.
54
+ */
52
55
  export declare class BadRequestError extends MidwayHttpError {
53
- constructor(resOrMessage: ResOrMessage);
56
+ constructor(resOrMessage?: ResOrMessage);
54
57
  }
58
+ /**
59
+ * 401 http error, Means that the request was legal, but the server is rejecting to answer it. For the use when authentication is required and has failed or has not yet been provided.
60
+ */
55
61
  export declare class UnauthorizedError extends MidwayHttpError {
56
- constructor(resOrMessage: ResOrMessage);
62
+ constructor(resOrMessage?: ResOrMessage);
57
63
  }
64
+ /**
65
+ * 4o4 http error, Means that the requested page cannot be found at the moment, but it may be available again in the future.
66
+ */
58
67
  export declare class NotFoundError extends MidwayHttpError {
59
- constructor(resOrMessage: ResOrMessage);
68
+ constructor(resOrMessage?: ResOrMessage);
60
69
  }
70
+ /**
71
+ * 403 http error, Means that the request is legal, but the server is rejecting to answer it.
72
+ */
61
73
  export declare class ForbiddenError extends MidwayHttpError {
62
- constructor(resOrMessage: ResOrMessage);
74
+ constructor(resOrMessage?: ResOrMessage);
63
75
  }
76
+ /**
77
+ * 406 http error, Means that the server can only generate an answer which the client doesn't accept.
78
+ */
64
79
  export declare class NotAcceptableError extends MidwayHttpError {
65
- constructor(resOrMessage: ResOrMessage);
80
+ constructor(resOrMessage?: ResOrMessage);
66
81
  }
82
+ /**
83
+ * 408 http error, Means that the server timed out waiting for the request.
84
+ */
67
85
  export declare class RequestTimeoutError extends MidwayHttpError {
68
- constructor(resOrMessage: ResOrMessage);
86
+ constructor(resOrMessage?: ResOrMessage);
69
87
  }
88
+ /**
89
+ * 409 http error, Means that the request cannot be completed, because of a conflict in the request.
90
+ */
70
91
  export declare class ConflictError extends MidwayHttpError {
71
- constructor(resOrMessage: ResOrMessage);
92
+ constructor(resOrMessage?: ResOrMessage);
72
93
  }
94
+ /**
95
+ * 410 http error, Means that the requested page is not available anymore.
96
+ */
73
97
  export declare class GoneError extends MidwayHttpError {
74
- constructor(resOrMessage: ResOrMessage);
98
+ constructor(resOrMessage?: ResOrMessage);
75
99
  }
100
+ /**
101
+ * 413 http error, Means that the request entity is too large and that's why the server won't accept the request.
102
+ */
76
103
  export declare class PayloadTooLargeError extends MidwayHttpError {
77
- constructor(resOrMessage: ResOrMessage);
104
+ constructor(resOrMessage?: ResOrMessage);
78
105
  }
106
+ /**
107
+ * 415 http error, Means that the media type is not supported and that's why the server won't accept the request.
108
+ */
79
109
  export declare class UnsupportedMediaTypeError extends MidwayHttpError {
80
- constructor(resOrMessage: ResOrMessage);
110
+ constructor(resOrMessage?: ResOrMessage);
81
111
  }
82
- export declare class UnprocessableError extends MidwayHttpError {
83
- constructor(resOrMessage: ResOrMessage);
112
+ export declare class UnprocessableEntityError extends MidwayHttpError {
113
+ constructor(resOrMessage?: ResOrMessage);
84
114
  }
115
+ /**
116
+ * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
117
+ */
85
118
  export declare class InternalServerErrorError extends MidwayHttpError {
86
- constructor(resOrMessage: ResOrMessage);
119
+ constructor(resOrMessage?: ResOrMessage);
87
120
  }
88
- declare class NotImplementedError extends MidwayHttpError {
89
- constructor(resOrMessage: ResOrMessage);
121
+ /**
122
+ * 501 http error, Means that the server doesn't recognize the request method or it lacks the ability to fulfill the request.
123
+ */
124
+ export declare class NotImplementedError extends MidwayHttpError {
125
+ constructor(resOrMessage?: ResOrMessage);
90
126
  }
127
+ /**
128
+ * 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.
129
+ */
91
130
  export declare class BadGatewayError extends MidwayHttpError {
92
- constructor(resOrMessage: ResOrMessage);
131
+ constructor(resOrMessage?: ResOrMessage);
93
132
  }
133
+ /**
134
+ * 503 http error, Means that the server is not available now (It may be overloaded or down).
135
+ */
94
136
  export declare class ServiceUnavailableError extends MidwayHttpError {
95
- constructor(resOrMessage: ResOrMessage);
137
+ constructor(resOrMessage?: ResOrMessage);
96
138
  }
139
+ /**
140
+ * 504 http error, Means that the server was acting as a gateway or proxy and it didn't get answer on time from the upstream server.
141
+ */
97
142
  export declare class GatewayTimeoutError extends MidwayHttpError {
98
- constructor(resOrMessage: ResOrMessage);
143
+ constructor(resOrMessage?: ResOrMessage);
99
144
  }
100
145
  export declare const httpError: {
101
146
  BadRequestError: typeof BadRequestError;
@@ -108,12 +153,11 @@ export declare const httpError: {
108
153
  GoneError: typeof GoneError;
109
154
  PayloadTooLargeError: typeof PayloadTooLargeError;
110
155
  UnsupportedMediaTypeError: typeof UnsupportedMediaTypeError;
111
- UnprocessableError: typeof UnprocessableError;
156
+ UnprocessableEntityError: typeof UnprocessableEntityError;
112
157
  InternalServerErrorError: typeof InternalServerErrorError;
113
158
  NotImplementedError: typeof NotImplementedError;
114
159
  BadGatewayError: typeof BadGatewayError;
115
160
  ServiceUnavailableError: typeof ServiceUnavailableError;
116
161
  GatewayTimeoutError: typeof GatewayTimeoutError;
117
162
  };
118
- export {};
119
163
  //# sourceMappingURL=http.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.InternalServerErrorError = exports.UnprocessableError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
3
+ exports.httpError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerErrorError = exports.UnprocessableEntityError = exports.UnsupportedMediaTypeError = exports.PayloadTooLargeError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.NotAcceptableError = exports.ForbiddenError = exports.NotFoundError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpStatus = void 0;
4
4
  const base_1 = require("./base");
5
5
  var HttpStatus;
6
6
  (function (HttpStatus) {
@@ -53,97 +53,143 @@ var HttpStatus;
53
53
  HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
54
54
  HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
55
55
  })(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));
56
+ /**
57
+ * 400 http error, Means that the request can be fulfilled because of the bad syntax.
58
+ */
56
59
  class BadRequestError extends base_1.MidwayHttpError {
57
- constructor(resOrMessage) {
60
+ constructor(resOrMessage = 'Bad Request') {
58
61
  super(resOrMessage, HttpStatus.BAD_REQUEST);
59
62
  }
60
63
  }
61
64
  exports.BadRequestError = BadRequestError;
65
+ /**
66
+ * 401 http error, Means that the request was legal, but the server is rejecting to answer it. For the use when authentication is required and has failed or has not yet been provided.
67
+ */
62
68
  class UnauthorizedError extends base_1.MidwayHttpError {
63
- constructor(resOrMessage) {
69
+ constructor(resOrMessage = 'Unauthorized') {
64
70
  super(resOrMessage, HttpStatus.UNAUTHORIZED);
65
71
  }
66
72
  }
67
73
  exports.UnauthorizedError = UnauthorizedError;
74
+ /**
75
+ * 4o4 http error, Means that the requested page cannot be found at the moment, but it may be available again in the future.
76
+ */
68
77
  class NotFoundError extends base_1.MidwayHttpError {
69
- constructor(resOrMessage) {
78
+ constructor(resOrMessage = 'Not Found') {
70
79
  super(resOrMessage, HttpStatus.NOT_FOUND);
71
80
  }
72
81
  }
73
82
  exports.NotFoundError = NotFoundError;
83
+ /**
84
+ * 403 http error, Means that the request is legal, but the server is rejecting to answer it.
85
+ */
74
86
  class ForbiddenError extends base_1.MidwayHttpError {
75
- constructor(resOrMessage) {
87
+ constructor(resOrMessage = 'Forbidden') {
76
88
  super(resOrMessage, HttpStatus.FORBIDDEN);
77
89
  }
78
90
  }
79
91
  exports.ForbiddenError = ForbiddenError;
92
+ /**
93
+ * 406 http error, Means that the server can only generate an answer which the client doesn't accept.
94
+ */
80
95
  class NotAcceptableError extends base_1.MidwayHttpError {
81
- constructor(resOrMessage) {
96
+ constructor(resOrMessage = 'Not Acceptable') {
82
97
  super(resOrMessage, HttpStatus.NOT_ACCEPTABLE);
83
98
  }
84
99
  }
85
100
  exports.NotAcceptableError = NotAcceptableError;
101
+ /**
102
+ * 408 http error, Means that the server timed out waiting for the request.
103
+ */
86
104
  class RequestTimeoutError extends base_1.MidwayHttpError {
87
- constructor(resOrMessage) {
105
+ constructor(resOrMessage = 'Request Timeout') {
88
106
  super(resOrMessage, HttpStatus.REQUEST_TIMEOUT);
89
107
  }
90
108
  }
91
109
  exports.RequestTimeoutError = RequestTimeoutError;
110
+ /**
111
+ * 409 http error, Means that the request cannot be completed, because of a conflict in the request.
112
+ */
92
113
  class ConflictError extends base_1.MidwayHttpError {
93
- constructor(resOrMessage) {
114
+ constructor(resOrMessage = 'Conflict') {
94
115
  super(resOrMessage, HttpStatus.CONFLICT);
95
116
  }
96
117
  }
97
118
  exports.ConflictError = ConflictError;
119
+ /**
120
+ * 410 http error, Means that the requested page is not available anymore.
121
+ */
98
122
  class GoneError extends base_1.MidwayHttpError {
99
- constructor(resOrMessage) {
123
+ constructor(resOrMessage = 'Gone') {
100
124
  super(resOrMessage, HttpStatus.GONE);
101
125
  }
102
126
  }
103
127
  exports.GoneError = GoneError;
128
+ /**
129
+ * 413 http error, Means that the request entity is too large and that's why the server won't accept the request.
130
+ */
104
131
  class PayloadTooLargeError extends base_1.MidwayHttpError {
105
- constructor(resOrMessage) {
132
+ constructor(resOrMessage = 'Request Entity Too Large') {
106
133
  super(resOrMessage, HttpStatus.PAYLOAD_TOO_LARGE);
107
134
  }
108
135
  }
109
136
  exports.PayloadTooLargeError = PayloadTooLargeError;
137
+ /**
138
+ * 415 http error, Means that the media type is not supported and that's why the server won't accept the request.
139
+ */
110
140
  class UnsupportedMediaTypeError extends base_1.MidwayHttpError {
111
- constructor(resOrMessage) {
141
+ constructor(resOrMessage = 'Unsupported Media Type') {
112
142
  super(resOrMessage, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
113
143
  }
114
144
  }
115
145
  exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
116
- class UnprocessableError extends base_1.MidwayHttpError {
117
- constructor(resOrMessage) {
146
+ class UnprocessableEntityError extends base_1.MidwayHttpError {
147
+ constructor(resOrMessage = 'Unprocessable Entity') {
118
148
  super(resOrMessage, HttpStatus.UNPROCESSABLE_ENTITY);
119
149
  }
120
150
  }
121
- exports.UnprocessableError = UnprocessableError;
151
+ exports.UnprocessableEntityError = UnprocessableEntityError;
152
+ /**
153
+ * 500 http error, Is a generic error and users receive this error message when there is no more suitable specific message.
154
+ */
122
155
  class InternalServerErrorError extends base_1.MidwayHttpError {
123
- constructor(resOrMessage) {
156
+ constructor(resOrMessage = 'Internal Server Error') {
124
157
  super(resOrMessage, HttpStatus.INTERNAL_SERVER_ERROR);
125
158
  }
126
159
  }
127
160
  exports.InternalServerErrorError = InternalServerErrorError;
161
+ /**
162
+ * 501 http error, Means that the server doesn't recognize the request method or it lacks the ability to fulfill the request.
163
+ */
128
164
  class NotImplementedError extends base_1.MidwayHttpError {
129
- constructor(resOrMessage) {
165
+ constructor(resOrMessage = 'Not Implemented') {
130
166
  super(resOrMessage, HttpStatus.NOT_IMPLEMENTED);
131
167
  }
132
168
  }
169
+ exports.NotImplementedError = NotImplementedError;
170
+ /**
171
+ * 502 http error, Means that the server was acting as a gateway or proxy and it received an invalid answer from the upstream server.
172
+ */
133
173
  class BadGatewayError extends base_1.MidwayHttpError {
134
- constructor(resOrMessage) {
174
+ constructor(resOrMessage = 'Bad Gateway') {
135
175
  super(resOrMessage, HttpStatus.BAD_GATEWAY);
136
176
  }
137
177
  }
138
178
  exports.BadGatewayError = BadGatewayError;
179
+ /**
180
+ * 503 http error, Means that the server is not available now (It may be overloaded or down).
181
+ */
139
182
  class ServiceUnavailableError extends base_1.MidwayHttpError {
140
- constructor(resOrMessage) {
183
+ constructor(resOrMessage = 'Service Unavailable') {
141
184
  super(resOrMessage, HttpStatus.SERVICE_UNAVAILABLE);
142
185
  }
143
186
  }
144
187
  exports.ServiceUnavailableError = ServiceUnavailableError;
188
+ /**
189
+ * 504 http error, Means that the server was acting as a gateway or proxy and it didn't get answer on time from the upstream server.
190
+ */
145
191
  class GatewayTimeoutError extends base_1.MidwayHttpError {
146
- constructor(resOrMessage) {
192
+ constructor(resOrMessage = 'Gateway Timeout') {
147
193
  super(resOrMessage, HttpStatus.GATEWAY_TIMEOUT);
148
194
  }
149
195
  }
@@ -159,7 +205,7 @@ exports.httpError = {
159
205
  GoneError,
160
206
  PayloadTooLargeError,
161
207
  UnsupportedMediaTypeError,
162
- UnprocessableError,
208
+ UnprocessableEntityError,
163
209
  InternalServerErrorError,
164
210
  NotImplementedError,
165
211
  BadGatewayError,
@@ -1,4 +1,4 @@
1
1
  export * from './base';
2
- export * from './http';
2
+ export { HttpStatus, httpError } from './http';
3
3
  export * from './framework';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -10,7 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.httpError = exports.HttpStatus = void 0;
13
14
  __exportStar(require("./base"), exports);
14
- __exportStar(require("./http"), exports);
15
+ var http_1 = require("./http");
16
+ Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return http_1.HttpStatus; } });
17
+ Object.defineProperty(exports, "httpError", { enumerable: true, get: function () { return http_1.httpError; } });
15
18
  __exportStar(require("./framework"), exports);
16
19
  //# sourceMappingURL=index.js.map
@@ -4,10 +4,12 @@ export declare class FunctionalConfiguration {
4
4
  private readyHandler;
5
5
  private stopHandler;
6
6
  private configLoadHandler;
7
+ private serverReadyHandler;
7
8
  private options;
8
9
  constructor(options: InjectionConfigurationOptions);
9
10
  onConfigLoad(configLoadHandler: ((container: IMidwayContainer, app: IMidwayApplication) => any) | IMidwayContainer, app?: IMidwayApplication): any;
10
11
  onReady(readyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
12
+ onServerReady(serverReadyHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
11
13
  onStop(stopHandler: ((container: IMidwayContainer, app: IMidwayApplication) => void) | IMidwayContainer, app?: IMidwayApplication): any;
12
14
  getConfigurationOptions(): InjectionConfigurationOptions;
13
15
  }
@@ -7,6 +7,7 @@ class FunctionalConfiguration {
7
7
  this.readyHandler = () => { };
8
8
  this.stopHandler = () => { };
9
9
  this.configLoadHandler = () => { };
10
+ this.serverReadyHandler = () => { };
10
11
  }
11
12
  onConfigLoad(configLoadHandler, app) {
12
13
  if (typeof configLoadHandler === 'function') {
@@ -26,6 +27,15 @@ class FunctionalConfiguration {
26
27
  }
27
28
  return this;
28
29
  }
30
+ onServerReady(serverReadyHandler, app) {
31
+ if (typeof serverReadyHandler === 'function') {
32
+ this.serverReadyHandler = serverReadyHandler;
33
+ }
34
+ else {
35
+ return this.serverReadyHandler(serverReadyHandler, app);
36
+ }
37
+ return this;
38
+ }
29
39
  onStop(stopHandler, app) {
30
40
  if (typeof stopHandler === 'function') {
31
41
  this.stopHandler = stopHandler;
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { MidwayDecoratorService } from './service/decoratorService';
22
22
  export * from './service/pipelineService';
23
23
  export * from './util/contextUtil';
24
24
  export * from './common/serviceFactory';
25
+ export * from './common/dataListener';
25
26
  export * from './common/fileDetector';
26
27
  export * from './common/webGenerator';
27
28
  export * from './common/middlewareManager';
package/dist/index.js CHANGED
@@ -56,6 +56,7 @@ Object.defineProperty(exports, "MidwayDecoratorService", { enumerable: true, get
56
56
  __exportStar(require("./service/pipelineService"), exports);
57
57
  __exportStar(require("./util/contextUtil"), exports);
58
58
  __exportStar(require("./common/serviceFactory"), exports);
59
+ __exportStar(require("./common/dataListener"), exports);
59
60
  __exportStar(require("./common/fileDetector"), exports);
60
61
  __exportStar(require("./common/webGenerator"), exports);
61
62
  __exportStar(require("./common/middlewareManager"), exports);
@@ -14,9 +14,19 @@ export declare type ServiceFactoryConfigOption<OPTIONS> = {
14
14
  [key: string]: PowerPartial<OPTIONS>;
15
15
  };
16
16
  };
17
- declare type ConfigType<T> = T extends (...args: any[]) => any ? PowerPartial<ReturnType<T>> : PowerPartial<T>;
17
+ declare type ConfigType<T> = T extends (...args: any[]) => any ? Writable<PowerPartial<ReturnType<T>>> : Writable<PowerPartial<T>>;
18
+ /**
19
+ * Get definition from config
20
+ */
18
21
  export declare type FileConfigOption<T, K = unknown> = K extends keyof ConfigType<T> ? Pick<ConfigType<T>, K> : ConfigType<T>;
19
22
  /**
23
+ * Make object property writeable
24
+ */
25
+ export declare type Writable<T> = {
26
+ -readonly [P in keyof T]: T[P];
27
+ };
28
+ /**
29
+ * Lifecycle Definition
20
30
  * 生命周期定义
21
31
  */
22
32
  export interface ILifeCycle extends Partial<IObjectLifeCycle> {
@@ -29,8 +39,8 @@ export declare type ObjectContext = {
29
39
  originName?: string;
30
40
  };
31
41
  /**
42
+ * Abstract Object Factory
32
43
  * 对象容器抽象
33
- * 默认用Xml容器实现一个
34
44
  */
35
45
  export interface IObjectFactory {
36
46
  registry: IObjectDefinitionRegistry;
@@ -46,6 +56,10 @@ export declare enum ObjectLifeCycleEvent {
46
56
  AFTER_INIT = "afterObjectInit",
47
57
  BEFORE_DESTROY = "beforeObjectDestroy"
48
58
  }
59
+ /**
60
+ * Object Lifecycle
61
+ * 对象生命周期
62
+ */
49
63
  export interface IObjectLifeCycle {
50
64
  onBeforeBind(fn: (Clzz: any, options: {
51
65
  context: IMidwayContainer;
@@ -72,6 +86,7 @@ export interface IObjectLifeCycle {
72
86
  }) => void): any;
73
87
  }
74
88
  /**
89
+ * Object Definition
75
90
  * 对象描述定义
76
91
  */
77
92
  export interface IObjectDefinition {
@@ -123,6 +138,7 @@ export interface IObjectCreator {
123
138
  doDestroyAsync(obj: any): Promise<void>;
124
139
  }
125
140
  /**
141
+ * Object Definition Registry
126
142
  * 对象定义存储容器
127
143
  */
128
144
  export interface IObjectDefinitionRegistry {
@@ -452,10 +468,5 @@ export interface MidwayAppInfo {
452
468
  export interface MidwayConfig extends FileConfigOption<typeof _default> {
453
469
  [customConfigKey: string]: unknown;
454
470
  }
455
- export interface TranslateOptions {
456
- lang?: string;
457
- group?: string;
458
- args?: any;
459
- }
460
471
  export {};
461
472
  //# sourceMappingURL=interface.d.ts.map