@webiny/db-dynamodb 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
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 +23 -25
- package/DynamoDbDriver.js +232 -240
- package/DynamoDbDriver.js.map +1 -0
- package/README.md +81 -1
- package/index.d.ts +2 -0
- package/index.js +18 -3
- package/index.js.map +1 -0
- package/package.json +19 -22
- package/plugins/definitions/AttributePlugin.d.ts +6 -8
- package/plugins/definitions/AttributePlugin.js +5 -20
- package/plugins/definitions/AttributePlugin.js.map +1 -0
- package/plugins/definitions/DateTimeTransformPlugin.d.ts +3 -2
- package/plugins/definitions/DateTimeTransformPlugin.js +16 -28
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -0
- package/plugins/definitions/FieldPathPlugin.d.ts +3 -3
- package/plugins/definitions/FieldPathPlugin.js +7 -21
- package/plugins/definitions/FieldPathPlugin.js.map +1 -0
- package/plugins/definitions/FieldPlugin.d.ts +5 -5
- package/plugins/definitions/FieldPlugin.js +2 -24
- package/plugins/definitions/FieldPlugin.js.map +1 -0
- package/plugins/definitions/TimeTransformPlugin.d.ts +3 -2
- package/plugins/definitions/TimeTransformPlugin.js +19 -30
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -0
- package/plugins/definitions/ValueFilterPlugin.d.ts +13 -11
- package/plugins/definitions/ValueFilterPlugin.js +10 -16
- package/plugins/definitions/ValueFilterPlugin.js.map +1 -0
- package/plugins/definitions/ValueTransformPlugin.d.ts +9 -9
- package/plugins/definitions/ValueTransformPlugin.js +7 -22
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -0
- package/plugins/definitions/assignFields.js +3 -10
- package/plugins/definitions/assignFields.js.map +1 -0
- package/plugins/filters/andIn.d.ts +2 -2
- package/plugins/filters/andIn.js +5 -9
- package/plugins/filters/andIn.js.map +1 -0
- package/plugins/filters/between.d.ts +2 -2
- package/plugins/filters/between.js +5 -9
- package/plugins/filters/between.js.map +1 -0
- package/plugins/filters/contains.d.ts +2 -2
- package/plugins/filters/contains.js +44 -17
- package/plugins/filters/contains.js.map +1 -0
- package/plugins/filters/eq.d.ts +2 -2
- package/plugins/filters/eq.js +17 -5
- package/plugins/filters/eq.js.map +1 -0
- package/plugins/filters/fuzzy.d.ts +2 -2
- package/plugins/filters/fuzzy.js +18 -12
- package/plugins/filters/fuzzy.js.map +1 -0
- package/plugins/filters/gt.d.ts +2 -2
- package/plugins/filters/gt.js +4 -4
- package/plugins/filters/gt.js.map +1 -0
- package/plugins/filters/gte.d.ts +2 -2
- package/plugins/filters/gte.js +4 -4
- package/plugins/filters/gte.js.map +1 -0
- package/plugins/filters/in.d.ts +2 -2
- package/plugins/filters/in.js +5 -9
- package/plugins/filters/in.js.map +1 -0
- package/plugins/filters/index.d.ts +1 -1
- package/plugins/filters/index.js +5 -15
- package/plugins/filters/index.js.map +1 -0
- package/plugins/filters/lt.d.ts +2 -2
- package/plugins/filters/lt.js +4 -4
- package/plugins/filters/lt.js.map +1 -0
- package/plugins/filters/lte.d.ts +2 -2
- package/plugins/filters/lte.js +4 -4
- package/plugins/filters/lte.js.map +1 -0
- package/plugins/filters/startsWith.d.ts +3 -0
- package/plugins/filters/startsWith.js +40 -0
- package/plugins/filters/startsWith.js.map +1 -0
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +3 -5
- package/plugins/index.js.map +1 -0
- package/store/entity.d.ts +78 -0
- package/store/entity.js +41 -0
- package/store/entity.js.map +1 -0
- package/store/keys.d.ts +6 -0
- package/store/keys.js +22 -0
- package/store/keys.js.map +1 -0
- package/store/types.d.ts +7 -0
- package/store/types.js +7 -0
- package/store/types.js.map +1 -0
- package/toolbox.d.ts +3 -0
- package/toolbox.js +20 -0
- package/toolbox.js.map +1 -0
- package/types.d.ts +37 -21
- package/types.js +3 -1
- package/types.js.map +1 -0
- package/utils/attributes.d.ts +5 -5
- package/utils/attributes.js +6 -14
- package/utils/attributes.js.map +1 -0
- package/utils/batch/batchRead.d.ts +15 -0
- package/utils/batch/batchRead.js +72 -0
- package/utils/batch/batchRead.js.map +1 -0
- package/utils/batch/batchWrite.d.ts +13 -0
- package/utils/batch/batchWrite.js +65 -0
- package/utils/batch/batchWrite.js.map +1 -0
- package/utils/batch/index.d.ts +3 -0
- package/utils/batch/index.js +40 -0
- package/utils/batch/index.js.map +1 -0
- package/utils/batch/types.d.ts +25 -0
- package/utils/batch/types.js +7 -0
- package/utils/batch/types.js.map +1 -0
- package/utils/cleanup.d.ts +3 -3
- package/utils/cleanup.js +11 -27
- package/utils/cleanup.js.map +1 -0
- package/utils/count.d.ts +2 -0
- package/utils/count.js +23 -0
- package/utils/count.js.map +1 -0
- package/utils/createEntity.d.ts +54 -0
- package/utils/createEntity.js +61 -0
- package/utils/createEntity.js.map +1 -0
- package/utils/createTable.d.ts +8 -0
- package/utils/createTable.js +29 -0
- package/utils/createTable.js.map +1 -0
- package/utils/cursor.d.ts +2 -2
- package/utils/cursor.js +2 -6
- package/utils/cursor.js.map +1 -0
- package/utils/delete.d.ts +10 -0
- package/utils/delete.js +18 -0
- package/utils/delete.js.map +1 -0
- package/utils/entity/Entity.d.ts +26 -0
- package/utils/entity/Entity.js +77 -0
- package/utils/entity/Entity.js.map +1 -0
- package/utils/entity/EntityReadBatch.d.ts +17 -0
- package/utils/entity/EntityReadBatch.js +41 -0
- package/utils/entity/EntityReadBatch.js.map +1 -0
- package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
- package/utils/entity/EntityReadBatchBuilder.js +29 -0
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
- package/utils/entity/EntityWriteBatch.d.ts +22 -0
- package/utils/entity/EntityWriteBatch.js +59 -0
- package/utils/entity/EntityWriteBatch.js.map +1 -0
- package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
- package/utils/entity/EntityWriteBatchBuilder.js +28 -0
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
- package/utils/entity/getEntity.d.ts +4 -0
- package/utils/entity/getEntity.js +19 -0
- package/utils/entity/getEntity.js.map +1 -0
- package/utils/entity/index.d.ts +7 -0
- package/utils/entity/index.js +84 -0
- package/utils/entity/index.js.map +1 -0
- package/utils/entity/types.d.ts +51 -0
- package/utils/entity/types.js +7 -0
- package/utils/entity/types.js.map +1 -0
- package/utils/filter.d.ts +4 -4
- package/utils/filter.js +12 -43
- package/utils/filter.js.map +1 -0
- package/utils/get.d.ts +10 -8
- package/utils/get.js +16 -7
- package/utils/get.js.map +1 -0
- package/utils/index.d.ts +17 -0
- package/utils/index.js +194 -0
- package/utils/index.js.map +1 -0
- package/utils/listResponse.d.ts +1 -1
- package/utils/listResponse.js +8 -7
- package/utils/listResponse.js.map +1 -0
- package/utils/put.d.ts +12 -0
- package/utils/put.js +19 -0
- package/utils/put.js.map +1 -0
- package/utils/query.d.ts +20 -8
- package/utils/query.js +71 -38
- package/utils/query.js.map +1 -0
- package/utils/scan.d.ts +38 -0
- package/utils/scan.js +90 -0
- package/utils/scan.js.map +1 -0
- package/utils/sort.d.ts +3 -3
- package/utils/sort.js +5 -22
- package/utils/sort.js.map +1 -0
- package/utils/table/Table.d.ts +11 -0
- package/utils/table/Table.js +38 -0
- package/utils/table/Table.js.map +1 -0
- package/utils/table/TableReadBatch.d.ts +19 -0
- package/utils/table/TableReadBatch.js +62 -0
- package/utils/table/TableReadBatch.js.map +1 -0
- package/utils/table/TableWriteBatch.d.ts +21 -0
- package/utils/table/TableWriteBatch.js +69 -0
- package/utils/table/TableWriteBatch.js.map +1 -0
- package/utils/table/index.d.ts +4 -0
- package/utils/table/index.js +51 -0
- package/utils/table/index.js.map +1 -0
- package/utils/table/types.d.ts +39 -0
- package/utils/table/types.js +7 -0
- package/utils/table/types.js.map +1 -0
- package/utils/update.d.ts +12 -0
- package/utils/update.js +19 -0
- package/utils/update.js.map +1 -0
- package/BatchProcess.d.ts +0 -31
- package/BatchProcess.js +0 -196
- package/QueryGenerator.d.ts +0 -19
- package/QueryGenerator.js +0 -79
- package/operators/comparison/beginsWith.d.ts +0 -3
- package/operators/comparison/beginsWith.js +0 -24
- package/operators/comparison/between.d.ts +0 -3
- package/operators/comparison/between.js +0 -30
- package/operators/comparison/eq.d.ts +0 -3
- package/operators/comparison/eq.js +0 -34
- package/operators/comparison/gt.d.ts +0 -3
- package/operators/comparison/gt.js +0 -24
- package/operators/comparison/gte.d.ts +0 -3
- package/operators/comparison/gte.js +0 -24
- package/operators/comparison/lt.d.ts +0 -3
- package/operators/comparison/lt.js +0 -24
- package/operators/comparison/lte.d.ts +0 -3
- package/operators/comparison/lte.js +0 -24
- package/operators/index.d.ts +0 -12
- package/operators/index.js +0 -39
- package/operators/logical/and.d.ts +0 -3
- package/operators/logical/and.js +0 -63
- package/operators/logical/or.d.ts +0 -3
- package/operators/logical/or.js +0 -63
- package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
- package/plugins/definitions/NumberTransformPlugin.js +0 -49
- package/statements/createKeyConditionExpressionArgs.d.ts +0 -12
- package/statements/createKeyConditionExpressionArgs.js +0 -48
- package/statements/processStatement.d.ts +0 -4
- package/statements/processStatement.js +0 -39
- package/utils/batchRead.d.ts +0 -15
- package/utils/batchRead.js +0 -58
- package/utils/batchWrite.d.ts +0 -17
- package/utils/batchWrite.js +0 -30
- package/utils/documentClient.d.ts +0 -8
- package/utils/documentClient.js +0 -33
- package/utils/table.d.ts +0 -7
- package/utils/table.js +0 -27
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _Entity = require("./Entity");
|
|
7
|
+
Object.keys(_Entity).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _Entity[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _Entity[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _EntityReadBatch = require("./EntityReadBatch");
|
|
18
|
+
Object.keys(_EntityReadBatch).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _EntityReadBatch[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _EntityReadBatch[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _EntityReadBatchBuilder = require("./EntityReadBatchBuilder");
|
|
29
|
+
Object.keys(_EntityReadBatchBuilder).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _EntityReadBatchBuilder[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _EntityReadBatchBuilder[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _EntityWriteBatch = require("./EntityWriteBatch");
|
|
40
|
+
Object.keys(_EntityWriteBatch).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _EntityWriteBatch[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _EntityWriteBatch[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _EntityWriteBatchBuilder = require("./EntityWriteBatchBuilder");
|
|
51
|
+
Object.keys(_EntityWriteBatchBuilder).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _EntityWriteBatchBuilder[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _EntityWriteBatchBuilder[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _getEntity = require("./getEntity");
|
|
62
|
+
Object.keys(_getEntity).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _getEntity[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _getEntity[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _types = require("./types");
|
|
73
|
+
Object.keys(_types).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _types[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_Entity","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_EntityReadBatch","_EntityReadBatchBuilder","_EntityWriteBatch","_EntityWriteBatchBuilder","_getEntity","_types"],"sources":["index.ts"],"sourcesContent":["export * from \"./Entity\";\nexport * from \"./EntityReadBatch\";\nexport * from \"./EntityReadBatchBuilder\";\nexport * from \"./EntityWriteBatch\";\nexport * from \"./EntityWriteBatchBuilder\";\nexport * from \"./getEntity\";\nexport * from \"./types\";\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA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ity } from "dynamodb-toolbox";
|
|
2
|
+
import type { BatchWriteItem, BatchWriteResult, IDeleteBatchItem, IPutBatchItem } from "../batch/types";
|
|
3
|
+
import type { GenericRecord } from "@webiny/api/types";
|
|
4
|
+
import type { TableDef } from "../../toolbox";
|
|
5
|
+
import type { ITableWriteBatch } from "../table/types";
|
|
6
|
+
import type { IPutParamsItem, put } from "../put";
|
|
7
|
+
import type { QueryAllParams, QueryOneParams } from "../query";
|
|
8
|
+
import type { get, getClean, GetRecordParamsKeys } from "../get";
|
|
9
|
+
import type { deleteItem, IDeleteItemKeys } from "../delete";
|
|
10
|
+
import type { batchReadAll } from "../batch/batchRead";
|
|
11
|
+
export type IEntityQueryOneParams = Omit<QueryOneParams, "entity">;
|
|
12
|
+
export type IEntityQueryAllParams = Omit<QueryAllParams, "entity">;
|
|
13
|
+
export interface IEntity {
|
|
14
|
+
readonly entity: BaseEntity;
|
|
15
|
+
createEntityReader(): IEntityReadBatch;
|
|
16
|
+
createEntityWriter(): IEntityWriteBatch;
|
|
17
|
+
createTableWriter(): ITableWriteBatch;
|
|
18
|
+
put<T extends GenericRecord = GenericRecord>(item: IPutParamsItem<T>): ReturnType<typeof put>;
|
|
19
|
+
get<T>(keys: GetRecordParamsKeys): ReturnType<typeof get<T>>;
|
|
20
|
+
getClean<T>(keys: GetRecordParamsKeys): ReturnType<typeof getClean<T>>;
|
|
21
|
+
delete(keys: IDeleteItemKeys): ReturnType<typeof deleteItem>;
|
|
22
|
+
queryOne<T>(params: IEntityQueryOneParams): Promise<T | null>;
|
|
23
|
+
queryAll<T>(params: IEntityQueryAllParams): Promise<T[]>;
|
|
24
|
+
}
|
|
25
|
+
export interface IEntityWriteBatchBuilder {
|
|
26
|
+
put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem;
|
|
27
|
+
delete(item: IDeleteBatchItem): BatchWriteItem;
|
|
28
|
+
}
|
|
29
|
+
export interface IEntityWriteBatch {
|
|
30
|
+
readonly total: number;
|
|
31
|
+
readonly items: BatchWriteItem[];
|
|
32
|
+
put(item: IPutBatchItem): void;
|
|
33
|
+
delete(item: IDeleteBatchItem): void;
|
|
34
|
+
execute(): Promise<BatchWriteResult>;
|
|
35
|
+
combine(items: BatchWriteItem[]): ITableWriteBatch;
|
|
36
|
+
}
|
|
37
|
+
export interface IEntityReadBatchKey {
|
|
38
|
+
PK: string;
|
|
39
|
+
SK: string;
|
|
40
|
+
}
|
|
41
|
+
export interface IEntityReadBatch {
|
|
42
|
+
get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void;
|
|
43
|
+
execute<T = GenericRecord>(): ReturnType<typeof batchReadAll<T>>;
|
|
44
|
+
}
|
|
45
|
+
export interface IEntityReadBatchBuilderGetResponse {
|
|
46
|
+
Table: TableDef;
|
|
47
|
+
Key: IEntityReadBatchKey;
|
|
48
|
+
}
|
|
49
|
+
export interface IEntityReadBatchBuilder {
|
|
50
|
+
get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { Entity as BaseEntity } from \"dynamodb-toolbox\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport type { TableDef } from \"~/toolbox\";\nimport type { ITableWriteBatch } from \"~/utils/table/types\";\nimport type { IPutParamsItem, put } from \"~/utils/put\";\nimport type { QueryAllParams, QueryOneParams } from \"~/utils/query\";\nimport type { get, getClean, GetRecordParamsKeys } from \"~/utils/get\";\nimport type { deleteItem, IDeleteItemKeys } from \"~/utils/delete\";\nimport type { batchReadAll } from \"~/utils/batch/batchRead\";\n\nexport type IEntityQueryOneParams = Omit<QueryOneParams, \"entity\">;\n\nexport type IEntityQueryAllParams = Omit<QueryAllParams, \"entity\">;\n\nexport interface IEntity {\n readonly entity: BaseEntity;\n createEntityReader(): IEntityReadBatch;\n createEntityWriter(): IEntityWriteBatch;\n createTableWriter(): ITableWriteBatch;\n put<T extends GenericRecord = GenericRecord>(item: IPutParamsItem<T>): ReturnType<typeof put>;\n get<T>(keys: GetRecordParamsKeys): ReturnType<typeof get<T>>;\n getClean<T>(keys: GetRecordParamsKeys): ReturnType<typeof getClean<T>>;\n delete(keys: IDeleteItemKeys): ReturnType<typeof deleteItem>;\n queryOne<T>(params: IEntityQueryOneParams): Promise<T | null>;\n queryAll<T>(params: IEntityQueryAllParams): Promise<T[]>;\n}\n\nexport interface IEntityWriteBatchBuilder {\n // readonly entity: Entity;\n put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem;\n delete(item: IDeleteBatchItem): BatchWriteItem;\n}\n\nexport interface IEntityWriteBatch {\n readonly total: number;\n // readonly entity: Entity;\n readonly items: BatchWriteItem[];\n // readonly builder: IEntityWriteBatchBuilder;\n\n put(item: IPutBatchItem): void;\n delete(item: IDeleteBatchItem): void;\n execute(): Promise<BatchWriteResult>;\n combine(items: BatchWriteItem[]): ITableWriteBatch;\n}\n\nexport interface IEntityReadBatchKey {\n PK: string;\n SK: string;\n}\n\nexport interface IEntityReadBatch {\n get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void;\n execute<T = GenericRecord>(): ReturnType<typeof batchReadAll<T>>;\n}\n\nexport interface IEntityReadBatchBuilderGetResponse {\n Table: TableDef;\n Key: IEntityReadBatchKey;\n}\n\nexport interface IEntityReadBatchBuilder {\n get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse;\n}\n"],"mappings":"","ignoreList":[]}
|
package/utils/filter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
2
|
-
import { FieldPlugin } from "../plugins/definitions/FieldPlugin";
|
|
3
|
-
export interface Params<T
|
|
1
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
2
|
+
import type { FieldPlugin } from "../plugins/definitions/FieldPlugin";
|
|
3
|
+
export interface Params<T = any> {
|
|
4
4
|
plugins: PluginsContainer;
|
|
5
5
|
items: T[];
|
|
6
6
|
where: Record<string, any>;
|
|
@@ -9,4 +9,4 @@ export interface Params<T extends any = any> {
|
|
|
9
9
|
*/
|
|
10
10
|
fields: FieldPlugin[];
|
|
11
11
|
}
|
|
12
|
-
export declare
|
|
12
|
+
export declare function filterItems<T = any>(params: Params<T>): T[];
|
package/utils/filter.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.filterItems =
|
|
9
|
-
|
|
7
|
+
exports.filterItems = filterItems;
|
|
10
8
|
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _ValueFilterPlugin = require("../plugins/definitions/ValueFilterPlugin");
|
|
15
|
-
|
|
16
11
|
const getMappedPlugins = params => {
|
|
17
12
|
return params.plugins.byType(params.type).reduce((plugins, plugin) => {
|
|
13
|
+
/**
|
|
14
|
+
* We expect op to be a string, that is why we cast.
|
|
15
|
+
*/
|
|
18
16
|
const op = plugin[params.property];
|
|
19
17
|
plugins[op] = plugin;
|
|
20
18
|
return plugins;
|
|
21
19
|
}, {});
|
|
22
20
|
};
|
|
23
|
-
|
|
24
21
|
const extractWhereArgs = key => {
|
|
25
22
|
const result = key.split("_");
|
|
26
23
|
const field = result.shift();
|
|
@@ -28,7 +25,6 @@ const extractWhereArgs = key => {
|
|
|
28
25
|
/**
|
|
29
26
|
* When rawOp is not, it means it is equal negated so just return that.
|
|
30
27
|
*/
|
|
31
|
-
|
|
32
28
|
if (rawOp === "not") {
|
|
33
29
|
return {
|
|
34
30
|
field,
|
|
@@ -36,7 +32,6 @@ const extractWhereArgs = key => {
|
|
|
36
32
|
negate: true
|
|
37
33
|
};
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
const negate = rawOp.match("not_") !== null;
|
|
41
36
|
const operation = rawOp.replace("not_", "");
|
|
42
37
|
return {
|
|
@@ -45,19 +40,15 @@ const extractWhereArgs = key => {
|
|
|
45
40
|
negate
|
|
46
41
|
};
|
|
47
42
|
};
|
|
48
|
-
|
|
49
43
|
const findFilterPlugin = (plugins, operation) => {
|
|
50
44
|
if (plugins[operation]) {
|
|
51
45
|
return plugins[operation];
|
|
52
46
|
}
|
|
53
|
-
|
|
54
47
|
throw new _error.default(`Missing filter plugin definition.`, "FILTER_PLUGIN_ERROR", {
|
|
55
48
|
operation
|
|
56
49
|
});
|
|
57
50
|
};
|
|
58
|
-
|
|
59
51
|
const multiSearchFieldOperations = ["contains", "fuzzy"];
|
|
60
|
-
|
|
61
52
|
const createFilters = params => {
|
|
62
53
|
const {
|
|
63
54
|
plugins,
|
|
@@ -68,11 +59,9 @@ const createFilters = params => {
|
|
|
68
59
|
/**
|
|
69
60
|
* Skip everything if there are no conditions to be applied.
|
|
70
61
|
*/
|
|
71
|
-
|
|
72
62
|
if (keys.length === 0) {
|
|
73
63
|
return [];
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
const filterPlugins = getMappedPlugins({
|
|
77
66
|
plugins,
|
|
78
67
|
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
@@ -80,41 +69,36 @@ const createFilters = params => {
|
|
|
80
69
|
});
|
|
81
70
|
return keys.reduce((filters, key) => {
|
|
82
71
|
const compareValue = where[key];
|
|
83
|
-
|
|
84
72
|
if (compareValue === undefined) {
|
|
85
73
|
return filters;
|
|
86
74
|
}
|
|
87
75
|
/**
|
|
88
76
|
* @see DynamoDbContainsFilter
|
|
89
77
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
78
|
if (multiSearchFieldOperations.includes(key) === true) {
|
|
93
79
|
const data = compareValue;
|
|
94
80
|
let transformValue = undefined;
|
|
95
81
|
const paths = data.fields.map(field => {
|
|
96
82
|
const fieldPlugin = fields.find(plugin => plugin.getField() === field);
|
|
97
|
-
|
|
98
83
|
if (fieldPlugin) {
|
|
99
84
|
transformValue = value => {
|
|
100
85
|
return fieldPlugin.transformValue(value);
|
|
101
86
|
};
|
|
102
|
-
|
|
103
87
|
return fieldPlugin.getPath();
|
|
104
88
|
}
|
|
105
|
-
|
|
106
89
|
return field;
|
|
107
90
|
});
|
|
91
|
+
const filterPlugin = findFilterPlugin(filterPlugins, key);
|
|
108
92
|
filters.push({
|
|
93
|
+
operation: filterPlugin.operation,
|
|
109
94
|
compareValue: data.value,
|
|
110
|
-
filterPlugin
|
|
95
|
+
filterPlugin,
|
|
111
96
|
transformValue,
|
|
112
97
|
paths,
|
|
113
98
|
negate: false
|
|
114
99
|
});
|
|
115
100
|
return filters;
|
|
116
101
|
}
|
|
117
|
-
|
|
118
102
|
const {
|
|
119
103
|
field,
|
|
120
104
|
operation,
|
|
@@ -124,16 +108,14 @@ const createFilters = params => {
|
|
|
124
108
|
const fieldPlugin = fields.find(plugin => plugin.getField() === field);
|
|
125
109
|
let path = field;
|
|
126
110
|
let transformValue = undefined;
|
|
127
|
-
|
|
128
111
|
if (fieldPlugin) {
|
|
129
112
|
transformValue = value => {
|
|
130
113
|
return fieldPlugin.transformValue(value);
|
|
131
114
|
};
|
|
132
|
-
|
|
133
115
|
path = fieldPlugin.getPath();
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
filters.push({
|
|
118
|
+
operation: filterPlugin.operation,
|
|
137
119
|
compareValue,
|
|
138
120
|
filterPlugin,
|
|
139
121
|
transformValue,
|
|
@@ -146,35 +128,27 @@ const createFilters = params => {
|
|
|
146
128
|
/**
|
|
147
129
|
* Transforms the value with given transformer callable.
|
|
148
130
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
131
|
const transform = (value, transformValue) => {
|
|
152
132
|
if (!transformValue) {
|
|
153
133
|
return value;
|
|
154
134
|
}
|
|
155
|
-
|
|
156
135
|
if (Array.isArray(value)) {
|
|
157
136
|
return value.map(v => transformValue(v));
|
|
158
137
|
}
|
|
159
|
-
|
|
160
138
|
return transformValue(value);
|
|
161
139
|
};
|
|
162
140
|
/**
|
|
163
141
|
* Creates a filter callable that we can send to the .filter() method of the array.
|
|
164
142
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
143
|
const createFilterCallable = params => {
|
|
168
144
|
const filters = createFilters(params);
|
|
169
145
|
/**
|
|
170
146
|
* Just return null so there are no filters to be applied.
|
|
171
147
|
* Later in the code we check for null so we do not loop through the items.
|
|
172
148
|
*/
|
|
173
|
-
|
|
174
149
|
if (filters.length === 0) {
|
|
175
150
|
return null;
|
|
176
151
|
}
|
|
177
|
-
|
|
178
152
|
return item => {
|
|
179
153
|
for (const filter of filters) {
|
|
180
154
|
const result = filter.paths.some(path => {
|
|
@@ -186,27 +160,22 @@ const createFilterCallable = params => {
|
|
|
186
160
|
});
|
|
187
161
|
return filter.negate ? !matched : matched;
|
|
188
162
|
});
|
|
189
|
-
|
|
190
163
|
if (result === false) {
|
|
191
164
|
return false;
|
|
192
165
|
}
|
|
193
166
|
}
|
|
194
|
-
|
|
195
167
|
return true;
|
|
196
168
|
};
|
|
197
169
|
};
|
|
198
|
-
|
|
199
|
-
const filterItems = params => {
|
|
170
|
+
function filterItems(params) {
|
|
200
171
|
const filter = createFilterCallable(params);
|
|
201
172
|
/**
|
|
202
173
|
* No point in going through all the items when there are no filters to be applied.
|
|
203
174
|
*/
|
|
204
|
-
|
|
205
175
|
if (!filter) {
|
|
206
176
|
return params.items;
|
|
207
177
|
}
|
|
208
|
-
|
|
209
178
|
return params.items.filter(filter);
|
|
210
|
-
}
|
|
179
|
+
}
|
|
211
180
|
|
|
212
|
-
|
|
181
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_dotProp","_interopRequireDefault","require","_error","_ValueFilterPlugin","getMappedPlugins","params","plugins","byType","type","reduce","plugin","op","property","extractWhereArgs","key","result","split","field","shift","rawOp","length","join","operation","negate","match","replace","findFilterPlugin","WebinyError","multiSearchFieldOperations","createFilters","where","fields","keys","Object","filterPlugins","ValueFilterPlugin","filters","compareValue","undefined","includes","data","transformValue","paths","map","fieldPlugin","find","getField","value","getPath","filterPlugin","push","path","transform","Array","isArray","v","createFilterCallable","item","filter","some","dotProp","get","matched","matches","filterItems","items"],"sources":["filter.ts"],"sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport type { Plugin, PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"~/plugins/definitions/ValueFilterPlugin\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\nimport type { DynamoDbContainsFilter } from \"~/types\";\n\ntype TransformValue = (value: any) => any;\n\nexport interface Params<T = any> {\n plugins: PluginsContainer;\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\ninterface MappedPluginParams<T extends Plugin = Plugin> {\n plugins: PluginsContainer;\n type: string;\n property: keyof T;\n}\n\ninterface Filter {\n operation: string;\n compareValue: any;\n filterPlugin: ValueFilterPlugin;\n transformValue?: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\nconst getMappedPlugins = <T extends Plugin>(params: MappedPluginParams<T>): Record<string, T> => {\n return params.plugins.byType<T>(params.type).reduce((plugins, plugin) => {\n /**\n * We expect op to be a string, that is why we cast.\n */\n const op = plugin[params.property] as unknown as string;\n plugins[op] = plugin;\n return plugins;\n }, {} as Record<string, T>);\n};\n\ninterface ExtractWhereArgsResult {\n field: string;\n operation: string;\n negate: boolean;\n}\nconst 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\nconst findFilterPlugin = (\n plugins: Record<string, ValueFilterPlugin>,\n operation: string\n): ValueFilterPlugin => {\n if (plugins[operation]) {\n return plugins[operation];\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nconst createFilters = (params: Omit<Params, \"items\">): Filter[] => {\n const { plugins, where, fields } = params;\n\n const keys = Object.keys(where);\n /**\n * Skip everything if there are no conditions to be applied.\n */\n if (keys.length === 0) {\n return [];\n }\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n\n return keys.reduce((filters, key) => {\n const compareValue = where[key];\n if (compareValue === undefined) {\n return filters;\n }\n /**\n * @see DynamoDbContainsFilter\n */\n if (multiSearchFieldOperations.includes(key) === true) {\n const data: DynamoDbContainsFilter = compareValue;\n let transformValue: TransformValue | undefined = 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 filterPlugin = findFilterPlugin(filterPlugins, key);\n filters.push({\n operation: filterPlugin.operation,\n compareValue: data.value,\n filterPlugin,\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filterPlugin = findFilterPlugin(filterPlugins, operation);\n\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n let path: string = field;\n let transformValue: TransformValue | undefined = 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: filterPlugin.operation,\n compareValue,\n filterPlugin,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\n};\n/**\n * Transforms the value with given transformer callable.\n */\nconst transform = (value: any, transformValue?: TransformValue): any => {\n if (!transformValue) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(v => transformValue(v));\n }\n return transformValue(value);\n};\n/**\n * Creates a filter callable that we can send to the .filter() method of the array.\n */\nconst createFilterCallable = (params: Omit<Params, \"items\">): ((item: any) => boolean) | null => {\n const filters = createFilters(params);\n /**\n * Just return null so there are no filters to be applied.\n * Later in the code we check for null so we do not loop through the items.\n */\n if (filters.length === 0) {\n return null;\n }\n\n return (item: any) => {\n for (const filter of filters) {\n const result = filter.paths.some(path => {\n const value = transform(dotProp.get(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filterPlugin.matches({\n value,\n compareValue\n });\n\n return filter.negate ? !matched : matched;\n });\n if (result === false) {\n return false;\n }\n }\n return true;\n };\n};\n\nexport function filterItems<T = any>(params: Params<T>): T[] {\n const filter = createFilterCallable(params);\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filter) {\n return params.items;\n }\n return params.items.filter(filter);\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,kBAAA,GAAAF,OAAA;AA+BA,MAAMG,gBAAgB,GAAsBC,MAA6B,IAAwB;EAC7F,OAAOA,MAAM,CAACC,OAAO,CAACC,MAAM,CAAIF,MAAM,CAACG,IAAI,CAAC,CAACC,MAAM,CAAC,CAACH,OAAO,EAAEI,MAAM,KAAK;IACrE;AACR;AACA;IACQ,MAAMC,EAAE,GAA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+B,OAAO,GAAGP,aAAa,CAACxB,MAAM,CAAC;EACrC;AACJ;AACA;AACA;EACI,IAAI+B,OAAO,CAAChB,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,IAAI;EACf;EAEA,OAAQqC,IAAS,IAAK;IAClB,KAAK,MAAMC,MAAM,IAAItB,OAAO,EAAE;MAC1B,MAAMrB,MAAM,GAAG2C,MAAM,CAAChB,KAAK,CAACiB,IAAI,CAACR,IAAI,IAAI;QACrC,MAAMJ,KAAK,GAAGK,SAAS,CAACQ,gBAAO,CAACC,GAAG,CAACJ,IAAI,EAAEN,IAAI,CAAC,EAAEO,MAAM,CAACjB,cAAc,CAAC;QACvE,MAAMJ,YAAY,GAAGe,SAAS,CAACM,MAAM,CAACrB,YAAY,EAAEqB,MAAM,CAACjB,cAAc,CAAC;QAC1E,MAAMqB,OAAO,GAAGJ,MAAM,CAACT,YAAY,CAACc,OAAO,CAAC;UACxChB,KAAK;UACLV;QACJ,CAAC,CAAC;QAEF,OAAOqB,MAAM,CAACnC,MAAM,GAAG,CAACuC,OAAO,GAAGA,OAAO;MAC7C,CAAC,CAAC;MACF,IAAI/C,MAAM,KAAK,KAAK,EAAE;QAClB,OAAO,KAAK;MAChB;IACJ;IACA,OAAO,IAAI;EACf,CAAC;AACL,CAAC;AAEM,SAASiD,WAAWA,CAAU3D,MAAiB,EAAO;EACzD,MAAMqD,MAAM,GAAGF,oBAAoB,CAACnD,MAAM,CAAC;EAC3C;AACJ;AACA;EACI,IAAI,CAACqD,MAAM,EAAE;IACT,OAAOrD,MAAM,CAAC4D,KAAK;EACvB;EACA,OAAO5D,MAAM,CAAC4D,KAAK,CAACP,MAAM,CAACA,MAAM,CAAC;AACtC","ignoreList":[]}
|
package/utils/get.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Entity } from "
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Entity } from "../toolbox";
|
|
2
|
+
export interface GetRecordParamsKeys {
|
|
3
|
+
PK: string;
|
|
4
|
+
SK: string;
|
|
5
|
+
}
|
|
6
|
+
export interface GetRecordParams {
|
|
7
|
+
entity: Entity;
|
|
8
|
+
keys: GetRecordParamsKeys;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Gets a single record from the DynamoDB table.
|
|
@@ -14,4 +15,5 @@ export interface Params {
|
|
|
14
15
|
*
|
|
15
16
|
* @throws
|
|
16
17
|
*/
|
|
17
|
-
export declare const get: <T>(params:
|
|
18
|
+
export declare const get: <T>(params: GetRecordParams) => Promise<T | null>;
|
|
19
|
+
export declare const getClean: <T>(params: GetRecordParams) => Promise<T | null>;
|
package/utils/get.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.get = void 0;
|
|
7
|
-
|
|
6
|
+
exports.getClean = exports.get = void 0;
|
|
7
|
+
var _cleanup = require("./cleanup");
|
|
8
8
|
/**
|
|
9
9
|
* Gets a single record from the DynamoDB table.
|
|
10
10
|
* Returns either record or null.
|
|
@@ -18,13 +18,22 @@ const get = async params => {
|
|
|
18
18
|
entity,
|
|
19
19
|
keys
|
|
20
20
|
} = params;
|
|
21
|
-
const result = await entity.get(keys
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const result = await entity.get(keys, {
|
|
22
|
+
execute: true
|
|
23
|
+
});
|
|
24
|
+
if (!result?.Item) {
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
27
|
return result.Item;
|
|
28
28
|
};
|
|
29
|
+
exports.get = get;
|
|
30
|
+
const getClean = async params => {
|
|
31
|
+
const result = await get(params);
|
|
32
|
+
if (!result) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return (0, _cleanup.cleanupItem)(params.entity, result);
|
|
36
|
+
};
|
|
37
|
+
exports.getClean = getClean;
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
//# sourceMappingURL=get.js.map
|
package/utils/get.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_cleanup","require","get","params","entity","keys","result","execute","Item","exports","getClean","cleanupItem"],"sources":["get.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox\";\nimport { cleanupItem } from \"~/utils/cleanup\";\n\nexport interface GetRecordParamsKeys {\n PK: string;\n SK: string;\n}\n\nexport interface GetRecordParams {\n entity: Entity;\n keys: GetRecordParamsKeys;\n}\n\n/**\n * Gets a single record from the DynamoDB table.\n * Returns either record or null.\n *\n * Be aware to wrap in try/catch to avoid the error killing your app.\n *\n * @throws\n */\nexport const get = async <T>(params: GetRecordParams): Promise<T | null> => {\n const { entity, keys } = params;\n\n const result = await entity.get(keys, {\n execute: true\n });\n\n if (!result?.Item) {\n return null;\n }\n return result.Item as T;\n};\n\nexport const getClean = async <T>(params: GetRecordParams): Promise<T | null> => {\n const result = await get<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem<T>(params.entity, result);\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,GAAG,GAAG,MAAUC,MAAuB,IAAwB;EACxE,MAAM;IAAEC,MAAM;IAAEC;EAAK,CAAC,GAAGF,MAAM;EAE/B,MAAMG,MAAM,GAAG,MAAMF,MAAM,CAACF,GAAG,CAACG,IAAI,EAAE;IAClCE,OAAO,EAAE;EACb,CAAC,CAAC;EAEF,IAAI,CAACD,MAAM,EAAEE,IAAI,EAAE;IACf,OAAO,IAAI;EACf;EACA,OAAOF,MAAM,CAACE,IAAI;AACtB,CAAC;AAACC,OAAA,CAAAP,GAAA,GAAAA,GAAA;AAEK,MAAMQ,QAAQ,GAAG,MAAUP,MAAuB,IAAwB;EAC7E,MAAMG,MAAM,GAAG,MAAMJ,GAAG,CAAIC,MAAM,CAAC;EACnC,IAAI,CAACG,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EACA,OAAO,IAAAK,oBAAW,EAAIR,MAAM,CAACC,MAAM,EAAEE,MAAM,CAAC;AAChD,CAAC;AAACG,OAAA,CAAAC,QAAA,GAAAA,QAAA","ignoreList":[]}
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./cleanup";
|
|
2
|
+
export * from "./createEntity";
|
|
3
|
+
export * from "./createTable";
|
|
4
|
+
export * from "./cursor";
|
|
5
|
+
export * from "./filter";
|
|
6
|
+
export * from "./get";
|
|
7
|
+
export * from "./delete";
|
|
8
|
+
export * from "./put";
|
|
9
|
+
export * from "./listResponse";
|
|
10
|
+
export * from "./query";
|
|
11
|
+
export * from "./count";
|
|
12
|
+
export * from "./scan";
|
|
13
|
+
export * from "./sort";
|
|
14
|
+
export * from "./update";
|
|
15
|
+
export * from "./batch";
|
|
16
|
+
export * from "./entity";
|
|
17
|
+
export * from "./table";
|