@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.97a151f74d
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.
- package/definitions/model.js +5 -0
- package/definitions/model.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +13 -3
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/index.js +11 -4
- package/index.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +18 -0
- package/operations/entry/filtering/createFields.js +124 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/createFilters.d.ts +20 -0
- package/operations/entry/filtering/createFilters.js +155 -0
- package/operations/entry/filtering/createFilters.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +13 -0
- package/operations/entry/filtering/extractSort.js +55 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +16 -0
- package/operations/entry/filtering/filter.js +137 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +18 -0
- package/operations/entry/filtering/fullTextSearch.js +64 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +81 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +21 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +39 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +18 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +9 -0
- package/operations/entry/filtering/sort.js +80 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +72 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +19 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +38 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.js +10 -8
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/utils.js +7 -3
- package/operations/entry/utils.js.map +1 -1
- package/package.json +10 -10
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createType","createLatestType","createPublishedType","convertToStorageEntry","params","model","storageEntry","values","convertValueKeyToStorage","fields","convertFromStorageEntry","convertValueKeyFromStorage","createEntriesStorageOperations","entity","plugins","dataLoaders","DataLoadersHandler","storageTransformPlugins","byType","StorageTransformPlugin","type","reduce","collection","plugin","fieldType","createStorageTransformCallable","field","value","fromStorage","getStoragePlugin","create","entry","initialStorageEntry","partitionKey","createPartitionKey","id","locale","tenant","isPublished","status","locked","items","putBatch","PK","SK","createRevisionSortKey","TYPE","GSI1_PK","createGSIPartitionKey","GSI1_SK","createGSISortKey","createLatestSortKey","push","createPublishedSortKey","batchWriteAll","table","clearAll","ex","WebinyError","message","code","error","createRevisionFrom","update","latestStorageEntry","getLatestRevisionByEntryId","deleteEntry","queryAllParams","options","gte","records","queryAll","map","item","deleteBatch","deleteRevision","latestEntry","initialLatestStorageEntry","publishedStorageEntry","getPublishedRevisionByEntryId","ids","shift","getRevisionById","getRevisions","getAllEntryRevisions","getByIds","getLatestByIds","getPublishedByIds","getPreviousRevision","entryId","version","queryParams","lt","zeroPad","filters","attr","eq","reverse","result","queryOne","cleanupItem","list","limit","initialLimit","where","initialWhere","after","sort","search","published","index","length","hasMoreItems","totalCount","cursor","modelFields","buildModelFields","filteredItems","filterItems","record","fullTextSearch","term","sortedItems","sortEntryItems","start","parseInt","decodeCursor","end","undefined","slicedItems","slice","encodeCursor","cleanupItems","get","publish","initialPublishedStorageEntry","CONTENT_ENTRY_STATUS","UNPUBLISHED","unpublish","delete"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DataLoadersHandler } from \"./dataLoaders\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryStorageOperations,\n CmsEntryStorageOperationsCreateParams,\n CmsEntryStorageOperationsCreateRevisionFromParams,\n CmsEntryStorageOperationsDeleteParams,\n CmsEntryStorageOperationsDeleteRevisionParams,\n CmsEntryStorageOperationsGetByIdsParams,\n CmsEntryStorageOperationsGetLatestByIdsParams,\n CmsEntryStorageOperationsGetLatestRevisionParams,\n CmsEntryStorageOperationsGetParams,\n CmsEntryStorageOperationsGetPreviousRevisionParams,\n CmsEntryStorageOperationsGetPublishedByIdsParams,\n CmsEntryStorageOperationsGetRevisionParams,\n CmsEntryStorageOperationsGetRevisionsParams,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsPublishParams,\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryStorageOperationsUpdateParams,\n StorageOperationsCmsModel,\n CONTENT_ENTRY_STATUS,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { filterItems, buildModelFields, sortEntryItems, FilterItemFromStorage } from \"./utils\";\nimport {\n createGSIPartitionKey,\n createGSISortKey,\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"~/operations/entry/keys\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport {\n queryAll,\n QueryAllParams,\n queryOne,\n QueryOneParams\n} from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { decodeCursor, encodeCursor } from \"@webiny/utils/cursor\";\nimport { zeroPad } from \"@webiny/utils/zeroPad\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\n\nconst createType = (): string => {\n return \"cms.entry\";\n};\nconst createLatestType = (): string => {\n return `${createType()}.l`;\n};\nconst createPublishedType = (): string => {\n return `${createType()}.p`;\n};\n\ninterface ConvertStorageEntryParams {\n storageEntry: CmsStorageEntry;\n model: StorageOperationsCmsModel;\n}\nconst convertToStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyToStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nconst convertFromStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyFromStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nexport interface CreateEntriesStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createEntriesStorageOperations = (\n params: CreateEntriesStorageOperationsParams\n): CmsEntryStorageOperations => {\n const { entity, plugins } = params;\n\n const dataLoaders = new DataLoadersHandler({\n entity\n });\n\n const storageTransformPlugins = plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n .reduce((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n const createStorageTransformCallable = (\n model: StorageOperationsCmsModel\n ): FilterItemFromStorage => {\n return (field, value) => {\n const plugin: StorageTransformPlugin = storageTransformPlugins[field.type];\n if (!plugin) {\n return value;\n }\n return plugin.fromStorage({\n model,\n field,\n value,\n getStoragePlugin(fieldType: string): StorageTransformPlugin {\n return storageTransformPlugins[fieldType] || storageTransformPlugins[\"*\"];\n },\n plugins\n });\n };\n };\n\n const create = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - create new main entry item\n * - create new or update latest entry item\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n\n /**\n * We need to create published entry if\n */\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert data into the DynamoDB.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n\n return initialStorageEntry;\n };\n\n const createRevisionFrom = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateRevisionFromParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - create the main entry item\n * - update the last entry item to a current one\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create revision from given entry.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n /**\n * There are no modifications on the entry created so just return the data.\n */\n return initialStorageEntry;\n };\n\n const update = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUpdateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const items = [];\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n /**\n * We need the latest entry to update it as well if neccessary.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n };\n\n const deleteEntry = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteParams\n ) => {\n const { entry } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n };\n\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all records.\",\n ex.code || \"LOAD_ALL_RECORDS_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n const items = records.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the entry.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n entry\n }\n );\n }\n };\n\n const deleteRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteRevisionParams\n ) => {\n const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n })\n ];\n\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n /**\n * If revision we are deleting is the published one as well, we need to delete those records as well.\n */\n if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n if (initialLatestStorageEntry) {\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...latestStorageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(latestStorageEntry)\n })\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n };\n\n const getLatestRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n const getPublishedRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisionById = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisions = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) => {\n const items = await dataLoaders.getAllEntryRevisions({\n model,\n ids: [params.id]\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetByIdsParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getLatestByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestByIdsParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPublishedByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPublishedByIdsParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPreviousRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) => {\n const { entryId, version } = params;\n const queryParams: QueryOneParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant: model.tenant,\n locale: model.locale,\n id: entryId\n }),\n options: {\n lt: `REV#${zeroPad(version)}`,\n /**\n * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.\n */\n filters: [\n {\n attr: \"TYPE\",\n eq: createType()\n },\n {\n attr: \"version\",\n lt: version\n }\n ],\n reverse: true\n }\n };\n\n try {\n const result = await queryOne<CmsEntry>(queryParams);\n\n const storageEntry = cleanupItem(entity, result);\n if (!storageEntry) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry,\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey: queryParams.partitionKey,\n options: queryParams.options,\n model\n }\n );\n }\n };\n\n const list = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsListParams\n ) => {\n const {\n limit: initialLimit = 10,\n where: initialWhere,\n after,\n sort,\n fields,\n search\n } = params;\n const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;\n\n const type = initialWhere.published ? \"P\" : \"L\";\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createGSIPartitionKey(model, type),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(ex.message, \"QUERY_ENTRIES_ERROR\", {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n });\n }\n if (records.length === 0) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n delete where[\"published\"];\n delete where[\"latest\"];\n /**\n * We need a object containing field, transformers and paths.\n * Just build it here and pass on into other methods that require it to avoid mapping multiple times.\n */\n const modelFields = buildModelFields({\n plugins,\n model\n });\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = await filterItems({\n items: records.map(record => {\n return convertFromStorageEntry({\n storageEntry: record,\n model\n });\n }),\n where,\n plugins,\n fields: modelFields,\n fromStorage: createStorageTransformCallable(model),\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const totalCount = filteredItems.length;\n\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedItems = sortEntryItems({\n items: filteredItems,\n sort,\n fields: modelFields\n });\n\n const start = parseInt((decodeCursor(after) as string) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const slicedItems = sortedItems.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = totalCount > start + limit ? encodeCursor(`${start + limit}`) : null;\n return {\n hasMoreItems,\n totalCount,\n cursor,\n items: cleanupItems(entity, slicedItems)\n };\n };\n\n const get = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetParams\n ) => {\n const { items } = await list(model, {\n ...params,\n limit: 1\n });\n return items.shift() || null;\n };\n\n const publish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsPublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n /**\n * We need the latest and published entries to see if something needs to be updated along side the publishing one.\n */\n const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to update:\n * - current entry revision sort key\n * - published sort key\n * - latest sort key - if entry updated is actually latest\n * - previous published entry to unpublished status - if any previously published entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {\n const publishedStorageEntry = convertToStorageEntry({\n storageEntry: initialPublishedStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...publishedStorageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(publishedStorageEntry),\n TYPE: createType(),\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED,\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(publishedStorageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the publishing batch.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n entry,\n latestStorageEntry: initialLatestStorageEntry,\n publishedStorageEntry: initialPublishedStorageEntry\n }\n );\n }\n };\n\n const unpublish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUnpublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update latest entry status - if entry being unpublished is latest\n */\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the unpublishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute unpublish batch.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n return {\n create,\n createRevisionFrom,\n update,\n delete: deleteEntry,\n deleteRevision,\n getPreviousRevision,\n getPublishedByIds,\n getLatestByIds,\n getByIds,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId,\n get,\n getRevisions,\n publ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qC;EAjBG,CAAP;AAmBH,CAx3BM"}
|
|
1
|
+
{"version":3,"names":["createType","createLatestType","createPublishedType","convertToStorageEntry","params","model","storageEntry","values","convertValueKeyToStorage","fields","convertFromStorageEntry","convertValueKeyFromStorage","createEntriesStorageOperations","entity","plugins","dataLoaders","DataLoadersHandler","storageTransformPlugins","byType","StorageTransformPlugin","type","reduce","collection","plugin","fieldType","createStorageTransformCallable","field","value","fromStorage","getStoragePlugin","create","entry","initialStorageEntry","partitionKey","createPartitionKey","id","locale","tenant","isPublished","status","locked","items","putBatch","PK","SK","createRevisionSortKey","TYPE","GSI1_PK","createGSIPartitionKey","GSI1_SK","createGSISortKey","createLatestSortKey","push","createPublishedSortKey","batchWriteAll","table","clearAll","ex","WebinyError","message","code","error","createRevisionFrom","update","latestStorageEntry","getLatestRevisionByEntryId","deleteEntry","queryAllParams","options","gte","records","queryAll","map","item","deleteBatch","deleteRevision","latestEntry","initialLatestStorageEntry","publishedStorageEntry","getPublishedRevisionByEntryId","ids","shift","getRevisionById","getRevisions","getAllEntryRevisions","getByIds","getLatestByIds","getPublishedByIds","getPreviousRevision","entryId","version","queryParams","lt","zeroPad","filters","attr","eq","reverse","result","queryOne","cleanupItem","list","limit","initialLimit","where","initialWhere","after","sort","sortBy","search","published","index","length","hasMoreItems","totalCount","cursor","modelFields","createFields","filteredItems","filter","record","fullTextSearch","term","sortedItems","start","parseInt","decodeCursor","end","undefined","slicedItems","slice","encodeCursor","cleanupItems","get","publish","initialPublishedStorageEntry","CONTENT_ENTRY_STATUS","UNPUBLISHED","unpublish","delete"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DataLoadersHandler } from \"./dataLoaders\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryStorageOperations,\n CmsEntryStorageOperationsCreateParams,\n CmsEntryStorageOperationsCreateRevisionFromParams,\n CmsEntryStorageOperationsDeleteParams,\n CmsEntryStorageOperationsDeleteRevisionParams,\n CmsEntryStorageOperationsGetByIdsParams,\n CmsEntryStorageOperationsGetLatestByIdsParams,\n CmsEntryStorageOperationsGetLatestRevisionParams,\n CmsEntryStorageOperationsGetParams,\n CmsEntryStorageOperationsGetPreviousRevisionParams,\n CmsEntryStorageOperationsGetPublishedByIdsParams,\n CmsEntryStorageOperationsGetRevisionParams,\n CmsEntryStorageOperationsGetRevisionsParams,\n CmsEntryStorageOperationsListParams,\n CmsEntryStorageOperationsPublishParams,\n CmsEntryStorageOperationsUnpublishParams,\n CmsEntryStorageOperationsUpdateParams,\n StorageOperationsCmsModel,\n CONTENT_ENTRY_STATUS,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport {\n createGSIPartitionKey,\n createGSISortKey,\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"~/operations/entry/keys\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport {\n queryAll,\n QueryAllParams,\n queryOne,\n QueryOneParams\n} from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { decodeCursor, encodeCursor } from \"@webiny/utils/cursor\";\nimport { zeroPad } from \"@webiny/utils/zeroPad\";\nimport { StorageTransformPlugin } from \"@webiny/api-headless-cms\";\nimport { FilterItemFromStorage } from \"./filtering/types\";\nimport { createFields } from \"~/operations/entry/filtering/createFields\";\nimport { filter, sort } from \"~/operations/entry/filtering\";\n\nconst createType = (): string => {\n return \"cms.entry\";\n};\nconst createLatestType = (): string => {\n return `${createType()}.l`;\n};\nconst createPublishedType = (): string => {\n return `${createType()}.p`;\n};\n\ninterface ConvertStorageEntryParams {\n storageEntry: CmsStorageEntry;\n model: StorageOperationsCmsModel;\n}\nconst convertToStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyToStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nconst convertFromStorageEntry = (params: ConvertStorageEntryParams): CmsStorageEntry => {\n const { model, storageEntry } = params;\n\n const values = model.convertValueKeyFromStorage({\n fields: model.fields,\n values: storageEntry.values\n });\n return {\n ...storageEntry,\n values\n };\n};\n\nexport interface CreateEntriesStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createEntriesStorageOperations = (\n params: CreateEntriesStorageOperationsParams\n): CmsEntryStorageOperations => {\n const { entity, plugins } = params;\n\n const dataLoaders = new DataLoadersHandler({\n entity\n });\n\n const storageTransformPlugins = plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n .reduce((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n const createStorageTransformCallable = (\n model: StorageOperationsCmsModel\n ): FilterItemFromStorage => {\n return (field, value) => {\n const plugin: StorageTransformPlugin = storageTransformPlugins[field.type];\n if (!plugin) {\n return value;\n }\n return plugin.fromStorage({\n model,\n field,\n value,\n getStoragePlugin(fieldType: string): StorageTransformPlugin {\n return storageTransformPlugins[fieldType] || storageTransformPlugins[\"*\"];\n },\n plugins\n });\n };\n };\n\n const create = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n\n const locked = isPublished ? true : entry.locked;\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - create new main entry item\n * - create new or update latest entry item\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n\n /**\n * We need to create published entry if\n */\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert data into the DynamoDB.\",\n ex.code || \"CREATE_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n\n return initialStorageEntry;\n };\n\n const createRevisionFrom = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsCreateRevisionFromParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - create the main entry item\n * - update the last entry item to a current one\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n ];\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create revision from given entry.\",\n ex.code || \"CREATE_REVISION_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n /**\n * There are no modifications on the entry created so just return the data.\n */\n return initialStorageEntry;\n };\n\n const update = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUpdateParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const items = [];\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to:\n * - update the current entry\n * - update the latest entry if the current entry is the latest one\n */\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createRevisionSortKey(storageEntry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n\n if (isPublished) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(storageEntry)\n })\n );\n }\n\n /**\n * We need the latest entry to update it as well if neccessary.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && latestStorageEntry.id === entry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n locked,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry.\",\n ex.code || \"UPDATE_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry\n }\n );\n }\n };\n\n const deleteEntry = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteParams\n ) => {\n const { entry } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n };\n\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all records.\",\n ex.code || \"LOAD_ALL_RECORDS_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n const items = records.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the entry.\",\n ex.code || \"DELETE_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n entry\n }\n );\n }\n };\n\n const deleteRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsDeleteRevisionParams\n ) => {\n const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createRevisionSortKey(entry)\n })\n ];\n\n const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n /**\n * If revision we are deleting is the published one as well, we need to delete those records as well.\n */\n if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n if (initialLatestStorageEntry) {\n const latestStorageEntry = convertToStorageEntry({\n storageEntry: initialLatestStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...latestStorageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(latestStorageEntry)\n })\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, {\n error: ex,\n entry,\n latestEntry\n });\n }\n };\n\n const getLatestRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n const getPublishedRevisionByEntryId = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisionById = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: [params.id]\n });\n const item = items.shift() || null;\n if (!item) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n };\n\n const getRevisions = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetRevisionsParams\n ) => {\n const items = await dataLoaders.getAllEntryRevisions({\n model,\n ids: [params.id]\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetByIdsParams\n ) => {\n const items = await dataLoaders.getRevisionById({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getLatestByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetLatestByIdsParams\n ) => {\n const items = await dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPublishedByIds = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPublishedByIdsParams\n ) => {\n const items = await dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: params.ids\n });\n\n return items.map(item => {\n return convertFromStorageEntry({\n storageEntry: item,\n model\n });\n });\n };\n\n const getPreviousRevision = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) => {\n const { entryId, version } = params;\n const queryParams: QueryOneParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant: model.tenant,\n locale: model.locale,\n id: entryId\n }),\n options: {\n lt: `REV#${zeroPad(version)}`,\n /**\n * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.\n */\n filters: [\n {\n attr: \"TYPE\",\n eq: createType()\n },\n {\n attr: \"version\",\n lt: version\n }\n ],\n reverse: true\n }\n };\n\n try {\n const result = await queryOne<CmsEntry>(queryParams);\n\n const storageEntry = cleanupItem(entity, result);\n if (!storageEntry) {\n return null;\n }\n return convertFromStorageEntry({\n storageEntry,\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey: queryParams.partitionKey,\n options: queryParams.options,\n model\n }\n );\n }\n };\n\n const list = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsListParams\n ) => {\n const {\n limit: initialLimit = 10,\n where: initialWhere,\n after,\n sort: sortBy,\n fields,\n search\n } = params;\n const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;\n\n const type = initialWhere.published ? \"P\" : \"L\";\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createGSIPartitionKey(model, type),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n let records = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(ex.message, \"QUERY_ENTRIES_ERROR\", {\n error: ex,\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n });\n }\n if (records.length === 0) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n delete where[\"published\"];\n delete where[\"latest\"];\n /**\n * We need an object containing field, transformers and paths.\n * Just build it here and pass on into other methods that require it to avoid mapping multiple times.\n */\n const modelFields = createFields({\n plugins,\n model\n });\n\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = await filter({\n items: records.map(record => {\n return convertFromStorageEntry({\n storageEntry: record,\n model\n });\n }),\n where,\n plugins,\n fields: modelFields,\n fromStorage: createStorageTransformCallable(model),\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const totalCount = filteredItems.length;\n\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedItems = sort({\n items: filteredItems,\n sort: sortBy,\n fields: modelFields\n });\n\n const start = parseInt((decodeCursor(after) as string) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const slicedItems = sortedItems.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = totalCount > start + limit ? encodeCursor(`${start + limit}`) : null;\n return {\n hasMoreItems,\n totalCount,\n cursor,\n items: cleanupItems(entity, slicedItems)\n };\n };\n\n const get = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsGetParams\n ) => {\n const { items } = await list(model, {\n ...params,\n limit: 1\n });\n return items.shift() || null;\n };\n\n const publish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsPublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n /**\n * We need the latest and published entries to see if something needs to be updated along side the publishing one.\n */\n const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);\n\n const storageEntry = convertToStorageEntry({\n model,\n storageEntry: initialStorageEntry\n });\n /**\n * We need to update:\n * - current entry revision sort key\n * - published sort key\n * - latest sort key - if entry updated is actually latest\n * - previous published entry to unpublished status - if any previously published entry\n */\n const items = [\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createPublishedSortKey(),\n TYPE: createPublishedType(),\n GSI1_PK: createGSIPartitionKey(model, \"P\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {\n const publishedStorageEntry = convertToStorageEntry({\n storageEntry: initialPublishedStorageEntry,\n model\n });\n items.push(\n entity.putBatch({\n ...publishedStorageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(publishedStorageEntry),\n TYPE: createType(),\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED,\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(publishedStorageEntry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute the publishing batch.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n entry,\n latestStorageEntry: initialLatestStorageEntry,\n publishedStorageEntry: initialPublishedStorageEntry\n }\n );\n }\n };\n\n const unpublish = async (\n model: StorageOperationsCmsModel,\n params: CmsEntryStorageOperationsUnpublishParams\n ) => {\n const { entry, storageEntry: initialStorageEntry } = params;\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n locale: model.locale,\n tenant: model.tenant\n });\n\n const storageEntry = convertToStorageEntry({\n storageEntry: initialStorageEntry,\n model\n });\n /**\n * We need to:\n * - delete currently published entry\n * - update current entry revision with new data\n * - update latest entry status - if entry being unpublished is latest\n */\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n }),\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createRevisionSortKey(entry),\n TYPE: createType(),\n GSI1_PK: createGSIPartitionKey(model, \"A\"),\n GSI1_SK: createGSISortKey(entry)\n })\n ];\n\n /**\n * We need the latest entry to see if something needs to be updated along side the unpublishing one.\n */\n const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);\n\n if (latestStorageEntry && entry.id === latestStorageEntry.id) {\n items.push(\n entity.putBatch({\n ...storageEntry,\n PK: partitionKey,\n SK: createLatestSortKey(),\n TYPE: createLatestType(),\n GSI1_PK: createGSIPartitionKey(model, \"L\"),\n GSI1_SK: createGSISortKey(entry)\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n dataLoaders.clearAll({\n model\n });\n return initialStorageEntry;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not execute unpublish batch.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n };\n\n return {\n create,\n createRevisionFrom,\n update,\n delete: deleteEntry,\n deleteRevision,\n getPreviousRevision,\n getPublishedByIds,\n getLatestByIds,\n getByIds,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId,\n get,\n getRevisions,\n publish,\n list,\n unpublish\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAyBA;;AAQA;;AACA;;AAMA;;AAEA;;AACA;;AACA;;AAEA;;AACA;;AAEA,MAAMA,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAP;AACH,CAFD;;AAGA,MAAMC,gBAAgB,GAAG,MAAc;EACnC,OAAQ,GAAED,UAAU,EAAG,IAAvB;AACH,CAFD;;AAGA,MAAME,mBAAmB,GAAG,MAAc;EACtC,OAAQ,GAAEF,UAAU,EAAG,IAAvB;AACH,CAFD;;AAQA,MAAMG,qBAAqB,GAAIC,MAAD,IAAwD;EAClF,MAAM;IAAEC,KAAF;IAASC;EAAT,IAA0BF,MAAhC;EAEA,MAAMG,MAAM,GAAGF,KAAK,CAACG,wBAAN,CAA+B;IAC1CC,MAAM,EAAEJ,KAAK,CAACI,MAD4B;IAE1CF,MAAM,EAAED,YAAY,CAACC;EAFqB,CAA/B,CAAf;EAIA,mEACOD,YADP;IAEIC;EAFJ;AAIH,CAXD;;AAaA,MAAMG,uBAAuB,GAAIN,MAAD,IAAwD;EACpF,MAAM;IAAEC,KAAF;IAASC;EAAT,IAA0BF,MAAhC;EAEA,MAAMG,MAAM,GAAGF,KAAK,CAACM,0BAAN,CAAiC;IAC5CF,MAAM,EAAEJ,KAAK,CAACI,MAD8B;IAE5CF,MAAM,EAAED,YAAY,CAACC;EAFuB,CAAjC,CAAf;EAIA,mEACOD,YADP;IAEIC;EAFJ;AAIH,CAXD;;AAiBO,MAAMK,8BAA8B,GACvCR,MAD0C,IAEd;EAC5B,MAAM;IAAES,MAAF;IAAUC;EAAV,IAAsBV,MAA5B;EAEA,MAAMW,WAAW,GAAG,IAAIC,+BAAJ,CAAuB;IACvCH;EADuC,CAAvB,CAApB;EAIA,MAAMI,uBAAuB,GAAGH,O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QHD,cARG;IASHD,QATG;IAUHH,eAVG;IAWHH,6BAXG;IAYHd,0BAZG;IAaHoE,GAbG;IAcHlD,YAdG;IAeHmD,OAfG;IAgBHjC,IAhBG;IAiBHqC;EAjBG,CAAP;AAmBH,CAz3BM"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.sortEntryItems = exports.filterItems = exports.buildModelFields = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
@@ -21,6 +21,10 @@ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueF
|
|
|
21
21
|
|
|
22
22
|
var _CmsEntryFieldFilterPathPlugin = require("../../plugins/CmsEntryFieldFilterPathPlugin");
|
|
23
23
|
|
|
24
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
+
|
|
26
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
27
|
+
|
|
24
28
|
const VALUES_ATTRIBUTE = "values";
|
|
25
29
|
|
|
26
30
|
const extractWhereParams = key => {
|
|
@@ -358,7 +362,7 @@ const filterItems = async params => {
|
|
|
358
362
|
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
359
363
|
}
|
|
360
364
|
|
|
361
|
-
const search = createFullTextSearch((
|
|
365
|
+
const search = createFullTextSearch(_objectSpread(_objectSpread({}, fullTextSearch), {}, {
|
|
362
366
|
plugin: fullTextSearchPlugin
|
|
363
367
|
}));
|
|
364
368
|
const promises = records.map(async record => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VALUES_ATTRIBUTE","extractWhereParams","key","result","split","fieldId","shift","rawOp","length","join","operation","negate","match","replace","transformValue","value","transform","Array","isArray","map","v","getFilterPlugin","params","plugins","plugin","WebinyError","createValuePath","field","index","valuePathPlugin","type","basePath","systemFields","canUse","path","createPath","isObjectFiltering","Date","toISOString","createFilters","where","fields","filterPlugins","getMappedPlugins","ValueFilterPlugin","property","transformValuePlugins","valuePathPlugins","CmsEntryFieldFilterPathPlugin","filters","hasOwnProperty","undefined","whereParams","transformValuePlugin","def","transformValueCallable","objectFilteringParams","propertyFilters","Object","keys","propertyFilter","propertyId","propertyOperation","propertyNegate","filterPlugin","multiValuesPath","multipleValues","push","compareValue","getFilterValuePath","filter","includes","paths","getFilterValuePropertyPath","pop","execFilter","plainValue","matched","matches","createFullTextSearch","term","targetFields","trim","item","fromStorage","targetField","values","find","target","filterItems","items","records","fullTextSearch","fullTextSearchPlugin","byType","getOperation","search","promises","record","valuePath","rawValue","dotProp","get","propertyPath","console","log","set","results","Promise","all","Boolean","extractSort","sortBy","order","modelField","reverse","sortEntryItems","sort","firstSort","itemsToSort","id","valueTransformer","sortedItems","lodashSortBy","newItems","s","i","sortingBy","pluginsContainer","reduce","collection","buildModelFields","model","isSystemField","storageId","modelId"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashSortBy from \"lodash/sortBy\";\nimport dotProp from \"dot-prop\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { systemFields } from \"./systemFields\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CmsEntryFieldFilterPathPluginParams,\n CreatePathCallable as CmsEntryFieldFieldCreatePathCallable\n} from \"~/plugins/CmsEntryFieldFilterPathPlugin\";\n\ninterface ModelField {\n def: CmsModelField;\n valueTransformer: (value: any) => any;\n createPath: CmsEntryFieldFieldCreatePathCallable;\n isSystemField?: boolean;\n}\n\ntype ModelFieldRecords = Record<string, ModelField>;\n\ntype MappedPlugins<T extends Plugin> = Record<string, T>;\n\ninterface CreateFiltersParams {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: ModelFieldRecords;\n}\n\ninterface ItemFilter {\n fieldId: string;\n path: string;\n filterPlugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport interface FilterItemFromStorage {\n <T = any>(field: CmsModelField, value: any): Promise<T>;\n}\ninterface FilterItemsParams {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: ModelFieldRecords;\n fromStorage: FilterItemFromStorage;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nconst VALUES_ATTRIBUTE = \"values\";\n\nconst extractWhereParams = (key: string) => {\n const result = key.split(\"_\");\n const fieldId = result.shift();\n if (!fieldId) {\n return null;\n }\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /**\n * When rawOp is not, it means it is equal negated so just return that.\n */\n if (rawOp === \"not\") {\n return {\n fieldId,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n fieldId,\n operation,\n negate\n };\n};\n\nconst transformValue = (value: any, transform: (value: any) => any): any => {\n if (Array.isArray(value)) {\n return value.map(v => transform(v));\n }\n return transform(value);\n};\n\ninterface GetFilterPluginParams {\n plugins: MappedPlugins<ValueFilterPlugin>;\n operation: string;\n}\nconst getFilterPlugin = (params: GetFilterPluginParams) => {\n const { plugins, operation } = params;\n const plugin = plugins[operation];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filter plugin for operation \"${operation}\".`,\n \"FILTER_PLUGIN_ERROR\",\n {\n operation\n }\n );\n};\n\ninterface CreateValuePathParams {\n field: CmsModelField;\n plugins: MappedPlugins<CmsEntryFieldFilterPathPlugin>;\n index?: number;\n}\nconst createValuePath = (params: CreateValuePathParams): string => {\n const { field, plugins, index } = params;\n const { fieldId } = field;\n const valuePathPlugin = plugins[field.type];\n const basePath = systemFields[fieldId] ? \"\" : `${VALUES_ATTRIBUTE}.`;\n if (!valuePathPlugin || valuePathPlugin.canUse(field) === false) {\n return `${basePath}${fieldId}`;\n }\n const path = valuePathPlugin.createPath({\n field,\n index\n });\n return `${basePath}${path}`;\n};\n\ninterface ObjectFilteringParams {\n key: string;\n field: CmsModelField;\n value: any;\n}\nconst isObjectFiltering = (params: ObjectFilteringParams): boolean => {\n const { value } = params;\n if (!value) {\n return false;\n } else if (Array.isArray(value) === true) {\n return false;\n } else if (value instanceof Date || !!value.toISOString) {\n return false;\n } else if (typeof value !== \"object\") {\n return false;\n }\n return true;\n};\n\nconst createFilters = (params: CreateFiltersParams): ItemFilter[] => {\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 valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const filters: ItemFilter[] = [];\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 const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field: ModelField = 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 const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.def.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field: field.def,\n value\n });\n };\n\n const objectFilteringParams = {\n key,\n value,\n field: field.def\n };\n if (isObjectFiltering(objectFilteringParams)) {\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n continue;\n }\n for (const propertyFilter of propertyFilters) {\n const whereParams = extractWhereParams(propertyFilter);\n if (!whereParams) {\n continue;\n }\n const {\n fieldId: propertyId,\n operation: propertyOperation,\n negate: propertyNegate\n } = whereParams;\n\n const filterPlugin = getFilterPlugin({\n plugins: filterPlugins,\n operation: propertyOperation\n });\n\n const basePath = createValuePath({\n field: field.def,\n plugins: valuePathPlugins\n });\n\n const multiValuesPath = field.def.multipleValues ? \"%s.\" : \"\";\n\n filters.push({\n fieldId,\n path: `${basePath}.${multiValuesPath}${propertyId}`,\n filterPlugin,\n negate: propertyNegate,\n compareValue: transformValue(value[propertyFilter], transformValueCallable),\n transformValue: transformValueCallable\n });\n }\n\n continue;\n }\n\n const filterPlugin = getFilterPlugin({\n plugins: filterPlugins,\n operation\n });\n\n filters.push({\n fieldId,\n path: createValuePath({\n field: field.def,\n plugins: valuePathPlugins\n }),\n filterPlugin,\n negate,\n compareValue: transformValue(value, transformValueCallable),\n transformValue: transformValueCallable\n });\n }\n\n return filters;\n};\n/**\n * In case filter field is not multiple values one, return exact path.\n * If is multiple values field, use path without the last part\n */\nconst getFilterValuePath = (filter: ItemFilter): string => {\n if (filter.path.includes(\".%s.\") === false) {\n return filter.path;\n }\n const paths = filter.path.split(\".%s.\");\n return paths.shift() as string;\n};\n\nconst getFilterValuePropertyPath = (filter: ItemFilter): string | null => {\n if (filter.path.includes(\".%s.\") === false) {\n return null;\n }\n const paths = filter.path.split(\".%s.\");\n return paths.pop() || null;\n};\n\ninterface ExecFilterParams {\n value: any;\n filter: ItemFilter;\n}\nconst execFilter = (params: ExecFilterParams) => {\n const { value: plainValue, filter } = params;\n\n const value = transformValue(plainValue, filter.transformValue);\n const matched = filter.filterPlugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface CreateFullTextSearchParams {\n term?: string;\n fields?: string[];\n plugin: ValueFilterPlugin;\n}\n\ninterface FullTextSearchParams {\n item: CmsEntry;\n fromStorage: FilterItemFromStorage;\n fields: ModelFieldRecords;\n}\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nconst createFullTextSearch = ({\n term,\n fields: targetFields,\n plugin\n}: CreateFullTextSearchParams) => {\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return async ({ item, fromStorage, fields }: FullTextSearchParams) => {\n for (const targetField of targetFields) {\n const field = Object.values(fields).find(field => {\n return field.def.fieldId === targetField;\n });\n if (!field) {\n throw new WebinyError(\n `Unknown field \"${targetField}\" in the model.`,\n \"UNKNOWN_FIELD\",\n {\n target: targetField\n }\n );\n }\n const value = await fromStorage(field.def, item.values[targetField]);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n\nexport const filterItems = async (params: FilterItemsParams): Promise<CmsEntry[]> => {\n const { items: records, where, plugins, fields, fromStorage, fullTextSearch } = params;\n\n const filters = createFilters({\n plugins,\n where,\n fields\n });\n\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\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 ...fullTextSearch,\n plugin: fullTextSearchPlugin\n });\n\n const promises: Promise<CmsEntry | null>[] = records.map(async record => {\n /**\n * We need to go through all the filters and apply them to the given record.\n */\n for (const filter of filters) {\n /**\n * In case is multiple values field, last part is removed from path.\n * -> values.categories.id -> values.categories\n */\n const valuePath = getFilterValuePath(filter);\n\n const rawValue = dotProp.get(record, valuePath);\n if (valuePath !== filter.path) {\n /**\n * Calculated is different than original because we need to search in the array of objects.\n */\n const propertyPath = getFilterValuePropertyPath(filter);\n if (!propertyPath) {\n console.log(`Cannot determine the property path of \"${filter.path}\".`);\n continue;\n }\n\n const plainValue = await fromStorage<Record<string, string>[]>(\n fields[filter.fieldId].def,\n rawValue\n );\n /**\n * We cannot go through the value because it is not array. Log the error and continue.\n */\n if (Array.isArray(plainValue) === false) {\n console.log(\n `Cannot go through the value on ${valuePath} because it is not an array, and we expect it to be.`\n );\n continue;\n }\n record = dotProp.set(record, valuePath, plainValue);\n\n const values = plainValue.map(value => {\n return value[propertyPath];\n });\n\n const result = execFilter({\n value: values,\n filter\n });\n\n if (!result) {\n return null;\n }\n continue;\n }\n\n const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);\n /**\n * If raw value is not same as the value after the storage transform, set the value to the items being filtered.\n */\n if (plainValue !== rawValue) {\n record = dotProp.set(record, filter.path, plainValue);\n }\n\n const result = execFilter({\n value: plainValue,\n filter\n });\n if (result === false) {\n return null;\n }\n }\n /**\n * If we have full text search defined, run it. Otherwise just return the given record.\n */\n if (!search) {\n return record;\n }\n const result = await search({\n item: record,\n fromStorage,\n fields\n });\n if (!result) {\n return null;\n }\n\n return record;\n });\n /**\n * We run filtering as promises so it is a bit faster than in for ... of loop.\n */\n const results: (CmsEntry | null)[] = await Promise.all(promises);\n /**\n * And filter out the null values which are returned when filter is not satisfied.\n */\n\n return results.filter(Boolean) as CmsEntry[];\n};\n\ninterface ExtractSortResult {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: ModelField;\n}\n\nconst extractSort = (sortBy: string, fields: ModelFieldRecords): ExtractSortResult => {\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 modelField = Object.values(fields).find(field => {\n return field.def.fieldId === fieldId;\n });\n\n if (!modelField) {\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 = modelField.createPath({\n field: modelField.def\n });\n return {\n field: modelField,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n\ninterface SortEntryItemsArgs {\n items: CmsEntry[];\n sort?: string[];\n fields: ModelFieldRecords;\n}\n\nexport const sortEntryItems = (params: SortEntryItemsArgs): CmsEntry[] => {\n const { items, sort = [], fields } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort: sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort(firstSort, fields);\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.valueTransformer(dotProp.get(item, valuePath))\n };\n });\n const sortedItems: { id: string; value: any }[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n\nconst getMappedPlugins = <T extends Plugin>(params: {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}): MappedPlugins<T> => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n throw new WebinyError(`There are no plugins of type \"${type}\".`, \"PLUGINS_ERROR\", {\n type\n });\n }\n return plugins.reduce((collection, plugin) => {\n const key = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {} as MappedPlugins<T>);\n};\n\nexport const buildModelFields = ({\n plugins,\n model\n}: {\n plugins: PluginsContainer;\n model: CmsModel;\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 const fields: ModelFieldRecords = Object.values(systemFields).reduce((collection, field) => {\n /**\n * This should be caught on the tests runs and never actually happen on live system.\n */\n if (!field.fieldId) {\n throw new WebinyError(\"Missing system field `fieldId`.\", \"FIELD_ID_ERROR\", {\n field\n });\n }\n const transformValuePlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n\n let createPath: CmsEntryFieldFilterPathPluginParams[\"path\"] = params => {\n return params.field.fieldId;\n };\n if (valuePathPlugin) {\n createPath = params => {\n return valuePathPlugin.createPath(params);\n };\n }\n collection[field.fieldId] = {\n def: field,\n valueTransformer: (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({ field, value });\n },\n createPath,\n isSystemField: true\n };\n\n return collection;\n }, {} as ModelFieldRecords);\n\n return model.fields.reduce((collection, field) => {\n if (!field.fieldId) {\n console.log(\n `Field \"${field.storageId}\" in model \"${model.modelId}\" is missing fieldId.`\n );\n return collection;\n }\n const transformValuePlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n\n let createPath: CmsEntryFieldFilterPathPluginParams[\"path\"] = params => {\n return `${VALUES_ATTRIBUTE}.${params.field.fieldId}`;\n };\n if (valuePathPlugin) {\n createPath = params => {\n return valuePathPlugin.createPath(params);\n };\n }\n\n collection[field.fieldId] = {\n def: field,\n valueTransformer: (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({ field, value });\n },\n createPath\n };\n\n return collection;\n }, fields);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AAEA;;AA+CA,MAAMA,gBAAgB,GAAG,QAAzB;;AAEA,MAAMC,kBAAkB,GAAIC,GAAD,IAAiB;EACxC,MAAMC,MAAM,GAAGD,GAAG,CAACE,KAAJ,CAAU,GAAV,CAAf;EACA,MAAMC,OAAO,GAAGF,MAAM,CAACG,KAAP,EAAhB;;EACA,IAAI,CAACD,OAAL,EAAc;IACV,OAAO,IAAP;EACH;;EACD,MAAME,KAAK,GAAGJ,MAAM,CAACK,MAAP,KAAkB,CAAlB,GAAsB,IAAtB,GAA6BL,MAAM,CAACM,IAAP,CAAY,GAAZ,CAA3C;EACA;AACJ;AACA;;EACI,IAAIF,KAAK,KAAK,KAAd,EAAqB;I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AU,eAAcF,KAAK,CAACG,OAAQ,uBAD1D;MAGA,OAAOL,UAAP;IACH;;IACD,MAAM7E,oBAAoB,GAAGP,qBAAqB,CAACnB,KAAK,CAACG,IAAP,CAAlD;IACA,MAAMD,eAAe,GAAGkB,gBAAgB,CAACpB,KAAK,CAACG,IAAP,CAAxC;;IAEA,IAAIK,UAAuD,GAAGb,MAAM,IAAI;MACpE,OAAQ,GAAEtB,gBAAiB,IAAGsB,MAAM,CAACK,KAAP,CAAatB,OAAQ,EAAnD;IACH,CAFD;;IAGA,IAAIwB,eAAJ,EAAqB;MACjBM,UAAU,GAAGb,MAAM,IAAI;QACnB,OAAOO,eAAe,CAACM,UAAhB,CAA2Bb,MAA3B,CAAP;MACH,CAFD;IAGH;;IAED4G,UAAU,CAACvG,KAAK,CAACtB,OAAP,CAAV,GAA4B;MACxBiD,GAAG,EAAE3B,KADmB;MAExB8F,gBAAgB,EAAG1G,KAAD,IAAgB;QAC9B,IAAI,CAACsC,oBAAL,EAA2B;UACvB,OAAOtC,KAAP;QACH;;QACD,OAAOsC,oBAAoB,CAACrC,SAArB,CAA+B;UAAEW,KAAF;UAASZ;QAAT,CAA/B,CAAP;MACH,CAPuB;MAQxBoB;IARwB,CAA5B;IAWA,OAAO+F,UAAP;EACH,CA/BM,EA+BJzF,MA/BI,CAAP;AAgCH,CApFM"}
|
|
1
|
+
{"version":3,"names":["VALUES_ATTRIBUTE","extractWhereParams","key","result","split","fieldId","shift","rawOp","length","join","operation","negate","match","replace","transformValue","value","transform","Array","isArray","map","v","getFilterPlugin","params","plugins","plugin","WebinyError","createValuePath","field","index","valuePathPlugin","type","basePath","systemFields","canUse","path","createPath","isObjectFiltering","Date","toISOString","createFilters","where","fields","filterPlugins","getMappedPlugins","ValueFilterPlugin","property","transformValuePlugins","valuePathPlugins","CmsEntryFieldFilterPathPlugin","filters","hasOwnProperty","undefined","whereParams","transformValuePlugin","def","transformValueCallable","objectFilteringParams","propertyFilters","Object","keys","propertyFilter","propertyId","propertyOperation","propertyNegate","filterPlugin","multiValuesPath","multipleValues","push","compareValue","getFilterValuePath","filter","includes","paths","getFilterValuePropertyPath","pop","execFilter","plainValue","matched","matches","createFullTextSearch","term","targetFields","trim","item","fromStorage","targetField","values","find","target","filterItems","items","records","fullTextSearch","fullTextSearchPlugin","byType","getOperation","search","promises","record","valuePath","rawValue","dotProp","get","propertyPath","console","log","set","results","Promise","all","Boolean","extractSort","sortBy","order","modelField","reverse","sortEntryItems","sort","firstSort","itemsToSort","id","valueTransformer","sortedItems","lodashSortBy","newItems","s","i","sortingBy","pluginsContainer","reduce","collection","buildModelFields","model","isSystemField","storageId","modelId"],"sources":["utils.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashSortBy from \"lodash/sortBy\";\nimport dotProp from \"dot-prop\";\nimport {\n CmsEntry,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { systemFields } from \"./systemFields\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CmsEntryFieldFilterPathPluginParams,\n CreatePathCallable as CmsEntryFieldFieldCreatePathCallable\n} from \"~/plugins/CmsEntryFieldFilterPathPlugin\";\n\ninterface ModelField {\n def: CmsModelField;\n valueTransformer: (value: any) => any;\n createPath: CmsEntryFieldFieldCreatePathCallable;\n isSystemField?: boolean;\n}\n\ntype ModelFieldRecords = Record<string, ModelField>;\n\ntype MappedPlugins<T extends Plugin> = Record<string, T>;\n\ninterface CreateFiltersParams {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: ModelFieldRecords;\n}\n\ninterface ItemFilter {\n fieldId: string;\n path: string;\n filterPlugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport interface FilterItemFromStorage {\n <T = any>(field: CmsModelField, value: any): Promise<T>;\n}\ninterface FilterItemsParams {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: ModelFieldRecords;\n fromStorage: FilterItemFromStorage;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nconst VALUES_ATTRIBUTE = \"values\";\n\nconst extractWhereParams = (key: string) => {\n const result = key.split(\"_\");\n const fieldId = result.shift();\n if (!fieldId) {\n return null;\n }\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /**\n * When rawOp is not, it means it is equal negated so just return that.\n */\n if (rawOp === \"not\") {\n return {\n fieldId,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n fieldId,\n operation,\n negate\n };\n};\n\nconst transformValue = (value: any, transform: (value: any) => any): any => {\n if (Array.isArray(value)) {\n return value.map(v => transform(v));\n }\n return transform(value);\n};\n\ninterface GetFilterPluginParams {\n plugins: MappedPlugins<ValueFilterPlugin>;\n operation: string;\n}\nconst getFilterPlugin = (params: GetFilterPluginParams) => {\n const { plugins, operation } = params;\n const plugin = plugins[operation];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filter plugin for operation \"${operation}\".`,\n \"FILTER_PLUGIN_ERROR\",\n {\n operation\n }\n );\n};\n\ninterface CreateValuePathParams {\n field: CmsModelField;\n plugins: MappedPlugins<CmsEntryFieldFilterPathPlugin>;\n index?: number;\n}\nconst createValuePath = (params: CreateValuePathParams): string => {\n const { field, plugins, index } = params;\n const { fieldId } = field;\n const valuePathPlugin = plugins[field.type];\n const basePath = systemFields[fieldId] ? \"\" : `${VALUES_ATTRIBUTE}.`;\n if (!valuePathPlugin || valuePathPlugin.canUse(field) === false) {\n return `${basePath}${fieldId}`;\n }\n const path = valuePathPlugin.createPath({\n field,\n index\n });\n return `${basePath}${path}`;\n};\n\ninterface ObjectFilteringParams {\n key: string;\n field: CmsModelField;\n value: any;\n}\nconst isObjectFiltering = (params: ObjectFilteringParams): boolean => {\n const { value } = params;\n if (!value) {\n return false;\n } else if (Array.isArray(value) === true) {\n return false;\n } else if (value instanceof Date || !!value.toISOString) {\n return false;\n } else if (typeof value !== \"object\") {\n return false;\n }\n return true;\n};\n\nconst createFilters = (params: CreateFiltersParams): ItemFilter[] => {\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 valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const filters: ItemFilter[] = [];\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 const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field: ModelField = 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 const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.def.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field: field.def,\n value\n });\n };\n\n const objectFilteringParams = {\n key,\n value,\n field: field.def\n };\n if (isObjectFiltering(objectFilteringParams)) {\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n continue;\n }\n for (const propertyFilter of propertyFilters) {\n const whereParams = extractWhereParams(propertyFilter);\n if (!whereParams) {\n continue;\n }\n const {\n fieldId: propertyId,\n operation: propertyOperation,\n negate: propertyNegate\n } = whereParams;\n\n const filterPlugin = getFilterPlugin({\n plugins: filterPlugins,\n operation: propertyOperation\n });\n\n const basePath = createValuePath({\n field: field.def,\n plugins: valuePathPlugins\n });\n\n const multiValuesPath = field.def.multipleValues ? \"%s.\" : \"\";\n\n filters.push({\n fieldId,\n path: `${basePath}.${multiValuesPath}${propertyId}`,\n filterPlugin,\n negate: propertyNegate,\n compareValue: transformValue(value[propertyFilter], transformValueCallable),\n transformValue: transformValueCallable\n });\n }\n\n continue;\n }\n\n const filterPlugin = getFilterPlugin({\n plugins: filterPlugins,\n operation\n });\n\n filters.push({\n fieldId,\n path: createValuePath({\n field: field.def,\n plugins: valuePathPlugins\n }),\n filterPlugin,\n negate,\n compareValue: transformValue(value, transformValueCallable),\n transformValue: transformValueCallable\n });\n }\n\n return filters;\n};\n/**\n * In case filter field is not multiple values one, return exact path.\n * If is multiple values field, use path without the last part\n */\nconst getFilterValuePath = (filter: ItemFilter): string => {\n if (filter.path.includes(\".%s.\") === false) {\n return filter.path;\n }\n const paths = filter.path.split(\".%s.\");\n return paths.shift() as string;\n};\n\nconst getFilterValuePropertyPath = (filter: ItemFilter): string | null => {\n if (filter.path.includes(\".%s.\") === false) {\n return null;\n }\n const paths = filter.path.split(\".%s.\");\n return paths.pop() || null;\n};\n\ninterface ExecFilterParams {\n value: any;\n filter: ItemFilter;\n}\nconst execFilter = (params: ExecFilterParams) => {\n const { value: plainValue, filter } = params;\n\n const value = transformValue(plainValue, filter.transformValue);\n const matched = filter.filterPlugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface CreateFullTextSearchParams {\n term?: string;\n fields?: string[];\n plugin: ValueFilterPlugin;\n}\n\ninterface FullTextSearchParams {\n item: CmsEntry;\n fromStorage: FilterItemFromStorage;\n fields: ModelFieldRecords;\n}\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nconst createFullTextSearch = ({\n term,\n fields: targetFields,\n plugin\n}: CreateFullTextSearchParams) => {\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return async ({ item, fromStorage, fields }: FullTextSearchParams) => {\n for (const targetField of targetFields) {\n const field = Object.values(fields).find(field => {\n return field.def.fieldId === targetField;\n });\n if (!field) {\n throw new WebinyError(\n `Unknown field \"${targetField}\" in the model.`,\n \"UNKNOWN_FIELD\",\n {\n target: targetField\n }\n );\n }\n const value = await fromStorage(field.def, item.values[targetField]);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n\nexport const filterItems = async (params: FilterItemsParams): Promise<CmsEntry[]> => {\n const { items: records, where, plugins, fields, fromStorage, fullTextSearch } = params;\n\n const filters = createFilters({\n plugins,\n where,\n fields\n });\n\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\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 ...fullTextSearch,\n plugin: fullTextSearchPlugin\n });\n\n const promises: Promise<CmsEntry | null>[] = records.map(async record => {\n /**\n * We need to go through all the filters and apply them to the given record.\n */\n for (const filter of filters) {\n /**\n * In case is multiple values field, last part is removed from path.\n * -> values.categories.id -> values.categories\n */\n const valuePath = getFilterValuePath(filter);\n\n const rawValue = dotProp.get(record, valuePath);\n if (valuePath !== filter.path) {\n /**\n * Calculated is different than original because we need to search in the array of objects.\n */\n const propertyPath = getFilterValuePropertyPath(filter);\n if (!propertyPath) {\n console.log(`Cannot determine the property path of \"${filter.path}\".`);\n continue;\n }\n\n const plainValue = await fromStorage<Record<string, string>[]>(\n fields[filter.fieldId].def,\n rawValue\n );\n /**\n * We cannot go through the value because it is not array. Log the error and continue.\n */\n if (Array.isArray(plainValue) === false) {\n console.log(\n `Cannot go through the value on ${valuePath} because it is not an array, and we expect it to be.`\n );\n continue;\n }\n record = dotProp.set(record, valuePath, plainValue);\n\n const values = plainValue.map(value => {\n return value[propertyPath];\n });\n\n const result = execFilter({\n value: values,\n filter\n });\n\n if (!result) {\n return null;\n }\n continue;\n }\n\n const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);\n /**\n * If raw value is not same as the value after the storage transform, set the value to the items being filtered.\n */\n if (plainValue !== rawValue) {\n record = dotProp.set(record, filter.path, plainValue);\n }\n\n const result = execFilter({\n value: plainValue,\n filter\n });\n if (result === false) {\n return null;\n }\n }\n /**\n * If we have full text search defined, run it. Otherwise just return the given record.\n */\n if (!search) {\n return record;\n }\n const result = await search({\n item: record,\n fromStorage,\n fields\n });\n if (!result) {\n return null;\n }\n\n return record;\n });\n /**\n * We run filtering as promises so it is a bit faster than in for ... of loop.\n */\n const results: (CmsEntry | null)[] = await Promise.all(promises);\n /**\n * And filter out the null values which are returned when filter is not satisfied.\n */\n\n return results.filter(Boolean) as CmsEntry[];\n};\n\ninterface ExtractSortResult {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: ModelField;\n}\n\nconst extractSort = (sortBy: string, fields: ModelFieldRecords): ExtractSortResult => {\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 modelField = Object.values(fields).find(field => {\n return field.def.fieldId === fieldId;\n });\n\n if (!modelField) {\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 = modelField.createPath({\n field: modelField.def\n });\n return {\n field: modelField,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n\ninterface SortEntryItemsArgs {\n items: CmsEntry[];\n sort?: string[];\n fields: ModelFieldRecords;\n}\n\nexport const sortEntryItems = (params: SortEntryItemsArgs): CmsEntry[] => {\n const { items, sort = [], fields } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort: sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort(firstSort, fields);\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.valueTransformer(dotProp.get(item, valuePath))\n };\n });\n const sortedItems: { id: string; value: any }[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n\nconst getMappedPlugins = <T extends Plugin>(params: {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}): MappedPlugins<T> => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n throw new WebinyError(`There are no plugins of type \"${type}\".`, \"PLUGINS_ERROR\", {\n type\n });\n }\n return plugins.reduce((collection, plugin) => {\n const key = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {} as MappedPlugins<T>);\n};\n\nexport const buildModelFields = ({\n plugins,\n model\n}: {\n plugins: PluginsContainer;\n model: CmsModel;\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 const fields: ModelFieldRecords = Object.values(systemFields).reduce((collection, field) => {\n /**\n * This should be caught on the tests runs and never actually happen on live system.\n */\n if (!field.fieldId) {\n throw new WebinyError(\"Missing system field `fieldId`.\", \"FIELD_ID_ERROR\", {\n field\n });\n }\n const transformValuePlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n\n let createPath: CmsEntryFieldFilterPathPluginParams[\"path\"] = params => {\n return params.field.fieldId;\n };\n if (valuePathPlugin) {\n createPath = params => {\n return valuePathPlugin.createPath(params);\n };\n }\n collection[field.fieldId] = {\n def: field,\n valueTransformer: (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({ field, value });\n },\n createPath,\n isSystemField: true\n };\n\n return collection;\n }, {} as ModelFieldRecords);\n\n return model.fields.reduce((collection, field) => {\n if (!field.fieldId) {\n console.log(\n `Field \"${field.storageId}\" in model \"${model.modelId}\" is missing fieldId.`\n );\n return collection;\n }\n const transformValuePlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n\n let createPath: CmsEntryFieldFilterPathPluginParams[\"path\"] = params => {\n return `${VALUES_ATTRIBUTE}.${params.field.fieldId}`;\n };\n if (valuePathPlugin) {\n createPath = params => {\n return valuePathPlugin.createPath(params);\n };\n }\n\n collection[field.fieldId] = {\n def: field,\n valueTransformer: (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({ field, value });\n },\n createPath\n };\n\n return collection;\n }, fields);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AAEA;;;;;;AA+CA,MAAMA,gBAAgB,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}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-ddb",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.97a151f74d",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-headless-cms",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "7.19.0",
|
|
25
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
26
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
27
|
-
"@webiny/error": "0.0.0-unstable.
|
|
28
|
-
"@webiny/handler-db": "0.0.0-unstable.
|
|
29
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
25
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.97a151f74d",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.97a151f74d",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.97a151f74d",
|
|
28
|
+
"@webiny/handler-db": "0.0.0-unstable.97a151f74d",
|
|
29
|
+
"@webiny/utils": "0.0.0-unstable.97a151f74d",
|
|
30
30
|
"aws-sdk": "2.1230.0",
|
|
31
31
|
"dataloader": "2.1.0",
|
|
32
32
|
"dot-prop": "6.0.1",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@babel/core": "^7.19.3",
|
|
40
40
|
"@babel/preset-env": "^7.19.4",
|
|
41
41
|
"@types/jsonpack": "^1.1.0",
|
|
42
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
43
|
-
"@webiny/plugins": "^0.0.0-unstable.
|
|
44
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
42
|
+
"@webiny/cli": "^0.0.0-unstable.97a151f74d",
|
|
43
|
+
"@webiny/plugins": "^0.0.0-unstable.97a151f74d",
|
|
44
|
+
"@webiny/project-utils": "^0.0.0-unstable.97a151f74d",
|
|
45
45
|
"jest": "^28.1.0",
|
|
46
46
|
"jest-dynalite": "^3.2.0",
|
|
47
47
|
"jest-environment-node": "^27.2.4",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"build": "yarn webiny run build",
|
|
57
57
|
"watch": "yarn webiny run watch"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "97a151f74d8c5679323989fcc8cc7036be0f150e"
|
|
60
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
2
|
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
3
3
|
export interface CreatePathCallableParams {
|
|
4
|
-
field: CmsModelField
|
|
4
|
+
field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
|
|
5
5
|
index?: number;
|
|
6
6
|
}
|
|
7
7
|
export interface CreatePathCallable {
|
|
@@ -17,6 +17,6 @@ export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
|
|
|
17
17
|
private readonly config;
|
|
18
18
|
get fieldType(): string;
|
|
19
19
|
constructor(config: CmsEntryFieldFilterPathPluginParams);
|
|
20
|
-
canUse(field: CmsModelField): boolean;
|
|
20
|
+
canUse(field: Pick<CmsModelField, "fieldId" | "type">): boolean;
|
|
21
21
|
createPath(params: CreatePathCallableParams): string;
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CmsEntryFieldFilterPathPlugin","Plugin","fieldType","config","constructor","name","type","canUse","field","fieldId","Array","isArray","length","includes","createPath","params","path","WebinyError"],"sources":["CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreatePathCallableParams {\n field: CmsModelField
|
|
1
|
+
{"version":3,"names":["CmsEntryFieldFilterPathPlugin","Plugin","fieldType","config","constructor","name","type","canUse","field","fieldId","Array","isArray","length","includes","createPath","params","path","WebinyError"],"sources":["CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n this.name = `${(this.constructor as any).type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAeO,MAAMA,6BAAN,SAA4CC,cAA5C,CAAmD;EAKlC,IAATC,SAAS,GAAW;IAC3B,OAAO,KAAKC,MAAL,CAAYD,SAAnB;EACH;;EAEME,WAAW,CAACD,MAAD,EAA8C;IAC5D;IAD4D;IAG5D,KAAKA,MAAL,GAAcA,MAAd;IAEA,KAAKE,IAAL,GAAa,GAAG,KAAKD,WAAN,CAA0BE,IAAK,IAAG,KAAKH,MAAL,CAAYD,SAAU,EAAvE;EACH;;EAEMK,MAAM,CAACC,KAAD,EAA0D;IACnE,IAAIA,KAAK,CAACF,IAAN,KAAe,KAAKH,MAAL,CAAYD,SAA/B,EAA0C;MACtC,OAAO,KAAP;IACH;;IACD,MAAMO,OAAO,GAAG,KAAKN,MAAL,CAAYM,OAA5B;;IACA,IAAI,CAACA,OAAD,IAAYC,KAAK,CAACC,OAAN,CAAcF,OAAd,MAA2B,KAAvC,IAAgDA,OAAO,CAACG,MAAR,KAAmB,CAAvE,EAA0E;MACtE,OAAO,IAAP;IACH;;IACD,OAAOH,OAAO,CAACI,QAAR,CAAiBL,KAAK,CAACC,OAAvB,CAAP;EACH;;EAEMK,UAAU,CAACC,MAAD,EAA2C;IACxD,IAAI,OAAO,KAAKZ,MAAL,CAAYa,IAAnB,KAA4B,UAAhC,EAA4C;MACxC,OAAO,KAAKb,MAAL,CAAYa,IAAZ,CAAiBD,MAAjB,CAAP;IACH,CAFD,MAEO,IAAI,OAAO,KAAKZ,MAAL,CAAYa,IAAnB,KAA4B,QAAhC,EAA0C;MAC7C,OAAO,KAAKb,MAAL,CAAYa,IAAnB;IACH;;IACD,MAAM,IAAIC,cAAJ,CAAiB,oBAAmB,KAAKZ,IAAK,WAA9C,CAAN;EACH;;AAnCqD;;;8BAA7CL,6B,UACsC,uB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
3
|
+
import { Field } from "../operations/entry/filtering/types";
|
|
4
|
+
import { CmsFieldFilterValueTransformPlugin } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* This plugin is used to create the filter.
|
|
7
|
+
* Internally we have default one + the one for the reference field - because it is actually an object when filtering.
|
|
8
|
+
*/
|
|
9
|
+
interface CmsEntryFieldFilterPluginParams {
|
|
10
|
+
fieldType: string;
|
|
11
|
+
create: (params: CmsEntryFieldFilterPluginCreateParams) => null | CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[];
|
|
12
|
+
}
|
|
13
|
+
interface CmsEntryFieldFilterPluginCreateParams {
|
|
14
|
+
key: string;
|
|
15
|
+
value: any;
|
|
16
|
+
field: Field;
|
|
17
|
+
fields: Record<string, Field>;
|
|
18
|
+
operation: string;
|
|
19
|
+
valueFilterPlugins: Record<string, ValueFilterPlugin>;
|
|
20
|
+
transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;
|
|
21
|
+
getFilterCreatePlugin: (type: string) => CmsEntryFieldFilterPlugin;
|
|
22
|
+
negate: boolean;
|
|
23
|
+
compareValue: any;
|
|
24
|
+
transformValue: <I = any, O = any>(value: I) => O;
|
|
25
|
+
}
|
|
26
|
+
export interface CmsEntryFieldFilterPluginCreateResponse {
|
|
27
|
+
field: Field;
|
|
28
|
+
path: string;
|
|
29
|
+
fieldPathId: string;
|
|
30
|
+
plugin: ValueFilterPlugin;
|
|
31
|
+
negate: boolean;
|
|
32
|
+
compareValue: any;
|
|
33
|
+
transformValue: <I = any, O = any>(value: I) => O;
|
|
34
|
+
}
|
|
35
|
+
export declare class CmsEntryFieldFilterPlugin extends Plugin {
|
|
36
|
+
static readonly type: string;
|
|
37
|
+
static readonly ALL: string;
|
|
38
|
+
private readonly config;
|
|
39
|
+
readonly fieldType: string;
|
|
40
|
+
constructor(config: CmsEntryFieldFilterPluginParams);
|
|
41
|
+
create(params: CmsEntryFieldFilterPluginCreateParams): CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[] | null;
|
|
42
|
+
}
|
|
43
|
+
export {};
|