@napp/dti-core 4.4.3 → 4.4.5
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/esm/action.d.ts +21 -0
- package/esm/action.js +30 -0
- package/esm/base62.d.ts +8 -0
- package/esm/base62.js +18 -0
- package/esm/common.d.ts +6 -0
- package/esm/common.js +7 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +5 -0
- package/esm/response.d.ts +6 -0
- package/esm/response.js +14 -0
- package/esm/route.d.ts +22 -0
- package/esm/route.js +64 -0
- package/package.json +9 -1
package/esm/action.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
10
|
+
export declare class DtiAction<RESULT, PARAM> {
|
|
11
|
+
private opt;
|
|
12
|
+
private constructor();
|
|
13
|
+
getName(): string;
|
|
14
|
+
getRoute(): DtiRoute;
|
|
15
|
+
getMode(): DtiMode;
|
|
16
|
+
getPath(): string;
|
|
17
|
+
getFullname(): string;
|
|
18
|
+
validate(p: PARAM): void;
|
|
19
|
+
static define<RESULT, PARAM>(opt: ODtiAction<RESULT, PARAM>): DtiAction<RESULT, PARAM>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/esm/action.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DtiMode } from "./common";
|
|
2
|
+
export class DtiAction {
|
|
3
|
+
constructor(opt) {
|
|
4
|
+
this.opt = opt;
|
|
5
|
+
opt.route.regAction(this);
|
|
6
|
+
}
|
|
7
|
+
getName() {
|
|
8
|
+
return this.opt.name;
|
|
9
|
+
}
|
|
10
|
+
getRoute() {
|
|
11
|
+
return this.opt.route;
|
|
12
|
+
}
|
|
13
|
+
getMode() {
|
|
14
|
+
return this.opt.mode || DtiMode.QString;
|
|
15
|
+
}
|
|
16
|
+
getPath() {
|
|
17
|
+
return '/' + (this.opt.path || this.getName());
|
|
18
|
+
}
|
|
19
|
+
getFullname() {
|
|
20
|
+
return `${this.getRoute().getFullname()}.${this.getName()}`;
|
|
21
|
+
}
|
|
22
|
+
validate(p) {
|
|
23
|
+
if (this.opt.validate) {
|
|
24
|
+
this.opt.validate(p);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
static define(opt) {
|
|
28
|
+
return new DtiAction(opt);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/esm/base62.d.ts
ADDED
package/esm/base62.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import base from 'base-x';
|
|
2
|
+
export class Base62 {
|
|
3
|
+
constructor(ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
|
|
4
|
+
this.utf8Encode = new TextEncoder();
|
|
5
|
+
this.utf8Decoder = new TextDecoder();
|
|
6
|
+
this.convert = base(ALPHABET);
|
|
7
|
+
}
|
|
8
|
+
encode(str) {
|
|
9
|
+
let bytes = this.utf8Encode.encode(str);
|
|
10
|
+
let txt = this.convert.encode(bytes);
|
|
11
|
+
return txt;
|
|
12
|
+
}
|
|
13
|
+
decode(str) {
|
|
14
|
+
let bytes = this.convert.decode(str);
|
|
15
|
+
let txt = this.utf8Decoder.decode(bytes);
|
|
16
|
+
return txt;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/esm/common.d.ts
ADDED
package/esm/common.js
ADDED
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
package/esm/response.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
const key = Symbol.for('DtiRawResponse_key');
|
|
3
|
+
export class DtiRawResponse {
|
|
4
|
+
constructor() {
|
|
5
|
+
this[_a] = key;
|
|
6
|
+
}
|
|
7
|
+
static is(obj) {
|
|
8
|
+
if (obj instanceof DtiRawResponse && obj[key] === key) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
_a = key;
|
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,64 @@
|
|
|
1
|
+
export class DtiRoute {
|
|
2
|
+
constructor(name) {
|
|
3
|
+
this.name = name;
|
|
4
|
+
}
|
|
5
|
+
getChildroutes() {
|
|
6
|
+
return this._children || [];
|
|
7
|
+
}
|
|
8
|
+
regChildroute(route) {
|
|
9
|
+
if (route._parent) {
|
|
10
|
+
throw new Error(`cannot register the route ("${route.name}") on route ("${this.name}"). already registered #"${route._parent.name}" `);
|
|
11
|
+
}
|
|
12
|
+
route._parent = this;
|
|
13
|
+
this._children = [...this._children || [], route];
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
getActions() {
|
|
17
|
+
return this._actions || [];
|
|
18
|
+
}
|
|
19
|
+
regAction(action) {
|
|
20
|
+
// if (action.getRoute()) {
|
|
21
|
+
// throw new Error(`the action(${action.name}) already registed. registered route(${action.route.name})`)
|
|
22
|
+
// }
|
|
23
|
+
let name = action.getName();
|
|
24
|
+
for (let a of this._actions || []) {
|
|
25
|
+
if (a.getName() === name) {
|
|
26
|
+
throw new Error(`the action(${name}) is registered`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this._actions = [...this._actions || [], action];
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
getNames() {
|
|
33
|
+
if (this._parent) {
|
|
34
|
+
let paths = this._parent.getNames();
|
|
35
|
+
return [...paths, this.name];
|
|
36
|
+
}
|
|
37
|
+
return [this.name];
|
|
38
|
+
}
|
|
39
|
+
getFullname() {
|
|
40
|
+
return this.getNames().join('.');
|
|
41
|
+
}
|
|
42
|
+
getPaths() {
|
|
43
|
+
if (this._parent) {
|
|
44
|
+
let paths = this._parent.getPaths();
|
|
45
|
+
return [...paths, this.getLocalPath()];
|
|
46
|
+
}
|
|
47
|
+
return [this.getLocalPath()];
|
|
48
|
+
}
|
|
49
|
+
getLocalPath() {
|
|
50
|
+
return `/${this.path || this.name}`;
|
|
51
|
+
}
|
|
52
|
+
static factory(name, opt) {
|
|
53
|
+
let route = new DtiRoute(name);
|
|
54
|
+
if (opt?.path) {
|
|
55
|
+
route.path = opt.path;
|
|
56
|
+
}
|
|
57
|
+
if (opt?.childrens) {
|
|
58
|
+
for (let r of opt.childrens) {
|
|
59
|
+
route.regChildroute(r);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return route;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napp/dti-core",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.5",
|
|
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",
|