lemon-core 4.1.15 → 4.2.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.
Files changed (154) hide show
  1. package/dist/common/test-helper.d.ts +2 -2
  2. package/dist/common/test-helper.js +24 -26
  3. package/dist/common/test-helper.js.map +1 -1
  4. package/dist/controllers/dummy-controller.js +39 -46
  5. package/dist/controllers/dummy-controller.js.map +1 -1
  6. package/dist/controllers/general-api-controller.js +95 -100
  7. package/dist/controllers/general-api-controller.js.map +1 -1
  8. package/dist/controllers/general-controller.js +81 -82
  9. package/dist/controllers/general-controller.js.map +1 -1
  10. package/dist/cores/api/api-service.d.ts +1 -1
  11. package/dist/cores/api/api-service.js +228 -269
  12. package/dist/cores/api/api-service.js.map +1 -1
  13. package/dist/cores/aws/aws-kms-service.d.ts +1 -2
  14. package/dist/cores/aws/aws-kms-service.js +143 -153
  15. package/dist/cores/aws/aws-kms-service.js.map +1 -1
  16. package/dist/cores/aws/aws-s3-service.d.ts +2 -4
  17. package/dist/cores/aws/aws-s3-service.js +306 -330
  18. package/dist/cores/aws/aws-s3-service.js.map +1 -1
  19. package/dist/cores/aws/aws-sns-service.js +147 -153
  20. package/dist/cores/aws/aws-sns-service.js.map +1 -1
  21. package/dist/cores/aws/aws-sqs-service.js +149 -170
  22. package/dist/cores/aws/aws-sqs-service.js.map +1 -1
  23. package/dist/cores/aws/index.js +10 -20
  24. package/dist/cores/aws/index.js.map +1 -1
  25. package/dist/cores/cache/cache-service.d.ts +2 -2
  26. package/dist/cores/cache/cache-service.js +435 -499
  27. package/dist/cores/cache/cache-service.js.map +1 -1
  28. package/dist/cores/config/config-service.d.ts +1 -1
  29. package/dist/cores/config/config-service.js +56 -63
  30. package/dist/cores/config/config-service.js.map +1 -1
  31. package/dist/cores/config/index.js +14 -24
  32. package/dist/cores/config/index.js.map +1 -1
  33. package/dist/cores/core-services.d.ts +1 -1
  34. package/dist/cores/dynamo/dynamo-query-service.js +37 -51
  35. package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
  36. package/dist/cores/dynamo/dynamo-scan-service.d.ts +2 -2
  37. package/dist/cores/dynamo/dynamo-scan-service.js +29 -40
  38. package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
  39. package/dist/cores/dynamo/dynamo-service.d.ts +2 -2
  40. package/dist/cores/dynamo/dynamo-service.js +528 -601
  41. package/dist/cores/dynamo/dynamo-service.js.map +1 -1
  42. package/dist/cores/dynamo/tools/expressions.js +17 -7
  43. package/dist/cores/dynamo/tools/expressions.js.map +1 -1
  44. package/dist/cores/dynamo/tools/query.js +142 -127
  45. package/dist/cores/dynamo/tools/query.js.map +1 -1
  46. package/dist/cores/dynamo/tools/scan.js +111 -97
  47. package/dist/cores/dynamo/tools/scan.js.map +1 -1
  48. package/dist/cores/dynamo/tools/serializer.js +17 -7
  49. package/dist/cores/dynamo/tools/serializer.js.map +1 -1
  50. package/dist/cores/dynamo/tools/utils.d.ts +0 -2
  51. package/dist/cores/dynamo/tools/utils.js.map +1 -1
  52. package/dist/cores/elastic/elastic6-query-service.js +307 -324
  53. package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
  54. package/dist/cores/elastic/elastic6-service.d.ts +3 -3
  55. package/dist/cores/elastic/elastic6-service.js +568 -647
  56. package/dist/cores/elastic/elastic6-service.js.map +1 -1
  57. package/dist/cores/elastic/hangul-service.js +52 -54
  58. package/dist/cores/elastic/hangul-service.js.map +1 -1
  59. package/dist/cores/lambda/index.js +42 -36
  60. package/dist/cores/lambda/index.js.map +1 -1
  61. package/dist/cores/lambda/lambda-alb-handler.d.ts +2 -2
  62. package/dist/cores/lambda/lambda-alb-handler.js +59 -72
  63. package/dist/cores/lambda/lambda-alb-handler.js.map +1 -1
  64. package/dist/cores/lambda/lambda-cognito-handler.js +10 -19
  65. package/dist/cores/lambda/lambda-cognito-handler.js.map +1 -1
  66. package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -1
  67. package/dist/cores/lambda/lambda-cron-handler.js +14 -23
  68. package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
  69. package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
  70. package/dist/cores/lambda/lambda-dynamo-stream-handler.js +57 -67
  71. package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
  72. package/dist/cores/lambda/lambda-handler.d.ts +22 -22
  73. package/dist/cores/lambda/lambda-handler.js +93 -106
  74. package/dist/cores/lambda/lambda-handler.js.map +1 -1
  75. package/dist/cores/lambda/lambda-notification-handler.d.ts +1 -1
  76. package/dist/cores/lambda/lambda-notification-handler.js +39 -50
  77. package/dist/cores/lambda/lambda-notification-handler.js.map +1 -1
  78. package/dist/cores/lambda/lambda-sns-handler.js +79 -88
  79. package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
  80. package/dist/cores/lambda/lambda-sqs-handler.js +79 -88
  81. package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
  82. package/dist/cores/lambda/lambda-web-handler.d.ts +6 -6
  83. package/dist/cores/lambda/lambda-web-handler.js +387 -412
  84. package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
  85. package/dist/cores/lambda/lambda-wss-handler.js +23 -32
  86. package/dist/cores/lambda/lambda-wss-handler.js.map +1 -1
  87. package/dist/cores/protocol/index.js +10 -20
  88. package/dist/cores/protocol/index.js.map +1 -1
  89. package/dist/cores/protocol/protocol-service.d.ts +3 -3
  90. package/dist/cores/protocol/protocol-service.js +235 -227
  91. package/dist/cores/protocol/protocol-service.js.map +1 -1
  92. package/dist/cores/storage/http-storage-service.js +65 -85
  93. package/dist/cores/storage/http-storage-service.js.map +1 -1
  94. package/dist/cores/storage/model-manager.js +66 -85
  95. package/dist/cores/storage/model-manager.js.map +1 -1
  96. package/dist/cores/storage/proxy-storage-service.d.ts +2 -2
  97. package/dist/cores/storage/proxy-storage-service.js +562 -599
  98. package/dist/cores/storage/proxy-storage-service.js.map +1 -1
  99. package/dist/cores/storage/redis-storage-service.js +163 -177
  100. package/dist/cores/storage/redis-storage-service.js.map +1 -1
  101. package/dist/cores/storage/storage-service.js +281 -322
  102. package/dist/cores/storage/storage-service.js.map +1 -1
  103. package/dist/engine/builder.d.ts +1 -1
  104. package/dist/engine/builder.js +59 -63
  105. package/dist/engine/builder.js.map +1 -1
  106. package/dist/engine/engine.d.ts +4 -4
  107. package/dist/engine/engine.js +9 -18
  108. package/dist/engine/engine.js.map +1 -1
  109. package/dist/engine/types.d.ts +1 -1
  110. package/dist/engine/utilities.d.ts +5 -5
  111. package/dist/engine/utilities.js +301 -293
  112. package/dist/engine/utilities.js.map +1 -1
  113. package/dist/environ.js +4 -6
  114. package/dist/environ.js.map +1 -1
  115. package/dist/extended/abstract-service.js +595 -645
  116. package/dist/extended/abstract-service.js.map +1 -1
  117. package/dist/extended/libs/sig-v4.js.map +1 -1
  118. package/dist/generated/field-registry.d.ts +10 -0
  119. package/dist/generated/field-registry.js +17 -0
  120. package/dist/generated/field-registry.js.map +1 -0
  121. package/dist/helpers/helpers.d.ts +17 -9
  122. package/dist/helpers/helpers.js +88 -78
  123. package/dist/helpers/helpers.js.map +1 -1
  124. package/dist/index.js +17 -7
  125. package/dist/index.js.map +1 -1
  126. package/dist/lib/dynamodb-value.js +2 -3
  127. package/dist/lib/dynamodb-value.js.map +1 -1
  128. package/dist/tools/express.js +4 -5
  129. package/dist/tools/express.js.map +1 -1
  130. package/dist/tools/tools.d.ts +3 -1
  131. package/dist/tools/tools.js +14 -21
  132. package/dist/tools/tools.js.map +1 -1
  133. package/package.json +19 -18
  134. package/dist/exec-cli.d.ts +0 -2
  135. package/dist/exec-cli.js +0 -211
  136. package/dist/exec-cli.js.map +0 -1
  137. package/dist/lib/dynamo/expressions.d.ts +0 -14
  138. package/dist/lib/dynamo/expressions.js +0 -212
  139. package/dist/lib/dynamo/expressions.js.map +0 -1
  140. package/dist/lib/dynamo/query.d.ts +0 -43
  141. package/dist/lib/dynamo/query.js +0 -246
  142. package/dist/lib/dynamo/query.js.map +0 -1
  143. package/dist/lib/dynamo/scan.d.ts +0 -33
  144. package/dist/lib/dynamo/scan.js +0 -172
  145. package/dist/lib/dynamo/scan.js.map +0 -1
  146. package/dist/lib/dynamo/serializer.d.ts +0 -12
  147. package/dist/lib/dynamo/serializer.js +0 -243
  148. package/dist/lib/dynamo/serializer.js.map +0 -1
  149. package/dist/lib/dynamo/utils.d.ts +0 -15
  150. package/dist/lib/dynamo/utils.js +0 -129
  151. package/dist/lib/dynamo/utils.js.map +0 -1
  152. package/dist/tools/shared.d.ts +0 -28
  153. package/dist/tools/shared.js +0 -143
  154. package/dist/tools/shared.js.map +0 -1
@@ -1,32 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
19
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
20
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
21
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
22
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
23
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
24
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
25
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
26
- function fulfill(value) { resume("next", value); }
27
- function reject(value) { resume("throw", value); }
28
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
29
- };
30
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
4
  };
