@napp/dti-client 4.0.2 → 4.1.4
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/bundler.d.ts +23 -0
- package/bundler.js +147 -0
- package/caller.d.ts +2 -0
- package/caller.js +3 -0
- package/client.d.ts +2 -0
- package/client.js +31 -0
- package/package.json +2 -2
package/bundler.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DtiAction } from "@napp/dti-core";
|
|
2
|
+
import { DtiClientBuilder } from "./builder";
|
|
3
|
+
export interface BundleMeta<RESULT, PARAM> {
|
|
4
|
+
meta: DtiAction<RESULT, PARAM>;
|
|
5
|
+
param: PARAM;
|
|
6
|
+
}
|
|
7
|
+
export declare class DtiClientBandler {
|
|
8
|
+
private bundleMetas;
|
|
9
|
+
private builder;
|
|
10
|
+
constructor(bundleMetas: Array<BundleMeta<any, any>>, builder: DtiClientBuilder);
|
|
11
|
+
validate(): void;
|
|
12
|
+
private getMethod;
|
|
13
|
+
private getBase;
|
|
14
|
+
getParam(): {
|
|
15
|
+
name: string;
|
|
16
|
+
param: any;
|
|
17
|
+
}[];
|
|
18
|
+
private getHeaders;
|
|
19
|
+
call(): Promise<any>;
|
|
20
|
+
private callGet;
|
|
21
|
+
private callPost;
|
|
22
|
+
private respHandle;
|
|
23
|
+
}
|
package/bundler.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DtiClientBandler = void 0;
|
|
16
|
+
const dti_core_1 = require("@napp/dti-core");
|
|
17
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
18
|
+
const base64url_1 = __importDefault(require("base64url"));
|
|
19
|
+
class DtiClientBandler {
|
|
20
|
+
constructor(bundleMetas, builder) {
|
|
21
|
+
this.bundleMetas = bundleMetas;
|
|
22
|
+
this.builder = builder;
|
|
23
|
+
}
|
|
24
|
+
validate() {
|
|
25
|
+
for (let it of this.bundleMetas) {
|
|
26
|
+
it.meta.validate(it.param);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getMethod() {
|
|
30
|
+
for (let it of this.bundleMetas) {
|
|
31
|
+
let m = it.meta.getMode();
|
|
32
|
+
if (m === dti_core_1.DtiMode.BFrom || m === dti_core_1.DtiMode.BJson) {
|
|
33
|
+
return 'post';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return 'get';
|
|
37
|
+
}
|
|
38
|
+
getBase() {
|
|
39
|
+
for (let it of this.bundleMetas) {
|
|
40
|
+
let base = this.builder.getBaseUrl(it.meta.getFullname());
|
|
41
|
+
if (base) {
|
|
42
|
+
return base;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
getParam() {
|
|
48
|
+
let param = [];
|
|
49
|
+
for (let it of this.bundleMetas) {
|
|
50
|
+
param.push({
|
|
51
|
+
name: it.meta.getFullname(),
|
|
52
|
+
param: it.param
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return param;
|
|
56
|
+
}
|
|
57
|
+
getHeaders() {
|
|
58
|
+
let headers = {};
|
|
59
|
+
for (let it of this.bundleMetas) {
|
|
60
|
+
let _headers = this.builder.getHeader(it.meta.getRoute().getFullname());
|
|
61
|
+
if (_headers) {
|
|
62
|
+
headers = Object.assign(Object.assign({}, headers), _headers);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
headers["Content-Type"] = "application/json";
|
|
66
|
+
return headers;
|
|
67
|
+
}
|
|
68
|
+
call() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
this.validate();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw dti_core_1.DtiError.fromCode('validation', error);
|
|
75
|
+
}
|
|
76
|
+
let method = this.getMethod();
|
|
77
|
+
if (method === 'get') {
|
|
78
|
+
return yield this.callGet();
|
|
79
|
+
}
|
|
80
|
+
return yield this.callPost();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
callGet() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
try {
|
|
86
|
+
let baseUrl = this.getBase();
|
|
87
|
+
let param = this.getParam();
|
|
88
|
+
let headers = this.getHeaders();
|
|
89
|
+
let p = base64url_1.default.encode(JSON.stringify(param));
|
|
90
|
+
let q = new URLSearchParams({ p }).toString();
|
|
91
|
+
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_get__?${q}`, {
|
|
92
|
+
method: 'get', headers
|
|
93
|
+
});
|
|
94
|
+
return yield this.respHandle(resp);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw dti_core_1.DtiError.from(error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
callPost() {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
let baseUrl = this.getBase();
|
|
105
|
+
let param = this.getParam();
|
|
106
|
+
let headers = this.getHeaders();
|
|
107
|
+
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_post__`, {
|
|
108
|
+
method: 'post', headers, body: JSON.stringify(param)
|
|
109
|
+
});
|
|
110
|
+
return yield this.respHandle(resp);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw dti_core_1.DtiError.from(error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
respHandle(resp) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
try {
|
|
120
|
+
let resu = yield resp.text();
|
|
121
|
+
if (resp.ok) {
|
|
122
|
+
try {
|
|
123
|
+
return JSON.parse(resu);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
throw dti_core_1.DtiError.fromCode("InvalidJSON", resu);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
let errObject = JSON.parse(resu);
|
|
131
|
+
let error = dti_core_1.DtiError.from(errObject);
|
|
132
|
+
if (error instanceof dti_core_1.DtiErrorUnknown) {
|
|
133
|
+
throw new dti_core_1.DtiError('' + resp.status, resp.statusText);
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new dti_core_1.DtiErrorUnknown(resu);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw dti_core_1.DtiError.from(error);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.DtiClientBandler = DtiClientBandler;
|
package/caller.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DtiAction } from "@napp/dti-core";
|
|
2
2
|
import { DtiClientBuilder } from "./builder";
|
|
3
|
+
import { BundleMeta } from "./bundler";
|
|
3
4
|
export declare class DtiClientCaller<RESULT, PARAM> {
|
|
4
5
|
private meta;
|
|
5
6
|
private builder;
|
|
@@ -11,5 +12,6 @@ export declare class DtiClientCaller<RESULT, PARAM> {
|
|
|
11
12
|
private getQeury;
|
|
12
13
|
private getHeaders;
|
|
13
14
|
private getUrl;
|
|
15
|
+
bundler(param: PARAM): BundleMeta<RESULT, PARAM>;
|
|
14
16
|
call(param: PARAM): Promise<RESULT>;
|
|
15
17
|
}
|
package/caller.js
CHANGED
package/client.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DtiAction, DtiRoute } from "@napp/dti-core";
|
|
2
2
|
import { DtiClientBuilder } from "./builder";
|
|
3
3
|
import { DtiClientCaller } from "./caller";
|
|
4
|
+
import { BundleMeta } from "./bundler";
|
|
4
5
|
export declare class DtiClient {
|
|
5
6
|
private builder;
|
|
6
7
|
constructor(builder: DtiClientBuilder);
|
|
7
8
|
dti<RESULT, PARAM>(meta: DtiAction<RESULT, PARAM>): DtiClientCaller<RESULT, PARAM>;
|
|
8
9
|
buildUrl(route: DtiRoute, actionPath: string): string;
|
|
10
|
+
bundle<R1, P1, R2, P2, R3, P3, R4, P4, R5, P5, R6, P6>(m1: BundleMeta<R1, P1>, m2?: BundleMeta<R2, P2>, m3?: BundleMeta<R3, P3>, m4?: BundleMeta<R4, P4>, m5?: BundleMeta<R5, P5>, m6?: BundleMeta<R6, P6>): Promise<[R1, R2, R3, R4, R5, R6]>;
|
|
9
11
|
}
|
package/client.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DtiClient = void 0;
|
|
4
13
|
const route_1 = require("./route");
|
|
5
14
|
const caller_1 = require("./caller");
|
|
15
|
+
const bundler_1 = require("./bundler");
|
|
6
16
|
class DtiClient {
|
|
7
17
|
constructor(builder) {
|
|
8
18
|
this.builder = builder;
|
|
@@ -13,5 +23,26 @@ class DtiClient {
|
|
|
13
23
|
buildUrl(route, actionPath) {
|
|
14
24
|
return new route_1.DtiClientRoute(route, this.builder).buildUrl(actionPath);
|
|
15
25
|
}
|
|
26
|
+
bundle(m1, m2, m3, m4, m5, m6) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let bundleMetas = [m1];
|
|
29
|
+
if (m2) {
|
|
30
|
+
bundleMetas.push(m2);
|
|
31
|
+
}
|
|
32
|
+
if (m3) {
|
|
33
|
+
bundleMetas.push(m3);
|
|
34
|
+
}
|
|
35
|
+
if (m4) {
|
|
36
|
+
bundleMetas.push(m4);
|
|
37
|
+
}
|
|
38
|
+
if (m5) {
|
|
39
|
+
bundleMetas.push(m5);
|
|
40
|
+
}
|
|
41
|
+
if (m6) {
|
|
42
|
+
bundleMetas.push(m6);
|
|
43
|
+
}
|
|
44
|
+
return yield new bundler_1.DtiClientBandler(bundleMetas, this.builder).call();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
16
47
|
}
|
|
17
48
|
exports.DtiClient = DtiClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napp/dti-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.4",
|
|
4
4
|
"description": "data transaction interface client library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "Farcek <farcek@gmail.com>",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@napp/dti-core": "4.
|
|
19
|
+
"@napp/dti-core": "4.1.4",
|
|
20
20
|
"base64url": "latest",
|
|
21
21
|
"cross-fetch": "latest"
|
|
22
22
|
}
|