@mavenmachines/event-handler-lib 1.5.1-rc.15 → 1.5.1-rc.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.
Files changed (154) hide show
  1. package/README.md +1 -368
  2. package/dist/config/default.d.ts +0 -18
  3. package/dist/config/default.js +0 -18
  4. package/dist/config/default.js.map +1 -1
  5. package/dist/package.json +2 -4
  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/eventLogService.js +1 -8
  10. package/dist/src/clients/eventLogService.js.map +1 -1
  11. package/dist/src/clients/openSearch/errors.d.ts +0 -2
  12. package/dist/src/clients/openSearch/errors.js +1 -4
  13. package/dist/src/clients/openSearch/errors.js.map +1 -1
  14. package/dist/src/clients/openSearch/mappings.d.ts +2 -6
  15. package/dist/src/clients/openSearch/mappings.js +2 -25
  16. package/dist/src/clients/openSearch/mappings.js.map +1 -1
  17. package/dist/src/clients/openSearch/openSearchClient.d.ts +3 -22
  18. package/dist/src/clients/openSearch/openSearchClient.js +60 -267
  19. package/dist/src/clients/openSearch/openSearchClient.js.map +1 -1
  20. package/dist/src/configs/inversifyConfig.d.ts +0 -2
  21. package/dist/src/configs/inversifyConfig.js +4 -31
  22. package/dist/src/configs/inversifyConfig.js.map +1 -1
  23. package/dist/src/dependencies/dependencyTypes.d.ts +0 -1
  24. package/dist/src/dependencies/dependencyTypes.js +0 -1
  25. package/dist/src/dependencies/dependencyTypes.js.map +1 -1
  26. package/dist/src/{handlers/commandHandlers → eventHandlers}/baseCommandHandler.d.ts +19 -19
  27. package/dist/src/{handlers/commandHandlers → eventHandlers}/baseCommandHandler.js +5 -5
  28. package/dist/src/eventHandlers/baseCommandHandler.js.map +1 -0
  29. package/dist/src/{handlers/eventHandlers → eventHandlers}/baseEventHandler.d.ts +18 -18
  30. package/dist/src/{handlers/eventHandlers → eventHandlers}/baseEventHandler.js +3 -3
  31. package/dist/src/eventHandlers/baseEventHandler.js.map +1 -0
  32. package/dist/src/{handlers → eventHandlers}/baseHandler.d.ts +2 -3
  33. package/dist/src/{handlers → eventHandlers}/baseHandler.js +1 -0
  34. package/dist/src/eventHandlers/baseHandler.js.map +1 -0
  35. package/dist/src/{handlers/commandHandlers → eventHandlers}/commandHandlingModule.d.ts +3 -3
  36. package/dist/src/{handlers/commandHandlers → eventHandlers}/commandHandlingModule.js +3 -3
  37. package/dist/src/eventHandlers/commandHandlingModule.js.map +1 -0
  38. package/dist/src/{handlers/eventHandlers → eventHandlers}/eventHandlingModule.d.ts +7 -7
  39. package/dist/src/{handlers/eventHandlers → eventHandlers}/eventHandlingModule.js +9 -8
  40. package/dist/src/eventHandlers/eventHandlingModule.js.map +1 -0
  41. package/dist/src/{handlers/eventHandlers → eventHandlers}/syncFirestoreEvents.d.ts +3 -3
  42. package/dist/src/{handlers/eventHandlers → eventHandlers}/syncFirestoreEvents.js +3 -3
  43. package/dist/src/eventHandlers/syncFirestoreEvents.js.map +1 -0
  44. package/dist/src/exports/services.d.ts +2 -2
  45. package/dist/src/exports/services.js +2 -2
  46. package/dist/src/exports/services.js.map +1 -1
  47. package/dist/src/exports/sourcing.d.ts +3 -4
  48. package/dist/src/exports/sourcing.js +3 -18
  49. package/dist/src/exports/sourcing.js.map +1 -1
  50. package/dist/src/exports/utils.d.ts +0 -2
  51. package/dist/src/exports/utils.js +0 -2
  52. package/dist/src/exports/utils.js.map +1 -1
  53. package/dist/src/helpers/dataStructure.helpers.d.ts +0 -2
  54. package/dist/src/helpers/dataStructure.helpers.js +0 -32
  55. package/dist/src/helpers/dataStructure.helpers.js.map +1 -1
  56. package/dist/src/initializers/logger.service.d.ts +0 -4
  57. package/dist/src/initializers/logger.service.js +0 -14
  58. package/dist/src/initializers/logger.service.js.map +1 -1
  59. package/dist/src/initializers/queue-manager.service.d.ts +2 -2
  60. package/dist/src/initializers/queue-manager.service.js +10 -17
  61. package/dist/src/initializers/queue-manager.service.js.map +1 -1
  62. package/dist/src/rpc/abstractRpcClient.d.ts +6 -13
  63. package/dist/src/rpc/abstractRpcClient.js +29 -76
  64. package/dist/src/rpc/abstractRpcClient.js.map +1 -1
  65. package/dist/src/rpc/returnEventService.rpc.js +1 -8
  66. package/dist/src/rpc/returnEventService.rpc.js.map +1 -1
  67. package/dist/src/rpc/rpcModule.js +1 -4
  68. package/dist/src/rpc/rpcModule.js.map +1 -1
  69. package/dist/src/testUtils/testDependencies.js +1 -2
  70. package/dist/src/testUtils/testDependencies.js.map +1 -1
  71. package/dist/test/testImplementations/testCommandHandler.d.ts +1 -1
  72. package/dist/test/testImplementations/testCommandHandler.js +1 -1
  73. package/dist/test/testImplementations/testCommandHandler.js.map +1 -1
  74. package/dist/test/testImplementations/testEventHandler.d.ts +1 -1
  75. package/dist/test/testImplementations/testEventHandler.js +1 -1
  76. package/dist/test/testImplementations/testEventHandler.js.map +1 -1
  77. package/dist/test/testImplementations/testFirestoreEventSync.js +1 -1
  78. package/dist/test/testImplementations/testFirestoreEventSync.js.map +1 -1
  79. package/dist/test/tests/clients/opensearch.client.spec.js +72 -1
  80. package/dist/test/tests/clients/opensearch.client.spec.js.map +1 -1
  81. package/dist/test/tests/common.js +5 -10
  82. package/dist/test/tests/common.js.map +1 -1
  83. package/dist/test/tests/helpers/syncOpensearch.spec.js +43 -0
  84. package/dist/test/tests/helpers/syncOpensearch.spec.js.map +1 -1
  85. package/package.json +2 -4
  86. package/dist/src/handlers/baseHandler.js.map +0 -1
  87. package/dist/src/handlers/commandHandlers/baseCommandHandler.js.map +0 -1
  88. package/dist/src/handlers/commandHandlers/commandHandlingModule.js.map +0 -1
  89. package/dist/src/handlers/crud/baseHandlers.d.ts +0 -26
  90. package/dist/src/handlers/crud/baseHandlers.js +0 -129
  91. package/dist/src/handlers/crud/baseHandlers.js.map +0 -1
  92. package/dist/src/handlers/crud/createProjectionHandler.d.ts +0 -10
  93. package/dist/src/handlers/crud/createProjectionHandler.js +0 -73
  94. package/dist/src/handlers/crud/createProjectionHandler.js.map +0 -1
  95. package/dist/src/handlers/crud/createUpdateProjectionHandler.d.ts +0 -10
  96. package/dist/src/handlers/crud/createUpdateProjectionHandler.js +0 -65
  97. package/dist/src/handlers/crud/createUpdateProjectionHandler.js.map +0 -1
  98. package/dist/src/handlers/crud/decorators.d.ts +0 -9
  99. package/dist/src/handlers/crud/decorators.js +0 -11
  100. package/dist/src/handlers/crud/decorators.js.map +0 -1
  101. package/dist/src/handlers/crud/deleteProjectionHandler.d.ts +0 -9
  102. package/dist/src/handlers/crud/deleteProjectionHandler.js +0 -43
  103. package/dist/src/handlers/crud/deleteProjectionHandler.js.map +0 -1
  104. package/dist/src/handlers/crud/getProjectionHandler.d.ts +0 -12
  105. package/dist/src/handlers/crud/getProjectionHandler.js +0 -58
  106. package/dist/src/handlers/crud/getProjectionHandler.js.map +0 -1
  107. package/dist/src/handlers/crud/getProjectionsHandler.d.ts +0 -11
  108. package/dist/src/handlers/crud/getProjectionsHandler.js +0 -76
  109. package/dist/src/handlers/crud/getProjectionsHandler.js.map +0 -1
  110. package/dist/src/handlers/crud/helpers.d.ts +0 -36
  111. package/dist/src/handlers/crud/helpers.js +0 -233
  112. package/dist/src/handlers/crud/helpers.js.map +0 -1
  113. package/dist/src/handlers/crud/index.d.ts +0 -33
  114. package/dist/src/handlers/crud/index.js +0 -108
  115. package/dist/src/handlers/crud/index.js.map +0 -1
  116. package/dist/src/handlers/crud/schemaHandler.d.ts +0 -24
  117. package/dist/src/handlers/crud/schemaHandler.js +0 -158
  118. package/dist/src/handlers/crud/schemaHandler.js.map +0 -1
  119. package/dist/src/handlers/crud/searchProjectionsHandler.d.ts +0 -10
  120. package/dist/src/handlers/crud/searchProjectionsHandler.js +0 -226
  121. package/dist/src/handlers/crud/searchProjectionsHandler.js.map +0 -1
  122. package/dist/src/handlers/crud/types.d.ts +0 -49
  123. package/dist/src/handlers/crud/types.js +0 -42
  124. package/dist/src/handlers/crud/types.js.map +0 -1
  125. package/dist/src/handlers/eventHandlers/baseEventHandler.js.map +0 -1
  126. package/dist/src/handlers/eventHandlers/eventHandlingModule.js.map +0 -1
  127. package/dist/src/handlers/eventHandlers/syncFirestoreEvents.js.map +0 -1
  128. package/dist/src/helpers/string.helpers.d.ts +0 -3
  129. package/dist/src/helpers/string.helpers.js +0 -24
  130. package/dist/src/helpers/string.helpers.js.map +0 -1
  131. package/dist/src/helpers/typeManipulation/classValidation.d.ts +0 -7
  132. package/dist/src/helpers/typeManipulation/classValidation.js +0 -30
  133. package/dist/src/helpers/typeManipulation/classValidation.js.map +0 -1
  134. package/dist/src/helpers/typeManipulation/decorators.d.ts +0 -16
  135. package/dist/src/helpers/typeManipulation/decorators.js +0 -144
  136. package/dist/src/helpers/typeManipulation/decorators.js.map +0 -1
  137. package/dist/src/helpers/typeManipulation/dynamicClasses.d.ts +0 -7
  138. package/dist/src/helpers/typeManipulation/dynamicClasses.js +0 -54
  139. package/dist/src/helpers/typeManipulation/dynamicClasses.js.map +0 -1
  140. package/dist/src/helpers/typeManipulation/index.d.ts +0 -3
  141. package/dist/src/helpers/typeManipulation/index.js +0 -20
  142. package/dist/src/helpers/typeManipulation/index.js.map +0 -1
  143. package/dist/src/testUtils/mocks/openSearch.client.mock.d.ts +0 -102
  144. package/dist/src/testUtils/mocks/openSearch.client.mock.js +0 -405
  145. package/dist/src/testUtils/mocks/openSearch.client.mock.js.map +0 -1
  146. package/dist/test/testImplementations/testCrud.d.ts +0 -48
  147. package/dist/test/testImplementations/testCrud.js +0 -233
  148. package/dist/test/testImplementations/testCrud.js.map +0 -1
  149. package/dist/test/tests/eventHandlers/crudHandlers.spec.d.ts +0 -1
  150. package/dist/test/tests/eventHandlers/crudHandlers.spec.js +0 -691
  151. package/dist/test/tests/eventHandlers/crudHandlers.spec.js.map +0 -1
  152. package/dist/test/tests/helpers/decorators.spec.d.ts +0 -1
  153. package/dist/test/tests/helpers/decorators.spec.js +0 -109
  154. package/dist/test/tests/helpers/decorators.spec.js.map +0 -1
