@grandlinex/kernel 1.1.1 → 1.2.1

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.
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const swagger_mate_1 = require("@grandlinex/swagger-mate");
10
10
  const index_js_1 = require("../classes/index.js");
11
- const index_js_2 = require("../annotation/index.js");
12
11
  let ApiAuthTestAction = class ApiAuthTestAction extends index_js_1.RouteApiAction {
13
12
  async handler({ data, res }) {
14
13
  this.debug(data.userid);
@@ -16,16 +15,11 @@ let ApiAuthTestAction = class ApiAuthTestAction extends index_js_1.RouteApiActio
16
15
  }
17
16
  };
18
17
  ApiAuthTestAction = __decorate([
19
- (0, swagger_mate_1.SPath)({
20
- '/test/auth': {
21
- get: {
22
- operationId: 'testAuth',
23
- summary: 'Test user auth',
24
- tags: ['kernel'],
25
- responses: swagger_mate_1.SPathUtil.defaultResponse('200', '403'),
26
- },
27
- },
28
- }),
29
- (0, index_js_2.Route)('GET', '/test/auth')
18
+ (0, swagger_mate_1.Route)('GET', '/test/auth', {
19
+ operationId: 'testAuth',
20
+ summary: 'Test user auth',
21
+ tags: ['kernel'],
22
+ responseCodes: ['200', '403'],
23
+ })
30
24
  ], ApiAuthTestAction);
31
25
  exports.default = ApiAuthTestAction;
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const swagger_mate_1 = require("@grandlinex/swagger-mate");
10
10
  const index_js_1 = require("../classes/index.js");
11
- const index_js_2 = require("../annotation/index.js");
12
11
  let ApiVersionAction = class ApiVersionAction extends index_js_1.RouteApiAction {
13
12
  async handler({ res, extension }) {
14
13
  extension.done();
@@ -16,24 +15,21 @@ let ApiVersionAction = class ApiVersionAction extends index_js_1.RouteApiAction
16
15
  }
17
16
  };
