@webiny/db-dynamodb 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/DynamoDbDriver.d.ts +4 -8
- package/DynamoDbDriver.js +71 -102
- package/DynamoDbDriver.js.map +1 -1
- package/README.md +6 -142
- package/index.d.ts +4 -3
- package/index.js +4 -28
- package/index.js.map +1 -1
- package/package.json +18 -20
- package/plugins/definitions/AttributePlugin.d.ts +1 -1
- package/plugins/definitions/AttributePlugin.js +4 -12
- package/plugins/definitions/AttributePlugin.js.map +1 -1
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -2
- package/plugins/definitions/DateTimeTransformPlugin.js +6 -14
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPathPlugin.js +6 -14
- package/plugins/definitions/FieldPathPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.d.ts +1 -1
- package/plugins/definitions/FieldPlugin.js +2 -9
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.d.ts +2 -2
- package/plugins/definitions/TimeTransformPlugin.js +7 -15
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueFilterPlugin.js +5 -13
- package/plugins/definitions/ValueFilterPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.js +6 -14
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +4 -12
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/filters/andIn.d.ts +1 -1
- package/plugins/filters/andIn.js +5 -12
- package/plugins/filters/andIn.js.map +1 -1
- package/plugins/filters/between.d.ts +1 -1
- package/plugins/filters/between.js +5 -12
- package/plugins/filters/between.js.map +1 -1
- package/plugins/filters/contains.d.ts +1 -1
- package/plugins/filters/contains.js +3 -9
- package/plugins/filters/contains.js.map +1 -1
- package/plugins/filters/eq.d.ts +1 -1
- package/plugins/filters/eq.js +3 -9
- package/plugins/filters/eq.js.map +1 -1
- package/plugins/filters/fuzzy.d.ts +1 -1
- package/plugins/filters/fuzzy.js +5 -12
- package/plugins/filters/fuzzy.js.map +1 -1
- package/plugins/filters/gt.d.ts +1 -1
- package/plugins/filters/gt.js +3 -9
- package/plugins/filters/gt.js.map +1 -1
- package/plugins/filters/gte.d.ts +1 -1
- package/plugins/filters/gte.js +3 -9
- package/plugins/filters/gte.js.map +1 -1
- package/plugins/filters/in.d.ts +1 -1
- package/plugins/filters/in.js +5 -12
- package/plugins/filters/in.js.map +1 -1
- package/plugins/filters/index.d.ts +1 -1
- package/plugins/filters/index.js +12 -20
- package/plugins/filters/index.js.map +1 -1
- package/plugins/filters/lt.d.ts +1 -1
- package/plugins/filters/lt.js +3 -9
- package/plugins/filters/lt.js.map +1 -1
- package/plugins/filters/lte.d.ts +1 -1
- package/plugins/filters/lte.js +3 -9
- package/plugins/filters/lte.js.map +1 -1
- package/plugins/filters/startsWith.d.ts +1 -1
- package/plugins/filters/startsWith.js +3 -9
- package/plugins/filters/startsWith.js.map +1 -1
- package/plugins/index.d.ts +9 -1
- package/plugins/index.js +11 -11
- package/plugins/index.js.map +1 -1
- package/store/entity.d.ts +4 -76
- package/store/entity.js +5 -35
- package/store/entity.js.map +1 -1
- package/store/keys.d.ts +1 -1
- package/store/keys.js +7 -13
- package/store/keys.js.map +1 -1
- package/store/types.d.ts +3 -4
- package/store/types.js +1 -5
- package/store/types.js.map +1 -1
- package/toolbox.d.ts +7 -2
- package/toolbox.js +2 -17
- package/toolbox.js.map +1 -1
- package/types.js +1 -5
- package/utils/attributes.d.ts +2 -2
- package/utils/attributes.js +4 -12
- package/utils/attributes.js.map +1 -1
- package/utils/batch/batchRead.d.ts +2 -2
- package/utils/batch/batchRead.js +5 -13
- package/utils/batch/batchRead.js.map +1 -1
- package/utils/batch/batchWrite.d.ts +2 -2
- package/utils/batch/batchWrite.js +3 -11
- package/utils/batch/batchWrite.js.map +1 -1
- package/utils/batch/index.d.ts +3 -3
- package/utils/batch/index.js +3 -38
- package/utils/batch/index.js.map +1 -1
- package/utils/batch/types.d.ts +7 -2
- package/utils/batch/types.js +1 -5
- package/utils/batch/types.js.map +1 -1
- package/utils/cleanup.d.ts +1 -1
- package/utils/cleanup.js +3 -10
- package/utils/cleanup.js.map +1 -1
- package/utils/count.d.ts +1 -1
- package/utils/count.js +1 -8
- package/utils/count.js.map +1 -1
- package/utils/createEntity.d.ts +36 -54
- package/utils/createEntity.js +75 -51
- package/utils/createEntity.js.map +1 -1
- package/utils/createTable.d.ts +10 -7
- package/utils/createTable.js +25 -15
- package/utils/createTable.js.map +1 -1
- package/utils/cursor.js +2 -10
- package/utils/cursor.js.map +1 -1
- package/utils/delete.d.ts +1 -1
- package/utils/delete.js +1 -8
- package/utils/delete.js.map +1 -1
- package/utils/entity/Entity.d.ts +23 -21
- package/utils/entity/Entity.js +56 -34
- package/utils/entity/Entity.js.map +1 -1
- package/utils/entity/EntityReadBatch.d.ts +9 -8
- package/utils/entity/EntityReadBatch.js +14 -16
- package/utils/entity/EntityReadBatch.js.map +1 -1
- package/utils/entity/EntityReadBatchBuilder.d.ts +4 -4
- package/utils/entity/EntityReadBatchBuilder.js +7 -15
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
- package/utils/entity/EntityWriteBatch.d.ts +9 -8
- package/utils/entity/EntityWriteBatch.js +10 -18
- package/utils/entity/EntityWriteBatch.js.map +1 -1
- package/utils/entity/EntityWriteBatchBuilder.d.ts +4 -4
- package/utils/entity/EntityWriteBatchBuilder.js +4 -12
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
- package/utils/entity/getEntity.d.ts +2 -2
- package/utils/entity/getEntity.js +3 -10
- package/utils/entity/getEntity.js.map +1 -1
- package/utils/entity/index.d.ts +7 -7
- package/utils/entity/index.js +7 -82
- package/utils/entity/index.js.map +1 -1
- package/utils/entity/types.d.ts +46 -22
- package/utils/entity/types.js +2 -5
- package/utils/entity/types.js.map +1 -1
- package/utils/filter.d.ts +1 -1
- package/utils/filter.js +7 -14
- package/utils/filter.js.map +1 -1
- package/utils/get.d.ts +1 -1
- package/utils/get.js +4 -12
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +17 -17
- package/utils/index.js +17 -192
- package/utils/index.js.map +1 -1
- package/utils/listResponse.js +4 -10
- package/utils/listResponse.js.map +1 -1
- package/utils/put.d.ts +2 -2
- package/utils/put.js +1 -8
- package/utils/put.js.map +1 -1
- package/utils/query.d.ts +5 -12
- package/utils/query.js +13 -27
- package/utils/query.js.map +1 -1
- package/utils/scan.d.ts +2 -2
- package/utils/scan.js +5 -13
- package/utils/scan.js.map +1 -1
- package/utils/sort.d.ts +1 -1
- package/utils/sort.js +7 -14
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.d.ts +4 -5
- package/utils/table/Table.js +9 -20
- package/utils/table/Table.js.map +1 -1
- package/utils/table/TableReadBatch.d.ts +4 -4
- package/utils/table/TableReadBatch.js +8 -16
- package/utils/table/TableReadBatch.js.map +1 -1
- package/utils/table/TableWriteBatch.d.ts +3 -3
- package/utils/table/TableWriteBatch.js +6 -14
- package/utils/table/TableWriteBatch.js.map +1 -1
- package/utils/table/index.d.ts +4 -4
- package/utils/table/index.js +4 -49
- package/utils/table/index.js.map +1 -1
- package/utils/table/types.d.ts +8 -8
- package/utils/table/types.js +1 -5
- package/utils/table/types.js.map +1 -1
- package/utils/update.d.ts +1 -1
- package/utils/update.js +1 -8
- package/utils/update.js.map +1 -1
package/store/entity.js
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createEntity = void 0;
|
|
7
|
-
var _toolbox = require("../toolbox");
|
|
8
|
-
/**
|
|
9
|
-
* TODO determine if GSIs are needed
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const createEntity = ({
|
|
1
|
+
import { createGlobalEntity as baseCreateGlobalEntity } from "../utils/index.js";
|
|
2
|
+
export const createEntity = ({
|
|
13
3
|
table
|
|
14
4
|
}) => {
|
|
15
|
-
return
|
|
16
|
-
table,
|
|
17
|
-
name: "WebinyKeyValue"
|
|
18
|
-
attributes: {
|
|
19
|
-
PK: {
|
|
20
|
-
partitionKey: true
|
|
21
|
-
},
|
|
22
|
-
SK: {
|
|
23
|
-
sortKey: true
|
|
24
|
-
},
|
|
25
|
-
TYPE: {
|
|
26
|
-
type: "string"
|
|
27
|
-
},
|
|
28
|
-
key: {
|
|
29
|
-
type: "string"
|
|
30
|
-
},
|
|
31
|
-
value: {
|
|
32
|
-
type: "string"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
autoExecute: true,
|
|
36
|
-
autoParse: true
|
|
5
|
+
return baseCreateGlobalEntity({
|
|
6
|
+
table: table.table,
|
|
7
|
+
name: "WebinyKeyValue"
|
|
37
8
|
});
|
|
38
9
|
};
|
|
39
|
-
exports.createEntity = createEntity;
|
|
40
10
|
|
|
41
11
|
//# sourceMappingURL=entity.js.map
|
package/store/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createGlobalEntity","baseCreateGlobalEntity","createEntity","table","name"],"sources":["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"],"mappings":"AACA,SAASA,kBAAkB,IAAIC,sBAAsB;AAOrD,OAAO,MAAMC,YAAY,GAAGA,CAAC;EAAEC;AAA2B,CAAC,KAAmB;EAC1E,OAAOF,sBAAsB,CAAoB;IAC7CE,KAAK,EAAEA,KAAK,CAACA,KAAK;IAClBC,IAAI,EAAE;EACV,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
package/store/keys.d.ts
CHANGED
package/store/keys.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createType = exports.createSortKey = exports.createPartitionKey = void 0;
|
|
7
|
-
const createPartitionKey = () => {
|
|
1
|
+
export const createPartitionKey = () => {
|
|
8
2
|
return `W#internal`;
|
|
9
3
|
};
|
|
10
|
-
|
|
11
|
-
const createSortKey = ({
|
|
4
|
+
export const createSortKey = ({
|
|
12
5
|
key
|
|
13
6
|
}) => {
|
|
14
|
-
|
|
7
|
+
if (typeof key === "symbol") {
|
|
8
|
+
return key.toString();
|
|
9
|
+
}
|
|
10
|
+
return String(key);
|
|
15
11
|
};
|
|
16
|
-
|
|
17
|
-
const createType = () => {
|
|
12
|
+
export const createType = () => {
|
|
18
13
|
return "internal";
|
|
19
14
|
};
|
|
20
|
-
exports.createType = createType;
|
|
21
15
|
|
|
22
16
|
//# sourceMappingURL=keys.js.map
|
package/store/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createPartitionKey","
|
|
1
|
+
{"version":3,"names":["createPartitionKey","createSortKey","key","toString","String","createType"],"sources":["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"],"mappings":"AAIA,OAAO,MAAMA,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAO,YAAY;AACvB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC;AAAa,CAAC,KAAK;EAC/C,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;IACzB,OAAOA,GAAG,CAACC,QAAQ,CAAC,CAAC;EACzB;EACA,OAAOC,MAAM,CAACF,GAAG,CAAC;AACtB,CAAC;AAED,OAAO,MAAMG,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,UAAU;AACrB,CAAC","ignoreList":[]}
|
package/store/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
SK: string;
|
|
4
|
-
TYPE: string;
|
|
1
|
+
import type { IEntity, IGlobalEntityAttributes } from "../utils/index.js";
|
|
2
|
+
export interface IStoreEntityValue {
|
|
5
3
|
key: string;
|
|
6
4
|
value: string;
|
|
7
5
|
}
|
|
6
|
+
export type IStoreEntity = IEntity<IGlobalEntityAttributes<IStoreEntityValue>>;
|
package/store/types.js
CHANGED
package/store/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IGlobalEntityAttributes } from \"~/utils/index.js\";\n\nexport interface IStoreEntityValue {\n key: string;\n value: string;\n}\n\nexport type IStoreEntity = IEntity<IGlobalEntityAttributes<IStoreEntityValue>>;\n"],"mappings":"","ignoreList":[]}
|
package/toolbox.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
-
|
|
3
|
-
export type
|
|
2
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
3
|
+
export type ScanOptions = NonNullable<Parameters<Entity["scan"]>[0]>;
|
|
4
|
+
export type DynamoDBTypes = "string" | "boolean" | "number" | "bigint" | "list" | "map" | "binary" | "set";
|
|
5
|
+
type Key = string | number | symbol;
|
|
6
|
+
export type TableDef = Table<string, Key, Key | null>;
|
|
7
|
+
export type TableConstructor<A extends string, B extends Key, C extends Key> = ConstructorParameters<typeof Table<A, B, C>>[0];
|
|
8
|
+
export type { EntityConstructor, Readonly, AttributeDefinition, EntityQueryOptions, AttributeDefinitions } from "dynamodb-toolbox/dist/cjs/classes/Entity/index.js";
|
package/toolbox.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Entity", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _dynamodbToolbox.Entity;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "Table", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _dynamodbToolbox.Table;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
3
|
+
// TODO: this needs to be replaced with either inferred types, or manual cherry picked types.
|
|
19
4
|
|
|
20
5
|
//# sourceMappingURL=toolbox.js.map
|
package/toolbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Entity","Table"],"sources":["toolbox.ts"],"sourcesContent":["export { Entity, Table } from \"dynamodb-toolbox\";\n\nimport { Entity, Table } from \"dynamodb-toolbox\";\n\nexport type ScanOptions = NonNullable<Parameters<Entity[\"scan\"]>[0]>;\nexport type DynamoDBTypes =\n | \"string\"\n | \"boolean\"\n | \"number\"\n | \"bigint\"\n | \"list\"\n | \"map\"\n | \"binary\"\n | \"set\";\n\ntype Key = string | number | symbol;\n\nexport type TableDef = Table<string, Key, Key | null>;\nexport type TableConstructor<\n A extends string,\n B extends Key,\n C extends Key\n> = ConstructorParameters<typeof Table<A, B, C>>[0];\n\n// TODO: this needs to be replaced with either inferred types, or manual cherry picked types.\nexport type {\n EntityConstructor,\n Readonly,\n AttributeDefinition,\n EntityQueryOptions,\n AttributeDefinitions\n} from \"dynamodb-toolbox/dist/cjs/classes/Entity/index.js\";\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,KAAK,QAAQ,kBAAkB;;AAwBhD","ignoreList":[]}
|
package/types.js
CHANGED
package/utils/attributes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Context } from "@webiny/api/types";
|
|
2
|
-
import { AttributePlugin } from "../plugins/definitions/AttributePlugin";
|
|
1
|
+
import type { Context } from "@webiny/api/types.js";
|
|
2
|
+
import { AttributePlugin } from "../plugins/definitions/AttributePlugin.js";
|
|
3
3
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
/**
|
|
5
5
|
* Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
|
package/utils/attributes.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getExtraAttributesFromPlugins = exports.getExtraAttributes = void 0;
|
|
7
|
-
var _AttributePlugin = require("../plugins/definitions/AttributePlugin");
|
|
1
|
+
import { AttributePlugin } from "../plugins/definitions/AttributePlugin.js";
|
|
8
2
|
/**
|
|
9
3
|
* Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
|
|
10
4
|
*
|
|
11
5
|
* @deprecated
|
|
12
6
|
*/
|
|
13
|
-
const getExtraAttributes = (context, entity) => {
|
|
7
|
+
export const getExtraAttributes = (context, entity) => {
|
|
14
8
|
return getExtraAttributesFromPlugins(context.plugins, entity);
|
|
15
9
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return plugins.byType(_AttributePlugin.AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
|
|
10
|
+
export const getExtraAttributesFromPlugins = (plugins, entity) => {
|
|
11
|
+
return plugins.byType(AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
|
|
19
12
|
return {
|
|
20
13
|
...attributes,
|
|
21
14
|
...plugin.getDefinition()
|
|
22
15
|
};
|
|
23
16
|
}, {});
|
|
24
17
|
};
|
|
25
|
-
exports.getExtraAttributesFromPlugins = getExtraAttributesFromPlugins;
|
|
26
18
|
|
|
27
19
|
//# sourceMappingURL=attributes.js.map
|
package/utils/attributes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["AttributePlugin","getExtraAttributes","context","entity","getExtraAttributesFromPlugins","plugins","byType","type","filter","plugin","reduce","attributes","getDefinition"],"sources":["attributes.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { AttributePlugin } from \"~/plugins/definitions/AttributePlugin.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: Context,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return getExtraAttributesFromPlugins(context.plugins, entity);\n};\n\nexport const getExtraAttributesFromPlugins = (\n plugins: PluginsContainer,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"mappings":"AACA,SAASA,eAAe;AAGxB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAC9BC,OAAgB,EAChBC,MAAc,KAC+B;EAC7C,OAAOC,6BAA6B,CAACF,OAAO,CAACG,OAAO,EAAEF,MAAM,CAAC;AACjE,CAAC;AAED,OAAO,MAAMC,6BAA6B,GAAGA,CACzCC,OAAyB,EACzBF,MAAc,KAC+B;EAC7C,OAAOE,OAAO,CACTC,MAAM,CAAkBN,eAAe,CAACO,IAAI,CAAC,CAC7CC,MAAM,CAACC,MAAM,IAAIA,MAAM,CAACN,MAAM,KAAKA,MAAM,CAAC,CAC1CO,MAAM,CAAC,CAACC,UAAU,EAAEF,MAAM,KAAK;IAC5B,OAAO;MACH,GAAGE,UAAU;MACb,GAAGF,MAAM,CAACG,aAAa,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,CAAC,CAAC,CAAC;AACd,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TableDef } from "../../toolbox";
|
|
2
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
1
|
+
import type { TableDef } from "../../toolbox.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
3
|
export interface BatchReadItem {
|
|
4
4
|
Table?: TableDef;
|
|
5
5
|
Key: any;
|
package/utils/batch/batchRead.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.batchReadAll = void 0;
|
|
8
|
-
var _chunk = _interopRequireDefault(require("lodash/chunk"));
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
1
|
+
import lodashChunk from "lodash/chunk.js";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
10
3
|
const MAX_BATCH_ITEMS = 100;
|
|
11
4
|
const flatten = responses => {
|
|
12
5
|
const entries = [];
|
|
@@ -48,16 +41,16 @@ const batchReadAllChunk = async params => {
|
|
|
48
41
|
* This helper function is meant to be used to batch read from one table.
|
|
49
42
|
* It will fetch all results, as there is a next() method call built in.
|
|
50
43
|
*/
|
|
51
|
-
const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
44
|
+
export const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
52
45
|
if (params.items.length === 0) {
|
|
53
46
|
return [];
|
|
54
47
|
} else if (maxChunk > MAX_BATCH_ITEMS) {
|
|
55
|
-
throw new
|
|
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", {
|
|
56
49
|
maxChunk
|
|
57
50
|
});
|
|
58
51
|
}
|
|
59
52
|
const records = [];
|
|
60
|
-
const chunkItemsList = (
|
|
53
|
+
const chunkItemsList = lodashChunk(params.items, maxChunk);
|
|
61
54
|
for (const chunkItems of chunkItemsList) {
|
|
62
55
|
const results = await batchReadAllChunk({
|
|
63
56
|
table: params.table,
|
|
@@ -67,6 +60,5 @@ const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
|
67
60
|
}
|
|
68
61
|
return records;
|
|
69
62
|
};
|
|
70
|
-
exports.batchReadAll = batchReadAll;
|
|
71
63
|
|
|
72
64
|
//# sourceMappingURL=batchRead.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["lodashChunk","WebinyError","MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","chunkItemsList","chunkItems","results"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AACzC,OAAOC,WAAW,MAAM,eAAe;AAavC,MAAMC,eAAe,GAAG,GAAG;AAE3B,MAAMC,OAAO,GAAIC,SAAgC,IAAY;EACzD,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAM,CAACF,SAAS,CAAC;EACvC,KAAK,MAAMI,KAAK,IAAIF,MAAM,EAAE;IACxBD,OAAO,CAACI,IAAI,CAAC,GAAGD,KAAK,CAAC;EAC1B;EACA,OAAOH,OAAO;AAClB,CAAC;AAMD,MAAMK,iBAAiB,GAAG,MAAgBC,MAA+B,IAAmB;EACxF,MAAM;IAAEC,KAAK;IAAEJ;EAAM,CAAC,GAAGG,MAAM;EAC/B,MAAME,OAAY,GAAG,EAAE;EAEvB,IAAI,CAACD,KAAK,EAAE;IACR,OAAOC,OAAO;EAClB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAQ,CAACP,KAAK,CAAC;EAC1C,IAAI,CAACM,MAAM,IAAI,CAACA,MAAM,CAACE,SAAS,EAAE;IAC9B,OAAOH,OAAO;EAClB;EACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACW,MAAM,CAACE,SAAS,CAAC,CAAC;EAC1C,IAAI,CAACF,MAAM,CAACG,IAAI,IAAI,OAAOH,MAAM,CAACG,IAAI,KAAK,UAAU,EAAE;IACnD,OAAOJ,OAAO;EAClB;EACA,IAAIK,QAAQ,GAAGJ,MAAM;EACrB,OAAO,OAAOI,QAAQ,CAACD,IAAI,KAAK,UAAU,EAAE;IACxC,MAAME,UAAU,GAAG,MAAMD,QAAQ,CAACD,IAAI,CAAC,CAAC;IACxC,IAAI,CAACE,UAAU,EAAE;MACb,OAAON,OAAO;IAClB;IACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACgB,UAAU,CAACH,SAAS,CAAC,CAAC;IAC9CE,QAAQ,GAAGC,UAAU;EACzB;EACA,OAAON,OAAO;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMO,YAAY,GAAG,MAAAA,CACxBT,MAAuB,EACvBU,QAAQ,GAAGnB,eAAe,KACX;EACf,IAAIS,MAAM,CAACH,KAAK,CAACc,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAO,EAAE;EACb,CAAC,MAAM,IAAID,QAAQ,GAAGnB,eAAe,EAAE;IACnC,MAAM,IAAID,WAAW,CACjB,gCAAgCC,eAAe,mCAAmC,EAClF,oCAAoC,EACpC;MACImB;IACJ,CACJ,CAAC;EACL;EAEA,MAAMR,OAAY,GAAG,EAAE;EAEvB,MAAMU,cAAc,GAAGvB,WAAW,CAACW,MAAM,CAACH,KAAK,EAAEa,QAAQ,CAAC;EAE1D,KAAK,MAAMG,UAAU,IAAID,cAAc,EAAE;IACrC,MAAME,OAAO,GAAG,MAAMf,iBAAiB,CAAI;MACvCE,KAAK,EAAED,MAAM,CAACC,KAAK;MACnBJ,KAAK,EAAEgB;IACX,CAAC,CAAC;IAEFX,OAAO,CAACJ,IAAI,CAAC,GAAGgB,OAAO,CAAC;EAC5B;EAEA,OAAOZ,OAAO;AAClB,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TableDef } from "../../toolbox";
|
|
2
|
-
import type { BatchWriteItem, BatchWriteResult } from "./types";
|
|
1
|
+
import type { TableDef } from "../../toolbox.js";
|
|
2
|
+
import type { BatchWriteItem, BatchWriteResult } from "./types.js";
|
|
3
3
|
export interface BatchWriteParams {
|
|
4
4
|
table: TableDef | undefined;
|
|
5
5
|
items: BatchWriteItem[];
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.batchWriteAll = void 0;
|
|
8
|
-
var _chunk = _interopRequireDefault(require("lodash/chunk"));
|
|
1
|
+
import lodashChunk from "lodash/chunk.js";
|
|
9
2
|
const hasUnprocessedItems = result => {
|
|
10
3
|
if (typeof result.next !== "function") {
|
|
11
4
|
return false;
|
|
@@ -38,7 +31,7 @@ const retry = async (input, results) => {
|
|
|
38
31
|
* It can either delete or put items
|
|
39
32
|
* The method does not check items before actually sending them into the underlying library.
|
|
40
33
|
*/
|
|
41
|
-
const batchWriteAll = async (params, maxChunk = 25) => {
|
|
34
|
+
export const batchWriteAll = async (params, maxChunk = 25) => {
|
|
42
35
|
const {
|
|
43
36
|
items: collection,
|
|
44
37
|
table
|
|
@@ -49,7 +42,7 @@ const batchWriteAll = async (params, maxChunk = 25) => {
|
|
|
49
42
|
} else if (collection.length === 0) {
|
|
50
43
|
return [];
|
|
51
44
|
}
|
|
52
|
-
const chunkedItems = (
|
|
45
|
+
const chunkedItems = lodashChunk(collection, maxChunk);
|
|
53
46
|
const results = [];
|
|
54
47
|
for (const items of chunkedItems) {
|
|
55
48
|
const result = await table.batchWrite(items, {
|
|
@@ -60,6 +53,5 @@ const batchWriteAll = async (params, maxChunk = 25) => {
|
|
|
60
53
|
}
|
|
61
54
|
return results;
|
|
62
55
|
};
|
|
63
|
-
exports.batchWriteAll = batchWriteAll;
|
|
64
56
|
|
|
65
57
|
//# sourceMappingURL=batchWrite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["lodashChunk","hasUnprocessedItems","result","next","items","UnprocessedItems","keys","Object","some","key","value","Array","isArray","val","PutRequest","DeleteRequest","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","log","length","chunkedItems","batchWrite","execute","push"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AASzC,MAAMC,mBAAmB,GAAIC,MAA0B,IAAc;EACjE,IAAI,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EAAE;IACnC,OAAO,KAAK;EAChB;EACA,MAAMC,KAAK,GAAGF,MAAM,CAACG,gBAAgB;EACrC,IAAI,CAACD,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IACrC,OAAO,KAAK;EAChB;EACA,MAAME,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,KAAK,CAAC;EAC/B,OAAOE,IAAI,CAACE,IAAI,CAACC,GAAG,IAAI;IACpB,MAAMC,KAAK,GAAGN,KAAK,CAACK,GAAG,CAAC;IACxB,IAAI,CAACE,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACvB,OAAO,KAAK;IAChB;IACA,OAAOA,KAAK,CAACF,IAAI,CAACK,GAAG,IAAI;MACrB,OAAOA,GAAG,CAACC,UAAU,IAAID,GAAG,CAACE,aAAa;IAC9C,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAED,MAAMC,KAAK,GAAG,MAAAA,CAAOC,KAAyB,EAAEC,OAAyB,KAAoB;EACzF,IAAI,CAACjB,mBAAmB,CAACgB,KAAK,CAAC,EAAE;IAC7B;EACJ;EACA,MAAMf,MAAM,GAAG,MAAMe,KAAK,CAACd,IAAI,CAAE,CAAC;EAClC,MAAMa,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;AAChC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG,MAAAA,CACzBC,MAAwB,EACxBC,QAAQ,GAAG,EAAE,KACe;EAC5B,MAAM;IAAEjB,KAAK,EAAEkB,UAAU;IAAEC;EAAM,CAAC,GAAGH,MAAM;EAC3C,IAAI,CAACG,KAAK,EAAE;IACRC,OAAO,CAACC,GAAG,CAAC,oBAAoB,CAAC;IACjC,OAAO,EAAE;EACb,CAAC,MAAM,IAAIH,UAAU,CAACI,MAAM,KAAK,CAAC,EAAE;IAChC,OAAO,EAAE;EACb;EAEA,MAAMC,YAAgC,GAAG3B,WAAW,CAACsB,UAAU,EAAED,QAAQ,CAAC;EAC1E,MAAMH,OAAyB,GAAG,EAAE;EACpC,KAAK,MAAMd,KAAK,IAAIuB,YAAY,EAAE;IAC9B,MAAMzB,MAAM,GAAI,MAAMqB,KAAK,CAACK,UAAU,CAACxB,KAAK,EAAE;MAC1CyB,OAAO,EAAE;IACb,CAAC,CAAwB;IACzBX,OAAO,CAACY,IAAI,CAAC5B,MAAM,CAAC;IACpB,MAAMc,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;EAChC;EACA,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
|
package/utils/batch/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./batchRead";
|
|
2
|
-
export * from "./batchWrite";
|
|
3
|
-
export * from "./types";
|
|
1
|
+
export * from "./batchRead.js";
|
|
2
|
+
export * from "./batchWrite.js";
|
|
3
|
+
export * from "./types.js";
|
package/utils/batch/index.js
CHANGED
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _batchRead = require("./batchRead");
|
|
7
|
-
Object.keys(_batchRead).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _batchRead[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _batchRead[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _batchWrite = require("./batchWrite");
|
|
18
|
-
Object.keys(_batchWrite).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _batchWrite[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _batchWrite[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _types = require("./types");
|
|
29
|
-
Object.keys(_types).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _types[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
1
|
+
export * from "./batchRead.js";
|
|
2
|
+
export * from "./batchWrite.js";
|
|
3
|
+
export * from "./types.js";
|
|
39
4
|
|
|
40
5
|
//# sourceMappingURL=index.js.map
|
package/utils/batch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./batchRead.js\";\nexport * from \"./batchWrite.js\";\nexport * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
|
package/utils/batch/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb";
|
|
1
|
+
import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
3
|
export interface BatchWriteResponse {
|
|
3
4
|
next?: () => Promise<BatchWriteResponse>;
|
|
4
5
|
$metadata: {
|
|
@@ -16,10 +17,14 @@ export interface IDeleteBatchItem {
|
|
|
16
17
|
PK: string;
|
|
17
18
|
SK: string;
|
|
18
19
|
}
|
|
19
|
-
export type IPutBatchItem<T
|
|
20
|
+
export type IPutBatchItem<T = GenericRecord> = {
|
|
20
21
|
PK: string;
|
|
21
22
|
SK: string;
|
|
22
23
|
} & T;
|
|
23
24
|
export interface BatchWriteItem {
|
|
24
25
|
[key: string]: WriteRequest;
|
|
25
26
|
}
|
|
27
|
+
export interface IReadBatchItem {
|
|
28
|
+
PK: string;
|
|
29
|
+
SK: string;
|
|
30
|
+
}
|
package/utils/batch/types.js
CHANGED
package/utils/batch/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { WriteRequest } from \"@webiny/aws-sdk/client-dynamodb\";\n\nexport interface BatchWriteResponse {\n next?: () => Promise<BatchWriteResponse>;\n $metadata: {\n httpStatusCode: number;\n requestId: string;\n attempts: number;\n totalRetryDelay: number;\n };\n UnprocessedItems?: {\n [table: string]: WriteRequest[];\n };\n}\n\nexport type BatchWriteResult = BatchWriteResponse[];\n\nexport interface IDeleteBatchItem {\n PK: string;\n SK: string;\n}\n\nexport type IPutBatchItem<T
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { WriteRequest } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchWriteResponse {\n next?: () => Promise<BatchWriteResponse>;\n $metadata: {\n httpStatusCode: number;\n requestId: string;\n attempts: number;\n totalRetryDelay: number;\n };\n UnprocessedItems?: {\n [table: string]: WriteRequest[];\n };\n}\n\nexport type BatchWriteResult = BatchWriteResponse[];\n\nexport interface IDeleteBatchItem {\n PK: string;\n SK: string;\n}\n\nexport type IPutBatchItem<T = GenericRecord> = {\n PK: string;\n SK: string;\n} & T;\n\nexport interface BatchWriteItem {\n [key: string]: WriteRequest;\n}\n\nexport interface IReadBatchItem {\n PK: string;\n SK: string;\n}\n"],"mappings":"","ignoreList":[]}
|
package/utils/cleanup.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Entity } from "../toolbox";
|
|
1
|
+
import type { Entity } from "../toolbox.js";
|
|
2
2
|
export declare function cleanupItem<T>(entity: Entity<any>, item?: T | null, removeAttributes?: string[]): T | null;
|
|
3
3
|
export declare function cleanupItems<T>(entity: Entity<any>, items: T[], removeAttributes?: string[]): T[];
|
package/utils/cleanup.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.cleanupItem = cleanupItem;
|
|
7
|
-
exports.cleanupItems = cleanupItems;
|
|
8
1
|
/**
|
|
9
2
|
* The attributes defined by us or the dynamodb-toolbox library.
|
|
10
3
|
* Add more attributes if necessary.
|
|
11
4
|
*/
|
|
12
|
-
const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "GSI2_PK", "GSI2_SK", "GSI3_PK", "GSI3_SK", "GSI4_PK", "GSI4_SK", "GSI5_PK", "GSI5_SK", "TYPE"];
|
|
13
|
-
function cleanupItem(entity, item, removeAttributes = []) {
|
|
5
|
+
const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "GSI2_PK", "GSI2_SK", "GSI3_PK", "GSI3_SK", "GSI4_PK", "GSI4_SK", "GSI5_PK", "GSI5_SK", "GSI_TENANT", "TYPE"];
|
|
6
|
+
export function cleanupItem(entity, item, removeAttributes = []) {
|
|
14
7
|
if (!item) {
|
|
15
8
|
return null;
|
|
16
9
|
}
|
|
@@ -30,7 +23,7 @@ function cleanupItem(entity, item, removeAttributes = []) {
|
|
|
30
23
|
}
|
|
31
24
|
return newItem;
|
|
32
25
|
}
|
|
33
|
-
function cleanupItems(entity, items, removeAttributes = []) {
|
|
26
|
+
export function cleanupItems(entity, items, removeAttributes = []) {
|
|
34
27
|
return items.map(item => cleanupItem(entity, item, removeAttributes));
|
|
35
28
|
}
|
|
36
29
|
|
package/utils/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"GSI_TENANT\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CACvB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,EACV,KAAK,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,EACZ,MAAM,CACT;AAED,OAAO,SAASC,WAAWA,CACvBC,MAAmB,EACnBC,IAAe,EACfC,gBAA0B,GAAG,EAAE,EACvB;EACR,IAAI,CAACD,IAAI,EAAE;IACP,OAAO,IAAI;EACf;EACA,MAAME,OAAO,GAAG;IACZ,GAAGF;EACP,CAAC;EACD,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAM,CAACH,gBAAgB,CAAC;EAC3D,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACD,UAAU;EAC3C,KAAK,MAAME,GAAG,IAAIP,IAAI,EAAE;IACpB,IAAIA,IAAI,CAACQ,cAAc,CAACD,GAAG,CAAC,KAAK,KAAK,EAAE;MACpC;IACJ;IACA,IAAIF,UAAU,CAACE,GAAG,CAAC,IAAIJ,OAAO,CAACM,QAAQ,CAACF,GAAG,CAAC,KAAK,KAAK,EAAE;MACpD;IACJ;IACA,OAAOL,OAAO,CAACK,GAAG,CAAC;EACvB;EACA,OAAOL,OAAO;AAClB;AAEA,OAAO,SAASQ,YAAYA,CACxBX,MAAmB,EACnBY,KAAU,EACVV,gBAA0B,GAAG,EAAE,EAC5B;EACH,OAAOU,KAAK,CAACC,GAAG,CAACZ,IAAI,IAAIF,WAAW,CAAIC,MAAM,EAAEC,IAAI,EAAEC,gBAAgB,CAAM,CAAC;AACjF","ignoreList":[]}
|
package/utils/count.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { QueryAllParams } from "
|
|
1
|
+
import type { QueryAllParams } from "../utils/query.js";
|
|
2
2
|
export declare const count: (params: QueryAllParams) => Promise<number>;
|
package/utils/count.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.count = void 0;
|
|
7
|
-
const count = async params => {
|
|
1
|
+
export const count = async params => {
|
|
8
2
|
const {
|
|
9
3
|
entity,
|
|
10
4
|
partitionKey,
|
|
@@ -18,6 +12,5 @@ const count = async params => {
|
|
|
18
12
|
});
|
|
19
13
|
return Count || 0;
|
|
20
14
|
};
|
|
21
|
-
exports.count = count;
|
|
22
15
|
|
|
23
16
|
//# sourceMappingURL=count.js.map
|
package/utils/count.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["count","params","entity","partitionKey","options","Count","query","select"
|
|
1
|
+
{"version":3,"names":["count","params","entity","partitionKey","options","Count","query","select"],"sources":["count.ts"],"sourcesContent":["import type { QueryAllParams } from \"~/utils/query.js\";\n\nexport const count = async (params: QueryAllParams): Promise<number> => {\n const { entity, partitionKey, options = {} } = params;\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,KAAK,GAAG,MAAOC,MAAsB,IAAsB;EACpE,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,OAAO,GAAG,CAAC;EAAE,CAAC,GAAGH,MAAM;EACrD,MAAM;IAAEI;EAAM,CAAC,GAAG,MAAMH,MAAM,CAACI,KAAK,CAACH,YAAY,EAAE;IAAE,GAAGC,OAAO;IAAEG,MAAM,EAAE;EAAQ,CAAC,CAAC;EACnF,OAAOF,KAAK,IAAI,CAAC;AACrB,CAAC","ignoreList":[]}
|