@webiny/api-headless-cms-ddb 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.7f63ea0744
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/model.js +5 -0
- package/definitions/model.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +10 -3
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +6 -0
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js.map +1 -1
- package/index.js +16 -5
- package/index.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +176 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +14 -0
- package/operations/entry/filtering/createFields.js +105 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +17 -0
- package/operations/entry/filtering/extractSort.js +67 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +15 -0
- package/operations/entry/filtering/filter.js +143 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
- package/operations/entry/filtering/fullTextSearch.js +48 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +63 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +19 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +31 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +41 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +13 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +86 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +71 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +12 -0
- package/operations/entry/filtering/sort.js +69 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +70 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +16 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- 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.d.ts +5 -0
- package/operations/entry/filtering/where.js +32 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.js +31 -18
- package/operations/entry/index.js.map +1 -1
- package/package.json +13 -13
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -0
- package/plugins/index.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
- package/operations/entry/utils.d.ts +0 -36
- package/operations/entry/utils.js +0 -566
- package/operations/entry/utils.js.map +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.objectFilterCreate = void 0;
|
|
8
|
+
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
9
|
+
var _where = require("../where");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
var _transform = require("../transform");
|
|
12
|
+
const objectFilterCreate = () => {
|
|
13
|
+
return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
14
|
+
fieldType: "object",
|
|
15
|
+
create: params => {
|
|
16
|
+
const {
|
|
17
|
+
value: objectValue,
|
|
18
|
+
valueFilterPlugins,
|
|
19
|
+
transformValuePlugins,
|
|
20
|
+
getFilterCreatePlugin,
|
|
21
|
+
field: parentField,
|
|
22
|
+
fields
|
|
23
|
+
} = params;
|
|
24
|
+
const filters = [];
|
|
25
|
+
for (const key in objectValue) {
|
|
26
|
+
const value = objectValue[key];
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const whereParams = (0, _where.extractWhereParams)(key);
|
|
31
|
+
if (!whereParams) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const {
|
|
35
|
+
negate,
|
|
36
|
+
fieldId,
|
|
37
|
+
operation
|
|
38
|
+
} = whereParams;
|
|
39
|
+
const fieldPath = parentField.parents.map(p => p.fieldId).concat([parentField.fieldId, fieldId]).join(".");
|
|
40
|
+
const field = fields[fieldPath];
|
|
41
|
+
if (!field) {
|
|
42
|
+
throw new _error.default(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
|
|
43
|
+
fieldId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
47
|
+
const transformValuePlugin = transformValuePlugins[field.type];
|
|
48
|
+
const transformValueCallable = value => {
|
|
49
|
+
if (!transformValuePlugin) {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
return transformValuePlugin.transform({
|
|
53
|
+
field,
|
|
54
|
+
value
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const result = filterCreatePlugin.create({
|
|
58
|
+
key,
|
|
59
|
+
value,
|
|
60
|
+
valueFilterPlugins,
|
|
61
|
+
transformValuePlugins,
|
|
62
|
+
getFilterCreatePlugin,
|
|
63
|
+
operation,
|
|
64
|
+
negate,
|
|
65
|
+
field,
|
|
66
|
+
fields,
|
|
67
|
+
compareValue: (0, _transform.transformValue)({
|
|
68
|
+
value,
|
|
69
|
+
transform: transformValueCallable
|
|
70
|
+
}),
|
|
71
|
+
transformValue: transformValueCallable
|
|
72
|
+
});
|
|
73
|
+
if (!result) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(result)) {
|
|
77
|
+
filters.push(...result);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
filters.push(result);
|
|
81
|
+
}
|
|
82
|
+
return filters;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
exports.objectFilterCreate = objectFilterCreate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["objectFilterCreate","CmsEntryFieldFilterPlugin","fieldType","create","params","value","objectValue","valueFilterPlugins","transformValuePlugins","getFilterCreatePlugin","field","parentField","fields","filters","key","undefined","whereParams","extractWhereParams","negate","fieldId","operation","fieldPath","parents","map","p","concat","join","WebinyError","filterCreatePlugin","type","transformValuePlugin","transformValueCallable","transform","result","compareValue","transformValue","Array","isArray","push"],"sources":["objectFilterCreate.ts"],"sourcesContent":["import { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { transformValue } from \"~/operations/entry/filtering/transform\";\n\nexport const objectFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: \"object\",\n create: params => {\n const {\n value: objectValue,\n valueFilterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n field: parentField,\n fields\n } = params;\n\n const filters = [];\n\n for (const key in objectValue) {\n const value = objectValue[key];\n if (value === undefined) {\n continue;\n }\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n const { negate, fieldId, operation } = whereParams;\n\n const fieldPath = parentField.parents\n .map(p => p.fieldId)\n .concat([parentField.fieldId, fieldId])\n .join(\".\");\n\n const field = fields[fieldPath];\n if (!field) {\n throw new WebinyError(\n `There is no field with the field path \"${fieldPath}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n if (!result) {\n continue;\n }\n if (Array.isArray(result)) {\n filters.push(...result);\n continue;\n }\n\n filters.push(result);\n }\n return filters;\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AAEO,MAAMA,kBAAkB,GAAG,MAAM;EACpC,OAAO,IAAIC,oDAAyB,CAAC;IACjCC,SAAS,EAAE,QAAQ;IACnBC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QACFC,KAAK,EAAEC,WAAW;QAClBC,kBAAkB;QAClBC,qBAAqB;QACrBC,qBAAqB;QACrBC,KAAK,EAAEC,WAAW;QAClBC;MACJ,CAAC,GAAGR,MAAM;MAEV,MAAMS,OAAO,GAAG,EAAE;MAElB,KAAK,MAAMC,GAAG,IAAIR,WAAW,EAAE;QAC3B,MAAMD,KAAK,GAAGC,WAAW,CAACQ,GAAG,CAAC;QAC9B,IAAIT,KAAK,KAAKU,SAAS,EAAE;UACrB;QACJ;QACA,MAAMC,WAAW,GAAG,IAAAC,yBAAkB,EAACH,GAAG,CAAC;QAC3C,IAAI,CAACE,WAAW,EAAE;UACd;QACJ;QACA,MAAM;UAAEE,MAAM;UAAEC,OAAO;UAAEC;QAAU,CAAC,GAAGJ,WAAW;QAElD,MAAMK,SAAS,GAAGV,WAAW,CAACW,OAAO,CAChCC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACL,OAAO,CAAC,CACnBM,MAAM,CAAC,CAACd,WAAW,CAACQ,OAAO,EAAEA,OAAO,CAAC,CAAC,CACtCO,IAAI,CAAC,GAAG,CAAC;QAEd,MAAMhB,KAAK,GAAGE,MAAM,CAACS,SAAS,CAAC;QAC/B,IAAI,CAACX,KAAK,EAAE;UACR,MAAM,IAAIiB,cAAW,CAChB,0CAAyCN,SAAU,IAAG,EACvD,aAAa,EACb;YACIF;UACJ,CAAC,CACJ;QACL;QAEA,MAAMS,kBAAkB,GAAGnB,qBAAqB,CAACC,KAAK,CAACmB,IAAI,CAAC;QAE5D,MAAMC,oBAAwD,GAC1DtB,qBAAqB,CAACE,KAAK,CAACmB,IAAI,CAAC;QAErC,MAAME,sBAAsB,GAAI1B,KAAU,IAAK;UAC3C,IAAI,CAACyB,oBAAoB,EAAE;YACvB,OAAOzB,KAAK;UAChB;UACA,OAAOyB,oBAAoB,CAACE,SAAS,CAAC;YAClCtB,KAAK;YACLL;UACJ,CAAC,CAAC;QACN,CAAC;QAED,MAAM4B,MAAM,GAAGL,kBAAkB,CAACzB,MAAM,CAAC;UACrCW,GAAG;UACHT,KAAK;UACLE,kBAAkB;UAClBC,qBAAqB;UACrBC,qBAAqB;UACrBW,SAAS;UACTF,MAAM;UACNR,KAAK;UACLE,MAAM;UACNsB,YAAY,EAAE,IAAAC,yBAAc,EAAC;YACzB9B,KAAK;YACL2B,SAAS,EAAED;UACf,CAAC,CAAC;UACFI,cAAc,EAAEJ;QACpB,CAAC,CAAC;QACF,IAAI,CAACE,MAAM,EAAE;UACT;QACJ;QACA,IAAIG,KAAK,CAACC,OAAO,CAACJ,MAAM,CAAC,EAAE;UACvBpB,OAAO,CAACyB,IAAI,CAAC,GAAGL,MAAM,CAAC;UACvB;QACJ;QAEApB,OAAO,CAACyB,IAAI,CAACL,MAAM,CAAC;MACxB;MACA,OAAOpB,OAAO;IAClB;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createRefFilterCreate = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
10
|
+
var _where = require("../where");
|
|
11
|
+
var _transform = require("../transform");
|
|
12
|
+
const createRefFilterCreate = () => {
|
|
13
|
+
return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
14
|
+
fieldType: "ref",
|
|
15
|
+
create: params => {
|
|
16
|
+
const {
|
|
17
|
+
value,
|
|
18
|
+
valueFilterPlugins,
|
|
19
|
+
transformValuePlugins,
|
|
20
|
+
field
|
|
21
|
+
} = params;
|
|
22
|
+
const propertyFilters = Object.keys(value);
|
|
23
|
+
if (propertyFilters.length === 0) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const filters = [];
|
|
27
|
+
for (const propertyFilter of propertyFilters) {
|
|
28
|
+
const whereParams = (0, _where.extractWhereParams)(propertyFilter);
|
|
29
|
+
if (!whereParams) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const {
|
|
33
|
+
fieldId: propertyId,
|
|
34
|
+
operation: propertyOperation,
|
|
35
|
+
negate
|
|
36
|
+
} = whereParams;
|
|
37
|
+
const transformValuePlugin = transformValuePlugins[field.type];
|
|
38
|
+
const transformValueCallable = value => {
|
|
39
|
+
if (!transformValuePlugin) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
return transformValuePlugin.transform({
|
|
43
|
+
field,
|
|
44
|
+
value
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const filterPlugin = valueFilterPlugins[propertyOperation];
|
|
48
|
+
if (!filterPlugin) {
|
|
49
|
+
throw new _error.default(`Missing operation filter for "${propertyOperation}".`, "MISSING_OPERATION_FILTER");
|
|
50
|
+
}
|
|
51
|
+
const paths = [field.createPath({
|
|
52
|
+
field
|
|
53
|
+
}), propertyId];
|
|
54
|
+
filters.push({
|
|
55
|
+
field,
|
|
56
|
+
path: paths.join("."),
|
|
57
|
+
fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
|
|
58
|
+
plugin: filterPlugin,
|
|
59
|
+
negate,
|
|
60
|
+
compareValue: (0, _transform.transformValue)({
|
|
61
|
+
value: value[propertyFilter],
|
|
62
|
+
transform: transformValueCallable
|
|
63
|
+
}),
|
|
64
|
+
transformValue: transformValueCallable
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return filters;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
exports.createRefFilterCreate = createRefFilterCreate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createRefFilterCreate","CmsEntryFieldFilterPlugin","fieldType","create","params","value","valueFilterPlugins","transformValuePlugins","field","propertyFilters","Object","keys","length","filters","propertyFilter","whereParams","extractWhereParams","fieldId","propertyId","operation","propertyOperation","negate","transformValuePlugin","type","transformValueCallable","transform","filterPlugin","WebinyError","paths","createPath","push","path","join","fieldPathId","parents","map","f","plugin","compareValue","transformValue"],"sources":["refFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n CmsEntryFieldFilterPlugin,\n CmsEntryFieldFilterPluginCreateResponse\n} from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where\";\nimport { transformValue } from \"~/operations/entry/filtering/transform\";\n\nexport const createRefFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: \"ref\",\n create: params => {\n const { value, valueFilterPlugins, transformValuePlugins, field } = params;\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n return null;\n }\n\n const filters: CmsEntryFieldFilterPluginCreateResponse[] = [];\n\n for (const propertyFilter of propertyFilters) {\n const whereParams = extractWhereParams(propertyFilter);\n if (!whereParams) {\n continue;\n }\n const { fieldId: propertyId, operation: propertyOperation, negate } = whereParams;\n\n const transformValuePlugin = transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const filterPlugin = valueFilterPlugins[propertyOperation];\n if (!filterPlugin) {\n throw new WebinyError(\n `Missing operation filter for \"${propertyOperation}\".`,\n \"MISSING_OPERATION_FILTER\"\n );\n }\n\n const paths = [\n field.createPath({\n field\n }),\n propertyId\n ];\n\n filters.push({\n field,\n path: paths.join(\".\"),\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n plugin: filterPlugin,\n negate,\n compareValue: transformValue({\n value: value[propertyFilter],\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n }\n\n return filters;\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAIA;AACA;AAEO,MAAMA,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIC,oDAAyB,CAAC;IACjCC,SAAS,EAAE,KAAK;IAChBC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,KAAK;QAAEC,kBAAkB;QAAEC,qBAAqB;QAAEC;MAAM,CAAC,GAAGJ,MAAM;MAC1E,MAAMK,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACN,KAAK,CAAC;MAC1C,IAAII,eAAe,CAACG,MAAM,KAAK,CAAC,EAAE;QAC9B,OAAO,IAAI;MACf;MAEA,MAAMC,OAAkD,GAAG,EAAE;MAE7D,KAAK,MAAMC,cAAc,IAAIL,eAAe,EAAE;QAC1C,MAAMM,WAAW,GAAG,IAAAC,yBAAkB,EAACF,cAAc,CAAC;QACtD,IAAI,CAACC,WAAW,EAAE;UACd;QACJ;QACA,MAAM;UAAEE,OAAO,EAAEC,UAAU;UAAEC,SAAS,EAAEC,iBAAiB;UAAEC;QAAO,CAAC,GAAGN,WAAW;QAEjF,MAAMO,oBAAoB,GAAGf,qBAAqB,CAACC,KAAK,CAACe,IAAI,CAAC;QAE9D,MAAMC,sBAAsB,GAAInB,KAAU,IAAK;UAC3C,IAAI,CAACiB,oBAAoB,EAAE;YACvB,OAAOjB,KAAK;UAChB;UACA,OAAOiB,oBAAoB,CAACG,SAAS,CAAC;YAClCjB,KAAK;YACLH;UACJ,CAAC,CAAC;QACN,CAAC;QAED,MAAMqB,YAAY,GAAGpB,kBAAkB,CAACc,iBAAiB,CAAC;QAC1D,IAAI,CAACM,YAAY,EAAE;UACf,MAAM,IAAIC,cAAW,CAChB,iCAAgCP,iBAAkB,IAAG,EACtD,0BAA0B,CAC7B;QACL;QAEA,MAAMQ,KAAK,GAAG,CACVpB,KAAK,CAACqB,UAAU,CAAC;UACbrB;QACJ,CAAC,CAAC,EACFU,UAAU,CACb;QAEDL,OAAO,CAACiB,IAAI,CAAC;UACTtB,KAAK;UACLuB,IAAI,EAAEH,KAAK,CAACI,IAAI,CAAC,GAAG,CAAC;UACrBC,WAAW,EAAE,CAAC,GAAGzB,KAAK,CAAC0B,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACnB,OAAO,CAAC,EAAET,KAAK,CAACS,OAAO,CAAC,CAACe,IAAI,CAAC,GAAG,CAAC;UAC5EK,MAAM,EAAEX,YAAY;UACpBL,MAAM;UACNiB,YAAY,EAAE,IAAAC,yBAAc,EAAC;YACzBlC,KAAK,EAAEA,KAAK,CAACS,cAAc,CAAC;YAC5BW,SAAS,EAAED;UACf,CAAC,CAAC;UACFe,cAAc,EAAEf;QACpB,CAAC,CAAC;MACN;MAEA,OAAOX,OAAO;IAClB;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Field } from "./types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
interface Params {
|
|
5
|
+
model: CmsModel;
|
|
6
|
+
items: CmsEntry[];
|
|
7
|
+
sort?: string[];
|
|
8
|
+
fields: Record<string, Field>;
|
|
9
|
+
plugins: PluginsContainer;
|
|
10
|
+
}
|
|
11
|
+
export declare const sort: (params: Params) => CmsEntry[];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.sort = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
10
|
+
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
11
|
+
var _extractSort = require("./extractSort");
|
|
12
|
+
const sort = params => {
|
|
13
|
+
const {
|
|
14
|
+
model,
|
|
15
|
+
items,
|
|
16
|
+
sort = [],
|
|
17
|
+
fields,
|
|
18
|
+
plugins
|
|
19
|
+
} = params;
|
|
20
|
+
if (items.length <= 1) {
|
|
21
|
+
return items;
|
|
22
|
+
} else if (sort.length === 0) {
|
|
23
|
+
sort.push("savedOn_DESC");
|
|
24
|
+
} else if (sort.length > 1) {
|
|
25
|
+
throw new _error.default("Sorting is limited to a single field.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
26
|
+
sort: sort
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const [firstSort] = sort;
|
|
30
|
+
if (!firstSort) {
|
|
31
|
+
throw new _error.default("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
32
|
+
sort
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
fieldId,
|
|
37
|
+
field,
|
|
38
|
+
valuePath,
|
|
39
|
+
reverse
|
|
40
|
+
} = (0, _extractSort.extractSort)({
|
|
41
|
+
model,
|
|
42
|
+
sortBy: firstSort,
|
|
43
|
+
fields,
|
|
44
|
+
plugins
|
|
45
|
+
});
|
|
46
|
+
const itemsToSort = items.map(item => {
|
|
47
|
+
return {
|
|
48
|
+
id: item.id,
|
|
49
|
+
value: field.transform(_dotProp.default.get(item, valuePath))
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const sortedItems = (0, _sortBy.default)(itemsToSort, "value");
|
|
53
|
+
const newItems = sortedItems.map(s => {
|
|
54
|
+
const item = items.find(i => i.id === s.id);
|
|
55
|
+
if (item) {
|
|
56
|
+
return item;
|
|
57
|
+
}
|
|
58
|
+
throw new _error.default("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
59
|
+
id: s.id,
|
|
60
|
+
sortingBy: fieldId,
|
|
61
|
+
reverse
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
if (!reverse) {
|
|
65
|
+
return newItems;
|
|
66
|
+
}
|
|
67
|
+
return newItems.reverse();
|
|
68
|
+
};
|
|
69
|
+
exports.sort = sort;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["sort","params","model","items","fields","plugins","length","push","WebinyError","firstSort","fieldId","field","valuePath","reverse","extractSort","sortBy","itemsToSort","map","item","id","value","transform","dotProp","get","sortedItems","lodashSortBy","newItems","s","find","i","sortingBy"],"sources":["sort.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport dotProp from \"dot-prop\";\nimport lodashSortBy from \"lodash/sortBy\";\nimport { extractSort } from \"./extractSort\";\nimport { Field } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface Params {\n model: CmsModel;\n items: CmsEntry[];\n sort?: string[];\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\ninterface SortedItem {\n id: string;\n value: any;\n}\n\nexport const sort = (params: Params): CmsEntry[] => {\n const { model, items, sort = [], fields, plugins } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort: sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort({\n model,\n sortBy: firstSort,\n fields,\n plugins\n });\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.transform(dotProp.get(item, valuePath))\n };\n });\n const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n"],"mappings":";;;;;;;AACA;AACA;AACA;AACA;AAiBO,MAAMA,IAAI,GAAIC,MAAc,IAAiB;EAChD,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEH,IAAI,GAAG,EAAE;IAAEI,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAC3D,IAAIE,KAAK,CAACG,MAAM,IAAI,CAAC,EAAE;IACnB,OAAOH,KAAK;EAChB,CAAC,MAAM,IAAIH,IAAI,CAACM,MAAM,KAAK,CAAC,EAAE;IAC1BN,IAAI,CAACO,IAAI,CAAC,cAAc,CAAC;EAC7B,CAAC,MAAM,IAAIP,IAAI,CAACM,MAAM,GAAG,CAAC,EAAE;IACxB,MAAM,IAAIE,cAAW,CACjB,uCAAuC,EACvC,4BAA4B,EAC5B;MACIR,IAAI,EAAEA;IACV,CAAC,CACJ;EACL;EACA,MAAM,CAACS,SAAS,CAAC,GAAGT,IAAI;EACxB,IAAI,CAACS,SAAS,EAAE;IACZ,MAAM,IAAID,cAAW,CAAC,wBAAwB,EAAE,kBAAkB,EAAE;MAChER;IACJ,CAAC,CAAC;EACN;EAEA,MAAM;IAAEU,OAAO;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAQ,CAAC,GAAG,IAAAC,wBAAW,EAAC;IACvDZ,KAAK;IACLa,MAAM,EAAEN,SAAS;IACjBL,MAAM;IACNC;EACJ,CAAC,CAAC;EAEF,MAAMW,WAAW,GAAGb,KAAK,CAACc,GAAG,CAACC,IAAI,IAAI;IAClC,OAAO;MACHC,EAAE,EAAED,IAAI,CAACC,EAAE;MACXC,KAAK,EAAET,KAAK,CAACU,SAAS,CAACC,gBAAO,CAACC,GAAG,CAACL,IAAI,EAAEN,SAAS,CAAC;IACvD,CAAC;EACL,CAAC,CAAC;EACF,MAAMY,WAAyB,GAAG,IAAAC,eAAY,EAACT,WAAW,EAAE,OAAO,CAAC;EACpE,MAAMU,QAAQ,GAAGF,WAAW,CAACP,GAAG,CAACU,CAAC,IAAI;IAClC,MAAMT,IAAI,GAAGf,KAAK,CAACyB,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACV,EAAE,KAAKQ,CAAC,CAACR,EAAE,CAAC;IAC3C,IAAID,IAAI,EAAE;MACN,OAAOA,IAAI;IACf;IACA,MAAM,IAAIV,cAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIW,EAAE,EAAEQ,CAAC,CAACR,EAAE;MACRW,SAAS,EAAEpB,OAAO;MAClBG;IACJ,CAAC,CACJ;EACL,CAAC,CAAC;EACF,IAAI,CAACA,OAAO,EAAE;IACV,OAAOa,QAAQ;EACnB;EACA,OAAOA,QAAQ,CAACb,OAAO,EAAE;AAC7B,CAAC;AAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSystemFields = void 0;
|
|
7
|
+
const createSystemFields = () => {
|
|
8
|
+
return [{
|
|
9
|
+
id: "id",
|
|
10
|
+
type: "text",
|
|
11
|
+
storageId: "id",
|
|
12
|
+
fieldId: "id",
|
|
13
|
+
label: "ID"
|
|
14
|
+
}, {
|
|
15
|
+
id: "entryId",
|
|
16
|
+
type: "text",
|
|
17
|
+
storageId: "entryId",
|
|
18
|
+
fieldId: "entryId",
|
|
19
|
+
label: "Entry ID"
|
|
20
|
+
}, {
|
|
21
|
+
id: "createdOn",
|
|
22
|
+
type: "datetime",
|
|
23
|
+
storageId: "createdOn",
|
|
24
|
+
fieldId: "createdOn",
|
|
25
|
+
label: "Created On"
|
|
26
|
+
}, {
|
|
27
|
+
id: "savedOn",
|
|
28
|
+
type: "datetime",
|
|
29
|
+
storageId: "savedOn",
|
|
30
|
+
fieldId: "savedOn",
|
|
31
|
+
label: "Saved On"
|
|
32
|
+
}, {
|
|
33
|
+
id: "createdBy",
|
|
34
|
+
type: "plainObject",
|
|
35
|
+
storageId: "createdBy",
|
|
36
|
+
fieldId: "createdBy",
|
|
37
|
+
label: "Created By",
|
|
38
|
+
settings: {
|
|
39
|
+
path: "createdBy.id"
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
id: "meta",
|
|
43
|
+
type: "plainObject",
|
|
44
|
+
storageId: "meta",
|
|
45
|
+
fieldId: "meta",
|
|
46
|
+
label: "Meta"
|
|
47
|
+
}, {
|
|
48
|
+
id: "ownedBy",
|
|
49
|
+
type: "plainObject",
|
|
50
|
+
storageId: "ownedBy",
|
|
51
|
+
fieldId: "ownedBy",
|
|
52
|
+
label: "Owned By",
|
|
53
|
+
settings: {
|
|
54
|
+
path: "ownedBy.id"
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
id: "version",
|
|
58
|
+
type: "number",
|
|
59
|
+
storageId: "version",
|
|
60
|
+
fieldId: "version",
|
|
61
|
+
label: "Version"
|
|
62
|
+
}, {
|
|
63
|
+
id: "status",
|
|
64
|
+
type: "text",
|
|
65
|
+
storageId: "status",
|
|
66
|
+
fieldId: "status",
|
|
67
|
+
label: "Status"
|
|
68
|
+
}];
|
|
69
|
+
};
|
|
70
|
+
exports.createSystemFields = createSystemFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSystemFields","id","type","storageId","fieldId","label","settings","path"],"sources":["systemFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ntype Field = Pick<CmsModelField, \"id\" | \"type\" | \"storageId\" | \"fieldId\" | \"settings\" | \"label\">;\n\nexport const createSystemFields = (): Field[] => {\n return [\n {\n id: \"id\",\n type: \"text\",\n storageId: \"id\",\n fieldId: \"id\",\n label: \"ID\"\n },\n {\n id: \"entryId\",\n type: \"text\",\n storageId: \"entryId\",\n fieldId: \"entryId\",\n label: \"Entry ID\"\n },\n {\n id: \"createdOn\",\n type: \"datetime\",\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n label: \"Created On\"\n },\n {\n id: \"savedOn\",\n type: \"datetime\",\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n label: \"Saved On\"\n },\n {\n id: \"createdBy\",\n type: \"plainObject\",\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n label: \"Created By\",\n settings: {\n path: \"createdBy.id\"\n }\n },\n {\n id: \"meta\",\n type: \"plainObject\",\n storageId: \"meta\",\n fieldId: \"meta\",\n label: \"Meta\"\n },\n {\n id: \"ownedBy\",\n type: \"plainObject\",\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n label: \"Owned By\",\n settings: {\n path: \"ownedBy.id\"\n }\n },\n {\n id: \"version\",\n type: \"number\",\n storageId: \"version\",\n fieldId: \"version\",\n label: \"Version\"\n },\n {\n id: \"status\",\n type: \"text\",\n storageId: \"status\",\n fieldId: \"status\",\n label: \"Status\"\n }\n ];\n};\n"],"mappings":";;;;;;AAIO,MAAMA,kBAAkB,GAAG,MAAe;EAC7C,OAAO,CACH;IACIC,EAAE,EAAE,IAAI;IACRC,IAAI,EAAE,MAAM;IACZC,SAAS,EAAE,IAAI;IACfC,OAAO,EAAE,IAAI;IACbC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,SAAS;IACbC,IAAI,EAAE,MAAM;IACZC,SAAS,EAAE,SAAS;IACpBC,OAAO,EAAE,SAAS;IAClBC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,WAAW;IACfC,IAAI,EAAE,UAAU;IAChBC,SAAS,EAAE,WAAW;IACtBC,OAAO,EAAE,WAAW;IACpBC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,SAAS;IACbC,IAAI,EAAE,UAAU;IAChBC,SAAS,EAAE,SAAS;IACpBC,OAAO,EAAE,SAAS;IAClBC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,WAAW;IACfC,IAAI,EAAE,aAAa;IACnBC,SAAS,EAAE,WAAW;IACtBC,OAAO,EAAE,WAAW;IACpBC,KAAK,EAAE,YAAY;IACnBC,QAAQ,EAAE;MACNC,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,MAAM;IACVC,IAAI,EAAE,aAAa;IACnBC,SAAS,EAAE,MAAM;IACjBC,OAAO,EAAE,MAAM;IACfC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,SAAS;IACbC,IAAI,EAAE,aAAa;IACnBC,SAAS,EAAE,SAAS;IACpBC,OAAO,EAAE,SAAS;IAClBC,KAAK,EAAE,UAAU;IACjBC,QAAQ,EAAE;MACNC,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,SAAS;IACbC,IAAI,EAAE,QAAQ;IACdC,SAAS,EAAE,SAAS;IACpBC,OAAO,EAAE,SAAS;IAClBC,KAAK,EAAE;EACX,CAAC,EACD;IACIJ,EAAE,EAAE,QAAQ;IACZC,IAAI,EAAE,MAAM;IACZC,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAE,QAAQ;IACjBC,KAAK,EAAE;EACX,CAAC,CACJ;AACL,CAAC;AAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformValue = void 0;
|
|
7
|
+
const transformValue = ({
|
|
8
|
+
value,
|
|
9
|
+
transform
|
|
10
|
+
}) => {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map(v => transform(v));
|
|
13
|
+
}
|
|
14
|
+
return transform(value);
|
|
15
|
+
};
|
|
16
|
+
exports.transformValue = transformValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transformValue","value","transform","Array","isArray","map","v"],"sources":["transform.ts"],"sourcesContent":["import { Field } from \"./types\";\n\ninterface Params extends Pick<Field, \"transform\"> {\n value: any;\n}\nexport const transformValue = ({ value, transform }: Params): any => {\n if (Array.isArray(value)) {\n return value.map(v => transform(v));\n }\n return transform(value);\n};\n"],"mappings":";;;;;;AAKO,MAAMA,cAAc,GAAG,CAAC;EAAEC,KAAK;EAAEC;AAAkB,CAAC,KAAU;EACjE,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IACtB,OAAOA,KAAK,CAACI,GAAG,CAACC,CAAC,IAAIJ,SAAS,CAACI,CAAC,CAAC,CAAC;EACvC;EACA,OAAOJ,SAAS,CAACD,KAAK,CAAC;AAC3B,CAAC;AAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { CreatePathCallable } from "../../../plugins";
|
|
3
|
+
interface FieldValueTransform {
|
|
4
|
+
(value: any): any;
|
|
5
|
+
}
|
|
6
|
+
export interface FieldParent {
|
|
7
|
+
fieldId: string;
|
|
8
|
+
multipleValues?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface Field extends Partial<Omit<CmsModelField, "id" | "type" | "storageId" | "fieldId">>, Pick<CmsModelField, "id" | "type" | "storageId" | "fieldId"> {
|
|
11
|
+
/**
|
|
12
|
+
* A list od fieldId of all parents of the current field.
|
|
13
|
+
*
|
|
14
|
+
* This is used to check if we need to iterate through an array of parent values.
|
|
15
|
+
*/
|
|
16
|
+
parents: FieldParent[];
|
|
17
|
+
/**
|
|
18
|
+
* The method which creates a path for the filtering.
|
|
19
|
+
*
|
|
20
|
+
* Always exists. In most cases it will return some fixed value.
|
|
21
|
+
* When having a CmsEntryFieldFilterPathPlugin then it is executed to create a path.
|
|
22
|
+
*/
|
|
23
|
+
createPath: CreatePathCallable;
|
|
24
|
+
/**
|
|
25
|
+
* In most cases, return value of this method is what ever is the input.
|
|
26
|
+
*
|
|
27
|
+
* In some cases there might be a CmsFieldFilterValueTransformPlugin, which transforms value to a comparable one.
|
|
28
|
+
* For example, time in format 15:45:58 is not comparable, so we transform it into the seconds and then compare.
|
|
29
|
+
*/
|
|
30
|
+
transform: FieldValueTransform;
|
|
31
|
+
/**
|
|
32
|
+
* Is the field a system field?
|
|
33
|
+
* System fields are built into the code and cannot be changed.
|
|
34
|
+
*/
|
|
35
|
+
system: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface FilterItemFromStorage {
|
|
38
|
+
<T = any>(field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id" | "settings" | "type">, value: any): Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { CreatePathCallable } from \"~/plugins\";\n\ninterface FieldValueTransform {\n (value: any): any;\n}\n\nexport interface FieldParent {\n fieldId: string;\n multipleValues?: boolean;\n}\n\nexport interface Field\n extends Partial<Omit<CmsModelField, \"id\" | \"type\" | \"storageId\" | \"fieldId\">>,\n Pick<CmsModelField, \"id\" | \"type\" | \"storageId\" | \"fieldId\"> {\n /**\n * A list od fieldId of all parents of the current field.\n *\n * This is used to check if we need to iterate through an array of parent values.\n */\n parents: FieldParent[];\n /**\n * The method which creates a path for the filtering.\n *\n * Always exists. In most cases it will return some fixed value.\n * When having a CmsEntryFieldFilterPathPlugin then it is executed to create a path.\n */\n createPath: CreatePathCallable;\n /**\n * In most cases, return value of this method is what ever is the input.\n *\n * In some cases there might be a CmsFieldFilterValueTransformPlugin, which transforms value to a comparable one.\n * For example, time in format 15:45:58 is not comparable, so we transform it into the seconds and then compare.\n */\n transform: FieldValueTransform;\n /**\n * Is the field a system field?\n * System fields are built into the code and cannot be changed.\n */\n system: boolean;\n}\n\nexport interface FilterItemFromStorage {\n <T = any>(\n field: Partial<CmsModelField> &\n Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\" | \"settings\" | \"type\">,\n value: any\n ): Promise<T>;\n}\n"],"mappings":""}
|
|
@@ -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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractWhereParams = void 0;
|
|
7
|
+
const extractWhereParams = key => {
|
|
8
|
+
const result = key.split("_");
|
|
9
|
+
const fieldId = result.shift();
|
|
10
|
+
if (!fieldId) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
14
|
+
/**
|
|
15
|
+
* When rawOp is not, it means it is equal negated so just return that.
|
|
16
|
+
*/
|
|
17
|
+
if (rawOp === "not") {
|
|
18
|
+
return {
|
|
19
|
+
fieldId,
|
|
20
|
+
operation: "eq",
|
|
21
|
+
negate: true
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const negate = rawOp.match("not_") !== null;
|
|
25
|
+
const operation = rawOp.replace("not_", "");
|
|
26
|
+
return {
|
|
27
|
+
fieldId,
|
|
28
|
+
operation,
|
|
29
|
+
negate
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.extractWhereParams = extractWhereParams;
|
|
@@ -0,0 +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":";;;;;;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"}
|
|
@@ -9,7 +9,6 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
10
|
var _dataLoaders = require("./dataLoaders");
|
|
11
11
|
var _types = require("@webiny/api-headless-cms/types");
|
|
12
|
-
var _utils = require("./utils");
|
|
13
12
|
var _keys = require("./keys");
|
|
14
13
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
15
14
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
@@ -17,6 +16,8 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
|
17
16
|
var _cursor = require("@webiny/utils/cursor");
|
|
18
17
|
var _zeroPad = require("@webiny/utils/zeroPad");
|
|
19
18
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
19
|
+
var _createFields = require("./filtering/createFields");
|
|
20
|
+
var _filtering = require("./filtering");
|
|
20
21
|
const createType = () => {
|
|
21
22
|
return "cms.entry";
|
|
22
23
|
};
|
|
@@ -513,7 +514,7 @@ const createEntriesStorageOperations = params => {
|
|
|
513
514
|
limit: initialLimit = 10,
|
|
514
515
|
where: initialWhere,
|
|
515
516
|
after,
|
|
516
|
-
sort,
|
|
517
|
+
sort: sortBy,
|
|
517
518
|
fields,
|
|
518
519
|
search
|
|
519
520
|
} = params;
|
|
@@ -527,9 +528,9 @@ const createEntriesStorageOperations = params => {
|
|
|
527
528
|
gte: " "
|
|
528
529
|
}
|
|
529
530
|
};
|
|
530
|
-
let
|
|
531
|
+
let storageEntries = [];
|
|
531
532
|
try {
|
|
532
|
-
|
|
533
|
+
storageEntries = await (0, _query.queryAll)(queryAllParams);
|
|
533
534
|
} catch (ex) {
|
|
534
535
|
throw new _error.default(ex.message, "QUERY_ENTRIES_ERROR", {
|
|
535
536
|
error: ex,
|
|
@@ -537,7 +538,7 @@ const createEntriesStorageOperations = params => {
|
|
|
537
538
|
options: queryAllParams.options
|
|
538
539
|
});
|
|
539
540
|
}
|
|
540
|
-
if (
|
|
541
|
+
if (storageEntries.length === 0) {
|
|
541
542
|
return {
|
|
542
543
|
hasMoreItems: false,
|
|
543
544
|
totalCount: 0,
|
|
@@ -549,28 +550,38 @@ const createEntriesStorageOperations = params => {
|
|
|
549
550
|
delete where["published"];
|
|
550
551
|
delete where["latest"];
|
|
551
552
|
/**
|
|
552
|
-
* We need
|
|
553
|
+
* We need an object containing field, transformers and paths.
|
|
553
554
|
* Just build it here and pass on into other methods that require it to avoid mapping multiple times.
|
|
554
555
|
*/
|
|
555
|
-
const modelFields = (0,
|
|
556
|
+
const modelFields = (0, _createFields.createFields)({
|
|
556
557
|
plugins,
|
|
557
|
-
model
|
|
558
|
+
fields: model.fields
|
|
558
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
|
+
}));
|
|
559
576
|
/**
|
|
560
577
|
* Filter the read items via the code.
|
|
561
578
|
* It will build the filters out of the where input and transform the values it is using.
|
|
562
579
|
*/
|
|
563
|
-
const filteredItems =
|
|
564
|
-
items: records
|
|
565
|
-
return convertFromStorageEntry({
|
|
566
|
-
storageEntry: record,
|
|
567
|
-
model
|
|
568
|
-
});
|
|
569
|
-
}),
|
|
580
|
+
const filteredItems = (0, _filtering.filter)({
|
|
581
|
+
items: records,
|
|
570
582
|
where,
|
|
571
583
|
plugins,
|
|
572
584
|
fields: modelFields,
|
|
573
|
-
fromStorage: createStorageTransformCallable(model),
|
|
574
585
|
fullTextSearch: {
|
|
575
586
|
term: search,
|
|
576
587
|
fields: fields || []
|
|
@@ -582,9 +593,11 @@ const createEntriesStorageOperations = params => {
|
|
|
582
593
|
* Sorting is also done via the code.
|
|
583
594
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
584
595
|
*/
|
|
585
|
-
const sortedItems = (0,
|
|
596
|
+
const sortedItems = (0, _filtering.sort)({
|
|
597
|
+
model,
|
|
598
|
+
plugins,
|
|
586
599
|
items: filteredItems,
|
|
587
|
-
sort,
|
|
600
|
+
sort: sortBy,
|
|
588
601
|
fields: modelFields
|
|
589
602
|
});
|
|
590
603
|
const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
|