@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (172) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +9 -94
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +9 -68
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +9 -90
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +8 -30
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +65 -0
  15. package/definitions/types.js +0 -0
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +11 -20
  18. package/dynamoDb/index.js.map +1 -1
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +21 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.d.ts +1 -1
  23. package/dynamoDb/path/plainObject.js +13 -37
  24. package/dynamoDb/path/plainObject.js.map +1 -1
  25. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  26. package/dynamoDb/transformValue/datetime.js +27 -50
  27. package/dynamoDb/transformValue/datetime.js.map +1 -1
  28. package/index.d.ts +2 -3
  29. package/index.js +83 -139
  30. package/index.js.map +1 -1
  31. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  32. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  33. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  34. package/operations/entry/dataLoader/constants.d.ts +1 -0
  35. package/operations/entry/dataLoader/constants.js +5 -0
  36. package/operations/entry/dataLoader/constants.js.map +1 -0
  37. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  38. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  39. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  40. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  41. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  42. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  43. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  44. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  45. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  46. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  47. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  48. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  49. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  50. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  51. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  52. package/operations/entry/dataLoader/index.d.ts +8 -0
  53. package/operations/entry/dataLoader/index.js +18 -0
  54. package/operations/entry/dataLoader/index.js.map +1 -0
  55. package/operations/entry/dataLoader/types.d.ts +6 -0
  56. package/operations/entry/dataLoader/types.js +0 -0
  57. package/operations/entry/dataLoaders.d.ts +14 -30
  58. package/operations/entry/dataLoaders.js +83 -314
  59. package/operations/entry/dataLoaders.js.map +1 -1
  60. package/operations/entry/filtering/createExpressions.d.ts +27 -0
  61. package/operations/entry/filtering/createExpressions.js +124 -0
  62. package/operations/entry/filtering/createExpressions.js.map +1 -0
  63. package/operations/entry/filtering/createFields.d.ts +16 -0
  64. package/operations/entry/filtering/createFields.js +93 -0
  65. package/operations/entry/filtering/createFields.js.map +1 -0
  66. package/operations/entry/filtering/extractSort.d.ts +17 -0
  67. package/operations/entry/filtering/extractSort.js +60 -0
  68. package/operations/entry/filtering/extractSort.js.map +1 -0
  69. package/operations/entry/filtering/filter.d.ts +16 -0
  70. package/operations/entry/filtering/filter.js +85 -0
  71. package/operations/entry/filtering/filter.js.map +1 -0
  72. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  73. package/operations/entry/filtering/fullTextSearch.js +25 -0
  74. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  75. package/operations/entry/filtering/getValue.d.ts +5 -0
  76. package/operations/entry/filtering/getValue.js +37 -0
  77. package/operations/entry/filtering/getValue.js.map +1 -0
  78. package/operations/entry/filtering/index.d.ts +2 -0
  79. package/operations/entry/filtering/index.js +2 -0
  80. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  81. package/operations/entry/filtering/mapPlugins.js +18 -0
  82. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  83. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  84. package/operations/entry/filtering/plugins/defaultFilterCreate.js +33 -0
  85. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  86. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  87. package/operations/entry/filtering/plugins/index.js +13 -0
  88. package/operations/entry/filtering/plugins/index.js.map +1 -0
  89. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  90. package/operations/entry/filtering/plugins/objectFilterCreate.js +68 -0
  91. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  92. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  93. package/operations/entry/filtering/plugins/refFilterCreate.js +63 -0
  94. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  95. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  96. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +49 -0
  97. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  98. package/operations/entry/filtering/sort.d.ts +12 -0
  99. package/operations/entry/filtering/sort.js +41 -0
  100. package/operations/entry/filtering/sort.js.map +1 -0
  101. package/operations/entry/filtering/systemFields.d.ts +2 -0
  102. package/operations/entry/filtering/systemFields.js +149 -0
  103. package/operations/entry/filtering/systemFields.js.map +1 -0
  104. package/operations/entry/filtering/transform.d.ts +6 -0
  105. package/operations/entry/filtering/transform.js +7 -0
  106. package/operations/entry/filtering/transform.js.map +1 -0
  107. package/operations/entry/filtering/types.d.ts +40 -0
  108. package/operations/entry/filtering/types.js +0 -0
  109. package/operations/entry/filtering/values.d.ts +2 -0
  110. package/operations/entry/filtering/values.js +15 -0
  111. package/operations/entry/filtering/values.js.map +1 -0
  112. package/operations/entry/filtering/where.d.ts +5 -0
  113. package/operations/entry/filtering/where.js +22 -0
  114. package/operations/entry/filtering/where.js.map +1 -0
  115. package/operations/entry/index.d.ts +5 -4
  116. package/operations/entry/index.js +931 -845
  117. package/operations/entry/index.js.map +1 -1
  118. package/operations/entry/keys.d.ts +46 -2
  119. package/operations/entry/keys.js +53 -66
  120. package/operations/entry/keys.js.map +1 -1
  121. package/operations/group/index.d.ts +4 -5
  122. package/operations/group/index.js +116 -187
  123. package/operations/group/index.js.map +1 -1
  124. package/operations/model/index.d.ts +3 -3
  125. package/operations/model/index.js +102 -158
  126. package/operations/model/index.js.map +1 -1
  127. package/package.json +34 -33
  128. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +5 -4
  129. package/plugins/CmsEntryFieldFilterPathPlugin.js +25 -50
  130. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  131. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  132. package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
  133. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  134. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  135. package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
  136. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  137. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  138. package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
  139. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  140. package/plugins/index.d.ts +4 -1
  141. package/plugins/index.js +4 -18
  142. package/types.d.ts +28 -21
  143. package/types.js +8 -15
  144. package/types.js.map +1 -1
  145. package/definitions/settings.d.ts +0 -9
  146. package/definitions/settings.js +0 -58
  147. package/definitions/settings.js.map +0 -1
  148. package/definitions/system.d.ts +0 -9
  149. package/definitions/system.js +0 -46
  150. package/definitions/system.js.map +0 -1
  151. package/dynamoDb/storage/date.d.ts +0 -2
  152. package/dynamoDb/storage/date.js +0 -99
  153. package/dynamoDb/storage/date.js.map +0 -1
  154. package/dynamoDb/storage/longText.d.ts +0 -10
  155. package/dynamoDb/storage/longText.js +0 -101
  156. package/dynamoDb/storage/longText.js.map +0 -1
  157. package/dynamoDb/storage/richText.d.ts +0 -2
  158. package/dynamoDb/storage/richText.js +0 -113
  159. package/dynamoDb/storage/richText.js.map +0 -1
  160. package/operations/entry/systemFields.d.ts +0 -2
  161. package/operations/entry/systemFields.js +0 -74
  162. package/operations/entry/systemFields.js.map +0 -1
  163. package/operations/entry/utils.d.ts +0 -36
  164. package/operations/entry/utils.js +0 -680
  165. package/operations/entry/utils.js.map +0 -1
  166. package/operations/settings/index.d.ts +0 -7
  167. package/operations/settings/index.js +0 -135
  168. package/operations/settings/index.js.map +0 -1
  169. package/operations/system/index.d.ts +0 -7
  170. package/operations/system/index.js +0 -99
  171. package/operations/system/index.js.map +0 -1
  172. package/plugins/index.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;EAAV,IAAoBF,MAA1B;EACA,MAAM;IAAEG,MAAF;IAAUC;EAAV,IAAqBF,KAA3B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GIC;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,"file":"operations/entry/dataLoaders.js","sources":["../../../src/operations/entry/dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type {\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader/index.js\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type {\n DataLoadersHandlerInterfaceClearAllParams,\n IDataLoadersHandler,\n IEntryEntity\n} from \"~/types.js\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n}\n\ninterface IDataLoadersHandlerParams {\n entity: IEntryEntity;\n}\n\nexport class DataLoadersHandler implements IDataLoadersHandler {\n private readonly entity;\n private readonly cache = new DataLoaderCache();\n\n public constructor(params: IDataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n return await this.loadMany<T>(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getLatestRevisionByEntryId\", params, ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: DataLoaders, params: GetLoaderParams): DataLoader<any, any> {\n const { model } = params;\n const cacheParams: CacheKeyParams = {\n tenant: model.tenant,\n modelId: model.modelId,\n name\n };\n let loader = this.cache.getDataLoader(cacheParams);\n if (loader) {\n return loader;\n }\n const factory = getDataLoaderFactory(name);\n loader = factory({\n entity: this.entity,\n tenant: model.tenant,\n modelId: model.modelId\n });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany<T extends CmsEntryValues = CmsEntryValues>(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry<T>[]> {\n let results: any[] = [];\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?: DataLoadersHandlerInterfaceClearAllParams): void {\n this.cache.clearAll(params?.model);\n }\n}\n"],"names":["DataLoadersHandler","params","DataLoaderCache","ids","id","entryId","parseIdentifier","name","model","cacheParams","loader","factory","getDataLoaderFactory","results","Array","acc","res","WebinyError","JSON","ex"],"mappings":";;;;AA+BO,MAAMA;IAIT,YAAmBC,MAAiC,CAAE;aAFrC,KAAK,GAAG,IAAIC;QAGzB,IAAI,CAAC,MAAM,GAAGD,OAAO,MAAM;IAC/B;IAEA,MAAa,qBACTA,MAAwB,EACK;QAC7B,MAAME,MAAMF,OAAO,GAAG,CAAC,GAAG,CAACG,CAAAA;YACvB,MAAM,EAAE,IAAIC,OAAO,EAAE,GAAGC,gBAAgBF;YACxC,OAAOC;QACX;QACA,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAI,wBAAwBJ,QAAQE;IAClE;IAEA,MAAa,gBACTF,MAAwB,EACK;QAC7B,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAI,mBAAmBA,QAAQA,OAAO,GAAG;IACvE;IAEA,MAAa,8BACTA,MAAwB,EACK;QAC7B,MAAME,MAAMF,OAAO,GAAG,CAAC,GAAG,CAACG,CAAAA;YACvB,MAAM,EAAE,IAAIC,OAAO,EAAE,GAAGC,gBAAgBF;YACxC,OAAOC;QACX;QACA,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAI,iCAAiCJ,QAAQE;IAC3E;IAEA,MAAa,2BACTF,MAAwB,EACK;QAC7B,MAAME,MAAMF,OAAO,GAAG,CAAC,GAAG,CAACG,CAAAA;YACvB,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,IAAI;YACT,MAAM,IAAIF,MACNE,GAAG,OAAO,IAAI,sBACdA,GAAG,IAAI,IAAI,qBACX;gBACI,OAAOA;gBACP,GAAGlB,MAAM;gBACTS;gBACAP;YACJ;QAER;QACA,MAAM,IAAIc,MACN,6DACA,8BACA;YACIP;YACAP;YACAU;QACJ;IAER;IAEO,SAASZ,MAAkD,EAAQ;QACtE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAACA,QAAQ;IAChC;AACJ"}
