@webiny/api-dynamodb-to-elasticsearch 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.f6dc066313
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NotEnoughRemainingTimeError.js +2 -9
- package/NotEnoughRemainingTimeError.js.map +1 -1
- package/Operations.d.ts +2 -2
- package/Operations.js +2 -9
- package/Operations.js.map +1 -1
- package/OperationsBuilder.d.ts +2 -2
- package/OperationsBuilder.js +9 -16
- package/OperationsBuilder.js.map +1 -1
- package/README.md +8 -6
- package/SynchronizationBuilder.d.ts +3 -3
- package/SynchronizationBuilder.js +6 -14
- package/SynchronizationBuilder.js.map +1 -1
- package/eventHandler.js +8 -14
- package/eventHandler.js.map +1 -1
- package/execute.d.ts +2 -2
- package/execute.js +31 -20
- package/execute.js.map +1 -1
- package/executeWithRetry.d.ts +1 -1
- package/executeWithRetry.js +18 -23
- package/executeWithRetry.js.map +1 -1
- package/helpers/getNumberEnvVariable.js +1 -8
- package/helpers/getNumberEnvVariable.js.map +1 -1
- package/helpers/shouldShowLogs.d.ts +1 -0
- package/helpers/shouldShowLogs.js +11 -0
- package/helpers/shouldShowLogs.js.map +1 -0
- package/index.d.ts +9 -9
- package/index.js +8 -104
- package/index.js.map +1 -1
- package/marshall.d.ts +2 -2
- package/marshall.js +5 -13
- package/marshall.js.map +1 -1
- package/package.json +13 -17
- package/types.d.ts +4 -5
- package/types.js +1 -5
- package/types.js.map +1 -1
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NotEnoughRemainingTimeError = void 0;
|
|
7
|
-
var _error = require("@webiny/error");
|
|
8
|
-
class NotEnoughRemainingTimeError extends _error.WebinyError {}
|
|
9
|
-
exports.NotEnoughRemainingTimeError = NotEnoughRemainingTimeError;
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
2
|
+
export class NotEnoughRemainingTimeError extends WebinyError {}
|
|
10
3
|
|
|
11
4
|
//# sourceMappingURL=NotEnoughRemainingTimeError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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":[]}
|
package/Operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
2
|
-
import type { IDeleteOperationParams, IInsertOperationParams, IModifyOperationParams, IOperations } from "./types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { IDeleteOperationParams, IInsertOperationParams, IModifyOperationParams, IOperations } from "./types.js";
|
|
3
3
|
export declare enum OperationType {
|
|
4
4
|
INSERT = "INSERT",
|
|
5
5
|
MODIFY = "MODIFY",
|
package/Operations.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Operations = exports.OperationType = void 0;
|
|
7
|
-
let OperationType = exports.OperationType = /*#__PURE__*/function (OperationType) {
|
|
1
|
+
export let OperationType = /*#__PURE__*/function (OperationType) {
|
|
8
2
|
OperationType["INSERT"] = "INSERT";
|
|
9
3
|
OperationType["MODIFY"] = "MODIFY";
|
|
10
4
|
OperationType["REMOVE"] = "REMOVE";
|
|
11
5
|
return OperationType;
|
|
12
6
|
}({});
|
|
13
|
-
class Operations {
|
|
7
|
+
export class Operations {
|
|
14
8
|
_items = [];
|
|
15
9
|
get items() {
|
|
16
10
|
return this._items;
|
|
@@ -41,6 +35,5 @@ class Operations {
|
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
|
-
exports.Operations = Operations;
|
|
45
38
|
|
|
46
39
|
//# sourceMappingURL=Operations.js.map
|
package/Operations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OperationType","
|
|
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":[]}
|
package/OperationsBuilder.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IOperations, IOperationsBuilder, IOperationsBuilderBuildParams } from "./types";
|
|
2
|
-
import type { ICompressor } from "@webiny/utils/compression/Compressor";
|
|
1
|
+
import type { IOperations, IOperationsBuilder, IOperationsBuilderBuildParams } from "./types.js";
|
|
2
|
+
import type { ICompressor } from "@webiny/utils/compression/Compressor.js";
|
|
3
3
|
export interface IOperationsBuilderParams {
|
|
4
4
|
compressor: ICompressor;
|
|
5
5
|
}
|
package/OperationsBuilder.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OperationsBuilder = void 0;
|
|
7
|
-
var _Operations = require("./Operations");
|
|
8
|
-
var _marshall = require("./marshall");
|
|
9
|
-
class OperationsBuilder {
|
|
1
|
+
import { Operations, OperationType } from "./Operations.js";
|
|
2
|
+
import { unmarshall } from "./marshall.js";
|
|
3
|
+
export class OperationsBuilder {
|
|
10
4
|
constructor(params) {
|
|
11
5
|
this.compressor = params.compressor;
|
|
12
6
|
}
|
|
13
7
|
async build(params) {
|
|
14
|
-
const operations = new
|
|
8
|
+
const operations = new Operations();
|
|
15
9
|
for (const record of params.records) {
|
|
16
10
|
if (!record.dynamodb) {
|
|
17
11
|
continue;
|
|
@@ -19,7 +13,7 @@ class OperationsBuilder {
|
|
|
19
13
|
console.error(`Could not get operation from the record, skipping event "${record.eventID}".`);
|
|
20
14
|
continue;
|
|
21
15
|
}
|
|
22
|
-
const keys =
|
|
16
|
+
const keys = unmarshall(record.dynamodb.Keys);
|
|
23
17
|
if (!keys?.PK || !keys.SK) {
|
|
24
18
|
console.error(`Could not get keys from the record, skipping event "${record.eventID}".`);
|
|
25
19
|
continue;
|
|
@@ -30,8 +24,8 @@ class OperationsBuilder {
|
|
|
30
24
|
* On operations other than REMOVE we decompress the data and store it into the Elasticsearch.
|
|
31
25
|
* No need to try to decompress if operation is REMOVE since there is no data sent into that operation.
|
|
32
26
|
*/
|
|
33
|
-
if (record.eventName ===
|
|
34
|
-
const newImage =
|
|
27
|
+
if (record.eventName === OperationType.INSERT || record.eventName === OperationType.MODIFY) {
|
|
28
|
+
const newImage = unmarshall(record.dynamodb.NewImage);
|
|
35
29
|
/**
|
|
36
30
|
* If there is no newImage, silently continue to the next operation.
|
|
37
31
|
*/
|
|
@@ -79,8 +73,8 @@ class OperationsBuilder {
|
|
|
79
73
|
index: newImage.index,
|
|
80
74
|
data
|
|
81
75
|
});
|
|
82
|
-
} else if (record.eventName ===
|
|
83
|
-
const oldImage =
|
|
76
|
+
} else if (record.eventName === OperationType.REMOVE) {
|
|
77
|
+
const oldImage = unmarshall(record.dynamodb.OldImage);
|
|
84
78
|
/**
|
|
85
79
|
* If there is no index found, silently continue to the next operation.
|
|
86
80
|
*/
|
|
@@ -96,6 +90,5 @@ class OperationsBuilder {
|
|
|
96
90
|
return operations;
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
|
-
exports.OperationsBuilder = OperationsBuilder;
|
|
100
93
|
|
|
101
94
|
//# sourceMappingURL=OperationsBuilder.js.map
|
package/OperationsBuilder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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 { ICompressor } from \"@webiny/utils/compression/Compressor.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: ICompressor;\n}\n\nexport class OperationsBuilder implements IOperationsBuilder {\n private readonly compressor: ICompressor;\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":[]}
|
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# @webiny/api-dynamodb-to-elasticsearch
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/api-file-manager)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/api-file-manager)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Context, IDeleteOperationParams, IInsertOperationParams, IModifyOperationParams } from "./types";
|
|
2
|
-
import type { IExecuteWithRetryParams } from "./executeWithRetry";
|
|
1
|
+
import type { Context, IDeleteOperationParams, IInsertOperationParams, IModifyOperationParams } from "./types.js";
|
|
2
|
+
import type { IExecuteWithRetryParams } from "./executeWithRetry.js";
|
|
3
3
|
import type { ITimer } from "@webiny/handler-aws";
|
|
4
4
|
export type ISynchronizationBuilderExecuteWithRetryParams = Omit<IExecuteWithRetryParams, "context" | "timer" | "maxRunningTime" | "operations">;
|
|
5
5
|
export interface ISynchronizationBuilder {
|
|
@@ -9,7 +9,7 @@ export interface ISynchronizationBuilder {
|
|
|
9
9
|
}
|
|
10
10
|
export interface ISynchronizationBuilderParams {
|
|
11
11
|
timer: ITimer;
|
|
12
|
-
context: Pick<Context, "elasticsearch"
|
|
12
|
+
context: Pick<Context, "elasticsearch">;
|
|
13
13
|
}
|
|
14
14
|
export declare class SynchronizationBuilder implements ISynchronizationBuilder {
|
|
15
15
|
private readonly timer;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createSynchronizationBuilder = exports.SynchronizationBuilder = void 0;
|
|
7
|
-
var _Operations = require("./Operations");
|
|
8
|
-
var _executeWithRetry = require("./executeWithRetry");
|
|
9
|
-
class SynchronizationBuilder {
|
|
1
|
+
import { Operations } from "./Operations.js";
|
|
2
|
+
import { executeWithRetry } from "./executeWithRetry.js";
|
|
3
|
+
export class SynchronizationBuilder {
|
|
10
4
|
constructor(params) {
|
|
11
5
|
this.timer = params.timer;
|
|
12
6
|
this.context = params.context;
|
|
13
|
-
this.operations = new
|
|
7
|
+
this.operations = new Operations();
|
|
14
8
|
}
|
|
15
9
|
insert(params) {
|
|
16
10
|
return this.operations.insert(params);
|
|
@@ -26,7 +20,7 @@ class SynchronizationBuilder {
|
|
|
26
20
|
if (this.operations.total === 0) {
|
|
27
21
|
return;
|
|
28
22
|
}
|
|
29
|
-
await
|
|
23
|
+
await executeWithRetry({
|
|
30
24
|
...params,
|
|
31
25
|
maxRunningTime: this.timer.getRemainingMilliseconds(),
|
|
32
26
|
timer: this.timer,
|
|
@@ -37,10 +31,8 @@ class SynchronizationBuilder {
|
|
|
37
31
|
};
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
const createSynchronizationBuilder = params => {
|
|
34
|
+
export const createSynchronizationBuilder = params => {
|
|
42
35
|
return new SynchronizationBuilder(params);
|
|
43
36
|
};
|
|
44
|
-
exports.createSynchronizationBuilder = createSynchronizationBuilder;
|
|
45
37
|
|
|
46
38
|
//# sourceMappingURL=SynchronizationBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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, \"elasticsearch\">;\n}\n\nexport class SynchronizationBuilder implements ISynchronizationBuilder {\n private readonly timer: ITimer;\n private readonly context: Pick<Context, \"elasticsearch\">;\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":[]}
|
package/eventHandler.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { createDynamoDBEventHandler, timerFactory } from "@webiny/handler-aws";
|
|
2
|
+
import { OperationsBuilder } from "./OperationsBuilder.js";
|
|
3
|
+
import { executeWithRetry } from "./executeWithRetry.js";
|
|
2
4
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createEventHandler = void 0;
|
|
7
|
-
var _handlerAws = require("@webiny/handler-aws");
|
|
8
|
-
var _OperationsBuilder = require("./OperationsBuilder");
|
|
9
|
-
var _executeWithRetry = require("./executeWithRetry");
|
|
10
5
|
/**
|
|
11
6
|
* Also, we need to set the maximum running time for the Lambda Function.
|
|
12
7
|
* https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreOpenSearch.ts#L232
|
|
13
8
|
* https://github.com/webiny/webiny-js/blob/f7352d418da2b5ae0b781376be46785aa7ac6ae0/packages/pulumi-aws/src/apps/core/CoreElasticSearch.ts#L218
|
|
14
9
|
*/
|
|
15
10
|
const MAX_RUNNING_TIME = 900;
|
|
16
|
-
const createEventHandler = () => {
|
|
17
|
-
return
|
|
11
|
+
export const createEventHandler = () => {
|
|
12
|
+
return createDynamoDBEventHandler(async ({
|
|
18
13
|
event,
|
|
19
14
|
context: ctx,
|
|
20
15
|
lambdaContext
|
|
21
16
|
}) => {
|
|
22
|
-
const timer =
|
|
17
|
+
const timer = timerFactory(lambdaContext);
|
|
23
18
|
const context = ctx;
|
|
24
19
|
if (!context.elasticsearch) {
|
|
25
20
|
console.error("Missing elasticsearch definition on context.");
|
|
26
21
|
return null;
|
|
27
22
|
}
|
|
28
|
-
const builder = new
|
|
23
|
+
const builder = new OperationsBuilder({
|
|
29
24
|
compressor: context.compressor
|
|
30
25
|
});
|
|
31
26
|
const operations = await builder.build({
|
|
@@ -40,7 +35,7 @@ const createEventHandler = () => {
|
|
|
40
35
|
/**
|
|
41
36
|
* Execute the operations with retry.
|
|
42
37
|
*/
|
|
43
|
-
await
|
|
38
|
+
await executeWithRetry({
|
|
44
39
|
timer,
|
|
45
40
|
maxRunningTime: MAX_RUNNING_TIME,
|
|
46
41
|
context,
|
|
@@ -49,6 +44,5 @@ const createEventHandler = () => {
|
|
|
49
44
|
return null;
|
|
50
45
|
});
|
|
51
46
|
};
|
|
52
|
-
exports.createEventHandler = createEventHandler;
|
|
53
47
|
|
|
54
48
|
//# sourceMappingURL=eventHandler.js.map
|
package/eventHandler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createDynamoDBEventHandler","timerFactory","OperationsBuilder","executeWithRetry","MAX_RUNNING_TIME","createEventHandler","event","context","ctx","lambdaContext","timer","elasticsearch","console","error","builder","compressor","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\";\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.elasticsearch) {\n console.error(\"Missing elasticsearch definition on context.\");\n return null;\n }\n\n const builder = new OperationsBuilder({\n compressor: context.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;;AAEzB;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,GAAG;AAE5B,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAOL,0BAA0B,CAAC,OAAO;IAAEM,KAAK;IAAEC,OAAO,EAAEC,GAAG;IAAEC;EAAc,CAAC,KAAK;IAChF,MAAMC,KAAK,GAAGT,YAAY,CAACQ,aAAa,CAAC;IACzC,MAAMF,OAAO,GAAGC,GAAyB;IACzC,IAAI,CAACD,OAAO,CAACI,aAAa,EAAE;MACxBC,OAAO,CAACC,KAAK,CAAC,8CAA8C,CAAC;MAC7D,OAAO,IAAI;IACf;IAEA,MAAMC,OAAO,GAAG,IAAIZ,iBAAiB,CAAC;MAClCa,UAAU,EAAER,OAAO,CAACQ;IACxB,CAAC,CAAC;IAEF,MAAMC,UAAU,GAAG,MAAMF,OAAO,CAACG,KAAK,CAAC;MACnCC,OAAO,EAAEZ,KAAK,CAACa;IACnB,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAIH,UAAU,CAACI,KAAK,KAAK,CAAC,EAAE;MACxB,OAAO,IAAI;IACf;IACA;AACR;AACA;IACQ,MAAMjB,gBAAgB,CAAC;MACnBO,KAAK;MACLW,cAAc,EAAEjB,gBAAgB;MAChCG,OAAO;MACPS;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
package/execute.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ITimer } from "@webiny/handler-aws";
|
|
2
|
-
import type { Context, IOperations } from "./types";
|
|
2
|
+
import type { Context, IOperations } from "./types.js";
|
|
3
3
|
export interface BulkOperationsResponseBodyItemIndexError {
|
|
4
4
|
reason?: string;
|
|
5
5
|
}
|
|
@@ -17,7 +17,7 @@ export interface IExecuteParams {
|
|
|
17
17
|
timer: ITimer;
|
|
18
18
|
maxRunningTime: number;
|
|
19
19
|
maxProcessorPercent: number;
|
|
20
|
-
context: Pick<Context, "elasticsearch"
|
|
20
|
+
context: Pick<Context, "elasticsearch">;
|
|
21
21
|
operations: Pick<IOperations, "items" | "total">;
|
|
22
22
|
}
|
|
23
23
|
export declare const execute: (params: IExecuteParams) => () => Promise<void>;
|
package/execute.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.execute = void 0;
|
|
7
|
-
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
8
|
-
var _error = require("@webiny/error");
|
|
1
|
+
import { createWaitUntilHealthy, ElasticsearchCatClusterHealthStatus, UnhealthyClusterError, WaitingHealthyClusterAbortedError } from "@webiny/api-elasticsearch";
|
|
2
|
+
import { WebinyError } from "@webiny/error";
|
|
3
|
+
import { shouldShowLogs } from "./helpers/shouldShowLogs.js";
|
|
9
4
|
const getError = item => {
|
|
10
5
|
if (!item.index?.error?.reason) {
|
|
11
6
|
return null;
|
|
@@ -31,10 +26,10 @@ const checkErrors = result => {
|
|
|
31
26
|
continue;
|
|
32
27
|
}
|
|
33
28
|
console.error("Body item with error", item);
|
|
34
|
-
throw new
|
|
29
|
+
throw new WebinyError(err, "DYNAMODB_TO_OPENSEARCH_ERROR", item);
|
|
35
30
|
}
|
|
36
31
|
};
|
|
37
|
-
const execute = params => {
|
|
32
|
+
export const execute = params => {
|
|
38
33
|
return async () => {
|
|
39
34
|
const {
|
|
40
35
|
context,
|
|
@@ -49,16 +44,34 @@ const execute = params => {
|
|
|
49
44
|
const remainingTime = timer.getRemainingSeconds();
|
|
50
45
|
const runningTime = maxRunningTime - remainingTime;
|
|
51
46
|
const maxWaitingTime = remainingTime - 90;
|
|
52
|
-
if (
|
|
47
|
+
if (shouldShowLogs()) {
|
|
53
48
|
console.debug(`The Lambda is already running for ${runningTime}s. Setting Health Check max waiting time: ${maxWaitingTime}s`);
|
|
54
49
|
}
|
|
55
|
-
const healthCheck =
|
|
56
|
-
minClusterHealthStatus:
|
|
50
|
+
const healthCheck = createWaitUntilHealthy(context.elasticsearch, {
|
|
51
|
+
minClusterHealthStatus: ElasticsearchCatClusterHealthStatus.Yellow,
|
|
57
52
|
waitingTimeStep: 30,
|
|
58
53
|
maxProcessorPercent,
|
|
59
54
|
maxWaitingTime
|
|
60
55
|
});
|
|
61
|
-
|
|
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
|
+
};
|
|
62
75
|
try {
|
|
63
76
|
await healthCheck.wait({
|
|
64
77
|
async onUnhealthy({
|
|
@@ -91,7 +104,7 @@ const execute = params => {
|
|
|
91
104
|
}
|
|
92
105
|
});
|
|
93
106
|
} catch (ex) {
|
|
94
|
-
if (ex instanceof
|
|
107
|
+
if (ex instanceof UnhealthyClusterError || ex instanceof WaitingHealthyClusterAbortedError) {
|
|
95
108
|
throw ex;
|
|
96
109
|
}
|
|
97
110
|
console.error(`Cluster health check failed.`, ex);
|
|
@@ -104,10 +117,9 @@ const execute = params => {
|
|
|
104
117
|
checkErrors(res);
|
|
105
118
|
} catch (error) {
|
|
106
119
|
log.error(error, {
|
|
107
|
-
tenant: "root"
|
|
108
|
-
locale: "unknown"
|
|
120
|
+
tenant: "root"
|
|
109
121
|
});
|
|
110
|
-
if (
|
|
122
|
+
if (shouldShowLogs() === false) {
|
|
111
123
|
throw error;
|
|
112
124
|
}
|
|
113
125
|
const meta = error?.meta || {};
|
|
@@ -115,12 +127,11 @@ const execute = params => {
|
|
|
115
127
|
console.error("Bulk error", JSON.stringify(error, null, 2));
|
|
116
128
|
throw error;
|
|
117
129
|
}
|
|
118
|
-
if (
|
|
130
|
+
if (shouldShowLogs() === false) {
|
|
119
131
|
return;
|
|
120
132
|
}
|
|
121
133
|
console.info(`Transferred ${operations.total} record operations to Elasticsearch.`);
|
|
122
134
|
};
|
|
123
135
|
};
|
|
124
|
-
exports.execute = execute;
|
|
125
136
|
|
|
126
137
|
//# sourceMappingURL=execute.js.map
|
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createWaitUntilHealthy","ElasticsearchCatClusterHealthStatus","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","elasticsearch","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 ElasticsearchCatClusterHealthStatus,\n UnhealthyClusterError,\n WaitingHealthyClusterAbortedError\n} from \"@webiny/api-elasticsearch\";\nimport type { ITimer } from \"@webiny/handler-aws\";\nimport type { ApiResponse } from \"@webiny/api-elasticsearch/types.js\";\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, \"elasticsearch\">;\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<BulkOperationsResponseBody>): 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.elasticsearch, {\n minClusterHealthStatus: ElasticsearchCatClusterHealthStatus.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.elasticsearch.bulk<BulkOperationsResponseBody>({\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":[]}
|
package/executeWithRetry.d.ts
CHANGED
package/executeWithRetry.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.executeWithRetry = void 0;
|
|
8
|
-
var _execute = require("./execute");
|
|
9
|
-
var _NotEnoughRemainingTimeError = require("./NotEnoughRemainingTimeError");
|
|
10
|
-
var _pRetry = _interopRequireDefault(require("p-retry"));
|
|
11
|
-
var _getNumberEnvVariable = require("./helpers/getNumberEnvVariable");
|
|
1
|
+
import { execute } from "./execute.js";
|
|
2
|
+
import { NotEnoughRemainingTimeError } from "./NotEnoughRemainingTimeError.js";
|
|
3
|
+
import pRetry from "p-retry";
|
|
4
|
+
import { getNumberEnvVariable } from "./helpers/getNumberEnvVariable.js";
|
|
12
5
|
const minRemainingSecondsToTimeout = 120;
|
|
13
|
-
const MAX_PROCESSOR_PERCENT =
|
|
14
|
-
const executeWithRetry = async params => {
|
|
15
|
-
const maxRetryTime =
|
|
16
|
-
const retries =
|
|
17
|
-
const minTimeout =
|
|
18
|
-
const maxTimeout =
|
|
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);
|
|
19
12
|
try {
|
|
20
|
-
await (
|
|
13
|
+
await pRetry(execute({
|
|
21
14
|
timer: params.timer,
|
|
22
15
|
maxRunningTime: params.maxRunningTime,
|
|
23
16
|
maxProcessorPercent: params.maxProcessorPercent || MAX_PROCESSOR_PERCENT,
|
|
@@ -28,17 +21,20 @@ const executeWithRetry = async params => {
|
|
|
28
21
|
retries,
|
|
29
22
|
minTimeout,
|
|
30
23
|
maxTimeout,
|
|
31
|
-
onFailedAttempt:
|
|
24
|
+
onFailedAttempt: ({
|
|
25
|
+
error,
|
|
26
|
+
attemptNumber
|
|
27
|
+
}) => {
|
|
32
28
|
if (params.timer.getRemainingSeconds() < minRemainingSecondsToTimeout) {
|
|
33
|
-
throw new
|
|
29
|
+
throw new NotEnoughRemainingTimeError(error);
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
32
|
* We will only log attempts which are after 3/4 of total attempts.
|
|
37
33
|
*/
|
|
38
|
-
if (
|
|
34
|
+
if (attemptNumber < retries * 0.75) {
|
|
39
35
|
return;
|
|
40
36
|
}
|
|
41
|
-
console.error(`Attempt #${
|
|
37
|
+
console.error(`Attempt #${attemptNumber} failed.`);
|
|
42
38
|
console.error(error);
|
|
43
39
|
}
|
|
44
40
|
});
|
|
@@ -47,6 +43,5 @@ const executeWithRetry = async params => {
|
|
|
47
43
|
throw ex;
|
|
48
44
|
}
|
|
49
45
|
};
|
|
50
|
-
exports.executeWithRetry = executeWithRetry;
|
|
51
46
|
|
|
52
47
|
//# sourceMappingURL=executeWithRetry.js.map
|
package/executeWithRetry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getNumberEnvVariable = void 0;
|
|
7
|
-
const getNumberEnvVariable = (name, def) => {
|
|
1
|
+
export const getNumberEnvVariable = (name, def) => {
|
|
8
2
|
const input = process.env[name];
|
|
9
3
|
const value = Number(input);
|
|
10
4
|
if (isNaN(value)) {
|
|
@@ -14,6 +8,5 @@ const getNumberEnvVariable = (name, def) => {
|
|
|
14
8
|
}
|
|
15
9
|
return value;
|
|
16
10
|
};
|
|
17
|
-
exports.getNumberEnvVariable = getNumberEnvVariable;
|
|
18
11
|
|
|
19
12
|
//# sourceMappingURL=getNumberEnvVariable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getNumberEnvVariable","name","def","input","process","env","value","Number","isNaN"
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shouldShowLogs: () => boolean;
|
|
@@ -0,0 +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":[]}
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from "./eventHandler";
|
|
2
|
-
export * from "./execute";
|
|
3
|
-
export * from "./executeWithRetry";
|
|
4
|
-
export * from "./marshall";
|
|
5
|
-
export * from "./NotEnoughRemainingTimeError";
|
|
6
|
-
export * from "./Operations";
|
|
7
|
-
export * from "./OperationsBuilder";
|
|
8
|
-
export * from "./SynchronizationBuilder";
|
|
9
|
-
export * from "./types";
|
|
1
|
+
export * from "./eventHandler.js";
|
|
2
|
+
export * from "./execute.js";
|
|
3
|
+
export * from "./executeWithRetry.js";
|
|
4
|
+
export * from "./marshall.js";
|
|
5
|
+
export * from "./NotEnoughRemainingTimeError.js";
|
|
6
|
+
export * from "./Operations.js";
|
|
7
|
+
export * from "./OperationsBuilder.js";
|
|
8
|
+
export * from "./SynchronizationBuilder.js";
|
|
9
|
+
export type * from "./types.js";
|
package/index.js
CHANGED
|
@@ -1,106 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (key in exports && exports[key] === _eventHandler[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _eventHandler[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _execute = require("./execute");
|
|
18
|
-
Object.keys(_execute).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _execute[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _execute[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _executeWithRetry = require("./executeWithRetry");
|
|
29
|
-
Object.keys(_executeWithRetry).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _executeWithRetry[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _executeWithRetry[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _marshall = require("./marshall");
|
|
40
|
-
Object.keys(_marshall).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _marshall[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _marshall[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
var _NotEnoughRemainingTimeError = require("./NotEnoughRemainingTimeError");
|
|
51
|
-
Object.keys(_NotEnoughRemainingTimeError).forEach(function (key) {
|
|
52
|
-
if (key === "default" || key === "__esModule") return;
|
|
53
|
-
if (key in exports && exports[key] === _NotEnoughRemainingTimeError[key]) return;
|
|
54
|
-
Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _NotEnoughRemainingTimeError[key];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
var _Operations = require("./Operations");
|
|
62
|
-
Object.keys(_Operations).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _Operations[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _Operations[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
var _OperationsBuilder = require("./OperationsBuilder");
|
|
73
|
-
Object.keys(_OperationsBuilder).forEach(function (key) {
|
|
74
|
-
if (key === "default" || key === "__esModule") return;
|
|
75
|
-
if (key in exports && exports[key] === _OperationsBuilder[key]) return;
|
|
76
|
-
Object.defineProperty(exports, key, {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _OperationsBuilder[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
var _SynchronizationBuilder = require("./SynchronizationBuilder");
|
|
84
|
-
Object.keys(_SynchronizationBuilder).forEach(function (key) {
|
|
85
|
-
if (key === "default" || key === "__esModule") return;
|
|
86
|
-
if (key in exports && exports[key] === _SynchronizationBuilder[key]) return;
|
|
87
|
-
Object.defineProperty(exports, key, {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return _SynchronizationBuilder[key];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
var _types = require("./types");
|
|
95
|
-
Object.keys(_types).forEach(function (key) {
|
|
96
|
-
if (key === "default" || key === "__esModule") return;
|
|
97
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
98
|
-
Object.defineProperty(exports, key, {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: function () {
|
|
101
|
-
return _types[key];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
1
|
+
export * from "./eventHandler.js";
|
|
2
|
+
export * from "./execute.js";
|
|
3
|
+
export * from "./executeWithRetry.js";
|
|
4
|
+
export * from "./marshall.js";
|
|
5
|
+
export * from "./NotEnoughRemainingTimeError.js";
|
|
6
|
+
export * from "./Operations.js";
|
|
7
|
+
export * from "./OperationsBuilder.js";
|
|
8
|
+
export * from "./SynchronizationBuilder.js";
|
|
105
9
|
|
|
106
10
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
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/marshall.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
2
|
-
import type { AttributeValue } from "@webiny/handler-aws/types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { AttributeValue } from "@webiny/handler-aws/types.js";
|
|
3
3
|
export interface MarshalledValue {
|
|
4
4
|
[key: string]: AttributeValue;
|
|
5
5
|
}
|
package/marshall.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.unmarshall = exports.marshall = void 0;
|
|
7
|
-
var _clientDynamodb = require("@webiny/aws-sdk/client-dynamodb");
|
|
8
|
-
const marshall = value => {
|
|
1
|
+
import { marshall as baseMarshall, unmarshall as baseUnmarshall } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export const marshall = value => {
|
|
9
3
|
if (!value) {
|
|
10
4
|
return value;
|
|
11
5
|
}
|
|
12
|
-
return (
|
|
6
|
+
return baseMarshall(value);
|
|
13
7
|
};
|
|
14
|
-
|
|
15
|
-
const unmarshall = value => {
|
|
8
|
+
export const unmarshall = value => {
|
|
16
9
|
if (!value) {
|
|
17
10
|
return undefined;
|
|
18
11
|
}
|
|
@@ -20,8 +13,7 @@ const unmarshall = value => {
|
|
|
20
13
|
* We can safely cast the return value to `T` because we are 100% positive that this is correct.
|
|
21
14
|
*/
|
|
22
15
|
// @ts-expect-error
|
|
23
|
-
return (
|
|
16
|
+
return baseUnmarshall(value);
|
|
24
17
|
};
|
|
25
|
-
exports.unmarshall = unmarshall;
|
|
26
18
|
|
|
27
19
|
//# sourceMappingURL=marshall.js.map
|
package/marshall.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-dynamodb-to-elasticsearch",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.f6dc066313",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -11,32 +12,27 @@
|
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"author": "Webiny Ltd.",
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@webiny/api": "0.0.0-unstable.
|
|
15
|
-
"@webiny/api-elasticsearch": "0.0.0-unstable.
|
|
16
|
-
"@webiny/
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/
|
|
20
|
-
"
|
|
21
|
-
"p-retry": "4.6.2"
|
|
15
|
+
"@webiny/api": "0.0.0-unstable.f6dc066313",
|
|
16
|
+
"@webiny/api-elasticsearch": "0.0.0-unstable.f6dc066313",
|
|
17
|
+
"@webiny/aws-sdk": "0.0.0-unstable.f6dc066313",
|
|
18
|
+
"@webiny/error": "0.0.0-unstable.f6dc066313",
|
|
19
|
+
"@webiny/handler-aws": "0.0.0-unstable.f6dc066313",
|
|
20
|
+
"@webiny/utils": "0.0.0-unstable.f6dc066313",
|
|
21
|
+
"p-retry": "7.1.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/
|
|
26
|
-
"typescript": "5.
|
|
24
|
+
"@webiny/build-tools": "0.0.0-unstable.f6dc066313",
|
|
25
|
+
"@webiny/plugins": "0.0.0-unstable.f6dc066313",
|
|
26
|
+
"typescript": "5.9.3"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public",
|
|
30
30
|
"directory": "dist"
|
|
31
31
|
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"build": "node ../cli/bin.js run build",
|
|
34
|
-
"watch": "node ../cli/bin.js run watch"
|
|
35
|
-
},
|
|
36
32
|
"adio": {
|
|
37
33
|
"ignoreDirs": [
|
|
38
34
|
"__tests__"
|
|
39
35
|
]
|
|
40
36
|
},
|
|
41
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f6dc066313ddce5339d2aacec3aa84e61232689b"
|
|
42
38
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
2
|
-
import type { DynamoDBRecord } from "@webiny/handler-aws/types";
|
|
3
|
-
import type { ElasticsearchContext } from "@webiny/api-elasticsearch/types";
|
|
4
|
-
import type { Context as LoggerContext } from "@webiny/api-log/types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { DynamoDBRecord } from "@webiny/handler-aws/types.js";
|
|
3
|
+
import type { ElasticsearchContext } from "@webiny/api-elasticsearch/types.js";
|
|
5
4
|
export interface IOperationsBuilderBuildParams {
|
|
6
5
|
records: DynamoDBRecord[];
|
|
7
6
|
}
|
|
@@ -26,5 +25,5 @@ export interface IOperations {
|
|
|
26
25
|
modify(params: IModifyOperationParams): void;
|
|
27
26
|
delete(params: IDeleteOperationParams): void;
|
|
28
27
|
}
|
|
29
|
-
export interface Context extends ElasticsearchContext
|
|
28
|
+
export interface Context extends ElasticsearchContext {
|
|
30
29
|
}
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types\";\nimport type { DynamoDBRecord } from \"@webiny/handler-aws/types\";\nimport type { ElasticsearchContext } from \"@webiny/api-elasticsearch/types\";\
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { DynamoDBRecord } from \"@webiny/handler-aws/types.js\";\nimport type { ElasticsearchContext } from \"@webiny/api-elasticsearch/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 ElasticsearchContext {}\n"],"mappings":"","ignoreList":[]}
|