@webiny/db-dynamodb 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9
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/DynamoDbDriver.js +204 -209
- package/DynamoDbDriver.js.map +1 -1
- package/exports/api/db.d.ts +2 -0
- package/exports/api/db.js +2 -0
- package/feature/FilterUtil/FilterUtil.d.ts +11 -0
- package/feature/FilterUtil/FilterUtil.js +26 -0
- package/feature/FilterUtil/FilterUtil.js.map +1 -0
- package/feature/FilterUtil/abstractions/FilterUtil.d.ts +17 -0
- package/feature/FilterUtil/abstractions/FilterUtil.js +5 -0
- package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -0
- package/feature/FilterUtil/createFilters.d.ts +22 -0
- package/feature/FilterUtil/createFilters.js +92 -0
- package/feature/FilterUtil/createFilters.js.map +1 -0
- package/feature/FilterUtil/extractWhereArgs.d.ts +7 -0
- package/feature/FilterUtil/extractWhereArgs.js +20 -0
- package/feature/FilterUtil/extractWhereArgs.js.map +1 -0
- package/feature/FilterUtil/feature.d.ts +4 -0
- package/feature/FilterUtil/feature.js +11 -0
- package/feature/FilterUtil/feature.js.map +1 -0
- package/feature/FilterUtil/index.d.ts +2 -0
- package/feature/FilterUtil/index.js +2 -0
- package/feature/ValueFilter/ValueFilterRegistry.d.ts +12 -0
- package/feature/ValueFilter/ValueFilterRegistry.js +27 -0
- package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -0
- package/feature/ValueFilter/abstractions/ValueFilter.d.ts +22 -0
- package/feature/ValueFilter/abstractions/ValueFilter.js +5 -0
- package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.d.ts +10 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +5 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -0
- package/feature/ValueFilter/feature.d.ts +4 -0
- package/feature/ValueFilter/feature.js +33 -0
- package/feature/ValueFilter/feature.js.map +1 -0
- package/feature/ValueFilter/filters/AndInFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/AndInFilter.js +28 -0
- package/feature/ValueFilter/filters/AndInFilter.js.map +1 -0
- package/feature/ValueFilter/filters/BetweenFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/BetweenFilter.js +31 -0
- package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -0
- package/feature/ValueFilter/filters/ContainsFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/ContainsFilter.js +42 -0
- package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -0
- package/feature/ValueFilter/filters/EqFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/EqFilter.js +24 -0
- package/feature/ValueFilter/filters/EqFilter.js.map +1 -0
- package/feature/ValueFilter/filters/FuzzyFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/FuzzyFilter.js +37 -0
- package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -0
- package/feature/ValueFilter/filters/GtFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/GtFilter.js +22 -0
- package/feature/ValueFilter/filters/GtFilter.js.map +1 -0
- package/feature/ValueFilter/filters/GteFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/GteFilter.js +22 -0
- package/feature/ValueFilter/filters/GteFilter.js.map +1 -0
- package/feature/ValueFilter/filters/InFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/InFilter.js +28 -0
- package/feature/ValueFilter/filters/InFilter.js.map +1 -0
- package/feature/ValueFilter/filters/LtFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/LtFilter.js +22 -0
- package/feature/ValueFilter/filters/LtFilter.js.map +1 -0
- package/feature/ValueFilter/filters/LteFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/LteFilter.js +22 -0
- package/feature/ValueFilter/filters/LteFilter.js.map +1 -0
- package/feature/ValueFilter/filters/StartsWithFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/StartsWithFilter.js +29 -0
- package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -0
- package/feature/ValueFilter/index.d.ts +3 -0
- package/feature/ValueFilter/index.js +3 -0
- package/index.d.ts +1 -0
- package/index.js +9 -2
- package/index.js.map +1 -1
- package/package.json +28 -20
- package/plugins/definitions/DateTimeTransformPlugin.js +18 -27
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.js +34 -37
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.js +25 -37
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.d.ts +1 -6
- package/plugins/definitions/ValueTransformPlugin.js +17 -22
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +14 -18
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.d.ts +0 -5
- package/plugins/index.js +0 -12
- package/store/entity.js +6 -9
- package/store/entity.js.map +1 -1
- package/store/keys.js +6 -13
- package/store/keys.js.map +1 -1
- package/store/types.js +0 -3
- package/toolbox.d.ts +53 -1
- package/toolbox.js +0 -4
- package/types.js +0 -3
- package/utils/batch/batchRead.js +37 -56
- package/utils/batch/batchRead.js.map +1 -1
- package/utils/batch/batchWrite.js +33 -51
- package/utils/batch/batchWrite.js.map +1 -1
- package/utils/batch/index.js +0 -2
- package/utils/batch/types.js +0 -3
- package/utils/cleanup.js +35 -25
- package/utils/cleanup.js.map +1 -1
- package/utils/count.js +8 -13
- package/utils/count.js.map +1 -1
- package/utils/createEntity.d.ts +1 -1
- package/utils/createEntity.js +75 -78
- package/utils/createEntity.js.map +1 -1
- package/utils/createTable.js +25 -35
- package/utils/createTable.js.map +1 -1
- package/utils/cursor.js +7 -10
- package/utils/cursor.js.map +1 -1
- package/utils/delete.js +6 -8
- package/utils/delete.js.map +1 -1
- package/utils/entity/Entity.d.ts +1 -1
- package/utils/entity/Entity.js +85 -89
- package/utils/entity/Entity.js.map +1 -1
- package/utils/entity/EntityReadBatch.js +23 -31
- package/utils/entity/EntityReadBatch.js.map +1 -1
- package/utils/entity/EntityReadBatchBuilder.js +12 -15
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
- package/utils/entity/EntityWriteBatch.js +34 -41
- package/utils/entity/EntityWriteBatch.js.map +1 -1
- package/utils/entity/EntityWriteBatchBuilder.js +15 -16
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
- package/utils/entity/getEntity.js +8 -9
- package/utils/entity/getEntity.js.map +1 -1
- package/utils/entity/index.js +0 -2
- package/utils/entity/types.js +0 -4
- package/utils/get.js +12 -26
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +1 -5
- package/utils/index.js +1 -7
- package/utils/put.js +7 -9
- package/utils/put.js.map +1 -1
- package/utils/query.js +77 -128
- package/utils/query.js.map +1 -1
- package/utils/scan.js +47 -73
- package/utils/scan.js.map +1 -1
- package/utils/sort.js +37 -61
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.js +22 -21
- package/utils/table/Table.js.map +1 -1
- package/utils/table/TableReadBatch.js +37 -45
- package/utils/table/TableReadBatch.js.map +1 -1
- package/utils/table/TableWriteBatch.js +47 -56
- package/utils/table/TableWriteBatch.js.map +1 -1
- package/utils/table/index.js +0 -2
- package/utils/table/types.js +0 -3
- package/plugins/definitions/AttributePlugin.d.ts +0 -18
- package/plugins/definitions/AttributePlugin.js +0 -38
- package/plugins/definitions/AttributePlugin.js.map +0 -1
- package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
- package/plugins/definitions/FieldPathPlugin.js +0 -26
- package/plugins/definitions/FieldPathPlugin.js.map +0 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +0 -22
- package/plugins/definitions/ValueFilterPlugin.js +0 -35
- package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
- package/plugins/filters/andIn.d.ts +0 -3
- package/plugins/filters/andIn.js +0 -24
- package/plugins/filters/andIn.js.map +0 -1
- package/plugins/filters/between.d.ts +0 -3
- package/plugins/filters/between.js +0 -25
- package/plugins/filters/between.js.map +0 -1
- package/plugins/filters/contains.d.ts +0 -3
- package/plugins/filters/contains.js +0 -53
- package/plugins/filters/contains.js.map +0 -1
- package/plugins/filters/eq.d.ts +0 -3
- package/plugins/filters/eq.js +0 -26
- package/plugins/filters/eq.js.map +0 -1
- package/plugins/filters/fuzzy.d.ts +0 -3
- package/plugins/filters/fuzzy.js +0 -29
- package/plugins/filters/fuzzy.js.map +0 -1
- package/plugins/filters/gt.d.ts +0 -3
- package/plugins/filters/gt.js +0 -14
- package/plugins/filters/gt.js.map +0 -1
- package/plugins/filters/gte.d.ts +0 -3
- package/plugins/filters/gte.js +0 -14
- package/plugins/filters/gte.js.map +0 -1
- package/plugins/filters/in.d.ts +0 -3
- package/plugins/filters/in.js +0 -24
- package/plugins/filters/in.js.map +0 -1
- package/plugins/filters/index.d.ts +0 -2
- package/plugins/filters/index.js +0 -14
- package/plugins/filters/index.js.map +0 -1
- package/plugins/filters/lt.d.ts +0 -3
- package/plugins/filters/lt.js +0 -14
- package/plugins/filters/lt.js.map +0 -1
- package/plugins/filters/lte.d.ts +0 -3
- package/plugins/filters/lte.js +0 -14
- package/plugins/filters/lte.js.map +0 -1
- package/plugins/filters/startsWith.d.ts +0 -3
- package/plugins/filters/startsWith.js +0 -34
- package/plugins/filters/startsWith.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/store/types.js.map +0 -1
- package/toolbox.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/attributes.d.ts +0 -10
- package/utils/attributes.js +0 -19
- package/utils/attributes.js.map +0 -1
- package/utils/batch/index.js.map +0 -1
- package/utils/batch/types.js.map +0 -1
- package/utils/entity/index.js.map +0 -1
- package/utils/entity/types.js.map +0 -1
- package/utils/filter.d.ts +0 -12
- package/utils/filter.js +0 -174
- package/utils/filter.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/listResponse.d.ts +0 -13
- package/utils/listResponse.js +0 -25
- package/utils/listResponse.js.map +0 -1
- package/utils/table/index.js.map +0 -1
- package/utils/table/types.js.map +0 -1
- package/utils/update.d.ts +0 -12
- package/utils/update.js +0 -12
- package/utils/update.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/definitions/TimeTransformPlugin.js","sources":["../../../src/plugins/definitions/TimeTransformPlugin.ts"],"sourcesContent":["import type {\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin.js\";\nimport { ValueTransformPlugin } from \"./ValueTransformPlugin.js\";\nimport WebinyError from \"@webiny/error\";\n\nconst transformTime = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n if (value === undefined || value === null) {\n throw new WebinyError(`Time value is null or undefined.`, \"TIME_PARSE_ERROR\", {\n value\n });\n } else if (typeof value === \"boolean\" || value === \"\" || Array.isArray(value)) {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n const converted = Number(`${value}`);\n if (typeof value === \"number\" || isNaN(converted) === false) {\n return Number(value);\n } else if (typeof value !== \"string\") {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n /**\n * This is for the time format, eg. 12:36:25 or 12:36:25.881\n */\n const [time, milliseconds = 0] = value.split(\".\");\n const values = time.split(\":\").map(Number);\n if (values.length < 2) {\n throw new WebinyError(\"Time must contain at least hours and minutes.\", \"TIME_PARSE_ERROR\", {\n value\n });\n }\n const [hours, minutes, seconds = 0] = values;\n return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);\n};\n\nexport class TimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformTime,\n ...params\n });\n }\n}\n"],"names":["transformTime","params","value","WebinyError","Array","converted","Number","isNaN","time","milliseconds","values","hours","minutes","seconds","TimeTransformPlugin","ValueTransformPlugin"],"mappings":";;AAOA,MAAMA,gBAAgB,CAACC;IACnB,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIC,QAAAA,OACA,MAAM,IAAIC,MAAY,oCAAoC,oBAAoB;QAC1ED;IACJ;IACG,IAAI,AAAiB,aAAjB,OAAOA,SAAuBA,AAAU,OAAVA,SAAgBE,MAAM,OAAO,CAACF,QACnE,MAAM,IAAIC,MACN,kEACA,oBACA;QACID;IACJ;IAGR,MAAMG,YAAYC,OAAO,GAAGJ,OAAO;IACnC,IAAI,AAAiB,YAAjB,OAAOA,SAAsBK,AAAqB,UAArBA,MAAMF,YACnC,OAAOC,OAAOJ;IACX,IAAI,AAAiB,YAAjB,OAAOA,OACd,MAAM,IAAIC,MACN,kEACA,oBACA;QACID;IACJ;IAMR,MAAM,CAACM,MAAMC,eAAe,CAAC,CAAC,GAAGP,MAAM,KAAK,CAAC;IAC7C,MAAMQ,SAASF,KAAK,KAAK,CAAC,KAAK,GAAG,CAACF;IACnC,IAAII,OAAO,MAAM,GAAG,GAChB,MAAM,IAAIP,MAAY,iDAAiD,oBAAoB;QACvFD;IACJ;IAEJ,MAAM,CAACS,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGH;IACtC,OAAQC,AAAAA,CAAAA,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA,UAAeC,OAAM,IAAK,OAAOP,OAAOG;AACtE;AAEO,MAAMK,4BAA4BC;IACrC,YAAmBd,MAAqD,CAAE;QACtE,KAAK,CAAC;YACF,WAAWD;YACX,GAAGC,MAAM;QACb;IACJ;AACJ"}
|
|
@@ -5,18 +5,13 @@ export interface ValueTransformPluginParamsTransformParams {
|
|
|
5
5
|
export interface ValueTransformPluginParamsTransform {
|
|
6
6
|
(params: ValueTransformPluginParamsTransformParams): any;
|
|
7
7
|
}
|
|
8
|
-
export interface CanTransform {
|
|
9
|
-
(field: string): boolean;
|
|
10
|
-
}
|
|
11
8
|
export interface ValueTransformPluginParams {
|
|
12
9
|
fields: string[];
|
|
13
10
|
transform: ValueTransformPluginParamsTransform;
|
|
14
|
-
canTransform?: CanTransform;
|
|
15
11
|
}
|
|
16
|
-
export declare class ValueTransformPlugin extends Plugin {
|
|
12
|
+
export declare abstract class ValueTransformPlugin extends Plugin {
|
|
17
13
|
static readonly type: string;
|
|
18
14
|
private readonly _params;
|
|
19
15
|
constructor(params: ValueTransformPluginParams);
|
|
20
|
-
canTransform(field: string): boolean;
|
|
21
16
|
transform(params: ValueTransformPluginParamsTransformParams): any;
|
|
22
17
|
}
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import
|
|
2
|
+
import error from "@webiny/error";
|
|
3
3
|
import { assignFields } from "./assignFields.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
super();
|
|
8
|
-
this._params = {
|
|
9
|
-
...params,
|
|
10
|
-
fields: assignFields(params.fields)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
canTransform(field) {
|
|
14
|
-
if (!this._params.canTransform) {
|
|
15
|
-
return this._params.fields.includes(field);
|
|
4
|
+
class ValueTransformPlugin extends Plugin {
|
|
5
|
+
static{
|
|
6
|
+
this.type = "dynamodb.value.transform";
|
|
16
7
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
constructor(params){
|
|
9
|
+
super();
|
|
10
|
+
this._params = {
|
|
11
|
+
...params,
|
|
12
|
+
fields: assignFields(params.fields)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
transform(params) {
|
|
16
|
+
if (!this._params.transform) throw new error('Missing "transform" in the plugin.', "TRANSFORM_ERROR", {
|
|
17
|
+
fields: this._params.fields
|
|
18
|
+
});
|
|
19
|
+
return this._params.transform(params);
|
|
24
20
|
}
|
|
25
|
-
return this._params.transform(params);
|
|
26
|
-
}
|
|
27
21
|
}
|
|
22
|
+
export { ValueTransformPlugin };
|
|
28
23
|
|
|
29
24
|
//# sourceMappingURL=ValueTransformPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/definitions/ValueTransformPlugin.js","sources":["../../../src/plugins/definitions/ValueTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { assignFields } from \"./assignFields.js\";\n\nexport interface ValueTransformPluginParamsTransformParams {\n value: Date | string | null | undefined;\n}\nexport interface ValueTransformPluginParamsTransform {\n (params: ValueTransformPluginParamsTransformParams): any;\n}\nexport interface ValueTransformPluginParams {\n fields: string[];\n transform: ValueTransformPluginParamsTransform;\n}\n\nexport abstract class ValueTransformPlugin extends Plugin {\n public static override readonly type: string = \"dynamodb.value.transform\";\n\n private readonly _params: ValueTransformPluginParams;\n\n public constructor(params: ValueTransformPluginParams) {\n super();\n this._params = {\n ...params,\n fields: assignFields(params.fields)\n };\n }\n\n public transform(params: ValueTransformPluginParamsTransformParams): any {\n if (!this._params.transform) {\n throw new WebinyError(`Missing \"transform\" in the plugin.`, \"TRANSFORM_ERROR\", {\n fields: this._params.fields\n });\n }\n return this._params.transform(params);\n }\n}\n"],"names":["ValueTransformPlugin","Plugin","params","assignFields","WebinyError"],"mappings":";;;AAeO,MAAeA,6BAA6BC;;aACf,IAAI,GAAW;;IAI/C,YAAmBC,MAAkC,CAAE;QACnD,KAAK;QACL,IAAI,CAAC,OAAO,GAAG;YACX,GAAGA,MAAM;YACT,QAAQC,aAAaD,OAAO,MAAM;QACtC;IACJ;IAEO,UAAUA,MAAiD,EAAO;QACrE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EACvB,MAAM,IAAIE,MAAY,sCAAsC,mBAAmB;YAC3E,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM;QAC/B;QAEJ,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAACF;IAClC;AACJ"}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new WebinyError("Passed empty field value into the plugin.", "EMPTY_FIELD_VALUE", {
|
|
14
|
-
fields: input
|
|
15
|
-
});
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
const assignFields = (rawInput)=>{
|
|
3
|
+
const input = Array.isArray(rawInput) ? rawInput : [
|
|
4
|
+
rawInput
|
|
5
|
+
];
|
|
6
|
+
if (0 === input.length) throw new error("Could not assign fields because there are none.", "ASSIGN_FIELDS_ERROR");
|
|
7
|
+
const fields = [];
|
|
8
|
+
for (const field of input){
|
|
9
|
+
if (!field) throw new error("Passed empty field value into the plugin.", "EMPTY_FIELD_VALUE", {
|
|
10
|
+
fields: input
|
|
11
|
+
});
|
|
12
|
+
fields.push(field);
|
|
16
13
|
}
|
|
17
|
-
fields
|
|
18
|
-
}
|
|
19
|
-
return fields;
|
|
14
|
+
return fields;
|
|
20
15
|
};
|
|
16
|
+
export { assignFields };
|
|
21
17
|
|
|
22
18
|
//# sourceMappingURL=assignFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/definitions/assignFields.js","sources":["../../../src/plugins/definitions/assignFields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport const assignFields = (rawInput: string | string[]): string[] => {\n const input = Array.isArray(rawInput) ? rawInput : [rawInput];\n if (input.length === 0) {\n throw new WebinyError(\n \"Could not assign fields because there are none.\",\n \"ASSIGN_FIELDS_ERROR\"\n );\n }\n const fields: string[] = [];\n for (const field of input) {\n /**\n * Need to make sure that no field is empty.\n */\n if (!field) {\n throw new WebinyError(\n \"Passed empty field value into the plugin.\",\n \"EMPTY_FIELD_VALUE\",\n {\n fields: input\n }\n );\n }\n fields.push(field);\n }\n return fields;\n};\n"],"names":["assignFields","rawInput","input","Array","WebinyError","fields","field"],"mappings":";AAEO,MAAMA,eAAe,CAACC;IACzB,MAAMC,QAAQC,MAAM,OAAO,CAACF,YAAYA,WAAW;QAACA;KAAS;IAC7D,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,MAAM,IAAIE,MACN,mDACA;IAGR,MAAMC,SAAmB,EAAE;IAC3B,KAAK,MAAMC,SAASJ,MAAO;QAIvB,IAAI,CAACI,OACD,MAAM,IAAIF,MACN,6CACA,qBACA;YACI,QAAQF;QACZ;QAGRG,OAAO,IAAI,CAACC;IAChB;IACA,OAAOD;AACX"}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
export * from "./definitions/assignFields.js";
|
|
2
|
-
export * from "./definitions/AttributePlugin.js";
|
|
3
2
|
export * from "./definitions/DateTimeTransformPlugin.js";
|
|
4
|
-
export * from "./definitions/FieldPathPlugin.js";
|
|
5
3
|
export * from "./definitions/FieldPlugin.js";
|
|
6
4
|
export * from "./definitions/TimeTransformPlugin.js";
|
|
7
|
-
export * from "./definitions/ValueFilterPlugin.js";
|
|
8
5
|
export * from "./definitions/ValueTransformPlugin.js";
|
|
9
|
-
declare const _default: () => import("./definitions/ValueFilterPlugin.js").ValueFilterPlugin<any, any>[][];
|
|
10
|
-
export default _default;
|
package/plugins/index.js
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
export * from "./definitions/assignFields.js";
|
|
2
|
-
export * from "./definitions/AttributePlugin.js";
|
|
3
2
|
export * from "./definitions/DateTimeTransformPlugin.js";
|
|
4
|
-
export * from "./definitions/FieldPathPlugin.js";
|
|
5
3
|
export * from "./definitions/FieldPlugin.js";
|
|
6
4
|
export * from "./definitions/TimeTransformPlugin.js";
|
|
7
|
-
export * from "./definitions/ValueFilterPlugin.js";
|
|
8
5
|
export * from "./definitions/ValueTransformPlugin.js";
|
|
9
|
-
/**
|
|
10
|
-
* List everything that needs to be loaded by default.
|
|
11
|
-
*/
|
|
12
|
-
import filterPlugins from "./filters/index.js";
|
|
13
|
-
export default () => {
|
|
14
|
-
return [filterPlugins()];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
package/store/entity.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { createGlobalEntity
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
name: "WebinyKeyValue"
|
|
8
|
-
});
|
|
9
|
-
};
|
|
1
|
+
import { createGlobalEntity } from "../utils/index.js";
|
|
2
|
+
const createEntity = ({ table })=>createGlobalEntity({
|
|
3
|
+
table: table.table,
|
|
4
|
+
name: "WebinyKeyValue"
|
|
5
|
+
});
|
|
6
|
+
export { createEntity };
|
|
10
7
|
|
|
11
8
|
//# sourceMappingURL=entity.js.map
|
package/store/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"store/entity.js","sources":["../../src/store/entity.ts"],"sourcesContent":["import type { ITable } from \"~/utils/index.js\";\nimport { createGlobalEntity as baseCreateGlobalEntity } from \"~/utils/index.js\";\nimport type { IStoreEntity, IStoreEntityValue } from \"~/store/types.js\";\n\nexport interface ICreateEntityParams {\n table: ITable;\n}\n\nexport const createEntity = ({ table }: ICreateEntityParams): IStoreEntity => {\n return baseCreateGlobalEntity<IStoreEntityValue>({\n table: table.table,\n name: \"WebinyKeyValue\"\n });\n};\n"],"names":["createEntity","table","baseCreateGlobalEntity"],"mappings":";AAQO,MAAMA,eAAe,CAAC,EAAEC,KAAK,EAAuB,GAChDC,mBAA0C;QAC7C,OAAOD,MAAM,KAAK;QAClB,MAAM;IACV"}
|
package/store/keys.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
key
|
|
6
|
-
}) => {
|
|
7
|
-
if (typeof key === "symbol") {
|
|
8
|
-
return key.toString();
|
|
9
|
-
}
|
|
10
|
-
return String(key);
|
|
11
|
-
};
|
|
12
|
-
export const createType = () => {
|
|
13
|
-
return "internal";
|
|
1
|
+
const createPartitionKey = ()=>"W#internal";
|
|
2
|
+
const createSortKey = ({ key })=>{
|
|
3
|
+
if ("symbol" == typeof key) return key.toString();
|
|
4
|
+
return String(key);
|
|
14
5
|
};
|
|
6
|
+
const createType = ()=>"internal";
|
|
7
|
+
export { createPartitionKey, createSortKey, createType };
|
|
15
8
|
|
|
16
9
|
//# sourceMappingURL=keys.js.map
|
package/store/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"store/keys.js","sources":["../../src/store/keys.ts"],"sourcesContent":["export interface IParams {\n key: string | number | symbol;\n}\n\nexport const createPartitionKey = () => {\n return `W#internal`;\n};\n\nexport const createSortKey = ({ key }: IParams) => {\n if (typeof key === \"symbol\") {\n return key.toString();\n }\n return String(key);\n};\n\nexport const createType = () => {\n return \"internal\";\n};\n"],"names":["createPartitionKey","createSortKey","key","String","createType"],"mappings":"AAIO,MAAMA,qBAAqB,IACvB;AAGJ,MAAMC,gBAAgB,CAAC,EAAEC,GAAG,EAAW;IAC1C,IAAI,AAAe,YAAf,OAAOA,KACP,OAAOA,IAAI,QAAQ;IAEvB,OAAOC,OAAOD;AAClB;AAEO,MAAME,aAAa,IACf"}
|
package/store/types.js
CHANGED
package/toolbox.d.ts
CHANGED
|
@@ -5,4 +5,56 @@ export type DynamoDBTypes = "string" | "boolean" | "number" | "bigint" | "list"
|
|
|
5
5
|
type Key = string | number | symbol;
|
|
6
6
|
export type TableDef = Table<string, Key, Key | null>;
|
|
7
7
|
export type TableConstructor<A extends string, B extends Key, C extends Key> = ConstructorParameters<typeof Table<A, B, C>>[0];
|
|
8
|
-
export type
|
|
8
|
+
export type Readonly<T> = T extends ((...args: any[]) => any) | undefined ? T : T extends object ? {
|
|
9
|
+
readonly [P in keyof T]: Readonly<T[P]>;
|
|
10
|
+
} : T;
|
|
11
|
+
export type AttributeDefinition = DynamoDBTypes | Partial<{
|
|
12
|
+
type: DynamoDBTypes;
|
|
13
|
+
coerce: boolean;
|
|
14
|
+
default: unknown;
|
|
15
|
+
dependsOn: string | string[];
|
|
16
|
+
required: boolean | "always";
|
|
17
|
+
hidden: boolean;
|
|
18
|
+
prefix: string;
|
|
19
|
+
suffix: string;
|
|
20
|
+
delimiter: string;
|
|
21
|
+
map: string;
|
|
22
|
+
alias: string;
|
|
23
|
+
onlyMap: boolean;
|
|
24
|
+
partitionKey: boolean;
|
|
25
|
+
sortKey: boolean;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}> | [string, number] | [string, number, string] | [string, number, Record<string, unknown>];
|
|
28
|
+
export type AttributeDefinitions = Record<PropertyKey, AttributeDefinition>;
|
|
29
|
+
export interface EntityConstructor<T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>> {
|
|
30
|
+
name: string;
|
|
31
|
+
attributes: T;
|
|
32
|
+
table?: TableDef;
|
|
33
|
+
timestamps?: boolean;
|
|
34
|
+
createdAlias?: string;
|
|
35
|
+
modifiedAlias?: string;
|
|
36
|
+
typeAlias?: string;
|
|
37
|
+
typeHidden?: boolean;
|
|
38
|
+
autoExecute?: boolean;
|
|
39
|
+
autoParse?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface EntityQueryOptions {
|
|
42
|
+
index?: string;
|
|
43
|
+
limit?: number;
|
|
44
|
+
reverse?: boolean;
|
|
45
|
+
consistent?: boolean;
|
|
46
|
+
capacity?: "indexes" | "total" | "none";
|
|
47
|
+
select?: "all_attributes" | "all_projected_attributes" | "count" | "specific_attributes";
|
|
48
|
+
eq?: string | number;
|
|
49
|
+
lt?: string | number;
|
|
50
|
+
lte?: string | number;
|
|
51
|
+
gt?: string | number;
|
|
52
|
+
gte?: string | number;
|
|
53
|
+
between?: [string, string] | [number, number] | [bigint, bigint];
|
|
54
|
+
beginsWith?: string;
|
|
55
|
+
startKey?: Record<string, unknown>;
|
|
56
|
+
filters?: Record<string, unknown>;
|
|
57
|
+
attributes?: string[];
|
|
58
|
+
execute?: boolean;
|
|
59
|
+
parse?: boolean;
|
|
60
|
+
}
|
package/toolbox.js
CHANGED
package/types.js
CHANGED
package/utils/batch/batchRead.js
CHANGED
|
@@ -1,64 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import chunk from "lodash/chunk.js";
|
|
2
|
+
import error from "@webiny/error";
|
|
3
3
|
const MAX_BATCH_ITEMS = 100;
|
|
4
|
-
const flatten = responses
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
entries
|
|
9
|
-
}
|
|
10
|
-
return entries;
|
|
4
|
+
const flatten = (responses)=>{
|
|
5
|
+
const entries = [];
|
|
6
|
+
const values = Object.values(responses);
|
|
7
|
+
for (const items of values)entries.push(...items);
|
|
8
|
+
return entries;
|
|
11
9
|
};
|
|
12
|
-
const batchReadAllChunk = async params
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return records;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!result.next || typeof result.next !== "function") {
|
|
27
|
-
return records;
|
|
28
|
-
}
|
|
29
|
-
let previous = result;
|
|
30
|
-
while (typeof previous.next === "function") {
|
|
31
|
-
const nextResult = await previous.next();
|
|
32
|
-
if (!nextResult) {
|
|
33
|
-
return records;
|
|
10
|
+
const batchReadAllChunk = async (params)=>{
|
|
11
|
+
const { table, items } = params;
|
|
12
|
+
const records = [];
|
|
13
|
+
if (!table) return records;
|
|
14
|
+
const result = await table.batchGet(items);
|
|
15
|
+
if (!result || !result.Responses) return records;
|
|
16
|
+
records.push(...flatten(result.Responses));
|
|
17
|
+
if (!result.next || "function" != typeof result.next) return records;
|
|
18
|
+
let previous = result;
|
|
19
|
+
while("function" == typeof previous.next){
|
|
20
|
+
const nextResult = await previous.next();
|
|
21
|
+
if (!nextResult) break;
|
|
22
|
+
records.push(...flatten(nextResult.Responses));
|
|
23
|
+
previous = nextResult;
|
|
34
24
|
}
|
|
35
|
-
records
|
|
36
|
-
previous = nextResult;
|
|
37
|
-
}
|
|
38
|
-
return records;
|
|
25
|
+
return records;
|
|
39
26
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
45
|
-
if (params.items.length === 0) {
|
|
46
|
-
return [];
|
|
47
|
-
} else if (maxChunk > MAX_BATCH_ITEMS) {
|
|
48
|
-
throw new WebinyError(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
|
|
49
|
-
maxChunk
|
|
27
|
+
const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS)=>{
|
|
28
|
+
if (0 === params.items.length) return [];
|
|
29
|
+
if (maxChunk > MAX_BATCH_ITEMS) throw new error(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
|
|
30
|
+
maxChunk
|
|
50
31
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return records;
|
|
32
|
+
const records = [];
|
|
33
|
+
const chunkItemsList = chunk(params.items, maxChunk);
|
|
34
|
+
for (const chunkItems of chunkItemsList){
|
|
35
|
+
const results = await batchReadAllChunk({
|
|
36
|
+
table: params.table,
|
|
37
|
+
items: chunkItems
|
|
38
|
+
});
|
|
39
|
+
records.push(...results);
|
|
40
|
+
}
|
|
41
|
+
return records;
|
|
62
42
|
};
|
|
43
|
+
export { batchReadAll };
|
|
63
44
|
|
|
64
45
|
//# sourceMappingURL=batchRead.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/batch/batchRead.js","sources":["../../../src/utils/batch/batchRead.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchReadItem {\n Table?: TableDef;\n Key: any;\n}\nexport interface BatchReadParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n if (!table) {\n return records;\n }\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = GenericRecord>(\n params: BatchReadParams,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"names":["MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","batchReadAllChunk","params","table","records","result","previous","nextResult","batchReadAll","maxChunk","WebinyError","chunkItemsList","lodashChunk","chunkItems","results"],"mappings":";;AAcA,MAAMA,kBAAkB;AAExB,MAAMC,UAAU,CAACC;IACb,MAAMC,UAAU,EAAE;IAClB,MAAMC,SAASC,OAAO,MAAM,CAACH;IAC7B,KAAK,MAAMI,SAASF,OAChBD,QAAQ,IAAI,IAAIG;IAEpB,OAAOH;AACX;AAMA,MAAMI,oBAAoB,OAAgBC;IACtC,MAAM,EAAEC,KAAK,EAAEH,KAAK,EAAE,GAAGE;IACzB,MAAME,UAAe,EAAE;IAEvB,IAAI,CAACD,OACD,OAAOC;IAGX,MAAMC,SAAS,MAAMF,MAAM,QAAQ,CAACH;IACpC,IAAI,CAACK,UAAU,CAACA,OAAO,SAAS,EAC5B,OAAOD;IAEXA,QAAQ,IAAI,IAAIT,QAAQU,OAAO,SAAS;IACxC,IAAI,CAACA,OAAO,IAAI,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClC,OAAOD;IAEX,IAAIE,WAAWD;IACf,MAAO,AAAyB,cAAzB,OAAOC,SAAS,IAAI,CAAiB;QACxC,MAAMC,aAAa,MAAMD,SAAS,IAAI;QACtC,IAAI,CAACC,YACD;QAEJH,QAAQ,IAAI,IAAIT,QAAQY,WAAW,SAAS;QAC5CD,WAAWC;IACf;IACA,OAAOH;AACX;AAKO,MAAMI,eAAe,OACxBN,QACAO,WAAWf,eAAe;IAE1B,IAAIQ,AAAwB,MAAxBA,OAAO,KAAK,CAAC,MAAM,EACnB,OAAO,EAAE;IACN,IAAIO,WAAWf,iBAClB,MAAM,IAAIgB,MACN,CAAC,6BAA6B,EAAEhB,gBAAgB,iCAAiC,CAAC,EAClF,sCACA;QACIe;IACJ;IAIR,MAAML,UAAe,EAAE;IAEvB,MAAMO,iBAAiBC,MAAYV,OAAO,KAAK,EAAEO;IAEjD,KAAK,MAAMI,cAAcF,eAAgB;QACrC,MAAMG,UAAU,MAAMb,kBAAqB;YACvC,OAAOC,OAAO,KAAK;YACnB,OAAOW;QACX;QAEAT,QAAQ,IAAI,IAAIU;IACpB;IAEA,OAAOV;AACX"}
|
|
@@ -1,57 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
const hasUnprocessedItems = result
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return keys.some(key => {
|
|
12
|
-
const value = items[key];
|
|
13
|
-
if (!Array.isArray(value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return value.some(val => {
|
|
17
|
-
return val.PutRequest || val.DeleteRequest;
|
|
1
|
+
import chunk from "lodash/chunk.js";
|
|
2
|
+
const hasUnprocessedItems = (result)=>{
|
|
3
|
+
if ("function" != typeof result.next) return false;
|
|
4
|
+
const items = result.UnprocessedItems;
|
|
5
|
+
if (!items || "object" != typeof items) return false;
|
|
6
|
+
const keys = Object.keys(items);
|
|
7
|
+
return keys.some((key)=>{
|
|
8
|
+
const value = items[key];
|
|
9
|
+
if (!Array.isArray(value)) return false;
|
|
10
|
+
return value.some((val)=>val.PutRequest || val.DeleteRequest);
|
|
18
11
|
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const retry = async (input, results) => {
|
|
22
|
-
if (!hasUnprocessedItems(input)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const result = await input.next();
|
|
26
|
-
await retry(result, results);
|
|
27
12
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* It can either delete or put items
|
|
32
|
-
* The method does not check items before actually sending them into the underlying library.
|
|
33
|
-
*/
|
|
34
|
-
export const batchWriteAll = async (params, maxChunk = 25) => {
|
|
35
|
-
const {
|
|
36
|
-
items: collection,
|
|
37
|
-
table
|
|
38
|
-
} = params;
|
|
39
|
-
if (!table) {
|
|
40
|
-
console.log("No table provided.");
|
|
41
|
-
return [];
|
|
42
|
-
} else if (collection.length === 0) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
const chunkedItems = lodashChunk(collection, maxChunk);
|
|
46
|
-
const results = [];
|
|
47
|
-
for (const items of chunkedItems) {
|
|
48
|
-
const result = await table.batchWrite(items, {
|
|
49
|
-
execute: true
|
|
50
|
-
});
|
|
51
|
-
results.push(result);
|
|
13
|
+
const retry = async (input, results)=>{
|
|
14
|
+
if (!hasUnprocessedItems(input)) return;
|
|
15
|
+
const result = await input.next();
|
|
52
16
|
await retry(result, results);
|
|
53
|
-
}
|
|
54
|
-
return results;
|
|
55
17
|
};
|
|
18
|
+
const batchWriteAll = async (params, maxChunk = 25)=>{
|
|
19
|
+
const { items: collection, table } = params;
|
|
20
|
+
if (table) {
|
|
21
|
+
if (0 === collection.length) return [];
|
|
22
|
+
} else {
|
|
23
|
+
console.log("No table provided.");
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const chunkedItems = chunk(collection, maxChunk);
|
|
27
|
+
const results = [];
|
|
28
|
+
for (const items of chunkedItems){
|
|
29
|
+
const result = await table.batchWrite(items, {
|
|
30
|
+
execute: true
|
|
31
|
+
});
|
|
32
|
+
results.push(result);
|
|
33
|
+
await retry(result, results);
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
};
|
|
37
|
+
export { batchWriteAll };
|
|
56
38
|
|
|
57
39
|
//# sourceMappingURL=batchWrite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/batch/batchWrite.js","sources":["../../../src/utils/batch/batchWrite.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types.js\";\n\nexport interface BatchWriteParams {\n table: TableDef | undefined;\n items: BatchWriteItem[];\n}\n\nconst hasUnprocessedItems = (result: BatchWriteResponse): boolean => {\n if (typeof result.next !== \"function\") {\n return false;\n }\n const items = result.UnprocessedItems;\n if (!items || typeof items !== \"object\") {\n return false;\n }\n const keys = Object.keys(items);\n return keys.some(key => {\n const value = items[key];\n if (!Array.isArray(value)) {\n return false;\n }\n return value.some(val => {\n return val.PutRequest || val.DeleteRequest;\n });\n });\n};\n\nconst retry = async (input: BatchWriteResponse, results: BatchWriteResult): Promise<void> => {\n if (!hasUnprocessedItems(input)) {\n return;\n }\n const result = await input.next!();\n await retry(result, results);\n};\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for writing.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (\n params: BatchWriteParams,\n maxChunk = 25\n): Promise<BatchWriteResult> => {\n const { items: collection, table } = params;\n if (!table) {\n console.log(\"No table provided.\");\n return [];\n } else if (collection.length === 0) {\n return [];\n }\n\n const chunkedItems: BatchWriteItem[][] = lodashChunk(collection, maxChunk);\n const results: BatchWriteResult = [];\n for (const items of chunkedItems) {\n const result = (await table.batchWrite(items, {\n execute: true\n })) as BatchWriteResponse;\n results.push(result);\n await retry(result, results);\n }\n return results;\n};\n"],"names":["hasUnprocessedItems","result","items","keys","Object","key","value","Array","val","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","chunkedItems","lodashChunk"],"mappings":";AASA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClB,OAAO;IAEX,MAAMC,QAAQD,OAAO,gBAAgB;IACrC,IAAI,CAACC,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO;IAEX,MAAMC,OAAOC,OAAO,IAAI,CAACF;IACzB,OAAOC,KAAK,IAAI,CAACE,CAAAA;QACb,MAAMC,QAAQJ,KAAK,CAACG,IAAI;QACxB,IAAI,CAACE,MAAM,OAAO,CAACD,QACf,OAAO;QAEX,OAAOA,MAAM,IAAI,CAACE,CAAAA,MACPA,IAAI,UAAU,IAAIA,IAAI,aAAa;IAElD;AACJ;AAEA,MAAMC,QAAQ,OAAOC,OAA2BC;IAC5C,IAAI,CAACX,oBAAoBU,QACrB;IAEJ,MAAMT,SAAS,MAAMS,MAAM,IAAI;IAC/B,MAAMD,MAAMR,QAAQU;AACxB;AAOO,MAAMC,gBAAgB,OACzBC,QACAC,WAAW,EAAE;IAEb,MAAM,EAAE,OAAOC,UAAU,EAAEC,KAAK,EAAE,GAAGH;IACrC,IAAKG,OAGE;QAAA,IAAID,AAAsB,MAAtBA,WAAW,MAAM,EACxB,OAAO,EAAE;IACb,OALY;QACRE,QAAQ,GAAG,CAAC;QACZ,OAAO,EAAE;IACb;IAIA,MAAMC,eAAmCC,MAAYJ,YAAYD;IACjE,MAAMH,UAA4B,EAAE;IACpC,KAAK,MAAMT,SAASgB,aAAc;QAC9B,MAAMjB,SAAU,MAAMe,MAAM,UAAU,CAACd,OAAO;YAC1C,SAAS;QACb;QACAS,QAAQ,IAAI,CAACV;QACb,MAAMQ,MAAMR,QAAQU;IACxB;IACA,OAAOA;AACX"}
|
package/utils/batch/index.js
CHANGED
package/utils/batch/types.js
CHANGED