@webiny/db-dynamodb 5.15.0-beta.3 → 5.16.0-beta.2
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/README.md +52 -5
- package/package.json +9 -9
- package/plugins/definitions/FieldPlugin.d.ts +5 -0
- package/plugins/definitions/FieldPlugin.js +10 -0
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/utils/attributes.d.ts +5 -0
- package/utils/attributes.js +5 -0
- package/utils/attributes.js.map +1 -1
- package/utils/documentClient.d.ts +5 -0
- package/utils/documentClient.js +5 -0
- package/utils/documentClient.js.map +1 -1
- package/utils/filter.d.ts +2 -2
- package/utils/filter.js +3 -3
- package/utils/filter.js.map +1 -1
- package/utils/get.d.ts +17 -0
- package/utils/get.js +31 -0
- package/utils/get.js.map +1 -0
- package/utils/sort.js +13 -4
- package/utils/sort.js.map +1 -1
- package/utils/table.d.ts +5 -0
- package/utils/table.js +5 -0
- package/utils/table.js.map +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,57 @@ For more information, please visit
|
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
13
|
```
|
|
14
|
-
npm install --save @webiny/db-dynamodb
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Or if you prefer yarn:
|
|
18
|
-
```
|
|
19
14
|
yarn add @webiny/db-dynamodb
|
|
20
15
|
```
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Helper functions
|
|
19
|
+
We have a number [helper](./src/utils) functions that ease the use of either dynamodb-toolbox, filtering, sorting or just creating proper response.
|
|
20
|
+
|
|
21
|
+
#### [batchRead](./src/utils/batchRead.ts)
|
|
22
|
+
Read a batch of records from the DynamoDB table.
|
|
23
|
+
|
|
24
|
+
This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.getBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L313).
|
|
25
|
+
|
|
26
|
+
Internally it reads records until there are no more to read and returns a list of read records.
|
|
27
|
+
|
|
28
|
+
#### [batchWrite](./src/utils/batchWrite.ts)
|
|
29
|
+
Write a batch of records to the DynamoDB table.
|
|
30
|
+
|
|
31
|
+
This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.putBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L989).
|
|
32
|
+
It also accepts a number which defines a number of items to be written in one request. DO NOT put that number over the official DynamoDB maximum.
|
|
33
|
+
|
|
34
|
+
Internally it loops through the items received (in chunks of `maxChunks` parameter) and does not return anything.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
#### [cleanupItem and cleanupItems](./src/utils/cleanup.ts)
|
|
38
|
+
Clean up records received from the DynamoDB table.
|
|
39
|
+
|
|
40
|
+
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and item to be cleaned up, in case of the cleanupItem.
|
|
41
|
+
In case of `cleanupItems` it accepts an array of items to clean up.
|
|
42
|
+
|
|
43
|
+
We use this to remove the properties that dynamodb-toolbox puts on the record automatically.
|
|
44
|
+
|
|
45
|
+
#### [get](./src/utils/get.ts)
|
|
46
|
+
Get a single record from the DynamoDB table with given keys.
|
|
47
|
+
|
|
48
|
+
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and keys to fetch the record by.
|
|
49
|
+
|
|
50
|
+
It returns either record or null. By default, [entity.get()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L281) returns a object with some meta data and `Item` property, which contains the record (or null if no record).
|
|
51
|
+
|
|
52
|
+
#### [queryOne and queryAll](./src/utils/query.ts)
|
|
53
|
+
Query the DynamoDB table for record(s) by given partition key and query options.
|
|
54
|
+
|
|
55
|
+
This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) to perform the query on, `partitionKey` to query by and [options](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts#L65) to define the query parameters with.
|
|
56
|
+
|
|
57
|
+
The `queryAll` method accepts `limit`, a number with which you can load only a certain amount of records. The `queryOne` method does not have that property.
|
|
58
|
+
|
|
59
|
+
#### [filter](./src/utils/filter.ts)
|
|
60
|
+
Filter the DynamoDB records by given where condition.
|
|
61
|
+
|
|
62
|
+
This function accepts items (records) to be filtered, a definition of fields to filter by (not required by default if no field modification is required), where conditions (eg. `{published: true, date_gte: "2021-01-01"}`) and filtering plugins.
|
|
63
|
+
|
|
64
|
+
#### [sort](./src/utils/sort.ts)
|
|
65
|
+
Sort the DynamoDB records by given sort condition.
|
|
66
|
+
|
|
67
|
+
This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.16.0-beta.2",
|
|
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.16.0-beta.2",
|
|
14
|
+
"@webiny/error": "5.16.0-beta.2",
|
|
15
|
+
"@webiny/handler": "5.16.0-beta.2",
|
|
16
|
+
"@webiny/handler-db": "5.16.0-beta.2",
|
|
17
|
+
"@webiny/plugins": "5.16.0-beta.2",
|
|
18
18
|
"date-fns": "2.23.0",
|
|
19
19
|
"dot-prop": "6.0.1",
|
|
20
20
|
"fuse.js": "6.4.6",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.5.5",
|
|
26
26
|
"@babel/core": "^7.5.5",
|
|
27
|
-
"@webiny/cli": "^5.
|
|
28
|
-
"@webiny/project-utils": "^5.
|
|
27
|
+
"@webiny/cli": "^5.16.0-beta.2",
|
|
28
|
+
"@webiny/project-utils": "^5.16.0-beta.2",
|
|
29
29
|
"dynamodb-toolbox": "^0.3.4",
|
|
30
30
|
"jest": "^26.6.3",
|
|
31
31
|
"jest-dynalite": "^3.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"build": "yarn webiny run build",
|
|
42
42
|
"watch": "yarn webiny run watch"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "f8ca0ffc49737da9d2f797382c4df9c701d6f037"
|
|
45
45
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
|
|
3
3
|
export declare type FieldType = DynamoDBTypes & "date" & any;
|
|
4
|
+
export interface TransformValueCb {
|
|
5
|
+
(value: any): any;
|
|
6
|
+
}
|
|
4
7
|
export interface Params {
|
|
5
8
|
/**
|
|
6
9
|
* Default is string.
|
|
@@ -12,6 +15,7 @@ export interface Params {
|
|
|
12
15
|
* Default is true.
|
|
13
16
|
*/
|
|
14
17
|
sortable?: boolean;
|
|
18
|
+
transformValue?: TransformValueCb;
|
|
15
19
|
}
|
|
16
20
|
export declare abstract class FieldPlugin extends Plugin {
|
|
17
21
|
private readonly path;
|
|
@@ -19,6 +23,7 @@ export declare abstract class FieldPlugin extends Plugin {
|
|
|
19
23
|
private readonly fieldType;
|
|
20
24
|
private readonly dynamoDbType;
|
|
21
25
|
private readonly sortable;
|
|
26
|
+
private readonly _transformValue;
|
|
22
27
|
constructor(params: Params);
|
|
23
28
|
getPath(): string;
|
|
24
29
|
getType(): FieldType;
|
|
@@ -19,11 +19,13 @@ class FieldPlugin extends _plugins.Plugin {
|
|
|
19
19
|
(0, _defineProperty2.default)(this, "fieldType", void 0);
|
|
20
20
|
(0, _defineProperty2.default)(this, "dynamoDbType", void 0);
|
|
21
21
|
(0, _defineProperty2.default)(this, "sortable", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "_transformValue", void 0);
|
|
22
23
|
this.fieldType = params.type || "string";
|
|
23
24
|
this.dynamoDbType = params.type === "date" ? "string" : params.type;
|
|
24
25
|
this.field = params.field;
|
|
25
26
|
this.path = params.path;
|
|
26
27
|
this.sortable = params.sortable === undefined ? true : params.sortable;
|
|
28
|
+
this._transformValue = params.transformValue;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
getPath() {
|
|
@@ -39,11 +41,19 @@ class FieldPlugin extends _plugins.Plugin {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
transformValue(value) {
|
|
44
|
+
if (this._transformValue) {
|
|
45
|
+
return this.transformValue(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
switch (this.fieldType) {
|
|
43
49
|
case "number":
|
|
44
50
|
return Number(value);
|
|
45
51
|
|
|
46
52
|
case "date":
|
|
53
|
+
if (!value) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
return new Date(value);
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/definitions/FieldPlugin.ts"],"names":["FieldPlugin","Plugin","constructor","params","fieldType","type","dynamoDbType","field","path","sortable","undefined","getPath","getType","getField","
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/definitions/FieldPlugin.ts"],"names":["FieldPlugin","Plugin","constructor","params","fieldType","type","dynamoDbType","field","path","sortable","undefined","_transformValue","transformValue","getPath","getType","getField","value","Number","Date","isSortable"],"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b-toolbox/dist/classes/Table\";\n\nexport type FieldType = DynamoDBTypes & \"date\" & any;\n\nexport interface TransformValueCb {\n (value: any): any;\n}\n\nexport interface Params {\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: Params) {\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 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"],"file":"FieldPlugin.js"}
|
package/utils/attributes.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { ContextInterface } from "@webiny/handler/types";
|
|
2
2
|
import { DefinitionParams } from "../plugins/definitions/AttributePlugin";
|
|
3
|
+
/**
|
|
4
|
+
* Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
3
8
|
export declare const getExtraAttributes: (context: ContextInterface, entity: string) => Record<string, DefinitionParams>;
|
package/utils/attributes.js
CHANGED
|
@@ -15,6 +15,11 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
15
15
|
|
|
16
16
|
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; }
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
18
23
|
const getExtraAttributes = (context, entity) => {
|
|
19
24
|
return context.plugins.byType(_AttributePlugin.AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
|
|
20
25
|
return _objectSpread(_objectSpread({}, attributes), plugin.getDefinition());
|
package/utils/attributes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/attributes.ts"],"names":["getExtraAttributes","context","entity","plugins","byType","AttributePlugin","type","filter","plugin","reduce","attributes","getDefinition"],"mappings":";;;;;;;;;;;AACA;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/attributes.ts"],"names":["getExtraAttributes","context","entity","plugins","byType","AttributePlugin","type","filter","plugin","reduce","attributes","getDefinition"],"mappings":";;;;;;;;;;;AACA;;;;;;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAC9BC,OAD8B,EAE9BC,MAF8B,KAGK;AACnC,SAAOD,OAAO,CAACE,OAAR,CACFC,MADE,CACsBC,iCAAgBC,IADtC,EAEFC,MAFE,CAEKC,MAAM,IAAIA,MAAM,CAACN,MAAP,KAAkBA,MAFjC,EAGFO,MAHE,CAGK,CAACC,UAAD,EAAaF,MAAb,KAAwB;AAC5B,2CACOE,UADP,GAEOF,MAAM,CAACG,aAAP,EAFP;AAIH,GARE,EAQA,EARA,CAAP;AASH,CAbM","sourcesContent":["import { ContextInterface } from \"@webiny/handler/types\";\nimport { AttributePlugin, DefinitionParams } from \"~/plugins/definitions/AttributePlugin\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: ContextInterface,\n entity: string\n): Record<string, DefinitionParams> => {\n return context.plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"file":"attributes.js"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
2
2
|
import { DbContext } from "@webiny/handler-db/types";
|
|
3
|
+
/**
|
|
4
|
+
* Will be removed in favor of directly passing the documentClient to the storage operations.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
3
8
|
export declare const getDocumentClient: <T extends DbContext>(context: T) => DocumentClient;
|
package/utils/documentClient.js
CHANGED
|
@@ -9,6 +9,11 @@ exports.getDocumentClient = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Will be removed in favor of directly passing the documentClient to the storage operations.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
12
17
|
const getDocumentClient = context => {
|
|
13
18
|
if (!context.db) {
|
|
14
19
|
throw new _error.default("Missing db on context.", "DB_ERROR");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/documentClient.ts"],"names":["getDocumentClient","context","db","WebinyError","driver","documentClient"],"mappings":";;;;;;;;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/documentClient.ts"],"names":["getDocumentClient","context","db","WebinyError","driver","documentClient"],"mappings":";;;;;;;;;AACA;;AAIA;AACA;AACA;AACA;AACA;AACO,MAAMA,iBAAiB,GAAyBC,OAAtB,IAAqD;AAClF,MAAI,CAACA,OAAO,CAACC,EAAb,EAAiB;AACb,UAAM,IAAIC,cAAJ,CAAgB,wBAAhB,EAA0C,UAA1C,CAAN;AACH,GAFD,MAEO,IAAI,CAACF,OAAO,CAACC,EAAR,CAAWE,MAAhB,EAAwB;AAC3B,UAAM,IAAID,cAAJ,CAAiB,4CAAjB,EAA8D,cAA9D,CAAN;AACH;;AACD,QAAMC,MAAM,GAAGH,OAAO,CAACC,EAAR,CAAWE,MAA1B;;AACA,MAAI,CAACA,MAAM,CAACC,cAAZ,EAA4B;AACxB,UAAM,IAAIF,cAAJ,CACD,2DADC,EAEF,uBAFE,CAAN;AAIH;;AACD,SAAOC,MAAM,CAACC,cAAd;AACH,CAdM","sourcesContent":["import { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport WebinyError from \"@webiny/error\";\nimport { DbContext } from \"@webiny/handler-db/types\";\nimport DynamoDbDriver from \"~/DynamoDbDriver\";\n\n/**\n * Will be removed in favor of directly passing the documentClient to the storage operations.\n *\n * @deprecated\n */\nexport const getDocumentClient = <T extends DbContext>(context: T): DocumentClient => {\n if (!context.db) {\n throw new WebinyError(\"Missing db on context.\", \"DB_ERROR\");\n } else if (!context.db.driver) {\n throw new WebinyError(`Missing driver on the context.db property.`, \"DRIVER_ERROR\");\n }\n const driver = context.db.driver as DynamoDbDriver;\n if (!driver.documentClient) {\n throw new WebinyError(\n `Missing documentClient on the context.db.driver property.`,\n \"DOCUMENT_CLIENT_ERROR\"\n );\n }\n return driver.documentClient;\n};\n"],"file":"documentClient.js"}
|
package/utils/filter.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
2
2
|
import { FieldPlugin } from "../plugins/definitions/FieldPlugin";
|
|
3
3
|
export interface Params<T extends any = any> {
|
|
4
|
+
plugins: PluginsContainer;
|
|
4
5
|
items: T[];
|
|
5
6
|
where: Record<string, any>;
|
|
6
|
-
context: ContextInterface;
|
|
7
7
|
fields: FieldPlugin[];
|
|
8
8
|
}
|
|
9
9
|
export declare const filterItems: <T extends unknown = any>(params: Params<T>) => T[];
|
package/utils/filter.js
CHANGED
|
@@ -14,7 +14,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
14
14
|
var _ValueFilterPlugin = require("../plugins/definitions/ValueFilterPlugin");
|
|
15
15
|
|
|
16
16
|
const getMappedPlugins = params => {
|
|
17
|
-
return params.
|
|
17
|
+
return params.plugins.byType(params.type).reduce((plugins, plugin) => {
|
|
18
18
|
const op = plugin[params.property];
|
|
19
19
|
plugins[op] = plugin;
|
|
20
20
|
return plugins;
|
|
@@ -60,7 +60,7 @@ const multiSearchFieldOperations = ["contains", "fuzzy"];
|
|
|
60
60
|
|
|
61
61
|
const createFilters = params => {
|
|
62
62
|
const {
|
|
63
|
-
|
|
63
|
+
plugins,
|
|
64
64
|
where,
|
|
65
65
|
fields
|
|
66
66
|
} = params;
|
|
@@ -74,7 +74,7 @@ const createFilters = params => {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const filterPlugins = getMappedPlugins({
|
|
77
|
-
|
|
77
|
+
plugins,
|
|
78
78
|
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
79
79
|
property: "operation"
|
|
80
80
|
});
|
package/utils/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/filter.ts"],"names":["getMappedPlugins","params","context","plugins","byType","type","reduce","plugin","op","property","extractWhereArgs","key","result","split","field","shift","rawOp","length","join","operation","negate","match","replace","findFilterPlugin","WebinyError","multiSearchFieldOperations","createFilters","where","fields","keys","Object","filterPlugins","ValueFilterPlugin","filters","compareValue","undefined","includes","data","transformValue","paths","map","fieldPlugin","find","getField","value","getPath","push","filterPlugin","path","transform","Array","isArray","v","createFilterCallable","item","filter","some","dotProp","get","matched","matches","filterItems","items"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AA4BA,MAAMA,gBAAgB,GAAsBC,MAAnB,IAAqE;AAC1F,SAAOA,MAAM,CAACC,OAAP,CAAeC,OAAf,CAAuBC,MAAvB,CAAiCH,MAAM,CAACI,IAAxC,EAA8CC,MAA9C,CAAqD,CAACH,OAAD,EAAUI,MAAV,KAAqB;AAC7E,UAAMC,EAAE,GAAGD,MAAM,CAACN,MAAM,CAACQ,QAAR,CAAjB;AACAN,IAAAA,OAAO,CAACK,EAAD,CAAP,GAAcD,MAAd;AACA,WAAOJ,OAAP;AACH,GAJM,EAIJ,EAJI,CAAP;AAKH,CAND;;AAQA,MAAMO,gBAAgB,GAAIC,GAAD,IAAiB;AACtC,QAAMC,MAAM,GAAGD,GAAG,CAACE,KAAJ,CAAU,GAAV,CAAf;AACA,QAAMC,KAAK,GAAGF,MAAM,CAACG,KAAP,EAAd;AACA,QAAMC,KAAK,GAAGJ,MAAM,CAACK,MAAP,KAAkB,CAAlB,GAAsB,IAAtB,GAA6BL,MAAM,CAACM,IAAP,CAAY,GAAZ,CAA3C;AACA;AACJ;AACA;;AACI,MAAIF,KAAK,KAAK,KAAd,EAAqB;AACjB,WAAO;AACHF,MAAAA,KADG;AAEHK,MAAAA,SAAS,EAAE,IAFR;AAGHC,MAAAA,MAAM,EAAE;AAHL,KAAP;AAKH;;AACD,QAAMA,MAAM,GAAGJ,KAAK,CAACK,KAAN,CAAY,MAAZ,MAAwB,IAAvC;AACA,QAAMF,SAAS,GAAGH,KAAK,CAACM,OAAN,CAAc,MAAd,EAAsB,EAAtB,CAAlB;AACA,SAAO;AAAER,IAAAA,KAAF;AAASK,IAAAA,SAAT;AAAoBC,IAAAA;AAApB,GAAP;AACH,CAjBD;;AAmBA,MAAMG,gBAAgB,GAAG,CACrBpB,OADqB,EAErBgB,SAFqB,KAGD;AACpB,MAAIhB,OAAO,CAACgB,SAAD,CA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D,WAAO,IAAP;AACH,GAjBD;AAkBH,CA5BD;;AA8BO,MAAMiD,WAAW,GAAyB5D,MAAtB,IAAiD;AACxE,QAAMsD,MAAM,GAAGF,oBAAoB,CAACpD,MAAD,CAAnC;AACA;AACJ;AACA;;AACI,MAAI,CAACsD,MAAL,EAAa;AACT,WAAOtD,MAAM,CAAC6D,KAAd;AACH;;AACD,SAAO7D,MAAM,CAAC6D,KAAP,CAAaP,MAAb,CAAoBA,MAApB,CAAP;AACH,CATM","sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"~/plugins/definitions/ValueFilterPlugin\";\nimport { ContextInterface } from \"@webiny/handler/types\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\nimport { DynamoDbContainsFilter } from \"~/types\";\n\ntype TransformValue = (value: any) => any;\n\nexport interface Params<T extends any = any> {\n items: T[];\n where: Record<string, any>;\n context: ContextInterface;\n fields: FieldPlugin[];\n}\n\ninterface MappedPluginParams {\n context: ContextInterface;\n type: string;\n property: string;\n}\n\ninterface Filter {\n compareValue: any;\n filterPlugin: ValueFilterPlugin;\n transformValue: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\nconst getMappedPlugins = <T extends Plugin>(params: MappedPluginParams): Record<string, T> => {\n return params.context.plugins.byType<T>(params.type).reduce((plugins, plugin) => {\n const op = plugin[params.property];\n plugins[op] = plugin;\n return plugins;\n }, {});\n};\n\nconst extractWhereArgs = (key: string) => {\n const result = key.split(\"_\");\n const field = result.shift();\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /**\n * When rawOp is not, it means it is equal negated so just return that.\n */\n if (rawOp === \"not\") {\n return {\n field,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return { field, operation, negate };\n};\n\nconst findFilterPlugin = (\n plugins: Record<string, ValueFilterPlugin>,\n operation: string\n): ValueFilterPlugin => {\n if (plugins[operation]) {\n return plugins[operation];\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nconst createFilters = (params: Omit<Params, \"items\">): Filter[] => {\n const { context, where, fields } = params;\n\n const keys = Object.keys(where);\n /**\n * Skip everything if there are no conditions to be applied.\n */\n if (keys.length === 0) {\n return [];\n }\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n context,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n\n return keys.reduce((filters, key) => {\n const compareValue = where[key];\n if (compareValue === undefined) {\n return filters;\n }\n /**\n * @see DynamoDbContainsFilter\n */\n if (multiSearchFieldOperations.includes(key) === true) {\n const data: DynamoDbContainsFilter = compareValue;\n let transformValue: TransformValue = undefined;\n const paths = data.fields.map(field => {\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n return fieldPlugin.getPath();\n }\n return field;\n });\n filters.push({\n compareValue: data.value,\n filterPlugin: findFilterPlugin(filterPlugins, key),\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filterPlugin = findFilterPlugin(filterPlugins, operation);\n\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n let path: string = field;\n let transformValue: TransformValue = undefined;\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n path = fieldPlugin.getPath();\n }\n\n filters.push({\n compareValue,\n filterPlugin,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\n};\n/**\n * Transforms the value with given transformer callable.\n */\nconst transform = (value: any, transformValue?: TransformValue): any => {\n if (!transformValue) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(v => transformValue(v));\n }\n return transformValue(value);\n};\n/**\n * Creates a filter callable that we can send to the .filter() method of the array.\n */\nconst createFilterCallable = (params: Omit<Params, \"items\">): ((item: any) => boolean) | null => {\n const filters = createFilters(params);\n /**\n * Just return null so there are no filters to be applied.\n * Later in the code we check for null so we do not loop through the items.\n */\n if (filters.length === 0) {\n return null;\n }\n\n return (item: any) => {\n for (const filter of filters) {\n const result = filter.paths.some(path => {\n const value = transform(dotProp.get(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filterPlugin.matches({\n value,\n compareValue\n });\n\n return filter.negate ? !matched : matched;\n });\n if (result === false) {\n return false;\n }\n }\n return true;\n };\n};\n\nexport const filterItems = <T extends any = any>(params: Params<T>): T[] => {\n const filter = createFilterCallable(params);\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filter) {\n return params.items;\n }\n return params.items.filter(filter);\n};\n"],"file":"filter.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/filter.ts"],"names":["getMappedPlugins","params","plugins","byType","type","reduce","plugin","op","property","extractWhereArgs","key","result","split","field","shift","rawOp","length","join","operation","negate","match","replace","findFilterPlugin","WebinyError","multiSearchFieldOperations","createFilters","where","fields","keys","Object","filterPlugins","ValueFilterPlugin","filters","compareValue","undefined","includes","data","transformValue","paths","map","fieldPlugin","find","getField","value","getPath","push","filterPlugin","path","transform","Array","isArray","v","createFilterCallable","item","filter","some","dotProp","get","matched","matches","filterItems","items"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AA2BA,MAAMA,gBAAgB,GAAsBC,MAAnB,IAAqE;AAC1F,SAAOA,MAAM,CAACC,OAAP,CAAeC,MAAf,CAAyBF,MAAM,CAACG,IAAhC,EAAsCC,MAAtC,CAA6C,CAACH,OAAD,EAAUI,MAAV,KAAqB;AACrE,UAAMC,EAAE,GAAGD,MAAM,CAACL,MAAM,CAACO,QAAR,CAAjB;AACAN,IAAAA,OAAO,CAACK,EAAD,CAAP,GAAcD,MAAd;AACA,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MAAD,IAAoE;AAC7F,QAAM+B,OAAO,GAAGP,aAAa,CAACxB,MAAD,CAA7B;AACA;AACJ;AACA;AACA;;AACI,MAAI+B,OAAO,CAAChB,MAAR,KAAmB,CAAvB,EAA0B;AACtB,WAAO,IAAP;AACH;;AAED,SAAQqC,IAAD,IAAe;AAClB,SAAK,MAAMC,MAAX,IAAqBtB,OAArB,EAA8B;AAC1B,YAAMrB,MAAM,GAAG2C,MAAM,CAAChB,KAAP,CAAaiB,IAAb,CAAkBR,IAAI,IAAI;AACrC,cAAMJ,KAAK,GAAGK,SAAS,CAACQ,iBAAQC,GAAR,CAAYJ,IAAZ,EAAkBN,IAAlB,CAAD,EAA0BO,MAAM,CAACjB,cAAjC,CAAvB;AACA,cAAMJ,YAAY,GAAGe,SAAS,CAACM,MAAM,CAACrB,YAAR,EAAsBqB,MAAM,CAACjB,cAA7B,CAA9B;AACA,cAAMqB,OAAO,GAAGJ,MAAM,CAACR,YAAP,CAAoBa,OAApB,CAA4B;AACxChB,UAAAA,KADwC;AAExCV,UAAAA;AAFwC,SAA5B,CAAhB;AAKA,eAAOqB,MAAM,CAACnC,MAAP,GAAgB,CAACuC,OAAjB,GAA2BA,OAAlC;AACH,OATc,CAAf;;AAUA,UAAI/C,MAAM,KAAK,KAAf,EAAsB;AAClB,eAAO,KAAP;AACH;AACJ;;AACD,WAAO,IAAP;AACH,GAjBD;AAkBH,CA5BD;;AA8BO,MAAMiD,WAAW,GAAyB3D,MAAtB,IAAiD;AACxE,QAAMqD,MAAM,GAAGF,oBAAoB,CAACnD,MAAD,CAAnC;AACA;AACJ;AACA;;AACI,MAAI,CAACqD,MAAL,EAAa;AACT,WAAOrD,MAAM,CAAC4D,KAAd;AACH;;AACD,SAAO5D,MAAM,CAAC4D,KAAP,CAAaP,MAAb,CAAoBA,MAApB,CAAP;AACH,CATM","sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport { Plugin, PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"~/plugins/definitions/ValueFilterPlugin\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\nimport { DynamoDbContainsFilter } from \"~/types\";\n\ntype TransformValue = (value: any) => any;\n\nexport interface Params<T extends any = any> {\n plugins: PluginsContainer;\n items: T[];\n where: Record<string, any>;\n fields: FieldPlugin[];\n}\n\ninterface MappedPluginParams {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\n\ninterface Filter {\n compareValue: any;\n filterPlugin: ValueFilterPlugin;\n transformValue: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\nconst getMappedPlugins = <T extends Plugin>(params: MappedPluginParams): Record<string, T> => {\n return params.plugins.byType<T>(params.type).reduce((plugins, plugin) => {\n const op = plugin[params.property];\n plugins[op] = plugin;\n return plugins;\n }, {});\n};\n\nconst extractWhereArgs = (key: string) => {\n const result = key.split(\"_\");\n const field = result.shift();\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /**\n * When rawOp is not, it means it is equal negated so just return that.\n */\n if (rawOp === \"not\") {\n return {\n field,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return { field, operation, negate };\n};\n\nconst findFilterPlugin = (\n plugins: Record<string, ValueFilterPlugin>,\n operation: string\n): ValueFilterPlugin => {\n if (plugins[operation]) {\n return plugins[operation];\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nconst createFilters = (params: Omit<Params, \"items\">): Filter[] => {\n const { plugins, where, fields } = params;\n\n const keys = Object.keys(where);\n /**\n * Skip everything if there are no conditions to be applied.\n */\n if (keys.length === 0) {\n return [];\n }\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n\n return keys.reduce((filters, key) => {\n const compareValue = where[key];\n if (compareValue === undefined) {\n return filters;\n }\n /**\n * @see DynamoDbContainsFilter\n */\n if (multiSearchFieldOperations.includes(key) === true) {\n const data: DynamoDbContainsFilter = compareValue;\n let transformValue: TransformValue = undefined;\n const paths = data.fields.map(field => {\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n return fieldPlugin.getPath();\n }\n return field;\n });\n filters.push({\n compareValue: data.value,\n filterPlugin: findFilterPlugin(filterPlugins, key),\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filterPlugin = findFilterPlugin(filterPlugins, operation);\n\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n let path: string = field;\n let transformValue: TransformValue = undefined;\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n path = fieldPlugin.getPath();\n }\n\n filters.push({\n compareValue,\n filterPlugin,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\n};\n/**\n * Transforms the value with given transformer callable.\n */\nconst transform = (value: any, transformValue?: TransformValue): any => {\n if (!transformValue) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(v => transformValue(v));\n }\n return transformValue(value);\n};\n/**\n * Creates a filter callable that we can send to the .filter() method of the array.\n */\nconst createFilterCallable = (params: Omit<Params, \"items\">): ((item: any) => boolean) | null => {\n const filters = createFilters(params);\n /**\n * Just return null so there are no filters to be applied.\n * Later in the code we check for null so we do not loop through the items.\n */\n if (filters.length === 0) {\n return null;\n }\n\n return (item: any) => {\n for (const filter of filters) {\n const result = filter.paths.some(path => {\n const value = transform(dotProp.get(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filterPlugin.matches({\n value,\n compareValue\n });\n\n return filter.negate ? !matched : matched;\n });\n if (result === false) {\n return false;\n }\n }\n return true;\n };\n};\n\nexport const filterItems = <T extends any = any>(params: Params<T>): T[] => {\n const filter = createFilterCallable(params);\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filter) {\n return params.items;\n }\n return params.items.filter(filter);\n};\n"],"file":"filter.js"}
|
package/utils/get.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Entity } from "dynamodb-toolbox";
|
|
2
|
+
export interface Params {
|
|
3
|
+
entity: Entity<any>;
|
|
4
|
+
keys: {
|
|
5
|
+
PK: string;
|
|
6
|
+
SK: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets a single record from the DynamoDB table.
|
|
11
|
+
* Returns either record or null.
|
|
12
|
+
*
|
|
13
|
+
* Be aware to wrap in try/catch to avoid the error killing your app.
|
|
14
|
+
*
|
|
15
|
+
* @throws
|
|
16
|
+
*/
|
|
17
|
+
export declare const get: <T>(params: Params) => Promise<T>;
|
package/utils/get.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.get = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets a single record from the DynamoDB table.
|
|
10
|
+
* Returns either record or null.
|
|
11
|
+
*
|
|
12
|
+
* Be aware to wrap in try/catch to avoid the error killing your app.
|
|
13
|
+
*
|
|
14
|
+
* @throws
|
|
15
|
+
*/
|
|
16
|
+
const get = async params => {
|
|
17
|
+
const {
|
|
18
|
+
entity,
|
|
19
|
+
keys
|
|
20
|
+
} = params;
|
|
21
|
+
const result = await entity.get(keys);
|
|
22
|
+
|
|
23
|
+
if (!result || !result.Item) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result.Item;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.get = get;
|
|
31
|
+
//# sourceMappingURL=get.js.map
|
package/utils/get.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get.ts"],"names":["get","params","entity","keys","result","Item"],"mappings":";;;;;;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,GAAG,GAAG,MAAUC,MAAV,IAAgD;AAC/D,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAmBF,MAAzB;AAEA,QAAMG,MAAM,GAAG,MAAMF,MAAM,CAACF,GAAP,CAAWG,IAAX,CAArB;;AAEA,MAAI,CAACC,MAAD,IAAW,CAACA,MAAM,CAACC,IAAvB,EAA6B;AACzB,WAAO,IAAP;AACH;;AACD,SAAOD,MAAM,CAACC,IAAd;AACH,CATM","sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\n\nexport interface Params {\n entity: Entity<any>;\n keys: {\n PK: string;\n SK: string;\n };\n}\n\n/**\n * Gets a single record from the DynamoDB table.\n * Returns either record or null.\n *\n * Be aware to wrap in try/catch to avoid the error killing your app.\n *\n * @throws\n */\nexport const get = async <T>(params: Params): Promise<T | null> => {\n const { entity, keys } = params;\n\n const result = await entity.get(keys);\n\n if (!result || !result.Item) {\n return null;\n }\n return result.Item;\n};\n"],"file":"get.js"}
|
package/utils/sort.js
CHANGED
|
@@ -31,8 +31,9 @@ const extractSort = (sortBy, fields) => {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const fieldPlugin = fields.find(f => f.getField() === field);
|
|
34
|
+
const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
|
|
34
35
|
|
|
35
|
-
if (
|
|
36
|
+
if (isSortable === false) {
|
|
36
37
|
throw new _error.default(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
|
|
37
38
|
fields,
|
|
38
39
|
field
|
|
@@ -51,11 +52,12 @@ const sortItems = params => {
|
|
|
51
52
|
sort: initialSort = [],
|
|
52
53
|
fields
|
|
53
54
|
} = params;
|
|
55
|
+
/**
|
|
56
|
+
* Skip sorting if nothing was passed to sort by or nothing to sort.
|
|
57
|
+
*/
|
|
54
58
|
|
|
55
|
-
if (items.length <= 1) {
|
|
59
|
+
if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {
|
|
56
60
|
return items;
|
|
57
|
-
} else if (initialSort.length === 0) {
|
|
58
|
-
initialSort.push("createdOn_DESC");
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
const info = {
|
|
@@ -64,6 +66,9 @@ const sortItems = params => {
|
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
for (const sort of initialSort) {
|
|
69
|
+
/**
|
|
70
|
+
* Possibly empty array item was passed.
|
|
71
|
+
*/
|
|
67
72
|
if (!sort) {
|
|
68
73
|
continue;
|
|
69
74
|
}
|
|
@@ -78,6 +83,10 @@ const sortItems = params => {
|
|
|
78
83
|
info.orders.push(reverse === true ? "desc" : "asc");
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
if (info.sorters.length === 0) {
|
|
87
|
+
return items;
|
|
88
|
+
}
|
|
89
|
+
|
|
81
90
|
return (0, _orderBy.default)(items, info.sorters, info.orders);
|
|
82
91
|
};
|
|
83
92
|
|
package/utils/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/sort.ts"],"names":["extractSort","sortBy","fields","result","split","length","WebinyError","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sort.ts"],"names":["extractSort","sortBy","fields","result","split","length","WebinyError","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","Array","isArray","info","sorters","orders","path","getPath","push"],"mappings":";;;;;;;;;AAAA;;AACA;;AAaA,MAAMA,WAAW,GAAG,CAACC,MAAD,EAAiBC,MAAjB,KAAqD;AACrE,QAAMC,MAAM,GAAG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,KAAP;AACH;;AAED,QAAMK,IAAU,GAAG;AACfC,IAAAA,OAAO,EAAE,EADM;AAEfC,IAAAA,MAAM,EAAE;AAFO,GAAnB;;AAKA,OAAK,MAAMN,IAAX,IAAmBC,WAAnB,EAAgC;AAC5B;AACR;AACA;AACQ,QAAI,CAACD,IAAL,EAAW;AACP;AACH;;AACD,UAAM;AAAEZ,MAAAA,KAAF;AAASO,MAAAA;AAAT,QAAqBd,WAAW,CAACmB,IAAD,EAAOjB,MAAP,CAAtC;AACA,UAAMO,WAAW,GAAGP,MAAM,CAACQ,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACC,QAAF,OAAiBL,KAAlC,CAApB;AACA,UAAMmB,IAAI,GAAGjB,WAAW,GAAGA,WAAW,CAACkB,OAAZ,EAAH,GAA2BpB,KAAnD;AAEAgB,IAAAA,IAAI,CAACC,OAAL,CAAaI,IAAb,CAAkBF,IAAlB;AACAH,IAAAA,IAAI,CAACE,MAAL,CAAYG,IAAZ,CAAiBd,OAAO,KAAK,IAAZ,GAAmB,MAAnB,GAA4B,KAA7C;AACH;;AAED,MAAIS,IAAI,CAACC,OAAL,CAAanB,MAAb,KAAwB,CAA5B,EAA+B;AAC3B,WAAOa,KAAP;AACH;;AAED,SAAO,sBAAcA,KAAd,EAAqBK,IAAI,CAACC,OAA1B,EAAmCD,IAAI,CAACE,MAAxC,CAAP;AACH,CAlCM","sourcesContent":["import lodashOrderBy from \"lodash/orderBy\";\nimport WebinyError from \"@webiny/error\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\n\ninterface Info {\n sorters: string[];\n orders: string[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort: string[];\n /**\n * Fields we can sort by.\n */\n fields: FieldPlugin[];\n}\n\nexport const sortItems = <T extends any = any>(params: Params<T>): T[] => {\n const { items, sort: initialSort = [], fields } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n};\n"],"file":"sort.js"}
|
package/utils/table.d.ts
CHANGED
package/utils/table.js
CHANGED
|
@@ -9,6 +9,11 @@ exports.getTable = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Will be removed in favor of passing the table name directly to the storage operations.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
12
17
|
const getTable = context => {
|
|
13
18
|
if (!context.db) {
|
|
14
19
|
throw new _error.default("Missing db on context.", "DB_ERROR");
|
package/utils/table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/table.ts"],"names":["getTable","context","db","WebinyError","table"],"mappings":";;;;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/table.ts"],"names":["getTable","context","db","WebinyError","table"],"mappings":";;;;;;;;;AAAA;;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAyBC,OAAtB,IAA6C;AACjE,MAAI,CAACA,OAAO,CAACC,EAAb,EAAiB;AACb,UAAM,IAAIC,cAAJ,CAAgB,wBAAhB,EAA0C,UAA1C,CAAN;AACH,GAFD,MAEO,IAAI,CAACF,OAAO,CAACC,EAAR,CAAWE,KAAhB,EAAuB;AAC1B,UAAM,IAAID,cAAJ,CAAgB,8BAAhB,EAAgD,aAAhD,CAAN;AACH;;AACD,SAAOF,OAAO,CAACC,EAAR,CAAWE,KAAlB;AACH,CAPM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DbContext } from \"@webiny/handler-db/types\";\n\n/**\n * Will be removed in favor of passing the table name directly to the storage operations.\n *\n * @deprecated\n */\nexport const getTable = <T extends DbContext>(context: T): string => {\n if (!context.db) {\n throw new WebinyError(\"Missing db on context.\", \"DB_ERROR\");\n } else if (!context.db.table) {\n throw new WebinyError(\"Missing table on context.db.\", \"TABLE_ERROR\");\n }\n return context.db.table;\n};\n"],"file":"table.js"}
|