@webiny/db-dynamodb 0.0.0-unstable.78f581c1d2 → 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.d.ts +18 -32
- package/DynamoDbDriver.js +215 -261
- package/DynamoDbDriver.js.map +1 -1
- package/README.md +6 -62
- 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 +5 -1
- package/index.js +12 -14
- package/index.js.map +1 -1
- package/package.json +32 -30
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/DateTimeTransformPlugin.js +21 -50
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.d.ts +2 -2
- package/plugins/definitions/FieldPlugin.js +36 -68
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/TimeTransformPlugin.js +29 -56
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.d.ts +2 -7
- package/plugins/definitions/ValueTransformPlugin.js +20 -46
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +15 -34
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.d.ts +5 -2
- package/plugins/index.js +5 -19
- package/store/entity.d.ts +6 -0
- package/store/entity.js +8 -0
- package/store/entity.js.map +1 -0
- package/store/keys.d.ts +6 -0
- package/store/keys.js +9 -0
- package/store/keys.js.map +1 -0
- package/store/types.d.ts +6 -0
- package/store/types.js +0 -0
- package/toolbox.d.ts +60 -0
- package/toolbox.js +1 -0
- package/types.d.ts +10 -23
- package/types.js +0 -5
- package/utils/batch/batchRead.d.ts +15 -0
- package/utils/batch/batchRead.js +45 -0
- package/utils/batch/batchRead.js.map +1 -0
- package/utils/batch/batchWrite.d.ts +13 -0
- package/utils/batch/batchWrite.js +39 -0
- package/utils/batch/batchWrite.js.map +1 -0
- package/utils/batch/index.d.ts +3 -0
- package/utils/batch/index.js +3 -0
- package/utils/batch/types.d.ts +30 -0
- package/utils/batch/types.js +0 -0
- package/utils/cleanup.d.ts +3 -3
- package/utils/cleanup.js +36 -41
- package/utils/cleanup.js.map +1 -1
- package/utils/count.d.ts +2 -0
- package/utils/count.js +11 -0
- package/utils/count.js.map +1 -0
- package/utils/createEntity.d.ts +36 -0
- package/utils/createEntity.js +82 -0
- package/utils/createEntity.js.map +1 -0
- package/utils/createTable.d.ts +11 -0
- package/utils/createTable.js +29 -0
- package/utils/createTable.js.map +1 -0
- package/utils/cursor.js +8 -23
- package/utils/cursor.js.map +1 -1
- package/utils/delete.d.ts +10 -0
- package/utils/delete.js +9 -0
- package/utils/delete.js.map +1 -0
- package/utils/entity/Entity.d.ts +28 -0
- package/utils/entity/Entity.js +95 -0
- package/utils/entity/Entity.js.map +1 -0
- package/utils/entity/EntityReadBatch.d.ts +18 -0
- package/utils/entity/EntityReadBatch.js +31 -0
- package/utils/entity/EntityReadBatch.js.map +1 -0
- package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
- package/utils/entity/EntityReadBatchBuilder.js +18 -0
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
- package/utils/entity/EntityWriteBatch.d.ts +23 -0
- package/utils/entity/EntityWriteBatch.js +44 -0
- package/utils/entity/EntityWriteBatch.js.map +1 -0
- package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
- package/utils/entity/EntityWriteBatchBuilder.js +19 -0
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
- package/utils/entity/getEntity.d.ts +4 -0
- package/utils/entity/getEntity.js +11 -0
- package/utils/entity/getEntity.js.map +1 -0
- package/utils/entity/index.d.ts +7 -0
- package/utils/entity/index.js +7 -0
- package/utils/entity/types.d.ts +75 -0
- package/utils/entity/types.js +0 -0
- package/utils/get.d.ts +8 -6
- package/utils/get.js +15 -28
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +13 -0
- package/utils/index.js +13 -0
- package/utils/put.d.ts +12 -0
- package/utils/put.js +10 -0
- package/utils/put.js.map +1 -0
- package/utils/query.d.ts +20 -14
- package/utils/query.js +84 -108
- package/utils/query.js.map +1 -1
- package/utils/scan.d.ts +38 -0
- package/utils/scan.js +56 -0
- package/utils/scan.js.map +1 -0
- package/utils/sort.d.ts +1 -1
- package/utils/sort.js +38 -84
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.d.ts +10 -0
- package/utils/table/Table.js +28 -0
- package/utils/table/Table.js.map +1 -0
- package/utils/table/TableReadBatch.d.ts +19 -0
- package/utils/table/TableReadBatch.js +46 -0
- package/utils/table/TableReadBatch.js.map +1 -0
- package/utils/table/TableWriteBatch.d.ts +21 -0
- package/utils/table/TableWriteBatch.js +52 -0
- package/utils/table/TableWriteBatch.js.map +1 -0
- package/utils/table/index.d.ts +4 -0
- package/utils/table/index.js +4 -0
- package/utils/table/types.d.ts +39 -0
- package/utils/table/types.js +0 -0
- package/BatchProcess.d.ts +0 -47
- package/BatchProcess.js +0 -198
- package/BatchProcess.js.map +0 -1
- package/QueryGenerator.d.ts +0 -21
- package/QueryGenerator.js +0 -78
- package/QueryGenerator.js.map +0 -1
- package/operators/comparison/beginsWith.d.ts +0 -3
- package/operators/comparison/beginsWith.js +0 -24
- package/operators/comparison/beginsWith.js.map +0 -1
- package/operators/comparison/between.d.ts +0 -3
- package/operators/comparison/between.js +0 -30
- package/operators/comparison/between.js.map +0 -1
- package/operators/comparison/eq.d.ts +0 -3
- package/operators/comparison/eq.js +0 -34
- package/operators/comparison/eq.js.map +0 -1
- package/operators/comparison/gt.d.ts +0 -3
- package/operators/comparison/gt.js +0 -24
- package/operators/comparison/gt.js.map +0 -1
- package/operators/comparison/gte.d.ts +0 -3
- package/operators/comparison/gte.js +0 -24
- package/operators/comparison/gte.js.map +0 -1
- package/operators/comparison/lt.d.ts +0 -3
- package/operators/comparison/lt.js +0 -24
- package/operators/comparison/lt.js.map +0 -1
- package/operators/comparison/lte.d.ts +0 -3
- package/operators/comparison/lte.js +0 -24
- package/operators/comparison/lte.js.map +0 -1
- package/operators/index.d.ts +0 -12
- package/operators/index.js +0 -39
- package/operators/index.js.map +0 -1
- package/operators/logical/and.d.ts +0 -3
- package/operators/logical/and.js +0 -63
- package/operators/logical/and.js.map +0 -1
- package/operators/logical/or.d.ts +0 -3
- package/operators/logical/or.js +0 -63
- package/operators/logical/or.js.map +0 -1
- package/plugins/definitions/AttributePlugin.d.ts +0 -20
- package/plugins/definitions/AttributePlugin.js +0 -61
- package/plugins/definitions/AttributePlugin.js.map +0 -1
- package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
- package/plugins/definitions/FieldPathPlugin.js +0 -46
- package/plugins/definitions/FieldPathPlugin.js.map +0 -1
- package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
- package/plugins/definitions/NumberTransformPlugin.js +0 -45
- package/plugins/definitions/NumberTransformPlugin.js.map +0 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +0 -20
- package/plugins/definitions/ValueFilterPlugin.js +0 -49
- package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
- package/plugins/filters/andIn.d.ts +0 -3
- package/plugins/filters/andIn.js +0 -35
- package/plugins/filters/andIn.js.map +0 -1
- package/plugins/filters/between.d.ts +0 -3
- package/plugins/filters/between.js +0 -36
- package/plugins/filters/between.js.map +0 -1
- package/plugins/filters/contains.d.ts +0 -3
- package/plugins/filters/contains.js +0 -32
- package/plugins/filters/contains.js.map +0 -1
- package/plugins/filters/eq.d.ts +0 -3
- package/plugins/filters/eq.js +0 -33
- package/plugins/filters/eq.js.map +0 -1
- package/plugins/filters/fuzzy.d.ts +0 -3
- package/plugins/filters/fuzzy.js +0 -30
- package/plugins/filters/fuzzy.js.map +0 -1
- package/plugins/filters/gt.d.ts +0 -3
- package/plugins/filters/gt.js +0 -20
- package/plugins/filters/gt.js.map +0 -1
- package/plugins/filters/gte.d.ts +0 -3
- package/plugins/filters/gte.js +0 -20
- package/plugins/filters/gte.js.map +0 -1
- package/plugins/filters/in.d.ts +0 -3
- package/plugins/filters/in.js +0 -35
- package/plugins/filters/in.js.map +0 -1
- package/plugins/filters/index.d.ts +0 -2
- package/plugins/filters/index.js +0 -34
- package/plugins/filters/index.js.map +0 -1
- package/plugins/filters/lt.d.ts +0 -3
- package/plugins/filters/lt.js +0 -20
- package/plugins/filters/lt.js.map +0 -1
- package/plugins/filters/lte.d.ts +0 -3
- package/plugins/filters/lte.js +0 -20
- package/plugins/filters/lte.js.map +0 -1
- package/plugins/filters/startsWith.d.ts +0 -3
- package/plugins/filters/startsWith.js +0 -33
- package/plugins/filters/startsWith.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/statements/createKeyConditionExpressionArgs.d.ts +0 -15
- package/statements/createKeyConditionExpressionArgs.js +0 -52
- package/statements/createKeyConditionExpressionArgs.js.map +0 -1
- package/statements/processStatement.d.ts +0 -3
- package/statements/processStatement.js +0 -42
- package/statements/processStatement.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/attributes.d.ts +0 -10
- package/utils/attributes.js +0 -31
- package/utils/attributes.js.map +0 -1
- package/utils/batchRead.d.ts +0 -15
- package/utils/batchRead.js +0 -89
- package/utils/batchRead.js.map +0 -1
- package/utils/batchWrite.d.ts +0 -17
- package/utils/batchWrite.js +0 -30
- package/utils/batchWrite.js.map +0 -1
- package/utils/filter.d.ts +0 -12
- package/utils/filter.js +0 -213
- package/utils/filter.js.map +0 -1
- package/utils/listResponse.d.ts +0 -13
- package/utils/listResponse.js +0 -33
- package/utils/listResponse.js.map +0 -1
- package/utils/table.d.ts +0 -7
- package/utils/table.js +0 -27
- package/utils/table.js.map +0 -1
package/toolbox.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export { Entity, Table } from "dynamodb-toolbox";
|
|
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 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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Entity, Table } from "dynamodb-toolbox";
|
package/types.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
export interface OperatorArgs {
|
|
2
|
-
expression: string;
|
|
3
|
-
attributeNames: Record<string, any>;
|
|
4
|
-
attributeValues: Record<string, any>;
|
|
5
|
-
}
|
|
6
|
-
interface CanProcessArgs {
|
|
7
|
-
key: string;
|
|
8
|
-
value: any;
|
|
9
|
-
args: OperatorArgs;
|
|
10
|
-
}
|
|
11
|
-
interface ProcessArgs {
|
|
12
|
-
key: string;
|
|
13
|
-
value: any;
|
|
14
|
-
args: OperatorArgs;
|
|
15
|
-
processStatement: any;
|
|
16
|
-
}
|
|
17
|
-
export interface Operator {
|
|
18
|
-
canProcess: ({ key }: CanProcessArgs) => boolean;
|
|
19
|
-
process: ({ key, value, args }: ProcessArgs) => void;
|
|
20
|
-
}
|
|
21
1
|
/**
|
|
22
2
|
* We use this definition to search for a value in any given field that was passed.
|
|
23
3
|
* It works as an "OR" condition.
|
|
@@ -53,6 +33,13 @@ export interface QueryKey {
|
|
|
53
33
|
unique?: boolean;
|
|
54
34
|
name: string;
|
|
55
35
|
}
|
|
56
|
-
export
|
|
57
|
-
export
|
|
58
|
-
export {
|
|
36
|
+
export type QueryKeys = QueryKey[];
|
|
37
|
+
export type QuerySort = Record<string, -1 | 1>;
|
|
38
|
+
export type DbItem<TData extends Record<string, any> = Record<string, any>> = {
|
|
39
|
+
PK: string;
|
|
40
|
+
SK: string;
|
|
41
|
+
GSI1_PK: string;
|
|
42
|
+
GSI1_SK: string;
|
|
43
|
+
TYPE: string;
|
|
44
|
+
data: TData;
|
|
45
|
+
};
|
package/types.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TableDef } from "../../toolbox.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
|
+
export interface BatchReadItem {
|
|
4
|
+
Table?: TableDef;
|
|
5
|
+
Key: any;
|
|
6
|
+
}
|
|
7
|
+
export interface BatchReadParams {
|
|
8
|
+
table?: TableDef;
|
|
9
|
+
items: BatchReadItem[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* This helper function is meant to be used to batch read from one table.
|
|
13
|
+
* It will fetch all results, as there is a next() method call built in.
|
|
14
|
+
*/
|
|
15
|
+
export declare const batchReadAll: <T = GenericRecord>(params: BatchReadParams, maxChunk?: number) => Promise<T[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import chunk from "lodash/chunk.js";
|
|
2
|
+
import error from "@webiny/error";
|
|
3
|
+
const MAX_BATCH_ITEMS = 100;
|
|
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;
|
|
9
|
+
};
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
return records;
|
|
26
|
+
};
|
|
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
|
|
31
|
+
});
|
|
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;
|
|
42
|
+
};
|
|
43
|
+
export { batchReadAll };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=batchRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TableDef } from "../../toolbox.js";
|
|
2
|
+
import type { BatchWriteItem, BatchWriteResult } from "./types.js";
|
|
3
|
+
export interface BatchWriteParams {
|
|
4
|
+
table: TableDef | undefined;
|
|
5
|
+
items: BatchWriteItem[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Method is meant for batch writing to a single table.
|
|
9
|
+
* It expects already prepared items for writing.
|
|
10
|
+
* It can either delete or put items
|
|
11
|
+
* The method does not check items before actually sending them into the underlying library.
|
|
12
|
+
*/
|
|
13
|
+
export declare const batchWriteAll: (params: BatchWriteParams, maxChunk?: number) => Promise<BatchWriteResult>;
|
|
@@ -0,0 +1,39 @@
|
|
|
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);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const retry = async (input, results)=>{
|
|
14
|
+
if (!hasUnprocessedItems(input)) return;
|
|
15
|
+
const result = await input.next();
|
|
16
|
+
await retry(result, results);
|
|
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 };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=batchWrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
|
+
export interface BatchWriteResponse {
|
|
4
|
+
next?: () => Promise<BatchWriteResponse>;
|
|
5
|
+
$metadata: {
|
|
6
|
+
httpStatusCode: number;
|
|
7
|
+
requestId: string;
|
|
8
|
+
attempts: number;
|
|
9
|
+
totalRetryDelay: number;
|
|
10
|
+
};
|
|
11
|
+
UnprocessedItems?: {
|
|
12
|
+
[table: string]: WriteRequest[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export type BatchWriteResult = BatchWriteResponse[];
|
|
16
|
+
export interface IDeleteBatchItem {
|
|
17
|
+
PK: string;
|
|
18
|
+
SK: string;
|
|
19
|
+
}
|
|
20
|
+
export type IPutBatchItem<T = GenericRecord> = {
|
|
21
|
+
PK: string;
|
|
22
|
+
SK: string;
|
|
23
|
+
} & T;
|
|
24
|
+
export interface BatchWriteItem {
|
|
25
|
+
[key: string]: WriteRequest;
|
|
26
|
+
}
|
|
27
|
+
export interface IReadBatchItem {
|
|
28
|
+
PK: string;
|
|
29
|
+
SK: string;
|
|
30
|
+
}
|
|
File without changes
|
package/utils/cleanup.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Entity } from "
|
|
2
|
-
export declare function cleanupItem<T>(entity: Entity<any>, item?:
|
|
3
|
-
export declare function cleanupItems<T>(entity: Entity<any>, items:
|
|
1
|
+
import type { Entity } from "../toolbox.js";
|
|
2
|
+
export declare function cleanupItem<T>(entity: Entity<any>, item?: T | null, removeAttributes?: string[]): T | null;
|
|
3
|
+
export declare function cleanupItems<T>(entity: Entity<any>, items: T[], removeAttributes?: string[]): T[];
|
package/utils/cleanup.js
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
const attributesToRemove = [
|
|
2
|
+
"PK",
|
|
3
|
+
"SK",
|
|
4
|
+
"created",
|
|
5
|
+
"_ct",
|
|
6
|
+
"modified",
|
|
7
|
+
"_mt",
|
|
8
|
+
"entity",
|
|
9
|
+
"_et",
|
|
10
|
+
"GSI1_PK",
|
|
11
|
+
"GSI1_SK",
|
|
12
|
+
"GSI2_PK",
|
|
13
|
+
"GSI2_SK",
|
|
14
|
+
"GSI3_PK",
|
|
15
|
+
"GSI3_SK",
|
|
16
|
+
"GSI4_PK",
|
|
17
|
+
"GSI4_SK",
|
|
18
|
+
"GSI5_PK",
|
|
19
|
+
"GSI5_SK",
|
|
20
|
+
"GSI_TENANT",
|
|
21
|
+
"TYPE"
|
|
22
|
+
];
|
|
19
23
|
function cleanupItem(entity, item, removeAttributes = []) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (const key in item) {
|
|
29
|
-
if (item.hasOwnProperty(key) === false) {
|
|
30
|
-
continue;
|
|
24
|
+
if (!item) return null;
|
|
25
|
+
const newItem = {
|
|
26
|
+
...item
|
|
27
|
+
};
|
|
28
|
+
const targets = attributesToRemove.concat(removeAttributes);
|
|
29
|
+
const attributes = entity.schema.attributes;
|
|
30
|
+
for(const key in item)if (false !== item.hasOwnProperty(key)) {
|
|
31
|
+
if (!attributes[key] || false !== targets.includes(key)) delete newItem[key];
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
if (attributes[key] && targets.includes(key) === false) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
delete newItem[key];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return newItem;
|
|
33
|
+
return newItem;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
function cleanupItems(entity, items, removeAttributes = []) {
|
|
44
|
-
|
|
45
|
-
}
|
|
36
|
+
return items.map((item)=>cleanupItem(entity, item, removeAttributes));
|
|
37
|
+
}
|
|
38
|
+
export { cleanupItem, cleanupItems };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=cleanup.js.map
|
package/utils/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/cleanup.js","sources":["../../src/utils/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"],"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","attributes","key","cleanupItems","items"],"mappings":"AAMA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,SAASC,YACZC,MAAmB,EACnBC,IAAe,EACfC,mBAA6B,EAAE;IAE/B,IAAI,CAACD,MACD,OAAO;IAEX,MAAME,UAAU;QACZ,GAAGF,IAAI;IACX;IACA,MAAMG,UAAUN,mBAAmB,MAAM,CAACI;IAC1C,MAAMG,aAAaL,OAAO,MAAM,CAAC,UAAU;IAC3C,IAAK,MAAMM,OAAOL,KACd,IAAIA,AAA6B,UAA7BA,KAAK,cAAc,CAACK,MAGxB;QAAA,IAAID,CAAAA,UAAU,CAACC,IAAI,IAAIF,AAA0B,UAA1BA,QAAQ,QAAQ,CAACE,MAGxC,OAAOH,OAAO,CAACG,IAAI;IADnB;IAGJ,OAAOH;AACX;AAEO,SAASI,aACZP,MAAmB,EACnBQ,KAAU,EACVN,mBAA6B,EAAE;IAE/B,OAAOM,MAAM,GAAG,CAACP,CAAAA,OAAQF,YAAeC,QAAQC,MAAMC;AAC1D"}
|
package/utils/count.d.ts
ADDED
package/utils/count.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const count = async (params)=>{
|
|
2
|
+
const { entity, partitionKey, options = {} } = params;
|
|
3
|
+
const { Count } = await entity.query(partitionKey, {
|
|
4
|
+
...options,
|
|
5
|
+
select: "count"
|
|
6
|
+
});
|
|
7
|
+
return Count || 0;
|
|
8
|
+
};
|
|
9
|
+
export { count };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/count.js","sources":["../../src/utils/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 // @ts-expect-error\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"names":["count","params","entity","partitionKey","options","Count"],"mappings":"AAEO,MAAMA,QAAQ,OAAOC;IACxB,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGH;IAE/C,MAAM,EAAEI,KAAK,EAAE,GAAG,MAAMH,OAAO,KAAK,CAACC,cAAc;QAAE,GAAGC,OAAO;QAAE,QAAQ;IAAQ;IACjF,OAAOC,SAAS;AACpB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AttributeDefinitions } from "../toolbox.js";
|
|
2
|
+
import { type EntityConstructor } from "../utils/entity/index.js";
|
|
3
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
4
|
+
export type IGlobalEntityAttributes<T = undefined> = {
|
|
5
|
+
PK: string;
|
|
6
|
+
SK: string;
|
|
7
|
+
TYPE: string;
|
|
8
|
+
GSI1_PK?: string;
|
|
9
|
+
GSI1_SK?: string;
|
|
10
|
+
GSI2_PK?: string;
|
|
11
|
+
GSI2_SK?: string;
|
|
12
|
+
expiresAt?: number | null;
|
|
13
|
+
} & (T extends undefined ? {
|
|
14
|
+
data?: undefined;
|
|
15
|
+
} : {
|
|
16
|
+
data: T;
|
|
17
|
+
});
|
|
18
|
+
export declare const globalEntityAttributes: AttributeDefinitions;
|
|
19
|
+
export declare const createGlobalEntity: <T extends GenericRecord = GenericRecord>(params: Omit<EntityConstructor, "attributes"> & Partial<Pick<EntityConstructor, "attributes">>) => import("~/utils/entity/index.js").IEntity<IGlobalEntityAttributes<T>>;
|
|
20
|
+
export type IStandardEntityAttributes<T = undefined> = {
|
|
21
|
+
PK: string;
|
|
22
|
+
SK: string;
|
|
23
|
+
GSI_TENANT: string;
|
|
24
|
+
TYPE: string;
|
|
25
|
+
GSI1_PK?: string;
|
|
26
|
+
GSI1_SK?: string;
|
|
27
|
+
GSI2_PK?: string;
|
|
28
|
+
GSI2_SK?: string;
|
|
29
|
+
expiresAt?: number | null;
|
|
30
|
+
} & (T extends undefined ? {
|
|
31
|
+
data?: undefined;
|
|
32
|
+
} : {
|
|
33
|
+
data: T;
|
|
34
|
+
});
|
|
35
|
+
export declare const standardEntityAttributes: AttributeDefinitions;
|
|
36
|
+
export declare const createStandardEntity: <T extends GenericRecord = GenericRecord>(params: Omit<EntityConstructor, "attributes"> & Partial<Pick<EntityConstructor, "attributes">>) => import("~/utils/entity/index.js").IEntity<IStandardEntityAttributes<T>>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createEntity } from "./entity/index.js";
|
|
2
|
+
const globalEntityAttributes = {
|
|
3
|
+
PK: {
|
|
4
|
+
partitionKey: true
|
|
5
|
+
},
|
|
6
|
+
SK: {
|
|
7
|
+
sortKey: true
|
|
8
|
+
},
|
|
9
|
+
GSI1_PK: {
|
|
10
|
+
type: "string"
|
|
11
|
+
},
|
|
12
|
+
GSI1_SK: {
|
|
13
|
+
type: "string"
|
|
14
|
+
},
|
|
15
|
+
GSI2_PK: {
|
|
16
|
+
type: "string"
|
|
17
|
+
},
|
|
18
|
+
GSI2_SK: {
|
|
19
|
+
type: "string"
|
|
20
|
+
},
|
|
21
|
+
TYPE: {
|
|
22
|
+
type: "string",
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
data: {
|
|
26
|
+
type: "map"
|
|
27
|
+
},
|
|
28
|
+
expiresAt: {
|
|
29
|
+
type: "number"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createGlobalEntity = (params)=>createEntity({
|
|
33
|
+
...params,
|
|
34
|
+
attributes: {
|
|
35
|
+
...globalEntityAttributes,
|
|
36
|
+
...params.attributes
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const standardEntityAttributes = {
|
|
40
|
+
PK: {
|
|
41
|
+
partitionKey: true
|
|
42
|
+
},
|
|
43
|
+
SK: {
|
|
44
|
+
sortKey: true
|
|
45
|
+
},
|
|
46
|
+
GSI_TENANT: {
|
|
47
|
+
type: "string",
|
|
48
|
+
required: true
|
|
49
|
+
},
|
|
50
|
+
GSI1_PK: {
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
GSI1_SK: {
|
|
54
|
+
type: "string"
|
|
55
|
+
},
|
|
56
|
+
GSI2_PK: {
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
GSI2_SK: {
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
TYPE: {
|
|
63
|
+
type: "string",
|
|
64
|
+
required: true
|
|
65
|
+
},
|
|
66
|
+
data: {
|
|
67
|
+
type: "map"
|
|
68
|
+
},
|
|
69
|
+
expiresAt: {
|
|
70
|
+
type: "number"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const createStandardEntity = (params)=>createEntity({
|
|
74
|
+
...params,
|
|
75
|
+
attributes: {
|
|
76
|
+
...standardEntityAttributes,
|
|
77
|
+
...params.attributes
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export { createGlobalEntity, createStandardEntity, globalEntityAttributes, standardEntityAttributes };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=createEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/createEntity.js","sources":["../../src/utils/createEntity.ts"],"sourcesContent":["import type { AttributeDefinitions } from \"~/toolbox.js\";\nimport { createEntity, type EntityConstructor } from \"~/utils/entity/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IGlobalEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const globalEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createGlobalEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IGlobalEntityAttributes<T>>({\n ...params,\n attributes: {\n ...globalEntityAttributes,\n ...params.attributes\n }\n });\n};\n\nexport type IStandardEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const standardEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI_TENANT: {\n type: \"string\",\n required: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createStandardEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IStandardEntityAttributes<T>>({\n ...params,\n attributes: {\n ...standardEntityAttributes,\n ...params.attributes\n }\n });\n};\n"],"names":["globalEntityAttributes","createGlobalEntity","params","createEntity","standardEntityAttributes","createStandardEntity"],"mappings":";AAeO,MAAMA,yBAA+C;IACxD,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,qBAAqB,CAC9BC,SAEOC,aAAyC;QAC5C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGF,sBAAsB;YACzB,GAAGE,OAAO,UAAU;QACxB;IACJ;AAeG,MAAME,2BAAiD;IAC1D,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,YAAY;QACR,MAAM;QACN,UAAU;IACd;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,uBAAuB,CAChCH,SAEOC,aAA2C;QAC9C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGE,wBAAwB;YAC3B,GAAGF,OAAO,UAAU;QACxB;IACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITable } from "../utils/table/index.js";
|
|
2
|
+
import type { TableConstructor } from "../toolbox.js";
|
|
3
|
+
export interface ICreateTableParamsIndexDefinition {
|
|
4
|
+
partitionKey: string;
|
|
5
|
+
sortKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export type ICreateTableParams = Partial<Omit<TableConstructor<string, string, string>, "DocumentClient">> & {
|
|
8
|
+
name: string;
|
|
9
|
+
documentClient: Pick<TableConstructor<string, string, string>, "DocumentClient">["DocumentClient"];
|
|
10
|
+
};
|
|
11
|
+
export declare const createTable: (params: ICreateTableParams) => ITable<string, "PK", "SK">;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Table } from "./table/index.js";
|
|
2
|
+
const createTable = (params)=>{
|
|
3
|
+
const { documentClient, indexes = {}, ...rest } = params;
|
|
4
|
+
return new Table({
|
|
5
|
+
partitionKey: "PK",
|
|
6
|
+
sortKey: "SK",
|
|
7
|
+
DocumentClient: documentClient,
|
|
8
|
+
indexes: {
|
|
9
|
+
GSI_TENANT: {
|
|
10
|
+
partitionKey: "GSI_TENANT"
|
|
11
|
+
},
|
|
12
|
+
GSI1: {
|
|
13
|
+
partitionKey: "GSI1_PK",
|
|
14
|
+
sortKey: "GSI1_SK"
|
|
15
|
+
},
|
|
16
|
+
GSI2: {
|
|
17
|
+
partitionKey: "GSI2_PK",
|
|
18
|
+
sortKey: "GSI2_SK"
|
|
19
|
+
},
|
|
20
|
+
...indexes
|
|
21
|
+
},
|
|
22
|
+
autoExecute: true,
|
|
23
|
+
autoParse: true,
|
|
24
|
+
...rest
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export { createTable };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=createTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/createTable.js","sources":["../../src/utils/createTable.ts"],"sourcesContent":["import type { ITable } from \"~/utils/table/index.js\";\nimport { Table } from \"~/utils/table/index.js\";\nimport type { TableConstructor } from \"~/toolbox.js\";\n\nexport interface ICreateTableParamsIndexDefinition {\n partitionKey: string;\n sortKey?: string;\n}\n\n// export interface ICreateTableParams {\n// name?: string;\n// documentClient: DynamoDBDocument;\n// indexes?: GenericRecord<string, ICreateTableParamsIndexDefinition>;\n// }\n\nexport type ICreateTableParams = Partial<\n Omit<TableConstructor<string, string, string>, \"DocumentClient\">\n> & {\n name: string;\n documentClient: Pick<\n TableConstructor<string, string, string>,\n \"DocumentClient\"\n >[\"DocumentClient\"];\n};\n\nexport const createTable = (params: ICreateTableParams): ITable<string, \"PK\", \"SK\"> => {\n const { documentClient, indexes = {}, ...rest } = params;\n return new Table({\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient,\n indexes: {\n GSI_TENANT: {\n partitionKey: \"GSI_TENANT\"\n },\n GSI1: {\n partitionKey: \"GSI1_PK\",\n sortKey: \"GSI1_SK\"\n },\n GSI2: {\n partitionKey: \"GSI2_PK\",\n sortKey: \"GSI2_SK\"\n },\n ...indexes\n },\n autoExecute: true,\n autoParse: true,\n ...rest\n });\n};\n"],"names":["createTable","params","documentClient","indexes","rest","Table"],"mappings":";AAyBO,MAAMA,cAAc,CAACC;IACxB,MAAM,EAAEC,cAAc,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGC,MAAM,GAAGH;IAClD,OAAO,IAAII,MAAM;QACb,cAAc;QACd,SAAS;QACT,gBAAgBH;QAChB,SAAS;YACL,YAAY;gBACR,cAAc;YAClB;YACA,MAAM;gBACF,cAAc;gBACd,SAAS;YACb;YACA,MAAM;gBACF,cAAc;gBACd,SAAS;YACb;YACA,GAAGC,OAAO;QACd;QACA,aAAa;QACb,WAAW;QACX,GAAGC,IAAI;IACX;AACJ"}
|
package/utils/cursor.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.encodeCursor = exports.decodeCursor = void 0;
|
|
7
|
-
|
|
8
|
-
const encodeCursor = cursor => {
|
|
9
|
-
if (!cursor) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return Buffer.from(JSON.stringify(cursor)).toString("base64");
|
|
1
|
+
const encodeCursor = (cursor)=>{
|
|
2
|
+
if (!cursor) return null;
|
|
3
|
+
return Buffer.from(JSON.stringify(cursor)).toString("base64");
|
|
14
4
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const decodeCursor = cursor => {
|
|
19
|
-
if (!cursor) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
|
|
5
|
+
const decodeCursor = (cursor)=>{
|
|
6
|
+
if (!cursor) return null;
|
|
7
|
+
return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
|
|
24
8
|
};
|
|
9
|
+
export { decodeCursor, encodeCursor };
|
|
25
10
|
|
|
26
|
-
|
|
11
|
+
//# sourceMappingURL=cursor.js.map
|
package/utils/cursor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/cursor.js","sources":["../../src/utils/cursor.ts"],"sourcesContent":["export const encodeCursor = (cursor?: any): string | null => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodeCursor = (cursor?: string | null): string | null => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n"],"names":["encodeCursor","cursor","Buffer","JSON","decodeCursor"],"mappings":"AAAO,MAAMA,eAAe,CAACC;IACzB,IAAI,CAACA,QACD,OAAO;IAGX,OAAOC,OAAO,IAAI,CAACC,KAAK,SAAS,CAACF,SAAS,QAAQ,CAAC;AACxD;AAEO,MAAMG,eAAe,CAACH;IACzB,IAAI,CAACA,QACD,OAAO;IAGX,OAAOE,KAAK,KAAK,CAACD,OAAO,IAAI,CAACD,QAAQ,UAAU,QAAQ,CAAC;AAC7D"}
|