@webiny/api-headless-cms-ddb 6.3.0 → 6.4.0-beta.1
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 +7 -9
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +7 -9
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +7 -9
- package/definitions/model.js.map +1 -1
- package/definitions/table.js +6 -7
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +1 -0
- package/definitions/types.js +0 -3
- package/dynamoDb/index.js +6 -1
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.js +16 -29
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.js +11 -21
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +21 -32
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +67 -77
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +2 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +33 -47
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +8 -9
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.js +0 -3
- package/operations/entry/dataLoaders.js +81 -99
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.js +109 -157
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.js +83 -96
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.js +50 -74
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.js +72 -140
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.js +21 -38
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +31 -53
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/mapPlugins.js +15 -22
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.js +7 -3
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -56
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.js +34 -60
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +144 -126
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +4 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.js +0 -3
- package/operations/entry/filtering/values.js +11 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +17 -23
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.js +894 -1148
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +54 -77
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.js +113 -134
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +100 -121
- package/operations/model/index.js.map +1 -1
- package/package.json +16 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.js +0 -2
- package/types.js +6 -5
- package/types.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/filtering/index.js.map +0 -1
- package/operations/entry/filtering/types.js.map +0 -1
- package/plugins/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/plugins/objectFilterCreate.js","sources":["../../../../../src/operations/entry/filtering/plugins/objectFilterCreate.ts"],"sourcesContent":["import { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { transformValue } from \"~/operations/entry/filtering/transform.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const objectFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: \"object\",\n create: params => {\n const {\n value: objectValue,\n valueFilterRegistry,\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 fieldType = getBaseFieldType(field);\n\n const filterCreatePlugin = getFilterCreatePlugin(fieldType);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\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 valueFilterRegistry,\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 plugin.name = `headless-cms.ddb.filter.object`;\n\n return plugin;\n};\n"],"names":["objectFilterCreate","plugin","CmsEntryFieldFilterPlugin","params","objectValue","valueFilterRegistry","transformValuePlugins","getFilterCreatePlugin","parentField","fields","filters","key","value","undefined","whereParams","extractWhereParams","negate","fieldId","operation","fieldPath","p","field","WebinyError","fieldType","getBaseFieldType","filterCreatePlugin","transformValuePlugin","transformValueCallable","result","transformValue","Array"],"mappings":";;;;;AAOO,MAAMA,qBAAqB;IAC9B,MAAMC,SAAS,IAAIC,0BAA0B;QACzC,WAAW;QACX,QAAQC,CAAAA;YACJ,MAAM,EACF,OAAOC,WAAW,EAClBC,mBAAmB,EACnBC,qBAAqB,EACrBC,qBAAqB,EACrB,OAAOC,WAAW,EAClBC,MAAM,EACT,GAAGN;YAEJ,MAAMO,UAAU,EAAE;YAElB,IAAK,MAAMC,OAAOP,YAAa;gBAC3B,MAAMQ,QAAQR,WAAW,CAACO,IAAI;gBAC9B,IAAIC,AAAUC,WAAVD,OACA;gBAEJ,MAAME,cAAcC,mBAAmBJ;gBACvC,IAAI,CAACG,aACD;gBAEJ,MAAM,EAAEE,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGJ;gBAEvC,MAAMK,YAAYX,YAAY,OAAO,CAChC,GAAG,CAACY,CAAAA,IAAKA,EAAE,OAAO,EAClB,MAAM,CAAC;oBAACZ,YAAY,OAAO;oBAAES;iBAAQ,EACrC,IAAI,CAAC;gBAEV,MAAMI,QAAQZ,MAAM,CAACU,UAAU;gBAC/B,IAAI,CAACE,OACD,MAAM,IAAIC,MACN,CAAC,uCAAuC,EAAEH,UAAU,EAAE,CAAC,EACvD,eACA;oBACIF;gBACJ;gBAIR,MAAMM,YAAYC,iBAAiBH;gBAEnC,MAAMI,qBAAqBlB,sBAAsBgB;gBAEjD,MAAMG,uBACFpB,qBAAqB,CAACiB,UAAU;gBAEpC,MAAMI,yBAAyB,CAACf;oBAC5B,IAAI,CAACc,sBACD,OAAOd;oBAEX,OAAOc,qBAAqB,SAAS,CAAC;wBAClCL;wBACAT;oBACJ;gBACJ;gBAEA,MAAMgB,SAASH,mBAAmB,MAAM,CAAC;oBACrCd;oBACAC;oBACAP;oBACAC;oBACAC;oBACAW;oBACAF;oBACAK;oBACAZ;oBACA,cAAcoB,eAAe;wBACzBjB;wBACA,WAAWe;oBACf;oBACA,gBAAgBA;gBACpB;gBACA,IAAKC;oBAGL,IAAIE,MAAM,OAAO,CAACF,SAAS;wBACvBlB,QAAQ,IAAI,IAAIkB;wBAChB;oBACJ;oBAEAlB,QAAQ,IAAI,CAACkB;;YACjB;YACA,OAAOlB;QACX;IACJ;IAEAT,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
|
@@ -1,74 +1,63 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
3
3
|
import { extractWhereParams } from "../where.js";
|
|
4
4
|
import { transformValue } from "../transform.js";
|
|
5
5
|
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
const createRefFilterCreate = ()=>{
|
|
7
|
+
const plugin = new CmsEntryFieldFilterPlugin({
|
|
8
|
+
fieldType: "ref",
|
|
9
|
+
create: (params)=>{
|
|
10
|
+
const { valueFilterRegistry, transformValuePlugins, field } = params;
|
|
11
|
+
let value = params.value;
|
|
12
|
+
if (!value) value = {
|
|
13
|
+
entryId: null
|
|
14
|
+
};
|
|
15
|
+
const propertyFilters = Object.keys(value);
|
|
16
|
+
if (0 === propertyFilters.length) return null;
|
|
17
|
+
const filters = [];
|
|
18
|
+
for (const propertyFilter of propertyFilters){
|
|
19
|
+
const whereParams = extractWhereParams(propertyFilter);
|
|
20
|
+
if (!whereParams) continue;
|
|
21
|
+
const { fieldId: propertyId, operation: propertyOperation, negate } = whereParams;
|
|
22
|
+
const fieldType = getBaseFieldType(field);
|
|
23
|
+
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
24
|
+
const transformValueCallable = (value)=>{
|
|
25
|
+
if (!transformValuePlugin) return value;
|
|
26
|
+
return transformValuePlugin.transform({
|
|
27
|
+
field,
|
|
28
|
+
value
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const filter = valueFilterRegistry.get(propertyOperation);
|
|
32
|
+
if (!filter) throw new error(`Missing operation filter for "${propertyOperation}".`, "MISSING_OPERATION_FILTER");
|
|
33
|
+
const paths = [
|
|
34
|
+
field.createPath({
|
|
35
|
+
field
|
|
36
|
+
}),
|
|
37
|
+
propertyId
|
|
38
|
+
];
|
|
39
|
+
filters.push({
|
|
40
|
+
field,
|
|
41
|
+
path: paths.join("."),
|
|
42
|
+
fieldPathId: [
|
|
43
|
+
...field.parents.map((f)=>f.fieldId),
|
|
44
|
+
field.fieldId
|
|
45
|
+
].join("."),
|
|
46
|
+
filter,
|
|
47
|
+
negate,
|
|
48
|
+
compareValue: transformValue({
|
|
49
|
+
value: value[propertyFilter],
|
|
50
|
+
transform: transformValueCallable
|
|
51
|
+
}),
|
|
52
|
+
transformValue: transformValueCallable
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return filters;
|
|
30
56
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
negate
|
|
35
|
-
} = whereParams;
|
|
36
|
-
const fieldType = getBaseFieldType(field);
|
|
37
|
-
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
38
|
-
const transformValueCallable = value => {
|
|
39
|
-
if (!transformValuePlugin) {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
return transformValuePlugin.transform({
|
|
43
|
-
field,
|
|
44
|
-
value
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
const filter = valueFilterRegistry.get(propertyOperation);
|
|
48
|
-
if (!filter) {
|
|
49
|
-
throw new WebinyError(`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
|
-
filter,
|
|
59
|
-
negate,
|
|
60
|
-
compareValue: transformValue({
|
|
61
|
-
value: value[propertyFilter],
|
|
62
|
-
transform: transformValueCallable
|
|
63
|
-
}),
|
|
64
|
-
transformValue: transformValueCallable
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return filters;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
plugin.name = `headless-cms.ddb.filter.ref`;
|
|
71
|
-
return plugin;
|
|
57
|
+
});
|
|
58
|
+
plugin.name = "headless-cms.ddb.filter.ref";
|
|
59
|
+
return plugin;
|
|
72
60
|
};
|
|
61
|
+
export { createRefFilterCreate };
|
|
73
62
|
|
|
74
63
|
//# sourceMappingURL=refFilterCreate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/plugins/refFilterCreate.js","sources":["../../../../../src/operations/entry/filtering/plugins/refFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryFieldFilterPluginCreateResponse } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where.js\";\nimport { transformValue } from \"~/operations/entry/filtering/transform.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const createRefFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin<GenericRecord | null | undefined>({\n fieldType: \"ref\",\n create: params => {\n const { valueFilterRegistry, transformValuePlugins, field } = params;\n let value = params.value;\n if (!value) {\n value = {\n entryId: null\n };\n }\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n return null;\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 fieldType = getBaseFieldType(field);\n\n const transformValuePlugin = transformValuePlugins[fieldType];\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 filter = valueFilterRegistry.get(propertyOperation);\n if (!filter) {\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 filter,\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 plugin.name = `headless-cms.ddb.filter.ref`;\n\n return plugin;\n};\n"],"names":["createRefFilterCreate","plugin","CmsEntryFieldFilterPlugin","params","valueFilterRegistry","transformValuePlugins","field","value","propertyFilters","Object","filters","propertyFilter","whereParams","extractWhereParams","propertyId","propertyOperation","negate","fieldType","getBaseFieldType","transformValuePlugin","transformValueCallable","filter","WebinyError","paths","f","transformValue"],"mappings":";;;;;AAQO,MAAMA,wBAAwB;IACjC,MAAMC,SAAS,IAAIC,0BAA4D;QAC3E,WAAW;QACX,QAAQC,CAAAA;YACJ,MAAM,EAAEC,mBAAmB,EAAEC,qBAAqB,EAAEC,KAAK,EAAE,GAAGH;YAC9D,IAAII,QAAQJ,OAAO,KAAK;YACxB,IAAI,CAACI,OACDA,QAAQ;gBACJ,SAAS;YACb;YAEJ,MAAMC,kBAAkBC,OAAO,IAAI,CAACF;YACpC,IAAIC,AAA2B,MAA3BA,gBAAgB,MAAM,EACtB,OAAO;YAEX,MAAME,UAAqD,EAAE;YAE7D,KAAK,MAAMC,kBAAkBH,gBAAiB;gBAC1C,MAAMI,cAAcC,mBAAmBF;gBACvC,IAAI,CAACC,aACD;gBAEJ,MAAM,EAAE,SAASE,UAAU,EAAE,WAAWC,iBAAiB,EAAEC,MAAM,EAAE,GAAGJ;gBAEtE,MAAMK,YAAYC,iBAAiBZ;gBAEnC,MAAMa,uBAAuBd,qBAAqB,CAACY,UAAU;gBAE7D,MAAMG,yBAAyB,CAACb;oBAC5B,IAAI,CAACY,sBACD,OAAOZ;oBAEX,OAAOY,qBAAqB,SAAS,CAAC;wBAClCb;wBACAC;oBACJ;gBACJ;gBAEA,MAAMc,SAASjB,oBAAoB,GAAG,CAACW;gBACvC,IAAI,CAACM,QACD,MAAM,IAAIC,MACN,CAAC,8BAA8B,EAAEP,kBAAkB,EAAE,CAAC,EACtD;gBAIR,MAAMQ,QAAQ;oBACVjB,MAAM,UAAU,CAAC;wBACbA;oBACJ;oBACAQ;iBACH;gBAEDJ,QAAQ,IAAI,CAAC;oBACTJ;oBACA,MAAMiB,MAAM,IAAI,CAAC;oBACjB,aAAa;2BAAIjB,MAAM,OAAO,CAAC,GAAG,CAACkB,CAAAA,IAAKA,EAAE,OAAO;wBAAGlB,MAAM,OAAO;qBAAC,CAAC,IAAI,CAAC;oBACxEe;oBACAL;oBACA,cAAcS,eAAe;wBACzB,OAAOlB,KAAK,CAACI,eAAe;wBAC5B,WAAWS;oBACf;oBACA,gBAAgBA;gBACpB;YACJ;YAEA,OAAOV;QACX;IACJ;IAEAT,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
|
@@ -1,62 +1,49 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dot_object from "dot-object";
|
|
2
2
|
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
3
3
|
import { extractWhereParams } from "../where.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
const searchableJsonFilterCreate = ()=>{
|
|
5
|
+
const plugin = new CmsEntryFieldFilterPlugin({
|
|
6
|
+
fieldType: "searchable-json",
|
|
7
|
+
create: (params)=>{
|
|
8
|
+
const { value: objectValue, valueFilterRegistry, field: parentField } = params;
|
|
9
|
+
const filters = [];
|
|
10
|
+
const accessPatterns = dot_object.dot(objectValue);
|
|
11
|
+
for(const key in accessPatterns){
|
|
12
|
+
const value = accessPatterns[key];
|
|
13
|
+
if (void 0 === value) continue;
|
|
14
|
+
const whereParams = extractWhereParams(key);
|
|
15
|
+
if (!whereParams) continue;
|
|
16
|
+
const { negate, operation } = whereParams;
|
|
17
|
+
const transformValueCallable = (value)=>value;
|
|
18
|
+
const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;
|
|
19
|
+
const filter = valueFilterRegistry.get(operation);
|
|
20
|
+
if (!filter) {
|
|
21
|
+
console.error(`Missing operation filter for "${operation}".`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const result = {
|
|
25
|
+
field: parentField,
|
|
26
|
+
path: `values.${fieldId}`,
|
|
27
|
+
fieldPathId: `values.${fieldId}`,
|
|
28
|
+
negate,
|
|
29
|
+
filter,
|
|
30
|
+
compareValue: value,
|
|
31
|
+
transformValue: transformValueCallable
|
|
32
|
+
};
|
|
33
|
+
if (result) {
|
|
34
|
+
if (Array.isArray(result)) {
|
|
35
|
+
filters.push(...result);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
filters.push(result);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return filters;
|
|
19
42
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
negate,
|
|
26
|
-
operation
|
|
27
|
-
} = whereParams;
|
|
28
|
-
const transformValueCallable = value => {
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
|
-
const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;
|
|
32
|
-
const filter = valueFilterRegistry.get(operation);
|
|
33
|
-
if (!filter) {
|
|
34
|
-
console.error(`Missing operation filter for "${operation}".`);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const result = {
|
|
38
|
-
field: parentField,
|
|
39
|
-
path: `values.${fieldId}`,
|
|
40
|
-
fieldPathId: `values.${fieldId}`,
|
|
41
|
-
negate,
|
|
42
|
-
filter,
|
|
43
|
-
compareValue: value,
|
|
44
|
-
transformValue: transformValueCallable
|
|
45
|
-
};
|
|
46
|
-
if (!result) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(result)) {
|
|
50
|
-
filters.push(...result);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
filters.push(result);
|
|
54
|
-
}
|
|
55
|
-
return filters;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
plugin.name = `headless-cms.ddb.filter.searchable-json`;
|
|
59
|
-
return plugin;
|
|
43
|
+
});
|
|
44
|
+
plugin.name = "headless-cms.ddb.filter.searchable-json";
|
|
45
|
+
return plugin;
|
|
60
46
|
};
|
|
47
|
+
export { searchableJsonFilterCreate };
|
|
61
48
|
|
|
62
49
|
//# sourceMappingURL=searchableJsonFilterCreate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/plugins/searchableJsonFilterCreate.js","sources":["../../../../../src/operations/entry/filtering/plugins/searchableJsonFilterCreate.ts"],"sourcesContent":["import dot from \"dot-object\";\nimport type { CmsEntryFieldFilterPluginCreateResponse } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where.js\";\n\nexport const searchableJsonFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: \"searchable-json\",\n create: params => {\n const { value: objectValue, valueFilterRegistry, field: parentField } = params;\n\n const filters = [];\n\n const accessPatterns = dot.dot(objectValue);\n\n for (const key in accessPatterns) {\n const value = accessPatterns[key];\n if (value === undefined) {\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n const { negate, operation } = whereParams;\n\n const transformValueCallable = (value: any) => {\n return value;\n };\n\n const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;\n\n const filter = valueFilterRegistry.get(operation);\n if (!filter) {\n console.error(`Missing operation filter for \"${operation}\".`);\n continue;\n }\n\n const result: CmsEntryFieldFilterPluginCreateResponse = {\n field: parentField,\n path: `values.${fieldId}`,\n fieldPathId: `values.${fieldId}`,\n negate,\n filter,\n compareValue: value,\n transformValue: transformValueCallable\n };\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 plugin.name = `headless-cms.ddb.filter.searchable-json`;\n\n return plugin;\n};\n"],"names":["searchableJsonFilterCreate","plugin","CmsEntryFieldFilterPlugin","params","objectValue","valueFilterRegistry","parentField","filters","accessPatterns","dot","key","value","undefined","whereParams","extractWhereParams","negate","operation","transformValueCallable","fieldId","filter","console","result","Array"],"mappings":";;;AAKO,MAAMA,6BAA6B;IACtC,MAAMC,SAAS,IAAIC,0BAA0B;QACzC,WAAW;QACX,QAAQC,CAAAA;YACJ,MAAM,EAAE,OAAOC,WAAW,EAAEC,mBAAmB,EAAE,OAAOC,WAAW,EAAE,GAAGH;YAExE,MAAMI,UAAU,EAAE;YAElB,MAAMC,iBAAiBC,WAAAA,GAAO,CAACL;YAE/B,IAAK,MAAMM,OAAOF,eAAgB;gBAC9B,MAAMG,QAAQH,cAAc,CAACE,IAAI;gBACjC,IAAIC,AAAUC,WAAVD,OACA;gBAGJ,MAAME,cAAcC,mBAAmBJ;gBACvC,IAAI,CAACG,aACD;gBAEJ,MAAM,EAAEE,MAAM,EAAEC,SAAS,EAAE,GAAGH;gBAE9B,MAAMI,yBAAyB,CAACN,QACrBA;gBAGX,MAAMO,UAAU,GAAGZ,YAAY,OAAO,CAAC,CAAC,EAAEO,YAAY,OAAO,IAAIH,KAAK;gBAEtE,MAAMS,SAASd,oBAAoB,GAAG,CAACW;gBACvC,IAAI,CAACG,QAAQ;oBACTC,QAAQ,KAAK,CAAC,CAAC,8BAA8B,EAAEJ,UAAU,EAAE,CAAC;oBAC5D;gBACJ;gBAEA,MAAMK,SAAkD;oBACpD,OAAOf;oBACP,MAAM,CAAC,OAAO,EAAEY,SAAS;oBACzB,aAAa,CAAC,OAAO,EAAEA,SAAS;oBAChCH;oBACAI;oBACA,cAAcR;oBACd,gBAAgBM;gBACpB;gBAEA,IAAKI;oBAGL,IAAIC,MAAM,OAAO,CAACD,SAAS;wBACvBd,QAAQ,IAAI,IAAIc;wBAChB;oBACJ;oBAEAd,QAAQ,IAAI,CAACc;;YACjB;YACA,OAAOd;QACX;IACJ;IAEAN,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
|
@@ -1,67 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import lodashSortBy from "lodash/sortBy.js";
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import sortBy from "lodash/sortBy.js";
|
|
4
3
|
import { extractSort } from "./extractSort.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
model,
|
|
8
|
-
items
|
|
9
|
-
sort
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = params;
|
|
13
|
-
if (items.length <= 1) {
|
|
14
|
-
return items;
|
|
15
|
-
} else if (sort.length === 0) {
|
|
16
|
-
sort.push("savedOn_DESC");
|
|
17
|
-
} else if (sort.length > 1) {
|
|
18
|
-
throw new WebinyError("Sorting is limited to a single field on DynamoDB only system.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
19
|
-
sort
|
|
4
|
+
import * as __rspack_external_dot_prop_de53db47 from "dot-prop";
|
|
5
|
+
const sort_sort = (params)=>{
|
|
6
|
+
const { model, items, sort = [], fields, plugins } = params;
|
|
7
|
+
if (items.length <= 1) return items;
|
|
8
|
+
if (0 === sort.length) sort.push("savedOn_DESC");
|
|
9
|
+
else if (sort.length > 1) throw new error("Sorting is limited to a single field on DynamoDB only system.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
10
|
+
sort
|
|
20
11
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new WebinyError("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
25
|
-
sort
|
|
12
|
+
const [firstSort] = sort;
|
|
13
|
+
if (!firstSort) throw new error("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
14
|
+
sort
|
|
26
15
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
reverse
|
|
33
|
-
} = extractSort({
|
|
34
|
-
model,
|
|
35
|
-
sortBy: firstSort,
|
|
36
|
-
fields,
|
|
37
|
-
plugins
|
|
38
|
-
});
|
|
39
|
-
const itemsToSort = items.map(item => {
|
|
40
|
-
return {
|
|
41
|
-
id: item.id,
|
|
42
|
-
value: field.transform(dotProp.getProperty(item, valuePath))
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
const sortedItems = lodashSortBy(itemsToSort, "value");
|
|
46
|
-
const newItems = sortedItems.map(s => {
|
|
47
|
-
const item = items.find(i => i.id === s.id);
|
|
48
|
-
if (item) {
|
|
49
|
-
return item;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* This is impossible to happen because sorting items does not remove the items.
|
|
53
|
-
* BUT, we need to have this check just in case for development purposes.
|
|
54
|
-
*/
|
|
55
|
-
throw new WebinyError("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
56
|
-
id: s.id,
|
|
57
|
-
sortingBy: fieldId,
|
|
58
|
-
reverse
|
|
16
|
+
const { fieldId, field, valuePath, reverse } = extractSort({
|
|
17
|
+
model,
|
|
18
|
+
sortBy: firstSort,
|
|
19
|
+
fields,
|
|
20
|
+
plugins
|
|
59
21
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
22
|
+
const itemsToSort = items.map((item)=>({
|
|
23
|
+
id: item.id,
|
|
24
|
+
value: field.transform(__rspack_external_dot_prop_de53db47.getProperty(item, valuePath))
|
|
25
|
+
}));
|
|
26
|
+
const sortedItems = sortBy(itemsToSort, "value");
|
|
27
|
+
const newItems = sortedItems.map((s)=>{
|
|
28
|
+
const item = items.find((i)=>i.id === s.id);
|
|
29
|
+
if (item) return item;
|
|
30
|
+
throw new error("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
31
|
+
id: s.id,
|
|
32
|
+
sortingBy: fieldId,
|
|
33
|
+
reverse
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
if (!reverse) return newItems;
|
|
37
|
+
return newItems.reverse();
|
|
65
38
|
};
|
|
39
|
+
export { sort_sort as sort };
|
|
66
40
|
|
|
67
41
|
//# sourceMappingURL=sort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/sort.js","sources":["../../../../src/operations/entry/filtering/sort.ts"],"sourcesContent":["import type { CmsEntry, CmsEntryValues, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport * as dotProp from \"dot-prop\";\nimport lodashSortBy from \"lodash/sortBy.js\";\nimport { extractSort } from \"./extractSort.js\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\ninterface Params<T extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n items: CmsEntry<T>[];\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 = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\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 on DynamoDB only system.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n 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.getProperty(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 /**\n * This is impossible to happen because sorting items does not remove the items.\n * BUT, we need to have this check just in case for development purposes.\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"],"names":["sort","params","model","items","fields","plugins","WebinyError","firstSort","fieldId","field","valuePath","reverse","extractSort","itemsToSort","item","dotProp","sortedItems","lodashSortBy","newItems","s","i"],"mappings":";;;;AAqBO,MAAMA,YAAO,CAChBC;IAEA,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEH,OAAO,EAAE,EAAEI,MAAM,EAAEC,OAAO,EAAE,GAAGJ;IACrD,IAAIE,MAAM,MAAM,IAAI,GAChB,OAAOA;IACJ,IAAIH,AAAgB,MAAhBA,KAAK,MAAM,EAClBA,KAAK,IAAI,CAAC;SACP,IAAIA,KAAK,MAAM,GAAG,GACrB,MAAM,IAAIM,MACN,iEACA,8BACA;QACIN;IACJ;IAGR,MAAM,CAACO,UAAU,GAAGP;IACpB,IAAI,CAACO,WACD,MAAM,IAAID,MAAY,0BAA0B,oBAAoB;QAChEN;IACJ;IAGJ,MAAM,EAAEQ,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE,GAAGC,YAAY;QACvDV;QACA,QAAQK;QACRH;QACAC;IACJ;IAEA,MAAMQ,cAAcV,MAAM,GAAG,CAACW,CAAAA,OACnB;YACH,IAAIA,KAAK,EAAE;YACX,OAAOL,MAAM,SAAS,CAACM,oCAAAA,WAAmB,CAACD,MAAMJ;QACrD;IAEJ,MAAMM,cAA4BC,OAAaJ,aAAa;IAC5D,MAAMK,WAAWF,YAAY,GAAG,CAACG,CAAAA;QAC7B,MAAML,OAAOX,MAAM,IAAI,CAACiB,CAAAA,IAAKA,EAAE,EAAE,KAAKD,EAAE,EAAE;QAC1C,IAAIL,MACA,OAAOA;QAMX,MAAM,IAAIR,MACN,sDACA,uBACA;YACI,IAAIa,EAAE,EAAE;YACR,WAAWX;YACXG;QACJ;IAER;IACA,IAAI,CAACA,SACD,OAAOO;IAEX,OAAOA,SAAS,OAAO;AAC3B"}
|