@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.97 kB
Source Map (JSON)
{"version":3,"file":"resolve-custom-field-sorts.mjs","names":[],"sources":["../../../src/utils/helpers/resolve-custom-field-sorts.ts"],"sourcesContent":["import { isFieldTypeSortable } from \"../../libs/collection/custom-fields/capabilities.js\";\nimport type { CollectionSchemaTable } from \"../../libs/collection/schema/types.js\";\nimport type { QueryParamSorts } from \"../../types/query-params.js\";\nimport type { LucidBrickTableName } from \"../../types.js\";\n\nconst CUSTOMFIELD_SORT_PREFIX = \"_\";\n\nexport type CustomFieldSort = {\n\t/** Raw sort key, e.g. `_title`. */\n\tkey: string;\n\t/** Generated document-fields value column. */\n\tcolumn: `_${string}`;\n};\n\n/** Resolves supported underscore-prefixed top-level field sort keys. */\nconst resolveCustomFieldSorts = (\n\tdocumentFieldsTableSchema:\n\t\t| CollectionSchemaTable<LucidBrickTableName>\n\t\t| undefined,\n\tsorts?: QueryParamSorts,\n): CustomFieldSort[] => {\n\tif (!sorts || !documentFieldsTableSchema) return [];\n\n\tconst results: CustomFieldSort[] = [];\n\tfor (const sort of sorts) {\n\t\tif (!sort.key.startsWith(CUSTOMFIELD_SORT_PREFIX)) continue;\n\n\t\t//* sort key matches the generated column name\n\t\tconst column = documentFieldsTableSchema.columns.find(\n\t\t\t(col) => col.name === sort.key && col.source === \"field\",\n\t\t);\n\t\tif (!column?.customField) continue;\n\t\tif (!isFieldTypeSortable(column.customField.type)) continue;\n\n\t\tresults.push({\n\t\t\tkey: sort.key,\n\t\t\tcolumn: column.name as `_${string}`,\n\t\t});\n\t}\n\n\treturn results;\n};\n\nexport default resolveCustomFieldSorts;\n"],"mappings":"2FAKA,MAUM,GACL,EAGA,IACuB,CACvB,GAAI,CAAC,GAAS,CAAC,EAA2B,MAAO,CAAC,EAElD,IAAM,EAA6B,CAAC,EACpC,IAAK,IAAM,KAAQ,EAAO,CACzB,GAAI,CAAC,EAAK,IAAI,WAAW,GAAuB,EAAG,SAGnD,IAAM,EAAS,EAA0B,QAAQ,KAC/C,GAAQ,EAAI,OAAS,EAAK,KAAO,EAAI,SAAW,OAClD,EACK,GAAQ,aACR,EAAoB,EAAO,YAAY,IAAI,GAEhD,EAAQ,KAAK,CACZ,IAAK,EAAK,IACV,OAAQ,EAAO,IAChB,CAAC,CACF,CAEA,OAAO,CACR"}