@mavenmachines/event-handler-lib 1.5.0-rc.0 → 1.5.0-rc.1

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 (142) hide show
  1. package/README.md +272 -1
  2. package/dist/config/default.d.ts +6 -0
  3. package/dist/config/default.js +6 -0
  4. package/dist/config/default.js.map +1 -1
  5. package/dist/package.json +1 -0
  6. package/dist/src/app.module.d.ts +2 -2
  7. package/dist/src/app.module.js +2 -2
  8. package/dist/src/app.module.js.map +1 -1
  9. package/dist/src/clients/openSearch/errors.d.ts +2 -0
  10. package/dist/src/clients/openSearch/errors.js +4 -1
  11. package/dist/src/clients/openSearch/errors.js.map +1 -1
  12. package/dist/src/clients/openSearch/mappings.d.ts +4 -2
  13. package/dist/src/clients/openSearch/mappings.js +18 -2
  14. package/dist/src/clients/openSearch/mappings.js.map +1 -1
  15. package/dist/src/clients/openSearch/openSearchClient.d.ts +19 -0
  16. package/dist/src/clients/openSearch/openSearchClient.js +228 -6
  17. package/dist/src/clients/openSearch/openSearchClient.js.map +1 -1
  18. package/dist/src/configs/inversifyConfig.js +1 -0
  19. package/dist/src/configs/inversifyConfig.js.map +1 -1
  20. package/dist/src/exports/clients.d.ts +1 -0
  21. package/dist/src/exports/clients.js +3 -1
  22. package/dist/src/exports/clients.js.map +1 -1
  23. package/dist/src/exports/services.d.ts +2 -2
  24. package/dist/src/exports/services.js +2 -2
  25. package/dist/src/exports/services.js.map +1 -1
  26. package/dist/src/exports/sourcing.d.ts +4 -3
  27. package/dist/src/exports/sourcing.js +18 -3
  28. package/dist/src/exports/sourcing.js.map +1 -1
  29. package/dist/src/exports/utils.d.ts +2 -0
  30. package/dist/src/exports/utils.js +2 -0
  31. package/dist/src/exports/utils.js.map +1 -1
  32. package/dist/src/{eventHandlers → handlers}/baseHandler.d.ts +0 -1
  33. package/dist/src/{eventHandlers → handlers}/baseHandler.js +2 -5
  34. package/dist/src/handlers/baseHandler.js.map +1 -0
  35. package/dist/src/{eventHandlers → handlers/commandHandlers}/baseCommandHandler.d.ts +10 -10
  36. package/dist/src/{eventHandlers → handlers/commandHandlers}/baseCommandHandler.js +7 -7
  37. package/dist/src/handlers/commandHandlers/baseCommandHandler.js.map +1 -0
  38. package/dist/src/{eventHandlers → handlers/commandHandlers}/commandHandlingModule.d.ts +3 -3
  39. package/dist/src/{eventHandlers → handlers/commandHandlers}/commandHandlingModule.js +3 -3
  40. package/dist/src/handlers/commandHandlers/commandHandlingModule.js.map +1 -0
  41. package/dist/src/handlers/crud/baseHandlers.d.ts +30 -0
  42. package/dist/src/handlers/crud/baseHandlers.js +101 -0
  43. package/dist/src/handlers/crud/baseHandlers.js.map +1 -0
  44. package/dist/src/handlers/crud/createProjectionHandler.d.ts +9 -0
  45. package/dist/src/handlers/crud/createProjectionHandler.js +36 -0
  46. package/dist/src/handlers/crud/createProjectionHandler.js.map +1 -0
  47. package/dist/src/handlers/crud/createUpdateProjectionHandler.d.ts +10 -0
  48. package/dist/src/handlers/crud/createUpdateProjectionHandler.js +39 -0
  49. package/dist/src/handlers/crud/createUpdateProjectionHandler.js.map +1 -0
  50. package/dist/src/handlers/crud/decorators.d.ts +3 -0
  51. package/dist/src/handlers/crud/decorators.js +9 -0
  52. package/dist/src/handlers/crud/decorators.js.map +1 -0
  53. package/dist/src/handlers/crud/deleteProjectionHandler.d.ts +9 -0
  54. package/dist/src/handlers/crud/deleteProjectionHandler.js +43 -0
  55. package/dist/src/handlers/crud/deleteProjectionHandler.js.map +1 -0
  56. package/dist/src/handlers/crud/getProjectionHandler.d.ts +11 -0
  57. package/dist/src/handlers/crud/getProjectionHandler.js +29 -0
  58. package/dist/src/handlers/crud/getProjectionHandler.js.map +1 -0
  59. package/dist/src/handlers/crud/getProjectionsHandler.d.ts +10 -0
  60. package/dist/src/handlers/crud/getProjectionsHandler.js +56 -0
  61. package/dist/src/handlers/crud/getProjectionsHandler.js.map +1 -0
  62. package/dist/src/handlers/crud/helpers.d.ts +9 -0
  63. package/dist/src/handlers/crud/helpers.js +71 -0
  64. package/dist/src/handlers/crud/helpers.js.map +1 -0
  65. package/dist/src/handlers/crud/index.d.ts +30 -0
  66. package/dist/src/handlers/crud/index.js +75 -0
  67. package/dist/src/handlers/crud/index.js.map +1 -0
  68. package/dist/src/handlers/crud/searchProjectionsHandler.d.ts +20 -0
  69. package/dist/src/handlers/crud/searchProjectionsHandler.js +148 -0
  70. package/dist/src/handlers/crud/searchProjectionsHandler.js.map +1 -0
  71. package/dist/src/{eventHandlers → handlers/eventHandlers}/baseEventHandler.d.ts +10 -10
  72. package/dist/src/{eventHandlers → handlers/eventHandlers}/baseEventHandler.js +3 -3
  73. package/dist/src/handlers/eventHandlers/baseEventHandler.js.map +1 -0
  74. package/dist/src/{eventHandlers → handlers/eventHandlers}/eventHandlingModule.d.ts +7 -7
  75. package/dist/src/{eventHandlers → handlers/eventHandlers}/eventHandlingModule.js +7 -7
  76. package/dist/src/handlers/eventHandlers/eventHandlingModule.js.map +1 -0
  77. package/dist/src/{eventHandlers → handlers/eventHandlers}/syncFirestoreEvents.d.ts +3 -3
  78. package/dist/src/{eventHandlers → handlers/eventHandlers}/syncFirestoreEvents.js +3 -3
  79. package/dist/src/handlers/eventHandlers/syncFirestoreEvents.js.map +1 -0
  80. package/dist/src/helpers/classConverter.d.ts +0 -1
  81. package/dist/src/helpers/classConverter.js +0 -18
  82. package/dist/src/helpers/classConverter.js.map +1 -1
  83. package/dist/src/helpers/dataStructure.helpers.d.ts +1 -0
  84. package/dist/src/helpers/dataStructure.helpers.js +16 -0
  85. package/dist/src/helpers/dataStructure.helpers.js.map +1 -1
  86. package/dist/src/helpers/string.helpers.d.ts +1 -0
  87. package/dist/src/helpers/string.helpers.js +7 -0
  88. package/dist/src/helpers/string.helpers.js.map +1 -0
  89. package/dist/src/helpers/typeManipulation/classValidation.d.ts +6 -0
  90. package/dist/src/helpers/typeManipulation/classValidation.js +30 -0
  91. package/dist/src/helpers/typeManipulation/classValidation.js.map +1 -0
  92. package/dist/src/helpers/typeManipulation/decorators.d.ts +13 -0
  93. package/dist/src/helpers/typeManipulation/decorators.js +86 -0
  94. package/dist/src/helpers/typeManipulation/decorators.js.map +1 -0
  95. package/dist/src/helpers/typeManipulation/dynamicClasses.d.ts +8 -0
  96. package/dist/src/helpers/typeManipulation/dynamicClasses.js +27 -0
  97. package/dist/src/helpers/typeManipulation/dynamicClasses.js.map +1 -0
  98. package/dist/src/helpers/typeManipulation/index.d.ts +3 -0
  99. package/dist/src/helpers/typeManipulation/index.js +20 -0
  100. package/dist/src/helpers/typeManipulation/index.js.map +1 -0
  101. package/dist/src/initializers/logger.service.d.ts +4 -0
  102. package/dist/src/initializers/logger.service.js +14 -0
  103. package/dist/src/initializers/logger.service.js.map +1 -1
  104. package/dist/src/repositories/projectionRepository.d.ts +4 -8
  105. package/dist/src/repositories/projectionRepository.js +13 -30
  106. package/dist/src/repositories/projectionRepository.js.map +1 -1
  107. package/dist/src/rpc/rpcModule.js +4 -1
  108. package/dist/src/rpc/rpcModule.js.map +1 -1
  109. package/dist/src/testUtils/testDependencies.d.ts +1 -2
  110. package/dist/src/testUtils/testDependencies.js +10 -13
  111. package/dist/src/testUtils/testDependencies.js.map +1 -1
  112. package/dist/test/testImplementations/testCommandHandler.d.ts +1 -1
  113. package/dist/test/testImplementations/testCommandHandler.js +1 -1
  114. package/dist/test/testImplementations/testCommandHandler.js.map +1 -1
  115. package/dist/test/testImplementations/testCrud.d.ts +19 -0
  116. package/dist/test/testImplementations/testCrud.js +109 -0
  117. package/dist/test/testImplementations/testCrud.js.map +1 -0
  118. package/dist/test/testImplementations/testEventHandler.d.ts +3 -10
  119. package/dist/test/testImplementations/testEventHandler.js +4 -32
  120. package/dist/test/testImplementations/testEventHandler.js.map +1 -1
  121. package/dist/test/testImplementations/testFirestoreEventSync.js +1 -1
  122. package/dist/test/testImplementations/testFirestoreEventSync.js.map +1 -1
  123. package/dist/test/tests/common.js +3 -0
  124. package/dist/test/tests/common.js.map +1 -1
  125. package/dist/test/tests/eventHandlers/baseEventHandler.spec.js +6 -19
  126. package/dist/test/tests/eventHandlers/baseEventHandler.spec.js.map +1 -1
  127. package/dist/test/tests/eventHandlers/crudHandlers.spec.d.ts +1 -0
  128. package/dist/test/tests/eventHandlers/crudHandlers.spec.js +494 -0
  129. package/dist/test/tests/eventHandlers/crudHandlers.spec.js.map +1 -0
  130. package/dist/test/tests/eventHandlers/firestoreEventSyncHandler.spec.js +6 -16
  131. package/dist/test/tests/eventHandlers/firestoreEventSyncHandler.spec.js.map +1 -1
  132. package/dist/test/tests/helpers/classConverter.spec.js +0 -21
  133. package/dist/test/tests/helpers/classConverter.spec.js.map +1 -1
  134. package/dist/test/tests/repositories/projectionRepository.spec.js +3 -4
  135. package/dist/test/tests/repositories/projectionRepository.spec.js.map +1 -1
  136. package/package.json +2 -1
  137. package/dist/src/eventHandlers/baseCommandHandler.js.map +0 -1
  138. package/dist/src/eventHandlers/baseEventHandler.js.map +0 -1
  139. package/dist/src/eventHandlers/baseHandler.js.map +0 -1
  140. package/dist/src/eventHandlers/commandHandlingModule.js.map +0 -1
  141. package/dist/src/eventHandlers/eventHandlingModule.js.map +0 -1
  142. package/dist/src/eventHandlers/syncFirestoreEvents.js.map +0 -1
