@webiny/api-dynamodb-to-elasticsearch 6.3.0 → 6.4.0-beta.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.
@@ -1,4 +1,6 @@
1
1
  import { WebinyError } from "@webiny/error";
2
- export class NotEnoughRemainingTimeError extends WebinyError {}
2
+ class NotEnoughRemainingTimeError extends WebinyError {
3
+ }
4
+ export { NotEnoughRemainingTimeError };
3
5
 
4
6
  //# sourceMappingURL=NotEnoughRemainingTimeError.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","NotEnoughRemainingTimeError"],"sources":["NotEnoughRemainingTimeError.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\n\nexport class NotEnoughRemainingTimeError extends WebinyError {}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,eAAe;AAE3C,OAAO,MAAMC,2BAA2B,SAASD,WAAW,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"NotEnoughRemainingTimeError.js","sources":["../src/NotEnoughRemainingTimeError.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\n\nexport class NotEnoughRemainingTimeError extends WebinyError {}\n"],"names":["NotEnoughRemainingTimeError","WebinyError"],"mappings":";AAEO,MAAMA,oCAAoCC;AAAa"}
package/Operations.js CHANGED
@@ -1,39 +1,42 @@
1
- export let OperationType = /*#__PURE__*/function (OperationType) {
2
- OperationType["INSERT"] = "INSERT";
3
- OperationType["MODIFY"] = "MODIFY";
4
- OperationType["REMOVE"] = "REMOVE";
5
- return OperationType;
1
+ var Operations_OperationType = /*#__PURE__*/ function(OperationType) {
2
+ OperationType["INSERT"] = "INSERT";
3
+ OperationType["MODIFY"] = "MODIFY";
4
+ OperationType["REMOVE"] = "REMOVE";
5
+ return OperationType;
6
6
  }({});
7
- export class Operations {
8
- _items = [];
9
- get items() {
10
- return this._items;
11
- }
12
- get total() {
13
- return this.items.length;
14
- }
15
- clear() {
16
- this._items = [];
17
- }
18
- insert(params) {
19
- this.items.push({
20
- index: {
21
- _id: params.id,
22
- _index: params.index
23
- }
24
- }, params.data);
25
- }
26
- modify(params) {
27
- this.insert(params);
28
- }
29
- delete(params) {
30
- this.items.push({
31
- delete: {
32
- _id: params.id,
33
- _index: params.index
34
- }
35
- });
36
- }
7
+ class Operations {
8
+ get items() {
9
+ return this._items;
10
+ }
11
+ get total() {
12
+ return this.items.length;
13
+ }
14
+ clear() {
15
+ this._items = [];
16
+ }
17
+ insert(params) {
18
+ this.items.push({
19
+ index: {
20
+ _id: params.id,
21
+ _index: params.index
22
+ }
23
+ }, params.data);
24
+ }
25
+ modify(params) {
26
+ this.insert(params);
27
+ }
28
+ delete(params) {
29
+ this.items.push({
30
+ delete: {
31
+ _id: params.id,
32
+ _index: params.index
33
+ }
34
+ });
35
+ }
36
+ constructor(){
37
+ this._items = [];
38
+ }
37
39
  }
40
+ export { Operations, Operations_OperationType as OperationType };
38
41
 
39
42
  //# sourceMappingURL=Operations.js.map
package/Operations.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["OperationType","Operations","_items","items","total","length","clear","insert","params","push","index","_id","id","_index","data","modify","delete"],"sources":["Operations.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type {\n IDeleteOperationParams,\n IInsertOperationParams,\n IModifyOperationParams,\n IOperations\n} from \"~/types.js\";\n\nexport enum OperationType {\n INSERT = \"INSERT\",\n MODIFY = \"MODIFY\",\n REMOVE = \"REMOVE\"\n}\n\nexport class Operations implements IOperations {\n private _items: GenericRecord[] = [];\n\n public get items(): GenericRecord[] {\n return this._items;\n }\n\n public get total(): number {\n return this.items.length;\n }\n\n public clear() {\n this._items = [];\n }\n\n public insert(params: IInsertOperationParams): void {\n this.items.push(\n {\n index: {\n _id: params.id,\n _index: params.index\n }\n },\n params.data\n );\n }\n\n public modify(params: IModifyOperationParams): void {\n this.insert(params);\n }\n\n public delete(params: IDeleteOperationParams): void {\n this.items.push({\n delete: {\n _id: params.id,\n _index: params.index\n }\n });\n }\n}\n"],"mappings":"AAQA,WAAYA,aAAa,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA;AAMzB,OAAO,MAAMC,UAAU,CAAwB;EACnCC,MAAM,GAAoB,EAAE;EAEpC,IAAWC,KAAKA,CAAA,EAAoB;IAChC,OAAO,IAAI,CAACD,MAAM;EACtB;EAEA,IAAWE,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACD,KAAK,CAACE,MAAM;EAC5B;EAEOC,KAAKA,CAAA,EAAG;IACX,IAAI,CAACJ,MAAM,GAAG,EAAE;EACpB;EAEOK,MAAMA,CAACC,MAA8B,EAAQ;IAChD,IAAI,CAACL,KAAK,CAACM,IAAI,CACX;MACIC,KAAK,EAAE;QACHC,GAAG,EAAEH,MAAM,CAACI,EAAE;QACdC,MAAM,EAAEL,MAAM,CAACE;MACnB;IACJ,CAAC,EACDF,MAAM,CAACM,IACX,CAAC;EACL;EAEOC,MAAMA,CAACP,MAA8B,EAAQ;IAChD,IAAI,CAACD,MAAM,CAACC,MAAM,CAAC;EACvB;EAEOQ,MAAMA,CAACR,MAA8B,EAAQ;IAChD,IAAI,CAACL,KAAK,CAACM,IAAI,CAAC;MACZO,MAAM,EAAE;QACJL,GAAG,EAAEH,MAAM,CAACI,EAAE;QACdC,MAAM,EAAEL,MAAM,CAACE;MACnB;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"Operations.js","sources":["../src/Operations.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type {\n IDeleteOperationParams,\n IInsertOperationParams,\n IModifyOperationParams,\n IOperations\n} from \"~/types.js\";\n\nexport enum OperationType {\n INSERT = \"INSERT\",\n MODIFY = \"MODIFY\",\n REMOVE = \"REMOVE\"\n}\n\nexport class Operations implements IOperations {\n private _items: GenericRecord[] = [];\n\n public get items(): GenericRecord[] {\n return this._items;\n }\n\n public get total(): number {\n return this.items.length;\n }\n\n public clear() {\n this._items = [];\n }\n\n public insert(params: IInsertOperationParams): void {\n this.items.push(\n {\n index: {\n _id: params.id,\n _index: params.index\n }\n },\n params.data\n );\n }\n\n public modify(params: IModifyOperationParams): void {\n this.insert(params);\n }\n\n public delete(params: IDeleteOperationParams): void {\n this.items.push({\n delete: {\n _id: params.id,\n _index: params.index\n }\n });\n }\n}\n"],"names":["OperationType","Operations","params"],"mappings":"AAQO,IAAKA,2BAAaA,WAAAA,GAAAA,SAAbA,aAAa;;;;WAAbA;;AAML,MAAMC;IAGT,IAAW,QAAyB;QAChC,OAAO,IAAI,CAAC,MAAM;IACtB;IAEA,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM;IAC5B;IAEO,QAAQ;QACX,IAAI,CAAC,MAAM,GAAG,EAAE;IACpB;IAEO,OAAOC,MAA8B,EAAQ;QAChD,IAAI,CAAC,KAAK,CAAC,IAAI,CACX;YACI,OAAO;gBACH,KAAKA,OAAO,EAAE;gBACd,QAAQA,OAAO,KAAK;YACxB;QACJ,GACAA,OAAO,IAAI;IAEnB;IAEO,OAAOA,MAA8B,EAAQ;QAChD,IAAI,CAAC,MAAM,CAACA;IAChB;IAEO,OAAOA,MAA8B,EAAQ;QAChD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACZ,QAAQ;gBACJ,KAAKA,OAAO,EAAE;gBACd,QAAQA,OAAO,KAAK;YACxB;QACJ;IACJ;;aArCQ,MAAM,GAAoB,EAAE;;AAsCxC"}
@@ -1,94 +1,56 @@
1
- import { Operations, OperationType } from "./Operations.js";
1
+ import { OperationType, Operations } from "./Operations.js";
2
2
  import { unmarshall } from "./marshall.js";
