@infrab4a/connect 4.9.0-beta.1 → 4.9.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +62 -20
- package/index.esm.js +62 -20
- package/package.json +1 -1
- package/src/infra/elasticsearch/adapters/axios.adapter.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -2500,28 +2500,34 @@ class DuplicatedResultsError extends tsCustomError.CustomError {
|
|
|
2500
2500
|
class AxiosAdapter {
|
|
2501
2501
|
constructor(config) {
|
|
2502
2502
|
this.config = config;
|
|
2503
|
+
this.logger = DebugHelper.from(this);
|
|
2503
2504
|
}
|
|
2504
2505
|
async get(index, id) {
|
|
2506
|
+
const logger = this.logger.with('get');
|
|
2507
|
+
const req = {
|
|
2508
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
2509
|
+
method: 'GET',
|
|
2510
|
+
responseType: 'json',
|
|
2511
|
+
headers: {
|
|
2512
|
+
'Content-Type': 'application/json',
|
|
2513
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
2514
|
+
},
|
|
2515
|
+
};
|
|
2505
2516
|
try {
|
|
2506
|
-
const { data } = await axios__default["default"](
|
|
2507
|
-
|
|
2508
|
-
method: 'GET',
|
|
2509
|
-
responseType: 'json',
|
|
2510
|
-
headers: {
|
|
2511
|
-
'Content-Type': 'application/json',
|
|
2512
|
-
Authorization: `ApiKey ${this.config.credential}`,
|
|
2513
|
-
},
|
|
2514
|
-
});
|
|
2517
|
+
const { data } = await axios__default["default"](req);
|
|
2518
|
+
logger.log({ req, res: data });
|
|
2515
2519
|
return data._source;
|
|
2516
2520
|
}
|
|
2517
2521
|
catch (error) {
|
|
2522
|
+
logger.error({ req, res: error });
|
|
2518
2523
|
if (!(error instanceof Error))
|
|
2519
2524
|
throw error;
|
|
2520
2525
|
throw new NotFoundError(error.message);
|
|
2521
2526
|
}
|
|
2522
2527
|
}
|
|
2523
2528
|
async query(index, query) {
|
|
2524
|
-
const
|
|
2529
|
+
const logger = this.logger.with('query');
|
|
2530
|
+
const req = {
|
|
2525
2531
|
url: `${this.config.url}/${index}/_search`,
|
|
2526
2532
|
method: 'POST',
|
|
2527
2533
|
responseType: 'json',
|
|
@@ -2531,34 +2537,70 @@ class AxiosAdapter {
|
|
|
2531
2537
|
Authorization: `ApiKey ${this.config.credential}`,
|
|
2532
2538
|
},
|
|
2533
2539
|
data: query,
|
|
2534
|
-
});
|
|
2535
|
-
return {
|
|
2536
|
-
total: data.hits.total.value,
|
|
2537
|
-
hits: data.hits.hits,
|
|
2538
2540
|
};
|
|
2541
|
+
try {
|
|
2542
|
+
const { data } = await axios__default["default"](req);
|
|
2543
|
+
const res = {
|
|
2544
|
+
total: data.hits.total.value,
|
|
2545
|
+
hits: data.hits.hits,
|
|
2546
|
+
};
|
|
2547
|
+
logger.log({ req, res });
|
|
2548
|
+
return res;
|
|
2549
|
+
}
|
|
2550
|
+
catch (error) {
|
|
2551
|
+
logger.error({ req, res: error });
|
|
2552
|
+
throw error;
|
|
2553
|
+
}
|
|
2539
2554
|
}
|
|
2540
2555
|
async save(index, data) {
|
|
2541
|
-
|
|
2556
|
+
const logger = this.logger.with('save');
|
|
2557
|
+
const req = {
|
|
2542
2558
|
url: `${this.config.url}/${index}/_doc`,
|
|
2543
2559
|
method: 'POST',
|
|
2544
2560
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2545
2561
|
data,
|
|
2546
|
-
}
|
|
2562
|
+
};
|
|
2563
|
+
try {
|
|
2564
|
+
await axios__default["default"](req);
|
|
2565
|
+
logger.log({ req, res: undefined });
|
|
2566
|
+
}
|
|
2567
|
+
catch (error) {
|
|
2568
|
+
logger.error({ req, res: error });
|
|
2569
|
+
throw error;
|
|
2570
|
+
}
|
|
2547
2571
|
}
|
|
2548
2572
|
async update(index, id, data) {
|
|
2549
|
-
|
|
2573
|
+
const logger = this.logger.with('update');
|
|
2574
|
+
const req = {
|
|
2550
2575
|
url: `${this.config.url}/${index}/_update/${id}`,
|
|
2551
2576
|
method: 'PUT',
|
|
2552
2577
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2553
2578
|
data,
|
|
2554
|
-
}
|
|
2579
|
+
};
|
|
2580
|
+
try {
|
|
2581
|
+
await axios__default["default"](req);
|
|
2582
|
+
logger.log({ req, res: undefined });
|
|
2583
|
+
}
|
|
2584
|
+
catch (error) {
|
|
2585
|
+
logger.error({ req, res: error });
|
|
2586
|
+
throw error;
|
|
2587
|
+
}
|
|
2555
2588
|
}
|
|
2556
2589
|
async delete(index, id) {
|
|
2557
|
-
|
|
2590
|
+
const logger = this.logger.with('delete');
|
|
2591
|
+
const req = {
|
|
2558
2592
|
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
2559
2593
|
method: 'DELETE',
|
|
2560
2594
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2561
|
-
}
|
|
2595
|
+
};
|
|
2596
|
+
try {
|
|
2597
|
+
await axios__default["default"](req);
|
|
2598
|
+
logger.log({ req, res: undefined });
|
|
2599
|
+
}
|
|
2600
|
+
catch (error) {
|
|
2601
|
+
logger.error({ req, res: error });
|
|
2602
|
+
throw error;
|
|
2603
|
+
}
|
|
2562
2604
|
}
|
|
2563
2605
|
}
|
|
2564
2606
|
|
package/index.esm.js
CHANGED
|
@@ -2476,28 +2476,34 @@ class DuplicatedResultsError extends CustomError {
|
|
|
2476
2476
|
class AxiosAdapter {
|
|
2477
2477
|
constructor(config) {
|
|
2478
2478
|
this.config = config;
|
|
2479
|
+
this.logger = DebugHelper.from(this);
|
|
2479
2480
|
}
|
|
2480
2481
|
async get(index, id) {
|
|
2482
|
+
const logger = this.logger.with('get');
|
|
2483
|
+
const req = {
|
|
2484
|
+
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
2485
|
+
method: 'GET',
|
|
2486
|
+
responseType: 'json',
|
|
2487
|
+
headers: {
|
|
2488
|
+
'Content-Type': 'application/json',
|
|
2489
|
+
Authorization: `ApiKey ${this.config.credential}`,
|
|
2490
|
+
},
|
|
2491
|
+
};
|
|
2481
2492
|
try {
|
|
2482
|
-
const { data } = await axios(
|
|
2483
|
-
|
|
2484
|
-
method: 'GET',
|
|
2485
|
-
responseType: 'json',
|
|
2486
|
-
headers: {
|
|
2487
|
-
'Content-Type': 'application/json',
|
|
2488
|
-
Authorization: `ApiKey ${this.config.credential}`,
|
|
2489
|
-
},
|
|
2490
|
-
});
|
|
2493
|
+
const { data } = await axios(req);
|
|
2494
|
+
logger.log({ req, res: data });
|
|
2491
2495
|
return data._source;
|
|
2492
2496
|
}
|
|
2493
2497
|
catch (error) {
|
|
2498
|
+
logger.error({ req, res: error });
|
|
2494
2499
|
if (!(error instanceof Error))
|
|
2495
2500
|
throw error;
|
|
2496
2501
|
throw new NotFoundError(error.message);
|
|
2497
2502
|
}
|
|
2498
2503
|
}
|
|
2499
2504
|
async query(index, query) {
|
|
2500
|
-
const
|
|
2505
|
+
const logger = this.logger.with('query');
|
|
2506
|
+
const req = {
|
|
2501
2507
|
url: `${this.config.url}/${index}/_search`,
|
|
2502
2508
|
method: 'POST',
|
|
2503
2509
|
responseType: 'json',
|
|
@@ -2507,34 +2513,70 @@ class AxiosAdapter {
|
|
|
2507
2513
|
Authorization: `ApiKey ${this.config.credential}`,
|
|
2508
2514
|
},
|
|
2509
2515
|
data: query,
|
|
2510
|
-
});
|
|
2511
|
-
return {
|
|
2512
|
-
total: data.hits.total.value,
|
|
2513
|
-
hits: data.hits.hits,
|
|
2514
2516
|
};
|
|
2517
|
+
try {
|
|
2518
|
+
const { data } = await axios(req);
|
|
2519
|
+
const res = {
|
|
2520
|
+
total: data.hits.total.value,
|
|
2521
|
+
hits: data.hits.hits,
|
|
2522
|
+
};
|
|
2523
|
+
logger.log({ req, res });
|
|
2524
|
+
return res;
|
|
2525
|
+
}
|
|
2526
|
+
catch (error) {
|
|
2527
|
+
logger.error({ req, res: error });
|
|
2528
|
+
throw error;
|
|
2529
|
+
}
|
|
2515
2530
|
}
|
|
2516
2531
|
async save(index, data) {
|
|
2517
|
-
|
|
2532
|
+
const logger = this.logger.with('save');
|
|
2533
|
+
const req = {
|
|
2518
2534
|
url: `${this.config.url}/${index}/_doc`,
|
|
2519
2535
|
method: 'POST',
|
|
2520
2536
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2521
2537
|
data,
|
|
2522
|
-
}
|
|
2538
|
+
};
|
|
2539
|
+
try {
|
|
2540
|
+
await axios(req);
|
|
2541
|
+
logger.log({ req, res: undefined });
|
|
2542
|
+
}
|
|
2543
|
+
catch (error) {
|
|
2544
|
+
logger.error({ req, res: error });
|
|
2545
|
+
throw error;
|
|
2546
|
+
}
|
|
2523
2547
|
}
|
|
2524
2548
|
async update(index, id, data) {
|
|
2525
|
-
|
|
2549
|
+
const logger = this.logger.with('update');
|
|
2550
|
+
const req = {
|
|
2526
2551
|
url: `${this.config.url}/${index}/_update/${id}`,
|
|
2527
2552
|
method: 'PUT',
|
|
2528
2553
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2529
2554
|
data,
|
|
2530
|
-
}
|
|
2555
|
+
};
|
|
2556
|
+
try {
|
|
2557
|
+
await axios(req);
|
|
2558
|
+
logger.log({ req, res: undefined });
|
|
2559
|
+
}
|
|
2560
|
+
catch (error) {
|
|
2561
|
+
logger.error({ req, res: error });
|
|
2562
|
+
throw error;
|
|
2563
|
+
}
|
|
2531
2564
|
}
|
|
2532
2565
|
async delete(index, id) {
|
|
2533
|
-
|
|
2566
|
+
const logger = this.logger.with('delete');
|
|
2567
|
+
const req = {
|
|
2534
2568
|
url: `${this.config.url}/${index}/_doc/${id}`,
|
|
2535
2569
|
method: 'DELETE',
|
|
2536
2570
|
headers: { Authorization: `ApiKey ${this.config.credential}` },
|
|
2537
|
-
}
|
|
2571
|
+
};
|
|
2572
|
+
try {
|
|
2573
|
+
await axios(req);
|
|
2574
|
+
logger.log({ req, res: undefined });
|
|
2575
|
+
}
|
|
2576
|
+
catch (error) {
|
|
2577
|
+
logger.error({ req, res: error });
|
|
2578
|
+
throw error;
|
|
2579
|
+
}
|
|
2538
2580
|
}
|
|
2539
2581
|
}
|
|
2540
2582
|
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ export type AxiosElasticSearchConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare class AxiosAdapter<T extends ModelBaseStructure<T>> implements ElasticSearchAdapter<T> {
|
|
9
9
|
private readonly config;
|
|
10
|
+
private logger;
|
|
10
11
|
constructor(config: AxiosElasticSearchConfig);
|
|
11
12
|
get(index: string, id: string): Promise<T>;
|
|
12
13
|
query(index: string, query: any): Promise<ElasticSearchResult<T>>;
|