package/README.md CHANGED
@@ -382,7 +382,7 @@ If the document ID should not be the same as the Projection's `entityId`, you
382
382
  can overload `getDocumentId(EventSourcedProjection<PayloadT>): string` to get
383
383
  the correct subpath for the Firestore document.
384
384
 
385
- #### Parital Document Update
385
+ #### Partial Document Update
386
386
 
387
387
  If you need to make partial modifications to Firestore documents, you can use
388
388
  the `UpdateFirestoreProjection` plugin, which has an additional property,
@@ -464,6 +464,277 @@ Note that `name` can either be the instance of your class, or any string that
464
464
  you want to call it. It is only used for logging purposes in the event of a
465
465
  failure.
466
466
 
467
+ ## Implementing CRUD Interfaces
468
+
469
+ There are many instances where one may want to expose a Projection type to a CRUD
470
+ (Create-Retrieve-Update-Delete) Interface via RPCs. Many entities are the
471
+ accumulation of events, but many also begin their lives externally, needing to be
472
+ created or updated via a command, and retrieved via ID or searched.
473
+
474
+ ### Annotating a Projection for CRUD support.
475
+
476
+ In addition to supporting `class-validator` and `class-transformer` decorators,
477
+ `event-handler-lib` provides CRUD-specific decorators to allow a developer control
478
+ over the behavior of their Projection in a CRUD app.
479
+
480
+ Firstly, all supported projections must have the `@ProjectionType` decorator, so
481
+ that the framework knows where the representation lives in Dynamo and Opensearch.
482
+
483
+ To allow Update calls, fields can be marked with `@IsEditable()`. If a field is
484
+ not marked with `@IsEditable()`, Update requests that provide values for that field
485
+ will fail.
486
+
487
+ To allow Search functionality, the OpenSearch indexes must be properly configured.
488
+ Adding an `@IsSearchable()` decorator will tell the service to ensure that the
489
+ Mapping is properly set for those fields. In the event of a conflict with an existing
490
+ mapping, the service will fail to start.
491
+
492
+ Caveats:
493
+
494
+ - All `Projection` types must have an `id: string` field representing their `entityId`
495
+ - Only `number` and `string` indexes are supported for now, but more will come
496
+ - While the binding keys are defined by convention, the service must still provide
497
+ them to `Pump` via the `bindingKeys.config.json` file.
498
+ - This is the expected location for binding keys at Maven, and we do not want
499
+ to hide important diagnostic information in case of emergencies.
500
+
501
+ ### Example
502
+
503
+ The `@ProjectionType()`, decorator will guide the names of the RabbitMQ binding keys
504
+ for a given Projection. Given the following examples:
505
+
506
+ ```
507
+ @ProjectionType("salesProduct")
508
+ export class SalesProductProjection {
509
+ @IsString()
510
+ id: string;
511
+
512
+ @IsString()
513
+ @IsSearchable()
514
+ productCode: string;
515
+
516
+ @IsString()
517
+ @IsSearchable()
518
+ upc: string
519
+
520
+ @IsOptional()
521
+ @IsString()
522
+ @IsSearchable()
523
+ @IsEditable()
524
+ description: string;
525
+
526
+ @ValidateNested()
527
+ @Type(() => MetadataFields)
528
+ metadata: MetadataFields;
529
+ }
530
+
531
+ export class MetadataFields {
532
+ @IsOptional()
533
+ @IsString()
534
+ @IsSearchable()
535
+ @IsEditable()
536
+ owner?: string;
537
+
538
+ @IsNumber()
539
+ @IsString()
540
+ @IsSearchable()
541
+ internalId: number
542
+ }
543
+ ```
544
+
545
+ #### Create Request: `createSalesProduct`
546
+
547
+ The `create` requests are similar to standard RPC requests. The `id` field is not
548
+ supported, and a `companyId` must be provided.
549
+
550
+ ```
551
+ {
552
+ companyId: 1234,
553
+ productCode: "Product-ABC",
554
+ upc: "00000-2334342",
555
+ metadata: {
556
+ owner: "this is optional",
557
+ internalId: 12359
558
+ }
559
+ }
560
+ ```
561
+
562
+ The response is simply `{id: UUID}`.
563
+
564
+ ### Update Request: `updateSalesProduct`
565
+
566
+ The `update` requests are also similar, except all fields are optional to both
567
+ TypeScript and `class-validator`. Unfortunately, it is impossible to remove
568
+ non-editable fields from the request type at compile-time, but server-side validation
569
+ will ensure they are not modified:
570
+
571
+ ```
572
+ {
573
+ companyId: 1234,
574
+ id: "XXXX-XXXXXX-XXXXX-XXXXX-XXXX",
575
+ metadata: {
576
+ owner: "new owner",
577
+ }
578
+ }
579
+ ```
580
+
581
+ The response is `{ modified: boolean }`, indicating whether or not the request
582
+ resulted in a modification to the projection.
583
+
584
+ ### Delete Request: `deleteSalesProduct`
585
+
586
+ The `delete` requests simply require a `companyId` and `id`, as the `projectionType`
587
+ is inherently tied to the endpoint.
588
+
589
+ ```
590
+ {
591
+ companyId: 1234,
592
+ id: "XXXX-XXXXXX-XXXXX-XXXXX-XXXX",
593
+ }
594
+ ```
595
+
596
+ The response is empty on success, and will fail with `"errorKey": "NOT_FOUND"`
597
+ if the entity does not exist.
598
+
599
+ ### Get Request: `getSalesProduct`
600
+
601
+ The `get` request also takes a `companyId` and `id`;
602
+
603
+ ```
604
+ {
605
+ companyId: 1234,
606
+ id: "XXXX-XXXXXX-XXXXX-XXXXX-XXXX",
607
+ }
608
+ ```
609
+
610
+ The response will contain the projections `payload` in its `projection` field if
611
+ it is found. If the entity does not exist, the `projection` field will be `undefined`:
612
+
613
+ ```
614
+ {
615
+ projection: {
616
+ id: "XXXX-XXXXXX-XXXXX-XXXXX-XXXX",
617
+ productCode: "Product-ABC",
618
+ upc: "0000-12312342432",
619
+ metadata: {
620
+ owner: "this is optional",
621
+ internalId: 12359
622
+ }
623
+ }
624
+ }
625
+ ```
626
+
627
+ ### Get Multiple Request: `getSalesProducts`.
628
+
629
+ The framework also exposes a multi-get endpoint, where you can provide several `ids`
630
+ and retrieve them all.
631
+
632
+ ```
633
+ {
634
+ companyId: 1234,
635
+ ids: ["UUID1", "UUID2", "UUID3"]
636
+ }
637
+ ```
638
+
639
+ The response now has two array fields, `projections` holding the projections that
640
+ were found, and `missing` holding the `id`s of those that were not:
641
+
642
+ ```
643
+ {
644
+ projections: [
645
+ {
646
+ id: "UUID2",
647
+ ...
648
+ }
649
+ ],
650
+ missing: ["UUID1", "UUID3"]
651
+ }
652
+ ```
653
+
654
+ If all or none of the projections are found, the arrays will still exist in the
655
+ response, they will simply be empty.
656
+
657
+ ### Searching Projections: `searchSalesProducts`
658
+
659
+ Finally, the framework provides search functionality. Any field marked
660
+ `@IsSearchable()` will have an appropriate index created. These fields can be
661
+ used in the query for filtering or sorting.
662
+
663
+ For example, to find fields with a matching `metadata.owner`, sorted by descending
664
+ `upc`, you can provide:
665
+
666
+ ```
667
+ {
668
+ companyId: 1234,
669
+ query: {
670
+ metadata: {
671
+ owner: "Owner Name"
672
+ }
673
+ },
674
+ sort: {
675
+ upc: "desc"
676
+ }
677
+ }
678
+ ```
679
+
680
+ By default, the searches are limited to 10 results per query, and will return
681
+ a `continuationToken`.
682
+
683
+ The optional fields are:
684
+
685
+ 1. `limit` to determine how many results are returned
686
+ 2. `page` the 1-indexed page number. If provided, the results will start at `limit * (page - 1)`
687
+ 3. The returned `continuationToken` can be sent back in another search to continue
688
+ where you left off.
689
+
690
+ Response:
691
+
692
+ ```
693
+ {
694
+ results: [{
695
+ id: "XXXXX",
696
+ productCode: "etc",
697
+ }, { ... }],
698
+ continuationToken: "XXXX"
699
+ }
700
+ ```
701
+
702
+ When paging through search results, the `continuationToken` will be valid for
703
+ ten minutes, after which it will expire and queries will fail. During that time,
704
+ OpenSearch maintains a point-in-time snapshot of the data, so the results will
705
+ be consistent _at the time of the query_.
706
+
707
+ ### Binding a CRUD handler for a Projection
708
+
709
+ If you want all of the functionality, the `CrudHandlerFactory` can set it all
710
+ up for you with on line of code.
711
+
712
+ ```
713
+ CrudHandlerFactory.bind(appContainer, SalesProductProjection)
714
+ ```
715
+
716
+ If you need to request an explicit subset, a list of `actions` can be provided,
717
+ followed by an optional `multi: boolean = true` to determine if the multi-Get endpoint
718
+ is provided.
719
+
720
+ ### Client-Side
721
+
722
+ The `event-handler-lib` provides utility types for clients:
723
+
724
+ - `CreateRequest<T>`/`CreatedResponse`
725
+ - `UpdateRequest<T>`/`ModifiedResponse`
726
+ - `DeleteProjectionRequest`/`DeleteProjectionResponse`
727
+ - `GetProjectionRequest`/`GetProjectionResponse<T>`
728
+ - `GetProjectionsRequest`/`GetProjectionsResponse<T>`
729
+ - `SearchRequest<T>`/`SearchResults<T>`
730
+
731
+ Additionally, if you need to create the types with validation includes, the
732
+ `CrudCommandFactory` provides `createRequest`, `updateRequest`, and `searchRequest`
733
+ members, all of which take the `ClassConstructor<ProjectionType>`.
734
+
735
+ These are not required for `Get` and `Delete`, as `class-validator` and
736
+ `class-transformer` manipulation are not required.
737
+
467
738
  ## Testing
