@webiny/db-dynamodb 5.23.0 → 5.24.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BatchProcess.d.ts +23 -11
- package/DynamoDbDriver.d.ts +16 -11
- package/QueryGenerator.d.ts +15 -13
- package/QueryGenerator.js +13 -10
- package/package.json +10 -9
- package/statements/createKeyConditionExpressionArgs.d.ts +12 -9
- package/statements/processStatement.d.ts +3 -4
- package/statements/processStatement.js +7 -4
- package/types.d.ts +37 -8
- package/utils/cursor.d.ts +2 -2
- package/utils/filter.js +3 -0
- package/utils/listResponse.js +6 -1
package/BatchProcess.d.ts
CHANGED
|
@@ -2,18 +2,30 @@ import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
|
2
2
|
import { Batch } from "@webiny/db";
|
|
3
3
|
declare type BatchType = "batchWrite" | "batchGet";
|
|
4
4
|
export declare type AddBatchOperationResponse = () => any | null;
|
|
5
|
+
interface RejectBuildCallable {
|
|
6
|
+
({ message }: {
|
|
7
|
+
message: string;
|
|
8
|
+
}): void;
|
|
9
|
+
}
|
|
10
|
+
interface RejectExecutionCallable {
|
|
11
|
+
({ message }: {
|
|
12
|
+
message: string;
|
|
13
|
+
}): void;
|
|
14
|
+
}
|
|
15
|
+
interface AddBatchOperationArgs {
|
|
16
|
+
/**
|
|
17
|
+
* TODO: determine correct type.
|
|
18
|
+
*/
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
5
21
|
declare class BatchProcess {
|
|
6
22
|
documentClient: DocumentClient;
|
|
7
23
|
batch: Batch;
|
|
8
24
|
resolveBuild: () => void;
|
|
9
|
-
rejectBuild:
|
|
10
|
-
message: any;
|
|
11
|
-
}) => void;
|
|
25
|
+
rejectBuild: RejectBuildCallable;
|
|
12
26
|
queryBuild: Promise<void>;
|
|
13
27
|
resolveExecution: () => void;
|
|
14
|
-
rejectExecution:
|
|
15
|
-
message: any;
|
|
16
|
-
}) => void;
|
|
28
|
+
rejectExecution: RejectExecutionCallable;
|
|
17
29
|
queryExecution: Promise<void>;
|
|
18
30
|
operations: [Record<string, any>, Record<string, any>][];
|
|
19
31
|
batchType: BatchType;
|
|
@@ -22,11 +34,11 @@ declare class BatchProcess {
|
|
|
22
34
|
constructor(batch: Batch, documentClient: DocumentClient);
|
|
23
35
|
waitStartExecution(): Promise<void>;
|
|
24
36
|
waitExecution(): Promise<void>;
|
|
25
|
-
addBatchOperation(type: BatchType, args:
|
|
26
|
-
addBatchWrite(args:
|
|
27
|
-
addBatchDelete(args:
|
|
28
|
-
addBatchGet(args:
|
|
37
|
+
addBatchOperation(type: BatchType, args: AddBatchOperationArgs, meta?: {}): AddBatchOperationResponse;
|
|
38
|
+
addBatchWrite(args: AddBatchOperationArgs): AddBatchOperationResponse;
|
|
39
|
+
addBatchDelete(args: AddBatchOperationArgs): AddBatchOperationResponse;
|
|
40
|
+
addBatchGet(args: AddBatchOperationArgs): AddBatchOperationResponse;
|
|
29
41
|
allOperationsAdded(): boolean;
|
|
30
|
-
startExecution(): import("aws-sdk/lib/request").Request<DocumentClient.
|
|
42
|
+
startExecution(): import("aws-sdk/lib/request").Request<DocumentClient.BatchWriteItemOutput, import("aws-sdk/lib/error").AWSError> | import("aws-sdk/lib/request").Request<DocumentClient.BatchGetItemOutput, import("aws-sdk/lib/error").AWSError>;
|
|
31
43
|
}
|
|
32
44
|
export default BatchProcess;
|
package/DynamoDbDriver.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
2
2
|
import BatchProcess from "./BatchProcess";
|
|
3
|
-
import { DbDriver, Args, Result } from "@webiny/db";
|
|
3
|
+
import { DbDriver, Args, Result, ArgsBatch } from "@webiny/db";
|
|
4
4
|
declare type ConstructorArgs = {
|
|
5
5
|
documentClient?: DocumentClient;
|
|
6
6
|
};
|
|
7
|
+
interface ReadLogsParams {
|
|
8
|
+
table: string;
|
|
9
|
+
}
|
|
10
|
+
interface CreateLogParams {
|
|
11
|
+
id: string;
|
|
12
|
+
operation: string;
|
|
13
|
+
/**
|
|
14
|
+
* TODO: determine the data type.
|
|
15
|
+
*/
|
|
16
|
+
data: any;
|
|
17
|
+
table: string;
|
|
18
|
+
}
|
|
7
19
|
declare class DynamoDbDriver implements DbDriver {
|
|
8
20
|
batchProcesses: Record<string, BatchProcess>;
|
|
9
21
|
documentClient: DocumentClient;
|
|
@@ -13,15 +25,8 @@ declare class DynamoDbDriver implements DbDriver {
|
|
|
13
25
|
update({ query, data, table, meta, __batch: batch }: Args): Promise<Result>;
|
|
14
26
|
delete({ query, table, meta, __batch: batch }: Args): Promise<Result>;
|
|
15
27
|
read<T>({ table, query, sort, limit, keys, meta, __batch: batch }: Args): Promise<Result<T[]>>;
|
|
16
|
-
createLog({ id, operation, data, table }:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
data: any;
|
|
20
|
-
table: any;
|
|
21
|
-
}): Promise<Result>;
|
|
22
|
-
readLogs<T>({ table }: {
|
|
23
|
-
table: any;
|
|
24
|
-
}): Promise<Result<T[]>>;
|
|
25
|
-
getBatchProcess(__batch: any): BatchProcess;
|
|
28
|
+
createLog({ id, operation, data, table }: CreateLogParams): Promise<Result>;
|
|
29
|
+
readLogs<T>({ table }: ReadLogsParams): Promise<Result<T[]>>;
|
|
30
|
+
getBatchProcess(__batch: ArgsBatch): BatchProcess;
|
|
26
31
|
}
|
|
27
32
|
export default DynamoDbDriver;
|
package/QueryGenerator.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
import { Query, QueryKey, QueryKeys, QuerySort } from "./types";
|
|
2
|
+
interface GenerateParams {
|
|
3
|
+
query: Query;
|
|
4
|
+
keys: QueryKeys;
|
|
5
|
+
sort: QuerySort;
|
|
6
|
+
limit: number;
|
|
7
|
+
tableName: string;
|
|
8
|
+
}
|
|
1
9
|
declare class QueryGenerator {
|
|
2
|
-
generate(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
sort: any;
|
|
6
|
-
limit: any;
|
|
7
|
-
tableName: any;
|
|
8
|
-
}): {
|
|
9
|
-
TableName: any;
|
|
10
|
-
Limit: any;
|
|
10
|
+
generate(params: GenerateParams): {
|
|
11
|
+
TableName: string;
|
|
12
|
+
Limit: number;
|
|
11
13
|
KeyConditionExpression: string;
|
|
12
|
-
ExpressionAttributeNames:
|
|
13
|
-
ExpressionAttributeValues:
|
|
14
|
+
ExpressionAttributeNames: Record<string, any>;
|
|
15
|
+
ExpressionAttributeValues: Record<string, any>;
|
|
14
16
|
ScanIndexForward: boolean;
|
|
15
|
-
IndexName:
|
|
17
|
+
IndexName: string;
|
|
16
18
|
};
|
|
17
|
-
findQueryKey(query?:
|
|
19
|
+
findQueryKey(query?: Query, keys?: QueryKeys): QueryKey | null;
|
|
18
20
|
}
|
|
19
21
|
export default QueryGenerator;
|
package/QueryGenerator.js
CHANGED
|
@@ -16,14 +16,15 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
16
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
17
|
|
|
18
18
|
class QueryGenerator {
|
|
19
|
-
generate({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// 1. Which key can we use in this query operation?
|
|
19
|
+
generate(params) {
|
|
20
|
+
const {
|
|
21
|
+
query,
|
|
22
|
+
keys,
|
|
23
|
+
sort,
|
|
24
|
+
limit,
|
|
25
|
+
tableName
|
|
26
|
+
} = params; // 1. Which key can we use in this query operation?
|
|
27
|
+
|
|
27
28
|
const key = this.findQueryKey(query, keys);
|
|
28
29
|
|
|
29
30
|
if (!key) {
|
|
@@ -31,8 +32,8 @@ class QueryGenerator {
|
|
|
31
32
|
} // 2. Now that we know the key, let's separate the key attributes from the rest.
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
const keyAttributesValues = {}
|
|
35
|
-
|
|
35
|
+
const keyAttributesValues = {};
|
|
36
|
+
const nonKeyAttributesValues = {};
|
|
36
37
|
|
|
37
38
|
for (const queryKey in query) {
|
|
38
39
|
if (key.fields.find(item => item.name === queryKey)) {
|
|
@@ -71,6 +72,8 @@ class QueryGenerator {
|
|
|
71
72
|
return key;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
|
|
76
|
+
return null;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.24.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/db": "5.
|
|
14
|
-
"@webiny/error": "5.
|
|
15
|
-
"@webiny/handler": "5.
|
|
16
|
-
"@webiny/handler-db": "5.
|
|
17
|
-
"@webiny/plugins": "5.
|
|
13
|
+
"@webiny/db": "5.24.0-beta.0",
|
|
14
|
+
"@webiny/error": "5.24.0-beta.0",
|
|
15
|
+
"@webiny/handler": "5.24.0-beta.0",
|
|
16
|
+
"@webiny/handler-db": "5.24.0-beta.0",
|
|
17
|
+
"@webiny/plugins": "5.24.0-beta.0",
|
|
18
18
|
"date-fns": "2.28.0",
|
|
19
19
|
"dot-prop": "6.0.1",
|
|
20
20
|
"fuse.js": "6.5.3",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.16.0",
|
|
26
26
|
"@babel/core": "^7.16.0",
|
|
27
|
-
"@
|
|
28
|
-
"@webiny/
|
|
27
|
+
"@types/is-number": "^7.0.2",
|
|
28
|
+
"@webiny/cli": "^5.24.0-beta.0",
|
|
29
|
+
"@webiny/project-utils": "^5.24.0-beta.0",
|
|
29
30
|
"dynamodb-toolbox": "^0.3.4",
|
|
30
31
|
"jest": "^26.6.3",
|
|
31
32
|
"jest-dynalite": "^3.2.0",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"build": "yarn webiny run build",
|
|
42
43
|
"watch": "yarn webiny run watch"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "05b90b92bbaf2ef3adf275d008c4641580cf5f42"
|
|
45
46
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
sort: any;
|
|
4
|
-
key: any;
|
|
5
|
-
}) => {
|
|
1
|
+
import { Query, QueryKey, QuerySort } from "../types";
|
|
2
|
+
interface Output {
|
|
6
3
|
KeyConditionExpression: string;
|
|
7
|
-
ExpressionAttributeNames:
|
|
8
|
-
ExpressionAttributeValues:
|
|
4
|
+
ExpressionAttributeNames: Record<string, any>;
|
|
5
|
+
ExpressionAttributeValues: Record<string, any>;
|
|
9
6
|
ScanIndexForward: boolean;
|
|
10
|
-
IndexName:
|
|
11
|
-
}
|
|
7
|
+
IndexName: string;
|
|
8
|
+
}
|
|
9
|
+
interface Params {
|
|
10
|
+
query: Query;
|
|
11
|
+
sort: QuerySort;
|
|
12
|
+
key: QueryKey;
|
|
13
|
+
}
|
|
14
|
+
declare const _default: ({ query, sort, key }: Params) => Output;
|
|
12
15
|
export default _default;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}): void;
|
|
1
|
+
import { ProcessStatementCallable } from "../types";
|
|
2
|
+
declare const processStatement: ProcessStatementCallable;
|
|
3
|
+
export default processStatement;
|
|
@@ -5,14 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = void 0;
|
|
9
9
|
|
|
10
10
|
var _operators = _interopRequireDefault(require("./../operators"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const processStatement = ({
|
|
13
13
|
args,
|
|
14
14
|
query
|
|
15
|
-
}) {
|
|
15
|
+
}) => {
|
|
16
16
|
outerLoop: for (const [key, value] of Object.entries(query)) {
|
|
17
17
|
const operators = Object.values(_operators.default);
|
|
18
18
|
|
|
@@ -36,4 +36,7 @@ function processStatement({
|
|
|
36
36
|
|
|
37
37
|
throw new Error(`Invalid operator {${key} : ${value}}.`);
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var _default = processStatement;
|
|
42
|
+
exports.default = _default;
|
package/types.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface OperatorArgs {
|
|
2
2
|
expression: string;
|
|
3
3
|
attributeNames: Record<string, any>;
|
|
4
4
|
attributeValues: Record<string, any>;
|
|
5
|
-
}
|
|
6
|
-
|
|
5
|
+
}
|
|
6
|
+
interface CanProcessArgs {
|
|
7
7
|
key: string;
|
|
8
8
|
value: any;
|
|
9
9
|
args: OperatorArgs;
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
}
|
|
11
|
+
interface ProcessArgs {
|
|
12
12
|
key: string;
|
|
13
13
|
value: any;
|
|
14
14
|
args: OperatorArgs;
|
|
15
15
|
processStatement: any;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
16
|
+
}
|
|
17
|
+
export interface Operator {
|
|
18
18
|
canProcess: ({ key }: CanProcessArgs) => boolean;
|
|
19
19
|
process: ({ key, value, args }: ProcessArgs) => void;
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
/**
|
|
22
22
|
* We use this definition to search for a value in any given field that was passed.
|
|
23
23
|
* It works as an "OR" condition.
|
|
@@ -26,4 +26,33 @@ export interface DynamoDbContainsFilter {
|
|
|
26
26
|
fields: string[];
|
|
27
27
|
value: string;
|
|
28
28
|
}
|
|
29
|
+
export interface ProcessStatementArgsParam {
|
|
30
|
+
expression: string;
|
|
31
|
+
attributeNames: Record<string, any>;
|
|
32
|
+
attributeValues: Record<string, any>;
|
|
33
|
+
}
|
|
34
|
+
export interface ProcessStatementQueryParam {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
export interface ProcessStatementParams {
|
|
38
|
+
args: ProcessStatementArgsParam;
|
|
39
|
+
query: ProcessStatementQueryParam;
|
|
40
|
+
}
|
|
41
|
+
export interface ProcessStatementCallable {
|
|
42
|
+
(params: ProcessStatementParams): void;
|
|
43
|
+
}
|
|
44
|
+
export interface Query {
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
}
|
|
47
|
+
export interface QueryKeyField {
|
|
48
|
+
name: string;
|
|
49
|
+
}
|
|
50
|
+
export interface QueryKey {
|
|
51
|
+
fields: QueryKeyField[];
|
|
52
|
+
primary?: boolean;
|
|
53
|
+
unique?: boolean;
|
|
54
|
+
name: string;
|
|
55
|
+
}
|
|
56
|
+
export declare type QueryKeys = QueryKey[];
|
|
57
|
+
export declare type QuerySort = Record<string, -1 | 1>;
|
|
29
58
|
export {};
|
package/utils/cursor.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const encodeCursor: (cursor?: any) => string;
|
|
2
|
-
export declare const decodeCursor: (cursor?: string) =>
|
|
1
|
+
export declare const encodeCursor: (cursor?: any) => string | null;
|
|
2
|
+
export declare const decodeCursor: (cursor?: string) => string | null;
|
package/utils/filter.js
CHANGED
|
@@ -15,6 +15,9 @@ var _ValueFilterPlugin = require("../plugins/definitions/ValueFilterPlugin");
|
|
|
15
15
|
|
|
16
16
|
const getMappedPlugins = params => {
|
|
17
17
|
return params.plugins.byType(params.type).reduce((plugins, plugin) => {
|
|
18
|
+
/**
|
|
19
|
+
* We expect op to be a string, that is why we cast.
|
|
20
|
+
*/
|
|
18
21
|
const op = plugin[params.property];
|
|
19
22
|
plugins[op] = plugin;
|
|
20
23
|
return plugins;
|
package/utils/listResponse.js
CHANGED
|
@@ -14,7 +14,12 @@ const createListResponse = params => {
|
|
|
14
14
|
totalCount,
|
|
15
15
|
limit
|
|
16
16
|
} = params;
|
|
17
|
-
|
|
17
|
+
let start = Number((0, _cursor.decodeCursor)(after));
|
|
18
|
+
|
|
19
|
+
if (isNaN(start) === true) {
|
|
20
|
+
start = 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
const hasMoreItems = totalCount > start + limit;
|
|
19
24
|
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
20
25
|
const items = end ? initialItems.slice(start, end) : initialItems;
|