@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/filter.js","sources":["../../../../src/operations/entry/filtering/filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields,\n container\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n filter: fullTextSearchFilter\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"names":["executeFilter","params","value","filter","canUse","matched","executeExpressions","expressions","getCachedValue","filters","condition","result","expression","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","ValueFilterRegistry","keys","Object","createExpressions","fullTextSearchFilter","WebinyError","search","createFullTextSearch","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","exprResult"],"mappings":";;;;;;AAqBA,MAAMA,gBAAgB,CAACC;IACnB,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGF;IAM1B,MAAMG,SAASD,OAAO,MAAM,CAAC,MAAM,CAAC;QAChCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAI,CAACC,QACD,OAAO;IAGX,MAAMC,UAAUF,OAAO,MAAM,CAAC,OAAO,CAAC;QAClCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAIA,OAAO,MAAM,EACb,OAAOE,AAAY,UAAZA;IAEX,OAAOA;AACX;AASA,MAAMC,qBAAqB,CAACL;IACxB,MAAM,EAAEM,WAAW,EAAEC,cAAc,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGT;IAC5D,IAAIM,AAAuB,MAAvBA,YAAY,MAAM,IAAUE,AAAmB,MAAnBA,QAAQ,MAAM,EAC1C,OAAO;IAKX,KAAK,MAAMN,UAAUM,QAAS;QAC1B,MAAMP,QAAQM,eAAeL;QAE7B,MAAMQ,SAASX,cAAc;YACzBE;YACAC;QACJ;QAKA,IAAI,CAACQ,QACD,OAAO;IAEf;IAIA,KAAK,MAAMC,cAAcL,YAAa;QAClC,MAAMI,SAASL,mBAAmB;YAC9B,GAAGM,UAAU;YACbJ;QACJ;QACA,IAAIG,UAAUD,AAAc,SAAdA,WACV,OAAO;QACJ,IAAI,CAACC,UAAUD,AAAa,SAAbA,WAClB,OAAO;IAEf;IAMA,OAAOA,AAAc,SAAdA;AACX;AAcO,MAAMP,gBAAS,CAClBF;IAEA,MAAM,EAAE,OAAOY,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGjB;IAE9E,MAAMkB,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,OAAOC,OAAO,IAAI,CAACR;IACzB,IAAIO,AAAgB,MAAhBA,KAAK,MAAM,IAAU,CAACJ,gBACtB,OAAOJ;IAEX,MAAMD,aAAaW,kBAAkB;QACjCR;QACAD;QACAE;QACAE;IACJ;IAKA,IACIN,AAA8B,MAA9BA,WAAW,OAAO,CAAC,MAAM,IACzBA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,IAC7B,CAACK,gBAAgB,MAEjB,OAAOJ;IAKX,MAAMW,uBAAuBL,oBAAoB,GAAG,CAAC;IACrD,IAAI,CAACK,sBACD,MAAM,IAAIC,MACN,0DACA;IAIR,MAAMC,SAASC,qBAAqB;QAChC,MAAMV,gBAAgB;QACtB,cAAcA,gBAAgB;QAC9BD;QACA,QAAQQ;IACZ;IAEA,OAAOX,QAAQ,MAAM,CAACe,CAAAA;QAClB,MAAMC,eAAoC,CAAC;QAE3C,MAAMrB,iBAAiB,CAACL;YACpB,MAAM,EAAE2B,IAAI,EAAE,GAAG3B;YACjB,IAAI0B,AAAuBE,WAAvBF,YAAY,CAACC,KAAK,EAClB,OAAOD,YAAY,CAACC,KAAK;YAE7B,MAAME,aAAaC,SAASL,QAAQE;YAEpC,MAAMI,WAAWC,eAAe;gBAC5B,OAAOH;gBACP,WAAW7B,OAAO,cAAc;YACpC;YAEA0B,YAAY,CAACC,KAAK,GAAGI;YACrB,OAAOA;QACX;QAEA,MAAME,aAAa9B,mBAAmB;YAAE,GAAGM,UAAU;YAAEJ;QAAe;QAKtE,IAAI,CAAC4B,cAAc,CAACV,QAChB,OAAOU;QAGX,OAAOV,OAAOE;IAClB;AACJ"}
|
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { getValue } from "./getValue.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!field) {
|
|
23
|
-
throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
24
|
-
target
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const value = getValue(item, target);
|
|
28
|
-
if (!value) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (filter.matches({
|
|
32
|
-
value,
|
|
33
|
-
compareValue: term
|
|
34
|
-
}) === true) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
3
|
+
const createFullTextSearch = (params)=>{
|
|
4
|
+
const { term, targetFields, fields: fieldDefinitions, filter } = params;
|
|
5
|
+
if (!term || 0 === term.trim().length || !targetFields || 0 === targetFields.length) return null;
|
|
6
|
+
return (item)=>{
|
|
7
|
+
for (const target of targetFields){
|
|
8
|
+
const field = fieldDefinitions[target];
|
|
9
|
+
if (!field) throw new error(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
10
|
+
target
|
|
11
|
+
});
|
|
12
|
+
const value = getValue(item, target);
|
|
13
|
+
if (value) {
|
|
14
|
+
if (true === filter.matches({
|
|
15
|
+
value,
|
|
16
|
+
compareValue: term
|
|
17
|
+
})) return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
40
22
|
};
|
|
23
|
+
export { createFullTextSearch };
|
|
41
24
|
|
|
42
25
|
//# sourceMappingURL=fullTextSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/fullTextSearch.js","sources":["../../../../src/operations/entry/filtering/fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n filter: ValueFilter.Interface;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, filter } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item, target);\n if (!value) {\n continue;\n }\n if (filter.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"names":["createFullTextSearch","params","term","targetFields","fieldDefinitions","filter","item","target","field","WebinyError","value","getValue"],"mappings":";;AAgBO,MAAMA,uBAAuB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,QAAQC,gBAAgB,EAAEC,MAAM,EAAE,GAAGJ;IACjE,IAAI,CAACC,QAAQA,AAAuB,MAAvBA,KAAK,IAAI,GAAG,MAAM,IAAU,CAACC,gBAAgBA,AAAwB,MAAxBA,aAAa,MAAM,EACzE,OAAO;IAEX,OAAO,CAACG;QACJ,KAAK,MAAMC,UAAUJ,aAAc;YAI/B,MAAMK,QAAQJ,gBAAgB,CAACG,OAAO;YAEtC,IAAI,CAACC,OACD,MAAM,IAAIC,MAAY,CAAC,eAAe,EAAEF,OAAO,eAAe,CAAC,EAAE,iBAAiB;gBAC9EA;YACJ;YAEJ,MAAMG,QAAQC,SAASL,MAAMC;YAC7B,IAAKG,OAGL;gBAAA,IAAIL,AAAkD,SAAlDA,OAAO,OAAO,CAAC;oBAAEK;oBAAO,cAAcR;gBAAK,IAC3C,OAAO;YACX;QACJ;QACA,OAAO;IACX;AACJ"}
|
|
@@ -1,59 +1,37 @@
|
|
|
1
|
-
const addArrayResult = (target, result)
|
|
2
|
-
|
|
3
|
-
if (target.some(t => r === t)) {
|
|
4
|
-
continue;
|
|
5
|
-
}
|
|
6
|
-
target.push(r);
|
|
7
|
-
}
|
|
1
|
+
const addArrayResult = (target, result)=>{
|
|
2
|
+
for (const r of result)if (!target.some((t)=>r === t)) target.push(r);
|
|
8
3
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
const find = (target, input)=>{
|
|
5
|
+
const paths = [
|
|
6
|
+
...input
|
|
7
|
+
];
|
|
8
|
+
const path = paths.shift();
|
|
9
|
+
if (!path) return;
|
|
10
|
+
const value = target?.[path];
|
|
11
|
+
if (void 0 === value) return;
|
|
12
|
+
if (0 === paths.length) return value;
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
if (0 === value.length) return;
|
|
15
|
+
return value.reduce((collection, v)=>{
|
|
16
|
+
const result = find(v, paths);
|
|
17
|
+
if (void 0 === result) return collection;
|
|
18
|
+
if (Array.isArray(result)) {
|
|
19
|
+
addArrayResult(collection, result);
|
|
20
|
+
return collection;
|
|
21
|
+
}
|
|
22
|
+
collection.push(result);
|
|
23
|
+
return collection;
|
|
24
|
+
}, []);
|
|
28
25
|
}
|
|
29
|
-
return value
|
|
30
|
-
const result = find(v, paths);
|
|
31
|
-
if (result === undefined) {
|
|
32
|
-
return collection;
|
|
33
|
-
} else if (Array.isArray(result)) {
|
|
34
|
-
addArrayResult(collection, result);
|
|
35
|
-
return collection;
|
|
36
|
-
}
|
|
37
|
-
collection.push(result);
|
|
38
|
-
return collection;
|
|
39
|
-
}, []);
|
|
40
|
-
}
|
|
41
|
-
return find(value, paths);
|
|
26
|
+
return find(value, paths);
|
|
42
27
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (paths.length === 0) {
|
|
50
|
-
throw new Error(`Path is empty!`);
|
|
51
|
-
}
|
|
52
|
-
const filtered = paths.filter(Boolean);
|
|
53
|
-
if (paths.length !== filtered.length) {
|
|
54
|
-
throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
|
|
55
|
-
}
|
|
56
|
-
return find(target, paths);
|
|
28
|
+
const getValue = (target, input)=>{
|
|
29
|
+
const paths = Array.isArray(input) ? input : input.split(".");
|
|
30
|
+
if (0 === paths.length) throw new Error("Path is empty!");
|
|
31
|
+
const filtered = paths.filter(Boolean);
|
|
32
|
+
if (paths.length !== filtered.length) throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
|
|
33
|
+
return find(target, paths);
|
|
57
34
|
};
|
|
35
|
+
export { getValue };
|
|
58
36
|
|
|
59
37
|
//# sourceMappingURL=getValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/getValue.js","sources":["../../../../src/operations/entry/filtering/getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"names":["addArrayResult","target","result","r","t","find","input","paths","path","value","undefined","Array","collection","v","getValue","Error","filtered","Boolean"],"mappings":"AAAA,MAAMA,iBAAiB,CAACC,QAAeC;IACnC,KAAK,MAAMC,KAAKD,OACZ,KAAID,OAAO,IAAI,CAACG,CAAAA,IAAKD,MAAMC,IAG3BH,OAAO,IAAI,CAACE;AAEpB;AAKA,MAAME,OAAO,CAACJ,QAAyCK;IACnD,MAAMC,QAAQ;WAAID;KAAM;IACxB,MAAME,OAAOD,MAAM,KAAK;IAExB,IAAI,CAACC,MACD;IAGJ,MAAMC,QAAQR,QAAQ,CAACO,KAAK;IAC5B,IAAIC,AAAUC,WAAVD,OACA;IAEJ,IAAIF,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAOE;IACJ,IAAIE,MAAM,OAAO,CAACF,QAAQ;QAC7B,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZ;QAEJ,OAAOA,MAAM,MAAM,CAAQ,CAACG,YAAYC;YACpC,MAAMX,SAASG,KAAKQ,GAAGN;YACvB,IAAIL,AAAWQ,WAAXR,QACA,OAAOU;YACJ,IAAID,MAAM,OAAO,CAACT,SAAS;gBAC9BF,eAAeY,YAAYV;gBAC3B,OAAOU;YACX;YACAA,WAAW,IAAI,CAACV;YAChB,OAAOU;QACX,GAAG,EAAE;IACT;IACA,OAAOP,KAAKI,OAAOF;AACvB;AAKO,MAAMO,WAAW,CAACb,QAA6BK;IAClD,MAAMC,QAAQI,MAAM,OAAO,CAACL,SAASA,QAAQA,MAAM,KAAK,CAAC;IACzD,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,MAAM,IAAIQ,MAAM;IAEpB,MAAMC,WAAWT,MAAM,MAAM,CAACU;IAC9B,IAAIV,MAAM,MAAM,KAAKS,SAAS,MAAM,EAChC,MAAM,IAAID,MACN,CAAC,8DAA8D,EAAER,MAAM,IAAI,CACvE,KACF,IAAI,EAAES,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC;IAIrC,OAAOX,KAAKJ,QAAQM;AACxB"}
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
plugins
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new WebinyError("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
16
|
-
type,
|
|
17
|
-
property
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
collection[key] = plugin;
|
|
21
|
-
return collection;
|
|
22
|
-
}, {});
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
const getMappedPlugins = (params)=>{
|
|
3
|
+
const { plugins: pluginsContainer, type, property } = params;
|
|
4
|
+
const plugins = pluginsContainer.byType(type);
|
|
5
|
+
if (0 === plugins.length) return {};
|
|
6
|
+
return plugins.reduce((collection, plugin)=>{
|
|
7
|
+
const key = plugin[property];
|
|
8
|
+
if ("string" != typeof key) throw new error("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
9
|
+
type,
|
|
10
|
+
property
|
|
11
|
+
});
|
|
12
|
+
collection[key] = plugin;
|
|
13
|
+
return collection;
|
|
14
|
+
}, {});
|
|
23
15
|
};
|
|
16
|
+
export { getMappedPlugins };
|
|
24
17
|
|
|
25
18
|
//# sourceMappingURL=mapPlugins.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/mapPlugins.js","sources":["../../../../src/operations/entry/filtering/mapPlugins.ts"],"sourcesContent":["import type { Plugin, PluginsContainer } from \"@webiny/plugins/types.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"names":["getMappedPlugins","params","pluginsContainer","type","property","plugins","collection","plugin","key","WebinyError"],"mappings":";AAQO,MAAMA,mBAAmB,CAAmBC;IAC/C,MAAM,EAAE,SAASC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGH;IACtD,MAAMI,UAAUH,iBAAiB,MAAM,CAAIC;IAC3C,IAAIE,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAO,CAAC;IAEZ,OAAOA,QAAQ,MAAM,CAAoB,CAACC,YAAYC;QAClD,MAAMC,MAA2BD,MAAM,CAACH,SAAS;QACjD,IAAI,AAAe,YAAf,OAAOI,KACP,MAAM,IAAIC,MACN,oDACA,yBACA;YACIN;YACAC;QACJ;QAGRE,UAAU,CAACE,IAAI,GAAGD;QAClB,OAAOD;IACX,GAAG,CAAC;AACR"}
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
plugin.name = `headless-cms.ddb.filter.default`;
|
|
34
|
-
return plugin;
|
|
3
|
+
const createDefaultFilterCreate = ()=>{
|
|
4
|
+
const plugin = new CmsEntryFieldFilterPlugin({
|
|
5
|
+
fieldType: CmsEntryFieldFilterPlugin.ALL,
|
|
6
|
+
create: (params)=>{
|
|
7
|
+
const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;
|
|
8
|
+
const filter = valueFilterRegistry.get(params.operation);
|
|
9
|
+
if (!filter) throw new error(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
|
|
10
|
+
operation: params.operation
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
negate,
|
|
14
|
+
transformValue,
|
|
15
|
+
field,
|
|
16
|
+
compareValue,
|
|
17
|
+
fieldPathId: [
|
|
18
|
+
...field.parents.map((f)=>f.fieldId),
|
|
19
|
+
field.fieldId
|
|
20
|
+
].join("."),
|
|
21
|
+
path: field.createPath({
|
|
22
|
+
field
|
|
23
|
+
}),
|
|
24
|
+
filter
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
plugin.name = "headless-cms.ddb.filter.default";
|
|
29
|
+
return plugin;
|
|
35
30
|
};
|
|
31
|
+
export { createDefaultFilterCreate };
|
|
36
32
|
|
|
37
33
|
//# sourceMappingURL=defaultFilterCreate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/plugins/defaultFilterCreate.js","sources":["../../../../../src/operations/entry/filtering/plugins/defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\n\nexport const createDefaultFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;\n const filter = valueFilterRegistry.get(params.operation);\n if (!filter) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n filter\n };\n }\n });\n\n plugin.name = `headless-cms.ddb.filter.default`;\n\n return plugin;\n};\n"],"names":["createDefaultFilterCreate","plugin","CmsEntryFieldFilterPlugin","params","negate","transformValue","field","compareValue","valueFilterRegistry","filter","WebinyError","f"],"mappings":";;AAGO,MAAMA,4BAA4B;IACrC,MAAMC,SAAS,IAAIC,0BAA0B;QACzC,WAAWA,0BAA0B,GAAG;QACxC,QAAQC,CAAAA;YACJ,MAAM,EAAEC,MAAM,EAAEC,cAAc,EAAEC,KAAK,EAAEC,YAAY,EAAEC,mBAAmB,EAAE,GAAGL;YAC7E,MAAMM,SAASD,oBAAoB,GAAG,CAACL,OAAO,SAAS;YACvD,IAAI,CAACM,QACD,MAAM,IAAIC,MACN,CAAC,yCAAyC,EAAEP,OAAO,SAAS,CAAC,EAAE,CAAC,EAChE,4BACA;gBACI,WAAWA,OAAO,SAAS;YAC/B;YAGR,OAAO;gBACHC;gBACAC;gBACAC;gBACAC;gBACA,aAAa;uBAAID,MAAM,OAAO,CAAC,GAAG,CAACK,CAAAA,IAAKA,EAAE,OAAO;oBAAGL,MAAM,OAAO;iBAAC,CAAC,IAAI,CAAC;gBACxE,MAAMA,MAAM,UAAU,CAAC;oBACnBA;gBACJ;gBACAG;YACJ;QACJ;IACJ;IAEAR,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
|
@@ -2,8 +2,12 @@ import { createDefaultFilterCreate } from "./defaultFilterCreate.js";
|
|
|
2
2
|
import { createRefFilterCreate } from "./refFilterCreate.js";
|
|
3
3
|
import { objectFilterCreate } from "./objectFilterCreate.js";
|
|
4
4
|
import { searchableJsonFilterCreate } from "./searchableJsonFilterCreate.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const createFilterCreatePlugins = ()=>[
|
|
6
|
+
createDefaultFilterCreate(),
|
|
7
|
+
createRefFilterCreate(),
|
|
8
|
+
objectFilterCreate(),
|
|
9
|
+
searchableJsonFilterCreate()
|
|
10
|
+
];
|
|
11
|
+
export { createFilterCreatePlugins };
|
|
8
12
|
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/filtering/plugins/index.js","sources":["../../../../../src/operations/entry/filtering/plugins/index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate.js\";\nimport { createRefFilterCreate } from \"./refFilterCreate.js\";\nimport { objectFilterCreate } from \"./objectFilterCreate.js\";\nimport { searchableJsonFilterCreate } from \"./searchableJsonFilterCreate.js\";\n\nexport const createFilterCreatePlugins = () => {\n return [\n createDefaultFilterCreate(),\n createRefFilterCreate(),\n objectFilterCreate(),\n searchableJsonFilterCreate()\n ];\n};\n"],"names":["createFilterCreatePlugins","createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate","searchableJsonFilterCreate"],"mappings":";;;;AAKO,MAAMA,4BAA4B,IAC9B;QACHC;QACAC;QACAC;QACAC;KACH"}
|
|
@@ -1,84 +1,68 @@
|
|
|
1
1
|
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
2
2
|
import { extractWhereParams } from "../where.js";
|
|
3
|
-
import
|
|
3
|
+
import error from "@webiny/error";
|
|
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
|
-
|
|
6
|
+
const objectFilterCreate = ()=>{
|
|
7
|
+
const plugin = new CmsEntryFieldFilterPlugin({
|
|
8
|
+
fieldType: "object",
|
|
9
|
+
create: (params)=>{
|
|
10
|
+
const { value: objectValue, valueFilterRegistry, transformValuePlugins, getFilterCreatePlugin, field: parentField, fields } = params;
|
|
11
|
+
const filters = [];
|
|
12
|
+
for(const key in objectValue){
|
|
13
|
+
const value = objectValue[key];
|
|
14
|
+
if (void 0 === value) continue;
|
|
15
|
+
const whereParams = extractWhereParams(key);
|
|
16
|
+
if (!whereParams) continue;
|
|
17
|
+
const { negate, fieldId, operation } = whereParams;
|
|
18
|
+
const fieldPath = parentField.parents.map((p)=>p.fieldId).concat([
|
|
19
|
+
parentField.fieldId,
|
|
20
|
+
fieldId
|
|
21
|
+
]).join(".");
|
|
22
|
+
const field = fields[fieldPath];
|
|
23
|
+
if (!field) throw new error(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
|
|
24
|
+
fieldId
|
|
25
|
+
});
|
|
26
|
+
const fieldType = getBaseFieldType(field);
|
|
27
|
+
const filterCreatePlugin = getFilterCreatePlugin(fieldType);
|
|
28
|
+
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
29
|
+
const transformValueCallable = (value)=>{
|
|
30
|
+
if (!transformValuePlugin) return value;
|
|
31
|
+
return transformValuePlugin.transform({
|
|
32
|
+
field,
|
|
33
|
+
value
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const result = filterCreatePlugin.create({
|
|
37
|
+
key,
|
|
38
|
+
value,
|
|
39
|
+
valueFilterRegistry,
|
|
40
|
+
transformValuePlugins,
|
|
41
|
+
getFilterCreatePlugin,
|
|
42
|
+
operation,
|
|
43
|
+
negate,
|
|
44
|
+
field,
|
|
45
|
+
fields,
|
|
46
|
+
compareValue: transformValue({
|
|
47
|
+
value,
|
|
48
|
+
transform: transformValueCallable
|
|
49
|
+
}),
|
|
50
|
+
transformValue: transformValueCallable
|
|
51
|
+
});
|
|
52
|
+
if (result) {
|
|
53
|
+
if (Array.isArray(result)) {
|
|
54
|
+
filters.push(...result);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
filters.push(result);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return filters;
|
|
23
61
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const {
|
|
29
|
-
negate,
|
|
30
|
-
fieldId,
|
|
31
|
-
operation
|
|
32
|
-
} = whereParams;
|
|
33
|
-
const fieldPath = parentField.parents.map(p => p.fieldId).concat([parentField.fieldId, fieldId]).join(".");
|
|
34
|
-
const field = fields[fieldPath];
|
|
35
|
-
if (!field) {
|
|
36
|
-
throw new WebinyError(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
|
|
37
|
-
fieldId
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const fieldType = getBaseFieldType(field);
|
|
41
|
-
const filterCreatePlugin = getFilterCreatePlugin(fieldType);
|
|
42
|
-
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
43
|
-
const transformValueCallable = value => {
|
|
44
|
-
if (!transformValuePlugin) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
return transformValuePlugin.transform({
|
|
48
|
-
field,
|
|
49
|
-
value
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const result = filterCreatePlugin.create({
|
|
53
|
-
key,
|
|
54
|
-
value,
|
|
55
|
-
valueFilterRegistry,
|
|
56
|
-
transformValuePlugins,
|
|
57
|
-
getFilterCreatePlugin,
|
|
58
|
-
operation,
|
|
59
|
-
negate,
|
|
60
|
-
field,
|
|
61
|
-
fields,
|
|
62
|
-
compareValue: transformValue({
|
|
63
|
-
value,
|
|
64
|
-
transform: transformValueCallable
|
|
65
|
-
}),
|
|
66
|
-
transformValue: transformValueCallable
|
|
67
|
-
});
|
|
68
|
-
if (!result) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (Array.isArray(result)) {
|
|
72
|
-
filters.push(...result);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
filters.push(result);
|
|
76
|
-
}
|
|
77
|
-
return filters;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
plugin.name = `headless-cms.ddb.filter.object`;
|
|
81
|
-
return plugin;
|
|
62
|
+
});
|
|
63
|
+
plugin.name = "headless-cms.ddb.filter.object";
|
|
64
|
+
return plugin;
|
|
82
65
|
};
|
|
66
|
+
export { objectFilterCreate };
|
|
83
67
|
|
|
84
68
|
//# sourceMappingURL=objectFilterCreate.js.map
|