@napp/dti-core 4.4.4 → 4.5.2

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/action.d.ts CHANGED
@@ -6,6 +6,7 @@ interface ODtiAction<RESULT, PARAM> {
6
6
  mode?: DtiMode;
7
7
  path?: string;
8
8
  validate?: (p: PARAM) => void;
9
+ sign?: (p: PARAM) => string;
9
10
  }
10
11
  export declare class DtiAction<RESULT, PARAM> {
11
12
  private opt;
@@ -16,6 +17,7 @@ export declare class DtiAction<RESULT, PARAM> {
16
17
  getPath(): string;
17
18
  getFullname(): string;
18
19
  validate(p: PARAM): void;
20
+ sign(p: PARAM): string;
19
21
  static define<RESULT, PARAM>(opt: ODtiAction<RESULT, PARAM>): DtiAction<RESULT, PARAM>;
20
22
  }
21
23
  export {};
package/action.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DtiAction = void 0;
4
4
  const common_1 = require("./common");
5
5
  class DtiAction {
6
+ opt;
6
7
  constructor(opt) {
7
8
  this.opt = opt;
8
9
  opt.route.regAction(this);
@@ -27,6 +28,12 @@ class DtiAction {
27
28
  this.opt.validate(p);
28
29
  }
29
30
  }
31
+ sign(p) {
32
+ if (this.opt.sign) {
33
+ return this.opt.sign(p);
34
+ }
35
+ return '';
36
+ }
30
37
  static define(opt) {
31
38
  return new DtiAction(opt);
32
39
  }
package/base62.js CHANGED
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Base62 = void 0;
7
7
  const base_x_1 = __importDefault(require("base-x"));
8
8
  class Base62 {
9
+ convert;
10
+ utf8Encode = new TextEncoder();
11
+ utf8Decoder = new TextDecoder();
9
12
  constructor(ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
10
- this.utf8Encode = new TextEncoder();
11
- this.utf8Decoder = new TextDecoder();
12
13
  this.convert = (0, base_x_1.default)(ALPHABET);
13
14
  }
14
15
  encode(str) {
@@ -0,0 +1,23 @@
1
+ import { DtiMode } from "./common";
2
+ import { DtiRoute } from "./route";
3
+ interface ODtiAction<RESULT, PARAM> {
4
+ name: string;
5
+ route: DtiRoute;
6
+ mode?: DtiMode;
7
+ path?: string;
8
+ validate?: (p: PARAM) => void;
9
+ sign?: (p: PARAM) => string;
10
+ }
11
+ export declare class DtiAction<RESULT, PARAM> {
12
+ private opt;
13
+ private constructor();
14
+ getName(): string;
15
+ getRoute(): DtiRoute;
16
+ getMode(): DtiMode;
17
+ getPath(): string;
18
+ getFullname(): string;
19
+ validate(p: PARAM): void;
20
+ sign(p: PARAM): string;
21
+ static define<RESULT, PARAM>(opt: ODtiAction<RESULT, PARAM>): DtiAction<RESULT, PARAM>;
22
+ }
23
+ export {};
package/esm/action.js ADDED
@@ -0,0 +1,37 @@
1
+ import { DtiMode } from "./common";
2
+ export class DtiAction {
3
+ opt;
4
+ constructor(opt) {
5
+ this.opt = opt;
6
+ opt.route.regAction(this);
7
+ }
8
+ getName() {
9
+ return this.opt.name;
10
+ }
11
+ getRoute() {
12
+ return this.opt.route;
13
+ }
14
+ getMode() {
15
+ return this.opt.mode || DtiMode.QString;
16
+ }
17
+ getPath() {
18
+ return '/' + (this.opt.path || this.getName());
19
+ }
20
+ getFullname() {
21
+ return `${this.getRoute().getFullname()}.${this.getName()}`;
22
+ }
23
+ validate(p) {
24
+ if (this.opt.validate) {
25
+ this.opt.validate(p);
26
+ }
27
+ }
28
+ sign(p) {
29
+ if (this.opt.sign) {
30
+ return this.opt.sign(p);
31
+ }
32
+ return '';
33
+ }
34
+ static define(opt) {
35
+ return new DtiAction(opt);
36
+ }
37
+ }
@@ -0,0 +1,8 @@
1
+ export declare class Base62 {
2
+ private convert;
3
+ private utf8Encode;
4
+ private utf8Decoder;
5
+ constructor(ALPHABET?: string);
6
+ encode(str: string): string;
7
+ decode(str: string): string;
8
+ }
package/esm/base62.js ADDED
@@ -0,0 +1,19 @@
1
+ import base from 'base-x';
2
+ export class Base62 {
3
+ convert;
4
+ utf8Encode = new TextEncoder();
5
+ utf8Decoder = new TextDecoder();
6
+ constructor(ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
7
+ this.convert = base(ALPHABET);
8
+ }
9
+ encode(str) {
10
+ let bytes = this.utf8Encode.encode(str);
11
+ let txt = this.convert.encode(bytes);
12
+ return txt;
13
+ }
14
+ decode(str) {
15
+ let bytes = this.convert.decode(str);
16
+ let txt = this.utf8Decoder.decode(bytes);
17
+ return txt;
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ export declare enum DtiMode {
2
+ QString = 1,
3
+ QJson = 2,
4
+ BJson = 3,
5
+ BFrom = 4
6
+ }
package/esm/common.js ADDED
@@ -0,0 +1,7 @@
1
+ export var DtiMode;
2
+ (function (DtiMode) {
3
+ DtiMode[DtiMode["QString"] = 1] = "QString";
4
+ DtiMode[DtiMode["QJson"] = 2] = "QJson";
5
+ DtiMode[DtiMode["BJson"] = 3] = "BJson";
6
+ DtiMode[DtiMode["BFrom"] = 4] = "BFrom";
7
+ })(DtiMode || (DtiMode = {}));
package/esm/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './common';
2
+ export * from './action';
3
+ export * from './route';
4
+ export * from './response';
5
+ export * from './base62';
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './common';
2
+ export * from './action';
3
+ export * from './route';
4
+ export * from './response';
5
+ export * from './base62';
@@ -0,0 +1,6 @@
1
+ declare const key: unique symbol;
2
+ export declare class DtiRawResponse {
3
+ private [key];
4
+ static is(obj: any): boolean;
5
+ }
6
+ export {};
@@ -0,0 +1,10 @@
1
+ const key = Symbol.for('DtiRawResponse_key');
2
+ export class DtiRawResponse {
3
+ [key] = key;
4
+ static is(obj) {
5
+ if (obj instanceof DtiRawResponse && obj[key] === key) {
6
+ return true;
7
+ }
8
+ return false;
9
+ }
10
+ }
package/esm/route.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { DtiAction } from "./action";
2
+ export interface ODtiRoute {
3
+ path?: string;
4
+ childrens?: DtiRoute[];
5
+ }
6
+ export declare class DtiRoute {
7
+ name: string;
8
+ private constructor();
9
+ private _parent?;
10
+ private _children?;
11
+ private _actions?;
12
+ private path?;
13
+ getChildroutes(): DtiRoute[];
14
+ regChildroute(route: DtiRoute): this;
15
+ getActions(): DtiAction<any, any>[];
16
+ regAction<RESULT, PARAM>(action: DtiAction<RESULT, PARAM>): this;
17
+ getNames(): string[];
18
+ getFullname(): string;
19
+ getPaths(): string[];
20
+ getLocalPath(): string;
21
+ static factory(name: string, opt?: ODtiRoute): DtiRoute;
22
+ }
package/esm/route.js ADDED
@@ -0,0 +1,69 @@
1
+ export class DtiRoute {
2
+ name;
3
+ constructor(name) {
4
+ this.name = name;
5
+ }
6
+ _parent;
7
+ _children;
8
+ _actions;
9
+ path;
10
+ getChildroutes() {
11
+ return this._children || [];
12
+ }
13
+ regChildroute(route) {
14
+ if (route._parent) {
15
+ throw new Error(`cannot register the route ("${route.name}") on route ("${this.name}"). already registered #"${route._parent.name}" `);
16
+ }
17
+ route._parent = this;
18
+ this._children = [...this._children || [], route];
19
+ return this;
20
+ }
21
+ getActions() {
22
+ return this._actions || [];
23
+ }
24
+ regAction(action) {
25
+ // if (action.getRoute()) {
26
+ // throw new Error(`the action(${action.name}) already registed. registered route(${action.route.name})`)
27
+ // }
28
+ let name = action.getName();
29
+ for (let a of this._actions || []) {
30
+ if (a.getName() === name) {
31
+ throw new Error(`the action(${name}) is registered`);
32
+ }
33
+ }
34
+ this._actions = [...this._actions || [], action];
35
+ return this;
36
+ }
37
+ getNames() {
38
+ if (this._parent) {
39
+ let paths = this._parent.getNames();
40
+ return [...paths, this.name];
41
+ }
42
+ return [this.name];
43
+ }
44
+ getFullname() {
45
+ return this.getNames().join('.');
46
+ }
47
+ getPaths() {
48
+ if (this._parent) {
49
+ let paths = this._parent.getPaths();
50
+ return [...paths, this.getLocalPath()];
51
+ }
52
+ return [this.getLocalPath()];
53
+ }
54
+ getLocalPath() {
55
+ return `/${this.path || this.name}`;
56
+ }
57
+ static factory(name, opt) {
58
+ let route = new DtiRoute(name);
59
+ if (opt?.path) {
60
+ route.path = opt.path;
61
+ }
62
+ if (opt?.childrens) {
63
+ for (let r of opt.childrens) {
64
+ route.regChildroute(r);
65
+ }
66
+ }
67
+ return route;
68
+ }
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napp/dti-core",
3
- "version": "4.4.4",
3
+ "version": "4.5.2",
4
4
  "description": "data transaction interface core library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,14 @@
11
11
  },
12
12
  "types": "index.d.ts",
13
13
  "main": "index.js",
14
+ "module": "esm/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "require": "./index.js",
18
+ "import": "./esm/index.js",
19
+ "types": "./index.d.ts"
20
+ }
21
+ },
14
22
  "keywords": [
15
23
  "napp",
16
24
  "Rest API",
package/response.js CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.DtiRawResponse = void 0;
5
4
  const key = Symbol.for('DtiRawResponse_key');
6
5
  class DtiRawResponse {
7
- constructor() {
8
- this[_a] = key;
9
- }
6
+ [key] = key;
10
7
  static is(obj) {
11
8
  if (obj instanceof DtiRawResponse && obj[key] === key) {
12
9
  return true;
@@ -15,4 +12,3 @@ class DtiRawResponse {
15
12
  }
16
13
  }
17
14
  exports.DtiRawResponse = DtiRawResponse;
18
- _a = key;
package/route.js CHANGED
@@ -2,9 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DtiRoute = void 0;
4
4
  class DtiRoute {
5
+ name;
5
6
  constructor(name) {
6
7
  this.name = name;
7
8
  }
9
+ _parent;
10
+ _children;
11
+ _actions;
12
+ path;
8
13
  getChildroutes() {
9
14
  return this._children || [];
10
15
  }
@@ -54,10 +59,10 @@ class DtiRoute {
54
59
  }
55
60
  static factory(name, opt) {
56
61
  let route = new DtiRoute(name);
57
- if (opt === null || opt === void 0 ? void 0 : opt.path) {
62
+ if (opt?.path) {
58
63
  route.path = opt.path;
59
64
  }
60
- if (opt === null || opt === void 0 ? void 0 : opt.childrens) {
65
+ if (opt?.childrens) {
61
66
  for (let r of opt.childrens) {
62
67
  route.regChildroute(r);
63
68
  }