468
739
 
469
740
  ### Stubbing EventHandler services
@@ -10,6 +10,12 @@ declare const _default: {
10
10
  disableLogging: boolean;
11
11
  bindingKeys: {
12
12
  testRpcRequest: string;
13
+ createExampleProjection: string;
14
+ updateExampleProjection: string;
15
+ deleteExampleProjection: string;
16
+ getExampleProjection: string;
17
+ getExampleProjections: string;
18
+ searchExampleProjections: string;
13
19
  };
14
20
  routingKey: {};
15
21
  };
@@ -54,6 +54,12 @@ exports.default = {
54
54
  disableLogging: process.env.rabbitmq_disablelogging === "true",
55
55
  bindingKeys: {
56
56
  testRpcRequest: "#.eventHandlerLib.test.rpcRequest",
57
+ createExampleProjection: "#.eventHandlerLib.test.exampleProjection.create",
58
+ updateExampleProjection: "#.eventHandlerLib.test.exampleProjection.update",
59
+ deleteExampleProjection: "#.eventHandlerLib.test.exampleProjection.delete",
60
+ getExampleProjection: "#.eventHandlerLib.test.exampleProjection.get",
61
+ getExampleProjections: "#.eventHandlerLib.test.get.exampleProjections",
62
+ searchExampleProjections: "#.eventHandlerLib.test.search.exampleProjections",
57
63
  },
58
64
  routingKey: {},
59
65
  },
