@webiny/db-dynamodb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DynamoDbDriver.d.ts +18 -32
- package/DynamoDbDriver.js +215 -261
- package/DynamoDbDriver.js.map +1 -1
- package/README.md +6 -62
- package/exports/api/db.d.ts +2 -0
- package/exports/api/db.js +2 -0
- package/feature/FilterUtil/FilterUtil.d.ts +11 -0
- package/feature/FilterUtil/FilterUtil.js +26 -0
- package/feature/FilterUtil/FilterUtil.js.map +1 -0
- package/feature/FilterUtil/abstractions/FilterUtil.d.ts +17 -0
- package/feature/FilterUtil/abstractions/FilterUtil.js +5 -0
- package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -0
- package/feature/FilterUtil/createFilters.d.ts +22 -0
- package/feature/FilterUtil/createFilters.js +92 -0
- package/feature/FilterUtil/createFilters.js.map +1 -0
- package/feature/FilterUtil/extractWhereArgs.d.ts +7 -0
- package/feature/FilterUtil/extractWhereArgs.js +20 -0
- package/feature/FilterUtil/extractWhereArgs.js.map +1 -0
- package/feature/FilterUtil/feature.d.ts +4 -0
- package/feature/FilterUtil/feature.js +11 -0
- package/feature/FilterUtil/feature.js.map +1 -0
- package/feature/FilterUtil/index.d.ts +2 -0
- package/feature/FilterUtil/index.js +2 -0
- package/feature/ValueFilter/ValueFilterRegistry.d.ts +12 -0
- package/feature/ValueFilter/ValueFilterRegistry.js +27 -0
- package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -0
- package/feature/ValueFilter/abstractions/ValueFilter.d.ts +22 -0
- package/feature/ValueFilter/abstractions/ValueFilter.js +5 -0
- package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.d.ts +10 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +5 -0
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -0
- package/feature/ValueFilter/feature.d.ts +4 -0
- package/feature/ValueFilter/feature.js +33 -0
- package/feature/ValueFilter/feature.js.map +1 -0
- package/feature/ValueFilter/filters/AndInFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/AndInFilter.js +28 -0
- package/feature/ValueFilter/filters/AndInFilter.js.map +1 -0
- package/feature/ValueFilter/filters/BetweenFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/BetweenFilter.js +31 -0
- package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -0
- package/feature/ValueFilter/filters/ContainsFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/ContainsFilter.js +42 -0
- package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -0
- package/feature/ValueFilter/filters/EqFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/EqFilter.js +24 -0
- package/feature/ValueFilter/filters/EqFilter.js.map +1 -0
- package/feature/ValueFilter/filters/FuzzyFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/FuzzyFilter.js +37 -0
- package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -0
- package/feature/ValueFilter/filters/GtFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/GtFilter.js +22 -0
- package/feature/ValueFilter/filters/GtFilter.js.map +1 -0
- package/feature/ValueFilter/filters/GteFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/GteFilter.js +22 -0
- package/feature/ValueFilter/filters/GteFilter.js.map +1 -0
- package/feature/ValueFilter/filters/InFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/InFilter.js +28 -0
- package/feature/ValueFilter/filters/InFilter.js.map +1 -0
- package/feature/ValueFilter/filters/LtFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/LtFilter.js +22 -0
- package/feature/ValueFilter/filters/LtFilter.js.map +1 -0
- package/feature/ValueFilter/filters/LteFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/LteFilter.js +22 -0
- package/feature/ValueFilter/filters/LteFilter.js.map +1 -0
- package/feature/ValueFilter/filters/StartsWithFilter.d.ts +11 -0
- package/feature/ValueFilter/filters/StartsWithFilter.js +29 -0
- package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -0
- package/feature/ValueFilter/index.d.ts +3 -0
- package/feature/ValueFilter/index.js +3 -0
- package/index.d.ts +5 -1
- package/index.js +12 -14
- package/index.js.map +1 -1
- package/package.json +32 -30
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/DateTimeTransformPlugin.js +21 -50
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.d.ts +2 -2
- package/plugins/definitions/FieldPlugin.js +36 -68
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/TimeTransformPlugin.js +29 -56
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.d.ts +2 -7
- package/plugins/definitions/ValueTransformPlugin.js +20 -46
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +15 -34
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.d.ts +5 -2
- package/plugins/index.js +5 -19
- package/store/entity.d.ts +6 -0
- package/store/entity.js +8 -0
- package/store/entity.js.map +1 -0
- package/store/keys.d.ts +6 -0
- package/store/keys.js +9 -0
- package/store/keys.js.map +1 -0
- package/store/types.d.ts +6 -0
- package/store/types.js +0 -0
- package/toolbox.d.ts +60 -0
- package/toolbox.js +1 -0
- package/types.d.ts +10 -23
- package/types.js +0 -5
- package/utils/batch/batchRead.d.ts +15 -0
- package/utils/batch/batchRead.js +45 -0
- package/utils/batch/batchRead.js.map +1 -0
- package/utils/batch/batchWrite.d.ts +13 -0
- package/utils/batch/batchWrite.js +39 -0
- package/utils/batch/batchWrite.js.map +1 -0
- package/utils/batch/index.d.ts +3 -0
- package/utils/batch/index.js +3 -0
- package/utils/batch/types.d.ts +30 -0
- package/utils/batch/types.js +0 -0
- package/utils/cleanup.d.ts +3 -3
- package/utils/cleanup.js +36 -41
- package/utils/cleanup.js.map +1 -1
- package/utils/count.d.ts +2 -0
- package/utils/count.js +11 -0
- package/utils/count.js.map +1 -0
- package/utils/createEntity.d.ts +36 -0
- package/utils/createEntity.js +82 -0
- package/utils/createEntity.js.map +1 -0
- package/utils/createTable.d.ts +11 -0
- package/utils/createTable.js +29 -0
- package/utils/createTable.js.map +1 -0
- package/utils/cursor.js +8 -23
- package/utils/cursor.js.map +1 -1
- package/utils/delete.d.ts +10 -0
- package/utils/delete.js +9 -0
- package/utils/delete.js.map +1 -0
- package/utils/entity/Entity.d.ts +28 -0
- package/utils/entity/Entity.js +95 -0
- package/utils/entity/Entity.js.map +1 -0
- package/utils/entity/EntityReadBatch.d.ts +18 -0
- package/utils/entity/EntityReadBatch.js +31 -0
- package/utils/entity/EntityReadBatch.js.map +1 -0
- package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
- package/utils/entity/EntityReadBatchBuilder.js +18 -0
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
- package/utils/entity/EntityWriteBatch.d.ts +23 -0
- package/utils/entity/EntityWriteBatch.js +44 -0
- package/utils/entity/EntityWriteBatch.js.map +1 -0
- package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
- package/utils/entity/EntityWriteBatchBuilder.js +19 -0
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
- package/utils/entity/getEntity.d.ts +4 -0
- package/utils/entity/getEntity.js +11 -0
- package/utils/entity/getEntity.js.map +1 -0
- package/utils/entity/index.d.ts +7 -0
- package/utils/entity/index.js +7 -0
- package/utils/entity/types.d.ts +75 -0
- package/utils/entity/types.js +0 -0
- package/utils/get.d.ts +8 -6
- package/utils/get.js +15 -28
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +13 -0
- package/utils/index.js +13 -0
- package/utils/put.d.ts +12 -0
- package/utils/put.js +10 -0
- package/utils/put.js.map +1 -0
- package/utils/query.d.ts +20 -14
- package/utils/query.js +84 -108
- package/utils/query.js.map +1 -1
- package/utils/scan.d.ts +38 -0
- package/utils/scan.js +56 -0
- package/utils/scan.js.map +1 -0
- package/utils/sort.d.ts +1 -1
- package/utils/sort.js +38 -84
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.d.ts +10 -0
- package/utils/table/Table.js +28 -0
- package/utils/table/Table.js.map +1 -0
- package/utils/table/TableReadBatch.d.ts +19 -0
- package/utils/table/TableReadBatch.js +46 -0
- package/utils/table/TableReadBatch.js.map +1 -0
- package/utils/table/TableWriteBatch.d.ts +21 -0
- package/utils/table/TableWriteBatch.js +52 -0
- package/utils/table/TableWriteBatch.js.map +1 -0
- package/utils/table/index.d.ts +4 -0
- package/utils/table/index.js +4 -0
- package/utils/table/types.d.ts +39 -0
- package/utils/table/types.js +0 -0
- package/BatchProcess.d.ts +0 -47
- package/BatchProcess.js +0 -198
- package/BatchProcess.js.map +0 -1
- package/QueryGenerator.d.ts +0 -21
- package/QueryGenerator.js +0 -78
- package/QueryGenerator.js.map +0 -1
- package/operators/comparison/beginsWith.d.ts +0 -3
- package/operators/comparison/beginsWith.js +0 -24
- package/operators/comparison/beginsWith.js.map +0 -1
- package/operators/comparison/between.d.ts +0 -3
- package/operators/comparison/between.js +0 -30
- package/operators/comparison/between.js.map +0 -1
- package/operators/comparison/eq.d.ts +0 -3
- package/operators/comparison/eq.js +0 -34
- package/operators/comparison/eq.js.map +0 -1
- package/operators/comparison/gt.d.ts +0 -3
- package/operators/comparison/gt.js +0 -24
- package/operators/comparison/gt.js.map +0 -1
- package/operators/comparison/gte.d.ts +0 -3
- package/operators/comparison/gte.js +0 -24
- package/operators/comparison/gte.js.map +0 -1
- package/operators/comparison/lt.d.ts +0 -3
- package/operators/comparison/lt.js +0 -24
- package/operators/comparison/lt.js.map +0 -1
- package/operators/comparison/lte.d.ts +0 -3
- package/operators/comparison/lte.js +0 -24
- package/operators/comparison/lte.js.map +0 -1
- package/operators/index.d.ts +0 -12
- package/operators/index.js +0 -39
- package/operators/index.js.map +0 -1
- package/operators/logical/and.d.ts +0 -3
- package/operators/logical/and.js +0 -63
- package/operators/logical/and.js.map +0 -1
- package/operators/logical/or.d.ts +0 -3
- package/operators/logical/or.js +0 -63
- package/operators/logical/or.js.map +0 -1
- package/plugins/definitions/AttributePlugin.d.ts +0 -20
- package/plugins/definitions/AttributePlugin.js +0 -61
- package/plugins/definitions/AttributePlugin.js.map +0 -1
- package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
- package/plugins/definitions/FieldPathPlugin.js +0 -46
- package/plugins/definitions/FieldPathPlugin.js.map +0 -1
- package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
- package/plugins/definitions/NumberTransformPlugin.js +0 -45
- package/plugins/definitions/NumberTransformPlugin.js.map +0 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +0 -20
- package/plugins/definitions/ValueFilterPlugin.js +0 -49
- package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
- package/plugins/filters/andIn.d.ts +0 -3
- package/plugins/filters/andIn.js +0 -35
- package/plugins/filters/andIn.js.map +0 -1
- package/plugins/filters/between.d.ts +0 -3
- package/plugins/filters/between.js +0 -36
- package/plugins/filters/between.js.map +0 -1
- package/plugins/filters/contains.d.ts +0 -3
- package/plugins/filters/contains.js +0 -32
- package/plugins/filters/contains.js.map +0 -1
- package/plugins/filters/eq.d.ts +0 -3
- package/plugins/filters/eq.js +0 -33
- package/plugins/filters/eq.js.map +0 -1
- package/plugins/filters/fuzzy.d.ts +0 -3
- package/plugins/filters/fuzzy.js +0 -30
- package/plugins/filters/fuzzy.js.map +0 -1
- package/plugins/filters/gt.d.ts +0 -3
- package/plugins/filters/gt.js +0 -20
- package/plugins/filters/gt.js.map +0 -1
- package/plugins/filters/gte.d.ts +0 -3
- package/plugins/filters/gte.js +0 -20
- package/plugins/filters/gte.js.map +0 -1
- package/plugins/filters/in.d.ts +0 -3
- package/plugins/filters/in.js +0 -35
- package/plugins/filters/in.js.map +0 -1
- package/plugins/filters/index.d.ts +0 -2
- package/plugins/filters/index.js +0 -34
- package/plugins/filters/index.js.map +0 -1
- package/plugins/filters/lt.d.ts +0 -3
- package/plugins/filters/lt.js +0 -20
- package/plugins/filters/lt.js.map +0 -1
- package/plugins/filters/lte.d.ts +0 -3
- package/plugins/filters/lte.js +0 -20
- package/plugins/filters/lte.js.map +0 -1
- package/plugins/filters/startsWith.d.ts +0 -3
- package/plugins/filters/startsWith.js +0 -33
- package/plugins/filters/startsWith.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/statements/createKeyConditionExpressionArgs.d.ts +0 -15
- package/statements/createKeyConditionExpressionArgs.js +0 -52
- package/statements/createKeyConditionExpressionArgs.js.map +0 -1
- package/statements/processStatement.d.ts +0 -3
- package/statements/processStatement.js +0 -42
- package/statements/processStatement.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/attributes.d.ts +0 -10
- package/utils/attributes.js +0 -31
- package/utils/attributes.js.map +0 -1
- package/utils/batchRead.d.ts +0 -15
- package/utils/batchRead.js +0 -89
- package/utils/batchRead.js.map +0 -1
- package/utils/batchWrite.d.ts +0 -17
- package/utils/batchWrite.js +0 -30
- package/utils/batchWrite.js.map +0 -1
- package/utils/filter.d.ts +0 -12
- package/utils/filter.js +0 -213
- package/utils/filter.js.map +0 -1
- package/utils/listResponse.d.ts +0 -13
- package/utils/listResponse.js +0 -33
- package/utils/listResponse.js.map +0 -1
- package/utils/table.d.ts +0 -7
- package/utils/table.js +0 -27
- package/utils/table.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,67 +1,11 @@
|
|
|
1
1
|
# @webiny/db-dynamodb
|
|
2
|
-
[](https://www.npmjs.com/package/webiny-data-dynamodb)
|
|
3
|
-
[](https://www.npmjs.com/package/webiny-data-dynamodb)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
[the official docs](https://github.com/doitadrian/data-dynamodb).
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
```
|
|
14
|
-
yarn add @webiny/db-dynamodb
|
|
15
|
-
```
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
16
8
|
|
|
9
|
+
---
|
|
17
10
|
|
|
18
|
-
|
|
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).
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FilterUtil as Abstraction } from "./abstractions/FilterUtil.js";
|
|
2
|
+
import { ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
|
|
3
|
+
declare class FilterUtilImpl implements Abstraction.Interface {
|
|
4
|
+
private readonly filterRegistry;
|
|
5
|
+
constructor(filterRegistry: ValueFilterRegistry.Interface);
|
|
6
|
+
filter<T = any>(params: Abstraction.Params<T>): T[];
|
|
7
|
+
}
|
|
8
|
+
export declare const FilterUtil: typeof FilterUtilImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions/FilterUtil.js").IFilterUtil>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FilterUtil } from "./abstractions/FilterUtil.js";
|
|
2
|
+
import { ValueFilterRegistry } from "../ValueFilter/index.js";
|
|
3
|
+
import { createFilterCallable } from "./createFilters.js";
|
|
4
|
+
class FilterUtilImpl {
|
|
5
|
+
constructor(filterRegistry){
|
|
6
|
+
this.filterRegistry = filterRegistry;
|
|
7
|
+
}
|
|
8
|
+
filter(params) {
|
|
9
|
+
const filterFn = createFilterCallable({
|
|
10
|
+
filterRegistry: this.filterRegistry,
|
|
11
|
+
where: params.where,
|
|
12
|
+
fields: params.fields
|
|
13
|
+
});
|
|
14
|
+
if (!filterFn) return params.items;
|
|
15
|
+
return params.items.filter(filterFn);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const FilterUtil_FilterUtil = FilterUtil.createImplementation({
|
|
19
|
+
implementation: FilterUtilImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
ValueFilterRegistry
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
export { FilterUtil_FilterUtil as FilterUtil };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=FilterUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/FilterUtil/FilterUtil.js","sources":["../../../src/feature/FilterUtil/FilterUtil.ts"],"sourcesContent":["import { FilterUtil as Abstraction } from \"./abstractions/FilterUtil.js\";\nimport { ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nimport { createFilterCallable } from \"./createFilters.js\";\n\nclass FilterUtilImpl implements Abstraction.Interface {\n public constructor(private readonly filterRegistry: ValueFilterRegistry.Interface) {}\n\n public filter<T = any>(params: Abstraction.Params<T>): T[] {\n const filterFn = createFilterCallable({\n filterRegistry: this.filterRegistry,\n where: params.where,\n fields: params.fields\n });\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filterFn) {\n return params.items;\n }\n return params.items.filter(filterFn);\n }\n}\n\nexport const FilterUtil = Abstraction.createImplementation({\n implementation: FilterUtilImpl,\n dependencies: [ValueFilterRegistry]\n});\n"],"names":["FilterUtilImpl","filterRegistry","params","filterFn","createFilterCallable","FilterUtil","Abstraction","ValueFilterRegistry"],"mappings":";;;AAIA,MAAMA;IACF,YAAoCC,cAA6C,CAAE;aAA/CA,cAAc,GAAdA;IAAgD;IAE7E,OAAgBC,MAA6B,EAAO;QACvD,MAAMC,WAAWC,qBAAqB;YAClC,gBAAgB,IAAI,CAAC,cAAc;YACnC,OAAOF,OAAO,KAAK;YACnB,QAAQA,OAAO,MAAM;QACzB;QAIA,IAAI,CAACC,UACD,OAAOD,OAAO,KAAK;QAEvB,OAAOA,OAAO,KAAK,CAAC,MAAM,CAACC;IAC/B;AACJ;AAEO,MAAME,wBAAaC,WAAAA,oBAAgC,CAAC;IACvD,gBAAgBN;IAChB,cAAc;QAACO;KAAoB;AACvC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FieldPlugin } from "../../../plugins/definitions/FieldPlugin.js";
|
|
2
|
+
export interface IFilterUtilParams<T = any> {
|
|
3
|
+
items: T[];
|
|
4
|
+
where: Record<string, any>;
|
|
5
|
+
/**
|
|
6
|
+
* An array of fields that require some special operation.
|
|
7
|
+
*/
|
|
8
|
+
fields: FieldPlugin[];
|
|
9
|
+
}
|
|
10
|
+
export interface IFilterUtil {
|
|
11
|
+
filter<T = any>(params: IFilterUtilParams<T>): T[];
|
|
12
|
+
}
|
|
13
|
+
export declare const FilterUtil: import("@webiny/di").Abstraction<IFilterUtil>;
|
|
14
|
+
export declare namespace FilterUtil {
|
|
15
|
+
type Interface = IFilterUtil;
|
|
16
|
+
type Params<T = any> = IFilterUtilParams<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/FilterUtil/abstractions/FilterUtil.js","sources":["../../../../src/feature/FilterUtil/abstractions/FilterUtil.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\nexport interface IFilterUtilParams<T = any> {\n items: T[];\n where: Record<string, any>;\n /**\n * An array of fields that require some special operation.\n */\n fields: FieldPlugin[];\n}\n\nexport interface IFilterUtil {\n filter<T = any>(params: IFilterUtilParams<T>): T[];\n}\n\nexport const FilterUtil = createAbstraction<IFilterUtil>(\"Db/DynamoDB/FilterUtil\");\n\nexport namespace FilterUtil {\n export type Interface = IFilterUtil;\n export type Params<T = any> = IFilterUtilParams<T>;\n}\n"],"names":["FilterUtil","createAbstraction"],"mappings":";AAgBO,MAAMA,aAAaC,kBAA+B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FieldPlugin } from "../../plugins/definitions/FieldPlugin.js";
|
|
2
|
+
import type { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
|
|
3
|
+
type TransformValue = (value: any) => any;
|
|
4
|
+
interface Filter {
|
|
5
|
+
operation: string;
|
|
6
|
+
compareValue: any;
|
|
7
|
+
filter: ValueFilter.Interface;
|
|
8
|
+
transformValue?: TransformValue;
|
|
9
|
+
paths: string[];
|
|
10
|
+
negate: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface CreateFiltersParams {
|
|
13
|
+
filterRegistry: ValueFilterRegistry.Interface;
|
|
14
|
+
where: Record<string, any>;
|
|
15
|
+
fields: FieldPlugin[];
|
|
16
|
+
}
|
|
17
|
+
export declare const createFilters: (params: CreateFiltersParams) => Filter[];
|
|
18
|
+
/**
|
|
19
|
+
* Creates a filter callable that we can send to the .filter() method of the array.
|
|
20
|
+
*/
|
|
21
|
+
export declare const createFilterCallable: (params: CreateFiltersParams) => ((item: any) => boolean) | null;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
2
|
+
import { extractWhereArgs } from "./extractWhereArgs.js";
|
|
3
|
+
import * as __rspack_external_dot_prop_de53db47 from "dot-prop";
|
|
4
|
+
const findFilter = (registry, operation)=>{
|
|
5
|
+
const filter = registry.get(operation);
|
|
6
|
+
if (filter) return filter;
|
|
7
|
+
throw new WebinyError("Missing filter plugin definition.", "FILTER_PLUGIN_ERROR", {
|
|
8
|
+
operation
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const multiSearchFieldOperations = [
|
|
12
|
+
"contains",
|
|
13
|
+
"fuzzy"
|
|
14
|
+
];
|
|
15
|
+
const createFilters = (params)=>{
|
|
16
|
+
const { where, fields, filterRegistry } = params;
|
|
17
|
+
const keys = Object.keys(where);
|
|
18
|
+
if (0 === keys.length) return [];
|
|
19
|
+
return keys.reduce((filters, key)=>{
|
|
20
|
+
const compareValue = where[key];
|
|
21
|
+
if (void 0 === compareValue) return filters;
|
|
22
|
+
if (true === multiSearchFieldOperations.includes(key)) {
|
|
23
|
+
const data = compareValue;
|
|
24
|
+
let transformValue;
|
|
25
|
+
const paths = data.fields.map((field)=>{
|
|
26
|
+
const fieldPlugin = fields.find((plugin)=>plugin.getField() === field);
|
|
27
|
+
if (fieldPlugin) {
|
|
28
|
+
transformValue = (value)=>fieldPlugin.transformValue(value);
|
|
29
|
+
return fieldPlugin.getPath();
|
|
30
|
+
}
|
|
31
|
+
return field;
|
|
32
|
+
});
|
|
33
|
+
const filter = findFilter(filterRegistry, key);
|
|
34
|
+
filters.push({
|
|
35
|
+
operation: filter.operation,
|
|
36
|
+
compareValue: data.value,
|
|
37
|
+
filter,
|
|
38
|
+
transformValue,
|
|
39
|
+
paths,
|
|
40
|
+
negate: false
|
|
41
|
+
});
|
|
42
|
+
return filters;
|
|
43
|
+
}
|
|
44
|
+
const { field, operation, negate } = extractWhereArgs(key);
|
|
45
|
+
const filter = findFilter(filterRegistry, operation);
|
|
46
|
+
const fieldPlugin = fields.find((plugin)=>plugin.getField() === field);
|
|
47
|
+
let path = field;
|
|
48
|
+
let transformValue;
|
|
49
|
+
if (fieldPlugin) {
|
|
50
|
+
transformValue = (value)=>fieldPlugin.transformValue(value);
|
|
51
|
+
path = fieldPlugin.getPath();
|
|
52
|
+
}
|
|
53
|
+
filters.push({
|
|
54
|
+
operation: filter.operation,
|
|
55
|
+
compareValue,
|
|
56
|
+
filter,
|
|
57
|
+
transformValue,
|
|
58
|
+
paths: [
|
|
59
|
+
path
|
|
60
|
+
],
|
|
61
|
+
negate
|
|
62
|
+
});
|
|
63
|
+
return filters;
|
|
64
|
+
}, []);
|
|
65
|
+
};
|
|
66
|
+
const transform = (value, transformValue)=>{
|
|
67
|
+
if (!transformValue) return value;
|
|
68
|
+
if (Array.isArray(value)) return value.map((v)=>transformValue(v));
|
|
69
|
+
return transformValue(value);
|
|
70
|
+
};
|
|
71
|
+
const createFilterCallable = (params)=>{
|
|
72
|
+
const filters = createFilters(params);
|
|
73
|
+
if (0 === filters.length) return null;
|
|
74
|
+
return (item)=>{
|
|
75
|
+
for (const filter of filters){
|
|
76
|
+
const result = filter.paths.some((path)=>{
|
|
77
|
+
const value = transform(__rspack_external_dot_prop_de53db47.getProperty(item, path), filter.transformValue);
|
|
78
|
+
const compareValue = transform(filter.compareValue, filter.transformValue);
|
|
79
|
+
const matched = filter.filter.matches({
|
|
80
|
+
value,
|
|
81
|
+
compareValue
|
|
82
|
+
});
|
|
83
|
+
return filter.negate ? !matched : matched;
|
|
84
|
+
});
|
|
85
|
+
if (false === result) return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export { createFilterCallable, createFilters };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=createFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/FilterUtil/createFilters.js","sources":["../../../src/feature/FilterUtil/createFilters.ts"],"sourcesContent":["import * as dotProp from \"dot-prop\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\nimport type { DynamoDbContainsFilter } from \"~/types.js\";\nimport type { ValueFilter, ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nimport { extractWhereArgs } from \"./extractWhereArgs.js\";\n\ntype TransformValue = (value: any) => any;\n\ninterface Filter {\n operation: string;\n compareValue: any;\n filter: ValueFilter.Interface;\n transformValue?: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\ninterface CreateFiltersParams {\n filterRegistry: ValueFilterRegistry.Interface;\n where: Record<string, any>;\n fields: FieldPlugin[];\n}\n\nconst findFilter = (\n registry: ValueFilterRegistry.Interface,\n operation: string\n): ValueFilter.Interface => {\n const filter = registry.get(operation);\n if (filter) {\n return filter;\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nexport const createFilters = (params: CreateFiltersParams): Filter[] => {\n const { where, fields, filterRegistry } = 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\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 = 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\n const filter = findFilter(filterRegistry, key);\n filters.push({\n operation: filter.operation,\n compareValue: data.value,\n filter,\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filter = findFilter(filterRegistry, operation);\n\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n let path: string = field;\n let transformValue: TransformValue | undefined = undefined;\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n path = fieldPlugin.getPath();\n }\n\n filters.push({\n operation: filter.operation,\n compareValue,\n filter,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\n};\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/**\n * Creates a filter callable that we can send to the .filter() method of the array.\n */\nexport const createFilterCallable = (\n params: CreateFiltersParams\n): ((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.getProperty(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filter.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"],"names":["findFilter","registry","operation","filter","WebinyError","multiSearchFieldOperations","createFilters","params","where","fields","filterRegistry","keys","Object","filters","key","compareValue","undefined","data","transformValue","paths","field","fieldPlugin","plugin","value","negate","extractWhereArgs","path","transform","Array","v","createFilterCallable","item","result","dotProp","matched"],"mappings":";;;AAwBA,MAAMA,aAAa,CACfC,UACAC;IAEA,MAAMC,SAASF,SAAS,GAAG,CAACC;IAC5B,IAAIC,QACA,OAAOA;IAEX,MAAM,IAAIC,YAAY,qCAAqC,uBAAuB;QAC9EF;IACJ;AACJ;AAEA,MAAMG,6BAA6B;IAAC;IAAY;CAAQ;AAEjD,MAAMC,gBAAgB,CAACC;IAC1B,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,cAAc,EAAE,GAAGH;IAE1C,MAAMI,OAAOC,OAAO,IAAI,CAACJ;IAIzB,IAAIG,AAAgB,MAAhBA,KAAK,MAAM,EACX,OAAO,EAAE;IAGb,OAAOA,KAAK,MAAM,CAAC,CAACE,SAASC;QACzB,MAAMC,eAAeP,KAAK,CAACM,IAAI;QAC/B,IAAIC,AAAiBC,WAAjBD,cACA,OAAOF;QAKX,IAAIR,AAA6C,SAA7CA,2BAA2B,QAAQ,CAACS,MAAe;YACnD,MAAMG,OAA+BF;YACrC,IAAIG;YACJ,MAAMC,QAAQF,KAAK,MAAM,CAAC,GAAG,CAACG,CAAAA;gBAC1B,MAAMC,cAAcZ,OAAO,IAAI,CAACa,CAAAA,SAAUA,OAAO,QAAQ,OAAOF;gBAChE,IAAIC,aAAa;oBACbH,iBAAiB,CAACK,QACPF,YAAY,cAAc,CAACE;oBAEtC,OAAOF,YAAY,OAAO;gBAC9B;gBACA,OAAOD;YACX;YAEA,MAAMjB,SAASH,WAAWU,gBAAgBI;YAC1CD,QAAQ,IAAI,CAAC;gBACT,WAAWV,OAAO,SAAS;gBAC3B,cAAcc,KAAK,KAAK;gBACxBd;gBACAe;gBACAC;gBACA,QAAQ;YACZ;YACA,OAAON;QACX;QAEA,MAAM,EAAEO,KAAK,EAAElB,SAAS,EAAEsB,MAAM,EAAE,GAAGC,iBAAiBX;QAEtD,MAAMX,SAASH,WAAWU,gBAAgBR;QAE1C,MAAMmB,cAAcZ,OAAO,IAAI,CAACa,CAAAA,SAAUA,OAAO,QAAQ,OAAOF;QAChE,IAAIM,OAAeN;QACnB,IAAIF;QACJ,IAAIG,aAAa;YACbH,iBAAiB,CAACK,QACPF,YAAY,cAAc,CAACE;YAEtCG,OAAOL,YAAY,OAAO;QAC9B;QAEAR,QAAQ,IAAI,CAAC;YACT,WAAWV,OAAO,SAAS;YAC3BY;YACAZ;YACAe;YACA,OAAO;gBAACQ;aAAK;YACbF;QACJ;QAEA,OAAOX;IACX,GAAG,EAAE;AACT;AAKA,MAAMc,YAAY,CAACJ,OAAYL;IAC3B,IAAI,CAACA,gBACD,OAAOK;IAEX,IAAIK,MAAM,OAAO,CAACL,QACd,OAAOA,MAAM,GAAG,CAACM,CAAAA,IAAKX,eAAeW;IAEzC,OAAOX,eAAeK;AAC1B;AAKO,MAAMO,uBAAuB,CAChCvB;IAEA,MAAMM,UAAUP,cAAcC;IAK9B,IAAIM,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAO;IAGX,OAAO,CAACkB;QACJ,KAAK,MAAM5B,UAAUU,QAAS;YAC1B,MAAMmB,SAAS7B,OAAO,KAAK,CAAC,IAAI,CAACuB,CAAAA;gBAC7B,MAAMH,QAAQI,UAAUM,oCAAAA,WAAmB,CAACF,MAAML,OAAOvB,OAAO,cAAc;gBAC9E,MAAMY,eAAeY,UAAUxB,OAAO,YAAY,EAAEA,OAAO,cAAc;gBACzE,MAAM+B,UAAU/B,OAAO,MAAM,CAAC,OAAO,CAAC;oBAClCoB;oBACAR;gBACJ;gBAEA,OAAOZ,OAAO,MAAM,GAAG,CAAC+B,UAAUA;YACtC;YACA,IAAIF,AAAW,UAAXA,QACA,OAAO;QAEf;QACA,OAAO;IACX;AACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const extractWhereArgs = (key)=>{
|
|
2
|
+
const result = key.split("_");
|
|
3
|
+
const field = result.shift();
|
|
4
|
+
const rawOp = 0 === result.length ? "eq" : result.join("_");
|
|
5
|
+
if ("not" === rawOp) return {
|
|
6
|
+
field,
|
|
7
|
+
operation: "eq",
|
|
8
|
+
negate: true
|
|
9
|
+
};
|
|
10
|
+
const negate = null !== rawOp.match("not_");
|
|
11
|
+
const operation = rawOp.replace("not_", "");
|
|
12
|
+
return {
|
|
13
|
+
field,
|
|
14
|
+
operation,
|
|
15
|
+
negate
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export { extractWhereArgs };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=extractWhereArgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/FilterUtil/extractWhereArgs.js","sources":["../../../src/feature/FilterUtil/extractWhereArgs.ts"],"sourcesContent":["interface ExtractWhereArgsResult {\n field: string;\n operation: string;\n negate: boolean;\n}\n\nexport const extractWhereArgs = (key: string): ExtractWhereArgsResult => {\n const result = key.split(\"_\");\n const field = result.shift() as string;\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 {\n field,\n operation,\n negate\n };\n};\n"],"names":["extractWhereArgs","key","result","field","rawOp","negate","operation"],"mappings":"AAMO,MAAMA,mBAAmB,CAACC;IAC7B,MAAMC,SAASD,IAAI,KAAK,CAAC;IACzB,MAAME,QAAQD,OAAO,KAAK;IAC1B,MAAME,QAAQF,AAAkB,MAAlBA,OAAO,MAAM,GAAS,OAAOA,OAAO,IAAI,CAAC;IAIvD,IAAIE,AAAU,UAAVA,OACA,OAAO;QACHD;QACA,WAAW;QACX,QAAQ;IACZ;IAEJ,MAAME,SAASD,AAAwB,SAAxBA,MAAM,KAAK,CAAC;IAC3B,MAAME,YAAYF,MAAM,OAAO,CAAC,QAAQ;IACxC,OAAO;QACHD;QACAG;QACAD;IACJ;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { FilterUtil } from "./FilterUtil.js";
|
|
3
|
+
const FilterUtilFeature = createFeature({
|
|
4
|
+
name: "Db/DynamoDB/FilterUtilFeature",
|
|
5
|
+
register: (container)=>{
|
|
6
|
+
container.register(FilterUtil);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { FilterUtilFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/FilterUtil/feature.js","sources":["../../../src/feature/FilterUtil/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FilterUtil } from \"./FilterUtil.js\";\n\nexport const FilterUtilFeature = createFeature({\n name: \"Db/DynamoDB/FilterUtilFeature\",\n register: container => {\n container.register(FilterUtil);\n }\n});\n"],"names":["FilterUtilFeature","createFeature","container","FilterUtil"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValueFilterRegistry as Abstraction } from "./abstractions/ValueFilterRegistry.js";
|
|
2
|
+
import { ValueFilter } from "./abstractions/ValueFilter.js";
|
|
3
|
+
declare class ValueFilterRegistryImpl implements Abstraction.Interface {
|
|
4
|
+
private readonly filters;
|
|
5
|
+
constructor(filters: ValueFilter.Interface[]);
|
|
6
|
+
get(operation: string): ValueFilter.Interface | undefined;
|
|
7
|
+
getAll(): ValueFilter.Interface[];
|
|
8
|
+
}
|
|
9
|
+
export declare const ValueFilterRegistry: typeof ValueFilterRegistryImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions/ValueFilterRegistry.js").IValueFilterRegistry>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ValueFilterRegistry } from "./abstractions/ValueFilterRegistry.js";
|
|
2
|
+
import { ValueFilter } from "./abstractions/ValueFilter.js";
|
|
3
|
+
class ValueFilterRegistryImpl {
|
|
4
|
+
constructor(filters){
|
|
5
|
+
this.filters = filters;
|
|
6
|
+
}
|
|
7
|
+
get(operation) {
|
|
8
|
+
return this.filters.find((filter)=>filter.is(operation));
|
|
9
|
+
}
|
|
10
|
+
getAll() {
|
|
11
|
+
return this.filters;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const ValueFilterRegistry_ValueFilterRegistry = ValueFilterRegistry.createImplementation({
|
|
15
|
+
implementation: ValueFilterRegistryImpl,
|
|
16
|
+
dependencies: [
|
|
17
|
+
[
|
|
18
|
+
ValueFilter,
|
|
19
|
+
{
|
|
20
|
+
multiple: true
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
export { ValueFilterRegistry_ValueFilterRegistry as ValueFilterRegistry };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=ValueFilterRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/ValueFilterRegistry.js","sources":["../../../src/feature/ValueFilter/ValueFilterRegistry.ts"],"sourcesContent":["import { ValueFilterRegistry as Abstraction } from \"./abstractions/ValueFilterRegistry.js\";\nimport { ValueFilter } from \"./abstractions/ValueFilter.js\";\n\nclass ValueFilterRegistryImpl implements Abstraction.Interface {\n public constructor(private readonly filters: ValueFilter.Interface[]) {}\n\n public get(operation: string): ValueFilter.Interface | undefined {\n return this.filters.find(filter => {\n return filter.is(operation);\n });\n }\n\n public getAll(): ValueFilter.Interface[] {\n return this.filters;\n }\n}\n\nexport const ValueFilterRegistry = Abstraction.createImplementation({\n implementation: ValueFilterRegistryImpl,\n dependencies: [[ValueFilter, { multiple: true }]]\n});\n"],"names":["ValueFilterRegistryImpl","filters","operation","filter","ValueFilterRegistry","Abstraction","ValueFilter"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,OAAgC,CAAE;aAAlCA,OAAO,GAAPA;IAAmC;IAEhE,IAAIC,SAAiB,EAAqC;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAACC,CAAAA,SACdA,OAAO,EAAE,CAACD;IAEzB;IAEO,SAAkC;QACrC,OAAO,IAAI,CAAC,OAAO;IACvB;AACJ;AAEO,MAAME,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgBL;IAChB,cAAc;QAAC;YAACM;YAAa;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface IValueFilterCanUseParams<TValue = any, TCompareValue = any> {
|
|
2
|
+
value: TValue;
|
|
3
|
+
compareValue: TCompareValue;
|
|
4
|
+
}
|
|
5
|
+
export interface IValueFilterMatchesParams<TValue = any, TCompareValue = any> {
|
|
6
|
+
value: TValue;
|
|
7
|
+
compareValue: TCompareValue;
|
|
8
|
+
}
|
|
9
|
+
export type IValueFilterMatchesResult = boolean;
|
|
10
|
+
export interface IValueFilter<TValue = any, TCompareValue = any> {
|
|
11
|
+
readonly operation: string;
|
|
12
|
+
is(operation: string): boolean;
|
|
13
|
+
canUse(params: IValueFilterCanUseParams): boolean;
|
|
14
|
+
matches(params: IValueFilterMatchesParams<TValue, TCompareValue>): IValueFilterMatchesResult;
|
|
15
|
+
}
|
|
16
|
+
export declare const ValueFilter: import("@webiny/di").Abstraction<IValueFilter<any, any>>;
|
|
17
|
+
export declare namespace ValueFilter {
|
|
18
|
+
type Interface<TValue = any, TCompareValue = any> = IValueFilter<TValue, TCompareValue>;
|
|
19
|
+
type CanUseParams = IValueFilterCanUseParams;
|
|
20
|
+
type MatchesParams = IValueFilterMatchesParams;
|
|
21
|
+
type Result = IValueFilterMatchesResult;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/abstractions/ValueFilter.js","sources":["../../../../src/feature/ValueFilter/abstractions/ValueFilter.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IValueFilterCanUseParams<TValue = any, TCompareValue = any> {\n value: TValue;\n compareValue: TCompareValue;\n}\n\nexport interface IValueFilterMatchesParams<TValue = any, TCompareValue = any> {\n value: TValue;\n compareValue: TCompareValue;\n}\n\nexport type IValueFilterMatchesResult = boolean;\n\nexport interface IValueFilter<TValue = any, TCompareValue = any> {\n readonly operation: string;\n is(operation: string): boolean;\n canUse(params: IValueFilterCanUseParams): boolean;\n matches(params: IValueFilterMatchesParams<TValue, TCompareValue>): IValueFilterMatchesResult;\n}\n\nexport const ValueFilter = createAbstraction<IValueFilter>(\"Db/DynamoDB/ValueFilter\");\n\nexport namespace ValueFilter {\n export type Interface<TValue = any, TCompareValue = any> = IValueFilter<TValue, TCompareValue>;\n export type CanUseParams = IValueFilterCanUseParams;\n export type MatchesParams = IValueFilterMatchesParams;\n export type Result = IValueFilterMatchesResult;\n}\n"],"names":["ValueFilter","createAbstraction"],"mappings":";AAqBO,MAAMA,cAAcC,kBAAgC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ValueFilter } from "./ValueFilter.js";
|
|
2
|
+
export interface IValueFilterRegistry {
|
|
3
|
+
get(operation: string): ValueFilter.Interface | undefined;
|
|
4
|
+
getAll(): ValueFilter.Interface[];
|
|
5
|
+
}
|
|
6
|
+
export declare const ValueFilterRegistry: import("@webiny/di").Abstraction<IValueFilterRegistry>;
|
|
7
|
+
export declare namespace ValueFilterRegistry {
|
|
8
|
+
type Interface = IValueFilterRegistry;
|
|
9
|
+
type Filter = ValueFilter.Interface;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/abstractions/ValueFilterRegistry.js","sources":["../../../../src/feature/ValueFilter/abstractions/ValueFilterRegistry.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ValueFilter } from \"./ValueFilter.js\";\n\nexport interface IValueFilterRegistry {\n get(operation: string): ValueFilter.Interface | undefined;\n getAll(): ValueFilter.Interface[];\n}\n\nexport const ValueFilterRegistry = createAbstraction<IValueFilterRegistry>(\n \"Db/DynamoDB/ValueFilterRegistry\"\n);\n\nexport namespace ValueFilterRegistry {\n export type Interface = IValueFilterRegistry;\n export type Filter = ValueFilter.Interface;\n}\n"],"names":["ValueFilterRegistry","createAbstraction"],"mappings":";AAQO,MAAMA,sBAAsBC,kBAC/B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { EqFilter } from "./filters/EqFilter.js";
|
|
3
|
+
import { GtFilter } from "./filters/GtFilter.js";
|
|
4
|
+
import { GteFilter } from "./filters/GteFilter.js";
|
|
5
|
+
import { LtFilter } from "./filters/LtFilter.js";
|
|
6
|
+
import { LteFilter } from "./filters/LteFilter.js";
|
|
7
|
+
import { BetweenFilter } from "./filters/BetweenFilter.js";
|
|
8
|
+
import { InFilter } from "./filters/InFilter.js";
|
|
9
|
+
import { AndInFilter } from "./filters/AndInFilter.js";
|
|
10
|
+
import { ContainsFilter } from "./filters/ContainsFilter.js";
|
|
11
|
+
import { FuzzyFilter } from "./filters/FuzzyFilter.js";
|
|
12
|
+
import { StartsWithFilter } from "./filters/StartsWithFilter.js";
|
|
13
|
+
import { ValueFilterRegistry } from "./ValueFilterRegistry.js";
|
|
14
|
+
const ValueFilterFeature = createFeature({
|
|
15
|
+
name: "Db/DynamoDB/ValueFilterFeature",
|
|
16
|
+
register: (container)=>{
|
|
17
|
+
container.register(EqFilter);
|
|
18
|
+
container.register(GtFilter);
|
|
19
|
+
container.register(GteFilter);
|
|
20
|
+
container.register(LtFilter);
|
|
21
|
+
container.register(LteFilter);
|
|
22
|
+
container.register(BetweenFilter);
|
|
23
|
+
container.register(InFilter);
|
|
24
|
+
container.register(AndInFilter);
|
|
25
|
+
container.register(ContainsFilter);
|
|
26
|
+
container.register(FuzzyFilter);
|
|
27
|
+
container.register(StartsWithFilter);
|
|
28
|
+
container.register(ValueFilterRegistry);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export { ValueFilterFeature };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/feature.js","sources":["../../../src/feature/ValueFilter/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { EqFilter } from \"./filters/EqFilter.js\";\nimport { GtFilter } from \"./filters/GtFilter.js\";\nimport { GteFilter } from \"./filters/GteFilter.js\";\nimport { LtFilter } from \"./filters/LtFilter.js\";\nimport { LteFilter } from \"./filters/LteFilter.js\";\nimport { BetweenFilter } from \"./filters/BetweenFilter.js\";\nimport { InFilter } from \"./filters/InFilter.js\";\nimport { AndInFilter } from \"./filters/AndInFilter.js\";\nimport { ContainsFilter } from \"./filters/ContainsFilter.js\";\nimport { FuzzyFilter } from \"./filters/FuzzyFilter.js\";\nimport { StartsWithFilter } from \"./filters/StartsWithFilter.js\";\nimport { ValueFilterRegistry } from \"./ValueFilterRegistry.js\";\n\nexport const ValueFilterFeature = createFeature({\n name: \"Db/DynamoDB/ValueFilterFeature\",\n register: container => {\n container.register(EqFilter);\n container.register(GtFilter);\n container.register(GteFilter);\n container.register(LtFilter);\n container.register(LteFilter);\n container.register(BetweenFilter);\n container.register(InFilter);\n container.register(AndInFilter);\n container.register(ContainsFilter);\n container.register(FuzzyFilter);\n container.register(StartsWithFilter);\n container.register(ValueFilterRegistry);\n }\n});\n"],"names":["ValueFilterFeature","createFeature","container","EqFilter","GtFilter","GteFilter","LtFilter","LteFilter","BetweenFilter","InFilter","AndInFilter","ContainsFilter","FuzzyFilter","StartsWithFilter","ValueFilterRegistry"],"mappings":";;;;;;;;;;;;;AAcO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;IACvB;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
+
declare class AndInFilterImpl implements ValueFilter.Interface {
|
|
3
|
+
readonly operation = "and_in";
|
|
4
|
+
is(operation: string): boolean;
|
|
5
|
+
canUse(): boolean;
|
|
6
|
+
matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result;
|
|
7
|
+
}
|
|
8
|
+
export declare const AndInFilter: typeof AndInFilterImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("../abstractions/ValueFilter.js").IValueFilter<any, any>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
2
|
+
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
+
class AndInFilterImpl {
|
|
4
|
+
is(operation) {
|
|
5
|
+
return this.operation === operation;
|
|
6
|
+
}
|
|
7
|
+
canUse() {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
matches({ value, compareValue }) {
|
|
11
|
+
if (!compareValue || false === Array.isArray(compareValue)) throw new WebinyError('The value given as "compareValue" must be an array!', "COMPARE_VALUE_ERROR", {
|
|
12
|
+
value,
|
|
13
|
+
compareValue
|
|
14
|
+
});
|
|
15
|
+
if (true === Array.isArray(value)) return compareValue.every((c)=>value.includes(c));
|
|
16
|
+
return compareValue.includes(value);
|
|
17
|
+
}
|
|
18
|
+
constructor(){
|
|
19
|
+
this.operation = "and_in";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const AndInFilter = ValueFilter.createImplementation({
|
|
23
|
+
implementation: AndInFilterImpl,
|
|
24
|
+
dependencies: []
|
|
25
|
+
});
|
|
26
|
+
export { AndInFilter };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=AndInFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/filters/AndInFilter.js","sources":["../../../../src/feature/ValueFilter/filters/AndInFilter.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { ValueFilter } from \"../abstractions/ValueFilter.js\";\n\nclass AndInFilterImpl implements ValueFilter.Interface {\n public readonly operation = \"and_in\";\n\n public is(operation: string): boolean {\n return this.operation === operation;\n }\n\n public canUse(): boolean {\n return true;\n }\n\n public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {\n if (!compareValue || Array.isArray(compareValue) === false) {\n throw new WebinyError(\n `The value given as \"compareValue\" must be an array!`,\n \"COMPARE_VALUE_ERROR\",\n {\n value,\n compareValue\n }\n );\n }\n if (Array.isArray(value) === true) {\n return compareValue.every((c: any) => value.includes(c));\n }\n return compareValue.includes(value);\n }\n}\n\nexport const AndInFilter = ValueFilter.createImplementation({\n implementation: AndInFilterImpl,\n dependencies: []\n});\n"],"names":["AndInFilterImpl","operation","value","compareValue","Array","WebinyError","c","AndInFilter","ValueFilter"],"mappings":";;AAGA,MAAMA;IAGK,GAAGC,SAAiB,EAAW;QAClC,OAAO,IAAI,CAAC,SAAS,KAAKA;IAC9B;IAEO,SAAkB;QACrB,OAAO;IACX;IAEO,QAAQ,EAAEC,KAAK,EAAEC,YAAY,EAA6B,EAAsB;QACnF,IAAI,CAACA,gBAAgBC,AAAgC,UAAhCA,MAAM,OAAO,CAACD,eAC/B,MAAM,IAAIE,YACN,uDACA,uBACA;YACIH;YACAC;QACJ;QAGR,IAAIC,AAAyB,SAAzBA,MAAM,OAAO,CAACF,QACd,OAAOC,aAAa,KAAK,CAAC,CAACG,IAAWJ,MAAM,QAAQ,CAACI;QAEzD,OAAOH,aAAa,QAAQ,CAACD;IACjC;;aAzBgB,SAAS,GAAG;;AA0BhC;AAEO,MAAMK,cAAcC,YAAY,oBAAoB,CAAC;IACxD,gBAAgBR;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
2
|
+
declare class BetweenFilterImpl implements ValueFilter.Interface {
|
|
3
|
+
readonly operation = "between";
|
|
4
|
+
is(operation: string): boolean;
|
|
5
|
+
canUse(): boolean;
|
|
6
|
+
matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result;
|
|
7
|
+
}
|
|
8
|
+
export declare const BetweenFilter: typeof BetweenFilterImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("../abstractions/ValueFilter.js").IValueFilter<any, any>>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WebinyError } from "@webiny/error";
|
|
2
|
+
import { ValueFilter } from "../abstractions/ValueFilter.js";
|
|
3
|
+
class BetweenFilterImpl {
|
|
4
|
+
is(operation) {
|
|
5
|
+
return this.operation === operation;
|
|
6
|
+
}
|
|
7
|
+
canUse() {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
matches({ value, compareValue }) {
|
|
11
|
+
if (Array.isArray(compareValue)) {
|
|
12
|
+
if (2 !== compareValue.length) throw new WebinyError("When comparing between and you give an array, there must be two items in it.", "FILTER_ERROR", {
|
|
13
|
+
value,
|
|
14
|
+
compareValue
|
|
15
|
+
});
|
|
16
|
+
const [from, to] = compareValue;
|
|
17
|
+
return value >= from && value <= to;
|
|
18
|
+
}
|
|
19
|
+
return value >= compareValue && value <= compareValue;
|
|
20
|
+
}
|
|
21
|
+
constructor(){
|
|
22
|
+
this.operation = "between";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const BetweenFilter = ValueFilter.createImplementation({
|
|
26
|
+
implementation: BetweenFilterImpl,
|
|
27
|
+
dependencies: []
|
|
28
|
+
});
|
|
29
|
+
export { BetweenFilter };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=BetweenFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/ValueFilter/filters/BetweenFilter.js","sources":["../../../../src/feature/ValueFilter/filters/BetweenFilter.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { ValueFilter } from \"../abstractions/ValueFilter.js\";\n\nclass BetweenFilterImpl implements ValueFilter.Interface {\n public readonly operation = \"between\";\n\n public is(operation: string): boolean {\n return this.operation === operation;\n }\n\n public canUse(): boolean {\n return true;\n }\n\n public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {\n if (Array.isArray(compareValue)) {\n if (compareValue.length !== 2) {\n throw new WebinyError(\n \"When comparing between and you give an array, there must be two items in it.\",\n \"FILTER_ERROR\",\n {\n value,\n compareValue\n }\n );\n }\n const [from, to] = compareValue;\n return value >= from && value <= to;\n }\n return value >= compareValue && value <= compareValue;\n }\n}\n\nexport const BetweenFilter = ValueFilter.createImplementation({\n implementation: BetweenFilterImpl,\n dependencies: []\n});\n"],"names":["BetweenFilterImpl","operation","value","compareValue","Array","WebinyError","from","to","BetweenFilter","ValueFilter"],"mappings":";;AAGA,MAAMA;IAGK,GAAGC,SAAiB,EAAW;QAClC,OAAO,IAAI,CAAC,SAAS,KAAKA;IAC9B;IAEO,SAAkB;QACrB,OAAO;IACX;IAEO,QAAQ,EAAEC,KAAK,EAAEC,YAAY,EAA6B,EAAsB;QACnF,IAAIC,MAAM,OAAO,CAACD,eAAe;YAC7B,IAAIA,AAAwB,MAAxBA,aAAa,MAAM,EACnB,MAAM,IAAIE,YACN,gFACA,gBACA;gBACIH;gBACAC;YACJ;YAGR,MAAM,CAACG,MAAMC,GAAG,GAAGJ;YACnB,OAAOD,SAASI,QAAQJ,SAASK;QACrC;QACA,OAAOL,SAASC,gBAAgBD,SAASC;IAC7C;;aA1BgB,SAAS,GAAG;;AA2BhC;AAEO,MAAMK,gBAAgBC,YAAY,oBAAoB,CAAC;IAC1D,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}
|