@webiny/api-search-index-tasks-ddb-os 6.6.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/index.d.ts +4 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/package.json +40 -0
- package/storage/StorageScanner.d.ts +11 -0
- package/storage/StorageScanner.js +45 -0
- package/storage/StorageScanner.js.map +1 -0
- package/storage/StorageWriter.d.ts +15 -0
- package/storage/StorageWriter.js +45 -0
- package/storage/StorageWriter.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-search-index-tasks-ddb-os
|
|
2
|
+
|
|
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.
|
|
6
|
+
|
|
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._
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SearchIndexTasksOsFeature } from "@webiny/api-search-index-tasks-os";
|
|
3
|
+
import { DdbStorageScanner } from "./storage/StorageScanner.js";
|
|
4
|
+
import { DdbStorageWriter } from "./storage/StorageWriter.js";
|
|
5
|
+
const SearchIndexTasksDdbOsFeature = createFeature({
|
|
6
|
+
name: "SearchIndexTasksDdbOs",
|
|
7
|
+
register (container) {
|
|
8
|
+
SearchIndexTasksOsFeature.register(container);
|
|
9
|
+
container.register(DdbStorageScanner);
|
|
10
|
+
container.register(DdbStorageWriter);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { SearchIndexTasksDdbOsFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SearchIndexTasksOsFeature } from \"@webiny/api-search-index-tasks-os\";\nimport { DdbStorageScanner } from \"~/storage/StorageScanner.js\";\nimport { DdbStorageWriter } from \"~/storage/StorageWriter.js\";\n\nexport const SearchIndexTasksDdbOsFeature = createFeature({\n name: \"SearchIndexTasksDdbOs\",\n register(container) {\n SearchIndexTasksOsFeature.register(container);\n container.register(DdbStorageScanner);\n container.register(DdbStorageWriter);\n }\n});\n"],"names":["SearchIndexTasksDdbOsFeature","createFeature","container","SearchIndexTasksOsFeature","DdbStorageScanner","DdbStorageWriter"],"mappings":";;;;AAKO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdC,0BAA0B,QAAQ,CAACD;QACnCA,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-search-index-tasks-ddb-os",
|
|
3
|
+
"version": "6.6.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
12
|
+
"directory": "packages/api-search-index-tasks-ddb-os"
|
|
13
|
+
},
|
|
14
|
+
"description": "DynamoDB + OpenSearch bridge for @webiny/api-search-index-tasks.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Webiny Ltd.",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@webiny/api-opensearch": "6.6.0-alpha.0",
|
|
19
|
+
"@webiny/api-search-index-tasks": "6.6.0-alpha.0",
|
|
20
|
+
"@webiny/api-search-index-tasks-os": "6.6.0-alpha.0",
|
|
21
|
+
"@webiny/db-dynamodb": "6.6.0-alpha.0",
|
|
22
|
+
"@webiny/feature": "6.6.0-alpha.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@webiny/build-tools": "6.6.0-alpha.0",
|
|
26
|
+
"typescript": "7.0.2",
|
|
27
|
+
"vitest": "4.1.10"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"adio": {
|
|
33
|
+
"ignoreDirs": [
|
|
34
|
+
"__tests__"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"webiny": {
|
|
38
|
+
"publishFrom": "dist"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StorageScanner as Abstraction } from "@webiny/api-search-index-tasks/abstractions/StorageScanner.js";
|
|
2
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
3
|
+
declare class DdbStorageScannerImpl implements Abstraction.Interface {
|
|
4
|
+
private readonly table;
|
|
5
|
+
constructor(dynamoDBClient: DynamoDBClient.Interface);
|
|
6
|
+
scan(cursor: string | undefined, limit: number): Promise<Abstraction.Result>;
|
|
7
|
+
}
|
|
8
|
+
export declare const DdbStorageScanner: typeof DdbStorageScannerImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-search-index-tasks/abstractions/StorageScanner.js").IStorageScanner>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { StorageScanner } from "@webiny/api-search-index-tasks/abstractions/StorageScanner.js";
|
|
2
|
+
import { scan } from "@webiny/db-dynamodb";
|
|
3
|
+
import { createOpenSearchTable } from "@webiny/api-opensearch";
|
|
4
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
5
|
+
class DdbStorageScannerImpl {
|
|
6
|
+
constructor(dynamoDBClient){
|
|
7
|
+
this.table = createOpenSearchTable({
|
|
8
|
+
documentClient: dynamoDBClient.client
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async scan(cursor, limit) {
|
|
12
|
+
const startKey = cursor ? JSON.parse(cursor) : void 0;
|
|
13
|
+
const results = await scan({
|
|
14
|
+
table: this.table.table,
|
|
15
|
+
options: {
|
|
16
|
+
startKey,
|
|
17
|
+
limit
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const items = results.items.map((item)=>({
|
|
21
|
+
index: item.index,
|
|
22
|
+
entity: item._et || item.entity,
|
|
23
|
+
data: item,
|
|
24
|
+
modified: item.modified
|
|
25
|
+
}));
|
|
26
|
+
let nextCursor;
|
|
27
|
+
if (results.lastEvaluatedKey?.PK && results.lastEvaluatedKey?.SK) nextCursor = JSON.stringify({
|
|
28
|
+
PK: results.lastEvaluatedKey.PK,
|
|
29
|
+
SK: results.lastEvaluatedKey.SK
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
items,
|
|
33
|
+
cursor: nextCursor
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const DdbStorageScanner = StorageScanner.createImplementation({
|
|
38
|
+
implementation: DdbStorageScannerImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
DynamoDBClient
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
export { DdbStorageScanner };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=StorageScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage/StorageScanner.js","sources":["../../src/storage/StorageScanner.ts"],"sourcesContent":["import { StorageScanner as Abstraction } from \"@webiny/api-search-index-tasks/abstractions/StorageScanner.js\";\nimport { scan } from \"@webiny/db-dynamodb\";\nimport { createOpenSearchTable } from \"@webiny/api-opensearch\";\nimport { DynamoDBClient } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface IDynamoDbElasticsearchRecord {\n PK: string;\n SK: string;\n index: string;\n _et?: string;\n entity: string;\n data: Record<string, any>;\n modified: string;\n [key: string]: any;\n}\n\ninterface IDdbCursor {\n PK: string;\n SK: string;\n}\n\nclass DdbStorageScannerImpl implements Abstraction.Interface {\n private readonly table;\n\n constructor(dynamoDBClient: DynamoDBClient.Interface) {\n this.table = createOpenSearchTable({\n documentClient: dynamoDBClient.client\n });\n }\n\n async scan(cursor: string | undefined, limit: number): Promise<Abstraction.Result> {\n const startKey = cursor ? (JSON.parse(cursor) as IDdbCursor) : undefined;\n\n const results = await scan<IDynamoDbElasticsearchRecord>({\n table: this.table.table,\n options: {\n startKey,\n limit\n }\n });\n\n const items = results.items.map(item => ({\n index: item.index,\n entity: item._et || item.entity,\n data: item,\n modified: item.modified\n }));\n\n let nextCursor: string | undefined;\n if (results.lastEvaluatedKey?.PK && results.lastEvaluatedKey?.SK) {\n nextCursor = JSON.stringify({\n PK: results.lastEvaluatedKey.PK,\n SK: results.lastEvaluatedKey.SK\n });\n }\n\n return {\n items,\n cursor: nextCursor\n };\n }\n}\n\nexport const DdbStorageScanner = Abstraction.createImplementation({\n implementation: DdbStorageScannerImpl,\n dependencies: [DynamoDBClient]\n});\n"],"names":["DdbStorageScannerImpl","dynamoDBClient","createOpenSearchTable","cursor","limit","startKey","JSON","undefined","results","scan","items","item","nextCursor","DdbStorageScanner","Abstraction","DynamoDBClient"],"mappings":";;;;AAqBA,MAAMA;IAGF,YAAYC,cAAwC,CAAE;QAClD,IAAI,CAAC,KAAK,GAAGC,sBAAsB;YAC/B,gBAAgBD,eAAe,MAAM;QACzC;IACJ;IAEA,MAAM,KAAKE,MAA0B,EAAEC,KAAa,EAA+B;QAC/E,MAAMC,WAAWF,SAAUG,KAAK,KAAK,CAACH,UAAyBI;QAE/D,MAAMC,UAAU,MAAMC,KAAmC;YACrD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;YACvB,SAAS;gBACLJ;gBACAD;YACJ;QACJ;QAEA,MAAMM,QAAQF,QAAQ,KAAK,CAAC,GAAG,CAACG,CAAAA,OAAS;gBACrC,OAAOA,KAAK,KAAK;gBACjB,QAAQA,KAAK,GAAG,IAAIA,KAAK,MAAM;gBAC/B,MAAMA;gBACN,UAAUA,KAAK,QAAQ;YAC3B;QAEA,IAAIC;QACJ,IAAIJ,QAAQ,gBAAgB,EAAE,MAAMA,QAAQ,gBAAgB,EAAE,IAC1DI,aAAaN,KAAK,SAAS,CAAC;YACxB,IAAIE,QAAQ,gBAAgB,CAAC,EAAE;YAC/B,IAAIA,QAAQ,gBAAgB,CAAC,EAAE;QACnC;QAGJ,OAAO;YACHE;YACA,QAAQE;QACZ;IACJ;AACJ;AAEO,MAAMC,oBAAoBC,eAAAA,oBAAgC,CAAC;IAC9D,gBAAgBd;IAChB,cAAc;QAACe;KAAe;AAClC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StorageWriter as Abstraction } from "@webiny/api-search-index-tasks/abstractions/StorageWriter.js";
|
|
2
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
3
|
+
declare class DdbStorageWriterImpl implements Abstraction.Interface {
|
|
4
|
+
private readonly table;
|
|
5
|
+
private readonly entities;
|
|
6
|
+
private buffer;
|
|
7
|
+
constructor(dynamoDBClient: DynamoDBClient.Interface);
|
|
8
|
+
put(record: Abstraction.Record): void;
|
|
9
|
+
execute(): Promise<void>;
|
|
10
|
+
private getEntity;
|
|
11
|
+
}
|
|
12
|
+
export declare const DdbStorageWriter: typeof DdbStorageWriterImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-search-index-tasks/abstractions/StorageWriter.js").IStorageWriter>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { StorageWriter } from "@webiny/api-search-index-tasks/abstractions/StorageWriter.js";
|
|
2
|
+
import { createTableWriteBatch } from "@webiny/db-dynamodb";
|
|
3
|
+
import { createOpenSearchEntity, createOpenSearchTable } from "@webiny/api-opensearch";
|
|
4
|
+
import { DynamoDBClient } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
5
|
+
class DdbStorageWriterImpl {
|
|
6
|
+
constructor(dynamoDBClient){
|
|
7
|
+
this.entities = {};
|
|
8
|
+
this.buffer = [];
|
|
9
|
+
this.table = createOpenSearchTable({
|
|
10
|
+
documentClient: dynamoDBClient.client
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
put(record) {
|
|
14
|
+
const entity = this.getEntity(record.entity);
|
|
15
|
+
this.buffer.push({
|
|
16
|
+
entity,
|
|
17
|
+
data: record.data
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async execute() {
|
|
21
|
+
if (0 === this.buffer.length) return;
|
|
22
|
+
const batch = createTableWriteBatch({
|
|
23
|
+
table: this.table.table
|
|
24
|
+
});
|
|
25
|
+
for (const { entity, data } of this.buffer)batch.put(entity.entity, data);
|
|
26
|
+
await batch.execute();
|
|
27
|
+
this.buffer = [];
|
|
28
|
+
}
|
|
29
|
+
getEntity(name) {
|
|
30
|
+
if (this.entities[name]) return this.entities[name];
|
|
31
|
+
return this.entities[name] = createOpenSearchEntity({
|
|
32
|
+
table: this.table,
|
|
33
|
+
entityName: name
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const DdbStorageWriter = StorageWriter.createImplementation({
|
|
38
|
+
implementation: DdbStorageWriterImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
DynamoDBClient
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
export { DdbStorageWriter };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=StorageWriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage/StorageWriter.js","sources":["../../src/storage/StorageWriter.ts"],"sourcesContent":["import { StorageWriter as Abstraction } from \"@webiny/api-search-index-tasks/abstractions/StorageWriter.js\";\nimport { createTableWriteBatch, type IEntity, type IPutBatchItem } from \"@webiny/db-dynamodb\";\nimport { createOpenSearchTable, createOpenSearchEntity } from \"@webiny/api-opensearch\";\nimport { DynamoDBClient } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface IBufferedRecord {\n entity: IEntity;\n data: Record<string, any>;\n}\n\nclass DdbStorageWriterImpl implements Abstraction.Interface {\n private readonly table;\n private readonly entities: Record<string, IEntity> = {};\n private buffer: IBufferedRecord[] = [];\n\n constructor(dynamoDBClient: DynamoDBClient.Interface) {\n this.table = createOpenSearchTable({\n documentClient: dynamoDBClient.client\n });\n }\n\n put(record: Abstraction.Record): void {\n const entity = this.getEntity(record.entity);\n this.buffer.push({\n entity,\n data: record.data\n });\n }\n\n async execute(): Promise<void> {\n if (this.buffer.length === 0) {\n return;\n }\n\n const batch = createTableWriteBatch({\n table: this.table.table\n });\n\n for (const { entity, data } of this.buffer) {\n batch.put(entity.entity, data as IPutBatchItem);\n }\n\n await batch.execute();\n this.buffer = [];\n }\n\n private getEntity(name: string): IEntity {\n if (this.entities[name]) {\n return this.entities[name];\n }\n\n return (this.entities[name] = createOpenSearchEntity({\n table: this.table,\n entityName: name\n }));\n }\n}\n\nexport const DdbStorageWriter = Abstraction.createImplementation({\n implementation: DdbStorageWriterImpl,\n dependencies: [DynamoDBClient]\n});\n"],"names":["DdbStorageWriterImpl","dynamoDBClient","createOpenSearchTable","record","entity","batch","createTableWriteBatch","data","name","createOpenSearchEntity","DdbStorageWriter","Abstraction","DynamoDBClient"],"mappings":";;;;AAUA,MAAMA;IAKF,YAAYC,cAAwC,CAAE;aAHrC,QAAQ,GAA4B,CAAC;aAC9C,MAAM,GAAsB,EAAE;QAGlC,IAAI,CAAC,KAAK,GAAGC,sBAAsB;YAC/B,gBAAgBD,eAAe,MAAM;QACzC;IACJ;IAEA,IAAIE,MAA0B,EAAQ;QAClC,MAAMC,SAAS,IAAI,CAAC,SAAS,CAACD,OAAO,MAAM;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACbC;YACA,MAAMD,OAAO,IAAI;QACrB;IACJ;IAEA,MAAM,UAAyB;QAC3B,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB;QAGJ,MAAME,QAAQC,sBAAsB;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QAC3B;QAEA,KAAK,MAAM,EAAEF,MAAM,EAAEG,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM,CACtCF,MAAM,GAAG,CAACD,OAAO,MAAM,EAAEG;QAG7B,MAAMF,MAAM,OAAO;QACnB,IAAI,CAAC,MAAM,GAAG,EAAE;IACpB;IAEQ,UAAUG,IAAY,EAAW;QACrC,IAAI,IAAI,CAAC,QAAQ,CAACA,KAAK,EACnB,OAAO,IAAI,CAAC,QAAQ,CAACA,KAAK;QAG9B,OAAQ,IAAI,CAAC,QAAQ,CAACA,KAAK,GAAGC,uBAAuB;YACjD,OAAO,IAAI,CAAC,KAAK;YACjB,YAAYD;QAChB;IACJ;AACJ;AAEO,MAAME,mBAAmBC,cAAAA,oBAAgC,CAAC;IAC7D,gBAAgBX;IAChB,cAAc;QAACY;KAAe;AAClC"}
|