dff-util 1.3.4 → 1.3.6

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 CHANGED
@@ -341,20 +341,14 @@ export type KeyValueType = {
341
341
  [key: string]: any;
342
342
  }
343
343
 
344
- export type SearchByType = {
345
- orderBy?: string;
346
- order?: "ASC" | "DESC";
347
- searchTerm?: string;
348
- [key: string]: any;
349
- };
350
-
351
- export type SearchByLimitType = {
352
- limit: number;
353
- skip: number;
344
+ export type SearchType = {
345
+ limit?: number;
346
+ skip?: number;
354
347
  orderBy?: string;
355
- order?: "ASC" | "DESC";
348
+ order?: 'ASC' | 'DESC';
356
349
  searchTerm?: string;
357
- [key: string]: any;
350
+ active?: boolean;
351
+ filters?: string;
358
352
  };
359
353
 
360
354
  ```
@@ -601,12 +595,12 @@ const original = "Hello World! @#$% 😊";
601
595
 
602
596
  // Encode
603
597
  const safe = safeEncode(original);
604
- console.log(safe);
598
+ console.log(safe);
605
599
  // Output: "U0dWc2JHOGdWMjl5YkdRPQ%3D%3D"
606
600
 
607
601
  // Decode
608
602
  const decoded = safeDecode(safe);
609
- console.log(decoded);
603
+ console.log(decoded);
610
604
  // Output: "Hello World! @#$% 😊"
611
605
 
612
606
  // Multiple encode/decode calls (idempotent)
@@ -936,4 +930,190 @@ toSchemaMapper(viewObj) -->
936
930
  }
937
931
  }
938
932
 
939
- ```
933
+ ```
934
+
935
+ ```
936
+ const got = QueryCond(input);
937
+
938
+ example:
939
+ QueryCond input: isApproved=true,status!=false,age>18,score<100,height>=170,weight<=80,type=["accept","inprogress"],type!=["accept","inprogress"],role in ["admin","editor"],role not in ["admin","editor"],role notin ["admin","editor"],deletedAt is null,deletedAt is not null,deletedAt isnull,updatedAt isnotnull,deletedAt=null,deletedAt!=null,age between [18,30],createdAt between 2020-01-01..2020-01-31,name like "Jo%",email ilike "%@gmail.com",title contains "hello",code startswith "AB",code endswith "99",path regex "^/api/.*$",archivedAt,!archivedAt,name="a,b",meta={"a":1,"b":true},tags=["x,y","z"]
940
+ QueryCond output: [
941
+ {
942
+ "key": "isApproved",
943
+ "opt": "=",
944
+ "value": true
945
+ },
946
+ {
947
+ "key": "status",
948
+ "opt": "!=",
949
+ "value": false
950
+ },
951
+ {
952
+ "key": "age",
953
+ "opt": ">",
954
+ "value": 18
955
+ },
956
+ {
957
+ "key": "score",
958
+ "opt": "<",
959
+ "value": 100
960
+ },
961
+ {
962
+ "key": "height",
963
+ "opt": ">=",
964
+ "value": 170
965
+ },
966
+ {
967
+ "key": "weight",
968
+ "opt": "<=",
969
+ "value": 80
970
+ },
971
+ {
972
+ "key": "type",
973
+ "opt": "in",
974
+ "value": [
975
+ "accept",
976
+ "inprogress"
977
+ ]
978
+ },
979
+ {
980
+ "key": "type",
981
+ "opt": "not in",
982
+ "value": [
983
+ "accept",
984
+ "inprogress"
985
+ ]
986
+ },
987
+ {
988
+ "key": "role",
989
+ "opt": "in",
990
+ "value": [
991
+ "admin",
992
+ "editor"
993
+ ]
994
+ },
995
+ {
996
+ "key": "role",
997
+ "opt": "not in",
998
+ "value": [
999
+ "admin",
1000
+ "editor"
1001
+ ]
1002
+ },
1003
+ {
1004
+ "key": "role",
1005
+ "opt": "not in",
1006
+ "value": [
1007
+ "admin",
1008
+ "editor"
1009
+ ]
1010
+ },
1011
+ {
1012
+ "key": "deletedAt",
1013
+ "opt": "is null",
1014
+ "value": null
1015
+ },
1016
+ {
1017
+ "key": "deletedAt",
1018
+ "opt": "is not null",
1019
+ "value": null
1020
+ },
1021
+ {
1022
+ "key": "deletedAt",
1023
+ "opt": "is null",
1024
+ "value": null
1025
+ },
1026
+ {
1027
+ "key": "updatedAt",
1028
+ "opt": "is not null",
1029
+ "value": null
1030
+ },
1031
+ {
1032
+ "key": "deletedAt",
1033
+ "opt": "is null",
1034
+ "value": null
1035
+ },
1036
+ {
1037
+ "key": "deletedAt",
1038
+ "opt": "is not null",
1039
+ "value": null
1040
+ },
1041
+ {
1042
+ "key": "age",
1043
+ "opt": "between",
1044
+ "value": [
1045
+ 18,
1046
+ 30
1047
+ ]
1048
+ },
1049
+ {
1050
+ "key": "createdAt",
1051
+ "opt": "between",
1052
+ "value": [
1053
+ "2020-01-01",
1054
+ "2020-01-31"
1055
+ ]
1056
+ },
1057
+ {
1058
+ "key": "name",
1059
+ "opt": "like",
1060
+ "value": "Jo%"
1061
+ },
1062
+ {
1063
+ "key": "email",
1064
+ "opt": "ilike",
1065
+ "value": "%@gmail.com"
1066
+ },
1067
+ {
1068
+ "key": "title",
1069
+ "opt": "contains",
1070
+ "value": "hello"
1071
+ },
1072
+ {
1073
+ "key": "code",
1074
+ "opt": "startswith",
1075
+ "value": "AB"
1076
+ },
1077
+ {
1078
+ "key": "code",
1079
+ "opt": "endswith",
1080
+ "value": "99"
1081
+ },
1082
+ {
1083
+ "key": "path",
1084
+ "opt": "regex",
1085
+ "value": "^/api/.*$"
1086
+ },
1087
+ {
1088
+ "key": "archivedAt",
1089
+ "opt": "exists",
1090
+ "value": true
1091
+ },
1092
+ {
1093
+ "key": "archivedAt",
1094
+ "opt": "exists",
1095
+ "value": false
1096
+ },
1097
+ {
1098
+ "key": "name",
1099
+ "opt": "=",
1100
+ "value": "a,b"
1101
+ },
1102
+ {
1103
+ "key": "meta",
1104
+ "opt": "=",
1105
+ "value": {
1106
+ "a": 1,
1107
+ "b": true
1108
+ }
1109
+ },
1110
+ {
1111
+ "key": "tags",
1112
+ "opt": "in",
1113
+ "value": [
1114
+ "x,y",
1115
+ "z"
1116
+ ]
1117
+ }
1118
+ ]
1119
+ ```
@@ -27,19 +27,14 @@ export type ResponseType = {
27
27
  skip?: number;
28
28
  limit?: number;
29
29
  };
30
- export type SearchByType = {
31
- orderBy?: string;
32
- order?: "ASC" | "DESC";
33
- searchTerm?: string;
34
- [key: string]: any;
35
- };
36
- export type SearchByLimitType = {
37
- limit: number;
38
- skip: number;
30
+ export type SearchType = {
31
+ limit?: number;
32
+ skip?: number;
39
33
  orderBy?: string;
40
- order?: "ASC" | "DESC";
34
+ order?: 'ASC' | 'DESC';
41
35
  searchTerm?: string;
42
- [key: string]: any;
36
+ active?: boolean;
37
+ filters?: string;
43
38
  };
44
39
  export type KeyValueType = {
45
40
  [key: string]: any;
@@ -32,4 +32,5 @@ export declare class Http {
32
32
  static FormUpload(url: string, file: File, isHeadersAddMultiForm?: boolean, data?: Record<string, any>, headers?: any, method?: 'POST' | 'PUT', type?: RespType): Promise<any>;
33
33
  static CloudUpload(fullUrl: string, file: File, headers?: any, method?: 'POST' | 'PUT'): Promise<Response>;
34
34
  static FileDownload(fullUrl: string, params: any, headers?: any, method?: string): Promise<Blob>;
35
+ static ErrorWrapper(errorData: any): any;
35
36
  }
package/dist/main/http.js CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Http = exports.HttpMethods = exports.BaseHeaders = exports.HttpHeaders = exports.RespType = void 0;
13
13
  const util_1 = require("./util");
14
+ const const_keys_1 = require("./const-keys");
14
15
  var RespType;
15
16
  (function (RespType) {
16
17
  RespType["JSON"] = "json";
@@ -76,7 +77,7 @@ class Http {
76
77
  return yield Http.RespData(response, type);
77
78
  }
78
79
  catch (error) {
79
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
80
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
80
81
  }
81
82
  });
82
83
  }
@@ -91,7 +92,7 @@ class Http {
91
92
  return yield Http.RespData(response, type);
92
93
  }
93
94
  catch (error) {
94
- throw { url: url, requestId: headers['request-id'], body: data, error: error };
95
+ throw { url: url, requestId: headers['request-id'], body: data, error: Http.ErrorWrapper(error) };
95
96
  }
96
97
  });
97
98
  }
@@ -106,7 +107,7 @@ class Http {
106
107
  return yield Http.RespData(response, type);
107
108
  }
108
109
  catch (error) {
109
- throw { url: url, requestId: headers['request-id'], body: data, error: error };
110
+ throw { url: url, requestId: headers['request-id'], body: data, error: Http.ErrorWrapper(error) };
110
111
  }
111
112
  });
112
113
  }
@@ -122,7 +123,7 @@ class Http {
122
123
  return yield Http.RespData(response, type);
123
124
  }
124
125
  catch (error) {
125
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
126
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
126
127
  }
127
128
  });
128
129
  }
@@ -139,7 +140,7 @@ class Http {
139
140
  return yield Http.RespData(response, type);
140
141
  }
141
142
  catch (error) {
142
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
143
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
143
144
  }
144
145
  });
145
146
  }
@@ -167,7 +168,7 @@ class Http {
167
168
  return yield Http.RespData(response, type);
168
169
  }
169
170
  catch (error) {
170
- throw { url: url, requestId: headers['request-id'], error: error };
171
+ throw { url: url, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
171
172
  }
172
173
  });
173
174
  }
@@ -187,7 +188,7 @@ class Http {
187
188
  return response;
188
189
  }
189
190
  catch (error) {
190
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
191
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
191
192
  }
192
193
  });
193
194
  }
@@ -203,10 +204,13 @@ class Http {
203
204
  return blob;
204
205
  }
205
206
  catch (error) {
206
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
207
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
207
208
  }
208
209
  });
209
210
  }
211
+ static ErrorWrapper(errorData) {
212
+ return Object.assign(Object.assign({}, errorData), { message: errorData.internal_message || errorData.message || const_keys_1.ConstKeys.INVALID_DATA, main_message: errorData.message || const_keys_1.ConstKeys.INVALID_DATA });
213
+ }
210
214
  }
211
215
  exports.Http = Http;
212
216
  Http.API_BASE_URL = "";
@@ -0,0 +1,6 @@
1
+ export type QueryCondItem = {
2
+ key: string;
3
+ opt: '=' | '!=' | '>' | '<' | '>=' | '<=' | 'in' | 'not in' | 'notin' | 'between' | 'isnull' | 'isnotnull' | 'is null' | 'is not null' | 'like' | 'ilike' | 'contains' | 'startswith' | 'endswith' | 'regex' | 'exists';
4
+ value: any;
5
+ };
6
+ export declare function QueryCond(input: string): QueryCondItem[];
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryCond = QueryCond;
4
+ function splitTopLevel(input, delimiter) {
5
+ const parts = [];
6
+ let buf = '';
7
+ let quote = null;
8
+ let escape = false;
9
+ let square = 0;
10
+ let curly = 0;
11
+ let paren = 0;
12
+ for (let i = 0; i < input.length; i++) {
13
+ const ch = input[i];
14
+ if (escape) {
15
+ buf += ch;
16
+ escape = false;
17
+ continue;
18
+ }
19
+ if (quote) {
20
+ if (ch === '\\') {
21
+ buf += ch;
22
+ escape = true;
23
+ continue;
24
+ }
25
+ buf += ch;
26
+ if (ch === quote)
27
+ quote = null;
28
+ continue;
29
+ }
30
+ if (ch === '"' || ch === "'") {
31
+ quote = ch;
32
+ buf += ch;
33
+ continue;
34
+ }
35
+ if (ch === '[')
36
+ square++;
37
+ if (ch === ']')
38
+ square = Math.max(0, square - 1);
39
+ if (ch === '{')
40
+ curly++;
41
+ if (ch === '}')
42
+ curly = Math.max(0, curly - 1);
43
+ if (ch === '(')
44
+ paren++;
45
+ if (ch === ')')
46
+ paren = Math.max(0, paren - 1);
47
+ if (ch === delimiter && square === 0 && curly === 0 && paren === 0) {
48
+ const seg = buf.trim();
49
+ if (seg)
50
+ parts.push(seg);
51
+ buf = '';
52
+ continue;
53
+ }
54
+ buf += ch;
55
+ }
56
+ const last = buf.trim();
57
+ if (last)
58
+ parts.push(last);
59
+ return parts;
60
+ }
61
+ function parseMaybeJson(raw) {
62
+ const s = raw.trim();
63
+ if (!s)
64
+ return '';
65
+ if (s === 'null')
66
+ return null;
67
+ if (s === 'true')
68
+ return true;
69
+ if (s === 'false')
70
+ return false;
71
+ if (/^-?\d+(\.\d+)?$/.test(s))
72
+ return Number(s);
73
+ const first = s[0];
74
+ const last = s[s.length - 1];
75
+ if ((first === '"' && last === '"') || (first === "'" && last === "'")) {
76
+ if (first === '"') {
77
+ try {
78
+ return JSON.parse(s);
79
+ }
80
+ catch (_a) {
81
+ return s.slice(1, -1);
82
+ }
83
+ }
84
+ const inner = s.slice(1, -1);
85
+ return inner.replace(/\\'/g, "'").replace(/\\\\/g, '\\');
86
+ }
87
+ if ((first === '[' && last === ']') || (first === '{' && last === '}')) {
88
+ try {
89
+ return JSON.parse(s);
90
+ }
91
+ catch (_b) {
92
+ if (s.includes("'") && !s.includes('"')) {
93
+ try {
94
+ return JSON.parse(s.replace(/'/g, '"'));
95
+ }
96
+ catch (_c) {
97
+ return s;
98
+ }
99
+ }
100
+ return s;
101
+ }
102
+ }
103
+ return s;
104
+ }
105
+ function findTopLevelOpIndex(expr, ops) {
106
+ let quote = null;
107
+ let escape = false;
108
+ let square = 0;
109
+ let curly = 0;
110
+ let paren = 0;
111
+ for (let i = 0; i < expr.length; i++) {
112
+ const ch = expr[i];
113
+ if (escape) {
114
+ escape = false;
115
+ continue;
116
+ }
117
+ if (quote) {
118
+ if (ch === '\\') {
119
+ escape = true;
120
+ continue;
121
+ }
122
+ if (ch === quote)
123
+ quote = null;
124
+ continue;
125
+ }
126
+ if (ch === '"' || ch === "'") {
127
+ quote = ch;
128
+ continue;
129
+ }
130
+ if (ch === '[')
131
+ square++;
132
+ else if (ch === ']')
133
+ square = Math.max(0, square - 1);
134
+ else if (ch === '{')
135
+ curly++;
136
+ else if (ch === '}')
137
+ curly = Math.max(0, curly - 1);
138
+ else if (ch === '(')
139
+ paren++;
140
+ else if (ch === ')')
141
+ paren = Math.max(0, paren - 1);
142
+ if (square !== 0 || curly !== 0 || paren !== 0)
143
+ continue;
144
+ for (const op of ops) {
145
+ if (expr.startsWith(op, i)) {
146
+ return { op, idx: i };
147
+ }
148
+ }
149
+ }
150
+ return null;
151
+ }
152
+ function findTopLevelTokenIndex(expr, token) {
153
+ let quote = null;
154
+ let escape = false;
155
+ let square = 0;
156
+ let curly = 0;
157
+ let paren = 0;
158
+ for (let i = 0; i < expr.length; i++) {
159
+ const ch = expr[i];
160
+ if (escape) {
161
+ escape = false;
162
+ continue;
163
+ }
164
+ if (quote) {
165
+ if (ch === '\\') {
166
+ escape = true;
167
+ continue;
168
+ }
169
+ if (ch === quote)
170
+ quote = null;
171
+ continue;
172
+ }
173
+ if (ch === '"' || ch === "'") {
174
+ quote = ch;
175
+ continue;
176
+ }
177
+ if (ch === '[')
178
+ square++;
179
+ else if (ch === ']')
180
+ square = Math.max(0, square - 1);
181
+ else if (ch === '{')
182
+ curly++;
183
+ else if (ch === '}')
184
+ curly = Math.max(0, curly - 1);
185
+ else if (ch === '(')
186
+ paren++;
187
+ else if (ch === ')')
188
+ paren = Math.max(0, paren - 1);
189
+ if (square !== 0 || curly !== 0 || paren !== 0)
190
+ continue;
191
+ if (expr.startsWith(token, i))
192
+ return i;
193
+ }
194
+ return -1;
195
+ }
196
+ function parseBetweenValue(raw) {
197
+ const s = raw.trim();
198
+ if (!s)
199
+ return [];
200
+ if (s.startsWith('[') && s.endsWith(']')) {
201
+ const parsed = parseMaybeJson(s);
202
+ if (Array.isArray(parsed))
203
+ return parsed.slice(0, 2);
204
+ }
205
+ const idx = findTopLevelTokenIndex(s, '..');
206
+ if (idx >= 0) {
207
+ const left = s.slice(0, idx).trim();
208
+ const right = s.slice(idx + 2).trim();
209
+ return [parseMaybeJson(left), parseMaybeJson(right)];
210
+ }
211
+ return [parseMaybeJson(s)];
212
+ }
213
+ function normalizeOpt(opt) {
214
+ const o = opt.trim().toLowerCase();
215
+ if (o === '==')
216
+ return '=';
217
+ if (o === 'notin')
218
+ return 'not in';
219
+ if (o === 'is null')
220
+ return 'is null';
221
+ if (o === 'is not null')
222
+ return 'is not null';
223
+ if (o === 'isnull')
224
+ return 'is null';
225
+ if (o === 'isnotnull')
226
+ return 'is not null';
227
+ if (o === 'in')
228
+ return 'in';
229
+ if (o === 'not in')
230
+ return 'not in';
231
+ if (o === 'notin')
232
+ return 'not in';
233
+ if (o === 'between')
234
+ return 'between';
235
+ if (o === 'like')
236
+ return 'like';
237
+ if (o === 'ilike')
238
+ return 'ilike';
239
+ if (o === 'contains')
240
+ return 'contains';
241
+ if (o === 'startswith')
242
+ return 'startswith';
243
+ if (o === 'endswith')
244
+ return 'endswith';
245
+ if (o === 'regex')
246
+ return 'regex';
247
+ if (o === 'exists')
248
+ return 'exists';
249
+ if (opt === '>=')
250
+ return '>=';
251
+ if (opt === '<=')
252
+ return '<=';
253
+ if (opt === '!=')
254
+ return '!=';
255
+ if (opt === '>')
256
+ return '>';
257
+ if (opt === '<')
258
+ return '<';
259
+ return '=';
260
+ }
261
+ function parseOneCond(segment) {
262
+ const s = segment.trim();
263
+ if (!s)
264
+ return null;
265
+ const unaryMatch = s.match(/^(.+?)\s+(isnull|isnotnull|is\s+null|is\s+not\s+null)\s*$/i);
266
+ if (unaryMatch) {
267
+ const key = unaryMatch[1].trim();
268
+ const opt = normalizeOpt(unaryMatch[2]);
269
+ return { key, opt, value: null };
270
+ }
271
+ const keywordMatch = s.match(/^(.+?)\s+(not\s+in|notin|in|between|ilike|like|contains|startswith|endswith|regex)\s+([\s\S]+)$/i);
272
+ if (keywordMatch) {
273
+ const key = keywordMatch[1].trim();
274
+ const opt = normalizeOpt(keywordMatch[2]);
275
+ const rawVal = keywordMatch[3].trim();
276
+ const value = opt === 'between' ? parseBetweenValue(rawVal) : parseMaybeJson(rawVal);
277
+ return { key, opt, value };
278
+ }
279
+ const opInfo = findTopLevelOpIndex(s, ['>=', '<=', '!=', '==', '>', '<', '=']);
280
+ if (opInfo) {
281
+ const key = s.slice(0, opInfo.idx).trim();
282
+ const rhs = s.slice(opInfo.idx + opInfo.op.length).trim();
283
+ let opt = normalizeOpt(opInfo.op);
284
+ let value = rhs ? parseMaybeJson(rhs) : null;
285
+ if (opt === '=' && Array.isArray(value))
286
+ opt = 'in';
287
+ if (opt === '!=' && Array.isArray(value))
288
+ opt = 'not in';
289
+ if (opt === '=' && value === null)
290
+ opt = 'is null';
291
+ if (opt === '!=' && value === null)
292
+ opt = 'is not null';
293
+ return { key, opt, value };
294
+ }
295
+ if (/^!\s*\w/.test(s)) {
296
+ const key = s.replace(/^!\s*/, '').trim();
297
+ return { key, opt: 'exists', value: false };
298
+ }
299
+ return { key: s, opt: 'exists', value: true };
300
+ }
301
+ function QueryCond(input) {
302
+ if (!input)
303
+ return [];
304
+ const segments = splitTopLevel(input, ',');
305
+ return segments.map(parseOneCond).filter((x) => Boolean(x));
306
+ }
@@ -1,4 +1,4 @@
1
- import { LangCountryType } from "./const-type";
1
+ import { LangCountryType } from './const-type';
2
2
  export declare const AppRandomString: (length: number, charset: string) => string;
3
3
  export declare const AppUniqueCode: () => string;
4
4
  export declare const AppCodeByType: (name: string, type?: null) => string;
@@ -20,3 +20,4 @@ export declare function EncodeURL(input: string): string;
20
20
  export declare function DecodeURL(input: string): string;
21
21
  export declare function SafeEncode(input: string): string;
22
22
  export declare function SafeDecode(encoded: string): string;
23
+ export { QueryCond, type QueryCondItem } from './query-cond';
package/dist/main/util.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CurrencyConvert = exports.LangCountryCode = exports.LangText = exports.TimeAgo = exports.DateAndTime = exports.DateTime12HrFormat = exports.DateTime24HrFormat = exports.TruncateText = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
12
+ exports.QueryCond = exports.CurrencyConvert = exports.LangCountryCode = exports.LangText = exports.TimeAgo = exports.DateAndTime = exports.DateTime12HrFormat = exports.DateTime24HrFormat = exports.TruncateText = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
13
13
  exports.EncodeBase64 = EncodeBase64;
14
14
  exports.DecodeBase64 = DecodeBase64;
15
15
  exports.EncodeURL = EncodeURL;
@@ -17,10 +17,10 @@ exports.DecodeURL = DecodeURL;
17
17
  exports.SafeEncode = SafeEncode;
18
18
  exports.SafeDecode = SafeDecode;
19
19
  const randomstring_1 = require("randomstring");
20
- const reg_exr_1 = require("./reg-exr");
20
+ const const_value_1 = require("./const-value");
21
21
  const countries_1 = require("./countries");
22
22
  const languages_1 = require("./languages");
23
- const const_value_1 = require("./const-value");
23
+ const reg_exr_1 = require("./reg-exr");
24
24
  const AppRandomString = (length, charset) => {
25
25
  return (0, randomstring_1.generate)({ length: length, charset: charset });
26
26
  };
@@ -37,15 +37,15 @@ const AppUniqueCode = () => {
37
37
  };
38
38
  exports.AppUniqueCode = AppUniqueCode;
39
39
  const AppCodeByType = (name, type = null) => {
40
- let str = "";
40
+ let str = '';
41
41
  if (type) {
42
- str = type + "_" + name;
42
+ str = type + '_' + name;
43
43
  }
44
44
  else {
45
- str = name + "_" + (0, exports.AppUniqueCode)();
45
+ str = name + '_' + (0, exports.AppUniqueCode)();
46
46
  }
47
- str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, "_");
48
- str = str.replace(/\s/g, "_");
47
+ str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, '_');
48
+ str = str.replace(/\s/g, '_');
49
49
  str = str.substr(0, 128);
50
50
  return str.toUpperCase();
51
51
  };
@@ -53,10 +53,10 @@ exports.AppCodeByType = AppCodeByType;
53
53
  const AppCode = (name) => {
54
54
  if (name == null)
55
55
  return null;
56
- let str = "";
56
+ let str = '';
57
57
  str = name.trim();
58
- str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, "_");
59
- str = str.replace(/\s/g, "_");
58
+ str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, '_');
59
+ str = str.replace(/\s/g, '_');
60
60
  return str.toUpperCase();
61
61
  };
62
62
  exports.AppCode = AppCode;
@@ -85,54 +85,54 @@ const AppAddDays = (date, addDays, isDays = true) => {
85
85
  };
86
86
  exports.AppAddDays = AppAddDays;
87
87
  const AppUUID4 = () => {
88
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
88
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
89
89
  const r = (Math.random() * 16) | 0;
90
- const v = c == "x" ? r : (r & 0x3) | 0x8;
90
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
91
91
  return v.toString(16);
92
92
  });
93
93
  };
94
94
  exports.AppUUID4 = AppUUID4;
95
95
  const TruncateText = (input, maxLength) => {
96
96
  if ((input === null || input === void 0 ? void 0 : input.length) > maxLength) {
97
- return input.substring(0, maxLength) + "...";
97
+ return input.substring(0, maxLength) + '...';
98
98
  }
99
99
  return input;
100
100
  };
101
101
  exports.TruncateText = TruncateText;
102
102
  const DateTime24HrFormat = (time) => {
103
- const [timeStr, modifier] = time.split(" ");
104
- let [hours, minutes] = timeStr.split(":").map(Number);
105
- if (modifier === "AM") {
103
+ const [timeStr, modifier] = time.split(' ');
104
+ let [hours, minutes] = timeStr.split(':').map(Number);
105
+ if (modifier === 'AM') {
106
106
  if (hours === 12)
107
107
  hours = 0;
108
108
  }
109
- else if (modifier === "PM") {
109
+ else if (modifier === 'PM') {
110
110
  if (hours !== 12)
111
111
  hours += 12;
112
112
  }
113
- return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:00`;
113
+ return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:00`;
114
114
  };
115
115
  exports.DateTime24HrFormat = DateTime24HrFormat;
116
116
  const DateTime12HrFormat = (timestamp, showDate = true, showTime) => {
117
117
  const newDate = new Date(timestamp);
118
118
  const months = const_value_1.ConstValue.MonthNames;
119
- const day = String(newDate.getDate()).padStart(2, "0");
119
+ const day = String(newDate.getDate()).padStart(2, '0');
120
120
  const month = months[newDate.getMonth()];
121
121
  const year = newDate.getFullYear();
122
122
  let hours = newDate.getHours();
123
- const minutes = String(newDate.getMinutes()).padStart(2, "0");
124
- const ampm = hours >= 12 ? "PM" : "AM";
123
+ const minutes = String(newDate.getMinutes()).padStart(2, '0');
124
+ const ampm = hours >= 12 ? 'PM' : 'AM';
125
125
  hours = hours % 12;
126
126
  hours = hours ? hours : 12;
127
- const date = showDate ? `${day} ${month} ${year}` : "";
128
- const time = showTime ? `${hours}:${minutes} ${ampm}` : "";
127
+ const date = showDate ? `${day} ${month} ${year}` : '';
128
+ const time = showTime ? `${hours}:${minutes} ${ampm}` : '';
129
129
  return `${date} ${time}`;
130
130
  };
131
131
  exports.DateTime12HrFormat = DateTime12HrFormat;
132
132
  const DateAndTime = (dateString, timeString) => {
133
133
  if (!dateString)
134
134
  return null;
135
- const validTimeString = timeString || "00:00:00";
135
+ const validTimeString = timeString || '00:00:00';
136
136
  const combined = new Date(`${dateString}T${validTimeString}Z`);
137
137
  return isNaN(combined.getTime()) ? null : combined;
138
138
  };
@@ -146,31 +146,31 @@ const TimeAgo = (date) => {
146
146
  if (days > 1)
147
147
  return `${days} days ago`;
148
148
  if (days === 1)
149
- return "1 day ago";
149
+ return '1 day ago';
150
150
  if (hours > 1)
151
151
  return `${hours} hours ago`;
152
152
  if (hours === 1)
153
- return "1 hour ago";
153
+ return '1 hour ago';
154
154
  if (minutes > 1)
155
155
  return `${minutes} minutes ago`;
156
156
  if (minutes === 1)
157
- return "1 minute ago";
158
- return "Just now";
157
+ return '1 minute ago';
158
+ return 'Just now';
159
159
  };
160
160
  exports.TimeAgo = TimeAgo;
161
161
  const LangText = (data, source, target) => __awaiter(void 0, void 0, void 0, function* () {
162
162
  if (!data || !source || !target) {
163
- throw new Error("Invalid input: data, source, or target is missing");
163
+ throw new Error('Invalid input: data, source, or target is missing');
164
164
  }
165
- const src = source.split("-")[0]; // e.g., "en-US" -> "en"
166
- const tgt = target.split("-")[0]; // e.g., "te-IN" -> "te"
165
+ const src = source.split('-')[0]; // e.g., "en-US" -> "en"
166
+ const tgt = target.split('-')[0]; // e.g., "te-IN" -> "te"
167
167
  if (!/^[a-zA-Z]{2}$/.test(src) || !/^[a-zA-Z]{2}$/.test(tgt)) {
168
- throw new Error("Invalid language code format");
168
+ throw new Error('Invalid language code format');
169
169
  }
170
170
  const encodedData = encodeURIComponent(data);
171
171
  const url = `https://lingva.ml/api/v1/${src}/${tgt}/${encodedData}`;
172
172
  const res = yield fetch(url, {
173
- method: "GET",
173
+ method: 'GET',
174
174
  });
175
175
  if (!res.ok) {
176
176
  throw new Error(`Translation failed: ${res.status} ${res.statusText}`);
@@ -179,11 +179,11 @@ const LangText = (data, source, target) => __awaiter(void 0, void 0, void 0, fun
179
179
  if (json.error) {
180
180
  throw new Error(`API error: ${json.error}`);
181
181
  }
182
- return json.translation || "";
182
+ return json.translation || '';
183
183
  });
184
184
  exports.LangText = LangText;
185
185
  const LangCountryCode = (lang) => {
186
- const countryCode = lang.split("-")[1];
186
+ const countryCode = lang.split('-')[1];
187
187
  const country = countries_1.countries.find((c) => c.code === countryCode) || {};
188
188
  const language = languages_1.languages.find((l) => l.lang === lang) || {};
189
189
  return {
@@ -201,7 +201,7 @@ const LangCountryCode = (lang) => {
201
201
  exports.LangCountryCode = LangCountryCode;
202
202
  const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function* () {
203
203
  if (!from || !to) {
204
- throw new Error("Invalid input: from or to is missing");
204
+ throw new Error('Invalid input: from or to is missing');
205
205
  }
206
206
  if (from === to) {
207
207
  return 1;
@@ -209,7 +209,7 @@ const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function
209
209
  try {
210
210
  const url = `https://api.frankfurter.app/latest?from=${from}&to=${to}`;
211
211
  const res = yield fetch(url, {
212
- method: "GET",
212
+ method: 'GET',
213
213
  });
214
214
  if (!res.ok) {
215
215
  throw new Error(`Currency conversion failed: ${res.status} ${res.statusText}`);
@@ -251,3 +251,5 @@ function SafeEncode(input) {
251
251
  function SafeDecode(encoded) {
252
252
  return DecodeBase64(DecodeURL(encoded));
253
253
  }
254
+ var query_cond_1 = require("./query-cond");
255
+ Object.defineProperty(exports, "QueryCond", { enumerable: true, get: function () { return query_cond_1.QueryCond; } });
@@ -11,16 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  const index_1 = require("../index");
14
- const url = '/auth/partner/signin';
15
- const reqBody = { language: 'en-US', mobile: '111111111', provider: 'mobile', telCode: '+91' };
16
- const runHttpExample = () => __awaiter(void 0, void 0, void 0, function* () {
14
+ index_1.Http.API_BASE_URL = 'http://localhost:4000';
15
+ const signinRun = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const payload = {
17
+ userid: 'aaa@anymail.com',
18
+ password: '11111',
19
+ type: 'admin',
20
+ provider: 'email',
21
+ };
17
22
  try {
18
- const res = yield index_1.Http.Post(url, reqBody, null);
23
+ const res = yield index_1.Http.Post("/auth/signin", payload, {});
19
24
  console.log(res);
20
- return res;
21
25
  }
22
- catch (error) {
23
- console.log(error);
26
+ catch (e) {
27
+ console.error(e);
24
28
  }
25
29
  });
26
- runHttpExample();
30
+ signinRun();
@@ -11,23 +11,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  const util_1 = require("../main/util");
14
- const CallLangCountry = () => {
15
- const lang = "en-US";
16
- const country = (0, util_1.LangCountryCode)(lang);
17
- console.log("LangCountryCode:: ", country);
18
- };
19
- const CallLangText = () => __awaiter(void 0, void 0, void 0, function* () {
20
- const resp = yield (0, util_2.LangText)("Hello, how are you?", "en-US", "hi-IN");
21
- console.log("Resp Kannada:: ", resp);
22
- });
23
- const CallCurrencyConvert = () => __awaiter(void 0, void 0, void 0, function* () {
24
- const resp = yield (0, util_1.CurrencyConvert)("USD", "INR");
25
- console.log("Resp Currency:: ", resp);
26
- });
27
- const util_2 = require("../main/util");
28
14
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
29
- // await CallLangCountry();
30
- // await CallLangText();
31
- yield CallCurrencyConvert();
15
+ const input = [
16
+ 'isApproved=true',
17
+ 'status!=false',
18
+ 'age>18',
19
+ 'score<100',
20
+ 'height>=170',
21
+ 'weight<=80',
22
+ 'type=["accept","inprogress"]',
23
+ 'type!=["accept","inprogress"]',
24
+ 'role in ["admin","editor"]',
25
+ 'role not in ["admin","editor"]',
26
+ 'role notin ["admin","editor"]',
27
+ 'deletedAt is null',
28
+ 'deletedAt is not null',
29
+ 'deletedAt isnull',
30
+ 'updatedAt isnotnull',
31
+ 'deletedAt=null',
32
+ 'deletedAt!=null',
33
+ 'age between [18,30]',
34
+ 'createdAt between 2020-01-01..2020-01-31',
35
+ 'name like "Jo%"',
36
+ 'email ilike "%@gmail.com"',
37
+ 'title contains "hello"',
38
+ 'code startswith "AB"',
39
+ 'code endswith "99"',
40
+ 'path regex "^/api/.*$"',
41
+ 'archivedAt',
42
+ '!archivedAt',
43
+ 'name="a,b"',
44
+ 'meta={"a":1,"b":true}',
45
+ 'tags=["x,y","z"]',
46
+ ].join(',');
47
+ const got = (0, util_1.QueryCond)(input);
48
+ console.log('QueryCond input:', input);
49
+ console.log('QueryCond output:', JSON.stringify(got, null, 2));
32
50
  });
33
51
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -28,4 +28,4 @@
28
28
  "jwt-encode": "^1.0.1",
29
29
  "randomstring": "1.3.0"
30
30
  }
31
- }
31
+ }