@mavenmachines/event-handler-lib 1.6.0-rc.44a7c2cc4 → 1.6.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 (24) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/clients/openSearch/base.types.d.ts +1 -8
  3. package/dist/src/clients/openSearch/openSearchClient.d.ts +3 -54
  4. package/dist/src/clients/openSearch/openSearchClient.js +3 -106
  5. package/dist/src/clients/openSearch/openSearchClient.js.map +1 -1
  6. package/dist/src/clients/openSearch/types.d.ts +0 -43
  7. package/dist/src/clients/openSearch/types.js +1 -48
  8. package/dist/src/clients/openSearch/types.js.map +1 -1
  9. package/package.json +1 -1
  10. package/dist/src/clients/openSearch/aggregations.d.ts +0 -252
  11. package/dist/src/clients/openSearch/aggregations.js +0 -256
  12. package/dist/src/clients/openSearch/aggregations.js.map +0 -1
  13. package/dist/test/tests/clients/aggregation.spec.d.ts +0 -1
  14. package/dist/test/tests/clients/aggregation.spec.js +0 -74
  15. package/dist/test/tests/clients/aggregation.spec.js.map +0 -1
  16. package/dist/test/tests/clients/generateFieldQuery.spec.d.ts +0 -1
  17. package/dist/test/tests/clients/generateFieldQuery.spec.js +0 -171
  18. package/dist/test/tests/clients/generateFieldQuery.spec.js.map +0 -1
  19. package/dist/test/tests/clients/searchProjectionAggregations.query.spec.d.ts +0 -1
  20. package/dist/test/tests/clients/searchProjectionAggregations.query.spec.js +0 -652
  21. package/dist/test/tests/clients/searchProjectionAggregations.query.spec.js.map +0 -1
  22. package/dist/test/tests/clients/searchProjections.query.spec.d.ts +0 -1
  23. package/dist/test/tests/clients/searchProjections.query.spec.js +0 -249
  24. package/dist/test/tests/clients/searchProjections.query.spec.js.map +0 -1
