@webiny/db-dynamodb 0.0.0-unstable.b14eaecf38 → 0.0.0-unstable.b6d7105cee
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 +216 -227
- package/DynamoDbDriver.js.map +1 -1
- package/README.md +6 -62
- package/exports/api/db.d.ts +3 -0
- package/exports/api/db.js +3 -0
- package/feature/DynamoDBClient/DynamoDBClient.d.ts +9 -0
- package/feature/DynamoDBClient/DynamoDBClient.js +8 -0
- package/feature/DynamoDBClient/DynamoDBClient.js.map +1 -0
- package/feature/DynamoDBClient/abstractions.d.ts +8 -0
- package/feature/DynamoDBClient/abstractions.js +5 -0
- package/feature/DynamoDBClient/abstractions.js.map +1 -0
- package/feature/DynamoDBClient/index.d.ts +6 -0
- package/feature/DynamoDBClient/index.js +15 -0
- package/feature/DynamoDBClient/index.js.map +1 -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/index.d.ts +3 -0
- package/feature/ValueFilter/index.js +1 -0
- package/index.d.ts +10 -3
- package/index.js +14 -35
- package/index.js.map +1 -1
- package/package.json +32 -30
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/DateTimeTransformPlugin.js +22 -37
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.d.ts +2 -2
- package/plugins/definitions/FieldPlugin.js +37 -53
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.d.ts +2 -1
- package/plugins/definitions/TimeTransformPlugin.js +30 -43
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.d.ts +2 -7
- package/plugins/definitions/ValueTransformPlugin.js +21 -34
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +16 -26
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.d.ts +5 -2
- package/plugins/index.js +5 -15
- 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 +3 -24
- 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 -31
- 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 +9 -18
- 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 +16 -25
- 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 +15 -14
- package/utils/query.js +83 -107
- 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 +39 -68
- 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 -164
- package/BatchProcess.js.map +0 -1
- package/QueryGenerator.d.ts +0 -21
- package/QueryGenerator.js +0 -64
- 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 -32
- 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 -28
- package/operators/index.js.map +0 -1
- package/operators/logical/and.d.ts +0 -3
- package/operators/logical/and.js +0 -58
- package/operators/logical/and.js.map +0 -1
- package/operators/logical/or.d.ts +0 -3
- package/operators/logical/or.js +0 -58
- package/operators/logical/or.js.map +0 -1
- package/plugins/definitions/AttributePlugin.d.ts +0 -20
- package/plugins/definitions/AttributePlugin.js +0 -48
- package/plugins/definitions/AttributePlugin.js.map +0 -1
- package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
- package/plugins/definitions/FieldPathPlugin.js +0 -34
- package/plugins/definitions/FieldPathPlugin.js.map +0 -1
- package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
- package/plugins/definitions/NumberTransformPlugin.js +0 -34
- package/plugins/definitions/NumberTransformPlugin.js.map +0 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +0 -20
- package/plugins/definitions/ValueFilterPlugin.js +0 -37
- package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
- package/plugins/filters/andIn.d.ts +0 -3
- package/plugins/filters/andIn.js +0 -30
- package/plugins/filters/andIn.js.map +0 -1
- package/plugins/filters/between.d.ts +0 -3
- package/plugins/filters/between.js +0 -31
- package/plugins/filters/between.js.map +0 -1
- package/plugins/filters/contains.d.ts +0 -3
- package/plugins/filters/contains.js +0 -29
- package/plugins/filters/contains.js.map +0 -1
- package/plugins/filters/eq.d.ts +0 -3
- package/plugins/filters/eq.js +0 -31
- package/plugins/filters/eq.js.map +0 -1
- package/plugins/filters/fuzzy.d.ts +0 -3
- package/plugins/filters/fuzzy.js +0 -26
- package/plugins/filters/fuzzy.js.map +0 -1
- package/plugins/filters/gt.d.ts +0 -3
- package/plugins/filters/gt.js +0 -19
- package/plugins/filters/gt.js.map +0 -1
- package/plugins/filters/gte.d.ts +0 -3
- package/plugins/filters/gte.js +0 -19
- package/plugins/filters/gte.js.map +0 -1
- package/plugins/filters/in.d.ts +0 -3
- package/plugins/filters/in.js +0 -30
- package/plugins/filters/in.js.map +0 -1
- package/plugins/filters/index.d.ts +0 -2
- package/plugins/filters/index.js +0 -20
- package/plugins/filters/index.js.map +0 -1
- package/plugins/filters/lt.d.ts +0 -3
- package/plugins/filters/lt.js +0 -19
- package/plugins/filters/lt.js.map +0 -1
- package/plugins/filters/lte.d.ts +0 -3
- package/plugins/filters/lte.js +0 -19
- package/plugins/filters/lte.js.map +0 -1
- package/plugins/filters/startsWith.d.ts +0 -3
- package/plugins/filters/startsWith.js +0 -29
- 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 -45
- package/statements/createKeyConditionExpressionArgs.js.map +0 -1
- package/statements/processStatement.d.ts +0 -3
- package/statements/processStatement.js +0 -35
- 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 -24
- package/utils/attributes.js.map +0 -1
- package/utils/batchRead.d.ts +0 -15
- package/utils/batchRead.js +0 -67
- package/utils/batchRead.js.map +0 -1
- package/utils/batchWrite.d.ts +0 -17
- package/utils/batchWrite.js +0 -24
- package/utils/batchWrite.js.map +0 -1
- package/utils/createStandardEntity.d.ts +0 -2
- package/utils/createStandardEntity.js +0 -34
- package/utils/createStandardEntity.js.map +0 -1
- package/utils/filter.d.ts +0 -12
- package/utils/filter.js +0 -176
- package/utils/filter.js.map +0 -1
- package/utils/listResponse.d.ts +0 -13
- package/utils/listResponse.js +0 -29
- package/utils/listResponse.js.map +0 -1
- package/utils/table.d.ts +0 -7
- package/utils/table.js +0 -22
- package/utils/table.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
import type { DynamoDBClient as Abstraction } from "./abstractions.js";
|
|
3
|
+
export interface IDynamoDBClientParams {
|
|
4
|
+
client: DynamoDBDocument;
|
|
5
|
+
}
|
|
6
|
+
export declare class DynamoDBClient implements Abstraction.Interface {
|
|
7
|
+
readonly client: DynamoDBDocument;
|
|
8
|
+
constructor(params: IDynamoDBClientParams);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/DynamoDBClient/DynamoDBClient.js","sources":["../../../src/feature/DynamoDBClient/DynamoDBClient.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { DynamoDBClient as Abstraction } from \"./abstractions.js\";\n\nexport interface IDynamoDBClientParams {\n client: DynamoDBDocument;\n}\n\nexport class DynamoDBClient implements Abstraction.Interface {\n public readonly client: DynamoDBDocument;\n\n public constructor(params: IDynamoDBClientParams) {\n this.client = params.client;\n }\n}\n"],"names":["DynamoDBClient","params"],"mappings":"AAOO,MAAMA;IAGT,YAAmBC,MAA6B,CAAE;QAC9C,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;IAC/B;AACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export interface IDynamoDBClient {
|
|
3
|
+
readonly client: DynamoDBDocument;
|
|
4
|
+
}
|
|
5
|
+
export declare const DynamoDBClient: import("@webiny/di").Abstraction<IDynamoDBClient>;
|
|
6
|
+
export declare namespace DynamoDBClient {
|
|
7
|
+
type Interface = IDynamoDBClient;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/DynamoDBClient/abstractions.js","sources":["../../../src/feature/DynamoDBClient/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport interface IDynamoDBClient {\n readonly client: DynamoDBDocument;\n}\n\nexport const DynamoDBClient = createAbstraction<IDynamoDBClient>(\"Db/DynamoDB/DynamoDBClient\");\n\nexport namespace DynamoDBClient {\n export type Interface = IDynamoDBClient;\n}\n"],"names":["DynamoDBClient","createAbstraction"],"mappings":";AAOO,MAAMA,iBAAiBC,kBAAmC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
2
|
+
export { DynamoDBClient } from "./abstractions.js";
|
|
3
|
+
export declare const DynamoDBClientFeature: {
|
|
4
|
+
name: string;
|
|
5
|
+
register(container: import("@webiny/di").Container, context: DynamoDBDocument): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { DynamoDBClient } from "./abstractions.js";
|
|
3
|
+
import { DynamoDBClient as external_DynamoDBClient_js_DynamoDBClient } from "./DynamoDBClient.js";
|
|
4
|
+
const DynamoDBClientFeature = createFeature({
|
|
5
|
+
name: "Db/DynamoDB/DynamoDBClientFeature",
|
|
6
|
+
register (container, documentClient) {
|
|
7
|
+
const client = new external_DynamoDBClient_js_DynamoDBClient({
|
|
8
|
+
client: documentClient
|
|
9
|
+
});
|
|
10
|
+
container.registerInstance(DynamoDBClient, client);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export { DynamoDBClient, DynamoDBClientFeature };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/DynamoDBClient/index.js","sources":["../../../src/feature/DynamoDBClient/index.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport { DynamoDBClient as DynamoDBClientAbstraction } from \"./abstractions.js\";\nimport { DynamoDBClient } from \"./DynamoDBClient.js\";\n\nexport { DynamoDBClient } from \"./abstractions.js\";\n\nexport const DynamoDBClientFeature = createFeature<DynamoDBDocument>({\n name: \"Db/DynamoDB/DynamoDBClientFeature\",\n register(container, documentClient) {\n const client = new DynamoDBClient({ client: documentClient });\n container.registerInstance(DynamoDBClientAbstraction, client);\n }\n});\n"],"names":["DynamoDBClientFeature","createFeature","container","documentClient","client","DynamoDBClient","DynamoDBClientAbstraction"],"mappings":";;;AAOO,MAAMA,wBAAwBC,cAAgC;IACjE,MAAM;IACN,UAASC,SAAS,EAAEC,cAAc;QAC9B,MAAMC,SAAS,IAAIC,0CAAe;YAAE,QAAQF;QAAe;QAC3DD,UAAU,gBAAgB,CAACI,gBAA2BF;IAC1D;AACJ"}
|
|
@@ -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_0ebbd169 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_0ebbd169.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 @@
|
|
|
1
|
+
export { ValueFilter, ValueFilterFeature, ValueFilterRegistry } from "@webiny/db-utils";
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { default as DynamoDbDriver } from "./DynamoDbDriver";
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { default as DynamoDbDriver } from "./DynamoDbDriver.js";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb/index.js";
|
|
3
|
+
export * from "./utils/index.js";
|
|
4
|
+
export * from "./plugins/index.js";
|
|
5
|
+
export type { DbItem } from "./types.js";
|
|
4
6
|
export { DynamoDbDriver };
|
|
7
|
+
interface IRegisterDbDynamoDbExtension {
|
|
8
|
+
documentClient: DynamoDBDocument;
|
|
9
|
+
}
|
|
10
|
+
export { DynamoDBClient } from "./feature/DynamoDBClient/index.js";
|
|
11
|
+
export declare const registerDynamoDBCore: ({ documentClient }: IRegisterDbDynamoDbExtension) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
|
package/index.js
CHANGED
|
@@ -1,36 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
2
|
+
import { DynamoDBClient, DynamoDBClientFeature } from "./feature/DynamoDBClient/index.js";
|
|
3
|
+
import { ValueFilterFeature } from "@webiny/db-utils";
|
|
4
|
+
import { FilterUtilFeature } from "./feature/FilterUtil/index.js";
|
|
5
|
+
export * from "./utils/index.js";
|
|
6
|
+
export * from "./plugins/index.js";
|
|
7
|
+
const registerDynamoDBCore = ({ documentClient })=>createRegisterExtensionPlugin(async (context)=>{
|
|
8
|
+
DynamoDBClientFeature.register(context.container, documentClient);
|
|
9
|
+
FilterUtilFeature.register(context.container);
|
|
10
|
+
ValueFilterFeature.register(context.container);
|
|
11
|
+
});
|
|
12
|
+
export { default as DynamoDbDriver } from "./DynamoDbDriver.js";
|
|
13
|
+
export { DynamoDBClient, registerDynamoDBCore };
|
|
2
14
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {
|
|
8
|
-
DynamoDbDriver: true,
|
|
9
|
-
DbItem: true
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "DbItem", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return _types.DbItem;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "DynamoDbDriver", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _DynamoDbDriver.default;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
var _DynamoDbDriver = _interopRequireDefault(require("./DynamoDbDriver"));
|
|
24
|
-
var _createStandardEntity = require("./utils/createStandardEntity");
|
|
25
|
-
Object.keys(_createStandardEntity).forEach(function (key) {
|
|
26
|
-
if (key === "default" || key === "__esModule") return;
|
|
27
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
-
if (key in exports && exports[key] === _createStandardEntity[key]) return;
|
|
29
|
-
Object.defineProperty(exports, key, {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return _createStandardEntity[key];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
var _types = require("./types");
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { default as DynamoDbDriver } from \"./DynamoDbDriver.js\";\nimport { ValueFilterFeature } from \"@webiny/db-utils\";\nimport { FilterUtilFeature } from \"~/feature/FilterUtil/index.js\";\nimport { DynamoDBClientFeature } from \"~/feature/DynamoDBClient/index.js\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\n\nexport * from \"./utils/index.js\";\nexport * from \"./plugins/index.js\";\nexport type { DbItem } from \"./types.js\";\n\nexport { DynamoDbDriver };\n\ninterface IRegisterDbDynamoDbExtension {\n documentClient: DynamoDBDocument;\n}\n\nexport { DynamoDBClient } from \"~/feature/DynamoDBClient/index.js\";\n\nexport const registerDynamoDBCore = ({ documentClient }: IRegisterDbDynamoDbExtension) => {\n return createRegisterExtensionPlugin(async context => {\n DynamoDBClientFeature.register(context.container, documentClient);\n FilterUtilFeature.register(context.container);\n ValueFilterFeature.register(context.container);\n });\n};\n"],"names":["registerDynamoDBCore","documentClient","createRegisterExtensionPlugin","context","DynamoDBClientFeature","FilterUtilFeature","ValueFilterFeature"],"mappings":";;;;;;AAmBO,MAAMA,uBAAuB,CAAC,EAAEC,cAAc,EAAgC,GAC1EC,8BAA8B,OAAMC;QACvCC,sBAAsB,QAAQ,CAACD,QAAQ,SAAS,EAAEF;QAClDI,kBAAkB,QAAQ,CAACF,QAAQ,SAAS;QAC5CG,mBAAmB,QAAQ,CAACH,QAAQ,SAAS;IACjD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.b6d7105cee",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -10,37 +14,35 @@
|
|
|
10
14
|
"author": "Webiny Ltd",
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"dependencies": {
|
|
13
|
-
"@webiny/api": "0.0.0-unstable.
|
|
14
|
-
"@webiny/
|
|
15
|
-
"@webiny/
|
|
16
|
-
"@webiny/
|
|
17
|
-
"@webiny/
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
17
|
+
"@webiny/api": "0.0.0-unstable.b6d7105cee",
|
|
18
|
+
"@webiny/aws-sdk": "0.0.0-unstable.b6d7105cee",
|
|
19
|
+
"@webiny/db": "0.0.0-unstable.b6d7105cee",
|
|
20
|
+
"@webiny/db-utils": "0.0.0-unstable.b6d7105cee",
|
|
21
|
+
"@webiny/error": "0.0.0-unstable.b6d7105cee",
|
|
22
|
+
"@webiny/feature": "0.0.0-unstable.b6d7105cee",
|
|
23
|
+
"@webiny/handler": "0.0.0-unstable.b6d7105cee",
|
|
24
|
+
"@webiny/plugins": "0.0.0-unstable.b6d7105cee",
|
|
25
|
+
"@webiny/utils": "0.0.0-unstable.b6d7105cee",
|
|
26
|
+
"date-fns": "4.4.0",
|
|
27
|
+
"dot-prop": "10.2.0",
|
|
28
|
+
"dynamodb-toolbox": "0.9.5",
|
|
29
|
+
"lodash": "4.18.1"
|
|
23
30
|
},
|
|
24
31
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@webiny/
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"rimraf": "^3.0.2",
|
|
34
|
-
"ttypescript": "^1.5.12",
|
|
35
|
-
"typescript": "4.7.4"
|
|
32
|
+
"@types/is-number": "7.0.5",
|
|
33
|
+
"@webiny/build-tools": "0.0.0-unstable.b6d7105cee",
|
|
34
|
+
"@webiny/di": "1.0.2",
|
|
35
|
+
"@webiny/project-utils": "0.0.0-unstable.b6d7105cee",
|
|
36
|
+
"jest-dynalite": "3.6.1",
|
|
37
|
+
"rimraf": "6.1.3",
|
|
38
|
+
"typescript": "7.0.2",
|
|
39
|
+
"vitest": "4.1.10"
|
|
36
40
|
},
|
|
37
41
|
"publishConfig": {
|
|
38
|
-
"access": "public"
|
|
39
|
-
"directory": "dist"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "yarn webiny run build",
|
|
43
|
-
"watch": "yarn webiny run watch"
|
|
42
|
+
"access": "public"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
45
|
+
"webiny": {
|
|
46
|
+
"publishFrom": "dist"
|
|
47
|
+
}
|
|
46
48
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ValueTransformPluginParams } from "./ValueTransformPlugin.js";
|
|
2
|
+
import { ValueTransformPlugin } from "./ValueTransformPlugin.js";
|
|
2
3
|
export declare class DateTimeTransformPlugin extends ValueTransformPlugin {
|
|
3
4
|
constructor(params: Omit<ValueTransformPluginParams, "transform">);
|
|
4
5
|
}
|
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
value
|
|
15
|
-
} = params;
|
|
16
|
-
if (value === null) {
|
|
1
|
+
import { ValueTransformPlugin } from "./ValueTransformPlugin.js";
|
|
2
|
+
import { parseISO } from "date-fns";
|
|
3
|
+
const transformDateTime = (params)=>{
|
|
4
|
+
const { value } = params;
|
|
5
|
+
if (null == value) return null;
|
|
6
|
+
if ("string" == typeof value) {
|
|
7
|
+
const parsedDateTime = parseISO(value).getTime();
|
|
8
|
+
if (false === isNaN(parsedDateTime)) return parsedDateTime;
|
|
9
|
+
} else if (value instanceof Date || "function" == typeof value?.getTime) return value.getTime();
|
|
10
|
+
console.warn("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
|
|
11
|
+
value
|
|
12
|
+
});
|
|
17
13
|
return null;
|
|
18
|
-
}
|
|
19
|
-
if (value && typeof value.getTime === "function") {
|
|
20
|
-
/**
|
|
21
|
-
* In this case we assume this is a date object and we just get the time.
|
|
22
|
-
*/
|
|
23
|
-
return value.getTime();
|
|
24
|
-
}
|
|
25
|
-
const parsedDateTime = (0, _dateFns.parseISO)(value).getTime();
|
|
26
|
-
if (isNaN(parsedDateTime) === false) {
|
|
27
|
-
return parsedDateTime;
|
|
28
|
-
}
|
|
29
|
-
throw new _error.default("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
|
|
30
|
-
value
|
|
31
|
-
});
|
|
32
14
|
};
|
|
33
|
-
class DateTimeTransformPlugin extends
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
class DateTimeTransformPlugin extends ValueTransformPlugin {
|
|
16
|
+
constructor(params){
|
|
17
|
+
super({
|
|
18
|
+
transform: transformDateTime,
|
|
19
|
+
...params
|
|
20
|
+
});
|
|
21
|
+
}
|
|
39
22
|
}
|
|
40
|
-
|
|
23
|
+
export { DateTimeTransformPlugin };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=DateTimeTransformPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/definitions/DateTimeTransformPlugin.js","sources":["../../../src/plugins/definitions/DateTimeTransformPlugin.ts"],"sourcesContent":["import type {\n ValueTransformPluginParams,\n ValueTransformPluginParamsTransformParams\n} from \"./ValueTransformPlugin.js\";\nimport { ValueTransformPlugin } from \"./ValueTransformPlugin.js\";\nimport { parseISO } from \"date-fns\";\n\nconst transformDateTime = (params: ValueTransformPluginParamsTransformParams): number | null => {\n const { value } = params;\n if (value === null || value === undefined) {\n return null;\n } else if (typeof value === \"string\") {\n const parsedDateTime = parseISO(value).getTime();\n if (isNaN(parsedDateTime) === false) {\n return parsedDateTime;\n }\n } else if (value instanceof Date || typeof (value as unknown as Date)?.getTime === \"function\") {\n /**\n * In this case we assume this is a date object, and we just get the time.\n */\n return value.getTime();\n }\n /**\n * No point in throwing an error here, as this would cause the entire transformation to fail. Instead, we just log a warning and return null.\n */\n console.warn(\"Could not parse given dateTime value.\", \"PARSE_DATE_ERROR\", {\n value\n });\n return null;\n};\n\nexport class DateTimeTransformPlugin extends ValueTransformPlugin {\n public constructor(params: Omit<ValueTransformPluginParams, \"transform\">) {\n super({\n transform: transformDateTime,\n ...params\n });\n }\n}\n"],"names":["transformDateTime","params","value","parsedDateTime","parseISO","isNaN","Date","console","DateTimeTransformPlugin","ValueTransformPlugin"],"mappings":";;AAOA,MAAMA,oBAAoB,CAACC;IACvB,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIC,QAAAA,OACA,OAAO;IACJ,IAAI,AAAiB,YAAjB,OAAOA,OAAoB;QAClC,MAAMC,iBAAiBC,SAASF,OAAO,OAAO;QAC9C,IAAIG,AAA0B,UAA1BA,MAAMF,iBACN,OAAOA;IAEf,OAAO,IAAID,iBAAiBI,QAAQ,AAA+C,cAA/C,OAAQJ,OAA2B,SAInE,OAAOA,MAAM,OAAO;IAKxBK,QAAQ,IAAI,CAAC,yCAAyC,oBAAoB;QACtEL;IACJ;IACA,OAAO;AACX;AAEO,MAAMM,gCAAgCC;IACzC,YAAmBR,MAAqD,CAAE;QACtE,KAAK,CAAC;YACF,WAAWD;YACX,GAAGC,MAAM;QACb;IACJ;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import { DynamoDBTypes } from "
|
|
3
|
-
export
|
|
2
|
+
import type { DynamoDBTypes } from "../../toolbox.js";
|
|
3
|
+
export type FieldType = DynamoDBTypes & "date" & any;
|
|
4
4
|
export interface TransformValueCb {
|
|
5
5
|
(value: any): any;
|
|
6
6
|
}
|