@webiny/db-dynamodb 0.0.0-ee-vpcs.549378cf03
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 +47 -0
- package/BatchProcess.js +198 -0
- package/BatchProcess.js.map +1 -0
- package/DynamoDbDriver.d.ts +35 -0
- package/DynamoDbDriver.js +274 -0
- package/DynamoDbDriver.js.map +1 -0
- package/LICENSE +21 -0
- package/QueryGenerator.d.ts +21 -0
- package/QueryGenerator.js +78 -0
- package/QueryGenerator.js.map +1 -0
- package/README.md +67 -0
- package/index.d.ts +2 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/operators/comparison/beginsWith.d.ts +3 -0
- package/operators/comparison/beginsWith.js +24 -0
- package/operators/comparison/beginsWith.js.map +1 -0
- package/operators/comparison/between.d.ts +3 -0
- package/operators/comparison/between.js +30 -0
- package/operators/comparison/between.js.map +1 -0
- package/operators/comparison/eq.d.ts +3 -0
- package/operators/comparison/eq.js +34 -0
- package/operators/comparison/eq.js.map +1 -0
- package/operators/comparison/gt.d.ts +3 -0
- package/operators/comparison/gt.js +24 -0
- package/operators/comparison/gt.js.map +1 -0
- package/operators/comparison/gte.d.ts +3 -0
- package/operators/comparison/gte.js +24 -0
- package/operators/comparison/gte.js.map +1 -0
- package/operators/comparison/lt.d.ts +3 -0
- package/operators/comparison/lt.js +24 -0
- package/operators/comparison/lt.js.map +1 -0
- package/operators/comparison/lte.d.ts +3 -0
- package/operators/comparison/lte.js +24 -0
- package/operators/comparison/lte.js.map +1 -0
- package/operators/index.d.ts +12 -0
- package/operators/index.js +39 -0
- package/operators/index.js.map +1 -0
- package/operators/logical/and.d.ts +3 -0
- package/operators/logical/and.js +63 -0
- package/operators/logical/and.js.map +1 -0
- package/operators/logical/or.d.ts +3 -0
- package/operators/logical/or.js +63 -0
- package/operators/logical/or.js.map +1 -0
- package/package.json +46 -0
- package/plugins/definitions/AttributePlugin.d.ts +20 -0
- package/plugins/definitions/AttributePlugin.js +61 -0
- package/plugins/definitions/AttributePlugin.js.map +1 -0
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +4 -0
- package/plugins/definitions/DateTimeTransformPlugin.js +54 -0
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -0
- package/plugins/definitions/FieldPathPlugin.d.ts +22 -0
- package/plugins/definitions/FieldPathPlugin.js +46 -0
- package/plugins/definitions/FieldPathPlugin.js.map +1 -0
- package/plugins/definitions/FieldPlugin.d.ts +34 -0
- package/plugins/definitions/FieldPlugin.js +73 -0
- package/plugins/definitions/FieldPlugin.js.map +1 -0
- package/plugins/definitions/NumberTransformPlugin.d.ts +4 -0
- package/plugins/definitions/NumberTransformPlugin.js +45 -0
- package/plugins/definitions/NumberTransformPlugin.js.map +1 -0
- package/plugins/definitions/TimeTransformPlugin.d.ts +4 -0
- package/plugins/definitions/TimeTransformPlugin.js +61 -0
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -0
- package/plugins/definitions/ValueFilterPlugin.d.ts +20 -0
- package/plugins/definitions/ValueFilterPlugin.js +49 -0
- package/plugins/definitions/ValueFilterPlugin.js.map +1 -0
- package/plugins/definitions/ValueTransformPlugin.d.ts +22 -0
- package/plugins/definitions/ValueTransformPlugin.js +50 -0
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -0
- package/plugins/definitions/assignFields.d.ts +1 -0
- package/plugins/definitions/assignFields.js +37 -0
- package/plugins/definitions/assignFields.js.map +1 -0
- package/plugins/filters/andIn.d.ts +3 -0
- package/plugins/filters/andIn.js +36 -0
- package/plugins/filters/andIn.js.map +1 -0
- package/plugins/filters/between.d.ts +3 -0
- package/plugins/filters/between.js +37 -0
- package/plugins/filters/between.js.map +1 -0
- package/plugins/filters/contains.d.ts +3 -0
- package/plugins/filters/contains.js +33 -0
- package/plugins/filters/contains.js.map +1 -0
- package/plugins/filters/eq.d.ts +3 -0
- package/plugins/filters/eq.js +34 -0
- package/plugins/filters/eq.js.map +1 -0
- package/plugins/filters/fuzzy.d.ts +3 -0
- package/plugins/filters/fuzzy.js +31 -0
- package/plugins/filters/fuzzy.js.map +1 -0
- package/plugins/filters/gt.d.ts +3 -0
- package/plugins/filters/gt.js +21 -0
- package/plugins/filters/gt.js.map +1 -0
- package/plugins/filters/gte.d.ts +3 -0
- package/plugins/filters/gte.js +21 -0
- package/plugins/filters/gte.js.map +1 -0
- package/plugins/filters/in.d.ts +3 -0
- package/plugins/filters/in.js +36 -0
- package/plugins/filters/in.js.map +1 -0
- package/plugins/filters/index.d.ts +2 -0
- package/plugins/filters/index.js +34 -0
- package/plugins/filters/index.js.map +1 -0
- package/plugins/filters/lt.d.ts +3 -0
- package/plugins/filters/lt.js +21 -0
- package/plugins/filters/lt.js.map +1 -0
- package/plugins/filters/lte.d.ts +3 -0
- package/plugins/filters/lte.js +21 -0
- package/plugins/filters/lte.js.map +1 -0
- package/plugins/filters/startsWith.d.ts +3 -0
- package/plugins/filters/startsWith.js +34 -0
- package/plugins/filters/startsWith.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +19 -0
- package/plugins/index.js.map +1 -0
- package/statements/createKeyConditionExpressionArgs.d.ts +15 -0
- package/statements/createKeyConditionExpressionArgs.js +52 -0
- package/statements/createKeyConditionExpressionArgs.js.map +1 -0
- package/statements/processStatement.d.ts +3 -0
- package/statements/processStatement.js +42 -0
- package/statements/processStatement.js.map +1 -0
- package/types.d.ts +58 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
- package/utils/attributes.d.ts +10 -0
- package/utils/attributes.js +31 -0
- package/utils/attributes.js.map +1 -0
- package/utils/batchRead.d.ts +15 -0
- package/utils/batchRead.js +89 -0
- package/utils/batchRead.js.map +1 -0
- package/utils/batchWrite.d.ts +17 -0
- package/utils/batchWrite.js +30 -0
- package/utils/batchWrite.js.map +1 -0
- package/utils/cleanup.d.ts +3 -0
- package/utils/cleanup.js +45 -0
- package/utils/cleanup.js.map +1 -0
- package/utils/cursor.d.ts +2 -0
- package/utils/cursor.js +26 -0
- package/utils/cursor.js.map +1 -0
- package/utils/filter.d.ts +12 -0
- package/utils/filter.js +213 -0
- package/utils/filter.js.map +1 -0
- package/utils/get.d.ts +17 -0
- package/utils/get.js +30 -0
- package/utils/get.js.map +1 -0
- package/utils/listResponse.d.ts +13 -0
- package/utils/listResponse.js +33 -0
- package/utils/listResponse.js.map +1 -0
- package/utils/query.d.ts +32 -0
- package/utils/query.js +119 -0
- package/utils/query.js.map +1 -0
- package/utils/sort.d.ts +17 -0
- package/utils/sort.js +91 -0
- package/utils/sort.js.map +1 -0
- package/utils/table.d.ts +7 -0
- package/utils/table.js +27 -0
- package/utils/table.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["processQuery","query","orArgs","processStatement","args","expression","attributeNames","attributeValues","Object","assign","or","canProcess","key","process","value","Array","isArray","i","length","orKey","orValue","entries"],"sources":["or.ts"],"sourcesContent":["import {\n Operator,\n ProcessStatementArgsParam,\n ProcessStatementCallable,\n ProcessStatementQueryParam\n} from \"~/types\";\n\nconst processQuery = (\n query: ProcessStatementQueryParam,\n orArgs: ProcessStatementArgsParam,\n processStatement: ProcessStatementCallable\n) => {\n const args: ProcessStatementArgsParam = {\n expression: \"\",\n attributeNames: {},\n attributeValues: {}\n };\n\n processStatement({ args, query });\n\n Object.assign(orArgs.attributeNames, args.attributeNames);\n Object.assign(orArgs.attributeValues, args.attributeValues);\n\n if (orArgs.expression === \"\") {\n orArgs.expression = args.expression;\n } else {\n orArgs.expression += \" or \" + args.expression;\n }\n};\n\nconst or: Operator = {\n canProcess: ({ key }) => {\n return key === \"$or\";\n },\n process: ({ value, args, processStatement }) => {\n const orArgs: ProcessStatementArgsParam = {\n expression: \"\",\n attributeNames: {},\n attributeValues: {}\n };\n\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n processQuery(value[i], orArgs, processStatement);\n }\n } else {\n for (const [orKey, orValue] of Object.entries(value)) {\n processQuery({ [orKey]: orValue }, orArgs, processStatement);\n }\n }\n\n args.expression += \"(\" + orArgs.expression + \")\";\n Object.assign(args.attributeNames, orArgs.attributeNames);\n Object.assign(args.attributeValues, orArgs.attributeValues);\n }\n};\n\nexport default or;\n"],"mappings":";;;;;;;AAOA,MAAMA,YAAY,GAAG,CACjBC,KADiB,EAEjBC,MAFiB,EAGjBC,gBAHiB,KAIhB;EACD,MAAMC,IAA+B,GAAG;IACpCC,UAAU,EAAE,EADwB;IAEpCC,cAAc,EAAE,EAFoB;IAGpCC,eAAe,EAAE;EAHmB,CAAxC;EAMAJ,gBAAgB,CAAC;IAAEC,IAAF;IAAQH;EAAR,CAAD,CAAhB;EAEAO,MAAM,CAACC,MAAP,CAAcP,MAAM,CAACI,cAArB,EAAqCF,IAAI,CAACE,cAA1C;EACAE,MAAM,CAACC,MAAP,CAAcP,MAAM,CAACK,eAArB,EAAsCH,IAAI,CAACG,eAA3C;;EAEA,IAAIL,MAAM,CAACG,UAAP,KAAsB,EAA1B,EAA8B;IAC1BH,MAAM,CAACG,UAAP,GAAoBD,IAAI,CAACC,UAAzB;EACH,CAFD,MAEO;IACHH,MAAM,CAACG,UAAP,IAAqB,SAASD,IAAI,CAACC,UAAnC;EACH;AACJ,CArBD;;AAuBA,MAAMK,EAAY,GAAG;EACjBC,UAAU,EAAE,CAAC;IAAEC;EAAF,CAAD,KAAa;IACrB,OAAOA,GAAG,KAAK,KAAf;EACH,CAHgB;EAIjBC,OAAO,EAAE,CAAC;IAAEC,KAAF;IAASV,IAAT;IAAeD;EAAf,CAAD,KAAuC;IAC5C,MAAMD,MAAiC,GAAG;MACtCG,UAAU,EAAE,EAD0B;MAEtCC,cAAc,EAAE,EAFsB;MAGtCC,eAAe,EAAE;IAHqB,CAA1C;;IAMA,IAAIQ,KAAK,CAACC,OAAN,CAAcF,KAAd,CAAJ,EAA0B;MACtB,KAAK,IAAIG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,KAAK,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;QACnCjB,YAAY,CAACc,KAAK,CAACG,CAAD,CAAN,EAAWf,MAAX,EAAmBC,gBAAnB,CAAZ;MACH;IACJ,CAJD,MAIO;MACH,KAAK,MAAM,CAACgB,KAAD,EAAQC,OAAR,CAAX,IAA+BZ,MAAM,CAACa,OAAP,CAAeP,KAAf,CAA/B,EAAsD;QAClDd,YAAY,CAAC;UAAE,CAACmB,KAAD,GAASC;QAAX,CAAD,EAAuBlB,MAAvB,EAA+BC,gBAA/B,CAAZ;MACH;IACJ;;IAEDC,IAAI,CAACC,UAAL,IAAmB,MAAMH,MAAM,CAACG,UAAb,GAA0B,GAA7C;IACAG,MAAM,CAACC,MAAP,CAAcL,IAAI,CAACE,cAAnB,EAAmCJ,MAAM,CAACI,cAA1C;IACAE,MAAM,CAACC,MAAP,CAAcL,IAAI,CAACG,eAAnB,EAAoCL,MAAM,CAACK,eAA3C;EACH;AAxBgB,CAArB;eA2BeG,E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/db-dynamodb",
|
|
3
|
+
"version": "0.0.0-ee-vpcs.549378cf03",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "A DynamoDB driver for the @webiny/db database client.",
|
|
10
|
+
"author": "Webiny Ltd",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@webiny/api": "0.0.0-ee-vpcs.549378cf03",
|
|
14
|
+
"@webiny/db": "0.0.0-ee-vpcs.549378cf03",
|
|
15
|
+
"@webiny/error": "0.0.0-ee-vpcs.549378cf03",
|
|
16
|
+
"@webiny/handler-db": "0.0.0-ee-vpcs.549378cf03",
|
|
17
|
+
"@webiny/plugins": "0.0.0-ee-vpcs.549378cf03",
|
|
18
|
+
"date-fns": "2.29.3",
|
|
19
|
+
"dot-prop": "6.0.1",
|
|
20
|
+
"fuse.js": "6.6.2",
|
|
21
|
+
"is-number": "7.0.0",
|
|
22
|
+
"lodash": "4.17.21"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.19.3",
|
|
26
|
+
"@babel/core": "^7.19.3",
|
|
27
|
+
"@types/is-number": "^7.0.2",
|
|
28
|
+
"@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
|
|
29
|
+
"@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
|
|
30
|
+
"dynamodb-toolbox": "^0.3.5",
|
|
31
|
+
"jest": "^28.1.0",
|
|
32
|
+
"jest-dynalite": "^3.2.0",
|
|
33
|
+
"rimraf": "^3.0.2",
|
|
34
|
+
"ttypescript": "^1.5.12",
|
|
35
|
+
"typescript": "4.7.4"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"directory": "dist"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "yarn webiny run build",
|
|
43
|
+
"watch": "yarn webiny run watch"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
|
|
3
|
+
import { EntityAttributeConfig, EntityCompositeAttributes } from "dynamodb-toolbox/dist/classes/Entity";
|
|
4
|
+
export declare type DefinitionParams = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;
|
|
5
|
+
export interface AttributePluginParams {
|
|
6
|
+
entity: string;
|
|
7
|
+
attribute: string;
|
|
8
|
+
params: DefinitionParams;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class AttributePlugin extends Plugin {
|
|
11
|
+
static readonly type: string;
|
|
12
|
+
private readonly _entity;
|
|
13
|
+
private readonly _attribute;
|
|
14
|
+
private readonly _params;
|
|
15
|
+
get entity(): string;
|
|
16
|
+
get attribute(): string;
|
|
17
|
+
constructor({ entity, attribute, params }: AttributePluginParams);
|
|
18
|
+
getDefinition(): Record<string, DefinitionParams>;
|
|
19
|
+
private validateReserved;
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.AttributePlugin = 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
|
+
const reservedFields = ["PK", "SK", "index", "data"];
|
|
17
|
+
|
|
18
|
+
class AttributePlugin extends _plugins.Plugin {
|
|
19
|
+
get entity() {
|
|
20
|
+
return this._entity;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get attribute() {
|
|
24
|
+
return this._attribute;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constructor({
|
|
28
|
+
entity,
|
|
29
|
+
attribute,
|
|
30
|
+
params
|
|
31
|
+
}) {
|
|
32
|
+
super();
|
|
33
|
+
(0, _defineProperty2.default)(this, "_entity", void 0);
|
|
34
|
+
(0, _defineProperty2.default)(this, "_attribute", void 0);
|
|
35
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
36
|
+
this.validateReserved(attribute);
|
|
37
|
+
this._entity = entity;
|
|
38
|
+
this._attribute = attribute;
|
|
39
|
+
this._params = params;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getDefinition() {
|
|
43
|
+
return {
|
|
44
|
+
[this.attribute]: this._params
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
validateReserved(attribute) {
|
|
49
|
+
if (reservedFields.includes(attribute) === false) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new _error.default(`Attribute name "${attribute}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
|
|
54
|
+
attribute
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.AttributePlugin = AttributePlugin;
|
|
61
|
+
(0, _defineProperty2.default)(AttributePlugin, "type", "db.dynamodb.attribute");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reservedFields","AttributePlugin","Plugin","entity","_entity","attribute","_attribute","constructor","params","validateReserved","_params","getDefinition","includes","WebinyError"],"sources":["AttributePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { DynamoDBTypes } from \"dynamodb-toolbox/dist/classes/Table\";\nimport {\n EntityAttributeConfig,\n EntityCompositeAttributes\n} from \"dynamodb-toolbox/dist/classes/Entity\";\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\"];\n\nexport type DefinitionParams = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;\n\nexport interface AttributePluginParams {\n entity: string;\n attribute: string;\n params: DefinitionParams;\n}\n\nexport abstract class AttributePlugin extends Plugin {\n public static override readonly type: string = \"db.dynamodb.attribute\";\n private readonly _entity: string;\n private readonly _attribute: string;\n private readonly _params: DefinitionParams;\n\n public get entity(): string {\n return this._entity;\n }\n\n public get attribute(): string {\n return this._attribute;\n }\n\n public constructor({ entity, attribute, params }: AttributePluginParams) {\n super();\n\n this.validateReserved(attribute);\n\n this._entity = entity;\n this._attribute = attribute;\n this._params = params;\n }\n\n public getDefinition(): Record<string, DefinitionParams> {\n return {\n [this.attribute]: this._params\n };\n }\n\n private validateReserved(attribute: string): void {\n if (reservedFields.includes(attribute) === false) {\n return;\n }\n throw new WebinyError(\n `Attribute name \"${attribute}\" is not allowed.`,\n \"ATTRIBUTE_NOT_ALLOWED\",\n {\n attribute\n }\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAMA,MAAMA,cAAc,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,OAAb,EAAsB,MAAtB,CAAvB;;AAUO,MAAeC,eAAf,SAAuCC,eAAvC,CAA8C;EAMhC,IAANC,MAAM,GAAW;IACxB,OAAO,KAAKC,OAAZ;EACH;;EAEmB,IAATC,SAAS,GAAW;IAC3B,OAAO,KAAKC,UAAZ;EACH;;EAEMC,WAAW,CAAC;IAAEJ,MAAF;IAAUE,SAAV;IAAqBG;EAArB,CAAD,EAAuD;IACrE;IADqE;IAAA;IAAA;IAGrE,KAAKC,gBAAL,CAAsBJ,SAAtB;IAEA,KAAKD,OAAL,GAAeD,MAAf;IACA,KAAKG,UAAL,GAAkBD,SAAlB;IACA,KAAKK,OAAL,GAAeF,MAAf;EACH;;EAEMG,aAAa,GAAqC;IACrD,OAAO;MACH,CAAC,KAAKN,SAAN,GAAkB,KAAKK;IADpB,CAAP;EAGH;;EAEOD,gBAAgB,CAACJ,SAAD,EAA0B;IAC9C,IAAIL,cAAc,CAACY,QAAf,CAAwBP,SAAxB,MAAuC,KAA3C,EAAkD;MAC9C;IACH;;IACD,MAAM,IAAIQ,cAAJ,CACD,mBAAkBR,SAAU,mBAD3B,EAEF,uBAFE,EAGF;MACIA;IADJ,CAHE,CAAN;EAOH;;AAzCgD;;;8BAA/BJ,e,UAC6B,uB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DateTimeTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _dateFns = require("date-fns");
|
|
17
|
+
|
|
18
|
+
const transformDateTime = params => {
|
|
19
|
+
const {
|
|
20
|
+
value
|
|
21
|
+
} = params;
|
|
22
|
+
|
|
23
|
+
if (value === null) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
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((0, _objectSpread2.default)({
|
|
48
|
+
transform: transformDateTime
|
|
49
|
+
}, params));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.DateTimeTransformPlugin = DateTimeTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transformDateTime","params","value","getTime","parsedDateTime","parseISO","isNaN","WebinyError","DateTimeTransformPlugin","ValueTransformPlugin","constructor","transform"],"sources":["DateTimeTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { parseISO } from \"date-fns\";\n\nconst transformDateTime = (params: ValueTransformPluginParamsTransformParams): number | null => {\n const { value } = params;\n if (value === null) {\n return null;\n }\n if (value && typeof (value as any).getTime === \"function\") {\n /**\n * In this case we assume this is a date object and we just get the time.\n */\n return (value as Date).getTime();\n }\n const parsedDateTime = parseISO(value).getTime();\n if (isNaN(parsedDateTime) === false) {\n return parsedDateTime;\n }\n throw new WebinyError(\"Could not parse given dateTime value.\", \"PARSE_DATE_ERROR\", {\n value\n });\n};\n\nexport class DateTimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformDateTime,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AACA;;AAEA,MAAMA,iBAAiB,GAAIC,MAAD,IAAsE;EAC5F,MAAM;IAAEC;EAAF,IAAYD,MAAlB;;EACA,IAAIC,KAAK,KAAK,IAAd,EAAoB;IAChB,OAAO,IAAP;EACH;;EACD,IAAIA,KAAK,IAAI,OAAQA,KAAD,CAAeC,OAAtB,KAAkC,UAA/C,EAA2D;IACvD;AACR;AACA;IACQ,OAAQD,KAAD,CAAgBC,OAAhB,EAAP;EACH;;EACD,MAAMC,cAAc,GAAG,IAAAC,iBAAA,EAASH,KAAT,EAAgBC,OAAhB,EAAvB;;EACA,IAAIG,KAAK,CAACF,cAAD,CAAL,KAA0B,KAA9B,EAAqC;IACjC,OAAOA,cAAP;EACH;;EACD,MAAM,IAAIG,cAAJ,CAAgB,uCAAhB,EAAyD,kBAAzD,EAA6E;IAC/EL;EAD+E,CAA7E,CAAN;AAGH,CAlBD;;AAoBO,MAAMM,uBAAN,SAAsCC,0CAAtC,CAA2D;EACvDC,WAAW,CAACT,MAAD,EAAwD;IACtE;MACIU,SAAS,EAAEX;IADf,GAEOC,MAFP;EAIH;;AAN6D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface CreatePath {
|
|
3
|
+
(field: string): string;
|
|
4
|
+
}
|
|
5
|
+
export interface FieldPathPluginParams {
|
|
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: string;
|
|
18
|
+
private readonly _params;
|
|
19
|
+
constructor(params: FieldPathPluginParams);
|
|
20
|
+
canCreate(field: string): boolean;
|
|
21
|
+
createPath(field: string): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FieldPathPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _plugins = require("@webiny/plugins");
|
|
15
|
+
|
|
16
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
17
|
+
|
|
18
|
+
var _assignFields = require("./assignFields");
|
|
19
|
+
|
|
20
|
+
class FieldPathPlugin extends _plugins.Plugin {
|
|
21
|
+
constructor(params) {
|
|
22
|
+
super();
|
|
23
|
+
(0, _defineProperty2.default)(this, "_params", void 0);
|
|
24
|
+
this._params = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
25
|
+
fields: (0, _assignFields.assignFields)(params.fields)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
canCreate(field) {
|
|
30
|
+
return this._params.fields.includes(field);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
createPath(field) {
|
|
34
|
+
if (!this._params.createPath) {
|
|
35
|
+
throw new _error.default(`Missing "createPath" in the plugin.`, "TRANSFORM_ERROR", {
|
|
36
|
+
fields: this._params.fields
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this._params.createPath(field);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.FieldPathPlugin = FieldPathPlugin;
|
|
46
|
+
(0, _defineProperty2.default)(FieldPathPlugin, "type", "dynamodb.value.path");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FieldPathPlugin","Plugin","constructor","params","_params","fields","assignFields","canCreate","field","includes","createPath","WebinyError"],"sources":["FieldPathPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { assignFields } from \"./assignFields\";\n\nexport interface CreatePath {\n (field: string): string;\n}\nexport interface FieldPathPluginParams {\n /**\n * Which field(s) is this plugin for.\n */\n fields: string | string[];\n /**\n * Create a path for given field.\n * Field is passed because it can be a multi-field plugin.\n */\n createPath: CreatePath;\n}\n\nexport class FieldPathPlugin extends Plugin {\n public static override readonly type: string = \"dynamodb.value.path\";\n private readonly _params: Omit<FieldPathPluginParams, \"fields\"> & { fields: string[] };\n\n public constructor(params: FieldPathPluginParams) {\n super();\n this._params = {\n ...params,\n fields: assignFields(params.fields)\n };\n }\n\n public canCreate(field: string): boolean {\n return this._params.fields.includes(field);\n }\n\n public createPath(field: string): string {\n if (!this._params.createPath) {\n throw new WebinyError(`Missing \"createPath\" in the plugin.`, \"TRANSFORM_ERROR\", {\n fields: this._params.fields\n });\n }\n return this._params.createPath(field);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAiBO,MAAMA,eAAN,SAA8BC,eAA9B,CAAqC;EAIjCC,WAAW,CAACC,MAAD,EAAgC;IAC9C;IAD8C;IAE9C,KAAKC,OAAL,+DACOD,MADP;MAEIE,MAAM,EAAE,IAAAC,0BAAA,EAAaH,MAAM,CAACE,MAApB;IAFZ;EAIH;;EAEME,SAAS,CAACC,KAAD,EAAyB;IACrC,OAAO,KAAKJ,OAAL,CAAaC,MAAb,CAAoBI,QAApB,CAA6BD,KAA7B,CAAP;EACH;;EAEME,UAAU,CAACF,KAAD,EAAwB;IACrC,IAAI,CAAC,KAAKJ,OAAL,CAAaM,UAAlB,EAA8B;MAC1B,MAAM,IAAIC,cAAJ,CAAiB,qCAAjB,EAAuD,iBAAvD,EAA0E;QAC5EN,MAAM,EAAE,KAAKD,OAAL,CAAaC;MADuD,CAA1E,CAAN;IAGH;;IACD,OAAO,KAAKD,OAAL,CAAaM,UAAb,CAAwBF,KAAxB,CAAP;EACH;;AAvBuC;;;8BAA/BR,e,UACsC,qB"}
|
|
@@ -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 FieldPluginParams {
|
|
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: FieldPluginParams);
|
|
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").default;
|
|
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 @@
|
|
|
1
|
+
{"version":3,"names":["FieldPlugin","Plugin","constructor","params","fieldType","type","dynamoDbType","field","path","sortable","undefined","_transformValue","transformValue","getPath","getType","getField","getDynamoDbType","value","Number","Date","isSortable"],"sources":["FieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { DynamoDBTypes } from \"dynamodb-toolbox/dist/classes/Table\";\n\nexport type FieldType = DynamoDBTypes & \"date\" & any;\n\nexport interface TransformValueCb {\n (value: any): any;\n}\n\nexport interface FieldPluginParams {\n /**\n * Default is string.\n */\n type?: FieldType;\n field: string;\n path?: string;\n /**\n * Default is true.\n */\n sortable?: boolean;\n\n transformValue?: TransformValueCb;\n}\n\nexport abstract class FieldPlugin extends Plugin {\n private readonly path?: string;\n private readonly field: string;\n private readonly fieldType: FieldType;\n private readonly dynamoDbType: DynamoDBTypes;\n private readonly sortable: boolean;\n private readonly _transformValue: TransformValueCb | undefined;\n\n public constructor(params: FieldPluginParams) {\n super();\n this.fieldType = params.type || \"string\";\n this.dynamoDbType = params.type === \"date\" ? \"string\" : params.type;\n this.field = params.field;\n this.path = params.path;\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this._transformValue = params.transformValue;\n }\n\n public getPath(): string {\n return this.path || this.field;\n }\n\n public getType(): FieldType {\n return this.fieldType;\n }\n\n public getField(): string {\n return this.field;\n }\n\n public getDynamoDbType(): string {\n return this.dynamoDbType;\n }\n\n public transformValue(value: any): any {\n if (this._transformValue) {\n return this.transformValue(value);\n }\n switch (this.fieldType) {\n case \"number\":\n return Number(value);\n case \"date\":\n if (!value) {\n return null;\n }\n return new Date(value);\n }\n return value;\n }\n\n public isSortable(): boolean {\n return this.sortable;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAwBO,MAAeA,WAAf,SAAmCC,eAAnC,CAA0C;EAQtCC,WAAW,CAACC,MAAD,EAA4B;IAC1C;IAD0C;IAAA;IAAA;IAAA;IAAA;IAAA;IAE1C,KAAKC,SAAL,GAAiBD,MAAM,CAACE,IAAP,IAAe,QAAhC;IACA,KAAKC,YAAL,GAAoBH,MAAM,CAACE,IAAP,KAAgB,MAAhB,GAAyB,QAAzB,GAAoCF,MAAM,CAACE,IAA/D;IACA,KAAKE,KAAL,GAAaJ,MAAM,CAACI,KAApB;IACA,KAAKC,IAAL,GAAYL,MAAM,CAACK,IAAnB;IACA,KAAKC,QAAL,GAAgBN,MAAM,CAACM,QAAP,KAAoBC,SAApB,GAAgC,IAAhC,GAAuCP,MAAM,CAACM,QAA9D;IACA,KAAKE,eAAL,GAAuBR,MAAM,CAACS,cAA9B;EACH;;EAEMC,OAAO,GAAW;IACrB,OAAO,KAAKL,IAAL,IAAa,KAAKD,KAAzB;EACH;;EAEMO,OAAO,GAAc;IACxB,OAAO,KAAKV,SAAZ;EACH;;EAEMW,QAAQ,GAAW;IACtB,OAAO,KAAKR,KAAZ;EACH;;EAEMS,eAAe,GAAW;IAC7B,OAAO,KAAKV,YAAZ;EACH;;EAEMM,cAAc,CAACK,KAAD,EAAkB;IACnC,IAAI,KAAKN,eAAT,EAA0B;MACtB,OAAO,KAAKC,cAAL,CAAoBK,KAApB,CAAP;IACH;;IACD,QAAQ,KAAKb,SAAb;MACI,KAAK,QAAL;QACI,OAAOc,MAAM,CAACD,KAAD,CAAb;;MACJ,KAAK,MAAL;QACI,IAAI,CAACA,KAAL,EAAY;UACR,OAAO,IAAP;QACH;;QACD,OAAO,IAAIE,IAAJ,CAASF,KAAT,CAAP;IAPR;;IASA,OAAOA,KAAP;EACH;;EAEMG,UAAU,GAAY;IACzB,OAAO,KAAKX,QAAZ;EACH;;AApD4C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.NumberTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _isNumber = _interopRequireDefault(require("is-number"));
|
|
17
|
+
|
|
18
|
+
const transformNumber = params => {
|
|
19
|
+
const {
|
|
20
|
+
value
|
|
21
|
+
} = params;
|
|
22
|
+
const typeOf = typeof value;
|
|
23
|
+
/**
|
|
24
|
+
* Due to some internal JS stuff, we must check for a number like this.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
if (typeOf === "number" || (0, _isNumber.default)(value) === true) {
|
|
28
|
+
return Number(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new _error.default("Field value must be a number because.", "NUMBER_ERROR", {
|
|
32
|
+
value
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class NumberTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
|
|
37
|
+
constructor(params) {
|
|
38
|
+
super((0, _objectSpread2.default)({
|
|
39
|
+
transform: transformNumber
|
|
40
|
+
}, params));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.NumberTransformPlugin = NumberTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transformNumber","params","value","typeOf","isNumber","Number","WebinyError","NumberTransformPlugin","ValueTransformPlugin","constructor","transform"],"sources":["NumberTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport isNumber from \"is-number\";\n\nconst transformNumber = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n const typeOf = typeof value;\n /**\n * Due to some internal JS stuff, we must check for a number like this.\n */\n if (typeOf === \"number\" || isNumber(value) === true) {\n return Number(value);\n }\n throw new WebinyError(\"Field value must be a number because.\", \"NUMBER_ERROR\", {\n value\n });\n};\n\nexport class NumberTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformNumber,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AACA;;AAEA,MAAMA,eAAe,GAAIC,MAAD,IAA+D;EACnF,MAAM;IAAEC;EAAF,IAAYD,MAAlB;EACA,MAAME,MAAM,GAAG,OAAOD,KAAtB;EACA;AACJ;AACA;;EACI,IAAIC,MAAM,KAAK,QAAX,IAAuB,IAAAC,iBAAA,EAASF,KAAT,MAAoB,IAA/C,EAAqD;IACjD,OAAOG,MAAM,CAACH,KAAD,CAAb;EACH;;EACD,MAAM,IAAII,cAAJ,CAAgB,uCAAhB,EAAyD,cAAzD,EAAyE;IAC3EJ;EAD2E,CAAzE,CAAN;AAGH,CAZD;;AAcO,MAAMK,qBAAN,SAAoCC,0CAApC,CAAyD;EACrDC,WAAW,CAACR,MAAD,EAAwD;IACtE;MACIS,SAAS,EAAEV;IADf,GAEOC,MAFP;EAIH;;AAN2D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.TimeTransformPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _ValueTransformPlugin = require("./ValueTransformPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _isNumber = _interopRequireDefault(require("is-number"));
|
|
17
|
+
|
|
18
|
+
const transformTime = params => {
|
|
19
|
+
const {
|
|
20
|
+
value
|
|
21
|
+
} = params;
|
|
22
|
+
const typeOf = typeof value;
|
|
23
|
+
/**
|
|
24
|
+
* Due to some internal JS stuff, we must check for a number like this.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
if (typeOf === "number" || (0, _isNumber.default)(value) === true) {
|
|
28
|
+
return Number(value);
|
|
29
|
+
} else if (typeOf !== "string") {
|
|
30
|
+
throw new _error.default("Field value must be a string because field is defined as time.", "TIME_PARSE_ERROR", {
|
|
31
|
+
value
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* This is for the time format, eg. 12:36:25 or 12:36:25.881
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const [time, milliseconds = 0] = value.split(".");
|
|
40
|
+
const values = time.split(":").map(Number);
|
|
41
|
+
|
|
42
|
+
if (values.length < 2) {
|
|
43
|
+
throw new _error.default("Time must contain at least hours and minutes.", "TIME_PARSE_ERROR", {
|
|
44
|
+
value
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const [hours, minutes, seconds = 0] = values;
|
|
49
|
+
return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class TimeTransformPlugin extends _ValueTransformPlugin.ValueTransformPlugin {
|
|
53
|
+
constructor(params) {
|
|
54
|
+
super((0, _objectSpread2.default)({
|
|
55
|
+
transform: transformTime
|
|
56
|
+
}, params));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.TimeTransformPlugin = TimeTransformPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transformTime","params","value","typeOf","isNumber","Number","WebinyError","time","milliseconds","split","values","map","length","hours","minutes","seconds","TimeTransformPlugin","ValueTransformPlugin","constructor","transform"],"sources":["TimeTransformPlugin.ts"],"sourcesContent":["import {\n ValueTransformPlugin,\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport isNumber from \"is-number\";\n\nconst transformTime = (params: ValueTransformPluginParamsTransformParams): number => {\n const { value } = params;\n const typeOf = typeof value;\n /**\n * Due to some internal JS stuff, we must check for a number like this.\n */\n if (typeOf === \"number\" || isNumber(value) === true) {\n return Number(value);\n } else if (typeOf !== \"string\") {\n throw new WebinyError(\n \"Field value must be a string because field is defined as time.\",\n \"TIME_PARSE_ERROR\",\n {\n value\n }\n );\n }\n /**\n * This is for the time format, eg. 12:36:25 or 12:36:25.881\n */\n const [time, milliseconds = 0] = (value as any).split(\".\");\n const values = time.split(\":\").map(Number);\n if (values.length < 2) {\n throw new WebinyError(\"Time must contain at least hours and minutes.\", \"TIME_PARSE_ERROR\", {\n value\n });\n }\n const [hours, minutes, seconds = 0] = values;\n return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);\n};\n\nexport class TimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformTime,\n ...params\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AACA;;AAEA,MAAMA,aAAa,GAAIC,MAAD,IAA+D;EACjF,MAAM;IAAEC;EAAF,IAAYD,MAAlB;EACA,MAAME,MAAM,GAAG,OAAOD,KAAtB;EACA;AACJ;AACA;;EACI,IAAIC,MAAM,KAAK,QAAX,IAAuB,IAAAC,iBAAA,EAASF,KAAT,MAAoB,IAA/C,EAAqD;IACjD,OAAOG,MAAM,CAACH,KAAD,CAAb;EACH,CAFD,MAEO,IAAIC,MAAM,KAAK,QAAf,EAAyB;IAC5B,MAAM,IAAIG,cAAJ,CACF,gEADE,EAEF,kBAFE,EAGF;MACIJ;IADJ,CAHE,CAAN;EAOH;EACD;AACJ;AACA;;;EACI,MAAM,CAACK,IAAD,EAAOC,YAAY,GAAG,CAAtB,IAA4BN,KAAD,CAAeO,KAAf,CAAqB,GAArB,CAAjC;EACA,MAAMC,MAAM,GAAGH,IAAI,CAACE,KAAL,CAAW,GAAX,EAAgBE,GAAhB,CAAoBN,MAApB,CAAf;;EACA,IAAIK,MAAM,CAACE,MAAP,GAAgB,CAApB,EAAuB;IACnB,MAAM,IAAIN,cAAJ,CAAgB,+CAAhB,EAAiE,kBAAjE,EAAqF;MACvFJ;IADuF,CAArF,CAAN;EAGH;;EACD,MAAM,CAACW,KAAD,EAAQC,OAAR,EAAiBC,OAAO,GAAG,CAA3B,IAAgCL,MAAtC;EACA,OAAO,CAACG,KAAK,GAAG,EAAR,GAAa,EAAb,GAAkBC,OAAO,GAAG,EAA5B,GAAiCC,OAAlC,IAA6C,IAA7C,GAAoDV,MAAM,CAACG,YAAD,CAAjE;AACH,CA7BD;;AA+BO,MAAMQ,mBAAN,SAAkCC,0CAAlC,CAAuD;EACnDC,WAAW,CAACjB,MAAD,EAAwD;IACtE;MACIkB,SAAS,EAAEnB;IADf,GAEOC,MAFP;EAIH;;AANyD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface ValueFilterPluginParamsMatchesParams<V = any, C = any> {
|
|
3
|
+
value: V;
|
|
4
|
+
compareValue: C;
|
|
5
|
+
}
|
|
6
|
+
export interface ValueFilterPluginParamsMatches {
|
|
7
|
+
(params: ValueFilterPluginParamsMatchesParams): boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ValueFilterPluginParams {
|
|
10
|
+
operation: string;
|
|
11
|
+
matches: ValueFilterPluginParamsMatches;
|
|
12
|
+
}
|
|
13
|
+
export declare class ValueFilterPlugin extends Plugin {
|
|
14
|
+
static readonly type: string;
|
|
15
|
+
private readonly _params;
|
|
16
|
+
get operation(): string;
|
|
17
|
+
constructor(params: ValueFilterPluginParams);
|
|
18
|
+
matches(params: ValueFilterPluginParamsMatchesParams): boolean;
|
|
19
|
+
getOperation(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
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 @@
|
|
|
1
|
+
{"version":3,"names":["ValueFilterPlugin","Plugin","operation","getOperation","constructor","params","_params","matches","WebinyError","plugin"],"sources":["ValueFilterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\n\nexport interface ValueFilterPluginParamsMatchesParams<V = any, C = any> {\n value: V;\n compareValue: C;\n}\n\nexport interface ValueFilterPluginParamsMatches {\n (params: ValueFilterPluginParamsMatchesParams): boolean;\n}\n\nexport interface ValueFilterPluginParams {\n operation: string;\n matches: ValueFilterPluginParamsMatches;\n}\nexport class ValueFilterPlugin extends Plugin {\n public static override readonly type: string = \"dynamodb.value.filter\";\n private readonly _params: ValueFilterPluginParams;\n\n public get operation(): string {\n return this.getOperation();\n }\n\n public constructor(params: ValueFilterPluginParams) {\n super();\n this._params = params;\n }\n\n public matches(params: ValueFilterPluginParamsMatchesParams): boolean {\n if (!this._params || !this._params.matches) {\n throw new WebinyError(`Missing \"matches\" in the plugin.`, \"MATCHES_ERROR\", {\n plugin: this,\n params\n });\n }\n return this._params.matches(params);\n }\n\n public getOperation(): string {\n if (!this._params || !this._params.operation) {\n throw new WebinyError(`Missing \"operation\" in the plugin.`, \"OPERATION_ERROR\");\n }\n return this._params.operation;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAeO,MAAMA,iBAAN,SAAgCC,eAAhC,CAAuC;EAItB,IAATC,SAAS,GAAW;IAC3B,OAAO,KAAKC,YAAL,EAAP;EACH;;EAEMC,WAAW,CAACC,MAAD,EAAkC;IAChD;IADgD;IAEhD,KAAKC,OAAL,GAAeD,MAAf;EACH;;EAEME,OAAO,CAACF,MAAD,EAAwD;IAClE,IAAI,CAAC,KAAKC,OAAN,IAAiB,CAAC,KAAKA,OAAL,CAAaC,OAAnC,EAA4C;MACxC,MAAM,IAAIC,cAAJ,CAAiB,kCAAjB,EAAoD,eAApD,EAAqE;QACvEC,MAAM,EAAE,IAD+D;QAEvEJ;MAFuE,CAArE,CAAN;IAIH;;IACD,OAAO,KAAKC,OAAL,CAAaC,OAAb,CAAqBF,MAArB,CAAP;EACH;;EAEMF,YAAY,GAAW;IAC1B,IAAI,CAAC,KAAKG,OAAN,IAAiB,CAAC,KAAKA,OAAL,CAAaJ,SAAnC,EAA8C;MAC1C,MAAM,IAAIM,cAAJ,CAAiB,oCAAjB,EAAsD,iBAAtD,CAAN;IACH;;IACD,OAAO,KAAKF,OAAL,CAAaJ,SAApB;EACH;;AA5ByC;;;8BAAjCF,iB,UACsC,uB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
export interface ValueTransformPluginParamsTransformParams {
|
|
3
|
+
value: any;
|
|
4
|
+
}
|
|
5
|
+
export interface ValueTransformPluginParamsTransform {
|
|
6
|
+
(params: ValueTransformPluginParamsTransformParams): any;
|
|
7
|
+
}
|
|
8
|
+
export interface CanTransform {
|
|
9
|
+
(field: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ValueTransformPluginParams {
|
|
12
|
+
fields: string[];
|
|
13
|
+
transform: ValueTransformPluginParamsTransform;
|
|
14
|
+
canTransform?: CanTransform;
|
|
15
|
+
}
|
|
16
|
+
export declare class ValueTransformPlugin extends Plugin {
|
|
17
|
+
static readonly type: string;
|
|
18
|
+
private readonly _params;
|
|
19
|
+
constructor(params: ValueTransformPluginParams);
|
|
20
|
+
canTransform(field: string): boolean;
|
|
21
|
+
transform(params: ValueTransformPluginParamsTransformParams): any;
|
|
22
|
+
}
|