18
17
  ApiVersionAction = __decorate([
19
- (0, swagger_mate_1.SPath)({
20
- '/version': {
21
- get: {
22
- operationId: 'getVersion',
23
- summary: 'Get API version',
24
- tags: ['kernel'],
25
- responses: swagger_mate_1.SPathUtil.jsonResponse('200', {
26
- type: 'object',
27
- properties: {
28
- api: {
29
- type: 'number',
30
- },
31
- },
32
- required: ['api'],
33
- }, false, '403'),
18
+ (0, swagger_mate_1.Route)('GET', '/version', {
19
+ mode: swagger_mate_1.ActionMode.DMZ,
20
+ operationId: 'getVersion',
21
+ summary: 'Get API version',
22
+ tags: ['kernel'],
23
+ responseSchema: {
24
+ type: 'object',
25
+ properties: {
26
+ api: {
27
+ type: 'number',
28
+ },
34
29
  },
30
+ required: ['api'],
35
31
  },
36
- }),
37
- (0, index_js_2.Route)('GET', '/version', index_js_1.ActionMode.DMZ)
32
+ responseCodes: ['200', '403'],
33
+ })
38
34
  ], ApiVersionAction);
39
35
  exports.default = ApiVersionAction;
@@ -8,19 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const swagger_mate_1 = require("@grandlinex/swagger-mate");
10
10
  const index_js_1 = require("../classes/index.js");
11
- const index_js_2 = require("../annotation/index.js");
12
- const schema = {
13
- type: 'object',
14
- properties: {
15
- username: {
16
- type: 'string',
17
- },
18
- token: {
19
- type: 'string',
20
- },
21
- },
22
- required: ['username', 'token'],
23
- };
24
11
  let GetTokenAction = class GetTokenAction extends index_js_1.RouteApiAction {
25
12
  async handler({ req, res, extension, body, }) {
26
13
  const cc = this.getKernel().getCryptoClient();
@@ -40,25 +27,33 @@ let GetTokenAction = class GetTokenAction extends index_js_1.RouteApiAction {
40
27
  }
41
28
  };
42
29
  GetTokenAction = __decorate([
43
- (0, swagger_mate_1.SPath)({
44
- '/token': {
45
- post: {
46
- operationId: 'getToken',
47
- summary: 'Get API token',
48
- tags: ['kernel'],
49
- requestBody: swagger_mate_1.SPathUtil.jsonBody(schema),
50
- responses: swagger_mate_1.SPathUtil.jsonResponse('200', {
51
- type: 'object',
52
- properties: {
53
- token: {
54
- type: 'string',
55
- },
56
- },
57
- required: ['token'],
58
- }, false, '403'),
30
+ (0, swagger_mate_1.Route)('POST', '/token', {
31
+ mode: swagger_mate_1.ActionMode.DMZ,
32
+ operationId: 'getToken',
33
+ summary: 'Get API token',
34
+ tags: ['kernel'],
35
+ requestSchema: {
36
+ type: 'object',
37
+ properties: {
38
+ username: {
39
+ type: 'string',
40
+ },
41
+ token: {
42
+ type: 'string',
43
+ },
44
+ },
45
+ required: ['username', 'token'],
46
+ },
47
+ responseSchema: {
48
+ type: 'object',
49
+ properties: {
50
+ token: {
51
+ type: 'string',
52
+ },
59
53
  },
54
+ required: ['token'],
60
55
  },
61
- }),
62
- (0, index_js_2.Route)('POST', '/token', index_js_1.ActionMode.DMZ, schema)
56
+ responseCodes: ['200', '403'],
57
+ })
63
58
  ], GetTokenAction);
64
59
  exports.default = GetTokenAction;
@@ -1,16 +1,11 @@
1
1
  import { CoreAction, IDataBase } from '@grandlinex/core';
2
- import { ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
2
+ import { ActionMode, ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
3
3
  import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
4
4
  import { XActionEvent, XRequest, XResponse } from '../lib/express.js';
5
- export declare enum ActionMode {
6
- 'DEFAULT' = 0,
7
- 'DMZ' = 1,
8
- 'DMZ_WITH_USER' = 2
9
- }
10
5
  export default abstract class BaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends CoreAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
11
6
  mode: ActionMode;
12
7
  forceDebug: boolean;
13
- schema: SSchemaEl | null;
8
+ requestSchema: SSchemaEl | null;
14
9
  constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
15
10
  abstract handler(event: XActionEvent): Promise<void>;
16
11
  static validateSchema(error: ErrorType, schema: SSchemaEl, key: string, field: any, required?: boolean): void;
@@ -1,23 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionMode = void 0;
4
3
  const core_1 = require("@grandlinex/core");
5
4
  const swagger_mate_1 = require("@grandlinex/swagger-mate");
6
5
  const index_js_1 = require("./timing/index.js");
7
6
  const BaseUserAgent_js_1 = require("./BaseUserAgent.js");
8
- var ActionMode;
9
- (function (ActionMode) {
10
- ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
11
- ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
12
- ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
13
- })(ActionMode || (exports.ActionMode = ActionMode = {}));
14
7
  class BaseAction extends core_1.CoreAction {
15
8
  constructor(chanel, module) {
16
9
  super(chanel, module);
17
10
  this.secureHandler = this.secureHandler.bind(this);
18
- this.mode = ActionMode.DEFAULT;
11
+ this.mode = swagger_mate_1.ActionMode.DEFAULT;
19
12
  this.forceDebug = false;
20
- this.schema = null;
13
+ this.requestSchema = null;
21
14
  }
22
15
  static validateSchema(error, schema, key, field, required = true) {
23
16
  if ((0, swagger_mate_1.isSwaggerRef)(schema)) {
@@ -91,7 +84,7 @@ class BaseAction extends core_1.CoreAction {
91
84
  }
92
85
  }
93
86
  bodyValidation(req) {
94
- if (!this.schema) {
87
+ if (!this.requestSchema) {
95
88
  return null;
96
89
  }
97
90
  if (!req.body) {
@@ -102,7 +95,7 @@ class BaseAction extends core_1.CoreAction {
102
95
  global: [],
103
96
  field: [],
104
97
  };
105
- BaseAction.validateSchema(error, this.schema, 'body', req.body);
98
+ BaseAction.validateSchema(error, this.requestSchema, 'body', req.body);
106
99
  if (error.field.length > 0 || error.global.length > 0) {
107
100
  return error;
108
101
  }
@@ -128,18 +121,18 @@ class BaseAction extends core_1.CoreAction {
128
121
  res.status(504).send('internal server error');
129
122
  return;
130
123
  }
131
- if (this.mode === ActionMode.DMZ) {
124
+ if (this.mode === swagger_mate_1.ActionMode.DMZ) {
132
125
  auth.stop();
133
126
  try {
134
127
  let body = null;
135
- if (this.schema) {
128
+ if (this.requestSchema) {
136
129
  body = this.bodyValidation(req);
137
130
  }
138
131
  if ((0, swagger_mate_1.isErrorType)(body)) {
139
132
  res.status(400).send(body);
140
133
  return;
141
134
  }
142
- if (this.schema && body === null) {
135
+ if (this.requestSchema && body === null) {
143
136
  res.sendStatus(400);
144
137
  return;
145
138
  }
@@ -168,14 +161,14 @@ class BaseAction extends core_1.CoreAction {
168
161
  if (dat && typeof dat !== 'number') {
169
162
  try {
170
163
  let body = null;
171
- if (this.schema) {
164
+ if (this.requestSchema) {
172
165
  body = this.bodyValidation(req);
173
166
  }
174
167
  if ((0, swagger_mate_1.isErrorType)(body)) {
175
168
  res.status(400).send(body);
176
169
  return;
177
170
  }
178
- if (this.schema && body === null) {
171
+ if (this.requestSchema && body === null) {
179
172
  res.sendStatus(400);
180
173
  return;
181
174
  }
@@ -198,17 +191,17 @@ class BaseAction extends core_1.CoreAction {
198
191
  }
199
192
  }
200
193
  }
201
- else if (this.mode === ActionMode.DMZ_WITH_USER) {
194
+ else if (this.mode === swagger_mate_1.ActionMode.DMZ_WITH_USER) {
202
195
  try {
203
196
  let body = null;
204
- if (this.schema) {
197
+ if (this.requestSchema) {
205
198
  body = this.bodyValidation(req);
206
199
  }
207
200
  if ((0, swagger_mate_1.isErrorType)(body)) {
208
201
  res.status(400).send(body);
209
202
  return;
210
203
  }
211
- if (this.schema && body === null) {
204
+ if (this.requestSchema && body === null) {
212
205
  res.sendStatus(400);
213
206
  return;
214
207
  }
@@ -1,5 +1,6 @@
1
1
  import { IDataBase } from '@grandlinex/core';
2
- import { ActionTypes, IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
2
+ import { ActionTypes } from '@grandlinex/swagger-mate';
3
+ import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
3
4
  import BaseAction from './BaseAction.js';
4
5
  export default abstract class BaseApiAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends BaseAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
5
6
  exmod: undefined | IBaseKernelModule<K>;
@@ -3,23 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const index_js_1 = require("../annotation/index.js");
6
+ const swagger_mate_1 = require("@grandlinex/swagger-mate");
7
7
  const BaseApiAction_js_1 = __importDefault(require("./BaseApiAction.js"));
8
8
  class RouteApiAction extends BaseApiAction_js_1.default {
9
9
  constructor(module, extMod) {
10
10
  super('GET', 'action', module, extMod);
11
11
  this.exmod = extMod;
12
- const meta = (0, index_js_1.getRouteMeta)(this);
13
- if (!meta) {
12
+ const route = (0, swagger_mate_1.getRouteMeta)(this);
13
+ if (!route) {
14
14
  throw this.lError('No route meta found for action');
15
15
  }
16
- const { type, path, mode, schema } = meta;
16
+ const { type, path, meta } = route;
17
17
  this.type = type;
18
18
  this.channel = path;
19
- if (mode) {
20
- this.setMode(mode);
19
+ if (meta?.mode) {
20
+ this.setMode(meta.mode);
21
21
  }
22
- this.schema = schema ?? null;
22
+ this.requestSchema = meta?.requestSchema ?? null;
23
23
  }
24
24
  }
25
25
  exports.default = RouteApiAction;
@@ -1,5 +1,5 @@
1
1
  import { CoreBridge as BaseBridge, CoreCache as BaseCache, CoreClient as BaseClient, CoreElement as BaseElement, CoreLoopService as BaseLoopService, CoreService as BaseService } from '@grandlinex/core';
2
- import BaseAction, { ActionMode } from './BaseAction.js';
2
+ import BaseAction from './BaseAction.js';
3
3
  import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
4
4
  import BaseKernelModule from './BaseKernelModule.js';
5
5
  import BaseApiAction from './BaseApiAction.js';
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
9
9
  export * from './BaseUserAgent.js';
10
10
  export * from './BaseAuthProvider.js';
11
11
  export * from './timing/index.js';
12
- export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
12
+ export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.ActionMode = exports.keepRawBody = exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.RouteApiAction = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
42
+ exports.keepRawBody = exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.RouteApiAction = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
43
43
  const core_1 = require("@grandlinex/core");
44
44
  Object.defineProperty(exports, "BaseBridge", { enumerable: true, get: function () { return core_1.CoreBridge; } });
45
45
  Object.defineProperty(exports, "BaseCache", { enumerable: true, get: function () { return core_1.CoreCache; } });
@@ -47,9 +47,8 @@ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function (
47
47
  Object.defineProperty(exports, "BaseElement", { enumerable: true, get: function () { return core_1.CoreElement; } });
48
48
  Object.defineProperty(exports, "BaseLoopService", { enumerable: true, get: function () { return core_1.CoreLoopService; } });
49
49
  Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return core_1.CoreService; } });
50
- const BaseAction_js_1 = __importStar(require("./BaseAction.js"));
50
+ const BaseAction_js_1 = __importDefault(require("./BaseAction.js"));
51
51
  exports.BaseAction = BaseAction_js_1.default;
52
- Object.defineProperty(exports, "ActionMode", { enumerable: true, get: function () { return BaseAction_js_1.ActionMode; } });
53
52
  const BaseEndpoint_js_1 = __importStar(require("./BaseEndpoint.js"));
54
53
  exports.BaseEndpoint = BaseEndpoint_js_1.default;
55
54
  Object.defineProperty(exports, "keepRawBody", { enumerable: true, get: function () { return BaseEndpoint_js_1.keepRawBody; } });
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
6
6
  import KernelModule from './KernelModule.js';
7
7
  export * from './actions/index.js';
8
8
  export * from './api/index.js';
9
- export * from './annotation/index.js';
10
9
  export * from './classes/index.js';
11
10
  export * from './modules/crypto/index.js';
12
11
  export * from './lib/index.js';
package/dist/cjs/index.js CHANGED
@@ -28,7 +28,6 @@ const KernelModule_js_1 = __importDefault(require("./KernelModule.js"));
28
28
  exports.KernelModule = KernelModule_js_1.default;
29
29
  __exportStar(require("./actions/index.js"), exports);
30
30
  __exportStar(require("./api/index.js"), exports);
31
- __exportStar(require("./annotation/index.js"), exports);
32
31
  __exportStar(require("./classes/index.js"), exports);
33
32
  __exportStar(require("./modules/crypto/index.js"), exports);
34
33
  __exportStar(require("./lib/index.js"), exports);
@@ -5,7 +5,6 @@ import { IAuthProvider, JwtExtend, JwtToken } from '../classes/index.js';
5
5
  import EntitySchemaExtender from './EntitySchemaExtender.js';
6
6
  import { XActionEvent, XRequest } from './express.js';
7
7
  export { EntitySchemaExtender };
8
- export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
9
8
  export interface ICClient<T extends JwtExtend = JwtExtend> extends ICoreCClient {
10
9
  setAuthProvider(provider: IAuthProvider<T>): boolean;
11
10
  jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
@@ -4,9 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  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;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { SPath, SPathUtil } from '@grandlinex/swagger-mate';
7
+ import { Route } from '@grandlinex/swagger-mate';
8
8
  import { RouteApiAction } from '../classes/index.js';
9
- import { Route } from '../annotation/index.js';
10
9
  let ApiAuthTestAction = class ApiAuthTestAction extends RouteApiAction {
11
10
  async handler({ data, res }) {
12
11
  this.debug(data.userid);
@@ -14,16 +13,11 @@ let ApiAuthTestAction = class ApiAuthTestAction extends RouteApiAction {
14
13
  }
15
14
  };
16
15
  ApiAuthTestAction = __decorate([
17
- SPath({
18
- '/test/auth': {
19
- get: {
20
- operationId: 'testAuth',
21
- summary: 'Test user auth',
22
- tags: ['kernel'],
23
- responses: SPathUtil.defaultResponse('200', '403'),
24
- },
25
- },
26
- }),
27
- Route('GET', '/test/auth')
16
+ Route('GET', '/test/auth', {
17
+ operationId: 'testAuth',
18
+ summary: 'Test user auth',
19
+ tags: ['kernel'],
20
+ responseCodes: ['200', '403'],
21
+ })
28
22
  ], ApiAuthTestAction);
29
23
  export default ApiAuthTestAction;
@@ -4,9 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  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;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { SPath, SPathUtil } from '@grandlinex/swagger-mate';
8
- import { ActionMode, RouteApiAction } from '../classes/index.js';
9
- import { Route } from '../annotation/index.js';
7
+ import { ActionMode, Route } from '@grandlinex/swagger-mate';
8
+ import { RouteApiAction } from '../classes/index.js';
10
9
  let ApiVersionAction = class ApiVersionAction extends RouteApiAction {
11
10
  async handler({ res, extension }) {
12
11
  extension.done();
@@ -14,24 +13,21 @@ let ApiVersionAction = class ApiVersionAction extends RouteApiAction {
14
13
  }
15
14
  };
16
15
  ApiVersionAction = __decorate([
17
- SPath({
18
- '/version': {
19
- get: {
20
- operationId: 'getVersion',
21
- summary: 'Get API version',
22
- tags: ['kernel'],
23
- responses: SPathUtil.jsonResponse('200', {
24
- type: 'object',
25
- properties: {
26
- api: {
27
- type: 'number',
28
- },
29
- },
30
- required: ['api'],
31
- }, false, '403'),
16
+ Route('GET', '/version', {
17
+ mode: ActionMode.DMZ,
18
+ operationId: 'getVersion',
19
+ summary: 'Get API version',
20
+ tags: ['kernel'],
21
+ responseSchema: {
22
+ type: 'object',
23
+ properties: {
24
+ api: {
25
+ type: 'number',
26
+ },
32
27
  },
28
+ required: ['api'],
33
29
  },
34
- }),
35
- Route('GET', '/version', ActionMode.DMZ)
30
+ responseCodes: ['200', '403'],
31
+ })
36
32
  ], ApiVersionAction);
37
33
  export default ApiVersionAction;
@@ -4,21 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  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;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { SPath, SPathUtil } from '@grandlinex/swagger-mate';
8
- import { ActionMode, RouteApiAction } from '../classes/index.js';
9
- import { Route } from '../annotation/index.js';
10
- const schema = {
11
- type: 'object',
12
- properties: {
13
- username: {
14
- type: 'string',
15
- },
16
- token: {
17
- type: 'string',
18
- },
19
- },
20
- required: ['username', 'token'],
21
- };
7
+ import { ActionMode, Route } from '@grandlinex/swagger-mate';
8
+ import { RouteApiAction } from '../classes/index.js';
22
9
  let GetTokenAction = class GetTokenAction extends RouteApiAction {
23
10
  async handler({ req, res, extension, body, }) {
24
11
  const cc = this.getKernel().getCryptoClient();
@@ -38,25 +25,33 @@ let GetTokenAction = class GetTokenAction extends RouteApiAction {
38
25
  }
39
26
  };
40
27
  GetTokenAction = __decorate([
41
- SPath({
42
- '/token': {
43
- post: {
44
- operationId: 'getToken',
45
- summary: 'Get API token',
46
- tags: ['kernel'],
47
- requestBody: SPathUtil.jsonBody(schema),
48
- responses: SPathUtil.jsonResponse('200', {
49
- type: 'object',
50
- properties: {
51
- token: {
52
- type: 'string',
53
- },
54
- },
55
- required: ['token'],
56
- }, false, '403'),
28
+ Route('POST', '/token', {
29
+ mode: ActionMode.DMZ,
30
+ operationId: 'getToken',
31
+ summary: 'Get API token',
32
+ tags: ['kernel'],
33
+ requestSchema: {
34
+ type: 'object',
35
+ properties: {
36
+ username: {
37
+ type: 'string',
38
+ },
39
+ token: {
40
+ type: 'string',
41
+ },
42
+ },
43
+ required: ['username', 'token'],
44
+ },
45
+ responseSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ token: {
49
+ type: 'string',
50
+ },
57
51
  },
52
+ required: ['token'],
58
53
  },
59
- }),
60
- Route('POST', '/token', ActionMode.DMZ, schema)
54
+ responseCodes: ['200', '403'],
55
+ })
61
56
  ], GetTokenAction);
62
57
  export default GetTokenAction;
@@ -1,16 +1,11 @@
1
1
  import { CoreAction, IDataBase } from '@grandlinex/core';
2
- import { ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
2
+ import { ActionMode, ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
3
3
  import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
4
4
  import { XActionEvent, XRequest, XResponse } from '../lib/express.js';
5
- export declare enum ActionMode {
6
- 'DEFAULT' = 0,
7
- 'DMZ' = 1,
8
- 'DMZ_WITH_USER' = 2
9
- }
10
5
  export default abstract class BaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends CoreAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
11
6
  mode: ActionMode;
12
7
  forceDebug: boolean;
13
- schema: SSchemaEl | null;
8
+ requestSchema: SSchemaEl | null;
14
9
  constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
15
10
  abstract handler(event: XActionEvent): Promise<void>;
16
11
  static validateSchema(error: ErrorType, schema: SSchemaEl, key: string, field: any, required?: boolean): void;
@@ -1,20 +1,14 @@
1
1
  import { CoreAction } from '@grandlinex/core';
2
- import { isErrorType, isSwaggerRef, } from '@grandlinex/swagger-mate';
2
+ import { ActionMode, isErrorType, isSwaggerRef, } from '@grandlinex/swagger-mate';
3
3
  import { ExpressServerTiming } from './timing/index.js';
4
4
  import { BaseUserAgent } from './BaseUserAgent.js';
5
- export var ActionMode;
6
- (function (ActionMode) {
7
- ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
8
- ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
9
- ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
10
- })(ActionMode || (ActionMode = {}));
11
5
  export default class BaseAction extends CoreAction {
12
6
  constructor(chanel, module) {
13
7
  super(chanel, module);
14
8
  this.secureHandler = this.secureHandler.bind(this);
15
9
  this.mode = ActionMode.DEFAULT;
16
10
  this.forceDebug = false;
17
- this.schema = null;
11
+ this.requestSchema = null;
18
12
  }
19
13
  static validateSchema(error, schema, key, field, required = true) {
20
14
  if (isSwaggerRef(schema)) {
@@ -88,7 +82,7 @@ export default class BaseAction extends CoreAction {
88
82
  }
89
83
  }
90
84
  bodyValidation(req) {
91
- if (!this.schema) {
85
+ if (!this.requestSchema) {
92
86
  return null;
93
87
  }
94
88
  if (!req.body) {
@@ -99,7 +93,7 @@ export default class BaseAction extends CoreAction {
99
93
  global: [],
100
94
  field: [],
101
95
  };
102
- BaseAction.validateSchema(error, this.schema, 'body', req.body);
96
+ BaseAction.validateSchema(error, this.requestSchema, 'body', req.body);
103
97
  if (error.field.length > 0 || error.global.length > 0) {
104
98
  return error;
105
99
  }
@@ -129,14 +123,14 @@ export default class BaseAction extends CoreAction {
129
123
  auth.stop();
130
124
  try {
131
125
  let body = null;
132
- if (this.schema) {
126
+ if (this.requestSchema) {
133
127
  body = this.bodyValidation(req);
134
128
  }
135
129
  if (isErrorType(body)) {
136
130
  res.status(400).send(body);
137
131
  return;
138
132
  }
139
- if (this.schema && body === null) {
133
+ if (this.requestSchema && body === null) {
140
134
  res.sendStatus(400);
141
135
  return;
142
136
  }
@@ -165,14 +159,14 @@ export default class BaseAction extends CoreAction {
165
159
  if (dat && typeof dat !== 'number') {
166
160
  try {
167
161
  let body = null;
168
- if (this.schema) {
162
+ if (this.requestSchema) {
169
163
  body = this.bodyValidation(req);
170
164
  }
171
165
  if (isErrorType(body)) {
172
166
  res.status(400).send(body);
173
167
  return;
174
168
  }
175
- if (this.schema && body === null) {
169
+ if (this.requestSchema && body === null) {
176
170
  res.sendStatus(400);
177
171
  return;
178
172
  }
@@ -198,14 +192,14 @@ export default class BaseAction extends CoreAction {
198
192
  else if (this.mode === ActionMode.DMZ_WITH_USER) {
199
193
  try {
200
194
  let body = null;
201
- if (this.schema) {
195
+ if (this.requestSchema) {
202
196
  body = this.bodyValidation(req);
203
197
  }
204
198
  if (isErrorType(body)) {
205
199
  res.status(400).send(body);
206
200
  return;
207
201
  }
208
- if (this.schema && body === null) {
202
+ if (this.requestSchema && body === null) {
209
203
  res.sendStatus(400);
210
204
  return;
211
205
  }
@@ -1,5 +1,6 @@
1
1
  import { IDataBase } from '@grandlinex/core';
2
- import { ActionTypes, IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
2
+ import { ActionTypes } from '@grandlinex/swagger-mate';
3
+ import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
3
4
  import BaseAction from './BaseAction.js';
4
5
  export default abstract class BaseApiAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends BaseAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
5
6
  exmod: undefined | IBaseKernelModule<K>;
@@ -1,19 +1,19 @@
1
- import { getRouteMeta } from '../annotation/index.js';
1
+ import { getRouteMeta } from '@grandlinex/swagger-mate';
2
2
  import BaseApiAction from './BaseApiAction.js';
3
3
  export default class RouteApiAction extends BaseApiAction {
4
4
  constructor(module, extMod) {
5
5
  super('GET', 'action', module, extMod);
6
6
  this.exmod = extMod;
7
- const meta = getRouteMeta(this);
8
- if (!meta) {
7
+ const route = getRouteMeta(this);
8
+ if (!route) {
9
9
  throw this.lError('No route meta found for action');
10
10
  }
11
- const { type, path, mode, schema } = meta;
11
+ const { type, path, meta } = route;
12
12
  this.type = type;
13
13
  this.channel = path;
14
- if (mode) {
15
- this.setMode(mode);
14
+ if (meta?.mode) {
15
+ this.setMode(meta.mode);
16
16
  }
17
- this.schema = schema ?? null;
17
+ this.requestSchema = meta?.requestSchema ?? null;
18
18
  }
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import { CoreBridge as BaseBridge, CoreCache as BaseCache, CoreClient as BaseClient, CoreElement as BaseElement, CoreLoopService as BaseLoopService, CoreService as BaseService } from '@grandlinex/core';
2
- import BaseAction, { ActionMode } from './BaseAction.js';
2
+ import BaseAction from './BaseAction.js';
3
3
  import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
4
4
  import BaseKernelModule from './BaseKernelModule.js';
5
5
  import BaseApiAction from './BaseApiAction.js';
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
9
9
  export * from './BaseUserAgent.js';
10
10
  export * from './BaseAuthProvider.js';
11
11
  export * from './timing/index.js';
12
- export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
12
+ export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
@@ -1,5 +1,5 @@
1
1
  import { CoreBridge as BaseBridge, CoreCache as BaseCache, CoreClient as BaseClient, CoreElement as BaseElement, CoreLoopService as BaseLoopService, CoreService as BaseService, } from '@grandlinex/core';
2
- import BaseAction, { ActionMode } from './BaseAction.js';
2
+ import BaseAction from './BaseAction.js';
3
3
  import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
4
4
  import BaseKernelModule from './BaseKernelModule.js';
5
5
  import BaseApiAction from './BaseApiAction.js';
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
9
9
  export * from './BaseUserAgent.js';
10
10
  export * from './BaseAuthProvider.js';
11
11
  export * from './timing/index.js';
12
- export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
12
+ export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
6
6
  import KernelModule from './KernelModule.js';
7
7
  export * from './actions/index.js';
8
8
  export * from './api/index.js';
9
- export * from './annotation/index.js';
10
9
  export * from './classes/index.js';
11
10
  export * from './modules/crypto/index.js';
12
11
  export * from './lib/index.js';
package/dist/mjs/index.js CHANGED
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
6
6
  import KernelModule from './KernelModule.js';
7
7
  export * from './actions/index.js';
8
8
  export * from './api/index.js';
9
- export * from './annotation/index.js';
10
9
  export * from './classes/index.js';
11
10
  export * from './modules/crypto/index.js';
12
11
  export * from './lib/index.js';
@@ -5,7 +5,6 @@ import { IAuthProvider, JwtExtend, JwtToken } from '../classes/index.js';
5
5
  import EntitySchemaExtender from './EntitySchemaExtender.js';
6
6
  import { XActionEvent, XRequest } from './express.js';
7
7
  export { EntitySchemaExtender };
8
- export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
9
8
  export interface ICClient<T extends JwtExtend = JwtExtend> extends ICoreCClient {
10
9
  setAuthProvider(provider: IAuthProvider<T>): boolean;
11
10
  jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/kernel",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -46,16 +46,16 @@
46
46
  },
47
47
  "license": "BSD-3-Clause",
48
48
  "dependencies": {
49
- "reflect-metadata": "0.2.2",
50
- "@grandlinex/core": "1.1.1",
51
- "@grandlinex/swagger-mate": "1.1.1",
49
+ "@grandlinex/core": "1.2.0",
50
+ "@grandlinex/swagger-mate": "1.2.1",
51
+ "@types/express": "5.0.3",
52
+ "@types/jsonwebtoken": "9.0.10",
53
+ "@types/ms": "2.1.0",
52
54
  "axios": "1.11.0",
53
55
  "body-parser": "1.20.3",
54
56
  "express": "5.1.0",
55
57
  "jsonwebtoken": "9.0.2",
56
- "@types/express": "5.0.3",
57
- "@types/jsonwebtoken": "9.0.10",
58
- "@types/ms": "2.1.0"
58
+ "reflect-metadata": "0.2.2"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/jest": "29.5.14",
@@ -1,13 +0,0 @@
1
- import 'reflect-metadata';
2
- import { ObjectLike } from '@grandlinex/core';
3
- import { SSchemaEl } from '@grandlinex/swagger-mate';
4
- import { ActionTypes } from '../lib/index.js';
5
- import { ActionMode } from '../classes/index.js';
6
- export type RouteMeta = {
7
- type: ActionTypes;
8
- path: string;
9
- mode?: ActionMode;
10
- schema?: SSchemaEl;
11
- };
12
- export declare const Route: (type: ActionTypes, path: string, mode?: ActionMode, schema?: SSchemaEl) => ClassDecorator;
13
- export declare function getRouteMeta<T extends ObjectLike>(target: T): RouteMeta | undefined;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Route = void 0;
4
- exports.getRouteMeta = getRouteMeta;
5
- require("reflect-metadata");
6
- const routeKey = Symbol('route');
7
- const Route = (type, path, mode, schema) => {
8
- return (target) => {
9
- const metadata = {
10
- type,
11
- path,
12
- mode,
13
- schema,
14
- };
15
- Reflect.defineMetadata(routeKey, metadata, target.prototype);
16
- };
17
- };
18
- exports.Route = Route;
19
- function getRouteMeta(target) {
20
- return Reflect.getMetadata(routeKey, target.constructor.prototype);
21
- }
@@ -1,13 +0,0 @@
1
- import 'reflect-metadata';
2
- import { ObjectLike } from '@grandlinex/core';
3
- import { SSchemaEl } from '@grandlinex/swagger-mate';
4
- import { ActionTypes } from '../lib/index.js';
5
- import { ActionMode } from '../classes/index.js';
6
- export type RouteMeta = {
7
- type: ActionTypes;
8
- path: string;
9
- mode?: ActionMode;
10
- schema?: SSchemaEl;
11
- };
12
- export declare const Route: (type: ActionTypes, path: string, mode?: ActionMode, schema?: SSchemaEl) => ClassDecorator;
13
- export declare function getRouteMeta<T extends ObjectLike>(target: T): RouteMeta | undefined;
@@ -1,16 +0,0 @@
1
- import 'reflect-metadata';
2
- const routeKey = Symbol('route');
3
- export const Route = (type, path, mode, schema) => {
4
- return (target) => {
5
- const metadata = {
6
- type,
7
- path,
8
- mode,
9
- schema,
10
- };
11
- Reflect.defineMetadata(routeKey, metadata, target.prototype);
12
- };
13
- };
14
- export function getRouteMeta(target) {
15
- return Reflect.getMetadata(routeKey, target.constructor.prototype);
16
- }