@webiny/api-headless-cms 6.4.4-beta.3 → 6.4.4-beta.4
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.
|
@@ -1,26 +1,48 @@
|
|
|
1
|
+
const FORBIDDEN_KEYS = new Set([
|
|
2
|
+
"__proto__",
|
|
3
|
+
"prototype",
|
|
4
|
+
"constructor"
|
|
5
|
+
]);
|
|
1
6
|
const transformWhereToNested = (where)=>{
|
|
2
7
|
if (!where) return;
|
|
3
|
-
|
|
4
|
-
for (const [key, value] of Object.entries(where)){
|
|
8
|
+
return Object.entries(where).reduce((result, [key, value])=>{
|
|
5
9
|
if ("AND" === key || "OR" === key) {
|
|
6
|
-
if (Array.isArray(value))
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
if (!Array.isArray(value)) return {
|
|
11
|
+
...result,
|
|
12
|
+
[key]: value
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
...result,
|
|
16
|
+
[key]: value.map((item)=>transformWhereToNested(item))
|
|
17
|
+
};
|
|
9
18
|
}
|
|
10
19
|
const dotIndex = key.indexOf(".");
|
|
11
|
-
if (-1 === dotIndex)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const expanded = transformWhereToNested({
|
|
18
|
-
[tail]: value
|
|
19
|
-
});
|
|
20
|
-
Object.assign(nested, expanded);
|
|
20
|
+
if (-1 === dotIndex) {
|
|
21
|
+
if (FORBIDDEN_KEYS.has(key)) throw new Error(`Invalid where key: "${key}".`);
|
|
22
|
+
return {
|
|
23
|
+
...result,
|
|
24
|
+
[key]: value
|
|
25
|
+
};
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const head = key.slice(0, dotIndex);
|
|
28
|
+
const tail = key.slice(dotIndex + 1);
|
|
29
|
+
if (FORBIDDEN_KEYS.has(head)) throw new Error(`Invalid where key: "${head}".`);
|
|
30
|
+
if (Object.hasOwn(result, head)) return {
|
|
31
|
+
...result,
|
|
32
|
+
[head]: {
|
|
33
|
+
...result[head],
|
|
34
|
+
...transformWhereToNested({
|
|
35
|
+
[tail]: value
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...result,
|
|
41
|
+
[head]: transformWhereToNested({
|
|
42
|
+
[tail]: value
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}, {});
|
|
24
46
|
};
|
|
25
47
|
export { transformWhereToNested };
|
|
26
48
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/schema/cms/helpers/transformWhereToNested.js","sources":["../../../../../src/graphql/schema/cms/helpers/transformWhereToNested.ts"],"sourcesContent":["/**\n * Transforms a flat where object with dot-notation keys into a nested object.\n * Keys without dots are passed through unchanged.\n * Handles logical operators (AND, OR) recursively.\n *\n * @param where - Where clause object potentially containing dot-notation keys\n * @returns Nested where object compatible with the GraphQL ListWhereInput type\n *\n * @example\n * transformWhereToNested({ \"values.name\": \"Keyboard\", id: \"abc\" })\n * // Returns: { values: { name: \"Keyboard\" }, id: \"abc\" }\n *\n * @example\n * transformWhereToNested({ \"values.price_gt\": 100, \"values.name_contains\": \"board\" })\n * // Returns: { values: { price_gt: 100, name_contains: \"board\" } }\n */\nexport const transformWhereToNested = (\n where?: Record<string, unknown>\n): Record<string, unknown> | undefined => {\n if (!where) {\n return undefined;\n }\n\n
|
|
1
|
+
{"version":3,"file":"graphql/schema/cms/helpers/transformWhereToNested.js","sources":["../../../../../src/graphql/schema/cms/helpers/transformWhereToNested.ts"],"sourcesContent":["const FORBIDDEN_KEYS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\n/**\n * Transforms a flat where object with dot-notation keys into a nested object.\n * Keys without dots are passed through unchanged.\n * Handles logical operators (AND, OR) recursively.\n *\n * @param where - Where clause object potentially containing dot-notation keys\n * @returns Nested where object compatible with the GraphQL ListWhereInput type\n *\n * @example\n * transformWhereToNested({ \"values.name\": \"Keyboard\", id: \"abc\" })\n * // Returns: { values: { name: \"Keyboard\" }, id: \"abc\" }\n *\n * @example\n * transformWhereToNested({ \"values.price_gt\": 100, \"values.name_contains\": \"board\" })\n * // Returns: { values: { price_gt: 100, name_contains: \"board\" } }\n */\nexport const transformWhereToNested = (\n where?: Record<string, unknown>\n): Record<string, unknown> | undefined => {\n if (!where) {\n return undefined;\n }\n\n return Object.entries(where).reduce<Record<string, unknown>>((result, [key, value]) => {\n if (key === \"AND\" || key === \"OR\") {\n if (!Array.isArray(value)) {\n return {\n ...result,\n [key]: value\n };\n }\n return {\n ...result,\n [key]: value.map(item => transformWhereToNested(item))\n };\n }\n\n const dotIndex = key.indexOf(\".\");\n\n if (dotIndex === -1) {\n if (FORBIDDEN_KEYS.has(key)) {\n throw new Error(`Invalid where key: \"${key}\".`);\n }\n return {\n ...result,\n [key]: value\n };\n }\n\n const head = key.slice(0, dotIndex);\n const tail = key.slice(dotIndex + 1);\n\n if (FORBIDDEN_KEYS.has(head)) {\n throw new Error(`Invalid where key: \"${head}\".`);\n }\n\n if (Object.hasOwn(result, head)) {\n return {\n ...result,\n [head]: {\n ...(result[head] as Record<string, unknown>),\n ...transformWhereToNested({ [tail]: value })\n }\n };\n }\n\n return {\n ...result,\n [head]: transformWhereToNested({ [tail]: value })\n };\n }, {});\n};\n"],"names":["FORBIDDEN_KEYS","Set","transformWhereToNested","where","Object","result","key","value","Array","item","dotIndex","Error","head","tail"],"mappings":"AAAA,MAAMA,iBAAiB,IAAIC,IAAI;IAAC;IAAa;IAAa;CAAc;AAkBjE,MAAMC,yBAAyB,CAClCC;IAEA,IAAI,CAACA,OACD;IAGJ,OAAOC,OAAO,OAAO,CAACD,OAAO,MAAM,CAA0B,CAACE,QAAQ,CAACC,KAAKC,MAAM;QAC9E,IAAID,AAAQ,UAARA,OAAiBA,AAAQ,SAARA,KAAc;YAC/B,IAAI,CAACE,MAAM,OAAO,CAACD,QACf,OAAO;gBACH,GAAGF,MAAM;gBACT,CAACC,IAAI,EAAEC;YACX;YAEJ,OAAO;gBACH,GAAGF,MAAM;gBACT,CAACC,IAAI,EAAEC,MAAM,GAAG,CAACE,CAAAA,OAAQP,uBAAuBO;YACpD;QACJ;QAEA,MAAMC,WAAWJ,IAAI,OAAO,CAAC;QAE7B,IAAII,AAAa,OAAbA,UAAiB;YACjB,IAAIV,eAAe,GAAG,CAACM,MACnB,MAAM,IAAIK,MAAM,CAAC,oBAAoB,EAAEL,IAAI,EAAE,CAAC;YAElD,OAAO;gBACH,GAAGD,MAAM;gBACT,CAACC,IAAI,EAAEC;YACX;QACJ;QAEA,MAAMK,OAAON,IAAI,KAAK,CAAC,GAAGI;QAC1B,MAAMG,OAAOP,IAAI,KAAK,CAACI,WAAW;QAElC,IAAIV,eAAe,GAAG,CAACY,OACnB,MAAM,IAAID,MAAM,CAAC,oBAAoB,EAAEC,KAAK,EAAE,CAAC;QAGnD,IAAIR,OAAO,MAAM,CAACC,QAAQO,OACtB,OAAO;YACH,GAAGP,MAAM;YACT,CAACO,KAAK,EAAE;gBACJ,GAAIP,MAAM,CAACO,KAAK;gBAChB,GAAGV,uBAAuB;oBAAE,CAACW,KAAK,EAAEN;gBAAM,EAAE;YAChD;QACJ;QAGJ,OAAO;YACH,GAAGF,MAAM;YACT,CAACO,KAAK,EAAEV,uBAAuB;gBAAE,CAACW,KAAK,EAAEN;YAAM;QACnD;IACJ,GAAG,CAAC;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.4.4-beta.
|
|
3
|
+
"version": "6.4.4-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@babel/code-frame": "7.29.7",
|
|
26
26
|
"@graphql-tools/merge": "9.1.9",
|
|
27
27
|
"@graphql-tools/schema": "10.0.33",
|
|
28
|
-
"@webiny/api": "6.4.4-beta.
|
|
29
|
-
"@webiny/api-core": "6.4.4-beta.
|
|
28
|
+
"@webiny/api": "6.4.4-beta.4",
|
|
29
|
+
"@webiny/api-core": "6.4.4-beta.4",
|
|
30
30
|
"@webiny/di": "1.0.1",
|
|
31
|
-
"@webiny/error": "6.4.4-beta.
|
|
32
|
-
"@webiny/feature": "6.4.4-beta.
|
|
33
|
-
"@webiny/handler": "6.4.4-beta.
|
|
34
|
-
"@webiny/handler-aws": "6.4.4-beta.
|
|
35
|
-
"@webiny/handler-db": "6.4.4-beta.
|
|
36
|
-
"@webiny/handler-graphql": "6.4.4-beta.
|
|
37
|
-
"@webiny/plugins": "6.4.4-beta.
|
|
38
|
-
"@webiny/project": "6.4.4-beta.
|
|
39
|
-
"@webiny/utils": "6.4.4-beta.
|
|
40
|
-
"@webiny/validation": "6.4.4-beta.
|
|
31
|
+
"@webiny/error": "6.4.4-beta.4",
|
|
32
|
+
"@webiny/feature": "6.4.4-beta.4",
|
|
33
|
+
"@webiny/handler": "6.4.4-beta.4",
|
|
34
|
+
"@webiny/handler-aws": "6.4.4-beta.4",
|
|
35
|
+
"@webiny/handler-db": "6.4.4-beta.4",
|
|
36
|
+
"@webiny/handler-graphql": "6.4.4-beta.4",
|
|
37
|
+
"@webiny/plugins": "6.4.4-beta.4",
|
|
38
|
+
"@webiny/project": "6.4.4-beta.4",
|
|
39
|
+
"@webiny/utils": "6.4.4-beta.4",
|
|
40
|
+
"@webiny/validation": "6.4.4-beta.4",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
42
|
"graphql": "16.14.2",
|
|
43
43
|
"graphql-tag": "2.12.6",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/babel__code-frame": "7.27.0",
|
|
53
53
|
"@types/pluralize": "0.0.33",
|
|
54
|
-
"@webiny/aws-sdk": "6.4.4-beta.
|
|
55
|
-
"@webiny/build-tools": "6.4.4-beta.
|
|
56
|
-
"@webiny/db-dynamodb": "6.4.4-beta.
|
|
57
|
-
"@webiny/handler-db": "6.4.4-beta.
|
|
58
|
-
"@webiny/project-utils": "6.4.4-beta.
|
|
59
|
-
"@webiny/sdk": "6.4.4-beta.
|
|
60
|
-
"@webiny/wcp": "6.4.4-beta.
|
|
54
|
+
"@webiny/aws-sdk": "6.4.4-beta.4",
|
|
55
|
+
"@webiny/build-tools": "6.4.4-beta.4",
|
|
56
|
+
"@webiny/db-dynamodb": "6.4.4-beta.4",
|
|
57
|
+
"@webiny/handler-db": "6.4.4-beta.4",
|
|
58
|
+
"@webiny/project-utils": "6.4.4-beta.4",
|
|
59
|
+
"@webiny/sdk": "6.4.4-beta.4",
|
|
60
|
+
"@webiny/wcp": "6.4.4-beta.4",
|
|
61
61
|
"apollo-graphql": "0.9.7",
|
|
62
62
|
"graphql": "16.14.2",
|
|
63
63
|
"oxfmt": "0.51.0",
|