@webiny/db-dynamodb 5.39.1 → 5.39.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -10
- package/utils/scan.d.ts +2 -1
- package/utils/scan.js +16 -2
- package/utils/scan.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "5.39.1",
|
|
3
|
+
"version": "5.39.2-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/api": "5.39.1",
|
|
14
|
-
"@webiny/aws-sdk": "5.39.1",
|
|
15
|
-
"@webiny/db": "5.39.1",
|
|
16
|
-
"@webiny/error": "5.39.1",
|
|
17
|
-
"@webiny/handler-db": "5.39.1",
|
|
18
|
-
"@webiny/plugins": "5.39.1",
|
|
13
|
+
"@webiny/api": "5.39.2-beta.1",
|
|
14
|
+
"@webiny/aws-sdk": "5.39.2-beta.1",
|
|
15
|
+
"@webiny/db": "5.39.2-beta.1",
|
|
16
|
+
"@webiny/error": "5.39.2-beta.1",
|
|
17
|
+
"@webiny/handler-db": "5.39.2-beta.1",
|
|
18
|
+
"@webiny/plugins": "5.39.2-beta.1",
|
|
19
19
|
"date-fns": "2.29.3",
|
|
20
20
|
"dot-prop": "6.0.1",
|
|
21
21
|
"dynamodb-toolbox": "0.9.2",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@babel/cli": "7.22.6",
|
|
28
28
|
"@babel/core": "7.22.8",
|
|
29
29
|
"@types/is-number": "7.0.3",
|
|
30
|
-
"@webiny/cli": "5.39.1",
|
|
31
|
-
"@webiny/project-utils": "5.39.1",
|
|
30
|
+
"@webiny/cli": "5.39.2-beta.1",
|
|
31
|
+
"@webiny/project-utils": "5.39.2-beta.1",
|
|
32
32
|
"jest": "29.5.0",
|
|
33
33
|
"jest-dynalite": "3.6.1",
|
|
34
34
|
"rimraf": "3.0.2",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"build": "yarn webiny run build",
|
|
44
44
|
"watch": "yarn webiny run watch"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "8fd4124689259202d8d9a61e8e77b5b28381e100"
|
|
47
47
|
}
|
package/utils/scan.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare type ScanDbItem<T> = T & {
|
|
|
28
28
|
SK: string;
|
|
29
29
|
GSI1_PK: string;
|
|
30
30
|
GSI1_SK: string;
|
|
31
|
+
TYPE: string;
|
|
31
32
|
};
|
|
32
33
|
export declare const scan: <T>(params: ScanParams) => Promise<ScanResponse<T>>;
|
|
33
|
-
export declare const scanWithCallback: <T>(params: ScanParams, callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void>) => Promise<void>;
|
|
34
|
+
export declare const scanWithCallback: <T>(params: ScanParams, callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>) => Promise<void>;
|
package/utils/scan.js
CHANGED
|
@@ -44,10 +44,24 @@ const scanWithCallback = async (params, callback) => {
|
|
|
44
44
|
if (!result.items?.length && !result.lastEvaluatedKey) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
// If the result of the callback was `false`, that means the
|
|
49
|
+
// user's intention was to stop further table scanning.
|
|
50
|
+
const callbackResult = await callback(result);
|
|
51
|
+
const mustBreak = callbackResult === false;
|
|
52
|
+
if (mustBreak) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
48
55
|
while (result.next) {
|
|
49
56
|
result = await result.next();
|
|
50
|
-
|
|
57
|
+
|
|
58
|
+
// If the result of the callback was `false`, that means the
|
|
59
|
+
// user's intention was to stop further table scanning.
|
|
60
|
+
const callbackResult = await callback(result);
|
|
61
|
+
const mustBreak = callbackResult === false;
|
|
62
|
+
if (mustBreak) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
51
65
|
if (!result.next) {
|
|
52
66
|
return;
|
|
53
67
|
}
|
package/utils/scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createNext","result","LastEvaluatedKey","next","undefined","response","convertResult","items","Items","count","Count","scannedCount","ScannedCount","lastEvaluatedKey","error","requestId","$response","scan","params","options","table","entity","Error","JSON","stringify","execute","exports","scanWithCallback","callback","length"],"sources":["scan.ts"],"sourcesContent":["import { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Entity, ScanOptions, Table } from \"~/toolbox\";\n\nexport type { ScanOptions };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: Table<any, any, any>;\n entity?: never;\n}\n\nexport interface ScanWithEntity extends BaseScanParams {\n entity: Entity;\n table?: never;\n}\n\nexport type ScanParams = ScanWithTable | ScanWithEntity;\n\nexport interface ScanResponse<T = any> {\n items: T[];\n count?: number;\n scannedCount?: number;\n lastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<ScanResponse<T>>;\n requestId: string;\n error: any;\n}\n\ninterface DdbScanResult<T> {\n Items?: T[];\n Count?: number;\n ScannedCount?: number;\n LastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<DdbScanResult<T>>;\n error?: any;\n $response?: {\n requestId: string;\n };\n}\n\ntype NextCb<T> = () => Promise<ScanResponse<T>>;\n\nconst createNext = <T>(result: DdbScanResult<T>): NextCb<T> | undefined => {\n if (!result?.LastEvaluatedKey || !result.next) {\n return undefined;\n }\n return async () => {\n const response = await result!.next!();\n return convertResult(response);\n };\n};\n\nconst convertResult = <T>(result: DdbScanResult<T>): ScanResponse<T> => {\n return {\n items: result.Items || [],\n count: result.Count,\n scannedCount: result.ScannedCount,\n lastEvaluatedKey: result.LastEvaluatedKey || undefined,\n next: createNext<T>(result),\n error: result.error,\n requestId: result.$response?.requestId || \"\"\n };\n};\n\nexport type ScanDbItem<T> = T & {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n};\n\nexport const scan = async <T>(params: ScanParams): Promise<ScanResponse<T>> => {\n const { options } = params;\n\n const table = params.table ? params.table : params.entity.table;\n if (!table) {\n throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);\n }\n\n const result = await table.scan(\n {\n ...options,\n execute: true\n },\n params.params\n );\n\n return convertResult(result) as ScanResponse<T>;\n};\n\nexport const scanWithCallback = async <T>(\n params: ScanParams,\n callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void>\n): Promise<void> => {\n let result = await scan<ScanDbItem<T>>(params);\n if (!result.items?.length && !result.lastEvaluatedKey) {\n return;\n }\n await callback(result);\n\n while (result.next) {\n result = await result.next();\n await callback(result);\n if (!result.next) {\n return;\n }\n }\n};\n"],"mappings":";;;;;;AA8CA,MAAMA,UAAU,GAAOC,MAAwB,IAA4B;EACvE,IAAI,CAACA,MAAM,EAAEC,gBAAgB,IAAI,CAACD,MAAM,CAACE,IAAI,EAAE;IAC3C,OAAOC,SAAS;EACpB;EACA,OAAO,YAAY;IACf,MAAMC,QAAQ,GAAG,MAAMJ,MAAM,CAAEE,IAAI,CAAE,CAAC;IACtC,OAAOG,aAAa,CAACD,QAAQ,CAAC;EAClC,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAOL,MAAwB,IAAsB;EACpE,OAAO;IACHM,KAAK,EAAEN,MAAM,CAACO,KAAK,IAAI,EAAE;IACzBC,KAAK,EAAER,MAAM,CAACS,KAAK;IACnBC,YAAY,EAAEV,MAAM,CAACW,YAAY;IACjCC,gBAAgB,EAAEZ,MAAM,CAACC,gBAAgB,IAAIE,SAAS;IACtDD,IAAI,EAAEH,UAAU,CAAIC,MAAM,CAAC;IAC3Ba,KAAK,EAAEb,MAAM,CAACa,KAAK;IACnBC,SAAS,EAAEd,MAAM,CAACe,SAAS,EAAED,SAAS,IAAI;EAC9C,CAAC;AACL,CAAC;
|
|
1
|
+
{"version":3,"names":["createNext","result","LastEvaluatedKey","next","undefined","response","convertResult","items","Items","count","Count","scannedCount","ScannedCount","lastEvaluatedKey","error","requestId","$response","scan","params","options","table","entity","Error","JSON","stringify","execute","exports","scanWithCallback","callback","length","callbackResult","mustBreak"],"sources":["scan.ts"],"sourcesContent":["import { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Entity, ScanOptions, Table } from \"~/toolbox\";\n\nexport type { ScanOptions };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: Table<any, any, any>;\n entity?: never;\n}\n\nexport interface ScanWithEntity extends BaseScanParams {\n entity: Entity;\n table?: never;\n}\n\nexport type ScanParams = ScanWithTable | ScanWithEntity;\n\nexport interface ScanResponse<T = any> {\n items: T[];\n count?: number;\n scannedCount?: number;\n lastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<ScanResponse<T>>;\n requestId: string;\n error: any;\n}\n\ninterface DdbScanResult<T> {\n Items?: T[];\n Count?: number;\n ScannedCount?: number;\n LastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<DdbScanResult<T>>;\n error?: any;\n $response?: {\n requestId: string;\n };\n}\n\ntype NextCb<T> = () => Promise<ScanResponse<T>>;\n\nconst createNext = <T>(result: DdbScanResult<T>): NextCb<T> | undefined => {\n if (!result?.LastEvaluatedKey || !result.next) {\n return undefined;\n }\n return async () => {\n const response = await result!.next!();\n return convertResult(response);\n };\n};\n\nconst convertResult = <T>(result: DdbScanResult<T>): ScanResponse<T> => {\n return {\n items: result.Items || [],\n count: result.Count,\n scannedCount: result.ScannedCount,\n lastEvaluatedKey: result.LastEvaluatedKey || undefined,\n next: createNext<T>(result),\n error: result.error,\n requestId: result.$response?.requestId || \"\"\n };\n};\n\nexport type ScanDbItem<T> = T & {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n};\n\nexport const scan = async <T>(params: ScanParams): Promise<ScanResponse<T>> => {\n const { options } = params;\n\n const table = params.table ? params.table : params.entity.table;\n if (!table) {\n throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);\n }\n\n const result = await table.scan(\n {\n ...options,\n execute: true\n },\n params.params\n );\n\n return convertResult(result) as ScanResponse<T>;\n};\n\nexport const scanWithCallback = async <T>(\n params: ScanParams,\n callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>\n): Promise<void> => {\n let result = await scan<ScanDbItem<T>>(params);\n if (!result.items?.length && !result.lastEvaluatedKey) {\n return;\n }\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n return;\n }\n\n while (result.next) {\n result = await result.next();\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n break;\n }\n\n if (!result.next) {\n return;\n }\n }\n};\n"],"mappings":";;;;;;AA8CA,MAAMA,UAAU,GAAOC,MAAwB,IAA4B;EACvE,IAAI,CAACA,MAAM,EAAEC,gBAAgB,IAAI,CAACD,MAAM,CAACE,IAAI,EAAE;IAC3C,OAAOC,SAAS;EACpB;EACA,OAAO,YAAY;IACf,MAAMC,QAAQ,GAAG,MAAMJ,MAAM,CAAEE,IAAI,CAAE,CAAC;IACtC,OAAOG,aAAa,CAACD,QAAQ,CAAC;EAClC,CAAC;AACL,CAAC;AAED,MAAMC,aAAa,GAAOL,MAAwB,IAAsB;EACpE,OAAO;IACHM,KAAK,EAAEN,MAAM,CAACO,KAAK,IAAI,EAAE;IACzBC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