@@ -1,691 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const class_validator_1 = require("class-validator");
7
- const class_transformer_1 = require("class-transformer");
8
- const crypto_1 = require("crypto");
9
- const chai_1 = require("chai");
10
- const lodash_1 = require("lodash");
11
- const exports_1 = require("../../../src/exports");
12
- const testCrud_1 = require("../../testImplementations/testCrud");
13
- const common_1 = require("../common");
14
- const assert_1 = require("assert");
15
- const createProjectionHandler_1 = require("../../../src/handlers/crud/createProjectionHandler");
16
- const createUpdateProjectionHandler_1 = require("../../../src/handlers/crud/createUpdateProjectionHandler");
17
- const errors_1 = require("../../../src/clients/openSearch/errors");
18
- const haversine_distance_1 = __importDefault(require("haversine-distance"));
19
- function doValidate(e, type, expectedError) {
20
- const instance = (0, class_transformer_1.plainToInstance)(type, e);
21
- const errors = (0, class_validator_1.validateSync)(instance);
22
- if (expectedError) {
23
- (0, chai_1.expect)(errors.join(", ")).to.include(expectedError);
24
- }
25
- else if (errors.length) {
26
- throw new Error(errors.join(", "));
27
- }
28
- }
29
- class CreateExampleRequest extends (0, createProjectionHandler_1.createCreateRequest)(testCrud_1.ExampleProjection) {
30
- }
31
- class UpdateExampleRequest extends (0, createUpdateProjectionHandler_1.createUpdateRequest)(testCrud_1.ExampleProjection) {
32
- }
33
- describe("Abstract CRUD handler", () => {
34
- let appContainer;
35
- let deps;
36
- before(async () => {
37
- appContainer = await (0, common_1.getTestAppContainer)();
38
- deps = await (0, exports_1.getTestDependencies)(appContainer);
39
- });
40
- (0, exports_1.registerTestHooks)(() => deps);
41
- describe("Type Validation", () => {
42
- it("Should properly handle a create request", async () => {
43
- doValidate({ companyId: deps.companyId, ...(0, lodash_1.omit)(testCrud_1.exampleProjection, "id") }, CreateExampleRequest);
44
- });
45
- it("Should properly handle an update request", async () => {
46
- doValidate({
47
- companyId: deps.companyId,
48
- id: (0, crypto_1.randomUUID)(),
49
- optionalEditableObject: {
50
- optionalEditableNumber: 9,
51
- },
52
- }, UpdateExampleRequest);
53
- });
54
- it("Should fail update request for invalid types", async () => {
55
- doValidate({
56
- companyId: deps.companyId,
57
- id: (0, crypto_1.randomUUID)(),
58
- optionalEditableNumber: "string",
59
- }, CreateExampleRequest, "property optionalEditableNumber has failed the following constraints: isNumber");
60
- });
61
- it("Should fail update of nested field", async () => {
62
- doValidate({
63
- companyId: deps.companyId,
64
- id: (0, crypto_1.randomUUID)(),
65
- optionalEditableObject: {
66
- optionalEditableNumber: "9",
67
- },
68
- }, CreateExampleRequest, "property optionalEditableObject.optionalEditableNumber has failed the following constraints: isNumber");
69
- });
70
- });
71
- describe("createProjectionHandler", () => {
72
- it("Should create a new projection", async () => {
73
- const { id } = await deps.rpc("createExampleProjection", {
74
- ...testCrud_1.exampleProjection,
75
- companyId: deps.companyId,
76
- });
77
- const loaded = await deps.projectionRepository.loadItem({
78
- companyId: deps.companyId,
79
- projectionType: "exampleProjection",
80
- entityId: id,
81
- });
82
- (0, chai_1.expect)(loaded.payload).to.deep.equal({
83
- companyId: deps.companyId,
84
- ...testCrud_1.exampleProjection,
85
- });
86
- });
87
- it("Should allow a custom creationRequest", async () => {
88
- const creationRequestEntityId = (0, crypto_1.randomUUID)();
89
- const creationRequestProjection = await deps.projectionRepository.putItem({
90
- companyId: deps.companyId,
91
- projectionType: "creationRequestProjection",
92
- entityId: creationRequestEntityId,
93
- payload: {
94
- companyId: deps.companyId,
95
- id: creationRequestEntityId,
96
- name: "Requested Projection Name",
97
- },
98
- });
99
- const { id } = await deps.rpc("createCreationRequestProjection", {
100
- companyId: deps.companyId,
101
- requestedId: creationRequestEntityId,
102
- });
103
- const projection = await deps.projectionRepository.loadItem({
104
- companyId: deps.companyId,
105
- projectionType: "creationRequestProjection",
106
- entityId: id,
107
- });
108
- (0, chai_1.expect)(projection.payload).to.deep.equal(creationRequestProjection.payload);
109
- });
110
- it("Should allow a nested custom creationRequest", async () => {
111
- const creationRequestEntityId = (0, crypto_1.randomUUID)();
112
- const creationRequestProjection = await deps.projectionRepository.putItem({
113
- companyId: deps.companyId,
114
- projectionType: "creationRequestProjection",
115
- entityId: creationRequestEntityId,
116
- payload: {
117
- companyId: deps.companyId,
118
- id: creationRequestEntityId,
119
- name: "Requested Projection Name",
120
- },
121
- });
122
- const { id } = await deps.rpc("createCreationRequestProjectionEnvelope", {
123
- companyId: deps.companyId,
124
- projection: {
125
- companyId: deps.companyId,
126
- requestedId: creationRequestEntityId,
127
- },
128
- });
129
- const projection = await deps.projectionRepository.loadItem({
130
- companyId: deps.companyId,
131
- projectionType: "creationRequestProjectionEnvelope",
132
- entityId: id,
133
- });
134
- (0, chai_1.expect)(projection.payload).to.deep.equal({
135
- companyId: deps.companyId,
136
- id,
137
- projection: creationRequestProjection.payload,
138
- });
139
- });
140
- it("Should allow an array of creationRequests", async () => {
141
- const projections = [];
142
- for (let i = 0; i < 5; i++) {
143
- const entityId = (0, crypto_1.randomUUID)();
144
- const projection = await deps.projectionRepository.putItem({
145
- companyId: deps.companyId,
146
- projectionType: "creationRequestProjection",
147
- entityId,
148
- payload: {
149
- companyId: deps.companyId,
150
- id: entityId,
151
- name: "Requested Projection Name",
152
- },
153
- });
154
- projections.push(projection.payload);
155
- }
156
- const { id } = await deps.rpc("createCreationRequestArray", {
157
- companyId: deps.companyId,
158
- projections: projections.map(({ id }) => ({
159
- companyId: deps.companyId,
160
- requestedId: id,
161
- })),
162
- });
163
- const projection = await deps.projectionRepository.loadItem({
164
- companyId: deps.companyId,
165
- projectionType: "creationRequestArray",
166
- entityId: id,
167
- });
168
- (0, chai_1.expect)(projection.payload).to.deep.equal({
169
- companyId: deps.companyId,
170
- id,
171
- projections,
172
- });
173
- });
174
- });
175
- describe("updateProjectionHandler", () => {
176
- let entityId;
177
- beforeEach(async () => {
178
- entityId = (0, crypto_1.randomUUID)();
179
- await deps.projectionRepository.putItem({
180
- companyId: deps.companyId,
181
- projectionType: "exampleProjection",
182
- entityId,
183
- payload: testCrud_1.exampleProjection,
184
- });
185
- });
186
- it("Should fail without a companyId", async () => {
187
- const result = await deps.rpc("updateExampleProjection", {
188
- id: entityId,
189
- mandatoryEditableObject: {
190
- optionalEditableNumber: 1000,
191
- },
192
- }, exports_1.RpcResponseStatus.Error);
193
- (0, chai_1.expect)(result.errorKey).to.equal(exports_1.RpcErrorKey.ERROR_INVALID_FORMAT);
194
- });
195
- it("Should update legal fields in a projection", async () => {
196
- const { modified } = await deps.rpc("updateExampleProjection", {
197
- companyId: deps.companyId,
198
- id: entityId,
199
- mandatoryEditableObject: {
200
- optionalEditableNumber: 1000,
201
- },
202
- mandatoryEditableNumber: 50,
203
- });
204
- (0, chai_1.expect)(modified).to.be.true;
205
- const projection = await deps.projectionRepository.loadItem({
206
- companyId: deps.companyId,
207
- projectionType: "exampleProjection",
208
- entityId,
209
- });
210
- (0, chai_1.expect)(projection.payload).to.deep.equal({
211
- ...testCrud_1.exampleProjection,
212
- mandatoryEditableNumber: 50,
213
- mandatoryEditableObject: {
214
- ...testCrud_1.exampleProjection.mandatoryEditableObject,
215
- optionalEditableNumber: 1000,
216
- },
217
- });
218
- });
219
- it("Should fail updating illegal fields in a projection", async () => {
220
- const { errorMessage } = await deps.rpc("updateExampleProjection", {
221
- companyId: deps.companyId,
222
- id: entityId,
223
- mandatoryEditableObject: {
224
- mandatoryNumber: 100,
225
- },
226
- }, exports_1.RpcResponseStatus.Error);
227
- (0, chai_1.expect)(errorMessage).to.contain(".mandatoryNumber");
228
- const projection = await deps.projectionRepository.loadItem({
229
- companyId: deps.companyId,
230
- projectionType: "exampleProjection",
231
- entityId,
232
- });
233
- (0, chai_1.expect)(projection.payload).to.deep.equal(testCrud_1.exampleProjection);
234
- });
235
- it("Should allow un-editable fields to be provided if they don't change", async () => {
236
- const { modified } = await deps.rpc("updateExampleProjection", {
237
- ...testCrud_1.exampleProjection,
238
- companyId: deps.companyId,
239
- id: entityId,
240
- mandatoryEditableObject: {
241
- optionalEditableNumber: 10000,
242
- },
243
- });
244
- (0, chai_1.expect)(modified).to.be.true;
245
- const projection = await deps.projectionRepository.loadItem({
246
- companyId: deps.companyId,
247
- projectionType: "exampleProjection",
248
- entityId,
249
- });
250
- (0, chai_1.expect)(projection.payload).to.deep.equal({
251
- ...testCrud_1.exampleProjection,
252
- mandatoryEditableObject: {
253
- ...testCrud_1.exampleProjection.mandatoryEditableObject,
254
- optionalEditableNumber: 10000,
255
- },
256
- });
257
- });
258
- });
259
- describe("deleteProjectionHandler", () => {
260
- it("Should delete a projection", async () => {
261
- const entityId = (0, crypto_1.randomUUID)();
262
- await deps.projectionRepository.putItem({
263
- companyId: deps.companyId,
264
- projectionType: "exampleProjection",
265
- entityId,
266
- payload: testCrud_1.exampleProjection,
267
- });
268
- await deps.rpc("deleteExampleProjection", {
269
- companyId: deps.companyId,
270
- id: entityId,
271
- });
272
- try {
273
- await deps.projectionRepository.loadItem({
274
- companyId: deps.companyId,
275
- projectionType: "exampleProjection",
276
- entityId,
277
- });
278
- (0, assert_1.fail)();
279
- }
280
- catch (err) {
281
- (0, chai_1.expect)(err).to.be.instanceOf(exports_1.ItemDeleted);
282
- }
283
- });
284
- it("Should return NOT_FOUND when deleting a non-existent projection", async () => {
285
- const { errorKey } = await deps.rpc("deleteExampleProjection", { companyId: deps.companyId, id: (0, crypto_1.randomUUID)() }, exports_1.RpcResponseStatus.Error);
286
- (0, chai_1.expect)(errorKey).to.equal("NOT_FOUND");
287
- });
288
- });
289
- describe("searchProjectionHandler", () => {
290
- let entityIds;
291
- let projections;
292
- const lat0 = 75.0;
293
- const lon0 = 40.71;
294
- function getPoint(i) {
295
- return [lat0 + i / 1000, lon0 + i / 1000];
296
- }
297
- async function putProjection(i) {
298
- const entityId = (0, crypto_1.randomUUID)();
299
- entityIds.push(entityId);
300
- const [lat, lon] = getPoint(i);
301
- const projection = await deps.projectionRepository.putItem({
302
- companyId: deps.companyId,
303
- projectionType: "exampleProjection",
304
- entityId,
305
- payload: {
306
- id: entityId,
307
- latLon: `${lat},${lon}`,
308
- latLonObject: { lat, lon },
309
- mandatoryEditableObject: {
310
- optionalEditableString: `sorting by ${(0, crypto_1.randomInt)(1000)}`,
311
- mandatoryEditableString: `test value ${i}`,
312
- mandatoryEditableNumber: i * 100,
313
- mandatoryString: `testMandatoryString${i}`,
314
- mandatoryNumber: i * 100 + 1,
315
- },
316
- mandatoryObject: {
317
- mandatoryEditableString: `TestEditable${i % 2}`,
318
- mandatoryEditableNumber: i * 100 + 2,
319
- mandatoryString: "",
320
- mandatoryNumber: i * 100 + 3,
321
- },
322
- mandatoryEditableString: "",
323
- mandatoryEditableNumber: i * 100 + 4,
324
- mandatoryString: "",
325
- mandatoryNumber: i * 100 + 5,
326
- },
327
- });
328
- await deps.openSearch.indexProjection(projection);
329
- return projection;
330
- }
331
- function sortBy(projections, key, direction) {
332
- if (direction === "asc") {
333
- return projections.sort((a, b) => key(a).localeCompare(key(b)));
334
- }
335
- else {
336
- return projections.sort((a, b) => key(b).localeCompare(key(a)));
337
- }
338
- }
339
- function sortById(projections, direction = "asc") {
340
- return sortBy(projections, (p) => p.id, direction);
341
- }
342
- function sortByQuery(projections, direction = "desc") {
343
- return sortBy(projections, (p) => p.mandatoryEditableObject.optionalEditableString, direction);
344
- }
345
- function getExpectedResults(projections) {
346
- return projections
347
- .filter((_, i) => i % 2 === 0)
348
- .map(({ payload }) => payload);
349
- }
350
- const query = {
351
- mandatoryObject: {
352
- mandatoryEditableString: "TestEditable0",
353
- },
354
- };
355
- const sort = {
356
- mandatoryEditableObject: {
357
- optionalEditableString: "desc",
358
- },
359
- };
360
- function doSearch(args, expectError) {
361
- if (expectError) {
362
- return deps.rpc("searchExampleProjections", {
363
- companyId: deps.companyId,
364
- ...args,
365
- }, exports_1.RpcResponseStatus.Error);
366
- }
367
- else {
368
- return deps.rpc("searchExampleProjections", {
369
- companyId: deps.companyId,
370
- ...args,
371
- });
372
- }
373
- }
374
- beforeEach(async () => {
375
- entityIds = [];
376
- projections = [];
377
- for (let i = 0; i < 10; i++) {
378
- projections.push(await putProjection(i));
379
- }
380
- });
381
- it("Should find a nested string match", async () => {
382
- const { results } = await doSearch({
383
- query: {
384
- mandatoryEditableObject: {
385
- mandatoryEditableString: "test value 4",
386
- },
387
- },
388
- });
389
- (0, chai_1.expect)(results).to.deep.equal([projections[4].payload]);
390
- });
391
- it("Should limit queries when requested", async () => {
392
- const { results, continuationToken } = await doSearch({
393
- query,
394
- limit: 2,
395
- });
396
- (0, chai_1.expect)(results.length).to.equal(2);
397
- (0, chai_1.expect)(continuationToken).to.not.be.empty;
398
- });
399
- it("Should properly paginate queries", async () => {
400
- const results = [];
401
- let continuationToken;
402
- do {
403
- const response = await doSearch({
404
- query,
405
- continuationToken,
406
- limit: 2,
407
- });
408
- results.push(...response.results);
409
- continuationToken = response.continuationToken;
410
- } while (continuationToken);
411
- (0, chai_1.expect)(sortById(results)).to.deep.equal(sortById(getExpectedResults(projections)));
412
- });
413
- it("Should properly sort an individual query", async () => {
414
- const { results, continuationToken } = await doSearch({
415
- query,
416
- sort,
417
- });
418
- (0, chai_1.expect)(continuationToken).to.be.undefined;
419
- (0, chai_1.expect)(results).to.deep.equal(sortByQuery(getExpectedResults(projections)));
420
- });
421
- it("Should properly sort a paginated query", async () => {
422
- const results = [];
423
- let continuationToken;
424
- do {
425
- const response = await doSearch({
426
- query,
427
- sort,
428
- continuationToken,
429
- limit: 2,
430
- });
431
- results.push(...response.results);
432
- continuationToken = response.continuationToken;
433
- } while (continuationToken);
434
- (0, chai_1.expect)(results).to.deep.equal(sortByQuery(getExpectedResults(projections)));
435
- });
436
- it("Should paginate over a point-in-time snapshot", async function () {
437
- if (deps.openSearch.isFakeClient) {
438
- this.skip();
439
- }
440
- const results = [];
441
- let continuationToken;
442
- let i = 10;
443
- do {
444
- const response = await doSearch({
445
- query,
446
- continuationToken,
447
- limit: 2,
448
- });
449
- results.push(...response.results);
450
- continuationToken = response.continuationToken;
451
- for (let j = 0; j < 4; j++) {
452
- await putProjection(i++);
453
- }
454
- } while (continuationToken);
455
- (0, chai_1.expect)(sortById(results)).to.deep.equal(sortById(getExpectedResults(projections)));
456
- });
457
- it("Should delete the point-in-time search when results are exhausted", async function () {
458
- if (deps.openSearch.isFakeClient) {
459
- this.skip();
460
- }
461
- let firstContinuationToken;
462
- let continuationToken;
463
- do {
464
- const response = await doSearch({
465
- query,
466
- continuationToken,
467
- limit: 2,
468
- });
469
- continuationToken = response.continuationToken;
470
- if (continuationToken) {
471
- if (!firstContinuationToken) {
472
- firstContinuationToken = continuationToken;
473
- }
474
- }
475
- else {
476
- if (!firstContinuationToken) {
477
- (0, assert_1.fail)("unexpected");
478
- }
479
- }
480
- } while (continuationToken);
481
- try {
482
- await deps.openSearch.searchProjections(deps.companyId, "exampleProjection", {
483
- mandatoryObject: { mandatoryEditableString: "TestEditable0" },
484
- }, undefined, undefined, undefined, firstContinuationToken);
485
- (0, assert_1.fail)();
486
- }
487
- catch (err) {
488
- (0, chai_1.expect)(err).to.be.instanceOf(errors_1.ExpiredPointInTime);
489
- }
490
- });
491
- it("Should successfully handle an expired point-in-time id", async () => {
492
- const results = [];
493
- const adminClient = await appContainer.getAsync(exports_1.OpensearchAdminClient);
494
- let continuationToken;
495
- do {
496
- const response = await doSearch({
497
- query,
498
- continuationToken,
499
- limit: 2,
500
- });
501
- results.push(...response.results);
502
- continuationToken = response.continuationToken;
503
- if (continuationToken) {
504
- const [pit_id] = continuationToken.split(":");
505
- await adminClient.expirePointInTime(pit_id);
506
- }
507
- } while (continuationToken);
508
- (0, chai_1.expect)(sortById(results)).to.deep.equal(sortById(getExpectedResults(projections)));
509
- });
510
- it("Should allow queries with point-in-time explicitly disabled", async () => {
511
- const results = [];
512
- let continuationToken;
513
- do {
514
- const response = await doSearch({
515
- query,
516
- continuationToken,
517
- limit: 2,
518
- pointInTime: false,
519
- });
520
- results.push(...response.results);
521
- continuationToken = response.continuationToken;
522
- } while (continuationToken);
523
- (0, chai_1.expect)(sortById(results)).to.deep.equal(sortById(getExpectedResults(projections)));
524
- });
525
- describe("Geospatial", async () => {
526
- it("Should find entries by distance", async () => {
527
- const fourthDistance = (0, haversine_distance_1.default)({ lat: lat0, lon: lon0 }, { lat: getPoint(3)[0], lon: getPoint(3)[1] });
528
- const fifthDistance = (0, haversine_distance_1.default)({ lat: lat0, lon: lon0 }, { lat: getPoint(4)[0], lon: getPoint(4)[1] });
529
- const maxDistance = (fourthDistance + fifthDistance) / 2;
530
- const units = "meters";
531
- const { results } = await doSearch({
532
- query: {
533
- latLonObject: {
534
- distance: maxDistance,
535
- units,
536
- lat: lat0,
537
- lon: lon0,
538
- },
539
- },
540
- limit: 5,
541
- });
542
- (0, chai_1.expect)(results.length).to.equal(4);
543
- for (const result of results) {
544
- const distance = (0, haversine_distance_1.default)({ lat: lat0, lon: lon0 }, result.latLonObject);
545
- (0, chai_1.expect)(distance).to.be.lessThan(maxDistance);
546
- }
547
- });
548
- it("Should find entries by bounding box", async () => {
549
- const { results } = await doSearch({
550
- query: {
551
- latLonObject: {
552
- top: lat0 + 1.2,
553
- left: lon0,
554
- bottom: lat0,
555
- right: lon0 + 1.5,
556
- },
557
- },
558
- });
559
- (0, chai_1.expect)(results).to.not.be.empty;
560
- for (const result of results) {
561
- (0, chai_1.expect)(result.latLonObject.lat).to.be.greaterThanOrEqual(lat0);
562
- (0, chai_1.expect)(result.latLonObject.lat).to.be.lessThanOrEqual(lat0 + 1.5);
563
- (0, chai_1.expect)(result.latLonObject.lon).to.be.greaterThanOrEqual(lon0);
564
- (0, chai_1.expect)(result.latLonObject.lon).to.be.lessThanOrEqual(lon0 + 1.5);
565
- }
566
- });
567
- });
568
- });
569
- describe("getProjectionHandler", async () => {
570
- function getProjection(id) {
571
- return deps.rpc("getExampleProjection", {
572
- companyId: deps.companyId,
573
- id,
574
- });
575
- }
576
- it("Should find an entity by id", async () => {
577
- const entityId = (0, crypto_1.randomUUID)();
578
- await deps.projectionRepository.putItem({
579
- companyId: deps.companyId,
580
- projectionType: "exampleProjection",
581
- entityId,
582
- payload: testCrud_1.exampleProjection,
583
- });
584
- const result = await deps.rpc("getExampleProjection", {
585
- companyId: deps.companyId,
586
- id: entityId,
587
- });
588
- (0, chai_1.expect)(result.projection).to.deep.equal(testCrud_1.exampleProjection);
589
- });
590
- it("Should return undefined if the id does not exist", async () => {
591
- const result = await deps.rpc("getExampleProjection", {
592
- companyId: deps.companyId,
593
- id: (0, crypto_1.randomUUID)(),
594
- });
595
- (0, chai_1.expect)(result).to.deep.equal({});
596
- });
597
- });
598
- describe("getProjectionsHandler", () => {
599
- let projectionStore;
600
- beforeEach(async () => {
601
- projectionStore = [];
602
- for (let i = 0; i < 10; i++) {
603
- const entityId = (0, crypto_1.randomUUID)();
604
- const projection = await deps.projectionRepository.putItem({
605
- companyId: deps.companyId,
606
- projectionType: "exampleProjection",
607
- entityId,
608
- payload: {
609
- id: entityId,
610
- mandatoryEditableObject: {
611
- mandatoryEditableString: `mandatoryEditableObject${i * 100}`,
612
- mandatoryEditableNumber: i * 100 + 1,
613
- mandatoryString: `mandatoryString${i * 100 + 2}`,
614
- mandatoryNumber: i * 100 + 3,
615
- },
616
- mandatoryObject: {
617
- mandatoryEditableString: `mandatoryEditableString${i * 100 + 4}`,
618
- mandatoryEditableNumber: i * 100 + 5,
619
- mandatoryString: `mandatoryString${i * 100 + 6}`,
620
- mandatoryNumber: i * 100 + 7,
621
- },
622
- mandatoryEditableString: `mandatoryEditableString${i * 100 + 8}`,
623
- mandatoryEditableNumber: i * 100 + 9,
624
- mandatoryString: `mandatoryString${i + 100 + 10}`,
625
- mandatoryNumber: i * 100 + 11,
626
- },
627
- }, testCrud_1.ExampleProjection);
628
- projectionStore.push(projection);
629
- }
630
- });
631
- function doRpc(ids) {
632
- return deps.rpc("getExampleProjections", {
633
- companyId: deps.companyId,
634
- ids,
635
- });
636
- }
637
- it("Should fetch all the requested projections if they exist", async () => {
638
- const { projections, missing } = await doRpc(projectionStore.slice(3, 8).map((p) => p.entityId));
639
- (0, chai_1.expect)(projections).to.deep.equal(projectionStore.slice(3, 8).map((p) => p.payload));
640
- (0, chai_1.expect)(missing).to.be.empty;
641
- });
642
- it("Should fetch a single requested projection", async () => {
643
- const { projections, missing } = await doRpc([
644
- projectionStore[5].entityId,
645
- ]);
646
- (0, chai_1.expect)(projections).to.deep.equal([projectionStore[5].payload]);
647
- (0, chai_1.expect)(missing).to.be.empty;
648
- });
649
- it("Should return an empty array if none are requested", async () => {
650
- const { projections, missing } = await doRpc([]);
651
- (0, chai_1.expect)(projections).to.be.empty;
652
- (0, chai_1.expect)(missing).to.be.empty;
653
- });
654
- it("Should return an empty array if none are found", async () => {
655
- const ids = [];
656
- for (let i = 0; i < 10; i++) {
657
- ids.push((0, crypto_1.randomUUID)());
658
- }
659
- const { projections, missing } = await doRpc(ids);
660
- (0, chai_1.expect)(projections).to.be.empty;
661
- (0, chai_1.expect)(missing).to.deep.equal(ids);
662
- });
663
- });
664
- describe("SchemaHandler", () => {
665
- [
666
- ["get", "getExampleProjectionSchema"],
667
- ["get-multiple", "getExampleProjectionsSchema"],
668
- ["create", "createExampleProjectionSchema"],
669
- ["update", "updateExampleProjectionSchema"],
670
- ["delete", "deleteExampleProjectionSchema"],
671
- ["search", "searchExampleProjectionsSchema"],
672
- ["create-with-request", "createCreationRequestProjectionSchema"],
673
- [
674
- "create-with-nested-request",
675
- "createCreationRequestProjectionEnvelopeSchema",
676
- ],
677
- ].forEach(([action, routingKey]) => {
678
- it(`Should fetch the ${action} schema for a projection`, async () => {
679
- const { requestSchema, responseSchema } = await deps.rpc(routingKey, {});
680
- console.log("----");
681
- console.log("requestSchema");
682
- console.log(requestSchema);
683
- console.log("----");
684
- console.log("responseSchema");
685
- console.log(responseSchema);
686
- console.log("----");
687
- });
688
- });
689
- });
690
- });
691
- //# sourceMappingURL=crudHandlers.spec.js.map