@webiny/db-dynamodb 0.0.0-unstable.6f45466a1d → 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.js +204 -209
- package/DynamoDbDriver.js.map +1 -1
- 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 +1 -0
- package/index.js +9 -2
- package/index.js.map +1 -1
- package/package.json +28 -20
- package/plugins/definitions/DateTimeTransformPlugin.js +18 -27
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.js +34 -37
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.js +25 -37
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.d.ts +1 -6
- package/plugins/definitions/ValueTransformPlugin.js +17 -22
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +14 -18
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.d.ts +0 -5
- package/plugins/index.js +0 -12
- package/store/entity.js +6 -9
- package/store/entity.js.map +1 -1
- package/store/keys.js +6 -13
- package/store/keys.js.map +1 -1
- package/store/types.js +0 -3
- package/toolbox.d.ts +53 -1
- package/toolbox.js +0 -4
- package/types.js +0 -3
- package/utils/batch/batchRead.js +37 -56
- package/utils/batch/batchRead.js.map +1 -1
- package/utils/batch/batchWrite.js +33 -51
- package/utils/batch/batchWrite.js.map +1 -1
- package/utils/batch/index.js +0 -2
- package/utils/batch/types.js +0 -3
- package/utils/cleanup.js +35 -25
- package/utils/cleanup.js.map +1 -1
- package/utils/count.js +8 -13
- package/utils/count.js.map +1 -1
- package/utils/createEntity.d.ts +1 -1
- package/utils/createEntity.js +75 -78
- package/utils/createEntity.js.map +1 -1
- package/utils/createTable.js +25 -35
- package/utils/createTable.js.map +1 -1
- package/utils/cursor.js +7 -10
- package/utils/cursor.js.map +1 -1
- package/utils/delete.js +6 -8
- package/utils/delete.js.map +1 -1
- package/utils/entity/Entity.d.ts +1 -1
- package/utils/entity/Entity.js +85 -89
- package/utils/entity/Entity.js.map +1 -1
- package/utils/entity/EntityReadBatch.js +23 -31
- package/utils/entity/EntityReadBatch.js.map +1 -1
- package/utils/entity/EntityReadBatchBuilder.js +12 -15
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
- package/utils/entity/EntityWriteBatch.js +34 -41
- package/utils/entity/EntityWriteBatch.js.map +1 -1
- package/utils/entity/EntityWriteBatchBuilder.js +15 -16
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
- package/utils/entity/getEntity.js +8 -9
- package/utils/entity/getEntity.js.map +1 -1
- package/utils/entity/index.js +0 -2
- package/utils/entity/types.js +0 -4
- package/utils/get.js +12 -26
- package/utils/get.js.map +1 -1
- package/utils/index.d.ts +1 -5
- package/utils/index.js +1 -7
- package/utils/put.js +7 -9
- package/utils/put.js.map +1 -1
- package/utils/query.js +77 -128
- package/utils/query.js.map +1 -1
- package/utils/scan.js +47 -73
- package/utils/scan.js.map +1 -1
- package/utils/sort.js +37 -61
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.js +22 -21
- package/utils/table/Table.js.map +1 -1
- package/utils/table/TableReadBatch.js +37 -45
- package/utils/table/TableReadBatch.js.map +1 -1
- package/utils/table/TableWriteBatch.js +47 -56
- package/utils/table/TableWriteBatch.js.map +1 -1
- package/utils/table/index.js +0 -2
- package/utils/table/types.js +0 -3
- package/plugins/definitions/AttributePlugin.d.ts +0 -18
- package/plugins/definitions/AttributePlugin.js +0 -38
- package/plugins/definitions/AttributePlugin.js.map +0 -1
- package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
- package/plugins/definitions/FieldPathPlugin.js +0 -26
- package/plugins/definitions/FieldPathPlugin.js.map +0 -1
- package/plugins/definitions/ValueFilterPlugin.d.ts +0 -22
- package/plugins/definitions/ValueFilterPlugin.js +0 -35
- package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
- package/plugins/filters/andIn.d.ts +0 -3
- package/plugins/filters/andIn.js +0 -24
- package/plugins/filters/andIn.js.map +0 -1
- package/plugins/filters/between.d.ts +0 -3
- package/plugins/filters/between.js +0 -25
- package/plugins/filters/between.js.map +0 -1
- package/plugins/filters/contains.d.ts +0 -3
- package/plugins/filters/contains.js +0 -53
- package/plugins/filters/contains.js.map +0 -1
- package/plugins/filters/eq.d.ts +0 -3
- package/plugins/filters/eq.js +0 -26
- package/plugins/filters/eq.js.map +0 -1
- package/plugins/filters/fuzzy.d.ts +0 -3
- package/plugins/filters/fuzzy.js +0 -29
- package/plugins/filters/fuzzy.js.map +0 -1
- package/plugins/filters/gt.d.ts +0 -3
- package/plugins/filters/gt.js +0 -14
- package/plugins/filters/gt.js.map +0 -1
- package/plugins/filters/gte.d.ts +0 -3
- package/plugins/filters/gte.js +0 -14
- package/plugins/filters/gte.js.map +0 -1
- package/plugins/filters/in.d.ts +0 -3
- package/plugins/filters/in.js +0 -24
- package/plugins/filters/in.js.map +0 -1
- package/plugins/filters/index.d.ts +0 -2
- package/plugins/filters/index.js +0 -14
- package/plugins/filters/index.js.map +0 -1
- package/plugins/filters/lt.d.ts +0 -3
- package/plugins/filters/lt.js +0 -14
- package/plugins/filters/lt.js.map +0 -1
- package/plugins/filters/lte.d.ts +0 -3
- package/plugins/filters/lte.js +0 -14
- package/plugins/filters/lte.js.map +0 -1
- package/plugins/filters/startsWith.d.ts +0 -3
- package/plugins/filters/startsWith.js +0 -34
- package/plugins/filters/startsWith.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/store/types.js.map +0 -1
- package/toolbox.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/attributes.d.ts +0 -10
- package/utils/attributes.js +0 -19
- package/utils/attributes.js.map +0 -1
- package/utils/batch/index.js.map +0 -1
- package/utils/batch/types.js.map +0 -1
- package/utils/entity/index.js.map +0 -1
- package/utils/entity/types.js.map +0 -1
- package/utils/filter.d.ts +0 -12
- package/utils/filter.js +0 -174
- package/utils/filter.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/listResponse.d.ts +0 -13
- package/utils/listResponse.js +0 -25
- package/utils/listResponse.js.map +0 -1
- package/utils/table/index.js.map +0 -1
- package/utils/table/types.js.map +0 -1
- package/utils/update.d.ts +0 -12
- package/utils/update.js +0 -12
- package/utils/update.js.map +0 -1
package/utils/sort.js
CHANGED
|
@@ -1,69 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const extractSort = (sortBy, fields)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sortBy
|
|
1
|
+
import orderBy from "lodash/orderBy.js";
|
|
2
|
+
import error from "@webiny/error";
|
|
3
|
+
const extractSort = (sortBy, fields)=>{
|
|
4
|
+
const result = sortBy.split("_");
|
|
5
|
+
if (2 !== result.length) throw new error("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
|
|
6
|
+
sortBy
|
|
8
7
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
order,
|
|
15
|
-
fields
|
|
8
|
+
const [field, order] = result;
|
|
9
|
+
if (!field) throw new error("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
|
|
10
|
+
field,
|
|
11
|
+
order,
|
|
12
|
+
fields
|
|
16
13
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
fields,
|
|
23
|
-
field
|
|
14
|
+
const fieldPlugin = fields.find((f)=>f.getField() === field);
|
|
15
|
+
const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
|
|
16
|
+
if (false === isSortable) throw new error(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
|
|
17
|
+
fields,
|
|
18
|
+
field
|
|
24
19
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
20
|
+
return {
|
|
21
|
+
field,
|
|
22
|
+
reverse: "DESC" === order.toUpperCase()
|
|
23
|
+
};
|
|
30
24
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
items
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
orders: []
|
|
46
|
-
};
|
|
47
|
-
for (const sort of initialSort) {
|
|
48
|
-
/**
|
|
49
|
-
* Possibly empty array item was passed.
|
|
50
|
-
*/
|
|
51
|
-
if (!sort) {
|
|
52
|
-
continue;
|
|
25
|
+
function sortItems(params) {
|
|
26
|
+
const { items, sort: initialSort = [], fields = [] } = params;
|
|
27
|
+
if (items.length <= 1 || false === Array.isArray(initialSort) || 0 === initialSort.length) return items;
|
|
28
|
+
const info = {
|
|
29
|
+
sorters: [],
|
|
30
|
+
orders: []
|
|
31
|
+
};
|
|
32
|
+
for (const sort of initialSort){
|
|
33
|
+
if (!sort) continue;
|
|
34
|
+
const { field, reverse } = extractSort(sort, fields);
|
|
35
|
+
const fieldPlugin = fields.find((f)=>f.getField() === field);
|
|
36
|
+
const path = fieldPlugin ? fieldPlugin.getPath() : field;
|
|
37
|
+
info.sorters.push(path);
|
|
38
|
+
info.orders.push(true === reverse ? "desc" : "asc");
|
|
53
39
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
reverse
|
|
57
|
-
} = extractSort(sort, fields);
|
|
58
|
-
const fieldPlugin = fields.find(f => f.getField() === field);
|
|
59
|
-
const path = fieldPlugin ? fieldPlugin.getPath() : field;
|
|
60
|
-
info.sorters.push(path);
|
|
61
|
-
info.orders.push(reverse === true ? "desc" : "asc");
|
|
62
|
-
}
|
|
63
|
-
if (info.sorters.length === 0) {
|
|
64
|
-
return items;
|
|
65
|
-
}
|
|
66
|
-
return lodashOrderBy(items, info.sorters, info.orders);
|
|
40
|
+
if (0 === info.sorters.length) return items;
|
|
41
|
+
return orderBy(items, info.sorters, info.orders);
|
|
67
42
|
}
|
|
43
|
+
export { sortItems };
|
|
68
44
|
|
|
69
45
|
//# sourceMappingURL=sort.js.map
|
package/utils/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/sort.js","sources":["../../src/utils/sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"names":["extractSort","sortBy","fields","result","WebinyError","field","order","fieldPlugin","f","isSortable","sortItems","params","items","initialSort","Array","info","sort","reverse","path","lodashOrderBy"],"mappings":";;AAcA,MAAMA,cAAc,CAACC,QAAgBC;IACjC,MAAMC,SAASF,OAAO,KAAK,CAAC;IAC5B,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb,MAAM,IAAIC,MACN,2DACA,cACA;QACIH;IACJ;IAGR,MAAM,CAACI,OAAOC,MAAM,GAAGH;IAEvB,IAAI,CAACE,OACD,MAAM,IAAID,MAAY,iCAAiC,uBAAuB;QAC1EC;QACAC;QACAJ;IACJ;IAEJ,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;IACtD,MAAMI,aAAaF,cAAcA,YAAY,UAAU,KAAK;IAC5D,IAAIE,AAAe,UAAfA,YACA,MAAM,IAAIL,MAAY,CAAC,6BAA6B,EAAEC,MAAM,EAAE,CAAC,EAAE,0BAA0B;QACvFH;QACAG;IACJ;IAGJ,OAAO;QACHA;QACA,SAASC,AAAwB,WAAxBA,MAAM,WAAW;IAC9B;AACJ;AAiBO,SAASI,UAAmBC,MAAiB;IAChD,MAAM,EAAEC,KAAK,EAAE,MAAMC,cAAc,EAAE,EAAEX,SAAS,EAAE,EAAE,GAAGS;IAIvD,IAAIC,MAAM,MAAM,IAAI,KAAKE,AAA+B,UAA/BA,MAAM,OAAO,CAACD,gBAA0BA,AAAuB,MAAvBA,YAAY,MAAM,EAC/E,OAAOD;IAGX,MAAMG,OAAa;QACf,SAAS,EAAE;QACX,QAAQ,EAAE;IACd;IAEA,KAAK,MAAMC,QAAQH,YAAa;QAI5B,IAAI,CAACG,MACD;QAEJ,MAAM,EAAEX,KAAK,EAAEY,OAAO,EAAE,GAAGjB,YAAYgB,MAAMd;QAC7C,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;QACtD,MAAMa,OAAOX,cAAcA,YAAY,OAAO,KAAKF;QAEnDU,KAAK,OAAO,CAAC,IAAI,CAACG;QAClBH,KAAK,MAAM,CAAC,IAAI,CAACE,AAAY,SAAZA,UAAmB,SAAS;IACjD;IAEA,IAAIF,AAAwB,MAAxBA,KAAK,OAAO,CAAC,MAAM,EACnB,OAAOH;IAGX,OAAOO,QAAcP,OAAOG,KAAK,OAAO,EAAEA,KAAK,MAAM;AACzD"}
|
package/utils/table/Table.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { Table
|
|
1
|
+
import { Table } from "../../toolbox.js";
|
|
2
2
|
import { createTableWriteBatch } from "./TableWriteBatch.js";
|
|
3
3
|
import { createTableReadBatch } from "./TableReadBatch.js";
|
|
4
4
|
import { scan } from "../scan.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
class Table_Table {
|
|
6
|
+
constructor(params){
|
|
7
|
+
this.table = new Table(params);
|
|
8
|
+
}
|
|
9
|
+
createWriter() {
|
|
10
|
+
return createTableWriteBatch({
|
|
11
|
+
table: this.table
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
createReader() {
|
|
15
|
+
return createTableReadBatch({
|
|
16
|
+
table: this.table
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async scan(params) {
|
|
20
|
+
return scan({
|
|
21
|
+
...params,
|
|
22
|
+
table: this.table
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
|
+
export { Table_Table as Table };
|
|
26
27
|
|
|
27
28
|
//# sourceMappingURL=Table.js.map
|
package/utils/table/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/table/Table.js","sources":["../../../src/utils/table/Table.ts"],"sourcesContent":["import type { TableConstructor } from \"~/toolbox.js\";\nimport { Table as BaseTable } from \"~/toolbox.js\";\nimport type {\n ITable,\n ITableReadBatch,\n ITableScanParams,\n ITableScanResponse,\n ITableWriteBatch\n} from \"./types.js\";\nimport { createTableWriteBatch } from \"./TableWriteBatch.js\";\nimport { createTableReadBatch } from \"./TableReadBatch.js\";\nimport { scan } from \"../scan.js\";\n\nexport class Table<\n Name extends string = string,\n PartitionKey extends string = string,\n SortKey extends string = string\n> implements ITable<Name, PartitionKey, SortKey> {\n public readonly table: BaseTable<Name, PartitionKey, SortKey>;\n\n public constructor(params: TableConstructor<Name, PartitionKey, SortKey>) {\n this.table = new BaseTable(params);\n }\n\n public createWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table\n });\n }\n\n public createReader(): ITableReadBatch {\n return createTableReadBatch({\n table: this.table\n });\n }\n\n public async scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>> {\n return scan<T>({\n ...params,\n table: this.table\n });\n }\n}\n"],"names":["Table","params","BaseTable","createTableWriteBatch","createTableReadBatch","scan"],"mappings":";;;;AAaO,MAAMA;IAOT,YAAmBC,MAAqD,CAAE;QACtE,IAAI,CAAC,KAAK,GAAG,IAAIC,MAAUD;IAC/B;IAEO,eAAiC;QACpC,OAAOE,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEO,eAAgC;QACnC,OAAOC,qBAAqB;YACxB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEA,MAAa,KAAQH,MAAwB,EAAkC;QAC3E,OAAOI,KAAQ;YACX,GAAGJ,MAAM;YACT,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;AACJ"}
|
|
@@ -1,54 +1,46 @@
|
|
|
1
1
|
import { batchReadAll } from "../batch/batchRead.js";
|
|
2
2
|
import { createEntityReadBatchBuilder } from "../entity/EntityReadBatchBuilder.js";
|
|
3
3
|
import { WebinyError } from "@webiny/error";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
get total() {
|
|
11
|
-
return this._items.length;
|
|
12
|
-
}
|
|
13
|
-
get items() {
|
|
14
|
-
return Array.from(this._items);
|
|
15
|
-
}
|
|
16
|
-
get(entity, input) {
|
|
17
|
-
const builder = this.getBuilder(entity);
|
|
18
|
-
const items = Array.isArray(input) ? input : [input];
|
|
19
|
-
for (const item of items) {
|
|
20
|
-
/**
|
|
21
|
-
* We cannot read from two tables at the same time, so check for that.
|
|
22
|
-
*/
|
|
23
|
-
if (this.table.name !== entity.table.name) {
|
|
24
|
-
throw new WebinyError(`Cannot read from two different tables at the same time.`);
|
|
25
|
-
}
|
|
26
|
-
this._items.push(builder.get(item));
|
|
4
|
+
class TableReadBatch {
|
|
5
|
+
constructor(params){
|
|
6
|
+
this._items = [];
|
|
7
|
+
this.builders = new Map();
|
|
8
|
+
this.table = params.table;
|
|
27
9
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (this._items.length === 0) {
|
|
31
|
-
return [];
|
|
10
|
+
get total() {
|
|
11
|
+
return this._items.length;
|
|
32
12
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
get items() {
|
|
14
|
+
return Array.from(this._items);
|
|
15
|
+
}
|
|
16
|
+
get(entity, input) {
|
|
17
|
+
const builder = this.getBuilder(entity);
|
|
18
|
+
const items = Array.isArray(input) ? input : [
|
|
19
|
+
input
|
|
20
|
+
];
|
|
21
|
+
for (const item of items){
|
|
22
|
+
if (this.table.name !== entity.table.name) throw new WebinyError("Cannot read from two different tables at the same time.");
|
|
23
|
+
this._items.push(builder.get(item));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async execute() {
|
|
27
|
+
if (0 === this._items.length) return [];
|
|
28
|
+
const items = Array.from(this._items);
|
|
29
|
+
this._items.length = 0;
|
|
30
|
+
return await batchReadAll({
|
|
31
|
+
items,
|
|
32
|
+
table: this.table
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getBuilder(entity) {
|
|
36
|
+
const builder = this.builders.get(entity.name);
|
|
37
|
+
if (builder) return builder;
|
|
38
|
+
const newBuilder = createEntityReadBatchBuilder(entity);
|
|
39
|
+
this.builders.set(entity.name, newBuilder);
|
|
40
|
+
return newBuilder;
|
|
44
41
|
}
|
|
45
|
-
const newBuilder = createEntityReadBatchBuilder(entity);
|
|
46
|
-
this.builders.set(entity.name, newBuilder);
|
|
47
|
-
return newBuilder;
|
|
48
|
-
}
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
43
|
+
const createTableReadBatch = (params)=>new TableReadBatch(params);
|
|
44
|
+
export { TableReadBatch, createTableReadBatch };
|
|
53
45
|
|
|
54
46
|
//# sourceMappingURL=TableReadBatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/table/TableReadBatch.js","sources":["../../../src/utils/table/TableReadBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse\n} from \"~/utils/entity/types.js\";\nimport { batchReadAll } from \"~/utils/batch/batchRead.js\";\nimport { createEntityReadBatchBuilder } from \"~/utils/entity/EntityReadBatchBuilder.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { ITableReadBatch, ITableReadBatchKey } from \"./types.js\";\n\nexport interface ITableReadBatchParams {\n table: TableDef;\n}\n\nexport class TableReadBatch implements ITableReadBatch {\n private readonly table: TableDef;\n\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n private readonly builders: Map<string, IEntityReadBatchBuilder> = new Map();\n\n public constructor(params: ITableReadBatchParams) {\n this.table = params.table;\n }\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): IEntityReadBatchBuilderGetResponse[] {\n return Array.from(this._items);\n }\n\n public get(entity: Entity, input: ITableReadBatchKey): void {\n const builder = this.getBuilder(entity);\n\n const items = Array.isArray(input) ? input : [input];\n for (const item of items) {\n /**\n * We cannot read from two tables at the same time, so check for that.\n */\n if (this.table.name !== entity.table!.name) {\n throw new WebinyError(`Cannot read from two different tables at the same time.`);\n }\n\n this._items.push(builder.get(item));\n }\n }\n\n public async execute<T = GenericRecord>(): Promise<T[]> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchReadAll<T>({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityReadBatchBuilder {\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityReadBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableReadBatch = (params: ITableReadBatchParams): ITableReadBatch => {\n return new TableReadBatch(params);\n};\n"],"names":["TableReadBatch","params","Map","Array","entity","input","builder","items","item","WebinyError","batchReadAll","newBuilder","createEntityReadBatchBuilder","createTableReadBatch"],"mappings":";;;AAeO,MAAMA;IAMT,YAAmBC,MAA6B,CAAE;aAHjC,MAAM,GAAyC,EAAE;aACjD,QAAQ,GAAyC,IAAIC;QAGlE,IAAI,CAAC,KAAK,GAAGD,OAAO,KAAK;IAC7B;IAEA,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;IAC7B;IAEA,IAAW,QAA8C;QACrD,OAAOE,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEO,IAAIC,MAAc,EAAEC,KAAyB,EAAQ;QACxD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAEhC,MAAMG,QAAQJ,MAAM,OAAO,CAACE,SAASA,QAAQ;YAACA;SAAM;QACpD,KAAK,MAAMG,QAAQD,MAAO;YAItB,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAKH,OAAO,KAAK,CAAE,IAAI,EACtC,MAAM,IAAIK,YAAY;YAG1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAACH,QAAQ,GAAG,CAACE;QACjC;IACJ;IAEA,MAAa,UAA2C;QACpD,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,OAAO,EAAE;QAEb,MAAMD,QAAQJ,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;QACrB,OAAO,MAAMO,aAAgB;YACzBH;YACA,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEQ,WAAWH,MAAc,EAA2B;QACxD,MAAME,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACF,OAAO,IAAI;QAC7C,IAAIE,SACA,OAAOA;QAEX,MAAMK,aAAaC,6BAA6BR;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,EAAEO;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAME,uBAAuB,CAACZ,SAC1B,IAAID,eAAeC"}
|
|
@@ -1,61 +1,52 @@
|
|
|
1
1
|
import { batchWriteAll } from "../batch/batchWrite.js";
|
|
2
2
|
import { createEntityWriteBatchBuilder } from "../entity/EntityWriteBatchBuilder.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
const builder = this.builders.get(entity.name);
|
|
49
|
-
if (builder) {
|
|
50
|
-
return builder;
|
|
51
|
-
}
|
|
52
|
-
const newBuilder = createEntityWriteBatchBuilder(entity);
|
|
53
|
-
this.builders.set(entity.name, newBuilder);
|
|
54
|
-
return newBuilder;
|
|
55
|
-
}
|
|
3
|
+
class TableWriteBatch {
|
|
4
|
+
get total() {
|
|
5
|
+
return this._items.length;
|
|
6
|
+
}
|
|
7
|
+
get items() {
|
|
8
|
+
return Array.from(this._items);
|
|
9
|
+
}
|
|
10
|
+
constructor(params){
|
|
11
|
+
this._items = [];
|
|
12
|
+
this.builders = new Map();
|
|
13
|
+
this.table = params.table;
|
|
14
|
+
if (!params.items?.length) return;
|
|
15
|
+
this._items.push(...params.items);
|
|
16
|
+
}
|
|
17
|
+
put(entity, item) {
|
|
18
|
+
const builder = this.getBuilder(entity);
|
|
19
|
+
this._items.push(builder.put(item));
|
|
20
|
+
}
|
|
21
|
+
delete(entity, item) {
|
|
22
|
+
const builder = this.getBuilder(entity);
|
|
23
|
+
this._items.push(builder.delete(item));
|
|
24
|
+
}
|
|
25
|
+
combine(items) {
|
|
26
|
+
return createTableWriteBatch({
|
|
27
|
+
table: this.table,
|
|
28
|
+
items: this._items.concat(items)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async execute() {
|
|
32
|
+
if (0 === this._items.length) return [];
|
|
33
|
+
const items = Array.from(this._items);
|
|
34
|
+
this._items.length = 0;
|
|
35
|
+
return await batchWriteAll({
|
|
36
|
+
items,
|
|
37
|
+
table: this.table
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getBuilder(entity) {
|
|
41
|
+
if (!entity.name) throw new Error("Entity must have a name.");
|
|
42
|
+
const builder = this.builders.get(entity.name);
|
|
43
|
+
if (builder) return builder;
|
|
44
|
+
const newBuilder = createEntityWriteBatchBuilder(entity);
|
|
45
|
+
this.builders.set(entity.name, newBuilder);
|
|
46
|
+
return newBuilder;
|
|
47
|
+
}
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
49
|
+
const createTableWriteBatch = (params)=>new TableWriteBatch(params);
|
|
50
|
+
export { TableWriteBatch, createTableWriteBatch };
|
|
60
51
|
|
|
61
52
|
//# sourceMappingURL=TableWriteBatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/table/TableWriteBatch.js","sources":["../../../src/utils/table/TableWriteBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"~/utils/entity/types.js\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite.js\";\nimport { createEntityWriteBatchBuilder } from \"~/utils/entity/EntityWriteBatchBuilder.js\";\nimport type { ITableWriteBatch } from \"./types.js\";\n\nexport interface ITableWriteBatchParams {\n table: TableDef;\n items?: BatchWriteItem[];\n}\n\nexport class TableWriteBatch implements ITableWriteBatch {\n private readonly table: TableDef;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builders: Map<string, IEntityWriteBatchBuilder> = new Map();\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: ITableWriteBatchParams) {\n this.table = params.table;\n if (!params.items?.length) {\n return;\n }\n this._items.push(...params.items);\n }\n\n public put(entity: Entity, item: IPutBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.put(item));\n }\n\n public delete(entity: Entity, item: IDeleteBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityWriteBatchBuilder {\n if (!entity.name) {\n throw new Error(\"Entity must have a name.\");\n }\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityWriteBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableWriteBatch = (params: ITableWriteBatchParams): ITableWriteBatch => {\n return new TableWriteBatch(params);\n};\n"],"names":["TableWriteBatch","Array","params","Map","entity","item","builder","items","createTableWriteBatch","batchWriteAll","Error","newBuilder","createEntityWriteBatchBuilder"],"mappings":";;AAiBO,MAAMA;IAKT,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;IAC7B;IAEA,IAAW,QAA0B;QACjC,OAAOC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEA,YAAmBC,MAA8B,CAAE;aAXlC,MAAM,GAAqB,EAAE;aAC7B,QAAQ,GAA0C,IAAIC;QAWnE,IAAI,CAAC,KAAK,GAAGD,OAAO,KAAK;QACzB,IAAI,CAACA,OAAO,KAAK,EAAE,QACf;QAEJ,IAAI,CAAC,MAAM,CAAC,IAAI,IAAIA,OAAO,KAAK;IACpC;IAEO,IAAIE,MAAc,EAAEC,IAAmB,EAAQ;QAClD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,GAAG,CAACD;IACjC;IAEO,OAAOD,MAAc,EAAEC,IAAsB,EAAQ;QACxD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,MAAM,CAACD;IACpC;IAEO,QAAQE,KAAuB,EAAoB;QACtD,OAAOC,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;YACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACD;QAC9B;IACJ;IAEA,MAAa,UAAqC;QAC9C,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,OAAO,EAAE;QAEb,MAAMA,QAAQN,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;QACrB,OAAO,MAAMQ,cAAc;YACvBF;YACA,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEQ,WAAWH,MAAc,EAA4B;QACzD,IAAI,CAACA,OAAO,IAAI,EACZ,MAAM,IAAIM,MAAM;QAEpB,MAAMJ,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACF,OAAO,IAAI;QAC7C,IAAIE,SACA,OAAOA;QAEX,MAAMK,aAAaC,8BAA8BR;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,EAAEO;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAMH,wBAAwB,CAACN,SAC3B,IAAIF,gBAAgBE"}
|
package/utils/table/index.js
CHANGED
package/utils/table/types.js
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { AttributeDefinition } from "../../toolbox.js";
|
|
3
|
-
export interface AttributePluginParams {
|
|
4
|
-
entity: string;
|
|
5
|
-
attribute: string;
|
|
6
|
-
params: AttributeDefinition;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class AttributePlugin extends Plugin {
|
|
9
|
-
static readonly type: string;
|
|
10
|
-
private readonly _entity;
|
|
11
|
-
private readonly _attribute;
|
|
12
|
-
private readonly _params;
|
|
13
|
-
get entity(): string;
|
|
14
|
-
get attribute(): string;
|
|
15
|
-
constructor({ entity, attribute, params }: AttributePluginParams);
|
|
16
|
-
getDefinition(): Record<string, AttributeDefinition>;
|
|
17
|
-
private validateReserved;
|
|
18
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import WebinyError from "@webiny/error";
|
|
2
|
-
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
const reservedFields = ["PK", "SK", "index", "data"];
|
|
4
|
-
export class AttributePlugin extends Plugin {
|
|
5
|
-
static type = "db.dynamodb.attribute";
|
|
6
|
-
get entity() {
|
|
7
|
-
return this._entity;
|
|
8
|
-
}
|
|
9
|
-
get attribute() {
|
|
10
|
-
return this._attribute;
|
|
11
|
-
}
|
|
12
|
-
constructor({
|
|
13
|
-
entity,
|
|
14
|
-
attribute,
|
|
15
|
-
params
|
|
16
|
-
}) {
|
|
17
|
-
super();
|
|
18
|
-
this.validateReserved(attribute);
|
|
19
|
-
this._entity = entity;
|
|
20
|
-
this._attribute = attribute;
|
|
21
|
-
this._params = params;
|
|
22
|
-
}
|
|
23
|
-
getDefinition() {
|
|
24
|
-
return {
|
|
25
|
-
[this.attribute]: this._params
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
validateReserved(attribute) {
|
|
29
|
-
if (reservedFields.includes(attribute) === false) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
throw new WebinyError(`Attribute name "${attribute}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
|
|
33
|
-
attribute
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=AttributePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["WebinyError","Plugin","reservedFields","AttributePlugin","type","entity","_entity","attribute","_attribute","constructor","params","validateReserved","_params","getDefinition","includes"],"sources":["AttributePlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { AttributeDefinition } from \"~/toolbox.js\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\"];\n\nexport interface AttributePluginParams {\n entity: string;\n attribute: string;\n params: AttributeDefinition;\n}\n\nexport abstract class AttributePlugin extends Plugin {\n public static override readonly type: string = \"db.dynamodb.attribute\";\n private readonly _entity: string;\n private readonly _attribute: string;\n private readonly _params: AttributeDefinition;\n\n public get entity(): string {\n return this._entity;\n }\n\n public get attribute(): string {\n return this._attribute;\n }\n\n public constructor({ entity, attribute, params }: AttributePluginParams) {\n super();\n\n this.validateReserved(attribute);\n\n this._entity = entity;\n this._attribute = attribute;\n this._params = params;\n }\n\n public getDefinition(): Record<string, AttributeDefinition> {\n return {\n [this.attribute]: this._params\n };\n }\n\n private validateReserved(attribute: string): void {\n if (reservedFields.includes(attribute) === false) {\n return;\n }\n throw new WebinyError(\n `Attribute name \"${attribute}\" is not allowed.`,\n \"ATTRIBUTE_NOT_ALLOWED\",\n {\n attribute\n }\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,iBAAiB;AAGxC,MAAMC,cAAc,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC;AAQpD,OAAO,MAAeC,eAAe,SAASF,MAAM,CAAC;EACjD,OAAgCG,IAAI,GAAW,uBAAuB;EAKtE,IAAWC,MAAMA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,OAAO;EACvB;EAEA,IAAWC,SAASA,CAAA,EAAW;IAC3B,OAAO,IAAI,CAACC,UAAU;EAC1B;EAEOC,WAAWA,CAAC;IAAEJ,MAAM;IAAEE,SAAS;IAAEG;EAA8B,CAAC,EAAE;IACrE,KAAK,CAAC,CAAC;IAEP,IAAI,CAACC,gBAAgB,CAACJ,SAAS,CAAC;IAEhC,IAAI,CAACD,OAAO,GAAGD,MAAM;IACrB,IAAI,CAACG,UAAU,GAAGD,SAAS;IAC3B,IAAI,CAACK,OAAO,GAAGF,MAAM;EACzB;EAEOG,aAAaA,CAAA,EAAwC;IACxD,OAAO;MACH,CAAC,IAAI,CAACN,SAAS,GAAG,IAAI,CAACK;IAC3B,CAAC;EACL;EAEQD,gBAAgBA,CAACJ,SAAiB,EAAQ;IAC9C,IAAIL,cAAc,CAACY,QAAQ,CAACP,SAAS,CAAC,KAAK,KAAK,EAAE;MAC9C;IACJ;IACA,MAAM,IAAIP,WAAW,CACjB,mBAAmBO,SAAS,mBAAmB,EAC/C,uBAAuB,EACvB;MACIA;IACJ,CACJ,CAAC;EACL;AACJ","ignoreList":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
export interface CreatePath {
|
|
3
|
-
(field: string): string;
|
|
4
|
-
}
|
|
5
|
-
export interface FieldPathPluginParams {
|
|
6
|
-
/**
|
|
7
|
-
* Which field(s) is this plugin for.
|
|
8
|
-
*/
|
|
9
|
-
fields: string | string[];
|
|
10
|
-
/**
|
|
11
|
-
* Create a path for given field.
|
|
12
|
-
* Field is passed because it can be a multi-field plugin.
|
|
13
|
-
*/
|
|
14
|
-
createPath: CreatePath;
|
|
15
|
-
}
|
|
16
|
-
export declare class FieldPathPlugin extends Plugin {
|
|
17
|
-
static readonly type: string;
|
|
18
|
-
private readonly _params;
|
|
19
|
-
constructor(params: FieldPathPluginParams);
|
|
20
|
-
canCreate(field: string): boolean;
|
|
21
|
-
createPath(field: string): string;
|
|
22
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import WebinyError from "@webiny/error";
|
|
3
|
-
import { assignFields } from "./assignFields.js";
|
|
4
|
-
export class FieldPathPlugin extends Plugin {
|
|
5
|
-
static type = "dynamodb.value.path";
|
|
6
|
-
constructor(params) {
|
|
7
|
-
super();
|
|
8
|
-
this._params = {
|
|
9
|
-
...params,
|
|
10
|
-
fields: assignFields(params.fields)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
canCreate(field) {
|
|
14
|
-
return this._params.fields.includes(field);
|
|
15
|
-
}
|
|
16
|
-
createPath(field) {
|
|
17
|
-
if (!this._params.createPath) {
|
|
18
|
-
throw new WebinyError(`Missing "createPath" in the plugin.`, "TRANSFORM_ERROR", {
|
|
19
|
-
fields: this._params.fields
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return this._params.createPath(field);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=FieldPathPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Plugin","WebinyError","assignFields","FieldPathPlugin","type","constructor","params","_params","fields","canCreate","field","includes","createPath"],"sources":["FieldPathPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { assignFields } from \"./assignFields.js\";\n\nexport interface CreatePath {\n (field: string): string;\n}\nexport interface FieldPathPluginParams {\n /**\n * Which field(s) is this plugin for.\n */\n fields: string | string[];\n /**\n * Create a path for given field.\n * Field is passed because it can be a multi-field plugin.\n */\n createPath: CreatePath;\n}\n\nexport class FieldPathPlugin extends Plugin {\n public static override readonly type: string = \"dynamodb.value.path\";\n private readonly _params: Omit<FieldPathPluginParams, \"fields\"> & { fields: string[] };\n\n public constructor(params: FieldPathPluginParams) {\n super();\n this._params = {\n ...params,\n fields: assignFields(params.fields)\n };\n }\n\n public canCreate(field: string): boolean {\n return this._params.fields.includes(field);\n }\n\n public createPath(field: string): string {\n if (!this._params.createPath) {\n throw new WebinyError(`Missing \"createPath\" in the plugin.`, \"TRANSFORM_ERROR\", {\n fields: this._params.fields\n });\n }\n return this._params.createPath(field);\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,YAAY;AAiBrB,OAAO,MAAMC,eAAe,SAASH,MAAM,CAAC;EACxC,OAAgCI,IAAI,GAAW,qBAAqB;EAG7DC,WAAWA,CAACC,MAA6B,EAAE;IAC9C,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,OAAO,GAAG;MACX,GAAGD,MAAM;MACTE,MAAM,EAAEN,YAAY,CAACI,MAAM,CAACE,MAAM;IACtC,CAAC;EACL;EAEOC,SAASA,CAACC,KAAa,EAAW;IACrC,OAAO,IAAI,CAACH,OAAO,CAACC,MAAM,CAACG,QAAQ,CAACD,KAAK,CAAC;EAC9C;EAEOE,UAAUA,CAACF,KAAa,EAAU;IACrC,IAAI,CAAC,IAAI,CAACH,OAAO,CAACK,UAAU,EAAE;MAC1B,MAAM,IAAIX,WAAW,CAAC,qCAAqC,EAAE,iBAAiB,EAAE;QAC5EO,MAAM,EAAE,IAAI,CAACD,OAAO,CAACC;MACzB,CAAC,CAAC;IACN;IACA,OAAO,IAAI,CAACD,OAAO,CAACK,UAAU,CAACF,KAAK,CAAC;EACzC;AACJ","ignoreList":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
export interface ValueFilterPluginParamsMatchesParams<V = any, C = any> {
|
|
3
|
-
value: V;
|
|
4
|
-
compareValue: C;
|
|
5
|
-
}
|
|
6
|
-
export interface ValueFilterPluginParamsMatches {
|
|
7
|
-
(params: ValueFilterPluginParamsMatchesParams): boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface ValueFilterPluginParams {
|
|
10
|
-
operation: string;
|
|
11
|
-
canUse?: (params: ValueFilterPluginParamsMatchesParams) => boolean;
|
|
12
|
-
matches: ValueFilterPluginParamsMatches;
|
|
13
|
-
}
|
|
14
|
-
export declare class ValueFilterPlugin<V = any, C = any> extends Plugin {
|
|
15
|
-
static readonly type: string;
|
|
16
|
-
private readonly _params;
|
|
17
|
-
get operation(): string;
|
|
18
|
-
constructor(params: ValueFilterPluginParams);
|
|
19
|
-
canUse(params: ValueFilterPluginParamsMatchesParams<V, C>): boolean;
|
|
20
|
-
matches(params: ValueFilterPluginParamsMatchesParams): boolean;
|
|
21
|
-
getOperation(): string;
|
|
22
|
-
}
|