lemon-core 3.0.0 → 3.0.2
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/README.md +11 -21
- package/dist/cores/cache-service.js +12 -12
- package/dist/cores/cache-service.js.map +1 -1
- package/dist/helpers/helpers.d.ts +266 -0
- package/dist/helpers/helpers.js +600 -0
- package/dist/helpers/helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +10 -0
- package/dist/helpers/index.js +23 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/helpers.d.ts +243 -0
- package/dist/tools/helpers.js +593 -0
- package/dist/tools/helpers.js.map +1 -0
- package/package.json +1 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -54,6 +54,7 @@ exports.lib = lib;
|
|
|
54
54
|
const tools = __importStar(require("./tools/"));
|
|
55
55
|
exports.tools = tools;
|
|
56
56
|
const controllers = __importStar(require("./controllers/"));
|
|
57
|
+
__exportStar(require("./helpers/"), exports);
|
|
57
58
|
//! export as default.
|
|
58
59
|
exports.default = { engine: engine_1.default, cores: cores_1.default, tools, controllers };
|
|
59
60
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,8EAA8E;AAC9E,iDAA+B;AAC/B,uDAAqC;AACrC,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,iDAA+B;AAE/B,wBAAwB;AACxB,uDAA+B;AAC/B,qDAA6B;AAE7B,4CAA8B;AAKrB,kBAAG;AAJZ,gDAAkC;AAIpB,sBAAK;AAHnB,4DAA8C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,8EAA8E;AAC9E,iDAA+B;AAC/B,uDAAqC;AACrC,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,iDAA+B;AAE/B,wBAAwB;AACxB,uDAA+B;AAC/B,qDAA6B;AAE7B,4CAA8B;AAKrB,kBAAG;AAJZ,gDAAkC;AAIpB,sBAAK;AAHnB,4DAA8C;AAI9C,6CAA2B;AAE3B,sBAAsB;AACtB,kBAAe,EAAE,MAAM,EAAN,gBAAM,EAAE,KAAK,EAAL,eAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { NextContext } from '../cores/';
|
|
2
|
+
/**
|
|
3
|
+
* type: simple data-types
|
|
4
|
+
* - it should be compartible with elastic-search.
|
|
5
|
+
* - it should be consistancy within same key name.
|
|
6
|
+
*/
|
|
7
|
+
export interface SimpleSet {
|
|
8
|
+
[key: string]: string | number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Helpers to transform data-types.
|
|
12
|
+
*/
|
|
13
|
+
export declare const $T: {
|
|
14
|
+
/**
|
|
15
|
+
* transform to string w/ trim()
|
|
16
|
+
*/
|
|
17
|
+
S: (val: any, def?: string) => string;
|
|
18
|
+
/**
|
|
19
|
+
* as string w/o white-space.
|
|
20
|
+
*/
|
|
21
|
+
S2: (val: any, def?: string, delim?: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* transform to string[]
|
|
24
|
+
*/
|
|
25
|
+
SS: (val: any, def?: string[]) => string[];
|
|
26
|
+
/**
|
|
27
|
+
* text to Plain text (remove html tag)
|
|
28
|
+
*/
|
|
29
|
+
P: (text: string, max?: number) => string;
|
|
30
|
+
/**
|
|
31
|
+
* transform to number(integer).
|
|
32
|
+
*/
|
|
33
|
+
N: (val: any, def?: number) => number;
|
|
34
|
+
/**
|
|
35
|
+
* number array
|
|
36
|
+
*/
|
|
37
|
+
NN: (val: any, def?: number[]) => number[];
|
|
38
|
+
/**
|
|
39
|
+
* transform to number(float)
|
|
40
|
+
*/
|
|
41
|
+
F: (val: any, def?: number) => number;
|
|
42
|
+
/**
|
|
43
|
+
* transform to number(float)[]
|
|
44
|
+
*/
|
|
45
|
+
FF: (val: any, def?: number[]) => number[];
|
|
46
|
+
B: (val: any, def?: 0 | 1) => 0 | 1;
|
|
47
|
+
/**
|
|
48
|
+
* transform to Time number via string | number.
|
|
49
|
+
*/
|
|
50
|
+
T: (val: any, def?: number) => number;
|
|
51
|
+
/**
|
|
52
|
+
* transform to Date formatted string
|
|
53
|
+
*/
|
|
54
|
+
D: (val: any, def?: string) => string;
|
|
55
|
+
/**
|
|
56
|
+
* date-time format
|
|
57
|
+
*/
|
|
58
|
+
DT: (val: any, def?: string) => string;
|
|
59
|
+
/**
|
|
60
|
+
* Extract Text
|
|
61
|
+
*/
|
|
62
|
+
EX: (data: string, txt1: string, txt2: string) => string;
|
|
63
|
+
/**
|
|
64
|
+
* transform to simple-set.
|
|
65
|
+
* @param val json object.
|
|
66
|
+
*/
|
|
67
|
+
simples: (val: any, throws?: boolean) => SimpleSet;
|
|
68
|
+
/**
|
|
69
|
+
* catch string between txt1 and txt2
|
|
70
|
+
* @param data string
|
|
71
|
+
* @param txt1 head
|
|
72
|
+
* @param txt2 tail
|
|
73
|
+
*/
|
|
74
|
+
catch: (data: any, txt1: string, txt2: string) => any;
|
|
75
|
+
/**
|
|
76
|
+
* merge simple-set from $org to $new
|
|
77
|
+
* @param $org the origin set
|
|
78
|
+
* @param $new the update set.
|
|
79
|
+
*/
|
|
80
|
+
merge: ($org: SimpleSet, $new: SimpleSet) => SimpleSet;
|
|
81
|
+
/**
|
|
82
|
+
* replace message with template.
|
|
83
|
+
*/
|
|
84
|
+
template: (msg: string, set: {
|
|
85
|
+
[key: string]: string | number;
|
|
86
|
+
}) => string;
|
|
87
|
+
/**
|
|
88
|
+
* make random-code by length
|
|
89
|
+
* @param size length of code
|
|
90
|
+
* @param rand flag to use random (0 => 0, 1 => max)
|
|
91
|
+
*/
|
|
92
|
+
makeRandomCode: (size?: number, rand?: boolean | number) => {
|
|
93
|
+
val: number;
|
|
94
|
+
min: number;
|
|
95
|
+
max: number;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* 객체 정규화 시킴.
|
|
99
|
+
* - null 에 대해서는 특별히 처리.
|
|
100
|
+
*/
|
|
101
|
+
normal: <T = object>(N: T) => T;
|
|
102
|
+
/**
|
|
103
|
+
* transform list to map by `id`
|
|
104
|
+
*/
|
|
105
|
+
asMap: <T_1>(list: T_1[], id?: string) => {
|
|
106
|
+
[key: string]: T_1;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* compare object, and extract the only diff properties.
|
|
110
|
+
*/
|
|
111
|
+
diff: <T_2 = any>(A: T_2, B: T_2, onlyValid?: boolean) => T_2;
|
|
112
|
+
/**
|
|
113
|
+
* get $perf instance.
|
|
114
|
+
* ```ts
|
|
115
|
+
* const p = $T.perf()
|
|
116
|
+
* const took = p.took();
|
|
117
|
+
*/
|
|
118
|
+
perf: () => {
|
|
119
|
+
readonly t0: number;
|
|
120
|
+
took: () => number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* parse `.meta` property as object.
|
|
124
|
+
* @param meta any
|
|
125
|
+
*/
|
|
126
|
+
parseMeta: <T_3 extends {
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
type?: string;
|
|
129
|
+
value?: any;
|
|
130
|
+
error?: string;
|
|
131
|
+
list?: any[];
|
|
132
|
+
}>(meta: any) => T_3;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* random number generator
|
|
136
|
+
*/
|
|
137
|
+
export declare const $rand: {
|
|
138
|
+
/**
|
|
139
|
+
* list of number[] in n-size.
|
|
140
|
+
*/
|
|
141
|
+
range: (n: number) => number[];
|
|
142
|
+
/**
|
|
143
|
+
* generate random number
|
|
144
|
+
*/
|
|
145
|
+
float: (from: number, to: number) => number;
|
|
146
|
+
/**
|
|
147
|
+
* generate multiple float numbers
|
|
148
|
+
*/
|
|
149
|
+
floats: (from: number, to: number, n: number) => number[];
|
|
150
|
+
/**
|
|
151
|
+
* generate an integer
|
|
152
|
+
*/
|
|
153
|
+
integer: (from: number, to: number) => number;
|
|
154
|
+
/**
|
|
155
|
+
* generate multiple integers
|
|
156
|
+
*/
|
|
157
|
+
integers: (from: number, to: number, n: number) => number[];
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* builder to support protocol-service.
|
|
161
|
+
* @param context the current context (or service name).
|
|
162
|
+
* @param service service name
|
|
163
|
+
* @param options additional options.
|
|
164
|
+
*/
|
|
165
|
+
export declare const $protocol: (context?: NextContext | string, service?: string, options?: {
|
|
166
|
+
param?: any;
|
|
167
|
+
body?: any;
|
|
168
|
+
isProd?: boolean;
|
|
169
|
+
}) => {
|
|
170
|
+
hello: () => string;
|
|
171
|
+
asTargetUrl: () => string;
|
|
172
|
+
execute: <T = any>(param?: any, body?: any, mode?: string) => Promise<T>;
|
|
173
|
+
enqueue: <T_1 = any>(param?: any, body?: any, mode?: string, callback?: string, delaySeconds?: number) => Promise<string>;
|
|
174
|
+
notify: (param?: any, body?: any, mode?: string, callback?: string) => Promise<string>;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* get the current config info
|
|
178
|
+
*/
|
|
179
|
+
export declare const $info: () => {
|
|
180
|
+
service: string;
|
|
181
|
+
version: string;
|
|
182
|
+
stage: import("../cores").STAGE;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* send message to slack/public
|
|
186
|
+
*
|
|
187
|
+
* @param title 헤터 타이틀
|
|
188
|
+
* @param text object or 텍스트 내용
|
|
189
|
+
* @param pretext (optional) 텍스트 미리보기용.
|
|
190
|
+
* @param params (optional) customize more options.
|
|
191
|
+
*/
|
|
192
|
+
export declare const $slack: (title?: string, text?: string | object, pretext?: string, params?: {
|
|
193
|
+
channel?: string;
|
|
194
|
+
color?: string;
|
|
195
|
+
scope?: string;
|
|
196
|
+
fields?: {
|
|
197
|
+
title: string;
|
|
198
|
+
value: string;
|
|
199
|
+
short?: boolean;
|
|
200
|
+
}[];
|
|
201
|
+
footer?: string;
|
|
202
|
+
context?: NextContext;
|
|
203
|
+
}) => Promise<string>;
|
|
204
|
+
/**
|
|
205
|
+
* event producer builder
|
|
206
|
+
* @param context current context
|
|
207
|
+
* @param defEndpoint (optional) the default endpoint.
|
|
208
|
+
*/
|
|
209
|
+
export declare const $event: (context: NextContext, defEndpoint?: string) => {
|
|
210
|
+
publish: (body: {
|
|
211
|
+
[key: string]: any;
|
|
212
|
+
}) => Promise<string>;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* authentication helper - get identity-id from context
|
|
216
|
+
* @param ctx
|
|
217
|
+
*/
|
|
218
|
+
export declare function getIdentityId(ctx: NextContext): string | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* authentication helper - check user is authorized
|
|
221
|
+
* - 이 메서드는 AWS IAM 인증 여부만을 확인한다.
|
|
222
|
+
* - 따라서 true를 반환한다고 하여 회원 가입이 되어있다는 의미는 아니다.
|
|
223
|
+
*
|
|
224
|
+
* @param ctx the current context
|
|
225
|
+
* @param param (optional) to override `identity` when running local.
|
|
226
|
+
*/
|
|
227
|
+
export declare function isUserAuthorized(ctx: NextContext, param?: any): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* parse range expression
|
|
230
|
+
* @param exp range expression (e.g. '[63100 TO 224000]' or '[* TO 150000}')
|
|
231
|
+
*/
|
|
232
|
+
export declare function parseRange(exp: string): any;
|
|
233
|
+
/**
|
|
234
|
+
* customized of `do_parrallel` for safe error-handling.
|
|
235
|
+
* - use `.error` to report the internal error.
|
|
236
|
+
*/
|
|
237
|
+
export declare const my_parrallel: <T extends {
|
|
238
|
+
id?: string;
|
|
239
|
+
error?: string;
|
|
240
|
+
}, U extends {
|
|
241
|
+
id?: string;
|
|
242
|
+
error?: string;
|
|
243
|
+
}>(list: T[], func: (item: T, index?: number) => Promise<U>, size?: number) => Promise<U[]>;
|