@@ -1 +1 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../../config/default.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAAuE;AACvE,+CAAiC;AAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAEjC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,uBAAuB,GAAG,EAAE;CACnC,CAAC,CAAC;AAEH,IAAI,KAAK,EAAE,CAAC;IACV,MAAM,KAAK,CAAC;AACd,CAAC;AAED,kBAAe;IACb,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;IACpC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,kBAAkB;QACrD,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,aAAa;QACxD,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,mBAAmB;QACxD,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC;QAChD,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,KAAK,MAAM;QAC3D,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,MAAM;QAC9D,WAAW,EAAE;YACX,cAAc,EAAE,mCAAmC;SACpD;QACD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;YACpE,qBAAqB,EAAE,+CAA+C;YACtE,wBAAwB,EACtB,kDAAkD;SACrD;QACD,UAAU,EAAE,EAAE;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe;KACjE;IACD,kBAAkB,EAAlB,uCAAkB;CACnB,CAAC"}
package/dist/package.json CHANGED
@@ -71,6 +71,7 @@
71
71
  "@mavenmachines/feature-flags-client": "^1.2.0",
72
72
  "@mavenmachines/prometheus-nodejs-client": "^1.0.2",
73
73
  "@mavenmachines/pump": "^1.5.4",
74
+ "@nestjs/mapped-types": "^2.1.0",
74
75
  "@opensearch-project/opensearch": "^3.5.1",
