@webiny/db-dynamodb 0.0.0-mt-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BatchProcess.d.ts +31 -0
- package/BatchProcess.js +196 -0
- package/DynamoDbDriver.d.ts +27 -0
- package/DynamoDbDriver.js +272 -0
- package/LICENSE +21 -0
- package/QueryGenerator.d.ts +19 -0
- package/QueryGenerator.js +79 -0
- package/README.md +67 -0
- package/index.d.ts +2 -0
- package/index.js +15 -0
- package/operators/comparison/beginsWith.d.ts +3 -0
- package/operators/comparison/beginsWith.js +24 -0
- package/operators/comparison/between.d.ts +3 -0
- package/operators/comparison/between.js +30 -0
- package/operators/comparison/eq.d.ts +3 -0
- package/operators/comparison/eq.js +34 -0
- package/operators/comparison/gt.d.ts +3 -0
- package/operators/comparison/gt.js +24 -0
- package/operators/comparison/gte.d.ts +3 -0
- package/operators/comparison/gte.js +24 -0
- package/operators/comparison/lt.d.ts +3 -0
- package/operators/comparison/lt.js +24 -0
- package/operators/comparison/lte.d.ts +3 -0
- package/operators/comparison/lte.js +24 -0
- package/operators/index.d.ts +12 -0
- package/operators/index.js +39 -0
- package/operators/logical/and.d.ts +3 -0
- package/operators/logical/and.js +63 -0
- package/operators/logical/or.d.ts +3 -0
- package/operators/logical/or.js +63 -0
- package/package.json +45 -0
- package/plugins/definitions/AttributePlugin.d.ts +20 -0
- package/plugins/definitions/AttributePlugin.js +61 -0
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +4 -0
- package/plugins/definitions/DateTimeTransformPlugin.js +54 -0
- package/plugins/definitions/FieldPathPlugin.d.ts +22 -0
- package/plugins/definitions/FieldPathPlugin.js +48 -0
- package/plugins/definitions/FieldPlugin.d.ts +34 -0
- package/plugins/definitions/FieldPlugin.js +73 -0
- package/plugins/definitions/NumberTransformPlugin.d.ts +4 -0
- package/plugins/definitions/NumberTransformPlugin.js +49 -0
- package/plugins/definitions/TimeTransformPlugin.d.ts +4 -0
- package/plugins/definitions/TimeTransformPlugin.js +65 -0
- package/plugins/definitions/ValueFilterPlugin.d.ts +20 -0
- package/plugins/definitions/ValueFilterPlugin.js +49 -0
- package/plugins/definitions/ValueTransformPlugin.d.ts +22 -0
- package/plugins/definitions/ValueTransformPlugin.js +52 -0
- package/plugins/definitions/assignFields.d.ts +1 -0
- package/plugins/definitions/assignFields.js +37 -0
- package/plugins/filters/andIn.d.ts +3 -0
- package/plugins/filters/andIn.js +35 -0
- package/plugins/filters/between.d.ts +3 -0
- package/plugins/filters/between.js +36 -0
- package/plugins/filters/contains.d.ts +3 -0
- package/plugins/filters/contains.js +32 -0
- package/plugins/filters/eq.d.ts +3 -0
- package/plugins/filters/eq.js +20 -0
- package/plugins/filters/fuzzy.d.ts +3 -0
- package/plugins/filters/fuzzy.js +30 -0
- package/plugins/filters/gt.d.ts +3 -0
- package/plugins/filters/gt.js +20 -0
- package/plugins/filters/gte.d.ts +3 -0
- package/plugins/filters/gte.js +20 -0
- package/plugins/filters/in.d.ts +3 -0
- package/plugins/filters/in.js +35 -0
- package/plugins/filters/index.d.ts +2 -0
- package/plugins/filters/index.js +32 -0
- package/plugins/filters/lt.d.ts +3 -0
- package/plugins/filters/lt.js +20 -0
- package/plugins/filters/lte.d.ts +3 -0
- package/plugins/filters/lte.js +20 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +19 -0
- package/statements/createKeyConditionExpressionArgs.d.ts +12 -0
- package/statements/createKeyConditionExpressionArgs.js +48 -0
- package/statements/processStatement.d.ts +4 -0
- package/statements/processStatement.js +39 -0
- package/types.d.ts +29 -0
- package/types.js +5 -0
- package/utils/attributes.d.ts +10 -0
- package/utils/attributes.js +35 -0
- package/utils/batchRead.d.ts +15 -0
- package/utils/batchRead.js +58 -0
- package/utils/batchWrite.d.ts +17 -0
- package/utils/batchWrite.js +30 -0
- package/utils/cleanup.d.ts +3 -0
- package/utils/cleanup.js +53 -0
- package/utils/cursor.d.ts +2 -0
- package/utils/cursor.js +26 -0
- package/utils/documentClient.d.ts +8 -0
- package/utils/documentClient.js +33 -0
- package/utils/filter.d.ts +12 -0
- package/utils/filter.js +212 -0
- package/utils/get.d.ts +17 -0
- package/utils/get.js +30 -0
- package/utils/listResponse.d.ts +13 -0
- package/utils/listResponse.js +30 -0
- package/utils/query.d.ts +33 -0
- package/utils/query.js +127 -0
- package/utils/sort.d.ts +17 -0
- package/utils/sort.js +93 -0
- package/utils/table.d.ts +7 -0
- package/utils/table.js +27 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DateTimeTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _dateFns = require("date-fns");
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
const transformDateTime = params => {
|
|
23
|
+
const {
|
|
24
|
+
value
|
|
25
|
+
} = params;
|
|
26
|
+
|
|
27
|
+
if (value && typeof value.getTime === "function") {
|
|
28
|
+
/**
|
|
29
|
+
* In this case we assume this is a date object and we just get the time.
|
|
30
|
+
*/
|
|
31
|
+
return value.getTime();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const parsedDateTime = (0, _dateFns.parseISO)(value).getTime();
|
|
35
|
+
|
|
36
|
+
if (isNaN(parsedDateTime) === false) {
|
|
37
|
+
return parsedDateTime;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw new _error.default("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
|
|
41
|
+
value
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
class DateTimeTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
|
|
46
|
+
constructor(params) {
|
|
47
|
+
super(_objectSpread({
|
|
48
|
+
transform: transformDateTime
|
|
49
|
+
}, params));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.DateTimeTransformPlugin = DateTimeTransformPlugin;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface CreatePath {
|
|
3
|
+
(field: string): string;
|
|
4
|
+
}
|
|
5
|
+
export interface Params {
|
|
6
|
+
/**
|
|
7
|
+
* Which field(s) is this plugin for.
|
|
8
|
+
*/
|
|
9
|
+
fields: string | string[];
|
|
10
|
+
/**
|
|
11
|
+
* Create a path for given field.
|
|
12
|
+
* Field is passed because it can be a multi-field plugin.
|
|
13
|
+
*/
|
|
14
|
+
createPath: CreatePath;
|
|
15
|
+
}
|
|
16
|
+
export declare class FieldPathPlugin extends Plugin {
|
|
17
|
+
static readonly type = "dynamodb.value.path";
|
|
18
|
+
private readonly _params;
|
|
19
|
+
constructor(params: Params);
|
|
20
|
+
canCreate(field: string): boolean;
|
|
21
|
+
createPath(field: string): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FieldPathPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _assignFields = require("./assignFields");
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
class FieldPathPlugin extends _plugins.Plugin {
|
|
23
|
+
constructor(params) {
|
|
24
|
+
super();
|
|
25
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
26
|
+
this._params = _objectSpread(_objectSpread({}, params), {}, {
|
|
27
|
+
fields: (0, _assignFields.assignFields)(params.fields)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canCreate(field) {
|
|
32
|
+
return this._params.fields.includes(field);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
createPath(field) {
|
|
36
|
+
if (!this._params.createPath) {
|
|
37
|
+
throw new _error.default(`Missing "createPath" in the plugin.`, "TRANSFORM_ERROR", {
|
|
38
|
+
fields: this._params.fields
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this._params.createPath(field);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.FieldPathPlugin = FieldPathPlugin;
|
|
48
|
+
(0, _defineProperty2.default)(FieldPathPlugin, "type", "dynamodb.value.path");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
|
|
3
|
+
export declare type FieldType = DynamoDBTypes & "date" & any;
|
|
4
|
+
export interface TransformValueCb {
|
|
5
|
+
(value: any): any;
|
|
6
|
+
}
|
|
7
|
+
export interface Params {
|
|
8
|
+
/**
|
|
9
|
+
* Default is string.
|
|
10
|
+
*/
|
|
11
|
+
type?: FieldType;
|
|
12
|
+
field: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Default is true.
|
|
16
|
+
*/
|
|
17
|
+
sortable?: boolean;
|
|
18
|
+
transformValue?: TransformValueCb;
|
|
19
|
+
}
|
|
20
|
+
export declare abstract class FieldPlugin extends Plugin {
|
|
21
|
+
private readonly path;
|
|
22
|
+
private readonly field;
|
|
23
|
+
private readonly fieldType;
|
|
24
|
+
private readonly dynamoDbType;
|
|
25
|
+
private readonly sortable;
|
|
26
|
+
private readonly _transformValue;
|
|
27
|
+
constructor(params: Params);
|
|
28
|
+
getPath(): string;
|
|
29
|
+
getType(): FieldType;
|
|
30
|
+
getField(): string;
|
|
31
|
+
getDynamoDbType(): string;
|
|
32
|
+
transformValue(value: any): any;
|
|
33
|
+
isSortable(): boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class FieldPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(params) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "path", void 0);
|
|
18
|
+
(0, _defineProperty2.default)(this, "field", void 0);
|
|
19
|
+
(0, _defineProperty2.default)(this, "fieldType", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "dynamoDbType", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "sortable", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "_transformValue", void 0);
|
|
23
|
+
this.fieldType = params.type || "string";
|
|
24
|
+
this.dynamoDbType = params.type === "date" ? "string" : params.type;
|
|
25
|
+
this.field = params.field;
|
|
26
|
+
this.path = params.path;
|
|
27
|
+
this.sortable = params.sortable === undefined ? true : params.sortable;
|
|
28
|
+
this._transformValue = params.transformValue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getPath() {
|
|
32
|
+
return this.path || this.field;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getType() {
|
|
36
|
+
return this.fieldType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getField() {
|
|
40
|
+
return this.field;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getDynamoDbType() {
|
|
44
|
+
return this.dynamoDbType;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
transformValue(value) {
|
|
48
|
+
if (this._transformValue) {
|
|
49
|
+
return this.transformValue(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
switch (this.fieldType) {
|
|
53
|
+
case "number":
|
|
54
|
+
return Number(value);
|
|
55
|
+
|
|
56
|
+
case "date":
|
|
57
|
+
if (!value) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return new Date(value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isSortable() {
|
|
68
|
+
return this.sortable;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.FieldPlugin = FieldPlugin;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.NumberTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _isNumber = _interopRequireDefault(require("is-number"));
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
const transformNumber = params => {
|
|
23
|
+
const {
|
|
24
|
+
value
|
|
25
|
+
} = params;
|
|
26
|
+
const typeOf = typeof value;
|
|
27
|
+
/**
|
|
28
|
+
* Due to some internal JS stuff, we must check for a number like this.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
if (typeOf === "number" || (0, _isNumber.default)(value) === true) {
|
|
32
|
+
return Number(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new _error.default("Field value must be a number because.", "NUMBER_ERROR", {
|
|
36
|
+
value
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class NumberTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
|
|
41
|
+
constructor(params) {
|
|
42
|
+
super(_objectSpread({
|
|
43
|
+
transform: transformNumber
|
|
44
|
+
}, params));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.NumberTransformPlugin = NumberTransformPlugin;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.TimeTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _isNumber = _interopRequireDefault(require("is-number"));
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
const transformTime = params => {
|
|
23
|
+
const {
|
|
24
|
+
value
|
|
25
|
+
} = params;
|
|
26
|
+
const typeOf = typeof value;
|
|
27
|
+
/**
|
|
28
|
+
* Due to some internal JS stuff, we must check for a number like this.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
if (typeOf === "number" || (0, _isNumber.default)(value) === true) {
|
|
32
|
+
return Number(value);
|
|
33
|
+
} else if (typeOf !== "string") {
|
|
34
|
+
throw new _error.default("Field value must be a string because field is defined as time.", "TIME_PARSE_ERROR", {
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* This is for the time format, eg. 12:36:25 or 12:36:25.881
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const [time, milliseconds = 0] = value.split(".");
|
|
44
|
+
const values = time.split(":").map(Number);
|
|
45
|
+
|
|
46
|
+
if (values.length < 2) {
|
|
47
|
+
throw new _error.default("Time must contain at least hours and minutes.", "TIME_PARSE_ERROR", {
|
|
48
|
+
value
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const [hours, minutes, seconds = 0] = values;
|
|
53
|
+
return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
class TimeTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
|
|
57
|
+
constructor(params) {
|
|
58
|
+
super(_objectSpread({
|
|
59
|
+
transform: transformTime
|
|
60
|
+
}, params));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.TimeTransformPlugin = TimeTransformPlugin;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface MatchesParams {
|
|
3
|
+
value: any;
|
|
4
|
+
compareValue: any;
|
|
5
|
+
}
|
|
6
|
+
export interface Matches {
|
|
7
|
+
(params: MatchesParams): boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface Params {
|
|
10
|
+
operation: string;
|
|
11
|
+
matches: Matches;
|
|
12
|
+
}
|
|
13
|
+
export declare class ValueFilterPlugin extends Plugin {
|
|
14
|
+
static readonly type = "dynamodb.value.filter";
|
|
15
|
+
private readonly _params;
|
|
16
|
+
get operation(): string;
|
|
17
|
+
constructor(params: Params);
|
|
18
|
+
matches(params: MatchesParams): boolean;
|
|
19
|
+
getOperation(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ValueFilterPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
class ValueFilterPlugin extends _plugins.Plugin {
|
|
17
|
+
get operation() {
|
|
18
|
+
return this.getOperation();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(params) {
|
|
22
|
+
super();
|
|
23
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
24
|
+
this._params = params;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
matches(params) {
|
|
28
|
+
if (!this._params || !this._params.matches) {
|
|
29
|
+
throw new _error.default(`Missing "matches" in the plugin.`, "MATCHES_ERROR", {
|
|
30
|
+
plugin: this,
|
|
31
|
+
params
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return this._params.matches(params);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getOperation() {
|
|
39
|
+
if (!this._params || !this._params.operation) {
|
|
40
|
+
throw new _error.default(`Missing "operation" in the plugin.`, "OPERATION_ERROR");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this._params.operation;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.ValueFilterPlugin = ValueFilterPlugin;
|
|
49
|
+
(0, _defineProperty2.default)(ValueFilterPlugin, "type", "dynamodb.value.filter");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface TransformParams {
|
|
3
|
+
value: any;
|
|
4
|
+
}
|
|
5
|
+
export interface Transform {
|
|
6
|
+
(params: TransformParams): any;
|
|
7
|
+
}
|
|
8
|
+
export interface CanTransform {
|
|
9
|
+
(field: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface Params {
|
|
12
|
+
fields: string[];
|
|
13
|
+
transform: Transform;
|
|
14
|
+
canTransform?: CanTransform;
|
|
15
|
+
}
|
|
16
|
+
export declare class ValueTransformPlugin extends Plugin {
|
|
17
|
+
static readonly type = "dynamodb.value.transform";
|
|
18
|
+
private readonly _params;
|
|
19
|
+
constructor(params: Params);
|
|
20
|
+
canTransform(field: string): boolean;
|
|
21
|
+
transform(params: TransformParams): any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ValueTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _assignFields = require("./assignFields");
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
21
|
+
|
|
22
|
+
class ValueTransformPlugin extends _plugins.Plugin {
|
|
23
|
+
constructor(params) {
|
|
24
|
+
super();
|
|
25
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
26
|
+
this._params = _objectSpread(_objectSpread({}, params), {}, {
|
|
27
|
+
fields: (0, _assignFields.assignFields)(params.fields)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canTransform(field) {
|
|
32
|
+
if (!this._params.canTransform) {
|
|
33
|
+
return this._params.fields.includes(field);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this._params.canTransform(field);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
transform(params) {
|
|
40
|
+
if (!this._params.transform) {
|
|
41
|
+
throw new _error.default(`Missing "transform" in the plugin.`, "TRANSFORM_ERROR", {
|
|
42
|
+
fields: this._params.fields
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this._params.transform(params);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.ValueTransformPlugin = ValueTransformPlugin;
|
|
52
|
+
(0, _defineProperty2.default)(ValueTransformPlugin, "type", "dynamodb.value.transform");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const assignFields: (rawInput: string | string[]) => string[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.assignFields = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const assignFields = rawInput => {
|
|
13
|
+
const input = Array.isArray(rawInput) ? rawInput : [rawInput];
|
|
14
|
+
|
|
15
|
+
if (input.length === 0) {
|
|
16
|
+
throw new _error.default("Could not assign fields because there are none.", "ASSIGN_FIELDS_ERROR");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const fields = [];
|
|
20
|
+
|
|
21
|
+
for (const field of input) {
|
|
22
|
+
/**
|
|
23
|
+
* Need to make sure that no field is empty.
|
|
24
|
+
*/
|
|
25
|
+
if (!field) {
|
|
26
|
+
throw new _error.default("Passed empty field value into the plugin.", "EMPTY_FIELD_VALUE", {
|
|
27
|
+
fields: input
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fields.push(field);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return fields;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.assignFields = assignFields;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _ValueFilterPlugin = require("../definitions/ValueFilterPlugin");
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _default = new _ValueFilterPlugin.ValueFilterPlugin({
|
|
15
|
+
operation: "and_in",
|
|
16
|
+
matches: ({
|
|
17
|
+
value,
|
|
18
|
+
compareValue
|
|
19
|
+
}) => {
|
|
20
|
+
if (!compareValue || Array.isArray(compareValue) === false) {
|
|
21
|
+
throw new _error.default(`The value given as "compareValue" must be an array!`, "COMPARE_VALUE_ERROR", {
|
|
22
|
+
value,
|
|
23
|
+
compareValue
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(value) === true) {
|
|
28
|
+
return compareValue.every(c => value.includes(c));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return compareValue.includes(value);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
exports.default = _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _ValueFilterPlugin = require("../definitions/ValueFilterPlugin");
|
|
13
|
+
|
|
14
|
+
var _default = new _ValueFilterPlugin.ValueFilterPlugin({
|
|
15
|
+
operation: "between",
|
|
16
|
+
matches: ({
|
|
17
|
+
value,
|
|
18
|
+
compareValue
|
|
19
|
+
}) => {
|
|
20
|
+
if (Array.isArray(compareValue)) {
|
|
21
|
+
if (compareValue.length !== 2) {
|
|
22
|
+
throw new _error.default("When comparing between and you give an array, there must be two items in it.", "FILTER_ERROR", {
|
|
23
|
+
value,
|
|
24
|
+
compareValue
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const [from, to] = compareValue;
|
|
29
|
+
return value >= from && value <= to;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return value >= compareValue && value <= compareValue;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
exports.default = _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _ValueFilterPlugin = require("../definitions/ValueFilterPlugin");
|
|
9
|
+
|
|
10
|
+
var _default = new _ValueFilterPlugin.ValueFilterPlugin({
|
|
11
|
+
operation: "contains",
|
|
12
|
+
matches: ({
|
|
13
|
+
value,
|
|
14
|
+
compareValue
|
|
15
|
+
}) => {
|
|
16
|
+
if (typeof value !== "string") {
|
|
17
|
+
if (Array.isArray(value) === true) {
|
|
18
|
+
const re = new RegExp(compareValue, "i");
|
|
19
|
+
return value.some(v => {
|
|
20
|
+
return v.match(re) !== null;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const re = new RegExp(compareValue, "i");
|
|
28
|
+
return value.match(re) !== null;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.default = _default;
|