@@ -68,21 +40,8 @@ const _S = (v, def = '') => typeof v === 'string' ? v : v === undefined || v ===
68
40
  * TODO - support `Elastic` and `OpenSearch`
69
41
  */
70
42
  class ElasticIndexService {
71
- /**
72
- * default constuctor w/ options.
73
- * @param options { endpoint, indexName } is required.
74
- */
75
- constructor(options) {
76
- (0, engine_1._inf)(NS, `ElasticIndexService(${options.indexName}/${options.idName})...`);
77
- if (!options.endpoint)
78
- throw new Error('.endpoint (URL) is required');
79
- if (!options.indexName)
80
- throw new Error('.indexName (string) is required');
81
- // default option values: docType='_doc', idName='$id'
82
- const { client } = ElasticIndexService.instance(options.endpoint);
83
- this._options = Object.assign({ docType: '_doc', idName: '$id', version: '6.8' }, options);
84
- this._client = client;
85
- }
43
+ _options;
44
+ _client;
86
45
  /**
87
46
  * simple instance maker.
88
47
  *
@@ -103,6 +62,21 @@ class ElasticIndexService {
103
62
  });
104
63
  return { client };
105
64
  }
65
+ /**
66
+ * default constuctor w/ options.
67
+ * @param options { endpoint, indexName } is required.
68
+ */
69
+ constructor(options) {
70
+ (0, engine_1._inf)(NS, `ElasticIndexService(${options.indexName}/${options.idName})...`);
71
+ if (!options.endpoint)
72
+ throw new Error('.endpoint (URL) is required');
73
+ if (!options.indexName)
74
+ throw new Error('.indexName (string) is required');
75
+ // default option values: docType='_doc', idName='$id'
76
+ const { client } = ElasticIndexService.instance(options.endpoint);
77
+ this._options = { docType: '_doc', idName: '$id', version: '6.8', ...options };
78
+ this._client = client;
79
+ }
106
80
  /**
107
81
  * get the client instance.
108
82
  */
@@ -129,18 +103,21 @@ exports.ElasticIndexService = ElasticIndexService;
129
103
  * - extends `ElasticIndexService` and adds version-specific implementation
130
104
  */
131
105
  class Elastic6Service extends ElasticIndexService {
106
+ // internal field name to store analyzed strings for autocomplete search
107
+ static DECOMPOSED_FIELD = '_decomposed';
108
+ static QWERTY_FIELD = '_qwerty';
132
109
  /**
133
110
  * default constuctor w/ options.
134
111
  * @param options { endpoint, indexName } is required.
135
112
  */
136
113
  constructor(options) {
137
114
  super(options);
138
- /**
139
- * say hello of identity.
140
- */
141
- this.hello = () => `elastic6-service:${this.options.indexName}:${this.options.version}`;
142
115
  (0, engine_1._inf)('Elastic6Service', `Elastic6Service(${options.indexName}/${options.idName})...`);
143
116
  }
117
+ /**
118
+ * say hello of identity.
119
+ */
120
+ hello = () => `elastic6-service:${this.options.indexName}:${this.options.version}`;
144
121
  /**
145
122
  * get isOldES6
146
123
  * - used when setting doctype
@@ -174,45 +151,43 @@ class Elastic6Service extends ElasticIndexService {
174
151
  *
175
152
  * @protected only for internal test.
176
153
  */
177
- getVersion(options) {
178
- var _a, _b, _c;
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const isDump = (_a = options === null || options === void 0 ? void 0 : options.dump) !== null && _a !== void 0 ? _a : false;
181
- // it consumes about >20ms
182
- const info = yield this.client.info();
183
- const rootVersion = engine_1.$U.S(info.body.version.number);
184
- const parsedVersion = this.parseVersion(rootVersion, { throwable: true });
185
- if (isDump) {
186
- //* save into `info.json`.
187
- const description = Object.assign({ '!': `${(_b = this.parsedVersion) === null || _b === void 0 ? void 0 : _b.engine}${this.options.version} client info` }, info);
188
- const filePath = path_1.default.resolve(__dirname, `../../../data/samples/${(_c = this.parsedVersion) === null || _c === void 0 ? void 0 : _c.engine}${this.options.version}/info.json`);
189
- yield this.saveInfoToFile(description, filePath);
190
- }
191
- return parsedVersion;
192
- });
154
+ async getVersion(options) {
155
+ const isDump = options?.dump ?? false;
156
+ // it consumes about >20ms
157
+ const info = await this.client.info();
158
+ const rootVersion = engine_1.$U.S(info.body.version.number);
159
+ const parsedVersion = this.parseVersion(rootVersion, { throwable: true });
160
+ if (isDump) {
161
+ //* save into `info.json`.
162
+ const description = {
163
+ '!': `${this.parsedVersion?.engine}${this.options.version} client info`,
164
+ ...info,
165
+ };
166
+ const filePath = path_1.default.resolve(__dirname, `../../../data/samples/${this.parsedVersion?.engine}${this.options.version}/info.json`);
167
+ await this.saveInfoToFile(description, filePath);
168
+ }
169
+ return parsedVersion;
193
170
  }
194
171
  /**
195
172
  * check whether the service version matches the version provided in the options.
196
173
  *
197
174
  * @protected only for internal test.
198
175
  */
199
- executeSelfTest() {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- // STEP.1 read the parsed-version.
202
- const optionVersion = this.parsedVersion;
203
- // STEP.2 get the real version via `getVersion()`
204
- const rootVersion = yield this.getVersion();
205
- // STEP.3 validate version
206
- const isEqual = optionVersion.engine === rootVersion.engine &&
207
- optionVersion.major === rootVersion.major &&
208
- optionVersion.minor === rootVersion.minor;
209
- // Return the comparison result
210
- return {
211
- isEqual: isEqual,
212
- optionVersion: optionVersion,
213
- rootVersion: rootVersion,
214
- };
215
- });
176
+ async executeSelfTest() {
177
+ // STEP.1 read the parsed-version.
178
+ const optionVersion = this.parsedVersion;
179
+ // STEP.2 get the real version via `getVersion()`
180
+ const rootVersion = await this.getVersion();
181
+ // STEP.3 validate version
182
+ const isEqual = optionVersion.engine === rootVersion.engine &&
183
+ optionVersion.major === rootVersion.major &&
184
+ optionVersion.minor === rootVersion.minor;
185
+ // Return the comparison result
186
+ return {
187
+ isEqual: isEqual,
188
+ optionVersion: optionVersion,
189
+ rootVersion: rootVersion,
190
+ };
216
191
  }
217
192
  /**
218
193
  * parse version according to Semantic Versioning (SemVer) rules.
@@ -222,18 +197,24 @@ class Elastic6Service extends ElasticIndexService {
222
197
  * @returns A ParsedVersion object or null if parsing fails and throwable is false.
223
198
  */
224
199
  parseVersion(version, options) {
225
- var _a;
226
- const isThrowable = (_a = options === null || options === void 0 ? void 0 : options.throwable) !== null && _a !== void 0 ? _a : true;
200
+ const isThrowable = options?.throwable ?? true;
227
201
  if (!version && isThrowable)
228
202
  throw new Error(`@version (string) is required!`);
229
203
  // RegEx to match Semantic Versioning patterns
230
- const match = version === null || version === void 0 ? void 0 : version.match(/^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,2}))?(?:-([a-zA-Z0-9-.]+))?(?:\+([a-zA-Z0-9-.]+))?$/);
204
+ const match = version?.match(/^(\d{1,2})(?:\.(\d{1,2}))?(?:\.(\d{1,2}))?(?:-([a-zA-Z0-9-.]+))?(?:\+([a-zA-Z0-9-.]+))?$/);
231
205
  if (!match) {
232
206
  if (isThrowable)
233
207
  throw new Error(`@version[${version}] is invalid - fail to parse`);
234
208
  return null;
235
209
  }
236
- const res = Object.assign(Object.assign({ engine: engine_1.$U.N(match[1], 10) < 6 ? 'os' : 'es', major: engine_1.$U.N(match[1], 10), minor: match[2] !== undefined ? engine_1.$U.N(match[2], 10) : 0, patch: match[3] !== undefined ? engine_1.$U.N(match[3], 10) : 0 }, (match[4] !== undefined ? { prerelease: match[4] } : {})), (match[5] !== undefined ? { build: match[5] } : {}));
210
+ const res = {
211
+ engine: engine_1.$U.N(match[1], 10) < 6 ? 'os' : 'es',
212
+ major: engine_1.$U.N(match[1], 10),
213
+ minor: match[2] !== undefined ? engine_1.$U.N(match[2], 10) : 0,
214
+ patch: match[3] !== undefined ? engine_1.$U.N(match[3], 10) : 0,
215
+ ...(match[4] !== undefined ? { prerelease: match[4] } : {}),
216
+ ...(match[5] !== undefined ? { build: match[5] } : {}),
217
+ };
237
218
  return res;
238
219
  }
239
220
  /**
@@ -241,234 +222,218 @@ class Elastic6Service extends ElasticIndexService {
241
222
  * @param info - The information to be saved
242
223
  * @param filePath - The file path where should be saved.
243
224
  */
244
- saveInfoToFile(info, filePath) {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- try {
247
- const directory = path_1.default.dirname(filePath);
248
- // check whether directory exists
249
- if (!fs_1.default.existsSync(directory)) {
250
- fs_1.default.mkdirSync(directory, { recursive: true });
251
- }
252
- // write info to file
253
- fs_1.default.writeFileSync(filePath, JSON.stringify(info, null, 2));
225
+ async saveInfoToFile(info, filePath) {
226
+ try {
227
+ const directory = path_1.default.dirname(filePath);
228
+ // check whether directory exists
229
+ if (!fs_1.default.existsSync(directory)) {
230
+ fs_1.default.mkdirSync(directory, { recursive: true });
254
231
  }
255
- catch (_a) {
256
- exports.$ERROR.handler('saveIntoFile', e => {
257
- throw e;
258
- });
259
- }
260
- });
232
+ // write info to file
233
+ fs_1.default.writeFileSync(filePath, JSON.stringify(info, null, 2));
234
+ }
235
+ catch {
236
+ exports.$ERROR.handler('saveIntoFile', e => {
237
+ throw e;
238
+ });
239
+ }
261
240
  }
262
241
  /**
263
242
  * list of index
264
243
  */