@@ -0,0 +1,27 @@
1
+ import type { CmsContext, CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { Field } from "./types.js";
4
+ import { ValueFilter } from "@webiny/db-dynamodb/feature/ValueFilter/index.js";
5
+ interface ICreateExpressionsParams {
6
+ plugins: PluginsContainer;
7
+ container: CmsContext["container"];
8
+ where: Partial<CmsEntryListWhere>;
9
+ fields: Record<string, Field>;
10
+ }
11
+ export type ExpressionCondition = "AND" | "OR";
12
+ export interface Expression {
13
+ expressions: Expression[];
14
+ filters: Filter[];
15
+ condition: ExpressionCondition;
16
+ }
17
+ export interface Filter {
18
+ field: Field;
19
+ path: string;
20
+ fieldPathId: string;
21
+ filter: ValueFilter.Interface;
22
+ negate: boolean;
23
+ compareValue: any;
24
+ transformValue: <I = any, O = any>(value: I) => O;
25
+ }
26
+ export declare const createExpressions: (params: ICreateExpressionsParams) => Expression;
27
+ export {};
@@ -0,0 +1,124 @@
1
+ import error from "@webiny/error";
2
+ import { getMappedPlugins } from "./mapPlugins.js";
3
+ import { extractWhereParams } from "./where.js";
4
+ import { transformValue } from "./transform.js";
5
+ import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
6
+ import { getWhereValues } from "./values.js";
7
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
8
+ import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
9
+ const createExpressions = (params)=>{
10
+ const { where, plugins, fields, container } = params;
11
+ const valueFilterRegistry = container.resolve(ValueFilterRegistry);
12
+ const transformValuePlugins = getMappedPlugins({
13
+ plugins,
14
+ type: "cms-field-filter-value-transform",
15
+ property: "fieldType"
16
+ });
17
+ const fieldFilterCreatePlugins = getMappedPlugins({
18
+ plugins,
19
+ type: CmsEntryFieldFilterPlugin.type,
20
+ property: "fieldType"
21
+ });
22
+ const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
23
+ const getFilterCreatePlugin = (type)=>{
24
+ const fieldType = getBaseFieldType({
25
+ type
26
+ });
27
+ const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
28
+ if (filterCreatePlugin) return filterCreatePlugin;
29
+ throw new error(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
30
+ fieldType
31
+ });
32
+ };
33
+ const createExpression = ({ where, condition })=>{
34
+ const expression = {
35
+ filters: [],
36
+ expressions: [],
37
+ condition
38
+ };
39
+ for(const key in where){
40
+ const value = where[key];
41
+ if (void 0 === value) continue;
42
+ if ("AND" === key) {
43
+ const childWhereList = getWhereValues(value, key);
44
+ const childExpression = {
45
+ condition: "AND",
46
+ filters: [],
47
+ expressions: []
48
+ };
49
+ for (const childWhere of childWhereList){
50
+ const result = createExpression({
51
+ where: childWhere,
52
+ condition: "AND"
53
+ });
54
+ childExpression.expressions.push(result);
55
+ }
56
+ expression.expressions.push(childExpression);
57
+ continue;
58
+ }
59
+ if ("OR" === key) {
60
+ const childWhereList = getWhereValues(value, key);
61
+ const childExpression = {
62
+ condition: "OR",
63
+ filters: [],
64
+ expressions: []
65
+ };
66
+ for (const childWhere of childWhereList){
67
+ const result = createExpression({
68
+ where: childWhere,
69
+ condition: "AND"
70
+ });
71
+ childExpression.expressions.push(result);
72
+ }
73
+ expression.expressions.push(childExpression);
74
+ continue;
75
+ }
76
+ const whereParams = extractWhereParams(key);
77
+ if (!whereParams) continue;
78
+ const { fieldId, operation, negate } = whereParams;
79
+ const field = fields[fieldId];
80
+ if (!field) throw new error(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
81
+ fieldId
82
+ });
83
+ const filterCreatePlugin = getFilterCreatePlugin(field.type);
84
+ const fieldType = getBaseFieldType(field);
85
+ const transformValuePlugin = transformValuePlugins[fieldType];
86
+ const transformValueCallable = (value)=>{
87
+ if (!transformValuePlugin) return value;
88
+ return transformValuePlugin.transform({
89
+ field,
90
+ value
91
+ });
92
+ };
93
+ const result = filterCreatePlugin.create({
94
+ key,
95
+ value,
96
+ valueFilterRegistry,
97
+ transformValuePlugins,
98
+ getFilterCreatePlugin,
99
+ operation,
100
+ negate,
101
+ field,
102
+ fields,
103
+ compareValue: transformValue({
104
+ value,
105
+ transform: transformValueCallable
106
+ }),
107
+ transformValue: transformValueCallable
108
+ });
109
+ if (!(!result || Array.isArray(result) && 0 === result.length)) expression.filters.push(...Array.isArray(result) ? result : [
110
+ result
111
+ ]);
112
+ }
113
+ return expression;
114
+ };
115
+ const expression = createExpression({
116
+ where,
117
+ condition: "AND"
118
+ });
119
+ if (expression.filters.length > 0 || 1 !== expression.expressions.length) return expression;
120
+ return expression.expressions[0];
121
+ };
122
+ export { createExpressions };
123
+
124
+ //# sourceMappingURL=createExpressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/filtering/createExpressions.js","sources":["../../../../src/operations/entry/filtering/createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsContext, CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/feature/ValueFilter/index.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface ICreateExpressionsParams {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\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 filter: ValueFilter.Interface;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: ICreateExpressionsParams): Expression => {\n const { where, plugins, fields, container } = params;\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\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 fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\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 fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\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 valueFilterRegistry,\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"],"names":["createExpressions","params","where","plugins","fields","container","valueFilterRegistry","ValueFilterRegistry","transformValuePlugins","getMappedPlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","type","fieldType","getBaseFieldType","filterCreatePlugin","WebinyError","createExpression","condition","expression","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transformValue","Array"],"mappings":";;;;;;;;AA4CO,MAAMA,oBAAoB,CAACC;IAC9B,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;IAC9C,MAAMK,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,wBAAwBC,iBAAqD;QAC/EN;QACA,MAAM;QACN,UAAU;IACd;IACA,MAAMO,2BAA2BD,iBAA4C;QACzEN;QACA,MAAMQ,0BAA0B,IAAI;QACpC,UAAU;IACd;IAEA,MAAMC,4BAA4BF,wBAAwB,CAAC,IAAI;IAE/D,MAAMG,wBAAwB,CAACC;QAC3B,MAAMC,YAAYC,iBAAiB;YAC/BF;QACJ;QACA,MAAMG,qBAAqBP,wBAAwB,CAACK,UAAU,IAAIH;QAClE,IAAIK,oBACA,OAAOA;QAEX,MAAM,IAAIC,MACN,CAAC,qDAAqD,EAAEH,UAAU,EAAE,CAAC,EACrE,gCACA;YACIA;QACJ;IAER;IAEA,MAAMI,mBAAmB,CAAC,EAAEjB,KAAK,EAAEkB,SAAS,EAA0B;QAClE,MAAMC,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,qBAAqB,CAACO,UAAU;YAEpC,MAAMsB,yBAAyB,CAACd;gBAC5B,IAAI,CAACa,sBACD,OAAOb;gBAEX,OAAOa,qBAAqB,SAAS,CAAC;oBAClCD;oBACAZ;gBACJ;YACJ;YAEA,MAAMM,SAASZ,mBAAmB,MAAM,CAAC;gBACrCK;gBACAC;gBACAjB;gBACAE;gBACAK;gBACAoB;gBACAC;gBACAC;gBACA/B;gBACA,cAAckC,eAAe;oBACzBf;oBACA,WAAWc;gBACf;gBACA,gBAAgBA;YACpB;YAOA,KAAI,EAACR,UAAWU,MAAM,OAAO,CAACV,WAAWA,AAAkB,MAAlBA,OAAO,MAAM,AAAK,GAI3DR,WAAW,OAAO,CAAC,IAAI,IAAKkB,MAAM,OAAO,CAACV,UAAUA,SAAS;gBAACA;aAAO;QACzE;QAEA,OAAOR;IACX;IAEA,MAAMA,aAAaF,iBAAiB;QAChCjB;QACA,WAAW;IACf;IAKA,IAAImB,WAAW,OAAO,CAAC,MAAM,GAAG,KAAKA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,EAC9D,OAAOA;IAEX,OAAOA,WAAW,WAAW,CAAC,EAAE;AACpC"}
@@ -0,0 +1,16 @@
1
+ import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { Field } from "./types.js";
3
+ import type { 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) => {
14
+ [x: string]: Field;
15
+ };
16
+ export {};
@@ -0,0 +1,93 @@
1
+ import { createSystemFields } from "./systemFields.js";
2
+ import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
3
+ import { getMappedPlugins } from "./mapPlugins.js";
4
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
+ const createFieldCollection = (params)=>{
6
+ const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;
7
+ return fields.reduce((collection, field)=>{
8
+ const fieldType = getBaseFieldType(field);
9
+ const transformPlugin = transformValuePlugins[fieldType];
10
+ const valuePathPlugin = valuePathPlugins[fieldType];
11
+ const fieldId = [
12
+ ...parents,
13
+ {
14
+ fieldId: field.fieldId,
15
+ list: field.list
16
+ }
17
+ ].map((f)=>f.fieldId).join(".");
18
+ collection[fieldId] = {
19
+ ...field,
20
+ parents,
21
+ system,
22
+ createPath: (params)=>{
23
+ if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map((p)=>p.fieldId))) return valuePathPlugin.createPath(params);
24
+ return parents.map((parent)=>parent.fieldId).concat([
25
+ params.field.fieldId
26
+ ]).join(".");
27
+ },
28
+ transform: (value)=>{
29
+ if (!transformPlugin) return value;
30
+ return transformPlugin.transform({
31
+ field,
32
+ value
33
+ });
34
+ }
35
+ };
36
+ const childFields = field.settings?.fields;
37
+ if (!childFields?.length) return collection;
38
+ const result = createFieldCollection({
39
+ fields: childFields,
40
+ parents: [
41
+ ...parents,
42
+ {
43
+ fieldId: field.fieldId,
44
+ list: field.list
45
+ }
46
+ ],
47
+ transformValuePlugins,
48
+ valuePathPlugins,
49
+ system
50
+ });
51
+ Object.assign(collection, result);
52
+ return collection;
53
+ }, {});
54
+ };
55
+ const createFields = (params)=>{
56
+ const { fields, plugins } = params;
57
+ const transformValuePlugins = getMappedPlugins({
58
+ plugins,
59
+ type: "cms-field-filter-value-transform",
60
+ property: "fieldType"
61
+ });
62
+ const valuePathPlugins = getMappedPlugins({
63
+ plugins,
64
+ type: CmsEntryFieldFilterPathPlugin.type,
65
+ property: "fieldType"
66
+ });
67
+ const collection = createFieldCollection({
68
+ fields: createSystemFields(),
69
+ transformValuePlugins,
70
+ valuePathPlugins,
71
+ parents: [],
72
+ system: true
73
+ });
74
+ const result = createFieldCollection({
75
+ fields,
76
+ transformValuePlugins,
77
+ valuePathPlugins,
78
+ parents: [
79
+ {
80
+ fieldId: "values",
81
+ list: false
82
+ }
83
+ ],
84
+ system: false
85
+ });
86
+ return {
87
+ ...collection,
88
+ ...result
89
+ };
90
+ };
91
+ export { createFields };
92
+
93
+ //# sourceMappingURL=createFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/filtering/createFields.js","sources":["../../../../src/operations/entry/filtering/createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\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 list: field.list\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return parents\n .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?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\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 = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [\n {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"names":["createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","collection","field","fieldType","getBaseFieldType","transformPlugin","valuePathPlugin","fieldId","f","p","parent","value","childFields","result","Object","createFields","plugins","getMappedPlugins","CmsEntryFieldFilterPathPlugin","createSystemFields"],"mappings":";;;;AA0BA,MAAMA,wBAAwB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,qBAAqB,EAAEC,gBAAgB,EAAEC,MAA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A,MAAM;QACN,UAAU;IACd;IACA,MAAMjB,mBAAmBkB,iBAAgD;QACrED;QACA,MAAME,8BAA8B,IAAI;QACxC,UAAU;IACd;IAEA,MAAMjB,aAAaP,sBAAsB;QACrC,QAAQyB;QACRrB;QACAC;QACA,SAAS,EAAE;QACX,QAAQ;IACZ;IAEA,MAAMc,SAASnB,sBAAsB;QACjCE;QACAE;QACAC;QACA,SAAS;YACL;gBACI,SAAS;gBACT,MAAM;YACV;SACH;QACD,QAAQ;IACZ;IAEA,OAAO;QACH,GAAGE,UAAU;QACb,GAAGY,MAAM;IACb;AACJ"}
@@ -0,0 +1,17 @@
1
+ import type { Field } from "./types.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
4
+ interface IResponse {
5
+ valuePath: string;
6
+ reverse: boolean;
7
+ fieldId: string;
8
+ field: Field;
9
+ }
10
+ interface IParams {
11
+ model: CmsModel;
12
+ sortBy: string;
13
+ fields: Record<string, Field>;
14
+ plugins: PluginsContainer;
15
+ }
16
+ export declare const extractSort: (params: IParams) => IResponse;
17
+ export {};
@@ -0,0 +1,60 @@
1
+ import error from "@webiny/error";
2
+ import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
3
+ const extractSortInfo = (sortBy)=>{
4
+ const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
5
+ if (rootSorting) return {
6
+ fieldId: rootSorting[1],
7
+ isValues: false,
8
+ order: rootSorting[2]
9
+ };
10
+ const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
11
+ if (valuesSorting) return {
12
+ fieldId: valuesSorting[1],
13
+ isValues: true,
14
+ order: valuesSorting[2]
15
+ };
16
+ throw new error("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
17
+ sortBy
18
+ });
19
+ };
20
+ const extractSort = (params)=>{
21
+ const { model, sortBy, fields, plugins } = params;
22
+ const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);
23
+ const field = Object.values(fields).find((f)=>{
24
+ const isValues = f.parents[0]?.fieldId === "values";
25
+ if (isValues && isValuesSorting) return f.fieldId === fieldId;
26
+ if (f.parents.length > 0) return false;
27
+ return f.fieldId === fieldId;
28
+ });
29
+ const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find((plugin)=>plugin.canUse({
30
+ model,
31
+ field,
32
+ fieldId,
33
+ order,
34
+ sortBy
35
+ }));
36
+ if (plugin) return plugin.createSort({
37
+ model,
38
+ fieldId,
39
+ order,
40
+ sortBy,
41
+ field,
42
+ fields
43
+ });
44
+ if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
45
+ fieldId,
46
+ fields
47
+ });
48
+ const valuePath = field.createPath({
49
+ field
50
+ });
51
+ return {
52
+ field,
53
+ fieldId,
54
+ valuePath,
55
+ reverse: "DESC" === order
56
+ };
57
+ };
58
+ export { extractSort };
59
+
60
+ //# sourceMappingURL=extractSort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/filtering/extractSort.js","sources":["../../../../src/operations/entry/filtering/extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\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\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else 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"],"names":["extractSortInfo","sortBy","rootSorting","valuesSorting","WebinyError","extractSort","params","model","fields","plugins","fieldId","isValuesSorting","order","field","Object","f","isValues","plugin","CmsEntryFieldSortingPlugin","valuePath"],"mappings":";;AAMA,MAAMA,kBAAkB,CAACC;IACrB,MAAMC,cAAcD,OAAO,KAAK,CAAC;IACjC,IAAIC,aACA,OAAO;QACH,SAASA,WAAW,CAAC,EAAE;QACvB,UAAU;QACV,OAAOA,WAAW,CAAC,EAAE;IACzB;IAEJ,MAAMC,gBAAgBF,OAAO,KAAK,CAAC;IACnC,IAAIE,eACA,OAAO;QACH,SAASA,aAAa,CAAC,EAAE;QACzB,UAAU;QACV,OAAOA,aAAa,CAAC,EAAE;IAC3B;IAEJ,MAAM,IAAIC,MACN,2DACA,sBACA;QACIH;IACJ;AAER;AAgBO,MAAMI,cAAc,CAACC;IACxB,MAAM,EAAEC,KAAK,EAAEN,MAAM,EAAEO,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAC3C,MAAM,EAAEI,OAAO,EAAE,UAAUC,eAAe,EAAEC,KAAK,EAAE,GAAGZ,gBAAgBC;IAEtE,MAAMY,QAAQC,OAAO,MAAM,CAACN,QAAQ,IAAI,CAACO,CAAAA;QAIrC,MAAMC,WAAWD,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY;QAC3C,IAAIC,YAAYL,iBACZ,OAAOI,EAAE,OAAO,KAAKL;QAEzB,IAAIK,EAAE,OAAO,CAAC,MAAM,GAAG,GACnB,OAAO;QAEX,OAAOA,EAAE,OAAO,KAAKL;IACzB;IAEA,MAAMO,SAASR,QACV,MAAM,CAA6BS,2BAA2B,IAAI,EAClE,OAAO,GACP,IAAI,CAACD,CAAAA,SACKA,OAAO,MAAM,CAAC;YACjBV;YACAM;YACAH;YACAE;YACAX;QACJ;IAGR,IAAIgB,QACA,OAAOA,OAAO,UAAU,CAAC;QACrBV;QACAG;QACAE;QACAX;QACAY;QACAL;IACJ;IACG,IAAI,CAACK,OACR,MAAM,IAAIT,MACN,sDACA,uBACA;QACIM;QACAF;IACJ;IAGR,MAAMW,YAAYN,MAAM,UAAU,CAAC;QAC/BA;IACJ;IACA,OAAO;QACHA;QACAH;QACAS;QACA,SAASP,AAAU,WAAVA;IACb;AACJ"}
@@ -0,0 +1,16 @@
1
+ import type { CmsContext, CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { Field } from "./types.js";
4
+ interface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {
5
+ plugins: PluginsContainer;
6
+ container: CmsContext["container"];
7
+ items: CmsEntry<T>[];
8
+ where: Partial<CmsEntryListWhere>;
9
+ fields: Record<string, Field>;
10
+ fullTextSearch?: {
11
+ term?: string;
12
+ fields?: string[];
13
+ };
14
+ }
15
+ export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: IFilterParams<T>) => CmsEntry<T>[];
16
+ export {};
@@ -0,0 +1,85 @@
1
+ import error from "@webiny/error";
2
+ import { createFullTextSearch } from "./fullTextSearch.js";
3
+ import { createExpressions } from "./createExpressions.js";
4
+ import { transformValue } from "./transform.js";
5
+ import { getValue } from "./getValue.js";
6
+ import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
7
+ const executeFilter = (params)=>{
8
+ const { value, filter } = params;
9
+ const canUse = filter.filter.canUse({
10
+ value,
11
+ compareValue: filter.compareValue
12
+ });
13
+ if (!canUse) return true;
14
+ const matched = filter.filter.matches({
15
+ value,
16
+ compareValue: filter.compareValue
17
+ });
18
+ if (filter.negate) return false === matched;
19
+ return matched;
20
+ };
21
+ const executeExpressions = (params)=>{
22
+ const { expressions, getCachedValue, filters, condition } = params;
23
+ if (0 === expressions.length && 0 === filters.length) return true;
24
+ for (const filter of filters){
25
+ const value = getCachedValue(filter);
26
+ const result = executeFilter({
27
+ value,
28
+ filter
29
+ });
30
+ if (!result) return false;
31
+ }
32
+ for (const expression of expressions){
33
+ const result = executeExpressions({
34
+ ...expression,
35
+ getCachedValue
36
+ });
37
+ if (result && "OR" === condition) return true;
38
+ if (!result && "AND" == condition) return false;
39
+ }
40
+ return "OR" !== condition;
41
+ };
42
+ const filter_filter = (params)=>{
43
+ const { items: records, where, plugins, fields, fullTextSearch, container } = params;
44
+ const valueFilterRegistry = container.resolve(ValueFilterRegistry);
45
+ const keys = Object.keys(where);
46
+ if (0 === keys.length && !fullTextSearch) return records;
47
+ const expression = createExpressions({
48
+ plugins,
49
+ where,
50
+ fields,
51
+ container
52
+ });
53
+ if (0 === expression.filters.length && 0 === expression.expressions.length && !fullTextSearch?.term) return records;
54
+ const fullTextSearchFilter = valueFilterRegistry.get("contains");
55
+ if (!fullTextSearchFilter) throw new error('Missing "contains" plugin to run the full-text search.', "MISSING_PLUGIN");
56
+ const search = createFullTextSearch({
57
+ term: fullTextSearch?.term,
58
+ targetFields: fullTextSearch?.fields,
59
+ fields,
60
+ filter: fullTextSearchFilter
61
+ });
62
+ return records.filter((record)=>{
63
+ const cachedValues = {};
64
+ const getCachedValue = (filter)=>{
65
+ const { path } = filter;
66
+ if (void 0 !== cachedValues[path]) return cachedValues[path];
67
+ const plainValue = getValue(record, path);
68
+ const rawValue = transformValue({
69
+ value: plainValue,
70
+ transform: filter.transformValue
71
+ });
72
+ cachedValues[path] = rawValue;
73
+ return rawValue;
74
+ };
75
+ const exprResult = executeExpressions({
76
+ ...expression,
77
+ getCachedValue
78
+ });
79
+ if (!exprResult || !search) return exprResult;
80
+ return search(record);
81
+ });
82
+ };
83
+ export { filter_filter as filter };
84
+
85
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
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,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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"}
@@ -0,0 +1,14 @@
1
+ import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { Field } from "./types.js";
3
+ import { ValueFilter } from "@webiny/db-dynamodb/exports/api/db.js";
4
+ interface Params {
5
+ term?: string;
6
+ targetFields?: string[];
7
+ fields: Record<string, Field>;
8
+ filter: ValueFilter.Interface;
9
+ }
10
+ /**
11
+ * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
12
+ */
13
+ export declare const createFullTextSearch: (params: Params) => ((item: CmsEntry) => boolean) | null;
14
+ export {};
@@ -0,0 +1,25 @@
1
+ import error from "@webiny/error";
2
+ import { getValue } from "./getValue.js";
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
+ };
22
+ };
23
+ export { createFullTextSearch };
24
+
25
+ //# sourceMappingURL=fullTextSearch.js.map
@@ -0,0 +1 @@
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"}