@ywfe/fe-tools 1.0.2-beta.3 → 1.0.2-beta.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/JSON2String.ts +13 -0
- package/index.ts +3 -0
- package/lib/JSON2String.d.ts +5 -0
- package/lib/JSON2String.d.ts.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/request.d.ts +10 -0
- package/lib/request.d.ts.map +1 -0
- package/lib/userInputToJson.d.ts +9 -0
- package/lib/userInputToJson.d.ts.map +1 -0
- package/{dist/bundle.js → lib/ywfe-tools.esm.js} +51 -209
- package/lib/ywfe-tools.esm.js.map +1 -0
- package/package.json +5 -6
- package/request.ts +49 -0
- package/rollup.config.js +26 -0
- package/tsconfig.json +38 -0
- package/tsconfig.type.json +8 -0
- package/userInputToJson.ts +18 -0
- package/dist/bundle.js.map +0 -1
package/JSON2String.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
interface userInput {
|
2
|
+
data?: object;
|
3
|
+
}
|
4
|
+
function JSON2String({ input }) {
|
5
|
+
const { data = {} } = input;
|
6
|
+
try {
|
7
|
+
return "```json" + JSON.stringify(data) + "json```";
|
8
|
+
} catch (error) {
|
9
|
+
return "```json" + JSON.stringify({}) + "json```";
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
export default JSON2String
|
package/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"JSON2String.d.ts","sourceRoot":"","sources":["../JSON2String.ts"],"names":[],"mappings":"AAGA,iBAAS,WAAW,CAAC,EAAE,KAAK,EAAE;;CAAA,UAO7B;AAED,eAAe,WAAW,CAAA"}
|
package/lib/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
|
package/lib/request.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../request.ts"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,GAAG,EAAC,MAAM,CAAC;IACX,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,MAAM,CAAC,EAAC,GAAG,CAAA;CACZ;AACD,iBAAe,OAAO,CAAC,EAAC,KAAK,EAAC,EAAC;IAAC,KAAK,EAAC,cAAc,CAAA;CAAC,gBAwCpD;AACD,eAAe,OAAO,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"userInputToJson.d.ts","sourceRoot":"","sources":["../userInputToJson.ts"],"names":[],"mappings":"AACA,UAAU,SAAS;IACjB,SAAS,CAAC,EAAC,MAAM,CAAC;IAClB,KAAK,CAAC,EAAC,MAAM,CAAC;CACf;AACD,iBAAe,eAAe,CAAC,EAAC,KAAK,EAAC,EAAC;IAAC,KAAK,EAAC,SAAS,CAAA;CAAC,gBAWvD;AACD,eAAe,eAAe,CAAA"}
|
@@ -1,141 +1,5 @@
|
|
1
1
|
import require$$1 from 'fs';
|
2
2
|
|
3
|
-
/******************************************************************************
|
4
|
-
Copyright (c) Microsoft Corporation.
|
5
|
-
|
6
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
7
|
-
purpose with or without fee is hereby granted.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
16
|
-
***************************************************************************** */
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
18
|
-
|
19
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
20
|
-
function adopt(value) {
|
21
|
-
return value instanceof P ? value : new P(function (resolve) {
|
22
|
-
resolve(value);
|
23
|
-
});
|
24
|
-
}
|
25
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
26
|
-
function fulfilled(value) {
|
27
|
-
try {
|
28
|
-
step(generator.next(value));
|
29
|
-
} catch (e) {
|
30
|
-
reject(e);
|
31
|
-
}
|
32
|
-
}
|
33
|
-
function rejected(value) {
|
34
|
-
try {
|
35
|
-
step(generator["throw"](value));
|
36
|
-
} catch (e) {
|
37
|
-
reject(e);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
function step(result) {
|
41
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
42
|
-
}
|
43
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
44
|
-
});
|
45
|
-
}
|
46
|
-
function __generator(thisArg, body) {
|
47
|
-
var _ = {
|
48
|
-
label: 0,
|
49
|
-
sent: function () {
|
50
|
-
if (t[0] & 1) throw t[1];
|
51
|
-
return t[1];
|
52
|
-
},
|
53
|
-
trys: [],
|
54
|
-
ops: []
|
55
|
-
},
|
56
|
-
f,
|
57
|
-
y,
|
58
|
-
t,
|
59
|
-
g;
|
60
|
-
return g = {
|
61
|
-
next: verb(0),
|
62
|
-
"throw": verb(1),
|
63
|
-
"return": verb(2)
|
64
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
65
|
-
return this;
|
66
|
-
}), g;
|
67
|
-
function verb(n) {
|
68
|
-
return function (v) {
|
69
|
-
return step([n, v]);
|
70
|
-
};
|
71
|
-
}
|
72
|
-
function step(op) {
|
73
|
-
if (f) throw new TypeError("Generator is already executing.");
|
74
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
75
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
76
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
77
|
-
switch (op[0]) {
|
78
|
-
case 0:
|
79
|
-
case 1:
|
80
|
-
t = op;
|
81
|
-
break;
|
82
|
-
case 4:
|
83
|
-
_.label++;
|
84
|
-
return {
|
85
|
-
value: op[1],
|
86
|
-
done: false
|
87
|
-
};
|
88
|
-
case 5:
|
89
|
-
_.label++;
|
90
|
-
y = op[1];
|
91
|
-
op = [0];
|
92
|
-
continue;
|
93
|
-
case 7:
|
94
|
-
op = _.ops.pop();
|
95
|
-
_.trys.pop();
|
96
|
-
continue;
|
97
|
-
default:
|
98
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
99
|
-
_ = 0;
|
100
|
-
continue;
|
101
|
-
}
|
102
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
103
|
-
_.label = op[1];
|
104
|
-
break;
|
105
|
-
}
|
106
|
-
if (op[0] === 6 && _.label < t[1]) {
|
107
|
-
_.label = t[1];
|
108
|
-
t = op;
|
109
|
-
break;
|
110
|
-
}
|
111
|
-
if (t && _.label < t[2]) {
|
112
|
-
_.label = t[2];
|
113
|
-
_.ops.push(op);
|
114
|
-
break;
|
115
|
-
}
|
116
|
-
if (t[2]) _.ops.pop();
|
117
|
-
_.trys.pop();
|
118
|
-
continue;
|
119
|
-
}
|
120
|
-
op = body.call(thisArg, _);
|
121
|
-
} catch (e) {
|
122
|
-
op = [6, e];
|
123
|
-
y = 0;
|
124
|
-
} finally {
|
125
|
-
f = t = 0;
|
126
|
-
}
|
127
|
-
if (op[0] & 5) throw op[1];
|
128
|
-
return {
|
129
|
-
value: op[0] ? op[1] : void 0,
|
130
|
-
done: true
|
131
|
-
};
|
132
|
-
}
|
133
|
-
}
|
134
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
135
|
-
var e = new Error(message);
|
136
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
137
|
-
};
|
138
|
-
|
139
3
|
var ywfeUtils_esm = {};
|
140
4
|
|
141
5
|
(function (exports) {
|
@@ -8746,83 +8610,61 @@ var ywfeUtils_esm = {};
|
|
8746
8610
|
|
8747
8611
|
} (ywfeUtils_esm));
|
8748
8612
|
|
8749
|
-
|
8750
|
-
|
8751
|
-
|
8752
|
-
|
8753
|
-
|
8754
|
-
|
8755
|
-
|
8756
|
-
|
8757
|
-
|
8758
|
-
|
8759
|
-
|
8760
|
-
|
8761
|
-
|
8762
|
-
|
8763
|
-
|
8764
|
-
|
8765
|
-
|
8766
|
-
|
8767
|
-
|
8768
|
-
|
8769
|
-
|
8770
|
-
|
8771
|
-
|
8772
|
-
|
8773
|
-
|
8774
|
-
|
8775
|
-
|
8776
|
-
|
8777
|
-
|
8778
|
-
|
8779
|
-
|
8780
|
-
|
8781
|
-
|
8782
|
-
|
8783
|
-
|
8784
|
-
|
8785
|
-
|
8786
|
-
|
8787
|
-
|
8788
|
-
else if (method.toUpperCase() === 'GET') {
|
8789
|
-
requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
|
8790
|
-
}
|
8791
|
-
return [4 /*yield*/, fetch(requestUrl, fetchOption)];
|
8792
|
-
case 1:
|
8793
|
-
res = _c.sent();
|
8794
|
-
return [2 /*return*/, res.json()];
|
8795
|
-
}
|
8796
|
-
});
|
8797
|
-
});
|
8613
|
+
// Ctrl-S保存代码
|
8614
|
+
async function request({ input }) {
|
8615
|
+
const method = input.method || 'GET';
|
8616
|
+
const basePathMap = new Map([
|
8617
|
+
['prod', 'https://gateway.ywwl.com'],
|
8618
|
+
['test', 'https://test-gateway.ywwl.com'],
|
8619
|
+
['test2', 'https://test2-gateway.ywwl.com'],
|
8620
|
+
['dev', 'https://dev-gateway.ywwl.com'],
|
8621
|
+
]);
|
8622
|
+
const getBasePath = () => {
|
8623
|
+
const env = '{{env}}';
|
8624
|
+
return basePathMap.get(env);
|
8625
|
+
};
|
8626
|
+
const isValidURL = (url) => {
|
8627
|
+
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
8628
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
8629
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
8630
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
8631
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
8632
|
+
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
8633
|
+
return !!pattern.test(url);
|
8634
|
+
};
|
8635
|
+
const prefix = getBasePath();
|
8636
|
+
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
8637
|
+
const fetchOption = {
|
8638
|
+
method: method,
|
8639
|
+
headers: {
|
8640
|
+
'Content-type': 'application/json',
|
8641
|
+
'x-token': '{{token}}',
|
8642
|
+
},
|
8643
|
+
};
|
8644
|
+
if (method.toUpperCase() === 'POST') {
|
8645
|
+
fetchOption.body = JSON.stringify(input.params);
|
8646
|
+
}
|
8647
|
+
else if (method.toUpperCase() === 'GET') {
|
8648
|
+
requestUrl = `${requestUrl}?${ywfeUtils_esm.querystring.stringify(input.params || {})}`;
|
8649
|
+
}
|
8650
|
+
const res = await fetch(requestUrl, fetchOption);
|
8651
|
+
return res.json();
|
8798
8652
|
}
|
8799
8653
|
|
8800
|
-
function userInputToJson(
|
8801
|
-
|
8802
|
-
|
8803
|
-
|
8804
|
-
|
8805
|
-
|
8806
|
-
|
8807
|
-
|
8808
|
-
console.log('cesh');
|
8809
|
-
return [4 /*yield*/, feTools.request({
|
8810
|
-
input: {
|
8811
|
-
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
8812
|
-
method: "GET"
|
8813
|
-
}
|
8814
|
-
})];
|
8815
|
-
case 1:
|
8816
|
-
res = _c.sent();
|
8817
|
-
return [2 /*return*/, res];
|
8818
|
-
}
|
8819
|
-
});
|
8654
|
+
async function userInputToJson({ input }) {
|
8655
|
+
console.log('cesh');
|
8656
|
+
//@ts-ignore
|
8657
|
+
const res = await feTools.request({
|
8658
|
+
input: {
|
8659
|
+
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
8660
|
+
method: "GET"
|
8661
|
+
}
|
8820
8662
|
});
|
8663
|
+
return res;
|
8821
8664
|
}
|
8822
8665
|
|
8823
|
-
function JSON2String(
|
8824
|
-
|
8825
|
-
var _b = input.data, data = _b === void 0 ? {} : _b;
|
8666
|
+
function JSON2String({ input }) {
|
8667
|
+
const { data = {} } = input;
|
8826
8668
|
try {
|
8827
8669
|
return "```json" + JSON.stringify(data) + "json```";
|
8828
8670
|
}
|
@@ -8832,4 +8674,4 @@ function JSON2String(_a) {
|
|
8832
8674
|
}
|
8833
8675
|
|
8834
8676
|
export { JSON2String, request, userInputToJson };
|
8835
|
-
//# sourceMappingURL=
|
8677
|
+
//# sourceMappingURL=ywfe-tools.esm.js.map
|