75
76
  "amqplib": "^0.10.5",
76
77
  "async-mutex": "^0.5.0",
@@ -1,7 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  import { LoggerService } from "./initializers/logger.service";
3
- import { EventHandlingModule } from "./eventHandlers/eventHandlingModule";
4
- import { CommandHandlingModule } from "./eventHandlers/commandHandlingModule";
3
+ import { EventHandlingModule } from "./handlers/eventHandlers/eventHandlingModule";
4
+ import { CommandHandlingModule } from "./handlers/commandHandlers/commandHandlingModule";
5
5
  import { RpcModule } from "./rpc/rpcModule";
6
6
  import { QueueManagerService } from "./initializers/queue-manager.service";
7
7
  export declare class AppModule {
@@ -16,8 +16,8 @@ exports.AppModule = void 0;
16
16
  require("reflect-metadata");
17
17
  const inversify_1 = require("inversify");
18
18
  const logger_service_1 = require("./initializers/logger.service");
19
- const eventHandlingModule_1 = require("./eventHandlers/eventHandlingModule");
20
- const commandHandlingModule_1 = require("./eventHandlers/commandHandlingModule");
19
+ const eventHandlingModule_1 = require("./handlers/eventHandlers/eventHandlingModule");
20
+ const commandHandlingModule_1 = require("./handlers/commandHandlers/commandHandlingModule");
21
21
  const rpcModule_1 = require("./rpc/rpcModule");
22
22
  const dependencyTypes_1 = require("./dependencies/dependencyTypes");
23
23
  const queue_manager_service_1 = require("./initializers/queue-manager.service");
@@ -1 +1 @@
1
- {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4BAA0B;AAC1B,yCAA+C;AAC/C,kEAAsE;AACtE,6EAA0E;AAC1E,iFAA8E;AAC9E,+CAA4C;AAC5C,oEAAuD;AACvD,gFAA2E;AAGpE,IAAM,SAAS,GAAf,MAAM,SAAS;IAGpB,YAC8C,WAAmB,EAE9C,YAAiC,EAE1C,mBAAwC,EAExC,qBAA4C,EAC7B,aAA4B,EACf,SAAoB;QARZ,gBAAW,GAAX,WAAW,CAAQ;QAE9C,iBAAY,GAAZ,YAAY,CAAqB;QAE1C,wBAAmB,GAAnB,mBAAmB,CAAqB;QAExC,0BAAqB,GAArB,qBAAqB,CAAuB;QAEhB,cAAS,GAAT,SAAS,CAAW;QAExD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAgD;QACzD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,iBAAiB,CAAC,CAAC;QACvD,MAAM,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;YAClC,MAAM,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK;YAC9B,SAAS,EAAE,KAAK,EAAE,SAAS;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAG1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,WAAW,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AA9BY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,GAAE;IAKR,WAAA,IAAA,kBA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K,EAAE,SAAS;SAC5B,CAAC,CAAC;QACH,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAG1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,WAAW,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AA9BY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,GAAE;IAKR,WAAA,IAAA,kBAAM,EAAC,uBAAK,CAAC,WAAW,CAAC,CAAA;IACzB,WAAA,IAAA,kBAAM,EAAC,2CAAmB,CAAC,CAAA;IAE3B,WAAA,IAAA,kBAAM,EAAC,yCAAmB,CAAC,CAAA;IAE3B,WAAA,IAAA,kBAAM,EAAC,6CAAqB,CAAC,CAAA;IAE7B,WAAA,IAAA,kBAAM,EAAC,8BAAa,CAAC,CAAA;IACrB,WAAA,IAAA,kBAAM,EAAC,qBAAS,CAAC,CAAA;6CANa,2CAAmB;QAErB,yCAAmB;QAEjB,6CAAqB;QACd,8BAAa;QACJ,qBAAS;GAZ/C,SAAS,CA8BrB"}
@@ -1,5 +1,7 @@
1
1
  export declare class OpenSearchError extends Error {
2
2
  }
3
+ export declare class ExpiredPointInTime extends OpenSearchError {
4
+ }
3
5
  export declare class MappingError extends OpenSearchError {
4
6
  }
5
7
  export declare class MaxRecursionSanitizationReached extends MappingError {
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MaxRecursionSanitizationReached = exports.MappingError = exports.OpenSearchError = void 0;
3
+ exports.MaxRecursionSanitizationReached = exports.MappingError = exports.ExpiredPointInTime = exports.OpenSearchError = void 0;
4
4
  class OpenSearchError extends Error {
5
5
  }
6
6
  exports.OpenSearchError = OpenSearchError;
7
+ class ExpiredPointInTime extends OpenSearchError {
8
+ }
9
+ exports.ExpiredPointInTime = ExpiredPointInTime;
7
10
  class MappingError extends OpenSearchError {
8
11
  }
9
12
  exports.MappingError = MappingError;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/clients/openSearch/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C;AAC7C,MAAa,YAAa,SAAQ,eAAe;CAAG;AAApD,oCAAoD;AACpD,MAAa,+BAAgC,SAAQ,YAAY;IAC/D,YACkB,KAAa,EACb,IAAY,EACZ,IAAyB,EACzB,aAA8B;QAE9C,KAAK,CAAC,iBAAiB,KAAK,qBAAqB,IAAI,EAAE,CAAC,CAAC;QALzC,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAqB;QACzB,kBAAa,GAAb,aAAa,CAAiB;IAGhD,CAAC;CACF;AATD,0EASC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/clients/openSearch/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C;AAC7C,MAAa,kBAAmB,SAAQ,eAAe;CAAG;AAA1D,gDAA0D;AAC1D,MAAa,YAAa,SAAQ,eAAe;CAAG;AAApD,oCAAoD;AACpD,MAAa,+BAAgC,SAAQ,YAAY;IAC/D,YACkB,KAAa,EACb,IAAY,EACZ,IAAyB,EACzB,aAA8B;QAE9C,KAAK,CAAC,iBAAiB,KAAK,qBAAqB,IAAI,EAAE,CAAC,CAAC;QALzC,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAqB;QACzB,kBAAa,GAAb,aAAa,CAAiB;IAGhD,CAAC;CACF;AATD,0EASC"}
@@ -1,6 +1,8 @@
1
- import { BooleanProperty, DateProperty, LongNumberProperty, TextProperty, TypeMapping } from "@opensearch-project/opensearch/api/_types/_common.mapping";
2
- export declare const NUM_MAPPING: LongNumberProperty;
1
+ import { BooleanProperty, DateProperty, DoubleNumberProperty, KeywordProperty, Property, TextProperty, TypeMapping } from "@opensearch-project/opensearch/api/_types/_common.mapping";
2
+ export declare const KEYWORD_MAPPING: KeywordProperty;
3
+ export declare const NUM_MAPPING: DoubleNumberProperty;
3
4
  export declare const STRING_MAPPING: TextProperty;
4
5
  export declare const DATE_MAPPING: DateProperty;
5
6
  export declare const BOOLEAN_MAPPING: BooleanProperty;
6
7
  export declare const DEFAULT_MAPPING: TypeMapping;
8
+ export declare function getTypeMapping(type: string): Property;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_MAPPING = exports.BOOLEAN_MAPPING = exports.DATE_MAPPING = exports.STRING_MAPPING = exports.NUM_MAPPING = void 0;
3
+ exports.DEFAULT_MAPPING = exports.BOOLEAN_MAPPING = exports.DATE_MAPPING = exports.STRING_MAPPING = exports.NUM_MAPPING = exports.KEYWORD_MAPPING = void 0;
4
+ exports.getTypeMapping = getTypeMapping;
5
+ exports.KEYWORD_MAPPING = {
6
+ type: "keyword",
7
+ };
4
8
  exports.NUM_MAPPING = {
5
- type: "long",
9
+ type: "double",
6
10
  };
7
11
  exports.STRING_MAPPING = {
8
12
  fields: {
@@ -51,4 +55,16 @@ exports.DEFAULT_MAPPING = {
51
55
  isDeleted: exports.BOOLEAN_MAPPING,
52
56
  },
53
57
  };
58
+ function getTypeMapping(type) {
59
+ switch (type) {
60
+ case "string":
61
+ return exports.STRING_MAPPING;
62
+ case "number":
63
+ return exports.NUM_MAPPING;
64
+ case "id":
65
+ return exports.KEYWORD_MAPPING;
66
+ default:
67
+ throw new Error(`Unknown field type ${type}`);
68
+ }
69
+ }
54
70
  //# sourceMappingURL=mappings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mappings.js","sourceRoot":"","sources":["../../../../src/clients/openSearch/mappings.ts"],"names":[],"mappings":";;;AAQa,QAAA,WAAW,GAAuB;IAC7C,IAAI,EAAE,MAAM;CACb,CAAC;AAEW,QAAA,cAAc,GAAiB;IAC1C,MAAM,EAAE;QACN,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,YAAY,EAAE,GAAG;SAClB;KACF;IACD,IAAI,EAAE,MAAM;CACb,CAAC;AAEW,QAAA,YAAY,GAAiB;IACxC,IAAI,EAAE,MAAM;IAEZ,MAAM,EAAE,WAAW;CACpB,CAAC;AAEW,QAAA,eAAe,GAAoB;IAC9C,IAAI,EAAE,SAAS;CAChB,CAAC;AAEW,QAAA,eAAe,GAAgB;IAC1C,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE;QACV,SAAS,EAAE,mBAAW;QACtB,iCAAiC,EAAE,sBAAc;QACjD,QAAQ,EAAE,sBAAc;QACxB,YAAY,EAAE;YACZ,IAAI,EAAE,aAAa;SACpB;QACD,OAAO,EAAE,sBAAc;QACvB,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE;gBACV,OAAO,EAAE,sBAAc;gBACvB,SAAS,EAAE,sBAAc;gBACzB,QAAQ,EAAE,sBAAc;aACzB;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE;gBACV,SAAS,EAAE,sBAAc;gBACzB,OAAO,EAAE,sBAAc;aACxB;SACF;QACD,oBAAoB,EAAE,oBAAY;QAClC,SAAS,EAAE,uBAAe;KAC3B;CACF,CAAC"}
1
+ {"version":3,"file":"mappings.js","sourceRoot":"","sources":["../../../../src/clients/openSearch/mappings.ts"],"names":[],"mappings":";;;AAsEA,wCAWC;AAvEY,QAAA,eAAe,GAAoB;IAC9C,IAAI,EAAE,SAAS;CAChB,CAAC;AAEW,QAAA,WAAW,GAAyB;IAC/C,IAAI,EAAE,QAAQ;CACf,CAAC;AAEW,QAAA,cAAc,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Projection } from "../../types/eventSourcedProjection.type";
3
3
  import { Logger, LoggerService } from "../../initializers/logger.service";
4
4
  import { DistributedLocking } from "../redisClient";
5
+ import { DeepPartial } from "../../helpers/dataStructure.helpers";
6
+ import { Sort } from "@opensearch-project/opensearch/api/_types/_common";
7
+ import { TypeMapping } from "@opensearch-project/opensearch/api/_types/_common.mapping";
5
8
  declare class BaseOpenSearchClient {
6
9
  protected readonly client: Client;
7
10
  protected readonly distributedLocking: DistributedLocking;
@@ -20,6 +23,7 @@ export declare class OpenSearchClient extends BaseOpenSearchClient {
20
23
  private indexSanitizedProjection;
21
24
  private getIndexName;
22
25
  private getAliasName;
26
+ private getWriteIndex;
23
27
  private createAliasedIndex;
24
28
  ensureIndex(projection: {
25
29
  projectionType: string;
@@ -40,11 +44,26 @@ export declare class OpenSearchClient extends BaseOpenSearchClient {
40
44
  projectionType: string;
41
45
  entityId: string;
42
46
  }): Promise<void>;
47
+ getMapping(index: string): Promise<TypeMapping>;
48
+ private ensureMapping;
49
+ ensureMappings(projectionType: string, fields: Record<string, "number" | "string" | "id">): Promise<void>;
50
+ private generateFieldQuery;
51
+ private zeroContinuation;
52
+ private parseContinuation;
53
+ private toContinuation;
54
+ private doSearch;
55
+ searchProjections<T extends object>(companyId: number, projectionType: string, fields: DeepPartial<T>, sort?: Record<string, Sort>, limit?: number, page?: number, continuationToken?: string, pointInTime?: boolean): Promise<{
56
+ results: EventSourcedProjection<T>[];
57
+ continuation?: string;
58
+ }>;
43
59
  }
44
60
  export declare class OpensearchAdminClient extends BaseOpenSearchClient {
45
61
  getIndexes(): Promise<string[]>;
46
62
  removeIndex(index: string): Promise<void>;
63
+ clearIndex(index: string): Promise<void>;
47
64
  cleanAliases(): Promise<void>;
48
65
  clean(): Promise<void>;
66
+ clearIndexes(): Promise<void>;
67
+ expirePointInTime(pit_id: string): Promise<void>;
49
68
  }
50
69
  export {};