baja-lite 1.3.27 → 1.3.29

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.
Files changed (74) hide show
  1. package/boot-remote.d.ts +2 -0
  2. package/{src/boot-remote.ts → boot-remote.js} +6 -7
  3. package/boot.d.ts +2 -0
  4. package/{src/boot.ts → boot.js} +31 -38
  5. package/code.d.ts +2 -0
  6. package/{src/code.ts → code.js} +71 -66
  7. package/convert-xml.d.ts +10 -0
  8. package/{src/convert-xml.ts → convert-xml.js} +105 -155
  9. package/enum.d.ts +2 -0
  10. package/enum.js +31 -0
  11. package/error.d.ts +5 -0
  12. package/error.js +13 -0
  13. package/fn.d.ts +128 -0
  14. package/fn.js +172 -0
  15. package/{src/index.ts → index.d.ts} +11 -12
  16. package/index.js +11 -0
  17. package/list.d.ts +10 -0
  18. package/{src/list.ts → list.js} +8 -9
  19. package/math.d.ts +83 -0
  20. package/math.js +451 -0
  21. package/object.d.ts +83 -0
  22. package/object.js +221 -0
  23. package/package.json +2 -2
  24. package/snowflake.d.ts +12 -0
  25. package/{src/snowflake.ts → snowflake.js} +33 -52
  26. package/sql.d.ts +1797 -0
  27. package/sql.js +4802 -0
  28. package/sqlite.d.ts +32 -0
  29. package/{src/sqlite.ts → sqlite.js} +53 -52
  30. package/string.d.ts +17 -0
  31. package/string.js +105 -0
  32. package/test-mysql.d.ts +2 -0
  33. package/test-mysql.js +109 -0
  34. package/test-postgresql.d.ts +2 -0
  35. package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
  36. package/test-sqlite.d.ts +1 -0
  37. package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
  38. package/test-xml.d.ts +1 -0
  39. package/{src/test-xml.ts → test-xml.js} +1 -1
  40. package/test.d.ts +1 -0
  41. package/{src/test.ts → test.js} +2 -3
  42. package/wx/base.d.ts +11 -0
  43. package/wx/base.js +78 -0
  44. package/wx/mini.d.ts +52 -0
  45. package/wx/mini.js +112 -0
  46. package/wx/organ.d.ts +65 -0
  47. package/wx/organ.js +171 -0
  48. package/{src/wx/types.ts → wx/types.d.ts} +21 -10
  49. package/wx/types.js +1 -0
  50. package/wx.js +3 -0
  51. package/.eslintignore +0 -7
  52. package/.eslintrc.cjs +0 -89
  53. package/.prettierrc +0 -4
  54. package/.vscode/settings.json +0 -8
  55. package/ci.js +0 -29
  56. package/package-cjs.json +0 -17
  57. package/src/enum.ts +0 -71
  58. package/src/error.ts +0 -11
  59. package/src/fn.ts +0 -295
  60. package/src/math.ts +0 -405
  61. package/src/object.ts +0 -247
  62. package/src/sql.ts +0 -5023
  63. package/src/string.ts +0 -111
  64. package/src/test-mysql.ts +0 -144
  65. package/src/wx/base.ts +0 -76
  66. package/src/wx/mini.ts +0 -147
  67. package/src/wx/organ.ts +0 -290
  68. package/tsconfig.cjs.json +0 -42
  69. package/tsconfig.json +0 -44
  70. package/tsconfig.tsbuildinfo +0 -1
  71. package/xml/event-report.xml +0 -13
  72. package/yarn.lock +0 -1757
  73. /package/{Readme.md → README.md} +0 -0
  74. /package/{src/wx.ts → wx.d.ts} +0 -0
@@ -1,39 +1,30 @@
1
1
  import LGet from 'lodash.get';
