@napp/dti-core 3.0.7 → 4.0.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.
- package/action.d.ts +21 -0
- package/action.js +34 -0
- package/common.d.ts +6 -26
- package/common.js +10 -10
- package/error.d.ts +21 -0
- package/error.js +86 -0
- package/index.d.ts +4 -2
- package/index.js +20 -14
- package/package.json +1 -1
- package/route.d.ts +21 -0
- package/route.js +63 -0
- package/meta.d.ts +0 -13
- package/meta.js +0 -71
package/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/action.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DtiAction = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
class DtiAction {
|
|
6
|
+
constructor(opt) {
|
|
7
|
+
this.opt = opt;
|
|
8
|
+
opt.route.regAction(this);
|
|
9
|
+
}
|
|
10
|
+
getName() {
|
|
11
|
+
return this.opt.name;
|
|
12
|
+
}
|
|
13
|
+
getRoute() {
|
|
14
|
+
return this.opt.route;
|
|
15
|
+
}
|
|
16
|
+
getMode() {
|
|
17
|
+
return this.opt.mode || common_1.DtiMode.QString;
|
|
18
|
+
}
|
|
19
|
+
getPath() {
|
|
20
|
+
return '/' + (this.opt.path || this.getName());
|
|
21
|
+
}
|
|
22
|
+
getFullname() {
|
|
23
|
+
return `${this.getRoute().getFullname()}.${this.getName()}`;
|
|
24
|
+
}
|
|
25
|
+
validate(p) {
|
|
26
|
+
if (this.opt.validate) {
|
|
27
|
+
this.opt.validate(p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static define(opt) {
|
|
31
|
+
return new DtiAction(opt);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.DtiAction = DtiAction;
|
package/common.d.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
export declare enum DtiMode {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
BJson =
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export interface Serializer<T> {
|
|
8
|
-
encode: (param: T) => string;
|
|
9
|
-
decode: (text: string) => T;
|
|
10
|
-
}
|
|
11
|
-
export interface DtiOption<RES, RQ = void, RB = void> {
|
|
12
|
-
name: string;
|
|
13
|
-
role?: (q: RQ, b: RB) => string;
|
|
14
|
-
path?: string;
|
|
15
|
-
method?: 'get' | 'post';
|
|
16
|
-
/**
|
|
17
|
-
* default: json
|
|
18
|
-
*/
|
|
19
|
-
bodyMode?: string;
|
|
20
|
-
/**
|
|
21
|
-
* default: base64
|
|
22
|
-
*/
|
|
23
|
-
queryMode?: string;
|
|
24
|
-
checkQ?: (q: RQ) => void;
|
|
25
|
-
checkB?: (b: RB) => void;
|
|
26
|
-
}
|
|
1
|
+
export declare enum DtiMode {
|
|
2
|
+
QString = 1,
|
|
3
|
+
QJson = 2,
|
|
4
|
+
BJson = 3,
|
|
5
|
+
BFrom = 4
|
|
6
|
+
}
|
package/common.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DtiMode = void 0;
|
|
4
|
-
var DtiMode;
|
|
5
|
-
(function (DtiMode) {
|
|
6
|
-
DtiMode["
|
|
7
|
-
DtiMode["
|
|
8
|
-
DtiMode["BJson"] = "
|
|
9
|
-
DtiMode["
|
|
10
|
-
})(DtiMode = exports.DtiMode || (exports.DtiMode = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DtiMode = void 0;
|
|
4
|
+
var DtiMode;
|
|
5
|
+
(function (DtiMode) {
|
|
6
|
+
DtiMode[DtiMode["QString"] = 1] = "QString";
|
|
7
|
+
DtiMode[DtiMode["QJson"] = 2] = "QJson";
|
|
8
|
+
DtiMode[DtiMode["BJson"] = 3] = "BJson";
|
|
9
|
+
DtiMode[DtiMode["BFrom"] = 4] = "BFrom";
|
|
10
|
+
})(DtiMode = exports.DtiMode || (exports.DtiMode = {}));
|
package/error.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IDtiError {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class DtiError extends Error implements IDtiError {
|
|
6
|
+
code: string;
|
|
7
|
+
constructor(code: string, message: string);
|
|
8
|
+
toPlanObject(): {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
toJson(): {
|
|
13
|
+
code: string;
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
static fromCode(code: string, obj: any): DtiError;
|
|
17
|
+
static from(obj: any): DtiError;
|
|
18
|
+
}
|
|
19
|
+
export declare class DtiErrorUnknown extends DtiError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
package/error.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DtiErrorUnknown = exports.DtiError = void 0;
|
|
4
|
+
class DtiError extends Error {
|
|
5
|
+
constructor(code, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = 'DtiError';
|
|
9
|
+
Object.setPrototypeOf(this, DtiError.prototype);
|
|
10
|
+
}
|
|
11
|
+
toPlanObject() {
|
|
12
|
+
return {
|
|
13
|
+
code: this.code,
|
|
14
|
+
message: this.message
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
toJson() {
|
|
18
|
+
return this.toPlanObject();
|
|
19
|
+
}
|
|
20
|
+
static fromCode(code, obj) {
|
|
21
|
+
if (obj) {
|
|
22
|
+
if (obj instanceof DtiError) {
|
|
23
|
+
return new DtiError(code, obj.message);
|
|
24
|
+
}
|
|
25
|
+
if (obj instanceof Error) {
|
|
26
|
+
return new DtiError(code, obj.message);
|
|
27
|
+
}
|
|
28
|
+
if (obj.message) {
|
|
29
|
+
return new DtiError(code, '' + obj.message);
|
|
30
|
+
}
|
|
31
|
+
if (obj.error) {
|
|
32
|
+
return new DtiError(code, '' + obj.error);
|
|
33
|
+
}
|
|
34
|
+
return new DtiError(code, '' + obj);
|
|
35
|
+
}
|
|
36
|
+
return new DtiError(code, "undefined error");
|
|
37
|
+
}
|
|
38
|
+
static from(obj) {
|
|
39
|
+
if (obj) {
|
|
40
|
+
if (obj instanceof DtiError) {
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
if (obj instanceof Error) {
|
|
44
|
+
if ('code' in obj) {
|
|
45
|
+
return new DtiError(`${obj.code}`, `${obj.message}`);
|
|
46
|
+
}
|
|
47
|
+
return new DtiError(obj.name, obj.message);
|
|
48
|
+
}
|
|
49
|
+
if (obj.code && obj.message) {
|
|
50
|
+
return new DtiError('' + obj.code, '' + obj.message);
|
|
51
|
+
}
|
|
52
|
+
if (obj.code && obj.error) {
|
|
53
|
+
return new DtiError('' + obj.code, '' + obj.error);
|
|
54
|
+
}
|
|
55
|
+
if (obj.name && obj.message) {
|
|
56
|
+
return new DtiError('' + obj.name, '' + obj.message);
|
|
57
|
+
}
|
|
58
|
+
if (obj.name && obj.error) {
|
|
59
|
+
return new DtiError('' + obj.name, '' + obj.error);
|
|
60
|
+
}
|
|
61
|
+
if (obj.code) {
|
|
62
|
+
return new DtiError('' + obj.code, 'error code=' + obj.code);
|
|
63
|
+
}
|
|
64
|
+
if (obj.name) {
|
|
65
|
+
return new DtiError('' + obj.name, 'error code=' + obj.name);
|
|
66
|
+
}
|
|
67
|
+
if (obj.message) {
|
|
68
|
+
return new DtiError('nocode', '' + obj.message);
|
|
69
|
+
}
|
|
70
|
+
if (obj.error) {
|
|
71
|
+
return new DtiError('nocode', '' + obj.error);
|
|
72
|
+
}
|
|
73
|
+
return new DtiErrorUnknown('unknown error; error=' + obj);
|
|
74
|
+
}
|
|
75
|
+
return new DtiErrorUnknown("undefined error");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.DtiError = DtiError;
|
|
79
|
+
class DtiErrorUnknown extends DtiError {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super('unknown', message);
|
|
82
|
+
this.name = 'DtiErrorUnknown';
|
|
83
|
+
Object.setPrototypeOf(this, DtiErrorUnknown.prototype);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.DtiErrorUnknown = DtiErrorUnknown;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__exportStar(
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./action"), exports);
|
|
19
|
+
__exportStar(require("./route"), exports);
|
|
20
|
+
__exportStar(require("./error"), exports);
|
package/package.json
CHANGED
package/route.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DtiAction } from "./action";
|
|
2
|
+
export interface ODtiRoute {
|
|
3
|
+
path?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class DtiRoute {
|
|
6
|
+
name: string;
|
|
7
|
+
private constructor();
|
|
8
|
+
private _parent?;
|
|
9
|
+
private _children?;
|
|
10
|
+
private _actions?;
|
|
11
|
+
private path?;
|
|
12
|
+
getChildroutes(): DtiRoute[];
|
|
13
|
+
regChildroute(route: DtiRoute): this;
|
|
14
|
+
getActions(): DtiAction<any, any>[];
|
|
15
|
+
regAction<RESULT, PARAM>(action: DtiAction<RESULT, PARAM>): this;
|
|
16
|
+
getNames(): string[];
|
|
17
|
+
getFullname(): string;
|
|
18
|
+
getPaths(): string[];
|
|
19
|
+
getLocalPath(): string;
|
|
20
|
+
static factory(name: string, opt?: ODtiRoute): DtiRoute;
|
|
21
|
+
}
|
package/route.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DtiRoute = void 0;
|
|
4
|
+
class DtiRoute {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
}
|
|
8
|
+
getChildroutes() {
|
|
9
|
+
return this._children || [];
|
|
10
|
+
}
|
|
11
|
+
regChildroute(route) {
|
|
12
|
+
if (route._parent) {
|
|
13
|
+
throw new Error(`cannot register the route ("${route.name}") on route ("${this.name}"). already registered #"${route._parent.name}" `);
|
|
14
|
+
}
|
|
15
|
+
route._parent = this;
|
|
16
|
+
this._children = [...this._children || [], route];
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
getActions() {
|
|
20
|
+
return this._actions || [];
|
|
21
|
+
}
|
|
22
|
+
regAction(action) {
|
|
23
|
+
// if (action.getRoute()) {
|
|
24
|
+
// throw new Error(`the action(${action.name}) already registed. registered route(${action.route.name})`)
|
|
25
|
+
// }
|
|
26
|
+
let name = action.getName();
|
|
27
|
+
for (let a of this._actions || []) {
|
|
28
|
+
if (a.getName() === name) {
|
|
29
|
+
throw new Error(`the action(${name}) is registered`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this._actions = [...this._actions || [], action];
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
getNames() {
|
|
36
|
+
if (this._parent) {
|
|
37
|
+
let paths = this._parent.getNames();
|
|
38
|
+
return [...paths, this.name];
|
|
39
|
+
}
|
|
40
|
+
return [this.name];
|
|
41
|
+
}
|
|
42
|
+
getFullname() {
|
|
43
|
+
return this.getNames().join('.');
|
|
44
|
+
}
|
|
45
|
+
getPaths() {
|
|
46
|
+
if (this._parent) {
|
|
47
|
+
let paths = this._parent.getPaths();
|
|
48
|
+
return [...paths, this.getLocalPath()];
|
|
49
|
+
}
|
|
50
|
+
return [this.getLocalPath()];
|
|
51
|
+
}
|
|
52
|
+
getLocalPath() {
|
|
53
|
+
return `/${this.path || this.name}`;
|
|
54
|
+
}
|
|
55
|
+
static factory(name, opt) {
|
|
56
|
+
let route = new DtiRoute(name);
|
|
57
|
+
if (opt === null || opt === void 0 ? void 0 : opt.path) {
|
|
58
|
+
route.path = opt.path;
|
|
59
|
+
}
|
|
60
|
+
return route;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.DtiRoute = DtiRoute;
|
package/meta.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DtiOption } from "./common";
|
|
2
|
-
export declare class Dti<RES, PQ, PB> {
|
|
3
|
-
private opt;
|
|
4
|
-
constructor(opt: DtiOption<RES, PQ, PB>);
|
|
5
|
-
get name(): string;
|
|
6
|
-
get method(): "get" | "post";
|
|
7
|
-
get path(): string;
|
|
8
|
-
get queryMode(): string;
|
|
9
|
-
get bodyMode(): string;
|
|
10
|
-
checkQ(q: PQ): void;
|
|
11
|
-
checkB(b: PB): void;
|
|
12
|
-
static define<RES, PQ, PB>(opt: DtiOption<RES, PQ, PB>): Dti<RES, PQ, PB>;
|
|
13
|
-
}
|
package/meta.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Dti = void 0;
|
|
4
|
-
var Dti = /** @class */ (function () {
|
|
5
|
-
function Dti(opt) {
|
|
6
|
-
this.opt = opt;
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(Dti.prototype, "name", {
|
|
9
|
-
get: function () {
|
|
10
|
-
return this.opt.name;
|
|
11
|
-
},
|
|
12
|
-
enumerable: false,
|
|
13
|
-
configurable: true
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(Dti.prototype, "method", {
|
|
16
|
-
get: function () {
|
|
17
|
-
var method = this.opt.method;
|
|
18
|
-
if (method === 'get')
|
|
19
|
-
return 'get';
|
|
20
|
-
if (method === 'post')
|
|
21
|
-
return 'post';
|
|
22
|
-
if (this.opt.checkB)
|
|
23
|
-
return 'post';
|
|
24
|
-
return 'get';
|
|
25
|
-
},
|
|
26
|
-
enumerable: false,
|
|
27
|
-
configurable: true
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(Dti.prototype, "path", {
|
|
30
|
-
get: function () {
|
|
31
|
-
var _a = this.opt, name = _a.name, path = _a.path;
|
|
32
|
-
if (path)
|
|
33
|
-
return path;
|
|
34
|
-
return '/' + name;
|
|
35
|
-
},
|
|
36
|
-
enumerable: false,
|
|
37
|
-
configurable: true
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(Dti.prototype, "queryMode", {
|
|
40
|
-
get: function () {
|
|
41
|
-
return this.opt.queryMode || '';
|
|
42
|
-
},
|
|
43
|
-
enumerable: false,
|
|
44
|
-
configurable: true
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(Dti.prototype, "bodyMode", {
|
|
47
|
-
get: function () {
|
|
48
|
-
return this.opt.bodyMode || '';
|
|
49
|
-
},
|
|
50
|
-
enumerable: false,
|
|
51
|
-
configurable: true
|
|
52
|
-
});
|
|
53
|
-
Dti.prototype.checkQ = function (q) {
|
|
54
|
-
if (this.opt.checkQ) {
|
|
55
|
-
this.opt.checkQ(q);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
Dti.prototype.checkB = function (b) {
|
|
59
|
-
if (this.opt.checkB) {
|
|
60
|
-
this.opt.checkB(b);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
Dti.define = function (opt) {
|
|
64
|
-
return new Dti(opt);
|
|
65
|
-
};
|
|
66
|
-
return Dti;
|
|
67
|
-
}());
|
|
68
|
-
exports.Dti = Dti;
|
|
69
|
-
var m = Dti.define({
|
|
70
|
-
name: ''
|
|
71
|
-
});
|