@webiny/api-headless-cms-ddb 5.33.5-beta.0 → 5.34.0-beta.0
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 -7
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +8 -7
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +14 -4
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +8 -1
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +1 -1
- package/dynamoDb/storage/richText.js.map +1 -1
- package/index.js +12 -5
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +7 -9
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +217 -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 +123 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +13 -0
- package/operations/entry/filtering/extractSort.js +55 -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 +178 -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 +60 -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 +81 -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 +21 -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 +39 -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 +48 -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 +18 -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 +107 -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 +89 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +9 -0
- package/operations/entry/filtering/sort.js +80 -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 +72 -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 +19 -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 +28 -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 +38 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.js +54 -166
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +1 -1
- package/operations/entry/systemFields.js +6 -0
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/group/index.js +6 -10
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +4 -8
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +6 -10
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +4 -8
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +1 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- 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 -684
- package/operations/entry/utils.js.map +0 -1
|
@@ -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,oDAAJ,CAA8B;IACjCC,SAAS,EAAE,QADsB;IAEjCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QACFC,KAAK,EAAEC,WADL;QAEFC,kBAFE;QAGFC,qBAHE;QAIFC,qBAJE;QAKFC,KAAK,EAAEC,WALL;QAMFC;MANE,IAOFR,MAPJ;MASA,MAAMS,OAAO,GAAG,EAAhB;;MAEA,KAAK,MAAMC,GAAX,IAAkBR,WAAlB,EAA+B;QAC3B,MAAMD,KAAK,GAAGC,WAAW,CAACQ,GAAD,CAAzB;;QACA,IAAIT,KAAK,KAAKU,SAAd,EAAyB;UACrB;QACH;;QACD,MAAMC,WAAW,GAAG,IAAAC,yBAAA,EAAmBH,GAAnB,CAApB;;QACA,IAAI,CAACE,WAAL,EAAkB;UACd;QACH;;QACD,MAAM;UAAEE,MAAF;UAAUC,OAAV;UAAmBC;QAAnB,IAAiCJ,WAAvC;QAEA,MAAMK,SAAS,GAAGV,WAAW,CAACW,OAAZ,CACbC,GADa,CACTC,CAAC,IAAIA,CAAC,CAACL,OADE,EAEbM,MAFa,CAEN,CAACd,WAAW,CAACQ,OAAb,EAAsBA,OAAtB,CAFM,EAGbO,IAHa,CAGR,GAHQ,CAAlB;QAKA,MAAMhB,KAAK,GAAGE,MAAM,CAACS,SAAD,CAApB;;QACA,IAAI,CAACX,KAAL,EAAY;UACR,MAAM,IAAIiB,cAAJ,CACD,0CAAyCN,SAAU,IADlD,EAEF,aAFE,EAGF;YACIF;UADJ,CAHE,CAAN;QAOH;;QAED,MAAMS,kBAAkB,GAAGnB,qBAAqB,CAACC,KAAK,CAACmB,IAAP,CAAhD;QAEA,MAAMC,oBAAwD,GAC1DtB,qBAAqB,CAACE,KAAK,CAACmB,IAAP,CADzB;;QAGA,MAAME,sBAAsB,GAAI1B,KAAD,IAAgB;UAC3C,IAAI,CAACyB,oBAAL,EAA2B;YACvB,OAAOzB,KAAP;UACH;;UACD,OAAOyB,oBAAoB,CAACE,SAArB,CAA+B;YAClCtB,KADkC;YAElCL;UAFkC,CAA/B,CAAP;QAIH,CARD;;QAUA,MAAM4B,MAAM,GAAGL,kBAAkB,CAACzB,MAAnB,CAA0B;UACrCW,GADqC;UAErCT,KAFqC;UAGrCE,kBAHqC;UAIrCC,qBAJqC;UAKrCC,qBALqC;UAMrCW,SANqC;UAOrCF,MAPqC;UAQrCR,KARqC;UASrCE,MATqC;UAUrCsB,YAAY,EAAE,IAAAC,yBAAA,EAAe;YACzB9B,KADyB;YAEzB2B,SAAS,EAAED;UAFc,CAAf,CAVuB;UAcrCI,cAAc,EAAEJ;QAdqB,CAA1B,CAAf;;QAgBA,IAAI,CAACE,MAAL,EAAa;UACT;QACH;;QACD,IAAIG,KAAK,CAACC,OAAN,CAAcJ,MAAd,CAAJ,EAA2B;UACvBpB,OAAO,CAACyB,IAAR,CAAa,GAAGL,MAAhB;UACA;QACH;;QAEDpB,OAAO,CAACyB,IAAR,CAAaL,MAAb;MACH;;MACD,OAAOpB,OAAP;IACH;EAnFgC,CAA9B,CAAP;AAqFH,CAtFM"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createRefFilterCreate = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
13
|
+
|
|
14
|
+
var _where = require("../where");
|
|
15
|
+
|
|
16
|
+
var _transform = require("../transform");
|
|
17
|
+
|
|
18
|
+
const createRefFilterCreate = () => {
|
|
19
|
+
return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
20
|
+
fieldType: "ref",
|
|
21
|
+
create: params => {
|
|
22
|
+
const {
|
|
23
|
+
value,
|
|
24
|
+
valueFilterPlugins,
|
|
25
|
+
transformValuePlugins,
|
|
26
|
+
field
|
|
27
|
+
} = params;
|
|
28
|
+
const propertyFilters = Object.keys(value);
|
|
29
|
+
|
|
30
|
+
if (propertyFilters.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const filters = [];
|
|
35
|
+
|
|
36
|
+
for (const propertyFilter of propertyFilters) {
|
|
37
|
+
const whereParams = (0, _where.extractWhereParams)(propertyFilter);
|
|
38
|
+
|
|
39
|
+
if (!whereParams) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
fieldId: propertyId,
|
|
45
|
+
operation: propertyOperation,
|
|
46
|
+
negate
|
|
47
|
+
} = whereParams;
|
|
48
|
+
const transformValuePlugin = transformValuePlugins[field.type];
|
|
49
|
+
|
|
50
|
+
const transformValueCallable = value => {
|
|
51
|
+
if (!transformValuePlugin) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return transformValuePlugin.transform({
|
|
56
|
+
field,
|
|
57
|
+
value
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const filterPlugin = valueFilterPlugins[propertyOperation];
|
|
62
|
+
|
|
63
|
+
if (!filterPlugin) {
|
|
64
|
+
throw new _error.default(`Missing operation filter for "${propertyOperation}".`, "MISSING_OPERATION_FILTER");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const paths = [field.createPath({
|
|
68
|
+
field
|
|
69
|
+
}), propertyId];
|
|
70
|
+
filters.push({
|
|
71
|
+
field,
|
|
72
|
+
path: paths.join("."),
|
|
73
|
+
fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
|
|
74
|
+
plugin: filterPlugin,
|
|
75
|
+
negate,
|
|
76
|
+
compareValue: (0, _transform.transformValue)({
|
|
77
|
+
value: value[propertyFilter],
|
|
78
|
+
transform: transformValueCallable
|
|
79
|
+
}),
|
|
80
|
+
transformValue: transformValueCallable
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return filters;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
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,oDAAJ,CAA8B;IACjCC,SAAS,EAAE,KADsB;IAEjCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,KAAF;QAASC,kBAAT;QAA6BC,qBAA7B;QAAoDC;MAApD,IAA8DJ,MAApE;MACA,MAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYN,KAAZ,CAAxB;;MACA,IAAII,eAAe,CAACG,MAAhB,KAA2B,CAA/B,EAAkC;QAC9B,OAAO,IAAP;MACH;;MAED,MAAMC,OAAkD,GAAG,EAA3D;;MAEA,KAAK,MAAMC,cAAX,IAA6BL,eAA7B,EAA8C;QAC1C,MAAMM,WAAW,GAAG,IAAAC,yBAAA,EAAmBF,cAAnB,CAApB;;QACA,IAAI,CAACC,WAAL,EAAkB;UACd;QACH;;QACD,MAAM;UAAEE,OAAO,EAAEC,UAAX;UAAuBC,SAAS,EAAEC,iBAAlC;UAAqDC;QAArD,IAAgEN,WAAtE;QAEA,MAAMO,oBAAoB,GAAGf,qBAAqB,CAACC,KAAK,CAACe,IAAP,CAAlD;;QAEA,MAAMC,sBAAsB,GAAInB,KAAD,IAAgB;UAC3C,IAAI,CAACiB,oBAAL,EAA2B;YACvB,OAAOjB,KAAP;UACH;;UACD,OAAOiB,oBAAoB,CAACG,SAArB,CAA+B;YAClCjB,KADkC;YAElCH;UAFkC,CAA/B,CAAP;QAIH,CARD;;QAUA,MAAMqB,YAAY,GAAGpB,kBAAkB,CAACc,iBAAD,CAAvC;;QACA,IAAI,CAACM,YAAL,EAAmB;UACf,MAAM,IAAIC,cAAJ,CACD,iCAAgCP,iBAAkB,IADjD,EAEF,0BAFE,CAAN;QAIH;;QAED,MAAMQ,KAAK,GAAG,CACVpB,KAAK,CAACqB,UAAN,CAAiB;UACbrB;QADa,CAAjB,CADU,EAIVU,UAJU,CAAd;QAOAL,OAAO,CAACiB,IAAR,CAAa;UACTtB,KADS;UAETuB,IAAI,EAAEH,KAAK,CAACI,IAAN,CAAW,GAAX,CAFG;UAGTC,WAAW,EAAE,CAAC,GAAGzB,KAAK,CAAC0B,OAAN,CAAcC,GAAd,CAAkBC,CAAC,IAAIA,CAAC,CAACnB,OAAzB,CAAJ,EAAuCT,KAAK,CAACS,OAA7C,EAAsDe,IAAtD,CAA2D,GAA3D,CAHJ;UAITK,MAAM,EAAEX,YAJC;UAKTL,MALS;UAMTiB,YAAY,EAAE,IAAAC,yBAAA,EAAe;YACzBlC,KAAK,EAAEA,KAAK,CAACS,cAAD,CADa;YAEzBW,SAAS,EAAED;UAFc,CAAf,CANL;UAUTe,cAAc,EAAEf;QAVP,CAAb;MAYH;;MAED,OAAOX,OAAP;IACH;EA5DgC,CAA9B,CAAP;AA8DH,CA/DM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Field } from "./types";
|
|
3
|
+
interface Params {
|
|
4
|
+
items: CmsEntry[];
|
|
5
|
+
sort?: string[];
|
|
6
|
+
fields: Record<string, Field>;
|
|
7
|
+
}
|
|
8
|
+
export declare const sort: (params: Params) => CmsEntry[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.sort = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
13
|
+
|
|
14
|
+
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
15
|
+
|
|
16
|
+
var _extractSort = require("./extractSort");
|
|
17
|
+
|
|
18
|
+
const sort = params => {
|
|
19
|
+
const {
|
|
20
|
+
items,
|
|
21
|
+
sort = [],
|
|
22
|
+
fields
|
|
23
|
+
} = params;
|
|
24
|
+
|
|
25
|
+
if (items.length <= 1) {
|
|
26
|
+
return items;
|
|
27
|
+
} else if (sort.length === 0) {
|
|
28
|
+
sort.push("savedOn_DESC");
|
|
29
|
+
} else if (sort.length > 1) {
|
|
30
|
+
throw new _error.default("Sorting is limited to a single field.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
31
|
+
sort: sort
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const [firstSort] = sort;
|
|
36
|
+
|
|
37
|
+
if (!firstSort) {
|
|
38
|
+
throw new _error.default("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
39
|
+
sort
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
fieldId,
|
|
45
|
+
field,
|
|
46
|
+
valuePath,
|
|
47
|
+
reverse
|
|
48
|
+
} = (0, _extractSort.extractSort)({
|
|
49
|
+
sortBy: firstSort,
|
|
50
|
+
fields
|
|
51
|
+
});
|
|
52
|
+
const itemsToSort = items.map(item => {
|
|
53
|
+
return {
|
|
54
|
+
id: item.id,
|
|
55
|
+
value: field.transform(_dotProp.default.get(item, valuePath))
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
const sortedItems = (0, _sortBy.default)(itemsToSort, "value");
|
|
59
|
+
const newItems = sortedItems.map(s => {
|
|
60
|
+
const item = items.find(i => i.id === s.id);
|
|
61
|
+
|
|
62
|
+
if (item) {
|
|
63
|
+
return item;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw new _error.default("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
67
|
+
id: s.id,
|
|
68
|
+
sortingBy: fieldId,
|
|
69
|
+
reverse
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!reverse) {
|
|
74
|
+
return newItems;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return newItems.reverse();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.sort = sort;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["sort","params","items","fields","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 } 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\";\n\ninterface Params {\n items: CmsEntry[];\n sort?: string[];\n fields: Record<string, Field>;\n}\n\ninterface SortedItem {\n id: string;\n value: any;\n}\n\nexport const sort = (params: Params): CmsEntry[] => {\n const { items, sort = [], fields } = 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 sortBy: firstSort,\n fields\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;;AAcO,MAAMA,IAAI,GAAIC,MAAD,IAAgC;EAChD,MAAM;IAAEC,KAAF;IAASF,IAAI,GAAG,EAAhB;IAAoBG;EAApB,IAA+BF,MAArC;;EACA,IAAIC,KAAK,CAACE,MAAN,IAAgB,CAApB,EAAuB;IACnB,OAAOF,KAAP;EACH,CAFD,MAEO,IAAIF,IAAI,CAACI,MAAL,KAAgB,CAApB,EAAuB;IAC1BJ,IAAI,CAACK,IAAL,CAAU,cAAV;EACH,CAFM,MAEA,IAAIL,IAAI,CAACI,MAAL,GAAc,CAAlB,EAAqB;IACxB,MAAM,IAAIE,cAAJ,CACF,uCADE,EAEF,4BAFE,EAGF;MACIN,IAAI,EAAEA;IADV,CAHE,CAAN;EAOH;;EACD,MAAM,CAACO,SAAD,IAAcP,IAApB;;EACA,IAAI,CAACO,SAAL,EAAgB;IACZ,MAAM,IAAID,cAAJ,CAAgB,wBAAhB,EAA0C,kBAA1C,EAA8D;MAChEN;IADgE,CAA9D,CAAN;EAGH;;EAED,MAAM;IAAEQ,OAAF;IAAWC,KAAX;IAAkBC,SAAlB;IAA6BC;EAA7B,IAAyC,IAAAC,wBAAA,EAAY;IACvDC,MAAM,EAAEN,SAD+C;IAEvDJ;EAFuD,CAAZ,CAA/C;EAKA,MAAMW,WAAW,GAAGZ,KAAK,CAACa,GAAN,CAAUC,IAAI,IAAI;IAClC,OAAO;MACHC,EAAE,EAAED,IAAI,CAACC,EADN;MAEHC,KAAK,EAAET,KAAK,CAACU,SAAN,CAAgBC,gBAAA,CAAQC,GAAR,CAAYL,IAAZ,EAAkBN,SAAlB,CAAhB;IAFJ,CAAP;EAIH,CALmB,CAApB;EAMA,MAAMY,WAAyB,GAAG,IAAAC,eAAA,EAAaT,WAAb,EAA0B,OAA1B,CAAlC;EACA,MAAMU,QAAQ,GAAGF,WAAW,CAACP,GAAZ,CAAgBU,CAAC,IAAI;IAClC,MAAMT,IAAI,GAAGd,KAAK,CAACwB,IAAN,CAAWC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASQ,CAAC,CAACR,EAA3B,CAAb;;IACA,IAAID,IAAJ,EAAU;MACN,OAAOA,IAAP;IACH;;IACD,MAAM,IAAIV,cAAJ,CACF,oDADE,EAEF,qBAFE,EAGF;MACIW,EAAE,EAAEQ,CAAC,CAACR,EADV;MAEIW,SAAS,EAAEpB,OAFf;MAGIG;IAHJ,CAHE,CAAN;EASH,CAdgB,CAAjB;;EAeA,IAAI,CAACA,OAAL,EAAc;IACV,OAAOa,QAAP;EACH;;EACD,OAAOA,QAAQ,CAACb,OAAT,EAAP;AACH,CArDM"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSystemFields = void 0;
|
|
7
|
+
|
|
8
|
+
const createSystemFields = () => {
|
|
9
|
+
return [{
|
|
10
|
+
id: "id",
|
|
11
|
+
type: "text",
|
|
12
|
+
storageId: "id",
|
|
13
|
+
fieldId: "id",
|
|
14
|
+
label: "ID"
|
|
15
|
+
}, {
|
|
16
|
+
id: "entryId",
|
|
17
|
+
type: "text",
|
|
18
|
+
storageId: "entryId",
|
|
19
|
+
fieldId: "entryId",
|
|
20
|
+
label: "Entry ID"
|
|
21
|
+
}, {
|
|
22
|
+
id: "createdOn",
|
|
23
|
+
type: "datetime",
|
|
24
|
+
storageId: "createdOn",
|
|
25
|
+
fieldId: "createdOn",
|
|
26
|
+
label: "Created On"
|
|
27
|
+
}, {
|
|
28
|
+
id: "savedOn",
|
|
29
|
+
type: "datetime",
|
|
30
|
+
storageId: "savedOn",
|
|
31
|
+
fieldId: "savedOn",
|
|
32
|
+
label: "Saved On"
|
|
33
|
+
}, {
|
|
34
|
+
id: "createdBy",
|
|
35
|
+
type: "plainObject",
|
|
36
|
+
storageId: "createdBy",
|
|
37
|
+
fieldId: "createdBy",
|
|
38
|
+
label: "Created By",
|
|
39
|
+
settings: {
|
|
40
|
+
path: "createdBy.id"
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
id: "meta",
|
|
44
|
+
type: "plainObject",
|
|
45
|
+
storageId: "meta",
|
|
46
|
+
fieldId: "meta",
|
|
47
|
+
label: "Meta"
|
|
48
|
+
}, {
|
|
49
|
+
id: "ownedBy",
|
|
50
|
+
type: "plainObject",
|
|
51
|
+
storageId: "ownedBy",
|
|
52
|
+
fieldId: "ownedBy",
|
|
53
|
+
label: "Owned By",
|
|
54
|
+
settings: {
|
|
55
|
+
path: "ownedBy.id"
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
id: "version",
|
|
59
|
+
type: "number",
|
|
60
|
+
storageId: "version",
|
|
61
|
+
fieldId: "version",
|
|
62
|
+
label: "Version"
|
|
63
|
+
}, {
|
|
64
|
+
id: "status",
|
|
65
|
+
type: "text",
|
|
66
|
+
storageId: "status",
|
|
67
|
+
fieldId: "status",
|
|
68
|
+
label: "Status"
|
|
69
|
+
}];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
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,IADR;IAEIC,IAAI,EAAE,MAFV;IAGIC,SAAS,EAAE,IAHf;IAIIC,OAAO,EAAE,IAJb;IAKIC,KAAK,EAAE;EALX,CADG,EAQH;IACIJ,EAAE,EAAE,SADR;IAEIC,IAAI,EAAE,MAFV;IAGIC,SAAS,EAAE,SAHf;IAIIC,OAAO,EAAE,SAJb;IAKIC,KAAK,EAAE;EALX,CARG,EAeH;IACIJ,EAAE,EAAE,WADR;IAEIC,IAAI,EAAE,UAFV;IAGIC,SAAS,EAAE,WAHf;IAIIC,OAAO,EAAE,WAJb;IAKIC,KAAK,EAAE;EALX,CAfG,EAsBH;IACIJ,EAAE,EAAE,SADR;IAEIC,IAAI,EAAE,UAFV;IAGIC,SAAS,EAAE,SAHf;IAIIC,OAAO,EAAE,SAJb;IAKIC,KAAK,EAAE;EALX,CAtBG,EA6BH;IACIJ,EAAE,EAAE,WADR;IAEIC,IAAI,EAAE,aAFV;IAGIC,SAAS,EAAE,WAHf;IAIIC,OAAO,EAAE,WAJb;IAKIC,KAAK,EAAE,YALX;IAMIC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EANd,CA7BG,EAuCH;IACIN,EAAE,EAAE,MADR;IAEIC,IAAI,EAAE,aAFV;IAGIC,SAAS,EAAE,MAHf;IAIIC,OAAO,EAAE,MAJb;IAKIC,KAAK,EAAE;EALX,CAvCG,EA8CH;IACIJ,EAAE,EAAE,SADR;IAEIC,IAAI,EAAE,aAFV;IAGIC,SAAS,EAAE,SAHf;IAIIC,OAAO,EAAE,SAJb;IAKIC,KAAK,EAAE,UALX;IAMIC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA;EANd,CA9CG,EAwDH;IACIN,EAAE,EAAE,SADR;IAEIC,IAAI,EAAE,QAFV;IAGIC,SAAS,EAAE,SAHf;IAIIC,OAAO,EAAE,SAJb;IAKIC,KAAK,EAAE;EALX,CAxDG,EA+DH;IACIJ,EAAE,EAAE,QADR;IAEIC,IAAI,EAAE,MAFV;IAGIC,SAAS,EAAE,QAHf;IAIIC,OAAO,EAAE,QAJb;IAKIC,KAAK,EAAE;EALX,CA/DG,CAAP;AAuEH,CAxEM"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformValue = void 0;
|
|
7
|
+
|
|
8
|
+
const transformValue = ({
|
|
9
|
+
value,
|
|
10
|
+
transform
|
|
11
|
+
}) => {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return value.map(v => transform(v));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return transform(value);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
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,KAAF;EAASC;AAAT,CAAD,KAAuC;EACjE,IAAIC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,EAA0B;IACtB,OAAOA,KAAK,CAACI,GAAN,CAAUC,CAAC,IAAIJ,SAAS,CAACI,CAAD,CAAxB,CAAP;EACH;;EACD,OAAOJ,SAAS,CAACD,KAAD,CAAhB;AACH,CALM"}
|
|
@@ -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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getWhereValues = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const getWhereValues = (value, condition) => {
|
|
13
|
+
const values = value;
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(values)) {
|
|
16
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
17
|
+
value
|
|
18
|
+
});
|
|
19
|
+
} else if (values.length === 0) {
|
|
20
|
+
throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
21
|
+
value
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return values;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
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,KAAD,EAAiBC,SAAjB,KAA6C;EACvE,MAAMC,MAAM,GAAGF,KAAf;;EACA,IAAI,CAACG,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAL,EAA4B;IACxB,MAAM,IAAIG,cAAJ,CACD,iCAAgCJ,SAAU,wCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH,CARD,MAQO,IAAIE,MAAM,CAACI,MAAP,KAAkB,CAAtB,EAAyB;IAC5B,MAAM,IAAID,cAAJ,CACD,iCAAgCJ,SAAU,uCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH;;EACD,OAAOE,MAAP;AACH,CApBM"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extractWhereParams = void 0;
|
|
7
|
+
|
|
8
|
+
const extractWhereParams = key => {
|
|
9
|
+
const result = key.split("_");
|
|
10
|
+
const fieldId = result.shift();
|
|
11
|
+
|
|
12
|
+
if (!fieldId) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
17
|
+
/**
|
|
18
|
+
* When rawOp is not, it means it is equal negated so just return that.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
if (rawOp === "not") {
|
|
22
|
+
return {
|
|
23
|
+
fieldId,
|
|
24
|
+
operation: "eq",
|
|
25
|
+
negate: true
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const negate = rawOp.match("not_") !== null;
|
|
30
|
+
const operation = rawOp.replace("not_", "");
|
|
31
|
+
return {
|
|
32
|
+
fieldId,
|
|
33
|
+
operation,
|
|
34
|
+
negate
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
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,GAAD,IAAiB;EAC/C,MAAMC,MAAM,GAAGD,GAAG,CAACE,KAAJ,CAAU,GAAV,CAAf;EACA,MAAMC,OAAO,GAAGF,MAAM,CAACG,KAAP,EAAhB;;EACA,IAAI,CAACD,OAAL,EAAc;IACV,OAAO,IAAP;EACH;;EACD,MAAME,KAAK,GAAGJ,MAAM,CAACK,MAAP,KAAkB,CAAlB,GAAsB,IAAtB,GAA6BL,MAAM,CAACM,IAAP,CAAY,GAAZ,CAA3C;EACA;AACJ;AACA;;EACI,IAAIF,KAAK,KAAK,KAAd,EAAqB;IACjB,OAAO;MACHF,OADG;MAEHK,SAAS,EAAE,IAFR;MAGHC,MAAM,EAAE;IAHL,CAAP;EAKH;;EACD,MAAMA,MAAM,GAAGJ,KAAK,CAACK,KAAN,CAAY,MAAZ,MAAwB,IAAvC;EACA,MAAMF,SAAS,GAAGH,KAAK,CAACM,OAAN,CAAc,MAAd,EAAsB,EAAtB,CAAlB;EACA,OAAO;IACHR,OADG;IAEHK,SAFG;IAGHC;EAHG,CAAP;AAKH,CAxBM"}
|