xjs-common 7.0.0
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/LICENSE +202 -0
- package/README.md +216 -0
- package/dist/const/gender.d.ts +4 -0
- package/dist/const/gender.js +8 -0
- package/dist/const/http-method.d.ts +8 -0
- package/dist/const/http-method.js +12 -0
- package/dist/const/types.d.ts +12 -0
- package/dist/const/types.js +14 -0
- package/dist/func/decorator/d-type.d.ts +24 -0
- package/dist/func/decorator/d-type.js +71 -0
- package/dist/func/decorator/d-validate.d.ts +20 -0
- package/dist/func/decorator/d-validate.js +64 -0
- package/dist/func/decorator/transaction.d.ts +7 -0
- package/dist/func/decorator/transaction.js +36 -0
- package/dist/func/u-array.d.ts +40 -0
- package/dist/func/u-array.js +67 -0
- package/dist/func/u-file.d.ts +10 -0
- package/dist/func/u-file.js +69 -0
- package/dist/func/u-http.d.ts +7 -0
- package/dist/func/u-http.js +25 -0
- package/dist/func/u-obj.d.ts +18 -0
- package/dist/func/u-obj.js +44 -0
- package/dist/func/u-string.d.ts +9 -0
- package/dist/func/u-string.js +56 -0
- package/dist/func/u-type.d.ts +21 -0
- package/dist/func/u-type.js +53 -0
- package/dist/func/u.d.ts +6 -0
- package/dist/func/u.js +45 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +35 -0
- package/dist/obj/type-exp.d.ts +8 -0
- package/dist/obj/type-exp.js +23 -0
- package/dist/obj/xjs-err.d.ts +4 -0
- package/dist/obj/xjs-err.js +11 -0
- package/dist/prcs/http/http-resolver-context.d.ts +46 -0
- package/dist/prcs/http/http-resolver-context.js +287 -0
- package/dist/prcs/http/http-resolver.d.ts +38 -0
- package/dist/prcs/http/http-resolver.js +52 -0
- package/dist/prcs/http/i-http-client.d.ts +37 -0
- package/dist/prcs/http/i-http-client.js +2 -0
- package/dist/prcs/http-resolver.d.ts +53 -0
- package/dist/prcs/http-resolver.js +255 -0
- package/package.json +30 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.transaction = void 0;
|
4
|
+
const xjs_err_1 = require("../../obj/xjs-err");
|
5
|
+
const u_1 = require("../u");
|
6
|
+
const s_errCode = 100;
|
7
|
+
/**
|
8
|
+
* applies transation to the method. note that the method must return a Promise.
|
9
|
+
* @param op.timeoutSec default is `30`.
|
10
|
+
*/
|
11
|
+
function transaction(op) {
|
12
|
+
let lock = 0;
|
13
|
+
const timeoutSec = op?.timeoutSec ?? 30;
|
14
|
+
return (target, propertyKey, descriptor) => {
|
15
|
+
const method = descriptor.value;
|
16
|
+
async function exe(...p) {
|
17
|
+
const timelimit = Date.now() + timeoutSec * 1000;
|
18
|
+
while (lock > 0) {
|
19
|
+
if (timelimit <= Date.now())
|
20
|
+
throw new xjs_err_1.XjsErr(s_errCode, "An exclusive process to execute was already running by other request.");
|
21
|
+
await (0, u_1.delay)(1);
|
22
|
+
}
|
23
|
+
try {
|
24
|
+
lock++;
|
25
|
+
const ret = method.apply(this, p);
|
26
|
+
return ret instanceof Promise ? await ret : ret;
|
27
|
+
}
|
28
|
+
finally {
|
29
|
+
lock--;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
;
|
33
|
+
descriptor.value = exe;
|
34
|
+
};
|
35
|
+
}
|
36
|
+
exports.transaction = transaction;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
export declare namespace UArray {
|
2
|
+
/**
|
3
|
+
* compares two arrays to valuate equality.
|
4
|
+
* if one side is null or undefined, it returns true when other side is the same.
|
5
|
+
* @param v1 it uses equal operator for comparing elements, so applying object element is not recommended.
|
6
|
+
* @param v2 same as v1.
|
7
|
+
* @param sort it uses {@link Array#sort} on v1 and v2 if true. default is true.
|
8
|
+
* @param useStrictEqual it uses === operator for compareing elements if true, otherwise using == operator. default is true.
|
9
|
+
*/
|
10
|
+
function eq(v1: any[], v2: any[], op: {
|
11
|
+
sort?: boolean;
|
12
|
+
useStrictEqual: false;
|
13
|
+
}): boolean;
|
14
|
+
function eq<T>(v1: T[], v2: T[], op: {
|
15
|
+
sort?: boolean;
|
16
|
+
useStrictEqual: true;
|
17
|
+
}): boolean;
|
18
|
+
function eq<T>(v1: T[], v2: T[], op: {
|
19
|
+
sort?: boolean;
|
20
|
+
}): boolean;
|
21
|
+
function eq<T>(v1: T[], v2: T[]): boolean;
|
22
|
+
/**
|
23
|
+
* returns array which is removed duplicate of elements.
|
24
|
+
* this doesn't mutate the param.
|
25
|
+
*/
|
26
|
+
function distinct<T>(array: T[]): T[];
|
27
|
+
function distinct<T>(array: T[], op: {
|
28
|
+
k: keyof T;
|
29
|
+
takeLast?: boolean;
|
30
|
+
}): T[];
|
31
|
+
function distinct<T>(array: T[], op: {
|
32
|
+
predicate: (v1: T, v2: T) => boolean;
|
33
|
+
takeLast?: boolean;
|
34
|
+
}): T[];
|
35
|
+
function chop<T>(array: T[], len: number): T[][];
|
36
|
+
function remove<T>(array: T[], v: T): void;
|
37
|
+
function randomPick<T>(array: T[], takeout?: boolean): T;
|
38
|
+
function shuffle<T>(array: T[]): T[];
|
39
|
+
function takeOut<T>(array: T[], filter: (v: T, i?: number) => boolean): T[];
|
40
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UArray = void 0;
|
4
|
+
const u_1 = require("./u");
|
5
|
+
var UArray;
|
6
|
+
(function (UArray) {
|
7
|
+
function eq(v1, v2, op = {}) {
|
8
|
+
const { sort, useStrictEqual } = Object.assign({ sort: true, useStrictEqual: true }, op);
|
9
|
+
if (v1 && !v2 || !v1 && v2)
|
10
|
+
return false;
|
11
|
+
if (!v1)
|
12
|
+
return true;
|
13
|
+
if (v1.length !== v2.length)
|
14
|
+
return false;
|
15
|
+
const a = sort ? [...v1].sort() : v1, b = sort ? [...v2].sort() : v2;
|
16
|
+
return a.every((v, i) => useStrictEqual ? v === b[i] : v == b[i]);
|
17
|
+
}
|
18
|
+
UArray.eq = eq;
|
19
|
+
function distinct(array, op) {
|
20
|
+
if (!array || array.length === 0)
|
21
|
+
return [];
|
22
|
+
if (op?.k)
|
23
|
+
return Array.from((0, u_1.array2map)(array, e => e[op.k]).values()).map(a => op?.takeLast ? a.pop() : a.shift());
|
24
|
+
const a = op?.takeLast ? [...array].reverse() : array;
|
25
|
+
return a.filter((v, i) => a.findIndex(v2 => op?.predicate ? op?.predicate(v, v2) : v == v2) === i);
|
26
|
+
}
|
27
|
+
UArray.distinct = distinct;
|
28
|
+
function chop(array, len) {
|
29
|
+
return [...Array(Math.ceil(array.length / len)).keys()]
|
30
|
+
.map(i => {
|
31
|
+
let endIdx = (i + 1) * len;
|
32
|
+
if (endIdx > array.length)
|
33
|
+
endIdx = array.length;
|
34
|
+
return array.slice(i * len, endIdx);
|
35
|
+
});
|
36
|
+
}
|
37
|
+
UArray.chop = chop;
|
38
|
+
function remove(array, v) {
|
39
|
+
const idx = array.indexOf(v);
|
40
|
+
if (idx !== -1)
|
41
|
+
array.splice(idx, 1);
|
42
|
+
}
|
43
|
+
UArray.remove = remove;
|
44
|
+
function randomPick(array, takeout = true) {
|
45
|
+
const i = Math.floor(array.length * Math.random());
|
46
|
+
const r = array[i];
|
47
|
+
if (takeout)
|
48
|
+
array.splice(i, 1);
|
49
|
+
return r;
|
50
|
+
}
|
51
|
+
UArray.randomPick = randomPick;
|
52
|
+
function shuffle(array) {
|
53
|
+
const cp = [...array];
|
54
|
+
return (0, u_1.int2array)(array.length).map(_ => randomPick(cp));
|
55
|
+
}
|
56
|
+
UArray.shuffle = shuffle;
|
57
|
+
function takeOut(array, filter) {
|
58
|
+
const result = [];
|
59
|
+
for (let i = array.length - 1; i >= 0; i--)
|
60
|
+
if (filter(array[i], i)) {
|
61
|
+
result.unshift(array[i]);
|
62
|
+
array.splice(i, 1);
|
63
|
+
}
|
64
|
+
return result;
|
65
|
+
}
|
66
|
+
UArray.takeOut = takeOut;
|
67
|
+
})(UArray = exports.UArray || (exports.UArray = {}));
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
export declare namespace UFile {
|
3
|
+
function mkdir(p: string | string[]): boolean;
|
4
|
+
function write(p: string | string[], c: string): void;
|
5
|
+
function exists(...p: string[]): boolean;
|
6
|
+
function read(p: string | string[]): Buffer;
|
7
|
+
function read(p: string | string[], encoding: BufferEncoding): string;
|
8
|
+
function cp(from: string | string[], to: string | string[]): void;
|
9
|
+
function mv(from: string | string[], to: string | string[]): void;
|
10
|
+
}
|
@@ -0,0 +1,69 @@
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.UFile = void 0;
|
27
|
+
const fs = __importStar(require("fs"));
|
28
|
+
const path = __importStar(require("path"));
|
29
|
+
const u_type_1 = require("./u-type");
|
30
|
+
var UFile;
|
31
|
+
(function (UFile) {
|
32
|
+
function mkdir(p) {
|
33
|
+
const dirPath = join(p);
|
34
|
+
const e = fs.existsSync(dirPath);
|
35
|
+
if (!e || !fs.statSync(dirPath).isDirectory())
|
36
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
37
|
+
return !e;
|
38
|
+
}
|
39
|
+
UFile.mkdir = mkdir;
|
40
|
+
function write(p, c) {
|
41
|
+
fs.writeFileSync(join(p), c);
|
42
|
+
}
|
43
|
+
UFile.write = write;
|
44
|
+
function exists(...p) {
|
45
|
+
return !!p && fs.existsSync(path.join(...p));
|
46
|
+
}
|
47
|
+
UFile.exists = exists;
|
48
|
+
function read(p, encoding) {
|
49
|
+
return fs.readFileSync(join(p), encoding);
|
50
|
+
}
|
51
|
+
UFile.read = read;
|
52
|
+
function cp(from, to) {
|
53
|
+
const f = join(from), t = join(to);
|
54
|
+
if (fs.existsSync(f))
|
55
|
+
fs.writeFileSync(t, fs.readFileSync(f));
|
56
|
+
}
|
57
|
+
UFile.cp = cp;
|
58
|
+
function mv(from, to) {
|
59
|
+
const f = join(from), t = join(to);
|
60
|
+
if (fs.existsSync(f) && fs.statSync(f).isFile()) {
|
61
|
+
fs.writeFileSync(t, fs.readFileSync(f));
|
62
|
+
fs.rmSync(f, { force: true });
|
63
|
+
}
|
64
|
+
}
|
65
|
+
UFile.mv = mv;
|
66
|
+
function join(p) {
|
67
|
+
return u_type_1.UType.isString(p) ? p : path.join(...p);
|
68
|
+
}
|
69
|
+
})(UFile = exports.UFile || (exports.UFile = {}));
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UHttp = void 0;
|
4
|
+
var UHttp;
|
5
|
+
(function (UHttp) {
|
6
|
+
function isHttpSuccess(statusCode) {
|
7
|
+
return statusCategoryOf(statusCode) === 2;
|
8
|
+
}
|
9
|
+
UHttp.isHttpSuccess = isHttpSuccess;
|
10
|
+
function statusCategoryOf(statusCode) {
|
11
|
+
return Math.floor(statusCode / 100);
|
12
|
+
}
|
13
|
+
UHttp.statusCategoryOf = statusCategoryOf;
|
14
|
+
function concatParamsWithEncoding(end, params) {
|
15
|
+
if (!params || Object.keys(params).length === 0)
|
16
|
+
return end;
|
17
|
+
const paramsFlatten = Object.entries(params)
|
18
|
+
.flatMap(kv => Array.isArray(kv[1]) ? kv[1].map(v => [kv[0], v]) : [kv]);
|
19
|
+
let result = end ? end + "?" : "";
|
20
|
+
for (var kv of paramsFlatten)
|
21
|
+
result += kv[0] + "=" + encodeURIComponent(kv[1]) + "&";
|
22
|
+
return result.substring(0, result.length - 1);
|
23
|
+
}
|
24
|
+
UHttp.concatParamsWithEncoding = concatParamsWithEncoding;
|
25
|
+
})(UHttp = exports.UHttp || (exports.UHttp = {}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { NormalRecord } from "../const/types";
|
2
|
+
export declare namespace UObj {
|
3
|
+
/**
|
4
|
+
* assign properties to the object with specified property keys.
|
5
|
+
* @param t target object.
|
6
|
+
* @param s source object.
|
7
|
+
* @param keys property keys which are copied from source object. if omit this, all keys in source object is applied.
|
8
|
+
* @param keepDtypeClass if true, class which has properties decorated with {@link DType} in target object is kept and that is assigned properties recursively.
|
9
|
+
*/
|
10
|
+
function assignProperties<T extends NormalRecord, S extends NormalRecord>(t: T, s: S, keys?: (keyof S)[], keepDtypeClass?: boolean): T & Partial<S>;
|
11
|
+
/**
|
12
|
+
* crop properties of the object. the properties is removed with `delete` operator.
|
13
|
+
* @param o object which properties is removed.
|
14
|
+
* @param keys property names to be remained. if omit this, it removes the properties other than properties decorated {@link DType}.
|
15
|
+
* @param exclusive if true, it removes `keys` instead of remaining it.
|
16
|
+
*/
|
17
|
+
function crop<T extends NormalRecord>(o: T, keys?: (keyof T)[], exclusive?: boolean): Partial<T>;
|
18
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UObj = void 0;
|
4
|
+
const d_type_1 = require("./decorator/d-type");
|
5
|
+
const u_type_1 = require("./u-type");
|
6
|
+
var UObj;
|
7
|
+
(function (UObj) {
|
8
|
+
/**
|
9
|
+
* assign properties to the object with specified property keys.
|
10
|
+
* @param t target object.
|
11
|
+
* @param s source object.
|
12
|
+
* @param keys property keys which are copied from source object. if omit this, all keys in source object is applied.
|
13
|
+
* @param keepDtypeClass if true, class which has properties decorated with {@link DType} in target object is kept and that is assigned properties recursively.
|
14
|
+
*/
|
15
|
+
function assignProperties(t, s, keys, keepDtypeClass) {
|
16
|
+
for (const k of keys ?? Object.keys(s))
|
17
|
+
if (u_type_1.UType.isDefined(s[k]))
|
18
|
+
if (keepDtypeClass && u_type_1.UType.isObject(t[k]) && u_type_1.UType.isObject(s[k]) && t[k]?.[d_type_1.smbl_tm]) {
|
19
|
+
assignProperties(t[k], s[k], null, true);
|
20
|
+
}
|
21
|
+
else
|
22
|
+
t[k] = s[k];
|
23
|
+
return t;
|
24
|
+
}
|
25
|
+
UObj.assignProperties = assignProperties;
|
26
|
+
/**
|
27
|
+
* crop properties of the object. the properties is removed with `delete` operator.
|
28
|
+
* @param o object which properties is removed.
|
29
|
+
* @param keys property names to be remained. if omit this, it removes the properties other than properties decorated {@link DType}.
|
30
|
+
* @param exclusive if true, it removes `keys` instead of remaining it.
|
31
|
+
*/
|
32
|
+
function crop(o, keys, exclusive) {
|
33
|
+
if (!keys && !o[d_type_1.smbl_tm])
|
34
|
+
return {};
|
35
|
+
const _keys = keys ?? Object.keys(o[d_type_1.smbl_tm]);
|
36
|
+
Object.keys(o).filter(k => {
|
37
|
+
if (!keys && o[d_type_1.smbl_tm]?.[k]?.rec)
|
38
|
+
crop(o[k]);
|
39
|
+
return !!exclusive === _keys.includes(k);
|
40
|
+
}).forEach(k => delete o[k]);
|
41
|
+
return o;
|
42
|
+
}
|
43
|
+
UObj.crop = crop;
|
44
|
+
})(UObj = exports.UObj || (exports.UObj = {}));
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare namespace UString {
|
2
|
+
function eq(s1: string, s2: string): boolean;
|
3
|
+
function simpleDate2sec(date?: Date): string;
|
4
|
+
function simpleDate2day(date?: Date): string;
|
5
|
+
function trimProps(obj: any): void;
|
6
|
+
function generateRandomString(len: number): string;
|
7
|
+
function idx2az(idx: number): string;
|
8
|
+
function az2idx(az: string): number;
|
9
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UString = void 0;
|
4
|
+
const xjs_err_1 = require("../obj/xjs-err");
|
5
|
+
const u_1 = require("./u");
|
6
|
+
const u_type_1 = require("./u-type");
|
7
|
+
const s_errCode = 20;
|
8
|
+
var UString;
|
9
|
+
(function (UString) {
|
10
|
+
function eq(s1, s2) {
|
11
|
+
return !u_type_1.UType.isString(s1) || !u_type_1.UType.isString(s2) ? s1 === s2 : s1.trim() === s2.trim();
|
12
|
+
}
|
13
|
+
UString.eq = eq;
|
14
|
+
function simpleDate2sec(date) {
|
15
|
+
return (date ?? new Date()).toISOString().split(".")[0].replace(/[-T:]/g, "");
|
16
|
+
}
|
17
|
+
UString.simpleDate2sec = simpleDate2sec;
|
18
|
+
function simpleDate2day(date) {
|
19
|
+
return simpleDate2sec(date).substring(0, 8);
|
20
|
+
}
|
21
|
+
UString.simpleDate2day = simpleDate2day;
|
22
|
+
function trimProps(obj) {
|
23
|
+
Object.keys(obj)
|
24
|
+
.filter(k => typeof obj[k] === "string")
|
25
|
+
.forEach(k => obj[k] = obj[k]?.trim());
|
26
|
+
}
|
27
|
+
UString.trimProps = trimProps;
|
28
|
+
function generateRandomString(len) {
|
29
|
+
return (0, u_1.int2array)(len).map(_ => {
|
30
|
+
let rnd = Math.floor(62 * Math.random());
|
31
|
+
const remain = rnd - 52;
|
32
|
+
if (remain >= 0)
|
33
|
+
return remain.toString();
|
34
|
+
if (rnd > 26)
|
35
|
+
rnd += 6;
|
36
|
+
return String.fromCharCode(rnd + 65);
|
37
|
+
}).join("");
|
38
|
+
}
|
39
|
+
UString.generateRandomString = generateRandomString;
|
40
|
+
function idx2az(idx) {
|
41
|
+
let az = "", num = idx;
|
42
|
+
while (num >= 0) {
|
43
|
+
az = String.fromCharCode(num % 26 + 97) + az;
|
44
|
+
num = Math.floor(num / 26) - 1;
|
45
|
+
}
|
46
|
+
return az.toUpperCase();
|
47
|
+
}
|
48
|
+
UString.idx2az = idx2az;
|
49
|
+
function az2idx(az) {
|
50
|
+
if (!az?.match(/^[a-zA-Z]+$/))
|
51
|
+
throw new xjs_err_1.XjsErr(s_errCode, "the parameter isn't az(AZ) format.");
|
52
|
+
return az.toLowerCase().split("").map(c => c.charCodeAt(0) - 97).reverse()
|
53
|
+
.map((idx, i) => (idx + 1) * (26 ** i)).reduce((v1, v2) => v1 + v2) - 1;
|
54
|
+
}
|
55
|
+
UString.az2idx = az2idx;
|
56
|
+
})(UString = exports.UString || (exports.UString = {}));
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Type } from "../const/types";
|
2
|
+
export declare namespace UType {
|
3
|
+
function isDefined(v: any): boolean;
|
4
|
+
function isEmpty(v: any): boolean;
|
5
|
+
function isString(v: any): v is string;
|
6
|
+
function isNumber(v: any): v is number;
|
7
|
+
function isBigint(v: any): v is bigint;
|
8
|
+
function isBoolean(v: any): v is boolean;
|
9
|
+
function isSymbol(v: any): v is symbol;
|
10
|
+
function isObject(v: any): v is object;
|
11
|
+
function isArray(v: any, t: Type.string): v is string[];
|
12
|
+
function isArray(v: any, t: Type.number): v is number[];
|
13
|
+
function isArray(v: any, t: Type.bigint): v is bigint[];
|
14
|
+
function isArray(v: any, t: Type.boolean): v is boolean[];
|
15
|
+
function isArray(v: any, t: Type.symbol): v is symbol[];
|
16
|
+
function isArray(v: any, t: Type.object): v is object[];
|
17
|
+
function isArray(v: any): v is any[];
|
18
|
+
/** validate properties which attached decorators in {@link DType} */
|
19
|
+
function validate(o: any): boolean;
|
20
|
+
function takeAsArray<T>(v: T | T[]): T[];
|
21
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.UType = void 0;
|
4
|
+
const types_1 = require("../const/types");
|
5
|
+
const d_type_1 = require("./decorator/d-type");
|
6
|
+
var UType;
|
7
|
+
(function (UType) {
|
8
|
+
function isDefined(v) {
|
9
|
+
return typeof v !== types_1.Type.undefined;
|
10
|
+
}
|
11
|
+
UType.isDefined = isDefined;
|
12
|
+
function isEmpty(v) {
|
13
|
+
return v === null || typeof v === types_1.Type.undefined;
|
14
|
+
}
|
15
|
+
UType.isEmpty = isEmpty;
|
16
|
+
function isString(v) { return typeof v === types_1.Type.string; }
|
17
|
+
UType.isString = isString;
|
18
|
+
function isNumber(v) { return typeof v === types_1.Type.number; }
|
19
|
+
UType.isNumber = isNumber;
|
20
|
+
function isBigint(v) { return typeof v === types_1.Type.bigint; }
|
21
|
+
UType.isBigint = isBigint;
|
22
|
+
function isBoolean(v) { return typeof v === types_1.Type.boolean; }
|
23
|
+
UType.isBoolean = isBoolean;
|
24
|
+
function isSymbol(v) { return typeof v === types_1.Type.symbol; }
|
25
|
+
UType.isSymbol = isSymbol;
|
26
|
+
function isObject(v) { return typeof v === types_1.Type.object; }
|
27
|
+
UType.isObject = isObject;
|
28
|
+
function isArray(v, t) {
|
29
|
+
return Array.isArray(v) && (!t || v.every(e => typeof e === t));
|
30
|
+
}
|
31
|
+
UType.isArray = isArray;
|
32
|
+
/** validate properties which attached decorators in {@link DType} */
|
33
|
+
function validate(o) {
|
34
|
+
return !o[d_type_1.smbl_tm] || Object.entries(o[d_type_1.smbl_tm])
|
35
|
+
.every(e => validateProp(o[e[0]], e[1]));
|
36
|
+
}
|
37
|
+
UType.validate = validate;
|
38
|
+
function validateProp(prop, td) {
|
39
|
+
if (isEmpty(prop))
|
40
|
+
return !td.req;
|
41
|
+
if (td.t && typeof prop !== td.t)
|
42
|
+
return false;
|
43
|
+
if (td.ary)
|
44
|
+
return Array.isArray(prop) && (!td.ary || prop.every(e => validateProp(e, td.ary)));
|
45
|
+
if (td.rec)
|
46
|
+
return validate(prop);
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
function takeAsArray(v) {
|
50
|
+
return Array.isArray(v) ? v : [v];
|
51
|
+
}
|
52
|
+
UType.takeAsArray = takeAsArray;
|
53
|
+
})(UType = exports.UType || (exports.UType = {}));
|
package/dist/func/u.d.ts
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare function getJSTDate(): Date;
|
2
|
+
export declare function delay(sec: number): Promise<void>;
|
3
|
+
export declare function int2array(size: number): number[];
|
4
|
+
export declare function array2map<K, T>(array: T[], keyGen: (e: T) => K): Map<K, T[]>;
|
5
|
+
export declare function bitor(...bit: number[]): number;
|
6
|
+
export declare function checkPortAvailability(port: number): Promise<boolean>;
|
package/dist/func/u.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.checkPortAvailability = exports.bitor = exports.array2map = exports.int2array = exports.delay = exports.getJSTDate = void 0;
|
4
|
+
const xjs_err_1 = require("../obj/xjs-err");
|
5
|
+
const s_errCode = 10;
|
6
|
+
function getJSTDate() {
|
7
|
+
return new Date(Date.now() + 9 * 60 * 60 * 1000);
|
8
|
+
}
|
9
|
+
exports.getJSTDate = getJSTDate;
|
10
|
+
function delay(sec) {
|
11
|
+
return new Promise(resolve => setTimeout(resolve, 1000 * sec));
|
12
|
+
}
|
13
|
+
exports.delay = delay;
|
14
|
+
function int2array(size) {
|
15
|
+
const s = Number(size);
|
16
|
+
if (Number.isNaN(s))
|
17
|
+
throw new xjs_err_1.XjsErr(s_errCode, "size of the argument is not number.");
|
18
|
+
return Array.from(Array(s).keys());
|
19
|
+
}
|
20
|
+
exports.int2array = int2array;
|
21
|
+
function array2map(array, keyGen) {
|
22
|
+
const map = new Map();
|
23
|
+
for (const e of array) {
|
24
|
+
const k = keyGen(e);
|
25
|
+
if (map.has(k))
|
26
|
+
map.get(k).push(e);
|
27
|
+
else
|
28
|
+
map.set(k, [e]);
|
29
|
+
}
|
30
|
+
return map;
|
31
|
+
}
|
32
|
+
exports.array2map = array2map;
|
33
|
+
function bitor(...bit) {
|
34
|
+
return bit.reduce((a, b) => a | b);
|
35
|
+
}
|
36
|
+
exports.bitor = bitor;
|
37
|
+
function checkPortAvailability(port) {
|
38
|
+
return new Promise(resolve => {
|
39
|
+
const server = require('net').createServer();
|
40
|
+
server.once('error', () => resolve(false))
|
41
|
+
.once('listening', () => { server.close(); resolve(true); })
|
42
|
+
.listen(port);
|
43
|
+
});
|
44
|
+
}
|
45
|
+
exports.checkPortAvailability = checkPortAvailability;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
export * from "./const/types";
|
2
|
+
export * from "./const/gender";
|
3
|
+
export * from "./const/http-method";
|
4
|
+
export * from "./func/u";
|
5
|
+
export * from "./func/u-obj";
|
6
|
+
export * from "./func/u-string";
|
7
|
+
export * from "./func/u-array";
|
8
|
+
export * from "./func/u-file";
|
9
|
+
export * from "./func/u-http";
|
10
|
+
export * from "./func/u-type";
|
11
|
+
export * from "./func/decorator/transaction";
|
12
|
+
export { DType } from "./func/decorator/d-type";
|
13
|
+
export * from "./obj/xjs-err";
|
14
|
+
export { HttpResolver } from "./prcs/http/http-resolver";
|
15
|
+
export { s_clientMode } from "./prcs/http/http-resolver-context";
|
16
|
+
export { IHttpClient } from "./prcs/http/i-http-client";
|
package/dist/index.js
ADDED
@@ -0,0 +1,35 @@
|
|
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
|
+
exports.s_clientMode = exports.HttpResolver = exports.DType = void 0;
|
18
|
+
__exportStar(require("./const/types"), exports);
|
19
|
+
__exportStar(require("./const/gender"), exports);
|
20
|
+
__exportStar(require("./const/http-method"), exports);
|
21
|
+
__exportStar(require("./func/u"), exports);
|
22
|
+
__exportStar(require("./func/u-obj"), exports);
|
23
|
+
__exportStar(require("./func/u-string"), exports);
|
24
|
+
__exportStar(require("./func/u-array"), exports);
|
25
|
+
__exportStar(require("./func/u-file"), exports);
|
26
|
+
__exportStar(require("./func/u-http"), exports);
|
27
|
+
__exportStar(require("./func/u-type"), exports);
|
28
|
+
__exportStar(require("./func/decorator/transaction"), exports);
|
29
|
+
var d_type_1 = require("./func/decorator/d-type");
|
30
|
+
Object.defineProperty(exports, "DType", { enumerable: true, get: function () { return d_type_1.DType; } });
|
31
|
+
__exportStar(require("./obj/xjs-err"), exports);
|
32
|
+
var http_resolver_1 = require("./prcs/http/http-resolver");
|
33
|
+
Object.defineProperty(exports, "HttpResolver", { enumerable: true, get: function () { return http_resolver_1.HttpResolver; } });
|
34
|
+
var http_resolver_context_1 = require("./prcs/http/http-resolver-context");
|
35
|
+
Object.defineProperty(exports, "s_clientMode", { enumerable: true, get: function () { return http_resolver_context_1.s_clientMode; } });
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Type } from "../const/types";
|
2
|
+
export declare class TypeExp<T> {
|
3
|
+
private t;
|
4
|
+
private readonly _m;
|
5
|
+
constructor(t: Type.string | Type.number | Type.bigint | Type.null | Type.symbol | Type.undefined);
|
6
|
+
constructor(t: Type.object, model: any);
|
7
|
+
match(o: any): o is T;
|
8
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TypeExp = void 0;
|
4
|
+
const types_1 = require("../const/types");
|
5
|
+
class TypeExp {
|
6
|
+
t;
|
7
|
+
_m;
|
8
|
+
constructor(t, model) {
|
9
|
+
this.t = t;
|
10
|
+
this._m = model;
|
11
|
+
}
|
12
|
+
match(o) {
|
13
|
+
if (typeof o !== this.t)
|
14
|
+
return false;
|
15
|
+
if (this.t !== types_1.Type.object)
|
16
|
+
return true;
|
17
|
+
const isArray = Array.isArray(o);
|
18
|
+
if (isArray !== Array.isArray(this._m))
|
19
|
+
return false;
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.TypeExp = TypeExp;
|