@webiny/api-headless-cms-ddb 0.0.0-unstable.615a930a68 → 0.0.0-unstable.6509387258
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/definitions/entry.js +3 -5
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +0 -5
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +22 -5
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +0 -5
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +0 -5
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +0 -7
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/plainObject.js +1 -8
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +1 -19
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +7 -17
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +0 -18
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +1 -8
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +5 -24
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +1 -44
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/{createFilters.d.ts → createExpressions.d.ts} +9 -3
- package/operations/entry/filtering/createExpressions.js +176 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +3 -7
- package/operations/entry/filtering/createFields.js +2 -21
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +4 -0
- package/operations/entry/filtering/extractSort.js +23 -11
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +2 -3
- package/operations/entry/filtering/filter.js +79 -73
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +2 -6
- package/operations/entry/filtering/fullTextSearch.js +2 -18
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +0 -18
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.js +0 -8
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -7
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +0 -5
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -21
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +0 -18
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.d.ts +4 -1
- package/operations/entry/filtering/sort.js +6 -17
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +0 -2
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +0 -3
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +22 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.js +0 -6
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.js +30 -102
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +0 -18
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/systemFields.js +0 -2
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/group/index.js +2 -32
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +0 -25
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +0 -24
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +0 -17
- package/operations/system/index.js.map +1 -1
- package/package.json +13 -13
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -14
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.js +0 -7
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +33 -2
- package/plugins/index.js.map +1 -1
- package/types.js +0 -1
- package/types.js.map +1 -1
- package/operations/entry/filtering/createFilters.js +0 -155
- package/operations/entry/filtering/createFilters.js.map +0 -1
- package/operations/entry/utils.d.ts +0 -36
- package/operations/entry/utils.js +0 -684
- package/operations/entry/utils.js.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getWhereValues = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const getWhereValues = (value, condition) => {
|
|
10
|
+
const values = value;
|
|
11
|
+
if (!Array.isArray(values)) {
|
|
12
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
13
|
+
value
|
|
14
|
+
});
|
|
15
|
+
} else if (values.length === 0) {
|
|
16
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
17
|
+
value
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return values;
|
|
21
|
+
};
|
|
22
|
+
exports.getWhereValues = getWhereValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getWhereValues","value","condition","values","Array","isArray","WebinyError","length"],"sources":["values.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"mappings":";;;;;;;AACA;AAEO,MAAMA,cAAc,GAAG,CAACC,KAAc,EAAEC,SAAuB,KAAK;EACvE,MAAMC,MAAM,GAAGF,KAAwC;EACvD,IAAI,CAACG,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACxB,MAAM,IAAIG,cAAW,CAChB,iCAAgCJ,SAAU,wCAAuC,EACjF,aAAYA,SAAU,YAAW,EAClC;MACID;IACJ,CAAC,CACJ;EACL,CAAC,MAAM,IAAIE,MAAM,CAACI,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM,IAAID,cAAW,CAChB,iCAAgCJ,SAAU,uCAAsC,EAChF,aAAYA,SAAU,YAAW,EAClC;MACID;IACJ,CAAC,CACJ;EACL;EACA,OAAOE,MAAM;AACjB,CAAC;AAAC"}
|
|
@@ -4,20 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.extractWhereParams = void 0;
|
|
7
|
-
|
|
8
7
|
const extractWhereParams = key => {
|
|
9
8
|
const result = key.split("_");
|
|
10
9
|
const fieldId = result.shift();
|
|
11
|
-
|
|
12
10
|
if (!fieldId) {
|
|
13
11
|
return null;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
17
14
|
/**
|
|
18
15
|
* When rawOp is not, it means it is equal negated so just return that.
|
|
19
16
|
*/
|
|
20
|
-
|
|
21
17
|
if (rawOp === "not") {
|
|
22
18
|
return {
|
|
23
19
|
fieldId,
|
|
@@ -25,7 +21,6 @@ const extractWhereParams = key => {
|
|
|
25
21
|
negate: true
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
const negate = rawOp.match("not_") !== null;
|
|
30
25
|
const operation = rawOp.replace("not_", "");
|
|
31
26
|
return {
|
|
@@ -34,5 +29,4 @@ const extractWhereParams = key => {
|
|
|
34
29
|
negate
|
|
35
30
|
};
|
|
36
31
|
};
|
|
37
|
-
|
|
38
32
|
exports.extractWhereParams = extractWhereParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["extractWhereParams","key","result","split","fieldId","shift","rawOp","length","join","operation","negate","match","replace"],"sources":["where.ts"],"sourcesContent":["export const extractWhereParams = (key: string) => {\n const result = key.split(\"_\");\n const fieldId = result.shift();\n if (!fieldId) {\n return null;\n }\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 fieldId,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n fieldId,\n operation,\n negate\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["extractWhereParams","key","result","split","fieldId","shift","rawOp","length","join","operation","negate","match","replace"],"sources":["where.ts"],"sourcesContent":["export const extractWhereParams = (key: string) => {\n const result = key.split(\"_\");\n const fieldId = result.shift();\n if (!fieldId) {\n return null;\n }\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 fieldId,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n fieldId,\n operation,\n negate\n };\n};\n"],"mappings":";;;;;;AAAO,MAAMA,kBAAkB,GAAIC,GAAW,IAAK;EAC/C,MAAMC,MAAM,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC;EAC7B,MAAMC,OAAO,GAAGF,MAAM,CAACG,KAAK,EAAE;EAC9B,IAAI,CAACD,OAAO,EAAE;IACV,OAAO,IAAI;EACf;EACA,MAAME,KAAK,GAAGJ,MAAM,CAACK,MAAM,KAAK,CAAC,GAAG,IAAI,GAAGL,MAAM,CAACM,IAAI,CAAC,GAAG,CAAC;EAC3D;AACJ;AACA;EACI,IAAIF,KAAK,KAAK,KAAK,EAAE;IACjB,OAAO;MACHF,OAAO;MACPK,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE;IACZ,CAAC;EACL;EACA,MAAMA,MAAM,GAAGJ,KAAK,CAACK,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;EAC3C,MAAMF,SAAS,GAAGH,KAAK,CAACM,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EAC3C,OAAO;IACHR,OAAO;IACPK,SAAS;IACTC;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,50 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createEntriesStorageOperations = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _dataLoaders = require("./dataLoaders");
|
|
15
|
-
|
|
16
11
|
var _types = require("@webiny/api-headless-cms/types");
|
|
17
|
-
|
|
18
12
|
var _keys = require("./keys");
|
|
19
|
-
|
|
20
13
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
21
|
-
|
|
22
14
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
23
|
-
|
|
24
15
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
25
|
-
|
|
26
16
|
var _cursor = require("@webiny/utils/cursor");
|
|
27
|
-
|
|
28
17
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
29
|
-
|
|
30
18
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
31
|
-
|
|
32
19
|
var _createFields = require("./filtering/createFields");
|
|
33
|
-
|
|
34
20
|
var _filtering = require("./filtering");
|
|
35
|
-
|
|
36
21
|
const createType = () => {
|
|
37
22
|
return "cms.entry";
|
|
38
23
|
};
|
|
39
|
-
|
|
40
24
|
const createLatestType = () => {
|
|
41
25
|
return `${createType()}.l`;
|
|
42
26
|
};
|
|
43
|
-
|
|
44
27
|
const createPublishedType = () => {
|
|
45
28
|
return `${createType()}.p`;
|
|
46
29
|
};
|
|
47
|
-
|
|
48
30
|
const convertToStorageEntry = params => {
|
|
49
31
|
const {
|
|
50
32
|
model,
|
|
@@ -58,7 +40,6 @@ const convertToStorageEntry = params => {
|
|
|
58
40
|
values
|
|
59
41
|
});
|
|
60
42
|
};
|
|
61
|
-
|
|
62
43
|
const convertFromStorageEntry = params => {
|
|
63
44
|
const {
|
|
64
45
|
model,
|
|
@@ -72,7 +53,6 @@ const convertFromStorageEntry = params => {
|
|
|
72
53
|
values
|
|
73
54
|
});
|
|
74
55
|
};
|
|
75
|
-
|
|
76
56
|
const createEntriesStorageOperations = params => {
|
|
77
57
|
const {
|
|
78
58
|
entity,
|
|
@@ -85,29 +65,23 @@ const createEntriesStorageOperations = params => {
|
|
|
85
65
|
collection[plugin.fieldType] = plugin;
|
|
86
66
|
return collection;
|
|
87
67
|
}, {});
|
|
88
|
-
|
|
89
68
|
const createStorageTransformCallable = model => {
|
|
90
69
|
return (field, value) => {
|
|
91
70
|
const plugin = storageTransformPlugins[field.type];
|
|
92
|
-
|
|
93
71
|
if (!plugin) {
|
|
94
72
|
return value;
|
|
95
73
|
}
|
|
96
|
-
|
|
97
74
|
return plugin.fromStorage({
|
|
98
75
|
model,
|
|
99
76
|
field,
|
|
100
77
|
value,
|
|
101
|
-
|
|
102
78
|
getStoragePlugin(fieldType) {
|
|
103
79
|
return storageTransformPlugins[fieldType] || storageTransformPlugins["*"];
|
|
104
80
|
},
|
|
105
|
-
|
|
106
81
|
plugins
|
|
107
82
|
});
|
|
108
83
|
};
|
|
109
84
|
};
|
|
110
|
-
|
|
111
85
|
const create = async (model, params) => {
|
|
112
86
|
const {
|
|
113
87
|
entry,
|
|
@@ -129,7 +103,6 @@ const createEntriesStorageOperations = params => {
|
|
|
129
103
|
* - create new main entry item
|
|
130
104
|
* - create new or update latest entry item
|
|
131
105
|
*/
|
|
132
|
-
|
|
133
106
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
134
107
|
locked,
|
|
135
108
|
PK: partitionKey,
|
|
@@ -145,10 +118,10 @@ const createEntriesStorageOperations = params => {
|
|
|
145
118
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
146
119
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
147
120
|
}))];
|
|
121
|
+
|
|
148
122
|
/**
|
|
149
123
|
* We need to create published entry if
|
|
150
124
|
*/
|
|
151
|
-
|
|
152
125
|
if (isPublished) {
|
|
153
126
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
154
127
|
locked,
|
|
@@ -159,7 +132,6 @@ const createEntriesStorageOperations = params => {
|
|
|
159
132
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
160
133
|
})));
|
|
161
134
|
}
|
|
162
|
-
|
|
163
135
|
try {
|
|
164
136
|
await (0, _batchWrite.batchWriteAll)({
|
|
165
137
|
table: entity.table,
|
|
@@ -174,10 +146,8 @@ const createEntriesStorageOperations = params => {
|
|
|
174
146
|
entry
|
|
175
147
|
});
|
|
176
148
|
}
|
|
177
|
-
|
|
178
149
|
return initialStorageEntry;
|
|
179
150
|
};
|
|
180
|
-
|
|
181
151
|
const createRevisionFrom = async (model, params) => {
|
|
182
152
|
const {
|
|
183
153
|
entry,
|
|
@@ -197,7 +167,6 @@ const createEntriesStorageOperations = params => {
|
|
|
197
167
|
* - create the main entry item
|
|
198
168
|
* - update the last entry item to a current one
|
|
199
169
|
*/
|
|
200
|
-
|
|
201
170
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
202
171
|
PK: partitionKey,
|
|
203
172
|
SK: (0, _keys.createRevisionSortKey)(storageEntry),
|
|
@@ -211,7 +180,6 @@ const createEntriesStorageOperations = params => {
|
|
|
211
180
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
|
|
212
181
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
213
182
|
}))];
|
|
214
|
-
|
|
215
183
|
try {
|
|
216
184
|
await (0, _batchWrite.batchWriteAll)({
|
|
217
185
|
table: entity.table,
|
|
@@ -230,11 +198,8 @@ const createEntriesStorageOperations = params => {
|
|
|
230
198
|
/**
|
|
231
199
|
* There are no modifications on the entry created so just return the data.
|
|
232
200
|
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
201
|
return initialStorageEntry;
|
|
236
202
|
};
|
|
237
|
-
|
|
238
203
|
const update = async (model, params) => {
|
|
239
204
|
const {
|
|
240
205
|
entry,
|
|
@@ -257,7 +222,6 @@ const createEntriesStorageOperations = params => {
|
|
|
257
222
|
* - update the current entry
|
|
258
223
|
* - update the latest entry if the current entry is the latest one
|
|
259
224
|
*/
|
|
260
|
-
|
|
261
225
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
262
226
|
locked,
|
|
263
227
|
PK: partitionKey,
|
|
@@ -266,7 +230,6 @@ const createEntriesStorageOperations = params => {
|
|
|
266
230
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
267
231
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
268
232
|
})));
|
|
269
|
-
|
|
270
233
|
if (isPublished) {
|
|
271
234
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
272
235
|
locked,
|
|
@@ -277,13 +240,11 @@ const createEntriesStorageOperations = params => {
|
|
|
277
240
|
GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
|
|
278
241
|
})));
|
|
279
242
|
}
|
|
243
|
+
|
|
280
244
|
/**
|
|
281
245
|
* We need the latest entry to update it as well if neccessary.
|
|
282
246
|
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
247
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
286
|
-
|
|
287
248
|
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
288
249
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
289
250
|
locked,
|
|
@@ -294,7 +255,6 @@ const createEntriesStorageOperations = params => {
|
|
|
294
255
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
295
256
|
})));
|
|
296
257
|
}
|
|
297
|
-
|
|
298
258
|
try {
|
|
299
259
|
await (0, _batchWrite.batchWriteAll)({
|
|
300
260
|
table: entity.table,
|
|
@@ -312,7 +272,6 @@ const createEntriesStorageOperations = params => {
|
|
|
312
272
|
});
|
|
313
273
|
}
|
|
314
274
|
};
|
|
315
|
-
|
|
316
275
|
const deleteEntry = async (model, params) => {
|
|
317
276
|
const {
|
|
318
277
|
entry
|
|
@@ -329,7 +288,6 @@ const createEntriesStorageOperations = params => {
|
|
|
329
288
|
}
|
|
330
289
|
};
|
|
331
290
|
let records = [];
|
|
332
|
-
|
|
333
291
|
try {
|
|
334
292
|
records = await (0, _query.queryAll)(queryAllParams);
|
|
335
293
|
} catch (ex) {
|
|
@@ -338,14 +296,12 @@ const createEntriesStorageOperations = params => {
|
|
|
338
296
|
entry
|
|
339
297
|
});
|
|
340
298
|
}
|
|
341
|
-
|
|
342
299
|
const items = records.map(item => {
|
|
343
300
|
return entity.deleteBatch({
|
|
344
301
|
PK: item.PK,
|
|
345
302
|
SK: item.SK
|
|
346
303
|
});
|
|
347
304
|
});
|
|
348
|
-
|
|
349
305
|
try {
|
|
350
306
|
await (0, _batchWrite.batchWriteAll)({
|
|
351
307
|
table: entity.table,
|
|
@@ -362,7 +318,6 @@ const createEntriesStorageOperations = params => {
|
|
|
362
318
|
});
|
|
363
319
|
}
|
|
364
320
|
};
|
|
365
|
-
|
|
366
321
|
const deleteRevision = async (model, params) => {
|
|
367
322
|
const {
|
|
368
323
|
entry,
|
|
@@ -379,17 +334,16 @@ const createEntriesStorageOperations = params => {
|
|
|
379
334
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
380
335
|
})];
|
|
381
336
|
const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
337
|
+
|
|
382
338
|
/**
|
|
383
339
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
384
340
|
*/
|
|
385
|
-
|
|
386
341
|
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
387
342
|
items.push(entity.deleteBatch({
|
|
388
343
|
PK: partitionKey,
|
|
389
344
|
SK: (0, _keys.createPublishedSortKey)()
|
|
390
345
|
}));
|
|
391
346
|
}
|
|
392
|
-
|
|
393
347
|
if (initialLatestStorageEntry) {
|
|
394
348
|
const latestStorageEntry = convertToStorageEntry({
|
|
395
349
|
storageEntry: initialLatestStorageEntry,
|
|
@@ -403,7 +357,6 @@ const createEntriesStorageOperations = params => {
|
|
|
403
357
|
GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
|
|
404
358
|
})));
|
|
405
359
|
}
|
|
406
|
-
|
|
407
360
|
try {
|
|
408
361
|
await (0, _batchWrite.batchWriteAll)({
|
|
409
362
|
table: entity.table,
|
|
@@ -420,58 +373,48 @@ const createEntriesStorageOperations = params => {
|
|
|
420
373
|
});
|
|
421
374
|
}
|
|
422
375
|
};
|
|
423
|
-
|
|
424
376
|
const getLatestRevisionByEntryId = async (model, params) => {
|
|
425
377
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
426
378
|
model,
|
|
427
379
|
ids: [params.id]
|
|
428
380
|
});
|
|
429
381
|
const item = items.shift() || null;
|
|
430
|
-
|
|
431
382
|
if (!item) {
|
|
432
383
|
return null;
|
|
433
384
|
}
|
|
434
|
-
|
|
435
385
|
return convertFromStorageEntry({
|
|
436
386
|
storageEntry: item,
|
|
437
387
|
model
|
|
438
388
|
});
|
|
439
389
|
};
|
|
440
|
-
|
|
441
390
|
const getPublishedRevisionByEntryId = async (model, params) => {
|
|
442
391
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
443
392
|
model,
|
|
444
393
|
ids: [params.id]
|
|
445
394
|
});
|
|
446
395
|
const item = items.shift() || null;
|
|
447
|
-
|
|
448
396
|
if (!item) {
|
|
449
397
|
return null;
|
|
450
398
|
}
|
|
451
|
-
|
|
452
399
|
return convertFromStorageEntry({
|
|
453
400
|
storageEntry: item,
|
|
454
401
|
model
|
|
455
402
|
});
|
|
456
403
|
};
|
|
457
|
-
|
|
458
404
|
const getRevisionById = async (model, params) => {
|
|
459
405
|
const items = await dataLoaders.getRevisionById({
|
|
460
406
|
model,
|
|
461
407
|
ids: [params.id]
|
|
462
408
|
});
|
|
463
409
|
const item = items.shift() || null;
|
|
464
|
-
|
|
465
410
|
if (!item) {
|
|
466
411
|
return null;
|
|
467
412
|
}
|
|
468
|
-
|
|
469
413
|
return convertFromStorageEntry({
|
|
470
414
|
storageEntry: item,
|
|
471
415
|
model
|
|
472
416
|
});
|
|
473
417
|
};
|
|
474
|
-
|
|
475
418
|
const getRevisions = async (model, params) => {
|
|
476
419
|
const items = await dataLoaders.getAllEntryRevisions({
|
|
477
420
|
model,
|
|
@@ -484,7 +427,6 @@ const createEntriesStorageOperations = params => {
|
|
|
484
427
|
});
|
|
485
428
|
});
|
|
486
429
|
};
|
|
487
|
-
|
|
488
430
|
const getByIds = async (model, params) => {
|
|
489
431
|
const items = await dataLoaders.getRevisionById({
|
|
490
432
|
model,
|
|
@@ -497,7 +439,6 @@ const createEntriesStorageOperations = params => {
|
|
|
497
439
|
});
|
|
498
440
|
});
|
|
499
441
|
};
|
|
500
|
-
|
|
501
442
|
const getLatestByIds = async (model, params) => {
|
|
502
443
|
const items = await dataLoaders.getLatestRevisionByEntryId({
|
|
503
444
|
model,
|
|
@@ -510,7 +451,6 @@ const createEntriesStorageOperations = params => {
|
|
|
510
451
|
});
|
|
511
452
|
});
|
|
512
453
|
};
|
|
513
|
-
|
|
514
454
|
const getPublishedByIds = async (model, params) => {
|
|
515
455
|
const items = await dataLoaders.getPublishedRevisionByEntryId({
|
|
516
456
|
model,
|
|
@@ -523,7 +463,6 @@ const createEntriesStorageOperations = params => {
|
|
|
523
463
|
});
|
|
524
464
|
});
|
|
525
465
|
};
|
|
526
|
-
|
|
527
466
|
const getPreviousRevision = async (model, params) => {
|
|
528
467
|
const {
|
|
529
468
|
entryId,
|
|
@@ -538,7 +477,6 @@ const createEntriesStorageOperations = params => {
|
|
|
538
477
|
}),
|
|
539
478
|
options: {
|
|
540
479
|
lt: `REV#${(0, _zeroPad.zeroPad)(version)}`,
|
|
541
|
-
|
|
542
480
|
/**
|
|
543
481
|
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
544
482
|
*/
|
|
@@ -552,15 +490,12 @@ const createEntriesStorageOperations = params => {
|
|
|
552
490
|
reverse: true
|
|
553
491
|
}
|
|
554
492
|
};
|
|
555
|
-
|
|
556
493
|
try {
|
|
557
494
|
const result = await (0, _query.queryOne)(queryParams);
|
|
558
495
|
const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
|
|
559
|
-
|
|
560
496
|
if (!storageEntry) {
|
|
561
497
|
return null;
|
|
562
498
|
}
|
|
563
|
-
|
|
564
499
|
return convertFromStorageEntry({
|
|
565
500
|
storageEntry,
|
|
566
501
|
model
|
|
@@ -574,7 +509,6 @@ const createEntriesStorageOperations = params => {
|
|
|
574
509
|
}));
|
|
575
510
|
}
|
|
576
511
|
};
|
|
577
|
-
|
|
578
512
|
const list = async (model, params) => {
|
|
579
513
|
const {
|
|
580
514
|
limit: initialLimit = 10,
|
|
@@ -594,10 +528,9 @@ const createEntriesStorageOperations = params => {
|
|
|
594
528
|
gte: " "
|
|
595
529
|
}
|
|
596
530
|
};
|
|
597
|
-
let
|
|
598
|
-
|
|
531
|
+
let storageEntries = [];
|
|
599
532
|
try {
|
|
600
|
-
|
|
533
|
+
storageEntries = await (0, _query.queryAll)(queryAllParams);
|
|
601
534
|
} catch (ex) {
|
|
602
535
|
throw new _error.default(ex.message, "QUERY_ENTRIES_ERROR", {
|
|
603
536
|
error: ex,
|
|
@@ -605,8 +538,7 @@ const createEntriesStorageOperations = params => {
|
|
|
605
538
|
options: queryAllParams.options
|
|
606
539
|
});
|
|
607
540
|
}
|
|
608
|
-
|
|
609
|
-
if (records.length === 0) {
|
|
541
|
+
if (storageEntries.length === 0) {
|
|
610
542
|
return {
|
|
611
543
|
hasMoreItems: false,
|
|
612
544
|
totalCount: 0,
|
|
@@ -614,7 +546,6 @@ const createEntriesStorageOperations = params => {
|
|
|
614
546
|
items: []
|
|
615
547
|
};
|
|
616
548
|
}
|
|
617
|
-
|
|
618
549
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
619
550
|
delete where["published"];
|
|
620
551
|
delete where["latest"];
|
|
@@ -622,39 +553,49 @@ const createEntriesStorageOperations = params => {
|
|
|
622
553
|
* We need an object containing field, transformers and paths.
|
|
623
554
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
624
555
|
*/
|
|
625
|
-
|
|
626
556
|
const modelFields = (0, _createFields.createFields)({
|
|
627
557
|
plugins,
|
|
628
|
-
model
|
|
558
|
+
fields: model.fields
|
|
629
559
|
});
|
|
560
|
+
const fromStorage = createStorageTransformCallable(model);
|
|
561
|
+
/**
|
|
562
|
+
* Let's transform records from storage ones to regular ones, so we do not need to do it later.
|
|
563
|
+
*
|
|
564
|
+
* This is always being done, but at least its in parallel.
|
|
565
|
+
*/
|
|
566
|
+
const records = await Promise.all(storageEntries.map(async storageEntry => {
|
|
567
|
+
const entry = convertFromStorageEntry({
|
|
568
|
+
storageEntry,
|
|
569
|
+
model
|
|
570
|
+
});
|
|
571
|
+
for (const field of model.fields) {
|
|
572
|
+
entry.values[field.fieldId] = await fromStorage(field, entry.values[field.fieldId]);
|
|
573
|
+
}
|
|
574
|
+
return entry;
|
|
575
|
+
}));
|
|
630
576
|
/**
|
|
631
577
|
* Filter the read items via the code.
|
|
632
578
|
* It will build the filters out of the where input and transform the values it is using.
|
|
633
579
|
*/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
items: records.map(record => {
|
|
637
|
-
return convertFromStorageEntry({
|
|
638
|
-
storageEntry: record,
|
|
639
|
-
model
|
|
640
|
-
});
|
|
641
|
-
}),
|
|
580
|
+
const filteredItems = (0, _filtering.filter)({
|
|
581
|
+
items: records,
|
|
642
582
|
where,
|
|
643
583
|
plugins,
|
|
644
584
|
fields: modelFields,
|
|
645
|
-
fromStorage: createStorageTransformCallable(model),
|
|
646
585
|
fullTextSearch: {
|
|
647
586
|
term: search,
|
|
648
587
|
fields: fields || []
|
|
649
588
|
}
|
|
650
589
|
});
|
|
651
590
|
const totalCount = filteredItems.length;
|
|
591
|
+
|
|
652
592
|
/**
|
|
653
593
|
* Sorting is also done via the code.
|
|
654
594
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
655
595
|
*/
|
|
656
|
-
|
|
657
596
|
const sortedItems = (0, _filtering.sort)({
|
|
597
|
+
model,
|
|
598
|
+
plugins,
|
|
658
599
|
items: filteredItems,
|
|
659
600
|
sort: sortBy,
|
|
660
601
|
fields: modelFields
|
|
@@ -667,7 +608,6 @@ const createEntriesStorageOperations = params => {
|
|
|
667
608
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
668
609
|
* Number is simply encoded.
|
|
669
610
|
*/
|
|
670
|
-
|
|
671
611
|
const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
|
|
672
612
|
return {
|
|
673
613
|
hasMoreItems,
|
|
@@ -676,7 +616,6 @@ const createEntriesStorageOperations = params => {
|
|
|
676
616
|
items: (0, _cleanup.cleanupItems)(entity, slicedItems)
|
|
677
617
|
};
|
|
678
618
|
};
|
|
679
|
-
|
|
680
619
|
const get = async (model, params) => {
|
|
681
620
|
const {
|
|
682
621
|
items
|
|
@@ -685,7 +624,6 @@ const createEntriesStorageOperations = params => {
|
|
|
685
624
|
}));
|
|
686
625
|
return items.shift() || null;
|
|
687
626
|
};
|
|
688
|
-
|
|
689
627
|
const publish = async (model, params) => {
|
|
690
628
|
const {
|
|
691
629
|
entry,
|
|
@@ -696,10 +634,10 @@ const createEntriesStorageOperations = params => {
|
|
|
696
634
|
locale: model.locale,
|
|
697
635
|
tenant: model.tenant
|
|
698
636
|
});
|
|
637
|
+
|
|
699
638
|
/**
|
|
700
639
|
* We need the latest and published entries to see if something needs to be updated along side the publishing one.
|
|
701
640
|
*/
|
|
702
|
-
|
|
703
641
|
const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
704
642
|
const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
|
|
705
643
|
const storageEntry = convertToStorageEntry({
|
|
@@ -713,7 +651,6 @@ const createEntriesStorageOperations = params => {
|
|
|
713
651
|
* - latest sort key - if entry updated is actually latest
|
|
714
652
|
* - previous published entry to unpublished status - if any previously published entry
|
|
715
653
|
*/
|
|
716
|
-
|
|
717
654
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
718
655
|
PK: partitionKey,
|
|
719
656
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
@@ -727,7 +664,6 @@ const createEntriesStorageOperations = params => {
|
|
|
727
664
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
|
|
728
665
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
729
666
|
}))];
|
|
730
|
-
|
|
731
667
|
if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
|
|
732
668
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
733
669
|
PK: partitionKey,
|
|
@@ -737,7 +673,6 @@ const createEntriesStorageOperations = params => {
|
|
|
737
673
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
738
674
|
})));
|
|
739
675
|
}
|
|
740
|
-
|
|
741
676
|
if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
|
|
742
677
|
const publishedStorageEntry = convertToStorageEntry({
|
|
743
678
|
storageEntry: initialPublishedStorageEntry,
|
|
@@ -752,7 +687,6 @@ const createEntriesStorageOperations = params => {
|
|
|
752
687
|
GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
|
|
753
688
|
})));
|
|
754
689
|
}
|
|
755
|
-
|
|
756
690
|
try {
|
|
757
691
|
await (0, _batchWrite.batchWriteAll)({
|
|
758
692
|
table: entity.table,
|
|
@@ -770,7 +704,6 @@ const createEntriesStorageOperations = params => {
|
|
|
770
704
|
});
|
|
771
705
|
}
|
|
772
706
|
};
|
|
773
|
-
|
|
774
707
|
const unpublish = async (model, params) => {
|
|
775
708
|
const {
|
|
776
709
|
entry,
|
|
@@ -791,7 +724,6 @@ const createEntriesStorageOperations = params => {
|
|
|
791
724
|
* - update current entry revision with new data
|
|
792
725
|
* - update latest entry status - if entry being unpublished is latest
|
|
793
726
|
*/
|
|
794
|
-
|
|
795
727
|
const items = [entity.deleteBatch({
|
|
796
728
|
PK: partitionKey,
|
|
797
729
|
SK: (0, _keys.createPublishedSortKey)()
|
|
@@ -802,12 +734,11 @@ const createEntriesStorageOperations = params => {
|
|
|
802
734
|
GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
|
|
803
735
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
804
736
|
}))];
|
|
737
|
+
|
|
805
738
|
/**
|
|
806
739
|
* We need the latest entry to see if something needs to be updated along side the unpublishing one.
|
|
807
740
|
*/
|
|
808
|
-
|
|
809
741
|
const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
|
|
810
|
-
|
|
811
742
|
if (latestStorageEntry && entry.id === latestStorageEntry.id) {
|
|
812
743
|
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
813
744
|
PK: partitionKey,
|
|
@@ -817,7 +748,6 @@ const createEntriesStorageOperations = params => {
|
|
|
817
748
|
GSI1_SK: (0, _keys.createGSISortKey)(entry)
|
|
818
749
|
})));
|
|
819
750
|
}
|
|
820
|
-
|
|
821
751
|
try {
|
|
822
752
|
await (0, _batchWrite.batchWriteAll)({
|
|
823
753
|
table: entity.table,
|
|
@@ -834,7 +764,6 @@ const createEntriesStorageOperations = params => {
|
|
|
834
764
|
});
|
|
835
765
|
}
|
|
836
766
|
};
|
|
837
|
-
|
|
838
767
|
return {
|
|
839
768
|
create,
|
|
840
769
|
createRevisionFrom,
|
|
@@ -855,5 +784,4 @@ const createEntriesStorageOperations = params => {
|
|
|
855
784
|
unpublish
|
|
856
785
|
};
|
|
857
786
|
};
|
|
858
|
-
|
|
859
787
|
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|