265
- listIndices() {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- (0, engine_1._log)(NS, `- listIndices()`);
268
- //* prepare client..
269
- const client = this.client;
270
- const res = yield client.cat.indices({ format: 'json' });
271
- (0, engine_1._log)(NS, `> indices =`, engine_1.$U.json(res));
272
- // eslint-disable-next-line prettier/prettier
273
- const list0 = Array.isArray(res) ? res : (res === null || res === void 0 ? void 0 : res.body) && Array.isArray(res === null || res === void 0 ? void 0 : res.body) ? res === null || res === void 0 ? void 0 : res.body : null;
274
- if (!list0)
275
- throw new Error(`@result<${typeof res}> is invalid - ${engine_1.$U.json(res)}!`);
276
- // {"docs.count": "84", "docs.deleted": "7", "health": "green", "index": "dev-eureka-alarms-v1", "pri": "5", "pri.store.size": "234.3kb", "rep": "1", "status": "open", "store.size": "468.6kb", "uuid": "xPp-Sx86SgmhAWxT3cGAFw"}
277
- const list = list0.map(N => ({
278
- pri: engine_1.$U.N(N['pri']),
279
- rep: engine_1.$U.N(N['rep']),
280
- docsCount: engine_1.$U.N(N['docs.count']),
281
- docsDeleted: engine_1.$U.N(N['docs.deleted']),
282
- health: _S(N['health']),
283
- index: _S(N['index']),
284
- status: _S(N['status']),
285
- uuid: _S(N['uuid']),
286
- priStoreSize: _S(N['pri.store.size']),
287
- storeSize: _S(N['store.size']),
288
- }));
289
- return { list };
290
- });
244
+ async listIndices() {
245
+ (0, engine_1._log)(NS, `- listIndices()`);
246
+ //* prepare client..
247
+ const client = this.client;
248
+ const res = await client.cat.indices({ format: 'json' });
249
+ (0, engine_1._log)(NS, `> indices =`, engine_1.$U.json(res));
250
+ // eslint-disable-next-line prettier/prettier
251
+ const list0 = Array.isArray(res) ? res : res?.body && Array.isArray(res?.body) ? res?.body : null;
252
+ if (!list0)
253
+ throw new Error(`@result<${typeof res}> is invalid - ${engine_1.$U.json(res)}!`);
254
+ // {"docs.count": "84", "docs.deleted": "7", "health": "green", "index": "dev-eureka-alarms-v1", "pri": "5", "pri.store.size": "234.3kb", "rep": "1", "status": "open", "store.size": "468.6kb", "uuid": "xPp-Sx86SgmhAWxT3cGAFw"}
255
+ const list = list0.map(N => ({
256
+ pri: engine_1.$U.N(N['pri']),
257
+ rep: engine_1.$U.N(N['rep']),
258
+ docsCount: engine_1.$U.N(N['docs.count']),
259
+ docsDeleted: engine_1.$U.N(N['docs.deleted']),
260
+ health: _S(N['health']),
261
+ index: _S(N['index']),
262
+ status: _S(N['status']),
263
+ uuid: _S(N['uuid']),
264
+ priStoreSize: _S(N['pri.store.size']),
265
+ storeSize: _S(N['store.size']),
266
+ }));
267
+ return { list };
291
268
  }
292
269
  /**
293
270
  * get mapping of an index
294
271
  * @param indexName - name of the index
295
272
  */
