@webiny/api-headless-cms-ddb 5.33.5 → 5.34.0-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.
Files changed (104) hide show
  1. package/definitions/entry.js +3 -7
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +3 -7
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +8 -7
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/settings.js +3 -7
  8. package/definitions/settings.js.map +1 -1
  9. package/definitions/system.js +3 -7
  10. package/definitions/system.js.map +1 -1
  11. package/dynamoDb/index.d.ts +1 -1
  12. package/dynamoDb/path/plainObject.js +1 -1
  13. package/dynamoDb/storage/date.d.ts +2 -1
  14. package/dynamoDb/storage/date.js +14 -4
  15. package/dynamoDb/storage/date.js.map +1 -1
  16. package/dynamoDb/storage/longText.d.ts +1 -1
  17. package/dynamoDb/storage/longText.js +8 -1
  18. package/dynamoDb/storage/longText.js.map +1 -1
  19. package/dynamoDb/storage/richText.d.ts +1 -1
  20. package/dynamoDb/storage/richText.js +1 -1
  21. package/dynamoDb/storage/richText.js.map +1 -1
  22. package/index.js +12 -5
  23. package/index.js.map +1 -1
  24. package/operations/entry/dataLoaders.js +7 -9
  25. package/operations/entry/dataLoaders.js.map +1 -1
  26. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  27. package/operations/entry/filtering/createExpressions.js +217 -0
  28. package/operations/entry/filtering/createExpressions.js.map +1 -0
  29. package/operations/entry/filtering/createFields.d.ts +14 -0
  30. package/operations/entry/filtering/createFields.js +123 -0
  31. package/operations/entry/filtering/createFields.js.map +1 -0
  32. package/operations/entry/filtering/extractSort.d.ts +13 -0
  33. package/operations/entry/filtering/extractSort.js +55 -0
  34. package/operations/entry/filtering/extractSort.js.map +1 -0
  35. package/operations/entry/filtering/filter.d.ts +15 -0
  36. package/operations/entry/filtering/filter.js +178 -0
  37. package/operations/entry/filtering/filter.js.map +1 -0
  38. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  39. package/operations/entry/filtering/fullTextSearch.js +60 -0
  40. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  41. package/operations/entry/filtering/getValue.d.ts +5 -0
  42. package/operations/entry/filtering/getValue.js +81 -0
  43. package/operations/entry/filtering/getValue.js.map +1 -0
  44. package/operations/entry/filtering/index.d.ts +2 -0
  45. package/operations/entry/filtering/index.js +21 -0
  46. package/operations/entry/filtering/index.js.map +1 -0
  47. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  48. package/operations/entry/filtering/mapPlugins.js +39 -0
  49. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  50. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  51. package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
  52. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  53. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  54. package/operations/entry/filtering/plugins/index.js +18 -0
  55. package/operations/entry/filtering/plugins/index.js.map +1 -0
  56. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  57. package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
  58. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  59. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  60. package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
  61. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  62. package/operations/entry/filtering/sort.d.ts +9 -0
  63. package/operations/entry/filtering/sort.js +80 -0
  64. package/operations/entry/filtering/sort.js.map +1 -0
  65. package/operations/entry/filtering/systemFields.d.ts +4 -0
  66. package/operations/entry/filtering/systemFields.js +72 -0
  67. package/operations/entry/filtering/systemFields.js.map +1 -0
  68. package/operations/entry/filtering/transform.d.ts +6 -0
  69. package/operations/entry/filtering/transform.js +19 -0
  70. package/operations/entry/filtering/transform.js.map +1 -0
  71. package/operations/entry/filtering/types.d.ts +40 -0
  72. package/operations/entry/filtering/types.js +5 -0
  73. package/operations/entry/filtering/types.js.map +1 -0
  74. package/operations/entry/filtering/values.d.ts +2 -0
  75. package/operations/entry/filtering/values.js +28 -0
  76. package/operations/entry/filtering/values.js.map +1 -0
  77. package/operations/entry/filtering/where.d.ts +5 -0
  78. package/operations/entry/filtering/where.js +38 -0
  79. package/operations/entry/filtering/where.js.map +1 -0
  80. package/operations/entry/index.js +54 -166
  81. package/operations/entry/index.js.map +1 -1
  82. package/operations/entry/keys.js +1 -1
  83. package/operations/entry/systemFields.js +6 -0
  84. package/operations/entry/systemFields.js.map +1 -1
  85. package/operations/group/index.js +6 -10
  86. package/operations/group/index.js.map +1 -1
  87. package/operations/model/index.js +4 -8
  88. package/operations/model/index.js.map +1 -1
  89. package/operations/settings/index.js +6 -10
  90. package/operations/settings/index.js.map +1 -1
  91. package/operations/system/index.js +4 -8
  92. package/operations/system/index.js.map +1 -1
  93. package/package.json +15 -16
  94. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
  95. package/plugins/CmsEntryFieldFilterPathPlugin.js +1 -1
  96. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  97. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  98. package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
  99. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  100. package/types.d.ts +1 -1
  101. package/types.js.map +1 -1
  102. package/operations/entry/utils.d.ts +0 -36
  103. package/operations/entry/utils.js +0 -684
  104. package/operations/entry/utils.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsStorageEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(\n params: GetAllEntryRevisionsParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;;;;;AAEA,MAAMA,oBAAoB,GAAIC,MAAD,IAA0B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EA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8C,cAAJ,CACD,2DADC,EAEF,4BAFE,EAGF;MACIO,MADJ;MAEIrD,GAFJ;MAGIC;IAHJ,CAHE,CAAN;EASH;;EAEMiE,QAAQ,CAACxE,MAAD,EAAiD;IAC5D,KAAK,MAAMmD,IAAX,IAAmBN,WAAnB,EAAgC;MAC5B,MAAMc,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBnD,MAArB,CAAf;MACA2D,MAAM,CAACa,QAAP;IACH;EACJ;;AAjH2B"}
1
+ {"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsStorageEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(\n params: GetAllEntryRevisionsParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAIC,MAAD,IAA0B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBF,MAA1B;EACA,MAAM;IAAEG,MAAF;IAAUC;EAAV,IAAqBF,KAA3B;EACA,OAAO,IAAIG,mBAAJ,CAA0C,MAAOC,GAAP,IAAkC;IAC/E,MAAMC,OAA0C,GAAG,EAAnD;;IACA,KAAK,MAAMC,EAAX,IAAiBF,GAAjB,EAAsB;MAClB,MAAMG,cAA8B,GAAG;QACnCR,MADmC;QAEnCS,YAAY,EAAE,IAAAC,wBAAA,EAAmB;UAC7BR,MAD6B;UAE7BC,MAF6B;UAG7BI;QAH6B,CAAnB,CAFqB;QAOnCI,OAAO,EAAE;UACLC,UAAU,EAAE;QADP;MAP0B,CAAvC;MAWA,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAA,EAA0BN,cAA1B,CAApB;MACAF,OAAO,CAACC,EAAD,CAAP,GAAc,IAAAQ,qBAAA,EAAaf,MAAb,EAAqBa,KAArB,CAAd;IACH;;IAED,OAAOR,GAAG,CAACW,GAAJ,CAAQT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAD,CAAP,IAAe,EAAtB;IACH,CAFM,CAAP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jC,8DACCF,GADD;gBAEFG,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeL,GAAG,CAACG,IAAJ,IAAY,EAA3B;cAFJ,GAAN;YAIH;;YACD,MAAM,IAAId,cAAJ,CACF,uFADE,EAEF,2BAFE,8DAIKpD,MAJL;cAKE2D;YALF,GAAN;UAQH;;UACDG,GAAG,CAACO,IAAJ,CAAS,GAAGN,GAAZ;UACA,OAAOD,GAAP;QACH,CAnBM,EAmBJ,EAnBI,CAAP;MAoBH;IACJ,CAxBD,CAwBE,OAAOQ,EAAP,EAAW;MACT,MAAM,IAAIlB,cAAJ,CACFkB,EAAE,CAACN,OAAH,IAAc,oBADZ,EAEFM,EAAE,CAACL,IAAH,IAAW,mBAFT;QAIEM,KAAK,EAAED;MAJT,GAKKtE,MALL;QAME2D,MANF;QAOErD;MAPF,GAAN;IAUH;;IACD,MAAM,IAAI8C,cAAJ,CACD,2DADC,EAEF,4BAFE,EAGF;MACIO,MADJ;MAEIrD,GAFJ;MAGIC;IAHJ,CAHE,CAAN;EASH;;EAEMiE,QAAQ,CAACxE,MAAD,EAAiD;IAC5D,KAAK,MAAMmD,IAAX,IAAmBN,WAAnB,EAAgC;MAC5B,MAAMc,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBnD,MAArB,CAAf;MACA2D,MAAM,CAACa,QAAP;IACH;EACJ;;AAjH2B"}
@@ -0,0 +1,26 @@
1
+ import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ import { Field } from "./types";
5
+ interface Params {
6
+ plugins: PluginsContainer;
7
+ where: Partial<CmsEntryListWhere>;
8
+ fields: Record<string, Field>;
9
+ }
10
+ export declare type ExpressionCondition = "AND" | "OR";
11
+ export interface Expression {
12
+ expressions: Expression[];
13
+ filters: Filter[];
14
+ condition: ExpressionCondition;
15
+ }
16
+ export interface Filter {
17
+ field: Field;
18
+ path: string;
19
+ fieldPathId: string;
20
+ plugin: ValueFilterPlugin;
21
+ negate: boolean;
22
+ compareValue: any;
23
+ transformValue: <I = any, O = any>(value: I) => O;
24
+ }
25
+ export declare const createExpressions: (params: Params) => Expression;
26
+ export {};
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createExpressions = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
13
+
14
+ var _mapPlugins = require("./mapPlugins");
15
+
16
+ var _where = require("./where");
17
+
18
+ var _transform = require("./transform");
19
+
20
+ var _CmsEntryFieldFilterPlugin = require("../../../plugins/CmsEntryFieldFilterPlugin");
21
+
22
+ var _values = require("./values");
23
+
24
+ const createExpressions = params => {
25
+ const {
26
+ where,
27
+ plugins,
28
+ fields
29
+ } = params;
30
+ const filterPlugins = (0, _mapPlugins.getMappedPlugins)({
31
+ plugins,
32
+ type: _ValueFilterPlugin.ValueFilterPlugin.type,
33
+ property: "operation"
34
+ });
35
+ const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
36
+ plugins,
37
+ type: "cms-field-filter-value-transform",
38
+ property: "fieldType"
39
+ });
40
+ const fieldFilterCreatePlugins = (0, _mapPlugins.getMappedPlugins)({
41
+ plugins,
42
+ type: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.type,
43
+ property: "fieldType"
44
+ });
45
+ const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
46
+
47
+ const getFilterCreatePlugin = type => {
48
+ const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;
49
+
50
+ if (filterCreatePlugin) {
51
+ return filterCreatePlugin;
52
+ }
53
+
54
+ throw new _error.default(`There is no filter create plugin for the field type "${type}".`, "MISSING_FILTER_CREATE_PLUGIN", {
55
+ type
56
+ });
57
+ };
58
+
59
+ const createExpression = ({
60
+ where,
61
+ condition
62
+ }) => {
63
+ const expression = {
64
+ filters: [],
65
+ expressions: [],
66
+ condition
67
+ };
68
+
69
+ for (const key in where) {
70
+ if (where.hasOwnProperty(key) === false) {
71
+ continue;
72
+ }
73
+
74
+ const value = where[key];
75
+
76
+ if (value === undefined) {
77
+ continue;
78
+ }
79
+ /**
80
+ * If there are "AND" or "OR" keys, let's sort them out first.
81
+ *
82
+ *
83
+ * AND conditional
84
+ */
85
+
86
+
87
+ if (key === "AND") {
88
+ const childWhereList = (0, _values.getWhereValues)(value, key);
89
+ const childExpression = {
90
+ condition: "AND",
91
+ filters: [],
92
+ expressions: []
93
+ };
94
+
95
+ for (const childWhere of childWhereList) {
96
+ const result = createExpression({
97
+ where: childWhere,
98
+ condition: "AND"
99
+ });
100
+ childExpression.expressions.push(result);
101
+ }
102
+
103
+ expression.expressions.push(childExpression);
104
+ continue;
105
+ }
106
+ /**
107
+ * OR conditional
108
+ */
109
+
110
+
111
+ if (key === "OR") {
112
+ const childWhereList = (0, _values.getWhereValues)(value, key);
113
+ const childExpression = {
114
+ condition: "OR",
115
+ filters: [],
116
+ expressions: []
117
+ };
118
+
119
+ for (const childWhere of childWhereList) {
120
+ const result = createExpression({
121
+ where: childWhere,
122
+ condition: "AND"
123
+ });
124
+ childExpression.expressions.push(result);
125
+ }
126
+
127
+ expression.expressions.push(childExpression);
128
+ continue;
129
+ }
130
+
131
+ const whereParams = (0, _where.extractWhereParams)(key);
132
+
133
+ if (!whereParams) {
134
+ continue;
135
+ }
136
+
137
+ const {
138
+ fieldId,
139
+ operation,
140
+ negate
141
+ } = whereParams;
142
+ const field = fields[fieldId];
143
+
144
+ if (!field) {
145
+ throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
146
+ fieldId
147
+ });
148
+ }
149
+ /**
150
+ * We need a filter create plugin for this type.
151
+ */
152
+
153
+
154
+ const filterCreatePlugin = getFilterCreatePlugin(field.type);
155
+ const transformValuePlugin = transformValuePlugins[field.type];
156
+
157
+ const transformValueCallable = value => {
158
+ if (!transformValuePlugin) {
159
+ return value;
160
+ }
161
+
162
+ return transformValuePlugin.transform({
163
+ field,
164
+ value
165
+ });
166
+ };
167
+
168
+ const result = filterCreatePlugin.create({
169
+ key,
170
+ value,
171
+ valueFilterPlugins: filterPlugins,
172
+ transformValuePlugins,
173
+ getFilterCreatePlugin,
174
+ operation,
175
+ negate,
176
+ field,
177
+ fields,
178
+ compareValue: (0, _transform.transformValue)({
179
+ value,
180
+ transform: transformValueCallable
181
+ }),
182
+ transformValue: transformValueCallable
183
+ });
184
+ /**
185
+ * There is a possibility of
186
+ * - no result
187
+ * - result being an array
188
+ * - result being an object
189
+ */
190
+
191
+ if (!result || Array.isArray(result) && result.length === 0) {
192
+ continue;
193
+ }
194
+
195
+ expression.filters.push(...(Array.isArray(result) ? result : [result]));
196
+ }
197
+
198
+ return expression;
199
+ };
200
+
201
+ const expression = createExpression({
202
+ where,
203
+ condition: "AND"
204
+ });
205
+ /**
206
+ * If the first expression has no filters and has only one expression, put that expression as main one.
207
+ * This will mostly be used when having an OR condition as the single expression in the root level of the where
208
+ */
209
+
210
+ if (expression.filters.length > 0 || expression.expressions.length !== 1) {
211
+ return expression;
212
+ }
213
+
214
+ return expression.expressions[0];
215
+ };
216
+
217
+ exports.createExpressions = createExpressions;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","hasOwnProperty","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\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 valueFilterPlugins: filterPlugins,\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 /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AAmCO,MAAMA,iBAAiB,GAAIC,MAAD,IAAgC;EAC7D,MAAM;IAAEC,KAAF;IAASC,OAAT;IAAkBC;EAAlB,IAA6BH,MAAnC;EACA,MAAMI,aAAa,GAAG,IAAAC,4BAAA,EAAoC;IACtDH,OADsD;IAEtDI,IAAI,EAAEC,oCAAA,CAAkBD,IAF8B;IAGtDE,QAAQ,EAAE;EAH4C,CAApC,CAAtB;EAKA,MAAMC,qBAAqB,GAAG,IAAAJ,4BAAA,EAAqD;IAC/EH,OAD+E;IAE/EI,IAAI,EAAE,kCAFyE;IAG/EE,QAAQ,EAAE;EAHqE,CAArD,CAA9B;EAKA,MAAME,wBAAwB,GAAG,IAAAL,4BAAA,EAA4C;IACzEH,OADyE;IAEzEI,IAAI,EAAEK,oDAAA,CAA0BL,IAFyC;IAGzEE,QAAQ,EAAE;EAH+D,CAA5C,CAAjC;EAMA,MAAMI,yBAAyB,GAAGF,wBAAwB,CAAC,GAAD,CAA1D;;EAEA,MAAMG,qB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/B,CAAP;MAIH,CARD;;MAUA,MAAMM,MAAM,GAAGf,kBAAkB,CAAC0B,MAAnB,CAA0B;QACrCnB,GADqC;QAErCE,KAFqC;QAGrCkB,kBAAkB,EAAErC,aAHiB;QAIrCK,qBAJqC;QAKrCI,qBALqC;QAMrCqB,SANqC;QAOrCC,MAPqC;QAQrCC,KARqC;QASrCjC,MATqC;QAUrCuC,YAAY,EAAE,IAAAC,yBAAA,EAAe;UACzBpB,KADyB;UAEzBgB,SAAS,EAAED;QAFc,CAAf,CAVuB;QAcrCK,cAAc,EAAEL;MAdqB,CAA1B,CAAf;MAgBA;AACZ;AACA;AACA;AACA;AACA;;MACY,IAAI,CAACT,MAAD,IAAYe,KAAK,CAACC,OAAN,CAAchB,MAAd,KAAyBA,MAAM,CAACiB,MAAP,KAAkB,CAA3D,EAA+D;QAC3D;MACH;;MAED5B,UAAU,CAACC,OAAX,CAAmBW,IAAnB,CAAwB,IAAIc,KAAK,CAACC,OAAN,CAAchB,MAAd,IAAwBA,MAAxB,GAAiC,CAACA,MAAD,CAArC,CAAxB;IACH;;IAED,OAAOX,UAAP;EACH,CAhID;;EAkIA,MAAMA,UAAU,GAAGF,gBAAgB,CAAC;IAChCf,KADgC;IAEhCgB,SAAS,EAAE;EAFqB,CAAD,CAAnC;EAIA;AACJ;AACA;AACA;;EACI,IAAIC,UAAU,CAACC,OAAX,CAAmB2B,MAAnB,GAA4B,CAA5B,IAAiC5B,UAAU,CAACE,WAAX,CAAuB0B,MAAvB,KAAkC,CAAvE,EAA0E;IACtE,OAAO5B,UAAP;EACH;;EACD,OAAOA,UAAU,CAACE,WAAX,CAAuB,CAAvB,CAAP;AACH,CAhLM"}
@@ -0,0 +1,14 @@
1
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
2
+ import { Field } from "./types";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ interface Params {
5
+ fields: CmsModelField[];
6
+ plugins: PluginsContainer;
7
+ }
8
+ /**
9
+ * This method will map the fieldId (fieldId -> field) to the actual field.
10
+ *
11
+ * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
12
+ */
13
+ export declare const createFields: (params: Params) => Record<string, Field>;
14
+ export {};
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createFields = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _systemFields = require("./systemFields");
13
+
14
+ var _plugins = require("../../../plugins");
15
+
16
+ var _mapPlugins = require("./mapPlugins");
17
+
18
+ /**
19
+ * This method will map the fieldId (fieldId -> field) to the actual field.
20
+ *
21
+ * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
22
+ */
23
+ const createFields = params => {
24
+ const {
25
+ fields,
26
+ plugins
27
+ } = params;
28
+ const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
29
+ plugins,
30
+ type: "cms-field-filter-value-transform",
31
+ property: "fieldType"
32
+ });
33
+ const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
34
+ plugins,
35
+ type: _plugins.CmsEntryFieldFilterPathPlugin.type,
36
+ property: "fieldType"
37
+ });
38
+ const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
39
+ const transformPlugin = transformValuePlugins[field.type];
40
+ fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
41
+ parents: [],
42
+ system: true,
43
+ createPath: ({
44
+ field
45
+ }) => {
46
+ var _field$settings;
47
+
48
+ return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
49
+ },
50
+ transform: value => {
51
+ if (!transformPlugin) {
52
+ return value;
53
+ }
54
+
55
+ return transformPlugin.transform({
56
+ field,
57
+ value
58
+ });
59
+ }
60
+ });
61
+ return fields;
62
+ }, {});
63
+
64
+ const addFieldsToCollection = (fields, parents = []) => {
65
+ /**
66
+ * Exit early if no fields are sent.
67
+ */
68
+ if (fields.length === 0) {
69
+ return;
70
+ }
71
+
72
+ for (const field of fields) {
73
+ var _field$settings2;
74
+
75
+ const transformPlugin = transformValuePlugins[field.type];
76
+ const valuePathPlugin = valuePathPlugins[field.type];
77
+ /**
78
+ * The required fieldId is a product of all of its parents and its own fieldId.
79
+ */
80
+
81
+ const fieldId = [...parents, {
82
+ fieldId: field.fieldId,
83
+ multipleValues: field.multipleValues
84
+ }].map(f => f.fieldId).join(".");
85
+ collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
86
+ parents,
87
+ system: false,
88
+ createPath: params => {
89
+ if (valuePathPlugin) {
90
+ return valuePathPlugin.createPath(params);
91
+ }
92
+
93
+ return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
94
+ },
95
+ transform: value => {
96
+ if (!transformPlugin) {
97
+ return value;
98
+ }
99
+
100
+ return transformPlugin.transform({
101
+ field,
102
+ value
103
+ });
104
+ }
105
+ });
106
+ const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
107
+
108
+ if (!childFields || childFields.length === 0) {
109
+ continue;
110
+ }
111
+
112
+ addFieldsToCollection(childFields, [...parents, {
113
+ fieldId: field.fieldId,
114
+ multipleValues: field.multipleValues
115
+ }]);
116
+ }
117
+ };
118
+
119
+ addFieldsToCollection(fields);
120
+ return collection;
121
+ };
122
+
123
+ exports.createFields = createFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFields","params","fields","plugins","transformValuePlugins","getMappedPlugins","type","property","valuePathPlugins","CmsEntryFieldFilterPathPlugin","collection","createSystemFields","reduce","field","transformPlugin","fieldId","parents","system","createPath","settings","path","transform","value","addFieldsToCollection","length","valuePathPlugin","multipleValues","map","f","join","concat","parent","childFields"],"sources":["createFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { createSystemFields } from \"./systemFields\";\nimport { Field, FieldParent } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins\";\nimport { getMappedPlugins } from \"./mapPlugins\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createSystemFields().reduce<Record<string, Field>>((fields, field) => {\n const transformPlugin = transformValuePlugins[field.type];\n\n fields[field.fieldId] = {\n ...field,\n parents: [],\n system: true,\n createPath: ({ field }) => {\n return field.settings?.path || field.fieldId;\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n\n return fields;\n }, {});\n\n const addFieldsToCollection = (fields: CmsModelField[], parents: FieldParent[] = []): void => {\n /**\n * Exit early if no fields are sent.\n */\n if (fields.length === 0) {\n return;\n }\n for (const field of fields) {\n const transformPlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system: false,\n createPath: params => {\n if (valuePathPlugin) {\n return valuePathPlugin.createPath(params);\n }\n\n return [\"values\"]\n .concat(parents.map(parent => parent.fieldId))\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields || childFields.length === 0) {\n continue;\n }\n addFieldsToCollection(childFields, [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]);\n }\n };\n\n addFieldsToCollection(fields);\n\n return collection;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AACA;;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,MAAD,IAAoB;EAC5C,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAsBF,MAA5B;EAEA,MAAMG,qBAAqB,GAAG,IAAAC,4BAAA,EAAqD;IAC/EF,OAD+E;IAE/EG,IAAI,EAAE,kCAFyE;IAG/EC,QAAQ,EAAE;EAHqE,CAArD,CAA9B;EAKA,MAAMC,gBAAgB,GAAG,IAAAH,4BAAA,EAAgD;IACrEF,OADqE;IAErEG,IAAI,EAAEG,sCAAA,CAA8BH,IAFiC;IAGrEC,QAAQ,EAAE;EAH2D,CAAhD,CAAzB;EAMA,MAAMG,UAAU,GAAG,IAAAC,gCAAA,IAAqBC,MAArB,CAAmD,CAACV,MAAD,EAASW,KAAT,KAAmB;IACrF,MAAMC,eAAe,GAAGV,qBAAqB,CAACS,KAAK,CAACP,IAAP,CAA7C;IAEAJ,MAAM,CAACW,KAAK,CAACE,OAAP,CAAN,+DACOF,KADP;MAEIG,OAAO,EAAE,EAFb;MAGIC,MAAM,EAAE,IAHZ;MAIIC,UAAU,EAAE,CAAC;QAAEL;MAAF,CAAD,KAAe;QAAA;;QACvB,OAAO,oBAAAA,KAAK,CAACM,QAAN,oEAAgBC,IAAhB,KAAwBP,KAAK,CAACE,OAArC;MACH,CANL;MAOIM,SAAS,EAAEC,KAAK,IAAI;QAChB,IAAI,CAAC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AChB,IAAI,CAACR,eAAL,EAAsB;YAClB,OAAOQ,KAAP;UACH;;UACD,OAAOR,eAAe,CAACO,SAAhB,CAA0B;YAC7BR,KAD6B;YAE7BS;UAF6B,CAA1B,CAAP;QAIH;MAtBL;MAwBA,MAAMU,WAAW,uBAAGnB,KAAK,CAACM,QAAT,qDAAG,iBAAgBjB,MAApC;;MACA,IAAI,CAAC8B,WAAD,IAAgBA,WAAW,CAACR,MAAZ,KAAuB,CAA3C,EAA8C;QAC1C;MACH;;MACDD,qBAAqB,CAACS,WAAD,EAAc,CAC/B,GAAGhB,OAD4B,EAE/B;QACID,OAAO,EAAEF,KAAK,CAACE,OADnB;QAEIW,cAAc,EAAEb,KAAK,CAACa;MAF1B,CAF+B,CAAd,CAArB;IAOH;EACJ,CA3DD;;EA6DAH,qBAAqB,CAACrB,MAAD,CAArB;EAEA,OAAOQ,UAAP;AACH,CAtGM"}
@@ -0,0 +1,13 @@
1
+ import { Field } from "./types";
2
+ interface Result {
3
+ valuePath: string;
4
+ reverse: boolean;
5
+ fieldId: string;
6
+ field: Field;
7
+ }
8
+ interface Params {
9
+ sortBy: string;
10
+ fields: Record<string, Field>;
11
+ }
12
+ export declare const extractSort: (params: Params) => Result;
13
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.extractSort = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ const extractSort = params => {
13
+ const {
14
+ sortBy,
15
+ fields
16
+ } = params;
17
+ const result = sortBy.split("_");
18
+
19
+ if (result.length !== 2) {
20
+ throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
21
+ sortBy
22
+ });
23
+ }
24
+
25
+ const [fieldId, order] = result;
26
+ const field = Object.values(fields).find(field => {
27
+ /**
28
+ * We do not support sorting by nested fields.
29
+ */
30
+ if (field.parents.length > 0) {
31
+ return false;
32
+ }
33
+
34
+ return field.fieldId === fieldId;
35
+ });
36
+
37
+ if (!field) {
38
+ throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
39
+ fieldId,
40
+ fields
41
+ });
42
+ }
43
+
44
+ const valuePath = field.createPath({
45
+ field
46
+ });
47
+ return {
48
+ field,
49
+ fieldId,
50
+ valuePath,
51
+ reverse: order === "DESC"
52
+ };
53
+ };
54
+
55
+ exports.extractSort = extractSort;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractSort","params","sortBy","fields","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","valuePath","createPath","reverse"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n sortBy: string;\n fields: Record<string, Field>;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { sortBy, fields } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result;\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAeO,MAAMA,WAAW,GAAIC,MAAD,IAA4B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,MAAMG,MAAM,GAAGF,MAAM,CAACG,KAAP,CAAa,GAAb,CAAf;;EACA,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,MAAM,IAAIC,cAAJ,CACF,yDADE,EAEF,oBAFE,EAGF;MACIL;IADJ,CAHE,CAAN;EAOH;;EACD,MAAM,CAACM,OAAD,EAAUC,KAAV,IAAmBL,MAAzB;EAEA,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAcT,MAAd,EAAsBU,IAAtB,CAA2BH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAN,CAAcR,MAAd,GAAuB,CAA3B,EAA8B;MAC1B,OAAO,KAAP;IACH;;IACD,OAAOI,KAAK,CAACF,OAAN,KAAkBA,OAAzB;EACH,CARa,CAAd;;EAUA,IAAI,CAACE,KAAL,EAAY;IACR,MAAM,IAAIH,cAAJ,CACF,oDADE,EAEF,qBAFE,EAGF;MACIC,OADJ;MAEIL;IAFJ,CAHE,CAAN;EAQH;;EACD,MAAMY,SAAS,GAAGL,KAAK,CAACM,UAAN,CAAiB;IAC/BN;EAD+B,CAAjB,CAAlB;EAGA,OAAO;IACHA,KADG;IAEHF,OAFG;IAGHO,SAHG;IAIHE,OAAO,EAAER,KAAK,KAAK;EAJhB,CAAP;AAMH,CA3CM"}
@@ -0,0 +1,15 @@
1
+ import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { Field } from "./types";
4
+ interface Params {
5
+ items: CmsEntry[];
6
+ where: Partial<CmsEntryListWhere>;
7
+ plugins: PluginsContainer;
8
+ fields: Record<string, Field>;
9
+ fullTextSearch?: {
10
+ term?: string;
11
+ fields?: string[];
12
+ };
13
+ }
14
+ export declare const filter: (params: Params) => CmsEntry[];
15
+ export {};