3
- export class OperationsBuilder {
4
- constructor(params) {
5
- this.compressor = params.compressor;
6
- }
7
- async build(params) {
8
- const operations = new Operations();
9
- for (const record of params.records) {
10
- if (!record.dynamodb) {
11
- continue;
12
- } else if (!record.eventName) {
13
- console.error(`Could not get operation from the record, skipping event "${record.eventID}".`);
14
- continue;
15
- }
16
- const keys = unmarshall(record.dynamodb.Keys);
17
- if (!keys?.PK || !keys.SK) {
18
- console.error(`Could not get keys from the record, skipping event "${record.eventID}".`);
19
- continue;
20
- }
21
- const id = `${keys.PK}:${keys.SK}`;
22
-
23
- /**
24
- * On operations other than REMOVE we decompress the data and store it into the Elasticsearch.
25
- * No need to try to decompress if operation is REMOVE since there is no data sent into that operation.
26
- */
27
- if (record.eventName === OperationType.INSERT || record.eventName === OperationType.MODIFY) {
28
- const newImage = unmarshall(record.dynamodb.NewImage);
29
- /**
30
- * If there is no newImage, silently continue to the next operation.
31
- */
32
- if (!newImage || typeof newImage !== "object" || Object.keys(newImage).length === 0) {
33
- continue;
34
- }
35
- /**
36
- * Note that with the `REMOVE` event, there is no `NewImage` property. Which means,
37
- * if the `newImage` is `undefined`, we are dealing with a `REMOVE` event and we still
38
- * need to process it.
39
- */
40
- //
41
- else if (newImage.ignore === true) {
42
- // Nothing to log here, we are skipping the record intentionally.
43
- continue;
44
- }
45
- /**
46
- * Also, possibly there is no index?
47
- */
48
- //
49
- else if (!newImage.index) {
50
- console.error(`Could not get index from the new image, skipping event "${record.eventID}".`);
51
- console.log({
52
- newImage
53
- });
54
- continue;
55
- }
56
- /**
57
- * We must decompress the data that is going into the Elasticsearch.
58
- */
59
- const data = await this.compressor.decompress(newImage.data);
60
- /**
61
- * No point in writing null or undefined data into the Elasticsearch.
62
- * This might happen on some error while decompressing. We will log it.
63
- *
64
- * Data should NEVER be null or undefined in the Elasticsearch DynamoDB table, unless it is a delete operations.
65
- * If it is - it is a bug.
66
- */
67
- if (data === undefined || data === null) {
68
- console.error(`Could not get decompressed data, skipping ES operation "${record.eventName}", ID ${id}. Skipping...`);
69
- continue;
70
- }
71
- operations.insert({
72
- id,
73
- index: newImage.index,
74
- data
75
- });
76
- } else if (record.eventName === OperationType.REMOVE) {
77
- const oldImage = unmarshall(record.dynamodb.OldImage);
78
- /**
79
- * If there is no index found, silently continue to the next operation.
80
- */
81
- if (!oldImage?.index) {
82
- continue;
3
+ class OperationsBuilder {
4
+ constructor(params){
5
+ this.compressor = params.compressor;
6
+ }
7
+ async build(params) {
8
+ const operations = new Operations();
9
+ for (const record of params.records){
10
+ if (!record.dynamodb) continue;
11
+ if (!record.eventName) {
12
+ console.error(`Could not get operation from the record, skipping event "${record.eventID}".`);
13
+ continue;
14
+ }
15
+ const keys = unmarshall(record.dynamodb.Keys);
16
+ if (!keys?.PK || !keys.SK) {
17
+ console.error(`Could not get keys from the record, skipping event "${record.eventID}".`);
18
+ continue;
19
+ }
20
+ const id = `${keys.PK}:${keys.SK}`;
21
+ if (record.eventName === OperationType.INSERT || record.eventName === OperationType.MODIFY) {
22
+ const newImage = unmarshall(record.dynamodb.NewImage);
23
+ if (!newImage || "object" != typeof newImage || 0 === Object.keys(newImage).length) continue;
24
+ if (true === newImage.ignore) continue;
25
+ if (!newImage.index) {
26
+ console.error(`Could not get index from the new image, skipping event "${record.eventID}".`);
27
+ console.log({
28
+ newImage
29
+ });
30
+ continue;
31
+ }
32
+ const data = await this.compressor.decompress(newImage.data);
33
+ if (null == data) {
34
+ console.error(`Could not get decompressed data, skipping ES operation "${record.eventName}", ID ${id}. Skipping...`);
35
+ continue;
36
+ }
37
+ operations.insert({
38
+ id,
39
+ index: newImage.index,
40
+ data
41
+ });
42
+ } else if (record.eventName === OperationType.REMOVE) {
43
+ const oldImage = unmarshall(record.dynamodb.OldImage);
44
+ if (!oldImage?.index) continue;
45
+ operations.delete({
46
+ id,
47
+ index: oldImage.index
48
+ });
49
+ }
83
50
  }
84
- operations.delete({
85
- id,
86
- index: oldImage.index
87
- });
88
- }
51
+ return operations;
89
52
  }
90
- return operations;
91
- }
92
53
  }
54
+ export { OperationsBuilder };
93
55
 
94
56
  //# sourceMappingURL=OperationsBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Operations","OperationType","unmarshall","OperationsBuilder","constructor","params","compressor","build","operations","record","records","dynamodb","eventName","console","error","eventID","keys","Keys","PK","SK","id","INSERT","MODIFY","newImage","NewImage","Object","length","ignore","index","log","data","decompress","undefined","insert","REMOVE","oldImage","OldImage","delete"],"sources":["OperationsBuilder.ts"],"sourcesContent":["import type { IOperations, IOperationsBuilder, IOperationsBuilderBuildParams } from \"./types.js\";\nimport { Operations, OperationType } from \"~/Operations.js\";\nimport { unmarshall } from \"~/marshall.js\";\nimport type { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\ninterface RecordDynamoDbImage {\n data: {\n compression: string;\n value: string;\n };\n ignore?: boolean;\n index: string;\n}\n\ninterface RecordDynamoDbKeys {\n PK: string;\n SK: string;\n}\n\nexport interface IOperationsBuilderParams {\n compressor: CompressionHandler.Interface;\n}\n\nexport class OperationsBuilder implements IOperationsBuilder {\n private readonly compressor: CompressionHandler.Interface;\n\n public constructor(params: IOperationsBuilderParams) {\n this.compressor = params.compressor;\n }\n\n public async build(params: IOperationsBuilderBuildParams): Promise<IOperations> {\n const operations = new Operations();\n for (const record of params.records) {\n if (!record.dynamodb) {\n continue;\n } else if (!record.eventName) {\n console.error(\n `Could not get operation from the record, skipping event \"${record.eventID}\".`\n );\n continue;\n }\n\n const keys = unmarshall<RecordDynamoDbKeys>(record.dynamodb.Keys);\n if (!keys?.PK || !keys.SK) {\n console.error(\n `Could not get keys from the record, skipping event \"${record.eventID}\".`\n );\n continue;\n }\n\n const id = `${keys.PK}:${keys.SK}`;\n\n /**\n * On operations other than REMOVE we decompress the data and store it into the Elasticsearch.\n * No need to try to decompress if operation is REMOVE since there is no data sent into that operation.\n */\n if (\n record.eventName === OperationType.INSERT ||\n record.eventName === OperationType.MODIFY\n ) {\n const newImage = unmarshall<RecordDynamoDbImage>(record.dynamodb.NewImage);\n /**\n * If there is no newImage, silently continue to the next operation.\n */\n if (\n !newImage ||\n typeof newImage !== \"object\" ||\n Object.keys(newImage).length === 0\n ) {\n continue;\n }\n /**\n * Note that with the `REMOVE` event, there is no `NewImage` property. Which means,\n * if the `newImage` is `undefined`, we are dealing with a `REMOVE` event and we still\n * need to process it.\n */\n //\n else if (newImage.ignore === true) {\n // Nothing to log here, we are skipping the record intentionally.\n continue;\n }\n /**\n * Also, possibly there is no index?\n */\n //\n else if (!newImage.index) {\n console.error(\n `Could not get index from the new image, skipping event \"${record.eventID}\".`\n );\n console.log({ newImage });\n continue;\n }\n /**\n * We must decompress the data that is going into the Elasticsearch.\n */\n const data = await this.compressor.decompress(newImage.data);\n /**\n * No point in writing null or undefined data into the Elasticsearch.\n * This might happen on some error while decompressing. We will log it.\n *\n * Data should NEVER be null or undefined in the Elasticsearch DynamoDB table, unless it is a delete operations.\n * If it is - it is a bug.\n */\n if (data === undefined || data === null) {\n console.error(\n `Could not get decompressed data, skipping ES operation \"${record.eventName}\", ID ${id}. Skipping...`\n );\n continue;\n }\n\n operations.insert({\n id,\n index: newImage.index,\n data\n });\n } else if (record.eventName === OperationType.REMOVE) {\n const oldImage = unmarshall<RecordDynamoDbImage>(record.dynamodb.OldImage);\n /**\n * If there is no index found, silently continue to the next operation.\n */\n if (!oldImage?.index) {\n continue;\n }\n operations.delete({\n id,\n index: oldImage.index\n });\n }\n }\n return operations;\n }\n}\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"OperationsBuilder.js","sources":["../src/OperationsBuilder.ts"],"sourcesContent":["import type { IOperations, IOperationsBuilder, IOperationsBuilderBuildParams } from \"./types.js\";\nimport { Operations, OperationType } from \"~/Operations.js\";\nimport { unmarshall } from \"~/marshall.js\";\nimport type { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\ninterface RecordDynamoDbImage {\n data: {\n compression: string;\n value: string;\n };\n ignore?: boolean;\n index: string;\n}\n\ninterface RecordDynamoDbKeys {\n PK: string;\n SK: string;\n}\n\nexport interface IOperationsBuilderParams {\n compressor: CompressionHandler.Interface;\n}\n\nexport class OperationsBuilder implements IOperationsBuilder {\n private readonly compressor: CompressionHandler.Interface;\n\n public constructor(params: IOperationsBuilderParams) {\n this.compressor = params.compressor;\n }\n\n public async build(params: IOperationsBuilderBuildParams): Promise<IOperations> {\n const operations = new Operations();\n for (const record of params.records) {\n if (!record.dynamodb) {\n continue;\n } else if (!record.eventName) {\n console.error(\n `Could not get operation from the record, skipping event \"${record.eventID}\".`\n );\n continue;\n }\n\n const keys = unmarshall<RecordDynamoDbKeys>(record.dynamodb.Keys);\n if (!keys?.PK || !keys.SK) {\n console.error(\n `Could not get keys from the record, skipping event \"${record.eventID}\".`\n );\n continue;\n }\n\n const id = `${keys.PK}:${keys.SK}`;\n\n /**\n * On operations other than REMOVE we decompress the data and store it into the Elasticsearch.\n * No need to try to decompress if operation is REMOVE since there is no data sent into that operation.\n */\n if (\n record.eventName === OperationType.INSERT ||\n record.eventName === OperationType.MODIFY\n ) {\n const newImage = unmarshall<RecordDynamoDbImage>(record.dynamodb.NewImage);\n /**\n * If there is no newImage, silently continue to the next operation.\n */\n if (\n !newImage ||\n typeof newImage !== \"object\" ||\n Object.keys(newImage).length === 0\n ) {\n continue;\n }\n /**\n * Note that with the `REMOVE` event, there is no `NewImage` property. Which means,\n * if the `newImage` is `undefined`, we are dealing with a `REMOVE` event and we still\n * need to process it.\n */\n //\n else if (newImage.ignore === true) {\n // Nothing to log here, we are skipping the record intentionally.\n continue;\n }\n /**\n * Also, possibly there is no index?\n */\n //\n else if (!newImage.index) {\n console.error(\n `Could not get index from the new image, skipping event \"${record.eventID}\".`\n );\n console.log({ newImage });\n continue;\n }\n /**\n * We must decompress the data that is going into the Elasticsearch.\n */\n const data = await this.compressor.decompress(newImage.data);\n /**\n * No point in writing null or undefined data into the Elasticsearch.\n * This might happen on some error while decompressing. We will log it.\n *\n * Data should NEVER be null or undefined in the Elasticsearch DynamoDB table, unless it is a delete operations.\n * If it is - it is a bug.\n */\n if (data === undefined || data === null) {\n console.error(\n `Could not get decompressed data, skipping ES operation \"${record.eventName}\", ID ${id}. Skipping...`\n );\n continue;\n }\n\n operations.insert({\n id,\n index: newImage.index,\n data\n });\n } else if (record.eventName === OperationType.REMOVE) {\n const oldImage = unmarshall<RecordDynamoDbImage>(record.dynamodb.OldImage);\n /**\n * If there is no index found, silently continue to the next operation.\n */\n if (!oldImage?.index) {\n continue;\n }\n operations.delete({\n id,\n index: oldImage.index\n });\n }\n }\n return operations;\n }\n}\n"],"names":["OperationsBuilder","params","operations","Operations","record","console","keys","unmarshall","id","OperationType","newImage","Object","data","oldImage"],"mappings":";;AAuBO,MAAMA;IAGT,YAAmBC,MAAgC,CAAE;QACjD,IAAI,CAAC,UAAU,GAAGA,OAAO,UAAU;IACvC;IAEA,MAAa,MAAMA,MAAqC,EAAwB;QAC5E,MAAMC,aAAa,IAAIC;QACvB,KAAK,MAAMC,UAAUH,OAAO,OAAO,CAAE;YACjC,IAAI,CAACG,OAAO,QAAQ,EAChB;YACG,IAAI,CAACA,OAAO,SAAS,EAAE;gBAC1BC,QAAQ,KAAK,CACT,CAAC,yDAAyD,EAAED,OAAO,OAAO,CAAC,EAAE,CAAC;gBAElF;YACJ;YAEA,MAAME,OAAOC,WAA+BH,OAAO,QAAQ,CAAC,IAAI;YAChE,IAAI,CAACE,MAAM,MAAM,CAACA,KAAK,EAAE,EAAE;gBACvBD,QAAQ,KAAK,CACT,CAAC,oDAAoD,EAAED,OAAO,OAAO,CAAC,EAAE,CAAC;gBAE7E;YACJ;YAEA,MAAMI,KAAK,GAAGF,KAAK,EAAE,CAAC,CAAC,EAAEA,KAAK,EAAE,EAAE;YAMlC,IACIF,OAAO,SAAS,KAAKK,cAAc,MAAM,IACzCL,OAAO,SAAS,KAAKK,cAAc,MAAM,EAC3C;gBACE,MAAMC,WAAWH,WAAgCH,OAAO,QAAQ,CAAC,QAAQ;gBAIzE,IACI,CAACM,YACD,AAAoB,YAApB,OAAOA,YACPC,AAAiC,MAAjCA,OAAO,IAAI,CAACD,UAAU,MAAM,EAE5B;gBAQC,IAAIA,AAAoB,SAApBA,SAAS,MAAM,EAEpB;gBAMC,IAAI,CAACA,SAAS,KAAK,EAAE;oBACtBL,QAAQ,KAAK,CACT,CAAC,wDAAwD,EAAED,OAAO,OAAO,CAAC,EAAE,CAAC;oBAEjFC,QAAQ,GAAG,CAAC;wBAAEK;oBAAS;oBACvB;gBACJ;gBAIA,MAAME,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAACF,SAAS,IAAI;gBAQ3D,IAAIE,QAAAA,MAAqC;oBACrCP,QAAQ,KAAK,CACT,CAAC,wDAAwD,EAAED,OAAO,SAAS,CAAC,MAAM,EAAEI,GAAG,aAAa,CAAC;oBAEzG;gBACJ;gBAEAN,WAAW,MAAM,CAAC;oBACdM;oBACA,OAAOE,SAAS,KAAK;oBACrBE;gBACJ;YACJ,OAAO,IAAIR,OAAO,SAAS,KAAKK,cAAc,MAAM,EAAE;gBAClD,MAAMI,WAAWN,WAAgCH,OAAO,QAAQ,CAAC,QAAQ;gBAIzE,IAAI,CAACS,UAAU,OACX;gBAEJX,WAAW,MAAM,CAAC;oBACdM;oBACA,OAAOK,SAAS,KAAK;gBACzB;YACJ;QACJ;QACA,OAAOX;IACX;AACJ"}
@@ -1,38 +1,35 @@
1
1
  import { Operations } from "./Operations.js";
2
2
  import { executeWithRetry } from "./executeWithRetry.js";
3
- export class SynchronizationBuilder {
4
- constructor(params) {
5
- this.timer = params.timer;
6
- this.context = params.context;
7
- this.operations = new Operations();
8
- }
9
- insert(params) {
10
- return this.operations.insert(params);
11
- }
12
- modify(params) {
13
- return this.operations.modify(params);
14
- }
15
- delete(params) {
16
- return this.operations.delete(params);
17
- }
18
- build() {
19
- return async params => {
20
- if (this.operations.total === 0) {
21
- return;
22
- }
23
- await executeWithRetry({
24
- ...params,
25
- maxRunningTime: this.timer.getRemainingMilliseconds(),
26
- timer: this.timer,
27
- context: this.context,
28
- operations: this.operations
29
- });
30
- this.operations.clear();
31
- };
32
- }
3
+ class SynchronizationBuilder {
4
+ constructor(params){
5
+ this.timer = params.timer;
6
+ this.context = params.context;
7
+ this.operations = new Operations();
8
+ }
9
+ insert(params) {
10
+ return this.operations.insert(params);
11
+ }
12
+ modify(params) {
13
+ return this.operations.modify(params);
14
+ }
15
+ delete(params) {
16
+ return this.operations.delete(params);
17
+ }
18
+ build() {
19
+ return async (params)=>{
20
+ if (0 === this.operations.total) return;
21
+ await executeWithRetry({
22
+ ...params,
23
+ maxRunningTime: this.timer.getRemainingMilliseconds(),
24
+ timer: this.timer,
25
+ context: this.context,
26
+ operations: this.operations
27
+ });
28
+ this.operations.clear();
29
+ };
30
+ }
33
31
  }
34
- export const createSynchronizationBuilder = params => {
35
- return new SynchronizationBuilder(params);
36
- };
32
+ const createSynchronizationBuilder = (params)=>new SynchronizationBuilder(params);
33
+ export { SynchronizationBuilder, createSynchronizationBuilder };
37
34
 
38
35
  //# sourceMappingURL=SynchronizationBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Operations","executeWithRetry","SynchronizationBuilder","constructor","params","timer","context","operations","insert","modify","delete","build","total","maxRunningTime","getRemainingMilliseconds","clear","createSynchronizationBuilder"],"sources":["SynchronizationBuilder.ts"],"sourcesContent":["import type {\n Context,\n IDeleteOperationParams,\n IInsertOperationParams,\n IModifyOperationParams,\n IOperations\n} from \"~/types.js\";\nimport { Operations } from \"~/Operations.js\";\nimport type { IExecuteWithRetryParams } from \"~/executeWithRetry.js\";\nimport { executeWithRetry } from \"~/executeWithRetry.js\";\nimport type { ITimer } from \"@webiny/handler-aws\";\n\nexport type ISynchronizationBuilderExecuteWithRetryParams = Omit<\n IExecuteWithRetryParams,\n \"context\" | \"timer\" | \"maxRunningTime\" | \"operations\"\n>;\n\nexport interface ISynchronizationBuilder {\n insert(params: IInsertOperationParams): void;\n delete(params: IDeleteOperationParams): void;\n build: () => (params?: ISynchronizationBuilderExecuteWithRetryParams) => Promise<void>;\n}\n\nexport interface ISynchronizationBuilderParams {\n timer: ITimer;\n context: Pick<Context, \"opensearch\">;\n}\n\nexport class SynchronizationBuilder implements ISynchronizationBuilder {\n private readonly timer: ITimer;\n private readonly context: Pick<Context, \"opensearch\">;\n private readonly operations: IOperations;\n\n public constructor(params: ISynchronizationBuilderParams) {\n this.timer = params.timer;\n this.context = params.context;\n this.operations = new Operations();\n }\n\n public insert(params: IInsertOperationParams): void {\n return this.operations.insert(params);\n }\n\n public modify(params: IModifyOperationParams): void {\n return this.operations.modify(params);\n }\n\n public delete(params: IDeleteOperationParams): void {\n return this.operations.delete(params);\n }\n\n public build() {\n return async (params?: ISynchronizationBuilderExecuteWithRetryParams) => {\n if (this.operations.total === 0) {\n return;\n }\n await executeWithRetry({\n ...params,\n maxRunningTime: this.timer.getRemainingMilliseconds(),\n timer: this.timer,\n context: this.context,\n operations: this.operations\n });\n this.operations.clear();\n };\n }\n}\n\nexport const createSynchronizationBuilder = (\n params: ISynchronizationBuilderParams\n): ISynchronizationBuilder => {\n return new SynchronizationBuilder(params);\n};\n"],"mappings":"AAOA,SAASA,UAAU;AAEnB,SAASC,gBAAgB;AAmBzB,OAAO,MAAMC,sBAAsB,CAAoC;EAK5DC,WAAWA,CAACC,MAAqC,EAAE;IACtD,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,UAAU,GAAG,IAAIP,UAAU,CAAC,CAAC;EACtC;EAEOQ,MAAMA,CAACJ,MAA8B,EAAQ;IAChD,OAAO,IAAI,CAACG,UAAU,CAACC,MAAM,CAACJ,MAAM,CAAC;EACzC;EAEOK,MAAMA,CAACL,MAA8B,EAAQ;IAChD,OAAO,IAAI,CAACG,UAAU,CAACE,MAAM,CAACL,MAAM,CAAC;EACzC;EAEOM,MAAMA,CAACN,MAA8B,EAAQ;IAChD,OAAO,IAAI,CAACG,UAAU,CAACG,MAAM,CAACN,MAAM,CAAC;EACzC;EAEOO,KAAKA,CAAA,EAAG;IACX,OAAO,MAAOP,MAAsD,IAAK;MACrE,IAAI,IAAI,CAACG,UAAU,CAACK,KAAK,KAAK,CAAC,EAAE;QAC7B;MACJ;MACA,MAAMX,gBAAgB,CAAC;QACnB,GAAGG,MAAM;QACTS,cAAc,EAAE,IAAI,CAACR,KAAK,CAACS,wBAAwB,CAAC,CAAC;QACrDT,KAAK,EAAE,IAAI,CAACA,KAAK;QACjBC,OAAO,EAAE,IAAI,CAACA,OAAO;QACrBC,UAAU,EAAE,IAAI,CAACA;MACrB,CAAC,CAAC;MACF,IAAI,CAACA,UAAU,CAACQ,KAAK,CAAC,CAAC;IAC3B,CAAC;EACL;AACJ;AAEA,OAAO,MAAMC,4BAA4B,GACrCZ,MAAqC,IACX;EAC1B,OAAO,IAAIF,sBAAsB,CAACE,MAAM,CAAC;AAC7C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"SynchronizationBuilder.js","sources":["../src/SynchronizationBuilder.ts"],"sourcesContent":["import type {\n Context,\n IDeleteOperationParams,\n IInsertOperationParams,\n IModifyOperationParams,\n IOperations\n} from \"~/types.js\";\nimport { Operations } from \"~/Operations.js\";\nimport type { IExecuteWithRetryParams } from \"~/executeWithRetry.js\";\nimport { executeWithRetry } from \"~/executeWithRetry.js\";\nimport type { ITimer } from \"@webiny/handler-aws\";\n\nexport type ISynchronizationBuilderExecuteWithRetryParams = Omit<\n IExecuteWithRetryParams,\n \"context\" | \"timer\" | \"maxRunningTime\" | \"operations\"\n>;\n\nexport interface ISynchronizationBuilder {\n insert(params: IInsertOperationParams): void;\n delete(params: IDeleteOperationParams): void;\n build: () => (params?: ISynchronizationBuilderExecuteWithRetryParams) => Promise<void>;\n}\n\nexport interface ISynchronizationBuilderParams {\n timer: ITimer;\n context: Pick<Context, \"opensearch\">;\n}\n\nexport class SynchronizationBuilder implements ISynchronizationBuilder {\n private readonly timer: ITimer;\n private readonly context: Pick<Context, \"opensearch\">;\n private readonly operations: IOperations;\n\n public constructor(params: ISynchronizationBuilderParams) {\n this.timer = params.timer;\n this.context = params.context;\n this.operations = new Operations();\n }\n\n public insert(params: IInsertOperationParams): void {\n return this.operations.insert(params);\n }\n\n public modify(params: IModifyOperationParams): void {\n return this.operations.modify(params);\n }\n\n public delete(params: IDeleteOperationParams): void {\n return this.operations.delete(params);\n }\n\n public build() {\n return async (params?: ISynchronizationBuilderExecuteWithRetryParams) => {\n if (this.operations.total === 0) {\n return;\n }\n await executeWithRetry({\n ...params,\n maxRunningTime: this.timer.getRemainingMilliseconds(),\n timer: this.timer,\n context: this.context,\n operations: this.operations\n });\n this.operations.clear();\n };\n }\n}\n\nexport const createSynchronizationBuilder = (\n params: ISynchronizationBuilderParams\n): ISynchronizationBuilder => {\n return new SynchronizationBuilder(params);\n};\n"],"names":["SynchronizationBuilder","params","Operations","executeWithRetry","createSynchronizationBuilder"],"mappings":";;AA4BO,MAAMA;IAKT,YAAmBC,MAAqC,CAAE;QACtD,IAAI,CAAC,KAAK,GAAGA,OAAO,KAAK;QACzB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAIC;IAC1B;IAEO,OAAOD,MAA8B,EAAQ;QAChD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAClC;IAEO,OAAOA,MAA8B,EAAQ;QAChD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAClC;IAEO,OAAOA,MAA8B,EAAQ;QAChD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;IAClC;IAEO,QAAQ;QACX,OAAO,OAAOA;YACV,IAAI,AAA0B,MAA1B,IAAI,CAAC,UAAU,CAAC,KAAK,EACrB;YAEJ,MAAME,iBAAiB;gBACnB,GAAGF,MAAM;gBACT,gBAAgB,IAAI,CAAC,KAAK,CAAC,wBAAwB;gBACnD,OAAO,IAAI,CAAC,KAAK;gBACjB,SAAS,IAAI,CAAC,OAAO;gBACrB,YAAY,IAAI,CAAC,UAAU;YAC/B;YACA,IAAI,CAAC,UAAU,CAAC,KAAK;QACzB;IACJ;AACJ;AAEO,MAAMG,+BAA+B,CACxCH,SAEO,IAAID,uBAAuBC"}
package/eventHandler.js CHANGED
@@ -2,49 +2,30 @@ import { createDynamoDBEventHandler, timerFactory } from "@webiny/handler-aws";
2
2
  import { OperationsBuilder } from "./OperationsBuilder.js";
3
3
  import { executeWithRetry } from "./executeWithRetry.js";
4
4
  import { CompressionHandler } from "@webiny/utils/exports/api.js";
5
-
6
- /**
7
- * Also, we need to set the maximum running time for the Lambda Function.
8
- * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreOpenSearch.ts#L232
9
- * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreElasticSearch.ts#L218
10
- */
11
5
  const MAX_RUNNING_TIME = 900;
12
- export const createEventHandler = () => {
13
- return createDynamoDBEventHandler(async ({
14
- event,
15
- context: ctx,
16
- lambdaContext
17
- }) => {
18
- const timer = timerFactory(lambdaContext);
19
- const context = ctx;
20
- if (!context.opensearch) {
21
- console.error("Missing opensearch definition on context.");
22
- return null;
23
- }
24
- const compressor = context.container.resolve(CompressionHandler);
25
- const builder = new OperationsBuilder({
26
- compressor
27
- });
28
- const operations = await builder.build({
29
- records: event.Records
30
- });
31
- /**
32
- * No need to do anything if there are no operations.
33
- */
34
- if (operations.total === 0) {
35
- return null;
36
- }
37
- /**
38
- * Execute the operations with retry.
39
- */
40
- await executeWithRetry({
41
- timer,
42
- maxRunningTime: MAX_RUNNING_TIME,
43
- context,
44
- operations
6
+ const createEventHandler = ()=>createDynamoDBEventHandler(async ({ event, context: ctx, lambdaContext })=>{
7
+ const timer = timerFactory(lambdaContext);
8
+ const context = ctx;
9
+ if (!context.opensearch) {
10
+ console.error("Missing opensearch definition on context.");
11
+ return null;
12
+ }
13
+ const compressor = context.container.resolve(CompressionHandler);
14
+ const builder = new OperationsBuilder({
15
+ compressor
16
+ });
17
+ const operations = await builder.build({
18
+ records: event.Records
19
+ });
20
+ if (0 === operations.total) return null;
21
+ await executeWithRetry({
22
+ timer,
23
+ maxRunningTime: MAX_RUNNING_TIME,
24
+ context,
25
+ operations
26
+ });
27
+ return null;
45
28
  });
46
- return null;
47
- });
48
- };
29
+ export { createEventHandler };
49
30
 
50
31
  //# sourceMappingURL=eventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createDynamoDBEventHandler","timerFactory","OperationsBuilder","executeWithRetry","CompressionHandler","MAX_RUNNING_TIME","createEventHandler","event","context","ctx","lambdaContext","timer","opensearch","console","error","compressor","container","resolve","builder","operations","build","records","Records","total","maxRunningTime"],"sources":["eventHandler.ts"],"sourcesContent":["import { createDynamoDBEventHandler, timerFactory } from \"@webiny/handler-aws\";\nimport type { Context } from \"~/types.js\";\nimport { OperationsBuilder } from \"~/OperationsBuilder.js\";\nimport { executeWithRetry } from \"~/executeWithRetry.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\n/**\n * Also, we need to set the maximum running time for the Lambda Function.\n * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreOpenSearch.ts#L232\n * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreElasticSearch.ts#L218\n */\nconst MAX_RUNNING_TIME = 900;\n\nexport const createEventHandler = () => {\n return createDynamoDBEventHandler(async ({ event, context: ctx, lambdaContext }) => {\n const timer = timerFactory(lambdaContext);\n const context = ctx as unknown as Context;\n if (!context.opensearch) {\n console.error(\"Missing opensearch definition on context.\");\n return null;\n }\n\n const compressor = context.container.resolve(CompressionHandler);\n\n const builder = new OperationsBuilder({\n compressor\n });\n\n const operations = await builder.build({\n records: event.Records\n });\n /**\n * No need to do anything if there are no operations.\n */\n if (operations.total === 0) {\n return null;\n }\n /**\n * Execute the operations with retry.\n */\n await executeWithRetry({\n timer,\n maxRunningTime: MAX_RUNNING_TIME,\n context,\n operations\n });\n\n return null;\n });\n};\n"],"mappings":"AAAA,SAASA,0BAA0B,EAAEC,YAAY,QAAQ,qBAAqB;AAE9E,SAASC,iBAAiB;AAC1B,SAASC,gBAAgB;AACzB,SAASC,kBAAkB,QAAQ,8BAA8B;;AAEjE;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,GAAG;AAE5B,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAON,0BAA0B,CAAC,OAAO;IAAEO,KAAK;IAAEC,OAAO,EAAEC,GAAG;IAAEC;EAAc,CAAC,KAAK;IAChF,MAAMC,KAAK,GAAGV,YAAY,CAACS,aAAa,CAAC;IACzC,MAAMF,OAAO,GAAGC,GAAyB;IACzC,IAAI,CAACD,OAAO,CAACI,UAAU,EAAE;MACrBC,OAAO,CAACC,KAAK,CAAC,2CAA2C,CAAC;MAC1D,OAAO,IAAI;IACf;IAEA,MAAMC,UAAU,GAAGP,OAAO,CAACQ,SAAS,CAACC,OAAO,CAACb,kBAAkB,CAAC;IAEhE,MAAMc,OAAO,GAAG,IAAIhB,iBAAiB,CAAC;MAClCa;IACJ,CAAC,CAAC;IAEF,MAAMI,UAAU,GAAG,MAAMD,OAAO,CAACE,KAAK,CAAC;MACnCC,OAAO,EAAEd,KAAK,CAACe;IACnB,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAIH,UAAU,CAACI,KAAK,KAAK,CAAC,EAAE;MACxB,OAAO,IAAI;IACf;IACA;AACR;AACA;IACQ,MAAMpB,gBAAgB,CAAC;MACnBQ,KAAK;MACLa,cAAc,EAAEnB,gBAAgB;MAChCG,OAAO;MACPW;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"eventHandler.js","sources":["../src/eventHandler.ts"],"sourcesContent":["import { createDynamoDBEventHandler, timerFactory } from \"@webiny/handler-aws\";\nimport type { Context } from \"~/types.js\";\nimport { OperationsBuilder } from \"~/OperationsBuilder.js\";\nimport { executeWithRetry } from \"~/executeWithRetry.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\n\n/**\n * Also, we need to set the maximum running time for the Lambda Function.\n * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreOpenSearch.ts#L232\n * https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreElasticSearch.ts#L218\n */\nconst MAX_RUNNING_TIME = 900;\n\nexport const createEventHandler = () => {\n return createDynamoDBEventHandler(async ({ event, context: ctx, lambdaContext }) => {\n const timer = timerFactory(lambdaContext);\n const context = ctx as unknown as Context;\n if (!context.opensearch) {\n console.error(\"Missing opensearch definition on context.\");\n return null;\n }\n\n const compressor = context.container.resolve(CompressionHandler);\n\n const builder = new OperationsBuilder({\n compressor\n });\n\n const operations = await builder.build({\n records: event.Records\n });\n /**\n * No need to do anything if there are no operations.\n */\n if (operations.total === 0) {\n return null;\n }\n /**\n * Execute the operations with retry.\n */\n await executeWithRetry({\n timer,\n maxRunningTime: MAX_RUNNING_TIME,\n context,\n operations\n });\n\n return null;\n });\n};\n"],"names":["MAX_RUNNING_TIME","createEventHandler","createDynamoDBEventHandler","event","ctx","lambdaContext","timer","timerFactory","context","console","compressor","CompressionHandler","builder","OperationsBuilder","operations","executeWithRetry"],"mappings":";;;;AAWA,MAAMA,mBAAmB;AAElB,MAAMC,qBAAqB,IACvBC,2BAA2B,OAAO,EAAEC,KAAK,EAAE,SAASC,GAAG,EAAEC,aAAa,EAAE;QAC3E,MAAMC,QAAQC,aAAaF;QAC3B,MAAMG,UAAUJ;QAChB,IAAI,CAACI,QAAQ,UAAU,EAAE;YACrBC,QAAQ,KAAK,CAAC;YACd,OAAO;QACX;QAEA,MAAMC,aAAaF,QAAQ,SAAS,CAAC,OAAO,CAACG;QAE7C,MAAMC,UAAU,IAAIC,kBAAkB;YAClCH;QACJ;QAEA,MAAMI,aAAa,MAAMF,QAAQ,KAAK,CAAC;YACnC,SAAST,MAAM,OAAO;QAC1B;QAIA,IAAIW,AAAqB,MAArBA,WAAW,KAAK,EAChB,OAAO;QAKX,MAAMC,iBAAiB;YACnBT;YACA,gBAAgBN;YAChBQ;YACAM;QACJ;QAEA,OAAO;IACX"}
package/execute.js CHANGED
@@ -1,137 +1,98 @@
1
- import { createWaitUntilHealthy, OpenSearchCatClusterHealthStatus, UnhealthyClusterError, WaitingHealthyClusterAbortedError } from "@webiny/api-opensearch";
1
+ import { OpenSearchCatClusterHealthStatus, UnhealthyClusterError, WaitingHealthyClusterAbortedError, createWaitUntilHealthy } from "@webiny/api-opensearch";
2
2
  import { WebinyError } from "@webiny/error";
3
3
  import { shouldShowLogs } from "./helpers/shouldShowLogs.js";
4
- const getError = item => {
5
- if (!item.index?.error?.reason) {
6
- return null;
7
- }
8
- const reason = item.index.error.reason;
9
- if (reason.match(/no such index \[([a-zA-Z0-9_-]+)\]/) !== null) {
10
- return "index";
11
- }
12
- return reason;
4
+ const getError = (item)=>{
5
+ if (!item.index?.error?.reason) return null;
6
+ const reason = item.index.error.reason;
7
+ if (null !== reason.match(/no such index \[([a-zA-Z0-9_-]+)\]/)) return "index";
8
+ return reason;
13
9
  };
14
- const checkErrors = result => {
15
- if (!result || !result.body || !result.body.items) {
16
- return;
17
- }
18
- for (const item of result.body.items) {
19
- const err = getError(item);
20
- if (!err) {
21
- continue;
22
- } else if (err === "index") {
23
- if (process.env.DEBUG === "true") {
24
- console.error("Bulk response", JSON.stringify(result, null, 2));
25
- }
26
- continue;
27
- }
28
- console.error("Body item with error", item);
29
- throw new WebinyError(err, "DYNAMODB_TO_OPENSEARCH_ERROR", item);
30
- }
31
- };
32
- export const execute = params => {
33
- return async () => {
34
- const {
35
- context,
36
- timer,
37
- maxRunningTime,
38
- maxProcessorPercent,
39
- operations
40
- } = params;
41
- if (operations.total === 0) {
42
- return;
43
- }
44
- const remainingTime = timer.getRemainingSeconds();
45
- const runningTime = maxRunningTime - remainingTime;
46
- const maxWaitingTime = remainingTime - 90;
47
- if (shouldShowLogs()) {
48
- console.debug(`The Lambda is already running for ${runningTime}s. Setting Health Check max waiting time: ${maxWaitingTime}s`);
49
- }
50
- const healthCheck = createWaitUntilHealthy(context.opensearch, {
51
- minClusterHealthStatus: OpenSearchCatClusterHealthStatus.Yellow,
52
- waitingTimeStep: 30,
53
- maxProcessorPercent,
54
- maxWaitingTime
55
- });
56
-
57
- // const log = context.logger.withSource("dynamodbToElasticsearch");
58
- const log = {
59
- notice: (...params) => {
60
- console.log(...params);
61
- },
62
- debug: (...params) => {
63
- console.debug(...params);
64
- },
65
- info: (...params) => {
66
- console.info(...params);
67
- },
68
- warn: (...params) => {
69
- console.warn(...params);
70
- },
71
- error: (...params) => {
72
- console.error(...params);
73
- }
74
- };
75
- try {
76
- await healthCheck.wait({
77
- async onUnhealthy({
78
- startedAt,
79
- runs,
80
- mustEndAt,
81
- waitingTimeStep,
82
- waitingReason
83
- }) {
84
- console.debug(`Cluster is unhealthy on run #${runs}.`, {
85
- startedAt,
86
- mustEndAt,
87
- waitingTimeStep,
88
- waitingReason
89
- });
90
- },
91
- async onTimeout({
92
- startedAt,
93
- runs,
94
- waitingTimeStep,
95
- mustEndAt,
96
- waitingReason
97
- }) {
98
- console.error(`Cluster health check timeout on run #${runs}.`, {
99
- startedAt,
100
- mustEndAt,
101
- waitingTimeStep,
102
- waitingReason
103
- });
10
+ const checkErrors = (result)=>{
11
+ if (!result || !result.body || !result.body.items) return;
12
+ for (const item of result.body.items){
13
+ const err = getError(item);
14
+ if (err) {
15
+ if ("index" === err) {
16
+ if ("true" === process.env.DEBUG) console.error("Bulk response", JSON.stringify(result, null, 2));
17
+ continue;
18
+ }
19
+ console.error("Body item with error", item);
20
+ throw new WebinyError(err, "DYNAMODB_TO_OPENSEARCH_ERROR", item);
104
21
  }
105
- });
106
- } catch (ex) {
107
- if (ex instanceof UnhealthyClusterError || ex instanceof WaitingHealthyClusterAbortedError) {
108
- throw ex;
109
- }
110
- console.error(`Cluster health check failed.`, ex);
111
- throw ex;
112
22
  }
113
- try {
114
- const res = await context.opensearch.bulk({
115
- body: operations.items
116
- });
117
- checkErrors(res);
118
- } catch (error) {
119
- log.error(error, {
120
- tenant: "root"
121
- });
122
- if (shouldShowLogs() === false) {
123
- throw error;
124
- }
125
- const meta = error?.meta || {};
126
- delete meta["meta"];
127
- console.error("Bulk error", JSON.stringify(error, null, 2));
128
- throw error;
129
- }
130
- if (shouldShowLogs() === false) {
131
- return;
132
- }
133
- console.info(`Transferred ${operations.total} record operations to Elasticsearch.`);
134
- };
135
23
  };
24
+ const execute = (params)=>async ()=>{
25
+ const { context, timer, maxRunningTime, maxProcessorPercent, operations } = params;
26
+ if (0 === operations.total) return;
27
+ const remainingTime = timer.getRemainingSeconds();
28
+ const runningTime = maxRunningTime - remainingTime;
29
+ const maxWaitingTime = remainingTime - 90;
30
+ if (shouldShowLogs()) console.debug(`The Lambda is already running for ${runningTime}s. Setting Health Check max waiting time: ${maxWaitingTime}s`);
31
+ const healthCheck = createWaitUntilHealthy(context.opensearch, {
32
+ minClusterHealthStatus: OpenSearchCatClusterHealthStatus.Yellow,
33
+ waitingTimeStep: 30,
34
+ maxProcessorPercent,
35
+ maxWaitingTime
36
+ });
37
+ const log = {
38
+ notice: (...params)=>{
39
+ console.log(...params);
40
+ },
41
+ debug: (...params)=>{
42
+ console.debug(...params);
43
+ },
44
+ info: (...params)=>{
45
+ console.info(...params);
46
+ },
47
+ warn: (...params)=>{
48
+ console.warn(...params);
49
+ },
50
+ error: (...params)=>{
51
+ console.error(...params);
52
+ }
53
+ };
54
+ try {
55
+ await healthCheck.wait({
56
+ async onUnhealthy ({ startedAt, runs, mustEndAt, waitingTimeStep, waitingReason }) {
57
+ console.debug(`Cluster is unhealthy on run #${runs}.`, {
58
+ startedAt,
59
+ mustEndAt,
60
+ waitingTimeStep,
61
+ waitingReason
62
+ });
63
+ },
64
+ async onTimeout ({ startedAt, runs, waitingTimeStep, mustEndAt, waitingReason }) {
65
+ console.error(`Cluster health check timeout on run #${runs}.`, {
66
+ startedAt,
67
+ mustEndAt,
68
+ waitingTimeStep,
69
+ waitingReason
70
+ });
71
+ }
72
+ });
73
+ } catch (ex) {
74
+ if (ex instanceof UnhealthyClusterError || ex instanceof WaitingHealthyClusterAbortedError) throw ex;
75
+ console.error("Cluster health check failed.", ex);
76
+ throw ex;
77
+ }
78
+ try {
79
+ const res = await context.opensearch.bulk({
80
+ body: operations.items
81
+ });
82
+ checkErrors(res);
83
+ } catch (error) {
84
+ log.error(error, {
85
+ tenant: "root"
86
+ });
87
+ if (false === shouldShowLogs()) throw error;
88
+ const meta = error?.meta || {};
89
+ delete meta["meta"];
90
+ console.error("Bulk error", JSON.stringify(error, null, 2));
91
+ throw error;
92
+ }
93
+ if (false === shouldShowLogs()) return;
94
+ console.info(`Transferred ${operations.total} record operations to Elasticsearch.`);
95
+ };
96
+ export { execute };
136
97
 
137
98
  //# sourceMappingURL=execute.js.map
package/execute.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createWaitUntilHealthy","OpenSearchCatClusterHealthStatus","UnhealthyClusterError","WaitingHealthyClusterAbortedError","WebinyError","shouldShowLogs","getError","item","index","error","reason","match","checkErrors","result","body","items","err","process","env","DEBUG","console","JSON","stringify","execute","params","context","timer","maxRunningTime","maxProcessorPercent","operations","total","remainingTime","getRemainingSeconds","runningTime","maxWaitingTime","debug","healthCheck","opensearch","minClusterHealthStatus","Yellow","waitingTimeStep","log","notice","info","warn","wait","onUnhealthy","startedAt","runs","mustEndAt","waitingReason","onTimeout","ex","res","bulk","tenant","meta"],"sources":["execute.ts"],"sourcesContent":["import {\n createWaitUntilHealthy,\n OpenSearchCatClusterHealthStatus,\n UnhealthyClusterError,\n WaitingHealthyClusterAbortedError\n} from \"@webiny/api-opensearch\";\nimport type { ITimer } from \"@webiny/handler-aws\";\nimport type { ApiResponse } from \"@webiny/api-opensearch/types.js\";\n\nimport { WebinyError } from \"@webiny/error\";\nimport type { Context, IOperations } from \"./types.js\";\nimport { shouldShowLogs } from \"~/helpers/shouldShowLogs.js\";\n\nexport interface BulkOperationsResponseBodyItemIndexError {\n reason?: string;\n}\n\nexport interface BulkOperationsResponseBodyItemIndex {\n error?: BulkOperationsResponseBodyItemIndexError;\n}\n\nexport interface BulkOperationsResponseBodyItem {\n index?: BulkOperationsResponseBodyItemIndex;\n error?: string;\n}\n\nexport interface BulkOperationsResponseBody {\n items: BulkOperationsResponseBodyItem[];\n}\n\nexport interface IExecuteParams {\n timer: ITimer;\n maxRunningTime: number;\n maxProcessorPercent: number;\n context: Pick<Context, \"opensearch\">;\n operations: Pick<IOperations, \"items\" | \"total\">;\n}\n\nconst getError = (item: BulkOperationsResponseBodyItem): string | null => {\n if (!item.index?.error?.reason) {\n return null;\n }\n const reason = item.index.error.reason;\n if (reason.match(/no such index \\[([a-zA-Z0-9_-]+)\\]/) !== null) {\n return \"index\";\n }\n return reason;\n};\n\nconst checkErrors = (result?: ApiResponse): void => {\n if (!result || !result.body || !result.body.items) {\n return;\n }\n for (const item of result.body.items) {\n const err = getError(item);\n if (!err) {\n continue;\n } else if (err === \"index\") {\n if (process.env.DEBUG === \"true\") {\n console.error(\"Bulk response\", JSON.stringify(result, null, 2));\n }\n continue;\n }\n console.error(\"Body item with error\", item);\n throw new WebinyError(err, \"DYNAMODB_TO_OPENSEARCH_ERROR\", item);\n }\n};\n\nexport const execute = (params: IExecuteParams) => {\n return async (): Promise<void> => {\n const { context, timer, maxRunningTime, maxProcessorPercent, operations } = params;\n\n if (operations.total === 0) {\n return;\n }\n\n const remainingTime = timer.getRemainingSeconds();\n const runningTime = maxRunningTime - remainingTime;\n const maxWaitingTime = remainingTime - 90;\n\n if (shouldShowLogs()) {\n console.debug(\n `The Lambda is already running for ${runningTime}s. Setting Health Check max waiting time: ${maxWaitingTime}s`\n );\n }\n\n const healthCheck = createWaitUntilHealthy(context.opensearch, {\n minClusterHealthStatus: OpenSearchCatClusterHealthStatus.Yellow,\n waitingTimeStep: 30,\n maxProcessorPercent,\n maxWaitingTime\n });\n\n // const log = context.logger.withSource(\"dynamodbToElasticsearch\");\n const log = {\n notice: (...params: any[]) => {\n console.log(...params);\n },\n debug: (...params: any[]) => {\n console.debug(...params);\n },\n info: (...params: any[]) => {\n console.info(...params);\n },\n warn: (...params: any[]) => {\n console.warn(...params);\n },\n error: (...params: any[]) => {\n console.error(...params);\n }\n };\n\n try {\n await healthCheck.wait({\n async onUnhealthy({ startedAt, runs, mustEndAt, waitingTimeStep, waitingReason }) {\n console.debug(`Cluster is unhealthy on run #${runs}.`, {\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason\n });\n },\n async onTimeout({ startedAt, runs, waitingTimeStep, mustEndAt, waitingReason }) {\n console.error(`Cluster health check timeout on run #${runs}.`, {\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason\n });\n }\n });\n } catch (ex) {\n if (\n ex instanceof UnhealthyClusterError ||\n ex instanceof WaitingHealthyClusterAbortedError\n ) {\n throw ex;\n }\n console.error(`Cluster health check failed.`, ex);\n throw ex;\n }\n\n try {\n const res = await context.opensearch.bulk({\n body: operations.items\n });\n checkErrors(res);\n } catch (error) {\n log.error(error, {\n tenant: \"root\"\n });\n\n if (shouldShowLogs() === false) {\n throw error;\n }\n const meta = error?.meta || {};\n delete meta[\"meta\"];\n console.error(\"Bulk error\", JSON.stringify(error, null, 2));\n throw error;\n }\n if (shouldShowLogs() === false) {\n return;\n }\n console.info(`Transferred ${operations.total} record operations to Elasticsearch.`);\n };\n};\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"execute.js","sources":["../src/execute.ts"],"sourcesContent":["import {\n createWaitUntilHealthy,\n OpenSearchCatClusterHealthStatus,\n UnhealthyClusterError,\n WaitingHealthyClusterAbortedError\n} from \"@webiny/api-opensearch\";\nimport type { ITimer } from \"@webiny/handler-aws\";\nimport type { ApiResponse } from \"@webiny/api-opensearch/types.js\";\n\nimport { WebinyError } from \"@webiny/error\";\nimport type { Context, IOperations } from \"./types.js\";\nimport { shouldShowLogs } from \"~/helpers/shouldShowLogs.js\";\n\nexport interface BulkOperationsResponseBodyItemIndexError {\n reason?: string;\n}\n\nexport interface BulkOperationsResponseBodyItemIndex {\n error?: BulkOperationsResponseBodyItemIndexError;\n}\n\nexport interface BulkOperationsResponseBodyItem {\n index?: BulkOperationsResponseBodyItemIndex;\n error?: string;\n}\n\nexport interface BulkOperationsResponseBody {\n items: BulkOperationsResponseBodyItem[];\n}\n\nexport interface IExecuteParams {\n timer: ITimer;\n maxRunningTime: number;\n maxProcessorPercent: number;\n context: Pick<Context, \"opensearch\">;\n operations: Pick<IOperations, \"items\" | \"total\">;\n}\n\nconst getError = (item: BulkOperationsResponseBodyItem): string | null => {\n if (!item.index?.error?.reason) {\n return null;\n }\n const reason = item.index.error.reason;\n if (reason.match(/no such index \\[([a-zA-Z0-9_-]+)\\]/) !== null) {\n return \"index\";\n }\n return reason;\n};\n\nconst checkErrors = (result?: ApiResponse): void => {\n if (!result || !result.body || !result.body.items) {\n return;\n }\n for (const item of result.body.items) {\n const err = getError(item);\n if (!err) {\n continue;\n } else if (err === \"index\") {\n if (process.env.DEBUG === \"true\") {\n console.error(\"Bulk response\", JSON.stringify(result, null, 2));\n }\n continue;\n }\n console.error(\"Body item with error\", item);\n throw new WebinyError(err, \"DYNAMODB_TO_OPENSEARCH_ERROR\", item);\n }\n};\n\nexport const execute = (params: IExecuteParams) => {\n return async (): Promise<void> => {\n const { context, timer, maxRunningTime, maxProcessorPercent, operations } = params;\n\n if (operations.total === 0) {\n return;\n }\n\n const remainingTime = timer.getRemainingSeconds();\n const runningTime = maxRunningTime - remainingTime;\n const maxWaitingTime = remainingTime - 90;\n\n if (shouldShowLogs()) {\n console.debug(\n `The Lambda is already running for ${runningTime}s. Setting Health Check max waiting time: ${maxWaitingTime}s`\n );\n }\n\n const healthCheck = createWaitUntilHealthy(context.opensearch, {\n minClusterHealthStatus: OpenSearchCatClusterHealthStatus.Yellow,\n waitingTimeStep: 30,\n maxProcessorPercent,\n maxWaitingTime\n });\n\n // const log = context.logger.withSource(\"dynamodbToElasticsearch\");\n const log = {\n notice: (...params: any[]) => {\n console.log(...params);\n },\n debug: (...params: any[]) => {\n console.debug(...params);\n },\n info: (...params: any[]) => {\n console.info(...params);\n },\n warn: (...params: any[]) => {\n console.warn(...params);\n },\n error: (...params: any[]) => {\n console.error(...params);\n }\n };\n\n try {\n await healthCheck.wait({\n async onUnhealthy({ startedAt, runs, mustEndAt, waitingTimeStep, waitingReason }) {\n console.debug(`Cluster is unhealthy on run #${runs}.`, {\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason\n });\n },\n async onTimeout({ startedAt, runs, waitingTimeStep, mustEndAt, waitingReason }) {\n console.error(`Cluster health check timeout on run #${runs}.`, {\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason\n });\n }\n });\n } catch (ex) {\n if (\n ex instanceof UnhealthyClusterError ||\n ex instanceof WaitingHealthyClusterAbortedError\n ) {\n throw ex;\n }\n console.error(`Cluster health check failed.`, ex);\n throw ex;\n }\n\n try {\n const res = await context.opensearch.bulk({\n body: operations.items\n });\n checkErrors(res);\n } catch (error) {\n log.error(error, {\n tenant: \"root\"\n });\n\n if (shouldShowLogs() === false) {\n throw error;\n }\n const meta = error?.meta || {};\n delete meta[\"meta\"];\n console.error(\"Bulk error\", JSON.stringify(error, null, 2));\n throw error;\n }\n if (shouldShowLogs() === false) {\n return;\n }\n console.info(`Transferred ${operations.total} record operations to Elasticsearch.`);\n };\n};\n"],"names":["getError","item","reason","checkErrors","result","err","process","console","JSON","WebinyError","execute","params","context","timer","maxRunningTime","maxProcessorPercent","operations","remainingTime","runningTime","maxWaitingTime","shouldShowLogs","healthCheck","createWaitUntilHealthy","OpenSearchCatClusterHealthStatus","log","startedAt","runs","mustEndAt","waitingTimeStep","waitingReason","ex","UnhealthyClusterError","WaitingHealthyClusterAbortedError","res","error","meta"],"mappings":"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"}
@@ -1,47 +1,37 @@
1
1
  import { execute } from "./execute.js";
2
2
  import { NotEnoughRemainingTimeError } from "./NotEnoughRemainingTimeError.js";
3
- import pRetry from "p-retry";
3
+ import p_retry from "p-retry";
4
4
  import { getNumberEnvVariable } from "./helpers/getNumberEnvVariable.js";
5
5
  const minRemainingSecondsToTimeout = 120;
6
- const MAX_PROCESSOR_PERCENT = getNumberEnvVariable("MAX_ES_PROCESSOR", process.env.NODE_ENV === "test" ? 101 : 98);
7
- export const executeWithRetry = async params => {
8
- const maxRetryTime = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_RETRY_TIME", params.maxRetryTime || 300000);
9
- const retries = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_RETRIES", params.retries || 20);
10
- const minTimeout = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MIN_TIMEOUT", params.minTimeout || 1500);
11
- const maxTimeout = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_TIMEOUT", params.maxTimeout || 30000);
12
- try {
13
- await pRetry(execute({
14
- timer: params.timer,
15
- maxRunningTime: params.maxRunningTime,
16
- maxProcessorPercent: params.maxProcessorPercent || MAX_PROCESSOR_PERCENT,
17
- context: params.context,
18
- operations: params.operations
19
- }), {
20
- maxRetryTime,
21
- retries,
22
- minTimeout,
23
- maxTimeout,
24
- onFailedAttempt: ({
25
- error,
26
- attemptNumber
27
- }) => {
28
- if (params.timer.getRemainingSeconds() < minRemainingSecondsToTimeout) {
29
- throw new NotEnoughRemainingTimeError(error);
30
- }
31
- /**
32
- * We will only log attempts which are after 3/4 of total attempts.
33
- */
34
- if (attemptNumber < retries * 0.75) {
35
- return;
36
- }
37
- console.error(`Attempt #${attemptNumber} failed.`);
38
- console.error(error);
39
- }
40
- });
41
- } catch (ex) {
42
- // TODO implement storing of failed operations
43
- throw ex;
44
- }
6
+ const MAX_PROCESSOR_PERCENT = getNumberEnvVariable("MAX_ES_PROCESSOR", "test" === process.env.NODE_ENV ? 101 : 98);
7
+ const executeWithRetry = async (params)=>{
8
+ const maxRetryTime = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_RETRY_TIME", params.maxRetryTime || 300000);
9
+ const retries = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_RETRIES", params.retries || 20);
10
+ const minTimeout = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MIN_TIMEOUT", params.minTimeout || 1500);
11
+ const maxTimeout = getNumberEnvVariable("WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_TIMEOUT", params.maxTimeout || 30000);
12
+ try {
13
+ await p_retry(execute({
14
+ timer: params.timer,
15
+ maxRunningTime: params.maxRunningTime,
16
+ maxProcessorPercent: params.maxProcessorPercent || MAX_PROCESSOR_PERCENT,
17
+ context: params.context,
18
+ operations: params.operations
19
+ }), {
20
+ maxRetryTime,
21
+ retries,
22
+ minTimeout,
23
+ maxTimeout,
24
+ onFailedAttempt: ({ error, attemptNumber })=>{
25
+ if (params.timer.getRemainingSeconds() < minRemainingSecondsToTimeout) throw new NotEnoughRemainingTimeError(error);
26
+ if (attemptNumber < 0.75 * retries) return;
27
+ console.error(`Attempt #${attemptNumber} failed.`);
28
+ console.error(error);
29
+ }
30
+ });
31
+ } catch (ex) {
32
+ throw ex;
33
+ }
45
34
  };
35
+ export { executeWithRetry };
46
36
 
47
37
  //# sourceMappingURL=executeWithRetry.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["execute","NotEnoughRemainingTimeError","pRetry","getNumberEnvVariable","minRemainingSecondsToTimeout","MAX_PROCESSOR_PERCENT","process","env","NODE_ENV","executeWithRetry","params","maxRetryTime","retries","minTimeout","maxTimeout","timer","maxRunningTime","maxProcessorPercent","context","operations","onFailedAttempt","error","attemptNumber","getRemainingSeconds","console","ex"],"sources":["executeWithRetry.ts"],"sourcesContent":["import type { IExecuteParams } from \"~/execute.js\";\nimport { execute } from \"~/execute.js\";\nimport { NotEnoughRemainingTimeError } from \"~/NotEnoughRemainingTimeError.js\";\nimport pRetry from \"p-retry\";\nimport { getNumberEnvVariable } from \"./helpers/getNumberEnvVariable.js\";\n\nconst minRemainingSecondsToTimeout = 120;\n\nconst MAX_PROCESSOR_PERCENT = getNumberEnvVariable(\n \"MAX_ES_PROCESSOR\",\n process.env.NODE_ENV === \"test\" ? 101 : 98\n);\n\nexport interface IExecuteWithRetryParams extends Omit<IExecuteParams, \"maxProcessorPercent\"> {\n maxRetryTime?: number;\n retries?: number;\n minTimeout?: number;\n maxTimeout?: number;\n maxProcessorPercent?: number;\n}\n\nexport const executeWithRetry = async (params: IExecuteWithRetryParams) => {\n const maxRetryTime = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_RETRY_TIME\",\n params.maxRetryTime || 300000\n );\n const retries = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_RETRIES\",\n params.retries || 20\n );\n const minTimeout = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MIN_TIMEOUT\",\n params.minTimeout || 1500\n );\n const maxTimeout = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_TIMEOUT\",\n params.maxTimeout || 30000\n );\n\n try {\n await pRetry(\n execute({\n timer: params.timer,\n maxRunningTime: params.maxRunningTime,\n maxProcessorPercent: params.maxProcessorPercent || MAX_PROCESSOR_PERCENT,\n context: params.context,\n operations: params.operations\n }),\n {\n maxRetryTime,\n retries,\n minTimeout,\n maxTimeout,\n onFailedAttempt: ({ error, attemptNumber }) => {\n if (params.timer.getRemainingSeconds() < minRemainingSecondsToTimeout) {\n throw new NotEnoughRemainingTimeError(error);\n }\n /**\n * We will only log attempts which are after 3/4 of total attempts.\n */\n if (attemptNumber < retries * 0.75) {\n return;\n }\n console.error(`Attempt #${attemptNumber} failed.`);\n console.error(error);\n }\n }\n );\n } catch (ex) {\n // TODO implement storing of failed operations\n throw ex;\n }\n};\n"],"mappings":"AACA,SAASA,OAAO;AAChB,SAASC,2BAA2B;AACpC,OAAOC,MAAM,MAAM,SAAS;AAC5B,SAASC,oBAAoB;AAE7B,MAAMC,4BAA4B,GAAG,GAAG;AAExC,MAAMC,qBAAqB,GAAGF,oBAAoB,CAC9C,kBAAkB,EAClBG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,MAAM,GAAG,GAAG,GAAG,EAC5C,CAAC;AAUD,OAAO,MAAMC,gBAAgB,GAAG,MAAOC,MAA+B,IAAK;EACvE,MAAMC,YAAY,GAAGR,oBAAoB,CACrC,8CAA8C,EAC9CO,MAAM,CAACC,YAAY,IAAI,MAC3B,CAAC;EACD,MAAMC,OAAO,GAAGT,oBAAoB,CAChC,uCAAuC,EACvCO,MAAM,CAACE,OAAO,IAAI,EACtB,CAAC;EACD,MAAMC,UAAU,GAAGV,oBAAoB,CACnC,2CAA2C,EAC3CO,MAAM,CAACG,UAAU,IAAI,IACzB,CAAC;EACD,MAAMC,UAAU,GAAGX,oBAAoB,CACnC,2CAA2C,EAC3CO,MAAM,CAACI,UAAU,IAAI,KACzB,CAAC;EAED,IAAI;IACA,MAAMZ,MAAM,CACRF,OAAO,CAAC;MACJe,KAAK,EAAEL,MAAM,CAACK,KAAK;MACnBC,cAAc,EAAEN,MAAM,CAACM,cAAc;MACrCC,mBAAmB,EAAEP,MAAM,CAACO,mBAAmB,IAAIZ,qBAAqB;MACxEa,OAAO,EAAER,MAAM,CAACQ,OAAO;MACvBC,UAAU,EAAET,MAAM,CAACS;IACvB,CAAC,CAAC,EACF;MACIR,YAAY;MACZC,OAAO;MACPC,UAAU;MACVC,UAAU;MACVM,eAAe,EAAEA,CAAC;QAAEC,KAAK;QAAEC;MAAc,CAAC,KAAK;QAC3C,IAAIZ,MAAM,CAACK,KAAK,CAACQ,mBAAmB,CAAC,CAAC,GAAGnB,4BAA4B,EAAE;UACnE,MAAM,IAAIH,2BAA2B,CAACoB,KAAK,CAAC;QAChD;QACA;AACpB;AACA;QACoB,IAAIC,aAAa,GAAGV,OAAO,GAAG,IAAI,EAAE;UAChC;QACJ;QACAY,OAAO,CAACH,KAAK,CAAC,YAAYC,aAAa,UAAU,CAAC;QAClDE,OAAO,CAACH,KAAK,CAACA,KAAK,CAAC;MACxB;IACJ,CACJ,CAAC;EACL,CAAC,CAAC,OAAOI,EAAE,EAAE;IACT;IACA,MAAMA,EAAE;EACZ;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"executeWithRetry.js","sources":["../src/executeWithRetry.ts"],"sourcesContent":["import type { IExecuteParams } from \"~/execute.js\";\nimport { execute } from \"~/execute.js\";\nimport { NotEnoughRemainingTimeError } from \"~/NotEnoughRemainingTimeError.js\";\nimport pRetry from \"p-retry\";\nimport { getNumberEnvVariable } from \"./helpers/getNumberEnvVariable.js\";\n\nconst minRemainingSecondsToTimeout = 120;\n\nconst MAX_PROCESSOR_PERCENT = getNumberEnvVariable(\n \"MAX_ES_PROCESSOR\",\n process.env.NODE_ENV === \"test\" ? 101 : 98\n);\n\nexport interface IExecuteWithRetryParams extends Omit<IExecuteParams, \"maxProcessorPercent\"> {\n maxRetryTime?: number;\n retries?: number;\n minTimeout?: number;\n maxTimeout?: number;\n maxProcessorPercent?: number;\n}\n\nexport const executeWithRetry = async (params: IExecuteWithRetryParams) => {\n const maxRetryTime = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_RETRY_TIME\",\n params.maxRetryTime || 300000\n );\n const retries = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_RETRIES\",\n params.retries || 20\n );\n const minTimeout = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MIN_TIMEOUT\",\n params.minTimeout || 1500\n );\n const maxTimeout = getNumberEnvVariable(\n \"WEBINY_DYNAMODB_TO_OPENSEARCH_MAX_TIMEOUT\",\n params.maxTimeout || 30000\n );\n\n try {\n await pRetry(\n execute({\n timer: params.timer,\n maxRunningTime: params.maxRunningTime,\n maxProcessorPercent: params.maxProcessorPercent || MAX_PROCESSOR_PERCENT,\n context: params.context,\n operations: params.operations\n }),\n {\n maxRetryTime,\n retries,\n minTimeout,\n maxTimeout,\n onFailedAttempt: ({ error, attemptNumber }) => {\n if (params.timer.getRemainingSeconds() < minRemainingSecondsToTimeout) {\n throw new NotEnoughRemainingTimeError(error);\n }\n /**\n * We will only log attempts which are after 3/4 of total attempts.\n */\n if (attemptNumber < retries * 0.75) {\n return;\n }\n console.error(`Attempt #${attemptNumber} failed.`);\n console.error(error);\n }\n }\n );\n } catch (ex) {\n // TODO implement storing of failed operations\n throw ex;\n }\n};\n"],"names":["minRemainingSecondsToTimeout","MAX_PROCESSOR_PERCENT","getNumberEnvVariable","process","executeWithRetry","params","maxRetryTime","retries","minTimeout","maxTimeout","pRetry","execute","error","attemptNumber","NotEnoughRemainingTimeError","console","ex"],"mappings":";;;;AAMA,MAAMA,+BAA+B;AAErC,MAAMC,wBAAwBC,qBAC1B,oBACAC,AAAyB,WAAzBA,QAAQ,GAAG,CAAC,QAAQ,GAAc,MAAM;AAWrC,MAAMC,mBAAmB,OAAOC;IACnC,MAAMC,eAAeJ,qBACjB,gDACAG,OAAO,YAAY,IAAI;IAE3B,MAAME,UAAUL,qBACZ,yCACAG,OAAO,OAAO,IAAI;IAEtB,MAAMG,aAAaN,qBACf,6CACAG,OAAO,UAAU,IAAI;IAEzB,MAAMI,aAAaP,qBACf,6CACAG,OAAO,UAAU,IAAI;IAGzB,IAAI;QACA,MAAMK,QACFC,QAAQ;YACJ,OAAON,OAAO,KAAK;YACnB,gBAAgBA,OAAO,cAAc;YACrC,qBAAqBA,OAAO,mBAAmB,IAAIJ;YACnD,SAASI,OAAO,OAAO;YACvB,YAAYA,OAAO,UAAU;QACjC,IACA;YACIC;YACAC;YACAC;YACAC;YACA,iBAAiB,CAAC,EAAEG,KAAK,EAAEC,aAAa,EAAE;gBACtC,IAAIR,OAAO,KAAK,CAAC,mBAAmB,KAAKL,8BACrC,MAAM,IAAIc,4BAA4BF;gBAK1C,IAAIC,gBAAgBN,AAAU,OAAVA,SAChB;gBAEJQ,QAAQ,KAAK,CAAC,CAAC,SAAS,EAAEF,cAAc,QAAQ,CAAC;gBACjDE,QAAQ,KAAK,CAACH;YAClB;QACJ;IAER,EAAE,OAAOI,IAAI;QAET,MAAMA;IACV;AACJ"}
@@ -1,12 +1,10 @@
1
- export const getNumberEnvVariable = (name, def) => {
2
- const input = process.env[name];
3
- const value = Number(input);
4
- if (isNaN(value)) {
5
- return def;
6
- } else if (value <= 0) {
7
- return def;
8
- }
9
- return value;
1
+ const getNumberEnvVariable = (name, def)=>{
2
+ const input = process.env[name];
3
+ const value = Number(input);
4
+ if (isNaN(value)) return def;
5
+ if (value <= 0) return def;
6
+ return value;
10
7
  };
8
+ export { getNumberEnvVariable };
11
9
 
12
10
  //# sourceMappingURL=getNumberEnvVariable.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getNumberEnvVariable","name","def","input","process","env","value","Number","isNaN"],"sources":["getNumberEnvVariable.ts"],"sourcesContent":["export const getNumberEnvVariable = (name: string, def: number): number => {\n const input = process.env[name];\n const value = Number(input);\n if (isNaN(value)) {\n return def;\n } else if (value <= 0) {\n return def;\n }\n return value;\n};\n"],"mappings":"AAAA,OAAO,MAAMA,oBAAoB,GAAGA,CAACC,IAAY,EAAEC,GAAW,KAAa;EACvE,MAAMC,KAAK,GAAGC,OAAO,CAACC,GAAG,CAACJ,IAAI,CAAC;EAC/B,MAAMK,KAAK,GAAGC,MAAM,CAACJ,KAAK,CAAC;EAC3B,IAAIK,KAAK,CAACF,KAAK,CAAC,EAAE;IACd,OAAOJ,GAAG;EACd,CAAC,MAAM,IAAII,KAAK,IAAI,CAAC,EAAE;IACnB,OAAOJ,GAAG;EACd;EACA,OAAOI,KAAK;AAChB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"helpers/getNumberEnvVariable.js","sources":["../../src/helpers/getNumberEnvVariable.ts"],"sourcesContent":["export const getNumberEnvVariable = (name: string, def: number): number => {\n const input = process.env[name];\n const value = Number(input);\n if (isNaN(value)) {\n return def;\n } else if (value <= 0) {\n return def;\n }\n return value;\n};\n"],"names":["getNumberEnvVariable","name","def","input","process","value","Number","isNaN"],"mappings":"AAAO,MAAMA,uBAAuB,CAACC,MAAcC;IAC/C,MAAMC,QAAQC,QAAQ,GAAG,CAACH,KAAK;IAC/B,MAAMI,QAAQC,OAAOH;IACrB,IAAII,MAAMF,QACN,OAAOH;IACJ,IAAIG,SAAS,GAChB,OAAOH;IAEX,OAAOG;AACX"}
@@ -1,11 +1,7 @@
1
- export const shouldShowLogs = () => {
2
- /**
3
- * Don't show logs during tests, really no point.
4
- */
5
- if (process.env.TESTING === "true") {
6
- return false;
7
- }
8
- return process.env.DEBUG === "true";
1
+ const shouldShowLogs = ()=>{
2
+ if ("true" === process.env.TESTING) return false;
3
+ return "true" === process.env.DEBUG;
9
4
  };
5
+ export { shouldShowLogs };
10
6
 
11
7
  //# sourceMappingURL=shouldShowLogs.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["shouldShowLogs","process","env","TESTING","DEBUG"],"sources":["shouldShowLogs.ts"],"sourcesContent":["export const shouldShowLogs = (): boolean => {\n /**\n * Don't show logs during tests, really no point.\n */\n if (process.env.TESTING === \"true\") {\n return false;\n }\n return process.env.DEBUG === \"true\";\n};\n"],"mappings":"AAAA,OAAO,MAAMA,cAAc,GAAGA,CAAA,KAAe;EACzC;AACJ;AACA;EACI,IAAIC,OAAO,CAACC,GAAG,CAACC,OAAO,KAAK,MAAM,EAAE;IAChC,OAAO,KAAK;EAChB;EACA,OAAOF,OAAO,CAACC,GAAG,CAACE,KAAK,KAAK,MAAM;AACvC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"helpers/shouldShowLogs.js","sources":["../../src/helpers/shouldShowLogs.ts"],"sourcesContent":["export const shouldShowLogs = (): boolean => {\n /**\n * Don't show logs during tests, really no point.\n */\n if (process.env.TESTING === \"true\") {\n return false;\n }\n return process.env.DEBUG === \"true\";\n};\n"],"names":["shouldShowLogs","process"],"mappings":"AAAO,MAAMA,iBAAiB;IAI1B,IAAIC,AAAwB,WAAxBA,QAAQ,GAAG,CAAC,OAAO,EACnB,OAAO;IAEX,OAAOA,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK;AAC5B"}
package/index.js CHANGED
@@ -6,5 +6,3 @@ export * from "./NotEnoughRemainingTimeError.js";
6
6
  export * from "./Operations.js";
7
7
  export * from "./OperationsBuilder.js";
8
8
  export * from "./SynchronizationBuilder.js";
9
-
10
- //# sourceMappingURL=index.js.map
package/marshall.js CHANGED
@@ -1,19 +1,12 @@
1
- import { marshall as baseMarshall, unmarshall as baseUnmarshall } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
- export const marshall = value => {
3
- if (!value) {
4
- return value;
5
- }
6
- return baseMarshall(value);
1
+ import { marshall, unmarshall } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ const marshall_marshall = (value)=>{
3
+ if (!value) return value;
4
+ return marshall(value);
7
5
  };
8
- export const unmarshall = value => {
9
- if (!value) {
10
- return undefined;
11
- }
12
- /**
13
- * We can safely cast the return value to `T` because we are 100% positive that this is correct.
14
- */
15
- // @ts-expect-error
16
- return baseUnmarshall(value);
6
+ const marshall_unmarshall = (value)=>{
7
+ if (!value) return;
8
+ return unmarshall(value);
17
9
  };
10
+ export { marshall_marshall as marshall, marshall_unmarshall as unmarshall };
18
11
 
19
12
  //# sourceMappingURL=marshall.js.map
package/marshall.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["marshall","baseMarshall","unmarshall","baseUnmarshall","value","undefined"],"sources":["marshall.ts"],"sourcesContent":["import {\n marshall as baseMarshall,\n unmarshall as baseUnmarshall\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nimport type { AttributeValue } from \"@webiny/handler-aws/types.js\";\n\nexport interface MarshalledValue {\n [key: string]: AttributeValue;\n}\n\nexport const marshall = (value: GenericRecord): MarshalledValue => {\n if (!value) {\n return value;\n }\n return baseMarshall(value) as MarshalledValue;\n};\n\nexport const unmarshall = <T>(value?: MarshalledValue): T | undefined => {\n if (!value) {\n return undefined;\n }\n /**\n * We can safely cast the return value to `T` because we are 100% positive that this is correct.\n */\n // @ts-expect-error\n return baseUnmarshall(value) as T;\n};\n"],"mappings":"AAAA,SACIA,QAAQ,IAAIC,YAAY,EACxBC,UAAU,IAAIC,cAAc,QACzB,0CAA0C;AASjD,OAAO,MAAMH,QAAQ,GAAII,KAAoB,IAAsB;EAC/D,IAAI,CAACA,KAAK,EAAE;IACR,OAAOA,KAAK;EAChB;EACA,OAAOH,YAAY,CAACG,KAAK,CAAC;AAC9B,CAAC;AAED,OAAO,MAAMF,UAAU,GAAOE,KAAuB,IAAoB;EACrE,IAAI,CAACA,KAAK,EAAE;IACR,OAAOC,SAAS;EACpB;EACA;AACJ;AACA;EACI;EACA,OAAOF,cAAc,CAACC,KAAK,CAAC;AAChC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"marshall.js","sources":["../src/marshall.ts"],"sourcesContent":["import {\n marshall as baseMarshall,\n unmarshall as baseUnmarshall\n} from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nimport type { AttributeValue } from \"@webiny/handler-aws/types.js\";\n\nexport interface MarshalledValue {\n [key: string]: AttributeValue;\n}\n\nexport const marshall = (value: GenericRecord): MarshalledValue => {\n if (!value) {\n return value;\n }\n return baseMarshall(value) as MarshalledValue;\n};\n\nexport const unmarshall = <T>(value?: MarshalledValue): T | undefined => {\n if (!value) {\n return undefined;\n }\n /**\n * We can safely cast the return value to `T` because we are 100% positive that this is correct.\n */\n // @ts-expect-error\n return baseUnmarshall(value) as T;\n};\n"],"names":["marshall","value","baseMarshall","unmarshall","baseUnmarshall"],"mappings":";AAYO,MAAMA,oBAAW,CAACC;IACrB,IAAI,CAACA,OACD,OAAOA;IAEX,OAAOC,SAAaD;AACxB;AAEO,MAAME,sBAAa,CAAIF;IAC1B,IAAI,CAACA,OACD;IAMJ,OAAOG,WAAeH;AAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-dynamodb-to-elasticsearch",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -15,17 +15,17 @@
15
15
  "license": "MIT",
16
16
  "author": "Webiny Ltd.",
17
17
  "dependencies": {
18
- "@webiny/api": "6.3.0",
19
- "@webiny/api-opensearch": "6.3.0",
20
- "@webiny/aws-sdk": "6.3.0",
21
- "@webiny/error": "6.3.0",
22
- "@webiny/handler-aws": "6.3.0",
23
- "@webiny/utils": "6.3.0",
18
+ "@webiny/api": "6.4.0-beta.0",
19
+ "@webiny/api-opensearch": "6.4.0-beta.0",
20
+ "@webiny/aws-sdk": "6.4.0-beta.0",
21
+ "@webiny/error": "6.4.0-beta.0",
22
+ "@webiny/handler-aws": "6.4.0-beta.0",
23
+ "@webiny/utils": "6.4.0-beta.0",
24
24
  "p-retry": "8.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@webiny/build-tools": "6.3.0",
28
- "@webiny/plugins": "6.3.0",
27
+ "@webiny/build-tools": "6.4.0-beta.0",
28
+ "@webiny/plugins": "6.4.0-beta.0",
29
29
  "typescript": "6.0.3"
30
30
  },
31
31
  "publishConfig": {
@@ -37,5 +37,5 @@
37
37
  "__tests__"
38
38
  ]
39
39
  },
40
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
40
+ "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
41
41
  }
package/types.js CHANGED
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./eventHandler.js\";\nexport * from \"./execute.js\";\nexport * from \"./executeWithRetry.js\";\nexport * from \"./marshall.js\";\nexport * from \"./NotEnoughRemainingTimeError.js\";\nexport * from \"./Operations.js\";\nexport * from \"./OperationsBuilder.js\";\nexport * from \"./SynchronizationBuilder.js\";\nexport type * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { DynamoDBRecord, Context as HandlerContext } from \"@webiny/handler-aws/types.js\";\nimport type { OpenSearchContext } from \"@webiny/api-opensearch/types.js\";\n\nexport interface IOperationsBuilderBuildParams {\n records: DynamoDBRecord[];\n}\n\nexport interface IOperationsBuilder {\n build(params: IOperationsBuilderBuildParams): Promise<IOperations>;\n}\n\nexport interface IInsertOperationParams {\n id: string;\n index: string;\n data: GenericRecord;\n}\n\nexport type IModifyOperationParams = IInsertOperationParams;\n\nexport interface IDeleteOperationParams {\n id: string;\n index: string;\n}\n\nexport interface IOperations {\n items: GenericRecord[];\n total: number;\n clear(): void;\n insert(params: IInsertOperationParams): void;\n modify(params: IModifyOperationParams): void;\n delete(params: IDeleteOperationParams): void;\n}\n\nexport interface Context extends OpenSearchContext, HandlerContext {}\n"],"mappings":"","ignoreList":[]}