296
- getIndexMapping() {
297
- var _a;
298
- return __awaiter(this, void 0, void 0, function* () {
299
- const client = this.client;
300
- const indexName = this.options.indexName;
301
- const res = yield client.indices.getMapping({ index: indexName }).catch(
302
- // $ERROR.throwAsJson,
303
- exports.$ERROR.handler('getMapping', e => {
304
- const msg = (0, test_helper_1.GETERR)(e);
305
- if (msg.startsWith('404 INDEX NOT FOUND'))
306
- throw new Error(`404 NOT FOUND - index:${indexName}`);
307
- throw e;
308
- }));
309
- const mapping = (res === null || res === void 0 ? void 0 : res.body) ? (_a = res.body[indexName]) === null || _a === void 0 ? void 0 : _a.mappings : null;
310
- if (!mapping)
311
- throw new Error(`@indexName[${indexName}] is not found - ${engine_1.$U.json(res)}!`);
312
- return mapping;
313
- });
273
+ async getIndexMapping() {
274
+ const client = this.client;
275
+ const indexName = this.options.indexName;
276
+ const res = await client.indices.getMapping({ index: indexName }).catch(
277
+ // $ERROR.throwAsJson,
278
+ exports.$ERROR.handler('getMapping', e => {
279
+ const msg = (0, test_helper_1.GETERR)(e);
280
+ if (msg.startsWith('404 INDEX NOT FOUND'))
281
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
282
+ throw e;
283
+ }));
284
+ const mapping = res?.body ? res.body[indexName]?.mappings : null;
285
+ if (!mapping)
286
+ throw new Error(`@indexName[${indexName}] is not found - ${engine_1.$U.json(res)}!`);
287
+ return mapping;
314
288
  }
315
289
  /**
316
290
  * find the index by name
317
291
  * @param indexName - name of the index
318
292
  */
319
- findIndex(indexName) {
320
- return __awaiter(this, void 0, void 0, function* () {
321
- indexName = indexName || this.options.indexName;
322
- (0, engine_1._log)(NS, `- findIndex(${indexName})`);
323
- const { list } = yield this.listIndices();
324
- const found = list.findIndex(N => N.index == indexName);
325
- return found >= 0 ? list[found] : null;
326
- });
293
+ async findIndex(indexName) {
294
+ indexName = indexName || this.options.indexName;
295
+ (0, engine_1._log)(NS, `- findIndex(${indexName})`);
296
+ const { list } = await this.listIndices();
297
+ const found = list.findIndex(N => N.index == indexName);
298
+ return found >= 0 ? list[found] : null;
327
299
  }
328
300
  /**
329
301
  * create index by name
330
302
  * @param settings - creating settings
331
303
  */
332
- createIndex(settings) {
333
- return __awaiter(this, void 0, void 0, function* () {
334
- const { indexName, docType, idName, timeSeries, version } = this.options;
335
- settings = settings || Elastic6Service.prepareSettings({ docType, idName, timeSeries, version });
336
- if (!indexName)
337
- new Error('@index is required!');
338
- (0, engine_1._log)(NS, `- createIndex(${indexName})`);
339
- //* prepare payload
340
- const payload = Object.assign({ settings: {
341
- number_of_shards: 5,
342
- number_of_replicas: 1,
343
- } }, settings);
344
- (0, engine_1._log)(NS, `> settings[${indexName}] = `, engine_1.$U.json(payload));
345
- //* call create index..
346
- const client = this.client;
347
- const res = yield client.indices.create({ index: indexName, body: payload }).catch(
348
- // $ERROR.throwAsJson,
349
- exports.$ERROR.handler('create', e => {
350
- const msg = (0, test_helper_1.GETERR)(e);
351
- if (msg.startsWith('400 RESOURCE ALREADY EXISTS'))
352
- throw new Error(`400 IN USE - index:${indexName}`);
353
- throw e;
354
- }));
355
- // if (res) throw res;
356
- (0, engine_1._log)(NS, `> create[${indexName}] =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
357
- //* build result.
358
- return {
359
- status: res.statusCode,
360
- index: indexName,
361
- acknowledged: res.body.shards_acknowledged,
362
- };
363
- });
304
+ async createIndex(settings) {
305
+ const { indexName, docType, idName, timeSeries, version } = this.options;
306
+ settings = settings || Elastic6Service.prepareSettings({ docType, idName, timeSeries, version });
307
+ if (!indexName)
308
+ new Error('@index is required!');
309
+ (0, engine_1._log)(NS, `- createIndex(${indexName})`);
310
+ //* prepare payload
311
+ const payload = {
312
+ settings: {
313
+ number_of_shards: 5,
314
+ number_of_replicas: 1,
315
+ },
316
+ ...settings,
317
+ };
318
+ (0, engine_1._log)(NS, `> settings[${indexName}] = `, engine_1.$U.json(payload));
319
+ //* call create index..
320
+ const client = this.client;
321
+ const res = await client.indices.create({ index: indexName, body: payload }).catch(
322
+ // $ERROR.throwAsJson,
323
+ exports.$ERROR.handler('create', e => {
324
+ const msg = (0, test_helper_1.GETERR)(e);
325
+ if (msg.startsWith('400 RESOURCE ALREADY EXISTS'))
326
+ throw new Error(`400 IN USE - index:${indexName}`);
327
+ throw e;
328
+ }));
329
+ // if (res) throw res;
330
+ (0, engine_1._log)(NS, `> create[${indexName}] =`, engine_1.$U.json({ ...res, meta: undefined }));
331
+ //* build result.
332
+ return {
333
+ status: res.statusCode,
334
+ index: indexName,
335
+ acknowledged: res.body.shards_acknowledged,
336
+ };
364
337
  }
365
338
  /**
366
339
  * destroy search index
367
340
  */
368
- destroyIndex() {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- const { indexName } = this.options;
371
- if (!indexName)
372
- new Error('@index is required!');
373
- (0, engine_1._log)(NS, `- destroyIndex(${indexName})`);
374
- //* call destroy index..
375
- // const { client } = instance(endpoint);
376
- const client = this.client;
377
- const res = yield client.indices.delete({ index: indexName }).catch(
378
- // $ERROR.throwAsJson,
379
- exports.$ERROR.handler('destroy', e => {
380
- const msg = (0, test_helper_1.GETERR)(e);
381
- if (msg.startsWith('404 INDEX NOT FOUND'))
382
- throw new Error(`404 NOT FOUND - index:${indexName}`);
383
- throw e;
384
- }));
385
- // if (res) throw res;
386
- (0, engine_1._log)(NS, `> destroy[${indexName}] =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
387
- return {
388
- status: res.statusCode,
389
- index: indexName,
390
- acknowledged: res.body.acknowledged,
391
- };
392
- });
341
+ async destroyIndex() {
342
+ const { indexName } = this.options;
343
+ if (!indexName)
344
+ new Error('@index is required!');
345
+ (0, engine_1._log)(NS, `- destroyIndex(${indexName})`);
346
+ //* call destroy index..
347
+ // const { client } = instance(endpoint);
348
+ const client = this.client;
349
+ const res = await client.indices.delete({ index: indexName }).catch(
350
+ // $ERROR.throwAsJson,
351
+ exports.$ERROR.handler('destroy', e => {
352
+ const msg = (0, test_helper_1.GETERR)(e);
353
+ if (msg.startsWith('404 INDEX NOT FOUND'))
354
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
355
+ throw e;
356
+ }));
357
+ // if (res) throw res;
358
+ (0, engine_1._log)(NS, `> destroy[${indexName}] =`, engine_1.$U.json({ ...res, meta: undefined }));
359
+ return {
360
+ status: res.statusCode,
361
+ index: indexName,
362
+ acknowledged: res.body.acknowledged,
363
+ };
393
364
  }
394
365
  /**
395
366
  * refresh search index - refresh index to make all items searchable
396
367
  */
397
- refreshIndex() {
398
- return __awaiter(this, void 0, void 0, function* () {
399
- const { indexName } = this.options;
400
- if (!indexName)
401
- throw new Error('.indexName is required!');
402
- (0, engine_1._log)(NS, `- refreshIndex(${indexName})`);
403
- //* call refresh index..
404
- // const { client } = instance(endpoint);
405
- const client = this.client;
406
- const res = yield client.indices.refresh({ index: indexName }).catch(
407
- // $ERROR.throwAsJson,
408
- exports.$ERROR.handler('refresh', e => {
409
- const msg = (0, test_helper_1.GETERR)(e);
410
- if (msg.startsWith('404 INDEX NOT FOUND'))
411
- throw new Error(`404 NOT FOUND - index:${indexName}`);
412
- throw e;
413
- }));
414
- (0, engine_1._log)(NS, `> refresh[${indexName}] =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
415
- return res.body;
416
- });
368
+ async refreshIndex() {
369
+ const { indexName } = this.options;
370
+ if (!indexName)
371
+ throw new Error('.indexName is required!');
372
+ (0, engine_1._log)(NS, `- refreshIndex(${indexName})`);
373
+ //* call refresh index..
374
+ // const { client } = instance(endpoint);
375
+ const client = this.client;
376
+ const res = await client.indices.refresh({ index: indexName }).catch(
377
+ // $ERROR.throwAsJson,
378
+ exports.$ERROR.handler('refresh', e => {
379
+ const msg = (0, test_helper_1.GETERR)(e);
380
+ if (msg.startsWith('404 INDEX NOT FOUND'))
381
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
382
+ throw e;
383
+ }));
384
+ (0, engine_1._log)(NS, `> refresh[${indexName}] =`, engine_1.$U.json({ ...res, meta: undefined }));
385
+ return res.body;
417
386
  }
418
387
  /**
419
388
  * flush search index - force store changes into search index immediately
420
389
  */
421
- flushIndex() {
422
- return __awaiter(this, void 0, void 0, function* () {
423
- const { indexName } = this.options;
424
- if (!indexName)
425
- throw new Error('.indexName is required!');
426
- (0, engine_1._log)(NS, `- flushIndex(${indexName})`);
427
- //* call flush index..
428
- // const { client } = instance(endpoint);
429
- const client = this.client;
430
- const res = yield client.indices.flush({ index: indexName }).catch(
431
- // $ERROR.throwAsJson,
432
- exports.$ERROR.handler('flush', e => {
433
- const msg = (0, test_helper_1.GETERR)(e);
434
- if (msg.startsWith('404 INDEX NOT FOUND'))
435
- throw new Error(`404 NOT FOUND - index:${indexName}`);
436
- throw e;
437
- }));
438
- (0, engine_1._log)(NS, `> flush[${indexName}] =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
439
- return res.body;
440
- });
390
+ async flushIndex() {
391
+ const { indexName } = this.options;
392
+ if (!indexName)
393
+ throw new Error('.indexName is required!');
394
+ (0, engine_1._log)(NS, `- flushIndex(${indexName})`);
395
+ //* call flush index..
396
+ // const { client } = instance(endpoint);
397
+ const client = this.client;
398
+ const res = await client.indices.flush({ index: indexName }).catch(
399
+ // $ERROR.throwAsJson,
400
+ exports.$ERROR.handler('flush', e => {
401
+ const msg = (0, test_helper_1.GETERR)(e);
402
+ if (msg.startsWith('404 INDEX NOT FOUND'))
403
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
404
+ throw e;
405
+ }));
406
+ (0, engine_1._log)(NS, `> flush[${indexName}] =`, engine_1.$U.json({ ...res, meta: undefined }));
407
+ return res.body;
441
408
  }
442
409
  /**
443
410
  * describe `settings` and `mappings` of index.
444
411
  */
445
- describe() {
446
- return __awaiter(this, void 0, void 0, function* () {
447
- const { indexName } = this.options;
448
- //* call create index..
449
- (0, engine_1._log)(NS, `- describe(${indexName})`);
450
- //* read settings.
451
- // const { client } = instance(endpoint);
452
- const client = this.client;
453
- const res = yield client.indices.getSettings({ index: indexName }).catch(
454
- // $ERROR.throwAsJson,
455
- exports.$ERROR.handler('describe', e => {
456
- const msg = (0, test_helper_1.GETERR)(e);
457
- if (msg.startsWith('404 INDEX NOT FOUND'))
458
- throw new Error(`404 NOT FOUND - index:${indexName}`);
459
- throw e;
460
- }));
461
- (0, engine_1._log)(NS, `> settings[${indexName}] =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
462
- const settings = (res.body && res.body[indexName] && res.body[indexName].settings) || {};
463
- (0, engine_1._log)(NS, `> number_of_shards =`, settings.index && settings.index.number_of_shards); // 5
464
- (0, engine_1._log)(NS, `> number_of_replicas =`, settings.index && settings.index.number_of_replicas); // 1
465
- //* read mappings.
466
- const res2 = yield client.indices.getMapping({ index: indexName });
467
- (0, engine_1._log)(NS, `> mappings[${indexName}] =`, engine_1.$U.json(res2));
468
- const mappings = (res2.body && res2.body[indexName] && res2.body[indexName].mappings) || {};
469
- //* returns
470
- return { settings, mappings };
471
- });
412
+ async describe() {
413
+ const { indexName } = this.options;
414
+ //* call create index..
415
+ (0, engine_1._log)(NS, `- describe(${indexName})`);
416
+ //* read settings.
417
+ // const { client } = instance(endpoint);
418
+ const client = this.client;
419
+ const res = await client.indices.getSettings({ index: indexName }).catch(
420
+ // $ERROR.throwAsJson,
421
+ exports.$ERROR.handler('describe', e => {
422
+ const msg = (0, test_helper_1.GETERR)(e);
423
+ if (msg.startsWith('404 INDEX NOT FOUND'))
424
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
425
+ throw e;
426
+ }));
427
+ (0, engine_1._log)(NS, `> settings[${indexName}] =`, engine_1.$U.json({ ...res, meta: undefined }));
428
+ const settings = (res.body && res.body[indexName] && res.body[indexName].settings) || {};
429
+ (0, engine_1._log)(NS, `> number_of_shards =`, settings.index && settings.index.number_of_shards); // 5
430
+ (0, engine_1._log)(NS, `> number_of_replicas =`, settings.index && settings.index.number_of_replicas); // 1
431
+ //* read mappings.
432
+ const res2 = await client.indices.getMapping({ index: indexName });
433
+ (0, engine_1._log)(NS, `> mappings[${indexName}] =`, engine_1.$U.json(res2));
434
+ const mappings = (res2.body && res2.body[indexName] && res2.body[indexName].mappings) || {};
435
+ //* returns
436
+ return { settings, mappings };
472
437
  }
473
438
  /**
474
439
  * save single item
@@ -477,47 +442,44 @@ class Elastic6Service extends ElasticIndexService {
477
442
  * @param item - item to save
478
443
  * @param type - document type (default: doc-type given at construction time)
479
444
  */
480
- saveItem(id, item, type) {
481
- var _a, _b;
482
- return __awaiter(this, void 0, void 0, function* () {
483
- const { indexName, docType, idName } = this.options;
484
- (0, engine_1._log)(NS, `- saveItem(${id})`);
485
- // const { client } = instance(endpoint);
486
- const client = this.client;
487
- // prepare item body and autocomplete fields
488
- const body = Object.assign(Object.assign({}, item), { [idName]: id });
489
- const body2 = this.popullateAutocompleteFields(body);
490
- type = `${type || docType}`;
491
- const params = { index: indexName, id, body: body2 };
492
- // check version to include 'type' in params
493
- if (this.isOldES6) {
494
- params.type = type;
445
+ async saveItem(id, item, type) {
446
+ const { indexName, docType, idName } = this.options;
447
+ (0, engine_1._log)(NS, `- saveItem(${id})`);
448
+ // const { client } = instance(endpoint);
449
+ const client = this.client;
450
+ // prepare item body and autocomplete fields
451
+ const body = { ...item, [idName]: id };
452
+ const body2 = this.popullateAutocompleteFields(body);
453
+ type = `${type || docType}`;
454
+ const params = { index: indexName, id, body: body2 };
455
+ // check version to include 'type' in params
456
+ if (this.isOldES6) {
457
+ params.type = type;
458
+ }
459
+ if (idName === '_id')
460
+ delete params.body[idName]; //WARN! `_id` is reserved in ES6.
461
+ (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
462
+ //NOTE - use npm `elasticsearch#13.2.0` for avoiding error.
463
+ const res = await client.create(params).catch(
464
+ // $ERROR.throwAsJson,
465
+ exports.$ERROR.handler('save', e => {
466
+ const msg = (0, test_helper_1.GETERR)(e);
467
+ //* try to overwrite document..
468
+ if (msg.startsWith('409 VERSION CONFLICT ENGINE')) {
469
+ // delete body2[idName]; // do set id while update
470
+ // return this.updateItem(id, body2);
471
+ const param2 = { index: indexName, id, body: { ...body2 } };
472
+ if (this.isOldES6)
473
+ param2.type = type;
474
+ return client.index(param2);
495
475
  }
496
- if (idName === '_id')
497
- delete params.body[idName]; //WARN! `_id` is reserved in ES6.
498
- (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
499
- //NOTE - use npm `elasticsearch#13.2.0` for avoiding error.
500
- const res = yield client.create(params).catch(
501
- // $ERROR.throwAsJson,
502
- exports.$ERROR.handler('save', e => {
503
- const msg = (0, test_helper_1.GETERR)(e);
504
- //* try to overwrite document..
505
- if (msg.startsWith('409 VERSION CONFLICT ENGINE')) {
506
- // delete body2[idName]; // do set id while update
507
- // return this.updateItem(id, body2);
508
- const param2 = { index: indexName, id, body: Object.assign({}, body2) };
509
- if (this.isOldES6)
510
- param2.type = type;
511
- return client.index(param2);
512
- }
513
- throw e;
514
- }));
515
- (0, engine_1._log)(NS, `> create[${id}].res =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
516
- const _version = engine_1.$U.N((_a = res.body) === null || _a === void 0 ? void 0 : _a._version, 0);
517
- const _id = (_b = res.body) === null || _b === void 0 ? void 0 : _b._id;
518
- const res2 = Object.assign(Object.assign({}, body), { _id, _version });
519
- return res2;
520
- });
476
+ throw e;
477
+ }));
478
+ (0, engine_1._log)(NS, `> create[${id}].res =`, engine_1.$U.json({ ...res, meta: undefined }));
479
+ const _version = engine_1.$U.N(res.body?._version, 0);
480
+ const _id = res.body?._id;
481
+ const res2 = { ...body, _id, _version };
482
+ return res2;
521
483
  }
522
484
  /**
523
485
  * push item for time-series data.
@@ -525,33 +487,30 @@ class Elastic6Service extends ElasticIndexService {
525
487
  * @param item - item to push
526
488
  * @param type - document type (default: doc-type given at construction time)
527
489
  */
528
- pushItem(item, type) {
529
- var _a, _b;
530
- return __awaiter(this, void 0, void 0, function* () {
531
- const { indexName, docType } = this.options;
532
- const id = '';
533
- type = `${type || docType}`;
534
- const body = Object.assign({}, item);
535
- const body2 = this.popullateAutocompleteFields(body);
536
- (0, engine_1._log)(NS, `- pushItem(${id})`);
537
- const params = { index: indexName, type, body: body2 };
538
- (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
539
- //NOTE - use npm `elasticsearch#13.2.0` for avoiding error.
540
- // const { client } = instance(endpoint);
541
- const client = this.client;
542
- const res = yield client.index(params).catch(
543
- // $ERROR.throwAsJson,
544
- exports.$ERROR.handler('index', e => {
545
- (0, engine_1._err)(NS, `> index[${indexName}].err =`, e instanceof Error ? e : engine_1.$U.json(e));
546
- throw e;
547
- }));
548
- // {"_index":"test-v3","_type":"_doc","_id":"rTeHiW4BPb_liACrA9qa","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":2,"_primary_term":1}
549
- (0, engine_1._log)(NS, `> create[${id}].res =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
550
- const _id = (_a = res.body) === null || _a === void 0 ? void 0 : _a._id;
551
- const _version = (_b = res.body) === null || _b === void 0 ? void 0 : _b._version;
552
- const res2 = Object.assign(Object.assign({}, body), { _id, _version });
553
- return res2;
554
- });
490
+ async pushItem(item, type) {
491
+ const { indexName, docType } = this.options;
492
+ const id = '';
493
+ type = `${type || docType}`;
494
+ const body = { ...item };
495
+ const body2 = this.popullateAutocompleteFields(body);
496
+ (0, engine_1._log)(NS, `- pushItem(${id})`);
497
+ const params = { index: indexName, type, body: body2 };
498
+ (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
499
+ //NOTE - use npm `elasticsearch#13.2.0` for avoiding error.
500
+ // const { client } = instance(endpoint);
501
+ const client = this.client;
502
+ const res = await client.index(params).catch(
503
+ // $ERROR.throwAsJson,
504
+ exports.$ERROR.handler('index', e => {
505
+ (0, engine_1._err)(NS, `> index[${indexName}].err =`, e instanceof Error ? e : engine_1.$U.json(e));
506
+ throw e;
507
+ }));
508
+ // {"_index":"test-v3","_type":"_doc","_id":"rTeHiW4BPb_liACrA9qa","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":2,"_primary_term":1}
509
+ (0, engine_1._log)(NS, `> create[${id}].res =`, engine_1.$U.json({ ...res, meta: undefined }));
510
+ const _id = res.body?._id;
511
+ const _version = res.body?._version;
512
+ const res2 = { ...body, _id, _version };
513
+ return res2;
555
514
  }
556
515
  /**
557
516
  * read item with projections
@@ -559,76 +518,70 @@ class Elastic6Service extends ElasticIndexService {
559
518
  * @param id - item-id
560
519
  * @param views - projections
561
520
  */
562
- readItem(id, views) {
563
- var _a, _b, _c;
564
- return __awaiter(this, void 0, void 0, function* () {
565
- const { indexName, docType } = this.options;
566
- const type = `${docType}`;
567
- (0, engine_1._log)(NS, `- readItem(${id})`);
568
- const params = { index: indexName, type, id };
569
- if (views) {
570
- const fields = [];
571
- const keys = Array.isArray(views) ? views : Object.keys(views);
572
- keys.forEach((k) => {
573
- fields.push(k);
574
- });
575
- params._source = fields;
576
- }
577
- (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
578
- // const { client } = instance(endpoint);
579
- const client = this.client;
580
- const res = yield client.get(params).catch(
581
- // $ERROR.throwAsJson,
582
- exports.$ERROR.handler('read', e => {
583
- const msg = (0, test_helper_1.GETERR)(e);
584
- if (msg.startsWith('404 NOT FOUND'))
585
- throw new Error(`404 NOT FOUND - id:${id}`);
586
- if (msg.startsWith('404 INDEX NOT FOUND'))
587
- throw new Error(`404 NOT FOUND - index:${indexName}`);
588
- throw e;
589
- }));
590
- (0, engine_1._log)(NS, `> read[${id}].res =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
591
- const _id = (_a = res.body) === null || _a === void 0 ? void 0 : _a._id;
592
- const _version = (_b = res.body) === null || _b === void 0 ? void 0 : _b._version;
593
- const data = (res === null || res === void 0 ? void 0 : res._source) || ((_c = res.body) === null || _c === void 0 ? void 0 : _c._source) || {};
594
- // delete internal (analyzed) field
595
- delete data[Elastic6Service.DECOMPOSED_FIELD];
596
- delete data[Elastic6Service.QWERTY_FIELD];
597
- const res2 = Object.assign(Object.assign({}, data), { _id, _version });
598
- return res2;
599
- });
521
+ async readItem(id, views) {
522
+ const { indexName, docType } = this.options;
523
+ const type = `${docType}`;
524
+ (0, engine_1._log)(NS, `- readItem(${id})`);
525
+ const params = { index: indexName, type, id };
526
+ if (views) {
527
+ const fields = [];
528
+ const keys = Array.isArray(views) ? views : Object.keys(views);
529
+ keys.forEach((k) => {
530
+ fields.push(k);
531
+ });
532
+ params._source = fields;
533
+ }
534
+ (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
535
+ // const { client } = instance(endpoint);
536
+ const client = this.client;
537
+ const res = await client.get(params).catch(
538
+ // $ERROR.throwAsJson,
539
+ exports.$ERROR.handler('read', e => {
540
+ const msg = (0, test_helper_1.GETERR)(e);
541
+ if (msg.startsWith('404 NOT FOUND'))
542
+ throw new Error(`404 NOT FOUND - id:${id}`);
543
+ if (msg.startsWith('404 INDEX NOT FOUND'))
544
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
545
+ throw e;
546
+ }));
547
+ (0, engine_1._log)(NS, `> read[${id}].res =`, engine_1.$U.json({ ...res, meta: undefined }));
548
+ const _id = res.body?._id;
549
+ const _version = res.body?._version;
550
+ const data = res?._source || res.body?._source || {};
551
+ // delete internal (analyzed) field
552
+ delete data[Elastic6Service.DECOMPOSED_FIELD];
553
+ delete data[Elastic6Service.QWERTY_FIELD];
554
+ const res2 = { ...data, _id, _version };
555
+ return res2;
600
556
  }
601
557
  /**
602
558
  * delete item with projections
603
559
  *
604
560
  * @param id - item-id
605
561
  */
606
- deleteItem(id) {
607
- var _a, _b, _c, _d;
608
- return __awaiter(this, void 0, void 0, function* () {
609
- const { indexName, docType } = this.options;
610
- const type = `${docType}`;
611
- (0, engine_1._log)(NS, `- readItem(${id})`);
612
- const params = { index: indexName, type, id };
613
- (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
614
- // const { client } = instance(endpoint);
615
- const client = this.client;
616
- const res = yield client.delete(params).catch(exports.$ERROR.handler('read', e => {
617
- const msg = (0, test_helper_1.GETERR)(e);
618
- if (msg.startsWith('404 NOT FOUND'))
619
- throw new Error(`404 NOT FOUND - id:${id}`);
620
- if (msg.startsWith('404 INDEX NOT FOUND'))
621
- throw new Error(`404 NOT FOUND - index:${indexName}`);
622
- throw e;
623
- }));
624
- // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":3,"result":"deleted","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":4,"_primary_term":1}
625
- (0, engine_1._log)(NS, `> delete[${id}].res =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
626
- const _id = (_a = res.body) === null || _a === void 0 ? void 0 : _a._id;
627
- const _version = (_b = res.body) === null || _b === void 0 ? void 0 : _b._version;
628
- const data = ((_c = res.body) === null || _c === void 0 ? void 0 : _c._source) || ((_d = res.body) === null || _d === void 0 ? void 0 : _d._source) || {};
629
- const res2 = Object.assign(Object.assign({}, data), { _id, _version });
630
- return res2;
631
- });
562
+ async deleteItem(id) {
563
+ const { indexName, docType } = this.options;
564
+ const type = `${docType}`;
565
+ (0, engine_1._log)(NS, `- readItem(${id})`);
566
+ const params = { index: indexName, type, id };
567
+ (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
568
+ // const { client } = instance(endpoint);
569
+ const client = this.client;
570
+ const res = await client.delete(params).catch(exports.$ERROR.handler('read', e => {
571
+ const msg = (0, test_helper_1.GETERR)(e);
572
+ if (msg.startsWith('404 NOT FOUND'))
573
+ throw new Error(`404 NOT FOUND - id:${id}`);
574
+ if (msg.startsWith('404 INDEX NOT FOUND'))
575
+ throw new Error(`404 NOT FOUND - index:${indexName}`);
576
+ throw e;
577
+ }));
578
+ // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":3,"result":"deleted","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":4,"_primary_term":1}
579
+ (0, engine_1._log)(NS, `> delete[${id}].res =`, engine_1.$U.json({ ...res, meta: undefined }));
580
+ const _id = res.body?._id;
581
+ const _version = res.body?._version;
582
+ const data = res.body?._source || res.body?._source || {};
583
+ const res2 = { ...data, _id, _version };
584
+ return res2;
632
585
  }
633
586
  /**
634
587
  * update item (throw if not exist)
@@ -643,122 +596,118 @@ class Elastic6Service extends ElasticIndexService {
643
596
  * @param increments - item to increase
644
597
  * @param options - (optional) request option of client.
645
598
  */
646
- updateItem(id, item, increments, options) {
647
- return __awaiter(this, void 0, void 0, function* () {
648
- const { indexName, docType, idName } = this.options;
649
- const type = `${docType}`;
650
- (0, engine_1._log)(NS, `- updateItem(${id})`);
651
- item = !item && increments ? undefined : item;
652
- //* prepare params.
653
- const params = { index: indexName, id, body: {} };
654
- // check version to include 'type' in params
655
- if (this.isOldES6) {
656
- params.type = type;
657
- }
658
- const scripts = [];
659
- if (increments) {
660
- //* it will create if not exists.
661
- params.body.upsert = Object.assign(Object.assign({}, increments), { [idName]: id });
662
- Object.entries(increments).forEach(([key, val]) => {
663
- if (Array.isArray(val)) {
664
- // If the value is an array, append it to the existing array in the source
665
- scripts.push(`if (ctx._source['${key}'] != null && ctx._source['${key}'] instanceof List) {
599
+ async updateItem(id, item, increments, options) {
600
+ const { indexName, docType, idName } = this.options;
601
+ const type = `${docType}`;
602
+ (0, engine_1._log)(NS, `- updateItem(${id})`);
603
+ item = !item && increments ? undefined : item;
604
+ //* prepare params.
605
+ const params = { index: indexName, id, body: {} };
606
+ // check version to include 'type' in params
607
+ if (this.isOldES6) {
608
+ params.type = type;
609
+ }
610
+ const scripts = [];
611
+ if (increments) {
612
+ //* it will create if not exists.
613
+ params.body.upsert = { ...increments, [idName]: id };
614
+ Object.entries(increments).forEach(([key, val]) => {
615
+ if (Array.isArray(val)) {
616
+ // If the value is an array, append it to the existing array in the source
617
+ scripts.push(`if (ctx._source['${key}'] != null && ctx._source['${key}'] instanceof List) {
666
618
  ctx._source['${key}'].addAll(params.increments['${key}']);
667
619
  } else {
668
620
  ctx._source['${key}'] = params.increments['${key}'];
669
621
  }`);
670
- }
671
- else {
672
- // If the value is a number, increment the existing field
673
- scripts.push(`if (ctx._source['${key}'] != null) {
622
+ }
623
+ else {
624
+ // If the value is a number, increment the existing field
625
+ scripts.push(`if (ctx._source['${key}'] != null) {
674
626
  ctx._source['${key}'] += params.increments['${key}'];
675
627
  } else {
676
628
  ctx._source['${key}'] = params.increments['${key}'];
677
629
  }`);
678
- }
679
- });
680
- }
681
- if (item) {
682
- // Handle item updates in the script
683
- Object.entries(item).forEach(([key]) => {
684
- scripts.push(`ctx._source['${key}'] = params.item['${key}'];`);
685
- });
686
- }
687
- params.body.script = {
688
- source: scripts.join(' '),
689
- lang: 'painless',
690
- params: { item, increments },
691
- };
692
- (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
693
- // const { client } = instance(endpoint);
694
- const client = this.client;
695
- const res = yield client.update(params, options).catch(exports.$ERROR.handler('update', (e, E) => {
696
- const msg = (0, test_helper_1.GETERR)(e);
697
- //* id 아이템이 없을 경우 발생함.
698
- if (msg.startsWith('404 DOCUMENT MISSING'))
699
- throw new Error(`404 NOT FOUND - id:${id}`);
700
- //* 해당 속성이 없을때 업데이트 하려면 생길 수 있음.
701
- if (msg.startsWith('400 REMOTE TRANSPORT'))
702
- throw new Error(`400 INVALID FIELD - id:${id}`);
703
- if (msg.startsWith('404 NOT FOUND'))
704
- throw new Error(`404 NOT FOUND - id:${id}`);
705
- if (msg.startsWith('400 ACTION REQUEST VALIDATION'))
706
- throw e;
707
- if (msg.startsWith('400 INVALID FIELD'))
708
- throw e; // at ES6.8
709
- if (msg.startsWith('400 MAPPER PARSING'))
710
- throw e;
711
- if (msg.startsWith('400 ILLEGAL ARGUMENT - Cannot apply') ||
712
- msg.startsWith('400 ILLEGAL ARGUMENT - class_cast_exception:'))
713
- throw new Error(`400 ILLEGAL ARGUMENT - failed to update due to type mismatch in item's field`); // at ES7.1
714
- if (msg.startsWith('400 ILLEGAL ARGUMENT'))
715
- throw e; // at ES7.1
716
- throw E;
717
- }));
718
- // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":8,"_primary_term":1}
719
- // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":2,"result":"noop","_shards":{"total":0,"successful":0,"failed":0}}
720
- (0, engine_1._log)(NS, `> update[${id}].res =`, engine_1.$U.json(Object.assign(Object.assign({}, res), { meta: undefined })));
721
- const _id = res.body._id;
722
- const _version = res.body._version;
723
- const res2 = Object.assign(Object.assign({}, item), { _id, _version });
724
- return res2;
725
- });
630
+ }
631
+ });
632
+ }
633
+ if (item) {
634
+ // Handle item updates in the script
635
+ Object.entries(item).forEach(([key]) => {
636
+ scripts.push(`ctx._source['${key}'] = params.item['${key}'];`);
637
+ });
638
+ }
639
+ params.body.script = {
640
+ source: scripts.join(' '),
641
+ lang: 'painless',
642
+ params: { item, increments },
643
+ };
644
+ (0, engine_1._log)(NS, `> params[${id}] =`, engine_1.$U.json(params));
645
+ // const { client } = instance(endpoint);
646
+ const client = this.client;
647
+ const res = await client.update(params, options).catch(exports.$ERROR.handler('update', (e, E) => {
648
+ const msg = (0, test_helper_1.GETERR)(e);
649
+ //* id 아이템이 없을 경우 발생함.
650
+ if (msg.startsWith('404 DOCUMENT MISSING'))
651
+ throw new Error(`404 NOT FOUND - id:${id}`);
652
+ //* 해당 속성이 없을때 업데이트 하려면 생길 수 있음.
653
+ if (msg.startsWith('400 REMOTE TRANSPORT'))
654
+ throw new Error(`400 INVALID FIELD - id:${id}`);
655
+ if (msg.startsWith('404 NOT FOUND'))
656
+ throw new Error(`404 NOT FOUND - id:${id}`);
657
+ if (msg.startsWith('400 ACTION REQUEST VALIDATION'))
658
+ throw e;
659
+ if (msg.startsWith('400 INVALID FIELD'))
660
+ throw e; // at ES6.8
661
+ if (msg.startsWith('400 MAPPER PARSING'))
662
+ throw e;
663
+ if (msg.startsWith('400 ILLEGAL ARGUMENT - Cannot apply') ||
664
+ msg.startsWith('400 ILLEGAL ARGUMENT - class_cast_exception:'))
665
+ throw new Error(`400 ILLEGAL ARGUMENT - failed to update due to type mismatch in item's field`); // at ES7.1
666
+ if (msg.startsWith('400 ILLEGAL ARGUMENT'))
667
+ throw e; // at ES7.1
668
+ throw E;
669
+ }));
670
+ // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":2,"result":"updated","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":8,"_primary_term":1}
671
+ // {"_index":"test-v3","_type":"_doc","_id":"aaa","_version":2,"result":"noop","_shards":{"total":0,"successful":0,"failed":0}}
672
+ (0, engine_1._log)(NS, `> update[${id}].res =`, engine_1.$U.json({ ...res, meta: undefined }));
673
+ const _id = res.body._id;
674
+ const _version = res.body._version;
675
+ const res2 = { ...item, _id, _version };
676
+ return res2;
726
677
  }
727
678
  /**
728
679
  * run search and get the raw response.
729
680
  * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
730
681
  * @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
731
682
  */
732
- searchRaw(body, searchType) {
733
- return __awaiter(this, void 0, void 0, function* () {
734
- if (!body)
735
- throw new Error('@body (SearchBody) is required');
736
- const { indexName, docType } = this.options;
737
- (0, engine_1._log)(NS, `- search(${indexName}, ${searchType || ''})....`);
738
- (0, engine_1._log)(NS, `> body =`, engine_1.$U.json(body));
739
- const tmp = docType ? docType : '';
740
- const type = docType ? `${docType}` : undefined;
741
- const params = { index: indexName, body, searchType };
742
- // check version to include 'type' in params
743
- if (this.isOldES6) {
744
- params.type = type;
745
- }
746
- (0, engine_1._log)(NS, `> params[${tmp}] =`, engine_1.$U.json(Object.assign(Object.assign({}, params), { body: undefined })));
747
- // const { client } = instance(endpoint);
748
- const client = this.client;
749
- const $res = yield client.search(params).catch(exports.$ERROR.handler('search', e => {
750
- (0, engine_1._err)(NS, `> search[${indexName}].err =`, e);
751
- throw e;
752
- }));
753
- // {"took":6,"timed_out":false,"_shards":{"total":4,"successful":4,"skipped":0,"failed":0},"hits":{"total":1,"max_score":0.2876821,"hits":[{"_index":"test-v3","_type":"_doc","_id":"aaa","_score":0.2876821,"_source":{"name":"AAA","@id":"aaa","a":-3,"b":-2}}]}}
754
- // _log(NS, `> search[${id}].res =`, $U.json({ ...res, meta: undefined }));
755
- // _log(NS, `> search[${tmp}].took =`, $res.took);
756
- // _log(NS, `> search[${tmp}].hits.total =`, $res.hits?.total);
757
- // _log(NS, `> search[${tmp}].hits.max_score =`, $res.hits?.max_score);
758
- // _log(NS, `> search[${tmp}].hits.hits[0] =`, $res.hits && $U.json($res.hits.hits[0]));
759
- //* return raw results.
760
- return $res === null || $res === void 0 ? void 0 : $res.body;
761
- });
683
+ async searchRaw(body, searchType) {
684
+ if (!body)
685
+ throw new Error('@body (SearchBody) is required');
686
+ const { indexName, docType } = this.options;
687
+ (0, engine_1._log)(NS, `- search(${indexName}, ${searchType || ''})....`);
688
+ (0, engine_1._log)(NS, `> body =`, engine_1.$U.json(body));
689
+ const tmp = docType ? docType : '';
690
+ const type = docType ? `${docType}` : undefined;
691
+ const params = { index: indexName, body, searchType };
692
+ // check version to include 'type' in params
693
+ if (this.isOldES6) {
694
+ params.type = type;
695
+ }
696
+ (0, engine_1._log)(NS, `> params[${tmp}] =`, engine_1.$U.json({ ...params, body: undefined }));
697
+ // const { client } = instance(endpoint);
698
+ const client = this.client;
699
+ const $res = await client.search(params).catch(exports.$ERROR.handler('search', e => {
700
+ (0, engine_1._err)(NS, `> search[${indexName}].err =`, e);
701
+ throw e;
702
+ }));
703
+ // {"took":6,"timed_out":false,"_shards":{"total":4,"successful":4,"skipped":0,"failed":0},"hits":{"total":1,"max_score":0.2876821,"hits":[{"_index":"test-v3","_type":"_doc","_id":"aaa","_score":0.2876821,"_source":{"name":"AAA","@id":"aaa","a":-3,"b":-2}}]}}
704
+ // _log(NS, `> search[${id}].res =`, $U.json({ ...res, meta: undefined }));
705
+ // _log(NS, `> search[${tmp}].took =`, $res.took);
706
+ // _log(NS, `> search[${tmp}].hits.total =`, $res.hits?.total);
707
+ // _log(NS, `> search[${tmp}].hits.max_score =`, $res.hits?.max_score);
708
+ // _log(NS, `> search[${tmp}].hits.hits[0] =`, $res.hits && $U.json($res.hits.hits[0]));
709
+ //* return raw results.
710
+ return $res?.body;
762
711
  }
763
712
  /**
764
713
  * run search, and get the formatmted response.
@@ -766,48 +715,36 @@ class Elastic6Service extends ElasticIndexService {
766
715
  * @param searchType - type of search (e.g., 'query_then_fetch', 'dfs_query_then_fetch').
767
716
  *
768
717
  */
769
- search(body, searchType) {
770
- var _a, _b, _c;
771
- return __awaiter(this, void 0, void 0, function* () {
772
- const size = engine_1.$U.N(body.size, 0);
773
- const response = yield this.searchRaw(body, searchType);
774
- // return w/ transformed id
775
- const hits = response.hits;
776
- if (typeof hits !== 'object')
777
- throw new Error(`.hits (object) is required - hits:${engine_1.$U.json(hits)}`);
778
- //NOTE - ES6.8 w/ OS1.1
779
- return {
780
- total: typeof ((_a = hits.total) === null || _a === void 0 ? void 0 : _a.value) === 'number' ? (_b = hits.total) === null || _b === void 0 ? void 0 : _b.value : hits.total,
781
- list: hits.hits.map((hit) => (Object.assign(Object.assign({}, hit._source), { _id: hit._id, _score: hit._score }))),
782
- last: hits.hits.length === size && size > 0 ? (_c = hits.hits[size - 1]) === null || _c === void 0 ? void 0 : _c.sort : undefined,
783
- aggregations: response.aggregations,
784
- };
785
- });
718
+ async search(body, searchType) {
719
+ const size = engine_1.$U.N(body.size, 0);
720
+ const response = await this.searchRaw(body, searchType);
721
+ // return w/ transformed id
722
+ const hits = response.hits;
723
+ if (typeof hits !== 'object')
724
+ throw new Error(`.hits (object) is required - hits:${engine_1.$U.json(hits)}`);
725
+ //NOTE - ES6.8 w/ OS1.1
726
+ return {
727
+ total: typeof hits.total?.value === 'number' ? hits.total?.value : hits.total,
728
+ list: hits.hits.map((hit) => ({
729
+ ...hit._source,
730
+ _id: hit._id,
731
+ _score: hit._score,
732
+ })),
733
+ last: hits.hits.length === size && size > 0 ? hits.hits[size - 1]?.sort : undefined,
734
+ aggregations: response.aggregations,
735
+ };
786
736
  }
787
737
  /**
788
738
  * search all until limit (-1 means no-limit)
789
739
  * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
790
740
  * @param params - parameters including search type, limit, and retry options.
791
741
  */
792
- searchAll(body, params) {
793
- var e_1, _a;
794
- return __awaiter(this, void 0, void 0, function* () {
795
- const list = [];
796
- try {
797
- for (var _b = __asyncValues(this.generateSearchResult(body, params)), _c; _c = yield _b.next(), !_c.done;) {
798
- const chunk = _c.value;
799
- chunk.forEach((N) => list.push(N));
800
- }
801
- }
802
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
803
- finally {
804
- try {
805
- if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
806
- }
807
- finally { if (e_1) throw e_1.error; }
808
- }
809
- return list;
810
- });
742
+ async searchAll(body, params) {
743
+ const list = [];
744
+ for await (const chunk of this.generateSearchResult(body, params)) {
745
+ chunk.forEach((N) => list.push(N));
746
+ }
747
+ return list;
811
748
  }
812
749
  /**
813
750
  * create async generator that yields items queried until last
@@ -815,38 +752,35 @@ class Elastic6Service extends ElasticIndexService {
815
752
  * @param body - Elasticsearch Query DSL that defines the search request (e.g., size, query, filters).
816
753
  * @param params - parameters including search type, limit, and retry options.
817
754
  */
818
- generateSearchResult(body, params) {
819
- var _a, _b, _c, _d, _e, _f, _g;
820
- return __asyncGenerator(this, arguments, function* generateSearchResult_1() {
821
- const doRetry = (_b = (_a = params === null || params === void 0 ? void 0 : params.retryOptions) === null || _a === void 0 ? void 0 : _a.do) !== null && _b !== void 0 ? _b : false;
822
- const t = (_d = (_c = params === null || params === void 0 ? void 0 : params.retryOptions) === null || _c === void 0 ? void 0 : _c.t) !== null && _d !== void 0 ? _d : 5000;
823
- const maxRetries = (_f = (_e = params === null || params === void 0 ? void 0 : params.retryOptions) === null || _e === void 0 ? void 0 : _e.maxRetries) !== null && _f !== void 0 ? _f : 3;
824
- let limit = (_g = params === null || params === void 0 ? void 0 : params.limit) !== null && _g !== void 0 ? _g : -1;
825
- let retryCount = 0;
826
- if (!body.sort)
827
- body.sort = '_doc';
828
- do {
829
- try {
830
- const { list, last } = yield __await(this.search(body, params === null || params === void 0 ? void 0 : params.searchType));
831
- body.search_after = last;
832
- if (list.length === 0 && !body.search_after) {
833
- break;
834
- }
835
- yield yield __await(list);
755
+ async *generateSearchResult(body, params) {
756
+ const doRetry = params?.retryOptions?.do ?? false;
757
+ const t = params?.retryOptions?.t ?? 5000;
758
+ const maxRetries = params?.retryOptions?.maxRetries ?? 3;
759
+ let limit = params?.limit ?? -1;
760
+ let retryCount = 0;
761
+ if (!body.sort)
762
+ body.sort = '_doc';
763
+ do {
764
+ try {
765
+ const { list, last } = await this.search(body, params?.searchType);
766
+ body.search_after = last;
767
+ if (list.length === 0 && !body.search_after) {
768
+ break;
836
769
  }
837
- catch (e) {
838
- const msg = (0, test_helper_1.GETERR)(e);
839
- if (doRetry && msg.startsWith('429 UNKNOWN') && retryCount < maxRetries) {
840
- retryCount++;
841
- yield __await((0, test_helper_1.waited)(t));
842
- continue;
843
- }
844
- else {
845
- throw e;
846
- }
770
+ yield list;
771
+ }
772
+ catch (e) {
773
+ const msg = (0, test_helper_1.GETERR)(e);
774
+ if (doRetry && msg.startsWith('429 UNKNOWN') && retryCount < maxRetries) {
775
+ retryCount++;
776
+ await (0, test_helper_1.waited)(t);
777
+ continue;
847
778
  }
848
- } while (body.search_after && (limit === -1 || --limit > 0));
849
- });
779
+ else {
780
+ throw e;
781
+ }
782
+ }
783
+ } while (body.search_after && (limit === -1 || --limit > 0));
850
784
  }
851
785
  /**
852
786
  * prepare default setting
@@ -954,9 +888,9 @@ class Elastic6Service extends ElasticIndexService {
954
888
  tokenizer: {
955
889
  hangul: {
956
890
  type: 'seunjeon_tokenizer',
957
- decompound: true,
958
- deinflect: true,
959
- index_eojeol: true,
891
+ decompound: true, // 복합명사 분해
892
+ deinflect: true, // 활용어의 원형 추출
893
+ index_eojeol: true, // 어절 추출
960
894
  pos_tagging: false, // 품사 태깅
961
895
  },
962
896
  edge_30grams: {
@@ -1038,13 +972,10 @@ class Elastic6Service extends ElasticIndexService {
1038
972
  }
1039
973
  }
1040
974
  return N;
1041
- }, Object.assign(Object.assign({}, body), { [Elastic6Service.DECOMPOSED_FIELD]: {}, [Elastic6Service.QWERTY_FIELD]: {} }));
975
+ }, { ...body, [Elastic6Service.DECOMPOSED_FIELD]: {}, [Elastic6Service.QWERTY_FIELD]: {} });
1042
976
  }
1043
977
  }
1044
978
  exports.Elastic6Service = Elastic6Service;
1045
- // internal field name to store analyzed strings for autocomplete search
1046
- Elastic6Service.DECOMPOSED_FIELD = '_decomposed';
1047
- Elastic6Service.QWERTY_FIELD = '_qwerty';
1048
979
  /**
1049
980
  * error samples
1050
981
  */
@@ -1055,7 +986,7 @@ exports.$ERROR = {
1055
986
  const err = e;
1056
987
  const meta = err.meta && typeof err.meta === 'object' ? err.meta : undefined;
1057
988
  const $err = _pack(err);
1058
- return Object.assign(Object.assign({}, $err), { meta });
989
+ return { ...$err, meta };
1059
990
  }
1060
991
  return e;
1061
992
  },
@@ -1100,16 +1031,15 @@ exports.$ERROR = {
1100
1031
  const status = `${E.statusCode || ''}`;
1101
1032
  const message = `${E.message || E.msg || ''}`;
1102
1033
  const reason = ((E) => {
1103
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1104
1034
  //* from ES7.1
1105
1035
  if (E.meta && typeof E.meta == 'object') {
1106
- const type = _S(E === null || E === void 0 ? void 0 : E.message).toUpperCase().split('_').slice(0, -1).join(' ');
1107
- const status = engine_1.$U.N((_a = E.meta) === null || _a === void 0 ? void 0 : _a.statusCode, type.includes('NOT FOUND') ? 404 : 400);
1036
+ const type = _S(E?.message).toUpperCase().split('_').slice(0, -1).join(' ');
1037
+ const status = engine_1.$U.N(E.meta?.statusCode, type.includes('NOT FOUND') ? 404 : 400);
1108
1038
  const $res = exports.$ERROR.parseMeta(E.meta);
1109
1039
  //* find the reason.
1110
- const reason = ((_c = (_b = $res.body) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.reason) === 'failed to execute script'
1111
- ? (_g = (_f = (_e = (_d = $res.body) === null || _d === void 0 ? void 0 : _d.error) === null || _e === void 0 ? void 0 : _e.caused_by) === null || _f === void 0 ? void 0 : _f.caused_by) === null || _g === void 0 ? void 0 : _g.reason
1112
- : (_j = (_h = $res.body) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j.reason;
1040
+ const reason = $res.body?.error?.reason === 'failed to execute script'
1041
+ ? $res.body?.error?.caused_by?.caused_by?.reason
1042
+ : $res.body?.error?.reason;
1113
1043
  const result = { status, type: type || (status === 404 ? 'NOT FOUND' : 'UNKNOWN') };
1114
1044
  if (typeof reason !== 'undefined') {
1115
1045
  result.reason = reason;
@@ -1122,29 +1052,28 @@ exports.$ERROR = {
1122
1052
  const $res = exports.$ERROR.parseMeta(E.response);
1123
1053
  //* find the root-cause.
1124
1054
  const pic1 = (N, i = 0) => (N && Array.isArray(N) ? N[i] : N);
1125
- const cause = pic1((_k = $res === null || $res === void 0 ? void 0 : $res.error) === null || _k === void 0 ? void 0 : _k.root_cause);
1126
- const status = engine_1.$U.N(((_l = $res.error) === null || _l === void 0 ? void 0 : _l.status) || $res.status);
1127
- const reason = _S((_m = $res.error) === null || _m === void 0 ? void 0 : _m.reason, $res.found === false || $res.result === 'not_found' ? 'NOT FOUND' : '');
1128
- const type = _S(cause === null || cause === void 0 ? void 0 : cause.type).toUpperCase().split('_').slice(0, -1).join(' ');
1055
+ const cause = pic1($res?.error?.root_cause);
1056
+ const status = engine_1.$U.N($res.error?.status || $res.status);
1057
+ const reason = _S($res.error?.reason, $res.found === false || $res.result === 'not_found' ? 'NOT FOUND' : '');
1058
+ const type = _S(cause?.type).toUpperCase().split('_').slice(0, -1).join(' ');
1129
1059
  return { status, reason, cause, type: type || reason };
1130
1060
  })(E);
1131
1061
  //* FINAL. convert to error-object.
1132
1062
  return {
1133
- status: engine_1.$U.N(status, (reason === null || reason === void 0 ? void 0 : reason.status) || 0),
1134
- message: message || (reason === null || reason === void 0 ? void 0 : reason.reason),
1063
+ status: engine_1.$U.N(status, reason?.status || 0),
1064
+ message: message || reason?.reason,
1135
1065
  reason,
1136
1066
  };
1137
1067
  },
1138
1068
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1139
1069
  handler: (name, cb) => (e) => {
1140
- var _a, _b, _c, _d, _e;
1141
1070
  const E = exports.$ERROR.asError(e);
1142
1071
  //* unknown error found..
1143
- if (!(E === null || E === void 0 ? void 0 : E.status)) {
1072
+ if (!E?.status) {
1144
1073
  (0, engine_1._err)(NS, `! err[${name}]@handler =`, e instanceof Error, engine_1.$U.json(e));
1145
1074
  throw e;
1146
1075
  }
1147
- const $e = new Error(`${E.status} ${(_b = (_a = E.reason) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : ''} - ${(_e = (_d = (_c = E.reason) === null || _c === void 0 ? void 0 : _c.reason) !== null && _d !== void 0 ? _d : E.message) !== null && _e !== void 0 ? _e : ''}`);
1076
+ const $e = new Error(`${E.status} ${E.reason?.type ?? ''} - ${E.reason?.reason ?? E.message ?? ''}`);
1148
1077
  if (cb)
1149
1078
  return cb($e, E);
1150
1079
  throw $e;
@@ -1160,17 +1089,13 @@ exports.$ERROR = {
1160
1089
  class DummyElastic6Service extends Elastic6Service {
1161
1090
  constructor(dataFile, options) {
1162
1091
  super(options);
1163
- this.buffer = {};
1164
- /**
1165
- * say hello()
1166
- */
1167
- this.hello = () => `dummy-elastic6-service:${this.options.indexName}`;
1168
1092
  (0, engine_1._log)(NS, `DummyElastic6Service(${dataFile || ''})...`);
1169
1093
  if (!dataFile)
1170
1094
  throw new Error('@dataFile(string) is required!');
1171
1095
  const dummy = (0, tools_1.loadDataYml)(dataFile);
1172
1096
  this.load(dummy.data);
1173
1097
  }
1098
+ buffer = {};
1174
1099
  load(data) {
1175
1100
  const { idName } = this.options;
1176
1101
  if (!data || !Array.isArray(data))
@@ -1180,56 +1105,52 @@ class DummyElastic6Service extends Elastic6Service {
1180
1105
  this.buffer[id] = item;
1181
1106
  });
1182
1107
  }
1183
- readItem(id) {
1184
- return __awaiter(this, void 0, void 0, function* () {
1185
- const item = this.buffer[id];
1186
- if (item === undefined)
1187
- throw new Error(`404 NOT FOUND - id:${id}`);
1188
- return item;
1189
- });
1108
+ /**
1109
+ * say hello()
1110
+ */
1111
+ hello = () => `dummy-elastic6-service:${this.options.indexName}`;
1112
+ async readItem(id) {
1113
+ const item = this.buffer[id];
1114
+ if (item === undefined)
1115
+ throw new Error(`404 NOT FOUND - id:${id}`);
1116
+ return item;
1190
1117
  }
1191
- saveItem(id, item) {
1192
- return __awaiter(this, void 0, void 0, function* () {
1193
- const { idName } = this.options;
1194
- this.buffer[id] = Object.assign({ id }, item);
1195
- return Object.assign(Object.assign({ [idName]: id }, item), { _version: 1 });
1196
- });
1118
+ async saveItem(id, item) {
1119
+ const { idName } = this.options;
1120
+ this.buffer[id] = { id, ...item };
1121
+ return { [idName]: id, ...item, _version: 1 };
1197
1122
  }
1198
- deleteItem(id, sort) {
1199
- return __awaiter(this, void 0, void 0, function* () {
1200
- const org = this.buffer[id];
1201
- delete this.buffer[id];
1202
- return Object.assign({}, org);
1203
- });
1123
+ async deleteItem(id, sort) {
1124
+ const org = this.buffer[id];
1125
+ delete this.buffer[id];
1126
+ return { ...org };
1204
1127
  }
1205
- updateItem(id, updates, increments) {
1206
- return __awaiter(this, void 0, void 0, function* () {
1207
- const org = yield this.readItem(id);
1208
- const item = Object.assign(Object.assign(Object.assign({}, org), updates), { _version: Number(org._version || 0) + 1 });
1209
- if (increments) {
1210
- Object.entries(increments).forEach(([key, value]) => {
1211
- if (Array.isArray(value)) {
1212
- // case of arrary increment
1213
- if (Array.isArray(item[key])) {
1214
- item[key] = [...item[key], ...value];
1215
- }
1216
- else {
1217
- item[key] = value;
1218
- }
1128
+ async updateItem(id, updates, increments) {
1129
+ const org = await this.readItem(id);
1130
+ const item = { ...org, ...updates, _version: Number(org._version || 0) + 1 };
1131
+ if (increments) {
1132
+ Object.entries(increments).forEach(([key, value]) => {
1133
+ if (Array.isArray(value)) {
1134
+ // case of arrary increment
1135
+ if (Array.isArray(item[key])) {
1136
+ item[key] = [...item[key], ...value];
1219
1137
  }
1220
1138
  else {
1221
- if (typeof item[key] === 'number') {
1222
- item[key] = item[key] + value;
1223
- }
1224
- else {
1225
- item[key] = value;
1226
- }
1139
+ item[key] = value;
1227
1140
  }
1228
- });
1229
- }
1230
- this.buffer[id] = item;
1231
- return Object.assign({ id: id, _version: Number(org._version || 0) + 1 }, updates);
1232
- });
1141
+ }
1142
+ else {
1143
+ if (typeof item[key] === 'number') {
1144
+ item[key] = item[key] + value;
1145
+ }
1146
+ else {
1147
+ item[key] = value;
1148
+ }
1149
+ }
1150
+ });
1151
+ }
1152
+ this.buffer[id] = item;
1153
+ return { id: id, _version: Number(org._version || 0) + 1, ...updates };
1233
1154
  }
1234
1155
  }
1235
1156
  exports.DummyElastic6Service = DummyElastic6Service;