@webiny/api-headless-cms 6.4.12 → 6.4.13-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.
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
const GRAPHQL_NAME = /^[_A-Za-z][_0-9A-Za-z]*$/;
|
|
2
|
+
const isValidFieldName = (name)=>GRAPHQL_NAME.test(name);
|
|
1
3
|
const buildFieldsSelection = (fields)=>{
|
|
2
4
|
if (!fields || 0 === fields.length) return `
|
|
3
5
|
id
|
|
4
6
|
entryId
|
|
5
7
|
values
|
|
6
8
|
`;
|
|
7
|
-
const fieldTree =
|
|
9
|
+
const fieldTree = Object.create(null);
|
|
8
10
|
fields.forEach((field)=>{
|
|
9
11
|
const parts = field.split(".");
|
|
12
|
+
for (const part of parts)if (!isValidFieldName(part)) throw new Error(`Invalid field "${field}".`);
|
|
10
13
|
let current = fieldTree;
|
|
11
14
|
parts.forEach((part, index)=>{
|
|
12
|
-
if (void 0 === current[part]) current[part] = index === parts.length - 1 ? null :
|
|
13
|
-
else if (null === current[part] && index < parts.length - 1) current[part] =
|
|
15
|
+
if (void 0 === current[part]) current[part] = index === parts.length - 1 ? null : Object.create(null);
|
|
16
|
+
else if (null === current[part] && index < parts.length - 1) current[part] = Object.create(null);
|
|
14
17
|
if (null !== current[part]) current = current[part];
|
|
15
18
|
});
|
|
16
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/schema/cms/helpers/buildFieldsSelection.js","sources":["../../../../../src/graphql/schema/cms/helpers/buildFieldsSelection.ts"],"sourcesContent":["/**\n * Helper to build GraphQL fields selection from fields array.\n * Supports both top-level fields (e.g., \"createdOn\", \"id\") and values fields (e.g., \"values.author.name\").\n * Properly merges nested fields that share common parent paths.\n *\n * @param fields - Optional array of field paths in dot notation\n * @returns GraphQL selection string with proper field nesting\n *\n * @example\n * buildFieldsSelection([\"id\", \"entryId\", \"createdOn\", \"values.name\", \"values.author.name\", \"values.author.email\"])\n * // Returns:\n * // id\n * // entryId\n * // createdOn\n * // values {\n * // name\n * // author {\n * // name\n * // email\n * // }\n * // }\n */\nexport const buildFieldsSelection = (fields?: string[]): string => {\n if (!fields || fields.length === 0) {\n return `\n id\n entryId\n values\n `;\n }\n\n interface FieldNode {\n [key: string]: FieldNode | null;\n }\n\n const fieldTree: FieldNode =
|
|
1
|
+
{"version":3,"file":"graphql/schema/cms/helpers/buildFieldsSelection.js","sources":["../../../../../src/graphql/schema/cms/helpers/buildFieldsSelection.ts"],"sourcesContent":["const GRAPHQL_NAME = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\nconst isValidFieldName = (name: string): boolean => {\n return GRAPHQL_NAME.test(name);\n};\n\n/**\n * Helper to build GraphQL fields selection from fields array.\n * Supports both top-level fields (e.g., \"createdOn\", \"id\") and values fields (e.g., \"values.author.name\").\n * Properly merges nested fields that share common parent paths.\n *\n * @param fields - Optional array of field paths in dot notation\n * @returns GraphQL selection string with proper field nesting\n *\n * @example\n * buildFieldsSelection([\"id\", \"entryId\", \"createdOn\", \"values.name\", \"values.author.name\", \"values.author.email\"])\n * // Returns:\n * // id\n * // entryId\n * // createdOn\n * // values {\n * // name\n * // author {\n * // name\n * // email\n * // }\n * // }\n */\nexport const buildFieldsSelection = (fields?: string[]): string => {\n if (!fields || fields.length === 0) {\n return `\n id\n entryId\n values\n `;\n }\n\n interface FieldNode {\n [key: string]: FieldNode | null;\n }\n\n // Security: the tree has no prototype, so caller-supplied keys can never reach Object.prototype.\n const fieldTree: FieldNode = Object.create(null);\n\n fields.forEach(field => {\n const parts = field.split(\".\");\n // Security: each part is inserted into a GraphQL query, so it must be a plain GraphQL name.\n for (const part of parts) {\n if (!isValidFieldName(part)) {\n throw new Error(`Invalid field \"${field}\".`);\n }\n }\n let current = fieldTree;\n\n parts.forEach((part, index) => {\n if (current[part] === undefined) {\n // Leaf node (null) or new branch (empty object)\n current[part] = index === parts.length - 1 ? null : Object.create(null);\n } else if (current[part] === null && index < parts.length - 1) {\n // Convert leaf to branch if we need to traverse deeper\n current[part] = Object.create(null);\n }\n if (current[part] !== null) {\n current = current[part] as FieldNode;\n }\n });\n });\n\n /**\n * Recursively converts the field tree into a GraphQL selection string.\n *\n * @param node - The current field tree node to process\n * @param indent - Current indentation level for formatting\n * @returns GraphQL selection string for this node and its children\n *\n * Handles two cases:\n * - Leaf nodes (value === null): Simple field name\n * - Branch nodes (value === object): Field name with nested selection in braces\n */\n const buildSelection = (node: FieldNode, indent: string = \" \"): string => {\n const lines: string[] = [];\n\n Object.keys(node)\n .sort()\n .forEach(key => {\n const value = node[key];\n if (value === null) {\n // Leaf field - just the field name\n lines.push(`${indent}${key}`);\n } else {\n // Branch field - field name with nested selection\n lines.push(`${indent}${key} {`);\n lines.push(buildSelection(value, indent + \" \"));\n lines.push(`${indent}}`);\n }\n });\n\n return lines.join(\"\\n\");\n };\n\n return buildSelection(fieldTree);\n};\n"],"names":["GRAPHQL_NAME","isValidFieldName","name","buildFieldsSelection","fields","fieldTree","Object","field","parts","part","Error","current","index","undefined","buildSelection","node","indent","lines","key","value"],"mappings":"AAAA,MAAMA,eAAe;AAErB,MAAMC,mBAAmB,CAACC,OACfF,aAAa,IAAI,CAACE;AAyBtB,MAAMC,uBAAuB,CAACC;IACjC,IAAI,CAACA,UAAUA,AAAkB,MAAlBA,OAAO,MAAM,EACxB,OAAO,CAAC;;;;QAIR,CAAC;IAQL,MAAMC,YAAuBC,OAAO,MAAM,CAAC;IAE3CF,OAAO,OAAO,CAACG,CAAAA;QACX,MAAMC,QAAQD,MAAM,KAAK,CAAC;QAE1B,KAAK,MAAME,QAAQD,MACf,IAAI,CAACP,iBAAiBQ,OAClB,MAAM,IAAIC,MAAM,CAAC,eAAe,EAAEH,MAAM,EAAE,CAAC;QAGnD,IAAII,UAAUN;QAEdG,MAAM,OAAO,CAAC,CAACC,MAAMG;YACjB,IAAID,AAAkBE,WAAlBF,OAAO,CAACF,KAAK,EAEbE,OAAO,CAACF,KAAK,GAAGG,UAAUJ,MAAM,MAAM,GAAG,IAAI,OAAOF,OAAO,MAAM,CAAC;iBAC/D,IAAIK,AAAkB,SAAlBA,OAAO,CAACF,KAAK,IAAaG,QAAQJ,MAAM,MAAM,GAAG,GAExDG,OAAO,CAACF,KAAK,GAAGH,OAAO,MAAM,CAAC;YAElC,IAAIK,AAAkB,SAAlBA,OAAO,CAACF,KAAK,EACbE,UAAUA,OAAO,CAACF,KAAK;QAE/B;IACJ;IAaA,MAAMK,iBAAiB,CAACC,MAAiBC,SAAiB,UAAU;QAChE,MAAMC,QAAkB,EAAE;QAE1BX,OAAO,IAAI,CAACS,MACP,IAAI,GACJ,OAAO,CAACG,CAAAA;YACL,MAAMC,QAAQJ,IAAI,CAACG,IAAI;YACvB,IAAIC,AAAU,SAAVA,OAEAF,MAAM,IAAI,CAAC,GAAGD,SAASE,KAAK;iBACzB;gBAEHD,MAAM,IAAI,CAAC,GAAGD,SAASE,IAAI,EAAE,CAAC;gBAC9BD,MAAM,IAAI,CAACH,eAAeK,OAAOH,SAAS;gBAC1CC,MAAM,IAAI,CAAC,GAAGD,OAAO,CAAC,CAAC;YAC3B;QACJ;QAEJ,OAAOC,MAAM,IAAI,CAAC;IACtB;IAEA,OAAOH,eAAeT;AAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.13-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@babel/code-frame": "8.0.6",
|
|
26
26
|
"@graphql-tools/merge": "10.0.9",
|
|
27
27
|
"@graphql-tools/schema": "11.0.9",
|
|
28
|
-
"@webiny/api": "6.4.
|
|
29
|
-
"@webiny/api-core": "6.4.
|
|
28
|
+
"@webiny/api": "6.4.13-beta.0",
|
|
29
|
+
"@webiny/api-core": "6.4.13-beta.0",
|
|
30
30
|
"@webiny/di": "1.1.0",
|
|
31
|
-
"@webiny/error": "6.4.
|
|
32
|
-
"@webiny/feature": "6.4.
|
|
33
|
-
"@webiny/handler": "6.4.
|
|
34
|
-
"@webiny/handler-aws": "6.4.
|
|
35
|
-
"@webiny/handler-db": "6.4.
|
|
36
|
-
"@webiny/handler-graphql": "6.4.
|
|
37
|
-
"@webiny/plugins": "6.4.
|
|
38
|
-
"@webiny/project": "6.4.
|
|
39
|
-
"@webiny/utils": "6.4.
|
|
40
|
-
"@webiny/validation": "6.4.
|
|
31
|
+
"@webiny/error": "6.4.13-beta.0",
|
|
32
|
+
"@webiny/feature": "6.4.13-beta.0",
|
|
33
|
+
"@webiny/handler": "6.4.13-beta.0",
|
|
34
|
+
"@webiny/handler-aws": "6.4.13-beta.0",
|
|
35
|
+
"@webiny/handler-db": "6.4.13-beta.0",
|
|
36
|
+
"@webiny/handler-graphql": "6.4.13-beta.0",
|
|
37
|
+
"@webiny/plugins": "6.4.13-beta.0",
|
|
38
|
+
"@webiny/project": "6.4.13-beta.0",
|
|
39
|
+
"@webiny/utils": "6.4.13-beta.0",
|
|
40
|
+
"@webiny/validation": "6.4.13-beta.0",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
42
|
"graphql": "16.15.0",
|
|
43
43
|
"graphql-tag": "2.12.7",
|
|
@@ -51,16 +51,16 @@
|
|
|
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.
|
|
55
|
-
"@webiny/build-tools": "6.4.
|
|
56
|
-
"@webiny/db-dynamodb": "6.4.
|
|
57
|
-
"@webiny/handler-db": "6.4.
|
|
58
|
-
"@webiny/project-utils": "6.4.
|
|
59
|
-
"@webiny/sdk": "6.4.
|
|
60
|
-
"@webiny/wcp": "6.4.
|
|
54
|
+
"@webiny/aws-sdk": "6.4.13-beta.0",
|
|
55
|
+
"@webiny/build-tools": "6.4.13-beta.0",
|
|
56
|
+
"@webiny/db-dynamodb": "6.4.13-beta.0",
|
|
57
|
+
"@webiny/handler-db": "6.4.13-beta.0",
|
|
58
|
+
"@webiny/project-utils": "6.4.13-beta.0",
|
|
59
|
+
"@webiny/sdk": "6.4.13-beta.0",
|
|
60
|
+
"@webiny/wcp": "6.4.13-beta.0",
|
|
61
61
|
"apollo-graphql": "0.9.7",
|
|
62
62
|
"graphql": "16.15.0",
|
|
63
|
-
"oxfmt": "0.
|
|
63
|
+
"oxfmt": "0.79.0",
|
|
64
64
|
"rimraf": "6.1.4",
|
|
65
65
|
"typescript": "6.0.3",
|
|
66
66
|
"vitest": "5.1.0",
|