@@ -1,652 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("reflect-metadata");
4
- const chai_1 = require("chai");
5
- const openSearchClient_1 = require("../../../src/clients/openSearch/openSearchClient");
6
- const aggregations_1 = require("../../../src/clients/openSearch/aggregations");
7
- const projectionType = "task";
8
- const alias = "task-projections";
9
- const companyId = 81;
10
- function recordingClient(response) {
11
- const searches = [];
12
- const client = {
13
- async search(request) {
14
- searches.push(request);
15
- return response;
16
- },
17
- };
18
- return { client, searches };
19
- }
20
- function openSearchFor(recorded) {
21
- const logger = {
22
- info() { },
23
- debug() { },
24
- warn() { },
25
- error() { },
26
- };
27
- const loggerService = {
28
- getLogger: () => logger,
29
- };
30
- const timer = {
31
- run: async (_action, fn) => fn(),
32
- };
33
- return new openSearchClient_1.OpenSearchClient(loggerService, recorded.client, {}, timer);
34
- }
35
- describe("searchProjectionAggregations request", () => {
36
- it("filters by company and builds one composite aggregation", async () => {
37
- const recorded = recordingClient({
38
- body: { aggregations: { customers: { buckets: [] } } },
39
- });
40
- const openSearch = openSearchFor(recorded);
41
- const result = await openSearch.searchProjectionAggregations()({
42
- companyId,
43
- projectionType,
44
- filter: aggregations_1.Aggregation.all([
45
- aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
46
- aggregations_1.Aggregation.none([aggregations_1.Aggregation.equals("payload.deliveryType", "DNS")]),
47
- ]),
48
- aggregation: {
49
- name: "customers",
50
- size: 10,
51
- sources: [
52
- {
53
- name: "customerNumber",
54
- field: "payload.customer.keyword",
55
- order: "asc",
56
- },
57
- ],
58
- },
59
- });
60
- (0, chai_1.expect)(recorded.searches).to.deep.equal([
61
- {
62
- index: alias,
63
- body: {
64
- size: 0,
65
- query: {
66
- bool: {
67
- filter: [
68
- { match: { companyId } },
69
- {
70
- bool: {
71
- filter: [
72
- { term: { "payload.status": "COMPLETED" } },
73
- {
74
- bool: {
75
- must_not: [{ term: { "payload.deliveryType": "DNS" } }],
76
- },
77
- },
78
- ],
79
- },
80
- },
81
- ],
82
- },
83
- },
84
- aggs: {
85
- customers: {
86
- composite: {
87
- size: 10,
88
- sources: [
89
- {
90
- customerNumber: {
91
- terms: { field: "payload.customer.keyword", order: "asc" },
92
- },
93
- },
94
- ],
95
- },
96
- },
97
- },
98
- },
99
- },
100
- ]);
101
- (0, chai_1.expect)(result.buckets).to.deep.equal([]);
102
- (0, chai_1.expect)(result.afterKey).to.equal(undefined);
103
- const absentKey = result.buckets[0]?.key.customerNumber;
104
- (0, chai_1.expect)(absentKey).to.equal(undefined);
105
- });
106
- it("returns buckets whose fields follow the aggregation names", async () => {
107
- const document = {
108
- companyId,
109
- projectionType,
110
- entityId: "e1",
111
- payload: { customerName: "Acme" },
112
- version: 1,
113
- referenceIds: { entityId: "e1" },
114
- };
115
- const recorded = recordingClient({
116
- body: {
117
- aggregations: {
118
- byTask: {
119
- after_key: { completedAt: 10, taskLookupId: "t2" },
120
- buckets: [
121
- {
122
- key: { completedAt: 9, taskLookupId: "t1" },
123
- full_document: { hits: { hits: [{ _source: document }] } },
124
- skus: {
125
- filtered: {
126
- values: { buckets: [{ key: "SKU-1", doc_count: 2 }] },
127
- },
128
- },
129
- },
130
- ],
131
- },
132
- },
133
- },
134
- });
135
- const openSearch = openSearchFor(recorded);
136
- const result = await openSearch.searchProjectionAggregations()({
137
- companyId,
138
- projectionType,
139
- filter: { equals: { path: "payload.status", value: "COMPLETED" } },
140
- aggregation: {
141
- name: "byTask",
142
- size: 11,
143
- after: { completedAt: 5, taskLookupId: "t0" },
144
- sources: [
145
- {
146
- name: "completedAt",
147
- field: "payload.completedAt",
148
- order: "desc",
149
- },
150
- { name: "taskLookupId", field: "payload.taskLookupId.keyword" },
151
- ],
152
- subAggregations: [
153
- { name: "full_document", type: "topHits", size: 1, source: true },
154
- {
155
- name: "skus",
156
- type: "nestedTerms",
157
- path: "payload.items",
158
- field: "payload.items.sku",
159
- size: 100,
160
- filter: { equals: { path: "payload.items.sku", value: "SKU-1" } },
161
- },
162
- ],
163
- },
164
- });
165
- (0, chai_1.expect)(recorded.searches[0].body).to.deep.equal({
166
- size: 0,
167
- query: {
168
- bool: {
169
- filter: [
170
- { match: { companyId } },
171
- { term: { "payload.status": "COMPLETED" } },
172
- ],
173
- },
174
- },
175
- aggs: {
176
- byTask: {
177
- composite: {
178
- size: 11,
179
- after: { completedAt: 5, taskLookupId: "t0" },
180
- sources: [
181
- {
182
- completedAt: {
183
- terms: { field: "payload.completedAt", order: "desc" },
184
- },
185
- },
186
- {
187
- taskLookupId: {
188
- terms: { field: "payload.taskLookupId.keyword" },
189
- },
190
- },
191
- ],
192
- },
193
- aggs: {
194
- full_document: { top_hits: { size: 1, _source: true } },
195
- skus: {
196
- nested: { path: "payload.items" },
197
- aggs: {
198
- filtered: {
199
- filter: { term: { "payload.items.sku": "SKU-1" } },
200
- aggs: {
201
- values: {
202
- terms: { field: "payload.items.sku", size: 100 },
203
- },
204
- },
205
- },
206
- },
207
- },
208
- },
209
- },
210
- },
211
- });
212
- const bucket = result.buckets[0];
213
- const completedAt = bucket.key.completedAt;
214
- const taskLookupId = bucket.key.taskLookupId;
215
- const fullDocument = bucket.full_document[0];
216
- const skuKey = bucket.skus[0].key;
217
- const skuCount = bucket.skus[0].docCount;
218
- (0, chai_1.expect)(completedAt).to.equal(9);
219
- (0, chai_1.expect)(taskLookupId).to.equal("t1");
220
- (0, chai_1.expect)(fullDocument).to.deep.equal(document);
221
- (0, chai_1.expect)(skuKey).to.equal("SKU-1");
222
- (0, chai_1.expect)(skuCount).to.equal(2);
223
- (0, chai_1.expect)(result.afterKey).to.deep.equal({ completedAt: 10, taskLookupId: "t2" });
224
- });
225
- it("requests a top_hits source list and types those hits as partial projections", async () => {
226
- const recorded = recordingClient({
227
- body: {
228
- aggregations: {
229
- customers: {
230
- buckets: [
231
- {
232
- key: { customerNumber: "C1" },
233
- customer: {
234
- hits: {
235
- hits: [{ _source: { payload: { customerName: "Acme" } } }],
236
- },
237
- },
238
- },
239
- ],
240
- },
241
- },
242
- },
243
- });
244
- const openSearch = openSearchFor(recorded);
245
- const result = await openSearch.searchProjectionAggregations()({
246
- companyId,
247
- projectionType,
248
- filter: { exists: { path: "payload.customerName" } },
249
- aggregation: {
250
- name: "customers",
251
- size: 5,
252
- sources: [{ name: "customerNumber", field: "payload.customer.keyword" }],
253
- subAggregations: [
254
- {
255
- name: "customer",
256
- type: "topHits",
257
- size: 1,
258
- source: ["payload.customerName"],
259
- },
260
- ],
261
- },
262
- });
263
- const body = recorded.searches[0].body;
264
- (0, chai_1.expect)(body.aggs.customers.aggs.customer).to.deep.equal({
265
- top_hits: { size: 1, _source: ["payload.customerName"] },
266
- });
267
- const customer = result.buckets[0].customer[0];
268
- (0, chai_1.expect)(customer.payload?.customerName).to.equal("Acme");
269
- });
270
- it("builds a composite from Aggregation helpers and omits a null after key", async () => {
271
- const document = {
272
- companyId,
273
- projectionType,
274
- entityId: "e1",
275
- payload: { customerName: "Acme" },
276
- version: 1,
277
- referenceIds: { entityId: "e1" },
278
- };
279
- const recorded = recordingClient({
280
- body: {
281
- aggregations: {
282
- by_task: {
283
- buckets: [
284
- {
285
- key: { completedAt: 9, taskLookupId: "t1" },
286
- full_document: { hits: { hits: [{ _source: document }] } },
287
- skus: {
288
- filtered: {
289
- values: { buckets: [{ key: "SKU-1", doc_count: 2 }] },
290
- },
291
- },
292
- },
293
- ],
294
- },
295
- },
296
- },
297
- });
298
- const openSearch = openSearchFor(recorded);
299
- const result = await openSearch.searchProjectionAggregations()({
300
- companyId,
301
- projectionType,
302
- filter: aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
303
- aggregation: aggregations_1.Aggregation.composite({
304
- name: "by_task",
305
- size: 11,
306
- after: null,
307
- sources: [
308
- aggregations_1.Aggregation.source({
309
- name: "completedAt",
310
- field: "payload.taskContext.completedAt",
311
- order: "desc",
312
- }),
313
- aggregations_1.Aggregation.source({
314
- name: "taskLookupId",
315
- field: "payload.taskLookupId.keyword",
316
- order: "asc",
317
- }),
318
- ],
319
- subAggregations: [
320
- aggregations_1.Aggregation.nestedTerms({
321
- name: "skus",
322
- path: "payload.taskContext.shipmentItems",
323
- field: "payload.taskContext.shipmentItems.sku",
324
- size: 100,
325
- filter: aggregations_1.Aggregation.terms("payload.taskContext.shipmentItems.sku", ["A"]),
326
- }),
327
- aggregations_1.Aggregation.topHits({ name: "full_document", size: 1 }),
328
- aggregations_1.Aggregation.topHits({
329
- name: "customer",
330
- fields: ["payload.customerName"],
331
- }),
332
- ],
333
- }),
334
- });
335
- const body = recorded.searches[0].body;
336
- (0, chai_1.expect)(body.aggs.by_task).to.deep.equal({
337
- composite: {
338
- size: 11,
339
- sources: [
340
- {
341
- completedAt: {
342
- terms: { field: "payload.taskContext.completedAt", order: "desc" },
343
- },
344
- },
345
- {
346
- taskLookupId: {
347
- terms: { field: "payload.taskLookupId.keyword", order: "asc" },
348
- },
349
- },
350
- ],
351
- },
352
- aggs: {
353
- skus: {
354
- nested: { path: "payload.taskContext.shipmentItems" },
355
- aggs: {
356
- filtered: {
357
- filter: { terms: { "payload.taskContext.shipmentItems.sku": ["A"] } },
358
- aggs: {
359
- values: {
360
- terms: { field: "payload.taskContext.shipmentItems.sku", size: 100 },
361
- },
362
- },
363
- },
364
- },
365
- },
366
- full_document: { top_hits: { size: 1 } },
367
- customer: { top_hits: { size: 1, _source: ["payload.customerName"] } },
368
- },
369
- });
370
- const completedAt = result.buckets[0].key.completedAt;
371
- const taskLookupId = result.buckets[0].key.taskLookupId;
372
- const fullDocument = result.buckets[0].full_document[0];
373
- const customer = result.buckets[0].customer[0];
374
- (0, chai_1.expect)(completedAt).to.equal(9);
375
- (0, chai_1.expect)(taskLookupId).to.equal("t1");
376
- (0, chai_1.expect)(fullDocument).to.deep.equal(document);
377
- (0, chai_1.expect)(customer).to.equal(undefined);
378
- });
379
- it("filters a top hit and still returns it under the aggregation name", async () => {
380
- const document = {
381
- companyId,
382
- projectionType,
383
- entityId: "e1",
384
- payload: { taskContext: { customerName: "Acme" } },
385
- version: 1,
386
- referenceIds: { entityId: "e1" },
387
- };
388
- const recorded = recordingClient({
389
- body: {
390
- aggregations: {
391
- customers: {
392
- buckets: [
393
- {
394
- key: { customerNumber: "C1" },
395
- customer: {
396
- hits: {
397
- hits: {
398
- hits: [{ _source: document }],
399
- },
400
- },
401
- },
402
- },
403
- ],
404
- },
405
- },
406
- },
407
- });
408
- const openSearch = openSearchFor(recorded);
409
- const result = await openSearch.searchProjectionAggregations()({
410
- companyId,
411
- projectionType,
412
- filter: aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
413
- aggregation: aggregations_1.Aggregation.composite({
414
- name: "customers",
415
- size: 10,
416
- sources: [
417
- aggregations_1.Aggregation.source({
418
- name: "customerNumber",
419
- field: "payload.taskContext.consigneeCustomerNumber.keyword",
420
- }),
421
- ],
422
- subAggregations: [
423
- aggregations_1.Aggregation.topHits({
424
- name: "customer",
425
- size: 1,
426
- fields: ["payload.taskContext.customerName"],
427
- filter: aggregations_1.Aggregation.exists("payload.taskContext.customerName"),
428
- }),
429
- ],
430
- }),
431
- });
432
- const body = recorded.searches[0].body;
433
- (0, chai_1.expect)(body.aggs.customers.aggs.customer).to.deep.equal({
434
- filter: { exists: { field: "payload.taskContext.customerName" } },
435
- aggs: {
436
- hits: {
437
- top_hits: { size: 1, _source: ["payload.taskContext.customerName"] },
438
- },
439
- },
440
- });
441
- const customer = result.buckets[0].customer[0];
442
- (0, chai_1.expect)(customer.payload?.taskContext?.customerName).to.equal("Acme");
443
- });
444
- });
445
- describe("searchProjectionGroups and uniqueProjectionValues", () => {
446
- it("pages groups by the given keys and collections", async () => {
447
- const document = {
448
- companyId,
449
- projectionType,
450
- entityId: "e1",
451
- payload: { customerName: "Acme" },
452
- version: 1,
453
- referenceIds: { entityId: "e1" },
454
- };
455
- const recorded = recordingClient({
456
- body: {
457
- aggregations: {
458
- groups: {
459
- after_key: { completedAt: 10, taskLookupId: "t2" },
460
- buckets: [
461
- {
462
- key: { completedAt: 9, taskLookupId: "t1" },
463
- full_document: { hits: { hits: [{ _source: document }] } },
464
- skus: {
465
- filtered: {
466
- values: { buckets: [{ key: "SKU-1", doc_count: 2 }] },
467
- },
468
- },
469
- },
470
- ],
471
- },
472
- },
473
- },
474
- });
475
- const openSearch = openSearchFor(recorded);
476
- const result = await openSearch.searchProjectionGroups()({
477
- companyId,
478
- projectionType,
479
- filter: aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
480
- limit: 11,
481
- after: null,
482
- groupBy: [
483
- {
484
- name: "completedAt",
485
- field: "payload.taskContext.completedAt",
486
- order: "desc",
487
- },
488
- {
489
- name: "taskLookupId",
490
- field: "payload.taskLookupId.keyword",
491
- order: "asc",
492
- },
493
- ],
494
- collect: {
495
- skus: {
496
- nested: {
497
- path: "payload.taskContext.shipmentItems",
498
- field: "payload.taskContext.shipmentItems.sku",
499
- size: 100,
500
- filter: aggregations_1.Aggregation.terms("payload.taskContext.shipmentItems.sku", ["A"]),
501
- },
502
- },
503
- full_document: { document: true },
504
- },
505
- });
506
- const body = recorded.searches[0].body;
507
- (0, chai_1.expect)(body.aggs.groups).to.deep.equal({
508
- composite: {
509
- size: 11,
510
- sources: [
511
- {
512
- completedAt: {
513
- terms: { field: "payload.taskContext.completedAt", order: "desc" },
514
- },
515
- },
516
- {
517
- taskLookupId: {
518
- terms: { field: "payload.taskLookupId.keyword", order: "asc" },
519
- },
520
- },
521
- ],
522
- },
523
- aggs: {
524
- skus: {
525
- nested: { path: "payload.taskContext.shipmentItems" },
526
- aggs: {
527
- filtered: {
528
- filter: { terms: { "payload.taskContext.shipmentItems.sku": ["A"] } },
529
- aggs: {
530
- values: {
531
- terms: { field: "payload.taskContext.shipmentItems.sku", size: 100 },
532
- },
533
- },
534
- },
535
- },
536
- },
537
- full_document: { top_hits: { size: 1 } },
538
- },
539
- });
540
- (0, chai_1.expect)(result.buckets[0].key.completedAt).to.equal(9);
541
- (0, chai_1.expect)(result.buckets[0].key.taskLookupId).to.equal("t1");
542
- (0, chai_1.expect)(result.buckets[0].full_document[0]).to.deep.equal(document);
543
- (0, chai_1.expect)(result.buckets[0].skus).to.deep.equal([{ key: "SKU-1", docCount: 2 }]);
544
- (0, chai_1.expect)(result.afterKey).to.deep.equal({ completedAt: 10, taskLookupId: "t2" });
545
- });
546
- it("returns one value per distinct field, with an optional sample", async () => {
547
- const document = {
548
- companyId,
549
- projectionType,
550
- entityId: "e1",
551
- payload: { taskContext: { customerName: "Acme" } },
552
- version: 1,
553
- referenceIds: { entityId: "e1" },
554
- };
555
- const recorded = recordingClient({
556
- body: {
557
- aggregations: {
558
- groups: {
559
- after_key: { value: "C2" },
560
- buckets: [
561
- {
562
- key: { value: "C1" },
563
- sample: {
564
- hits: {
565
- hits: {
566
- hits: [{ _source: document }],
567
- },
568
- },
569
- },
570
- },
571
- ],
572
- },
573
- },
574
- },
575
- });
576
- const openSearch = openSearchFor(recorded);
577
- const result = await openSearch.uniqueProjectionValues()({
578
- companyId,
579
- projectionType,
580
- filter: aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
581
- field: "payload.taskContext.consigneeCustomerNumber.keyword",
582
- limit: 10,
583
- after: null,
584
- sample: {
585
- fields: ["payload.taskContext.customerName"],
586
- when: aggregations_1.Aggregation.exists("payload.taskContext.customerName"),
587
- },
588
- });
589
- const body = recorded.searches[0].body;
590
- (0, chai_1.expect)(body.aggs.groups.composite).to.deep.equal({
591
- size: 10,
592
- sources: [
593
- {
594
- value: {
595
- terms: { field: "payload.taskContext.consigneeCustomerNumber.keyword" },
596
- },
597
- },
598
- ],
599
- });
600
- (0, chai_1.expect)(body.aggs.groups.aggs.sample).to.deep.equal({
601
- filter: { exists: { field: "payload.taskContext.customerName" } },
602
- aggs: {
603
- hits: {
604
- top_hits: { size: 1, _source: ["payload.taskContext.customerName"] },
605
- },
606
- },
607
- });
608
- (0, chai_1.expect)(result.values[0].key).to.equal("C1");
609
- (0, chai_1.expect)(result.values[0].sample?.payload?.taskContext?.customerName).to.equal("Acme");
610
- (0, chai_1.expect)(result.after).to.equal("C2");
611
- });
612
- it("returns only the distinct keys when no sample is requested", async () => {
613
- const recorded = recordingClient({
614
- body: {
615
- aggregations: {
616
- groups: {
617
- buckets: [{ key: { value: "SKU-1" } }, { key: { value: "SKU-2" } }],
618
- },
619
- },
620
- },
621
- });
622
- const openSearch = openSearchFor(recorded);
623
- const result = await openSearch.uniqueProjectionValues()({
624
- companyId,
625
- projectionType,
626
- filter: aggregations_1.Aggregation.equals("payload.status", "COMPLETED"),
627
- field: "payload.returnEventData.data.taskResult.products.sku",
628
- limit: 3,
629
- after: "SKU-0",
630
- order: "asc",
631
- });
632
- const body = recorded.searches[0].body;
633
- (0, chai_1.expect)(body.aggs.groups.composite).to.deep.equal({
634
- size: 3,
635
- after: { value: "SKU-0" },
636
- sources: [
637
- {
638
- value: {
639
- terms: {
640
- field: "payload.returnEventData.data.taskResult.products.sku",
641
- order: "asc",
642
- },
643
- },
644
- },
645
- ],
646
- });
647
- (0, chai_1.expect)(body.aggs.groups.aggs).to.equal(undefined);
648
- (0, chai_1.expect)(result.values.map((value) => value.key)).to.deep.equal(["SKU-1", "SKU-2"]);
649
- (0, chai_1.expect)(result.after).to.equal(undefined);
650
- });
651
- });
652
- //# sourceMappingURL=searchProjectionAggregations.query.spec.js.map