2
- export interface XML {
3
- type: 'tag' | 'text';
4
- name: string;
5
- id?: string;
6
- voidElement: boolean;
7
- attrs: Record<string, string>;
8
- children: XML[];
9
- content: string;
10
- }
11
- export const convert = function (childrens: XML[], param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
2
+ export const convert = function (childrens, param, parentIds, myBatisMapper) {
12
3
  let statement = '';
13
- for (let i = 0, children: XML; children = childrens[i]!; i++) {
4
+ for (let i = 0, children; children = childrens[i]; i++) {
14
5
  // Convert SQL statement recursively
15
6
  statement += convertChildren(children, param, parentIds, myBatisMapper);
16
7
  }
17
8
  // Check not converted Parameters
18
9
  const regexList = ['\\#{\\S*}', '\\${\\S*}'];
19
- for (let i = 0, regexString: string; regexString = regexList[i]!; i++) {
10
+ for (let i = 0, regexString; regexString = regexList[i]; i++) {
20
11
  var checkParam = statement.match(regexString);
21
12
  if (checkParam != null && checkParam.length > 0) {
22
13
  throw new Error("Parameter " + checkParam.join(",") + " is not converted.");
23
14
  }
24
15
  }
25
16
  return statement;
26
- }
27
- const convertChildren = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
28
- param ??= {};
17
+ };
18
+ const convertChildren = function (children, param, parentIds, myBatisMapper) {
19
+ param ?? (param = {});
29
20
  if (!isDict(param)) {
30
21
  throw new Error('Parameter argument should be Key-Value type or Null.');
31
22
  }
32
23
  if (children.type == 'text') {
33
24
  // Convert Parameters
34
25
  return convertParameters(children, param);
35
-
36
- } else if (children.type == 'tag') {
26
+ }
27
+ else if (children.type == 'tag') {
37
28
  switch (children.name.toLowerCase()) {
38
29
  case 'if':
39
30
  return convertIf(children, param, parentIds, myBatisMapper);
@@ -54,74 +45,69 @@ const convertChildren = function (children: XML, param: Record<string, any>, par
54
45
  default:
55
46
  throw new Error('XML is not well-formed character or markup. Consider using CDATA section.');
56
47
  }
57
- } else {
48
+ }
49
+ else {
58
50
  return '';
59
51
  }
60
- }
61
-
62
- const convertParameters = function (children: XML, param: Record<string, any>) {
52
+ };
53
+ const convertParameters = function (children, param) {
63
54
  let convertString = children.content;
64
-
65
55
  try {
66
56
  convertString = convertParametersInner('#', convertString, param);
67
57
  convertString = convertParametersInner('$', convertString, param);
68
- } catch (err) {
58
+ }
59
+ catch (err) {
69
60
  throw new Error('Error occurred during convert parameters.');
70
61
  }
71
-
72
62
  try {
73
63
  // convert CDATA string
74
64
  convertString = convertString.replace(/(\&amp\;)/g, '&');
75
65
  convertString = convertString.replace(/(\&lt\;)/g, '<');
76
66
  convertString = convertString.replace(/(\&gt\;)/g, '>');
77
67
  convertString = convertString.replace(/(\&quot\;)/g, '"');
78
- } catch (err) {
68
+ }
69
+ catch (err) {
79
70
  throw new Error('Error occurred during convert CDATA section.');
80
71
  }
81
-
82
72
  return convertString;
83
- }
84
-
85
- const isObject = function (variable: any) {
73
+ };
74
+ const isObject = function (variable) {
86
75
  return typeof variable === 'object' && variable !== null;
87
- }
88
-
89
- const isArray = function (variable: any) {
76
+ };
77
+ const isArray = function (variable) {
90
78
  return isObject(variable) && variable.hasOwnProperty('length');
91
- }
92
-
93
- const convertParametersInner = function (change: string, convertString: string, param: Record<string, any>) {
79
+ };
80
+ const convertParametersInner = function (change, convertString, param) {
94
81
  const stringReg = new RegExp('(\\' + change + '\\{[a-zA-Z0-9._\\$]+\\})', 'g');
95
82
  let stringTarget = convertString.match(stringReg);
96
-
97
83
  if (stringTarget != null && stringTarget.length > 0) {
98
84
  const _stringTarget = uniqueArray(stringTarget);
99
-
100
- let target: string | undefined;
85
+ let target;
101
86
  for (let i = 0; i < _stringTarget.length; i++) {
102
87
  target = _stringTarget[i];
103
- const t = target!.replace(change + '{', '').replace('}', '');
88
+ const t = target.replace(change + '{', '').replace('}', '');
104
89
  let tempParamKey = LGet(param, t);
105
90
  if (tempParamKey !== undefined) {
106
91
  const reg = new RegExp('\\' + change + '{' + t + '}', 'g');
107
-
108
92
  if (tempParamKey === null) {
109
93
  tempParamKey = 'NULL';
110
94
  convertString = convertString.replace(reg, tempParamKey);
111
- } else {
95
+ }
96
+ else {
112
97
  if (change == '#') {
113
98
  // processing JSON fields structures
114
99
  if (isObject(tempParamKey) || isArray(tempParamKey)) {
115
100
  tempParamKey = JSON.stringify(tempParamKey);
116
- } else {
101
+ }
102
+ else {
117
103
  tempParamKey = tempParamKey.toString().replace(/"/g, '\\\"');
118
104
  tempParamKey = mysqlRealEscapeParam(tempParamKey);
119
105
  }
120
-
121
106
  tempParamKey = tempParamKey.replace(/'/g, "''");
122
- const replaceWith = "'" + tempParamKey + "'"
107
+ const replaceWith = "'" + tempParamKey + "'";
123
108
  convertString = convertString.replace(reg, () => replaceWith);
124
- } else if (change == '$') {
109
+ }
110
+ else if (change == '$') {
125
111
  convertString = convertString.replace(reg, tempParamKey);
126
112
  }
127
113
  }
@@ -129,134 +115,122 @@ const convertParametersInner = function (change: string, convertString: string,
129
115
  }
130
116
  }
131
117
  return convertString;
132
- }
133
-
134
- const convertIf = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
135
- let evalString = children.attrs['test']!;
118
+ };
119
+ const convertIf = function (children, param, parentIds, myBatisMapper) {
120
+ let evalString = children.attrs['test'];
136
121
  try {
137
122
  // Create Evaluate string
138
123
  evalString = replaceEvalString(evalString, param);
139
-
140
124
  evalString = evalString.replace(/ and /gi, ' && ');
141
125
  evalString = evalString.replace(/ or /gi, ' || ');
142
-
143
126
  // replace == to === for strict evaluate
144
127
  // TODO: fix != null & != ''
145
128
  // evalString = evalString.replace(/==/g, '===');
146
129
  // evalString = evalString.replace(/!=/g, '!==');
147
-
148
130
  evalString = evalString.replace(/^'(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
149
131
  evalString = evalString.replace(/\('(.*?)'\.equalsIgnoreCase\( ([a-zA-Z]+\.[a-zA-Z]+) \)/i, `(($2 && $2.toUpperCase() === '$1'.toUpperCase())`);
150
-
151
- } catch (err) {
132
+ }
133
+ catch (err) {
152
134
  throw new Error('Error occurred during convert <if> element.');
153
135
  }
154
-
155
136
  // Execute Evaluate string
156
137
  try {
157
138
  if (eval(evalString)) {
158
139
  let convertString = '';
159
- for (let i = 0, nextChildren: XML; nextChildren = children['children'][i]!; i++) {
140
+ for (let i = 0, nextChildren; nextChildren = children['children'][i]; i++) {
160
141
  convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
161
142
  }
162
143
  return convertString;
163
-
164
- } else {
144
+ }
145
+ else {
165
146
  return '';
166
147
  }
167
- } catch (e) {
148
+ }
149
+ catch (e) {
168
150
  return '';
169
151
  }
170
- }
171
-
172
- const convertForeach = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
152
+ };
153
+ const convertForeach = function (children, param, parentIds, myBatisMapper) {
173
154
  try {
174
155
  const collection = eval('param.' + children.attrs['collection']);
175
- const item = children.attrs['item']!;
156
+ const item = children.attrs['item'];
176
157
  const open = (children.attrs['open'] == null) ? '' : children.attrs['open'];
177
158
  const close = (children.attrs['close'] == null) ? '' : children.attrs['close'];
178
159
  const separator = (children.attrs['separator'] == null) ? '' : children.attrs['separator'];
179
-
180
- const foreachTexts: string[] = [];
160
+ const foreachTexts = [];
181
161
  let coll = null;
182
162
  for (let j = 0; j < collection.length; j++) {
183
163
  coll = collection[j];
184
164
  const foreachParam = param;
185
165
  foreachParam[item] = coll;
186
-
187
166
  let foreachText = '';
188
- for (let k = 0, nextChildren: XML; nextChildren = children.children[k]!; k++) {
167
+ for (let k = 0, nextChildren; nextChildren = children.children[k]; k++) {
189
168
  let fText = convertChildren(nextChildren, foreachParam, parentIds, myBatisMapper);
190
169
  fText = fText.replace(/^\s*$/g, '');
191
170
  if (fText != null && fText.length > 0) {
192
171
  foreachText += fText;
193
172
  }
194
173
  }
195
-
196
174
  if (foreachText != null && foreachText.length > 0) {
197
175
  foreachTexts.push(foreachText);
198
176
  }
199
177
  }
200
-
201
178
  return (open + foreachTexts.join(separator) + close);
202
- } catch (err) {
179
+ }
180
+ catch (err) {
203
181
  throw new Error('Error occurred during convert <foreach> element.');
204
182
  }
205
- }
206
-
207
- const convertChoose = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
183
+ };
184
+ const convertChoose = function (children, param, parentIds, myBatisMapper) {
208
185
  try {
209
186
  for (let i = 0, whenChildren; whenChildren = children.children[i]; i++) {
210
187
  if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'when') {
211
188
  let evalString = whenChildren.attrs.test;
212
-
213
189
  // Create Evaluate string
214
190
  evalString = replaceEvalString(evalString, param);
215
-
216
191
  evalString = evalString.replace(/ and /gi, ' && ');
217
192
  evalString = evalString.replace(/ or /gi, ' || ');
218
-
219
193
  // Execute Evaluate string
220
194
  try {
221
195
  if (eval(evalString)) {
222
196
  // If <when> condition is true, do it.
223
197
  let convertString = '';
224
- for (let k = 0, nextChildren: XML; nextChildren = whenChildren.children[k]; k++) {
198
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
225
199
  convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
226
200
  }
227
201
  return convertString;
228
- } else {
202
+ }
203
+ else {
229
204
  continue;
230
205
  }
231
- } catch (e) {
206
+ }
207
+ catch (e) {
232
208
  continue;
233
209
  }
234
- } else if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'otherwise') {
210
+ }
211
+ else if (whenChildren.type == 'tag' && whenChildren.name.toLowerCase() == 'otherwise') {
235
212
  // If reached <otherwise> tag, do it.
236
213
  let convertString = '';
237
- for (let k = 0, nextChildren: XML; nextChildren = whenChildren.children[k]; k++) {
214
+ for (let k = 0, nextChildren; nextChildren = whenChildren.children[k]; k++) {
238
215
  convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
239
216
  }
240
217
  return convertString;
241
218
  }
242
219
  }
243
-
244
220
  // If there is no suitable when and otherwise, just return null.
245
221
  return '';
246
-
247
- } catch (err) {
222
+ }
223
+ catch (err) {
248
224
  throw new Error('Error occurred during convert <choose> element.');
249
225
  }
250
- }
251
-
252
- const convertTrimWhere = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
226
+ };
227
+ const convertTrimWhere = function (children, param, parentIds, myBatisMapper) {
253
228
  let convertString = '';
254
- let prefix: string | undefined;
255
- let prefixOverrides: string | undefined;
256
- let suffix: string | undefined;
257
- let suffixOverrides: string | undefined;
258
- let globalSet: string | undefined;
259
-
229
+ let prefix;
230
+ let prefixOverrides;
231
+ let suffix;
232
+ let suffixOverrides;
233
+ let globalSet;
260
234
  try {
261
235
  switch (children.name.toLowerCase()) {
262
236
  case 'trim':
@@ -274,102 +248,86 @@ const convertTrimWhere = function (children: XML, param: Record<string, any>, pa
274
248
  default:
275
249
  throw new Error('Error occurred during convert <trim/where> element.');
276
250
  }
277
-
278
251
  // Convert children first.
279
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
252
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
280
253
  convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
281
254
  }
282
-
283
255
  // Remove prefixOverrides
284
256
  let trimRegex = new RegExp('(^)([\\s]*?)(' + prefixOverrides + ')', globalSet);
285
257
  convertString = convertString.replace(trimRegex, '');
286
258
  // Remove suffixOverrides
287
259
  trimRegex = new RegExp('(' + suffixOverrides + ')([\\s]*?)($)', globalSet);
288
260
  convertString = convertString.replace(trimRegex, '');
289
-
290
261
  if (children.name.toLowerCase() != 'trim') {
291
262
  trimRegex = new RegExp('(' + prefixOverrides + ')([\\s]*?)($)', globalSet);
292
263
  convertString = convertString.replace(trimRegex, '');
293
264
  }
294
-
295
265
  // Add Prefix if String is not empty.
296
266
  trimRegex = new RegExp('([a-zA-Z])', 'g');
297
267
  const w = convertString.match(trimRegex);
298
-
299
268
  if (w != null && w.length > 0) {
300
269
  convertString = prefix + ' ' + convertString;
301
270
  if (suffix) {
302
- convertString = convertString + ' ' + suffix
271
+ convertString = convertString + ' ' + suffix;
303
272
  }
304
273
  }
305
-
306
274
  // Remove comma(,) before WHERE
307
275
  if (children.name.toLowerCase() != 'where') {
308
276
  const regex = new RegExp('(,)([\\s]*?)(where)', 'gi');
309
277
  convertString = convertString.replace(regex, ' WHERE ');
310
278
  }
311
-
312
279
  return convertString;
313
- } catch (err) {
280
+ }
281
+ catch (err) {
314
282
  throw new Error('Error occurred during convert <' + children.name.toLowerCase() + '> element.');
315
283
  }
316
- }
317
-
318
- const convertSet = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
284
+ };
285
+ const convertSet = function (children, param, parentIds, myBatisMapper) {
319
286
  let convertString = '';
320
-
321
287
  try {
322
288
  // Convert children first.
323
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
289
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
324
290
  convertString += convertChildren(nextChildren, param, parentIds, myBatisMapper);
325
291
  }
326
-
327
292
  // Remove comma repeated more than 2.
328
293
  let regex = new RegExp('(,)(,|\\s){2,}', 'g');
329
294
  convertString = convertString.replace(regex, ',\n');
330
-
331
295
  // Remove first comma if exists.
332
296
  regex = new RegExp('(^)([\\s]*?)(,)', 'g');
333
297
  convertString = convertString.replace(regex, '');
334
-
335
298
  // Remove last comma if exists.
336
299
  regex = new RegExp('(,)([\\s]*?)($)', 'g');
337
300
  convertString = convertString.replace(regex, '');
338
-
339
301
  convertString = ' SET ' + convertString;
340
302
  return convertString;
341
- } catch (err) {
303
+ }
304
+ catch (err) {
342
305
  throw new Error('Error occurred during convert <set> element.');
343
306
  }
344
- }
345
-
346
- const convertBind = function (children: XML, param: Record<string, any>) {
347
- let evalString = children.attrs["value"]!;
348
-
307
+ };
308
+ const convertBind = function (children, param) {
309
+ let evalString = children.attrs["value"];
349
310
  // Create Evaluate string
350
311
  evalString = replaceEvalString(evalString, param);
351
-
352
- param[children.attrs["name"]!] = eval(evalString);
353
-
312
+ param[children.attrs["name"]] = eval(evalString);
354
313
  return param;
355
- }
356
-
357
- const convertInclude = function (children: XML, param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) {
314
+ };
315
+ const convertInclude = function (children, param, parentIds, myBatisMapper) {
358
316
  try {
359
317
  // Add Properties to param
360
- for (let j = 0, nextChildren: XML; nextChildren = children.children[j]!; j++) {
318
+ for (let j = 0, nextChildren; nextChildren = children.children[j]; j++) {
361
319
  if (nextChildren.type == 'tag' && nextChildren.name == 'property') {
362
- param[nextChildren.attrs['name']!] = nextChildren.attrs['value'];
320
+ param[nextChildren.attrs['name']] = nextChildren.attrs['value'];
363
321
  }
364
322
  }
365
- } catch (err) {
323
+ }
324
+ catch (err) {
366
325
  throw new Error('Error occurred during read <property> element in <include> element.');
367
326
  }
368
-
369
327
  try {
370
- let refid = convertParametersInner('#', children.attrs['refid']!, param);
328
+ let refid = convertParametersInner('#', children.attrs['refid'], param);
371
329
  refid = convertParametersInner('$', refid, param);
372
- let mapper: XML[] | undefined;
330
+ let mapper;
373
331
  for (const psqlid of parentIds) {
374
332
  mapper = myBatisMapper[`${psqlid}.${refid}`];
375
333
  if (mapper) {
@@ -377,34 +335,30 @@ const convertInclude = function (children: XML, param: Record<string, any>, pare
377
335
  }
378
336
  }
379
337
  let statement = '';
380
- for (let i = 0, children: XML; children = mapper![i]!; i++) {
338
+ for (let i = 0, children; children = mapper[i]; i++) {
381
339
  statement += convertChildren(children, param, parentIds, myBatisMapper);
382
340
  }
383
341
  return statement;
384
- } catch (err) {
342
+ }
343
+ catch (err) {
385
344
  throw new Error('Error occurred during convert refid attribute in <include> element.');
386
345
  }
387
-
388
- }
389
-
390
- const isDict = function (v: any) {
346
+ };
347
+ const isDict = function (v) {
391
348
  return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
392
- }
393
-
394
- const replaceEvalString = function (evalString: string, param: Record<string, any>) {
349
+ };
350
+ const replaceEvalString = function (evalString, param) {
395
351
  const keys = Object.keys(param);
396
-
397
352
  for (let i = 0; i < keys.length; i++) {
398
353
  let replacePrefix = '';
399
354
  let replacePostfix = '';
400
- let paramRegex: RegExp | undefined;
401
-
402
- if (isDict(param[keys[i]!])) {
355
+ let paramRegex;
356
+ if (isDict(param[keys[i]])) {
403
357
  replacePrefix = ' param.';
404
358
  replacePostfix = '';
405
-
406
359
  paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + '\\.)([a-zA-Z0-9_]+)', 'g');
407
- } else {
360
+ }
361
+ else {
408
362
  replacePrefix = ' param.';
409
363
  replacePostfix = ' ';
410
364
  paramRegex = new RegExp('(^|[^a-zA-Z0-9_])(' + keys[i] + ')($|[^a-zA-Z0-9_])', 'g');
@@ -412,27 +366,24 @@ const replaceEvalString = function (evalString: string, param: Record<string, an
412
366
  evalString = evalString.replace(paramRegex, ('$1' + replacePrefix + '$2' + replacePostfix + '$3'));
413
367
  }
414
368
  return evalString;
415
- }
416
-
417
- const uniqueArray = function (a: RegExpMatchArray) {
369
+ };
370
+ const uniqueArray = function (a) {
418
371
  const seen = {};
419
- const out: string[] = [];
372
+ const out = [];
420
373
  const len = a.length;
421
374
  let j = 0;
422
375
  for (let i = 0; i < len; i++) {
423
- const item = a[i]!;
376
+ const item = a[i];
424
377
  if (seen[item] !== 1) {
425
378
  seen[item] = 1;
426
379
  out[j++] = item;
427
380
  }
428
381
  }
429
382
  return out;
430
- }
431
-
383
+ };
432
384
  const mysqlRealEscapeParam = function (param) {
433
385
  if (typeof param != 'string')
434
386
  return param;
435
-
436
387
  return param.replace(/[\0\x08\x09\x1a\n\r''\\\%]/g, function (char) {
437
388
  switch (char) {
438
389
  case '\0':
@@ -456,5 +407,4 @@ const mysqlRealEscapeParam = function (param) {
456
407
  return char;
457
408
  }
458
409
  });
459
- }
460
-
410
+ };
package/enum.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { EnmuJson, EnumMap } from "baja-lite-field";
2
+ export declare const getEnums: (GlobalValues?: EnumMap) => EnmuJson;
package/enum.js ADDED
@@ -0,0 +1,31 @@
1
+ import { _enums } from "./sql.js";
2
+ let configData = null;
3
+ export const getEnums = (GlobalValues) => {
4
+ if (!GlobalValues) {
5
+ return globalThis[_enums];
6
+ }
7
+ if (configData) {
8
+ return configData;
9
+ }
10
+ const result = {
11
+ GlobalArray: {},
12
+ GlobalMap: {}
13
+ };
14
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
15
+ Object.keys(GlobalValues).forEach((item) => {
16
+ // const guess = /([\w\W]+)_([^_]+)$/.exec(item);
17
+ const guess = item.replace(new RegExp(`_${GlobalValues[item].value()}`, 'i'), '');
18
+ if (guess) {
19
+ if (!result.GlobalArray[guess]) {
20
+ result.GlobalArray[guess] = [];
21
+ }
22
+ result.GlobalArray[guess].push([GlobalValues[item].value(), GlobalValues[item].desc()]);
23
+ if (!result.GlobalMap[guess]) {
24
+ result.GlobalMap[guess] = {};
25
+ }
26
+ result.GlobalMap[guess][GlobalValues[item].value()] = GlobalValues[item].desc();
27
+ }
28
+ });
29
+ configData = result;
30
+ return result;
31
+ };
package/error.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare const Throw: {
2
+ if(test: boolean, message: string | Error | any): void;
3
+ ifNot(test: boolean, message: string | Error | any): void;
4
+ now(message: string | Error | any): never;
5
+ };
package/error.js ADDED
@@ -0,0 +1,13 @@
1
+ export const Throw = {
2
+ if(test, message) {
3
+ if (test === true)
4
+ this.now(message);
5
+ },
6
+ ifNot(test, message) {
7
+ if (test !== true)
8
+ this.now(message);
9
+ },
10
+ now(message) {
11
+ throw typeof message === 'string' ? new Error(message) : message;
12
+ }
13
+ };