@webiny/api-headless-cms-ddb 0.0.0-mt-3 → 0.0.0-unstable.8c4d9f045a
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/entry.d.ts +2 -1
- package/definitions/entry.js +5 -2
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +2 -1
- package/definitions/group.js +2 -2
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +2 -1
- package/definitions/model.js +2 -2
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +2 -2
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +2 -2
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +2 -1
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -10
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +2 -3
- package/dynamoDb/path/plainObject.js +28 -21
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +2 -3
- package/dynamoDb/storage/date.js +79 -45
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +71 -53
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -8
- package/dynamoDb/storage/richText.js +69 -66
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +4 -2
- package/dynamoDb/transformValue/datetime.js +31 -26
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.js +20 -19
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +12 -8
- package/operations/entry/dataLoaders.js +26 -6
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/index.d.ts +2 -2
- package/operations/entry/index.js +264 -103
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js +11 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/systemFields.js +18 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/entry/utils.d.ts +10 -5
- package/operations/entry/utils.js +373 -95
- package/operations/entry/utils.js.map +1 -0
- package/operations/group/index.d.ts +3 -2
- package/operations/group/index.js +3 -5
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +3 -2
- package/operations/model/index.js +15 -10
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +3 -2
- package/operations/settings/index.js +3 -5
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +3 -2
- package/operations/system/index.js +3 -5
- package/operations/system/index.js.map +1 -0
- package/package.json +23 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/types.d.ts +1 -32
- package/types.js.map +1 -0
- package/dynamoDb/path/ref.d.ts +0 -3
- package/dynamoDb/path/ref.js +0 -27
|
@@ -0,0 +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,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,EAAE;IATS,CAA5B;IAYA,OAAOH,UAAP;EACH,CAjCiC,EAiC/B,EAjC+B,CAAlC;EAmCA,OAAOE,KAAK,CAAC3F,MAAN,CAAawF,MAAb,CAAoB,CAACC,UAAD,EAAavG,KAAb,KAAuB;IAC9C,IAAI,CAACA,KAAK,CAACtB,OAAX,EAAoB;MAChBmG,OAAO,CAACC,GAAR,CACK,UAAS9E,KAAK,CAAC2G,SAAU,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,8 +1,9 @@
|
|
|
1
1
|
import { CmsGroupStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { Entity } from "dynamodb-toolbox";
|
|
3
3
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
|
|
4
|
+
interface CreateGroupsStorageOperationsParams {
|
|
5
5
|
entity: Entity<any>;
|
|
6
6
|
plugins: PluginsContainer;
|
|
7
7
|
}
|
|
8
|
-
export declare const createGroupsStorageOperations: (params:
|
|
8
|
+
export declare const createGroupsStorageOperations: (params: CreateGroupsStorageOperationsParams) => CmsGroupStorageOperations;
|
|
9
|
+
export {};
|
|
@@ -23,9 +23,9 @@ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueF
|
|
|
23
23
|
|
|
24
24
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
25
25
|
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
26
|
+
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; }
|
|
27
27
|
|
|
28
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
28
|
+
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; }
|
|
29
29
|
|
|
30
30
|
const createPartitionKey = params => {
|
|
31
31
|
const {
|
|
@@ -86,8 +86,7 @@ const createGroupsStorageOperations = params => {
|
|
|
86
86
|
|
|
87
87
|
const update = async params => {
|
|
88
88
|
const {
|
|
89
|
-
group
|
|
90
|
-
original
|
|
89
|
+
group
|
|
91
90
|
} = params;
|
|
92
91
|
const keys = createKeys(group);
|
|
93
92
|
|
|
@@ -100,7 +99,6 @@ const createGroupsStorageOperations = params => {
|
|
|
100
99
|
throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
|
|
101
100
|
error: ex,
|
|
102
101
|
group,
|
|
103
|
-
original,
|
|
104
102
|
keys
|
|
105
103
|
});
|
|
106
104
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","createSortKeys","id","createKeys","PK","SK","createType","createGroupsStorageOperations","entity","plugins","filteringPlugins","byType","ValueFilterPlugin","type","length","WebinyError","create","group","keys","put","TYPE","ex","message","code","error","update","deleteGroup","delete","get","getRecord","cleanupItem","list","sort","where","queryAllParams","partitionKey","options","gte","records","queryAll","filteredItems","filterItems","items","fields","sortItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, plugins } = params;\n\n const filteringPlugins = plugins.byType<ValueFilterPlugin>(ValueFilterPlugin.type);\n if (filteringPlugins.length === 0) {\n throw new WebinyError(\n \"DynamoDB filtering plugins not loaded.\",\n \"MISSING_DYNAMODB_FILTERING_PLUGINS\"\n );\n }\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n // TODO make sure that group has locale and tenant on it - add it in the crud just in case\n const keys = createKeys(group);\n\n try {\n await entity.delete(keys);\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const group = await getRecord<CmsGroup>({\n entity,\n keys\n });\n\n return cleanupItem(entity, group);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n\n let records: CmsGroup[] = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterItems({\n items: records,\n where,\n fields: [],\n plugins\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n return sortItems({\n items: filteredItems,\n sort,\n fields: []\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EAC/D,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,OAAQ,KAAIC,MAAO,MAAKC,MAAO,UAA/B;AACH,CAHD;;AAQA,MAAMC,cAAc,GAAIH,MAAD,IAAmC;EACtD,MAAM;IAAEI;EAAF,IAASJ,MAAf;EACA,OAAOI,EAAP;AACH,CAHD;;AASA,MAAMC,UAAU,GAAIL,MAAD,IAAsD;EACrE,OAAO;IACHM,EAAE,EAAEP,kBAAkB,CAACC,MAAD,CADnB;IAEHO,EAAE,EAAEJ,cAAc,CAACH,MAAD;EAFf,CAAP;AAIH,CALD;;AAOA,M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AEtC,kBAAkB,CAACoC,KAAD,CAFG;MAGnCG,OAAO,EAAE;QACLC,GAAG,EAAE;MADA;IAH0B,CAAvC;IAQA,IAAIC,OAAmB,GAAG,EAA1B;;IACA,IAAI;MACAA,OAAO,GAAG,MAAM,IAAAC,eAAA,EAASL,cAAT,CAAhB;IACH,CAFD,CAEE,OAAOb,EAAP,EAAW;MACT,MAAM,IAAIN,cAAJ,CACFM,EAAE,CAACC,OAAH,IAAc,wBADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,kBAFT;QAIEC,KAAK,EAAEH;MAJT,GAKKvB,MALL;QAMEkC,IANF;QAOEC;MAPF,GAAN;IAUH;;IAED,MAAMO,aAAa,GAAG,IAAAC,mBAAA,EAAY;MAC9BC,KAAK,EAAEJ,OADuB;MAE9BL,KAF8B;MAG9BU,MAAM,EAAE,EAHsB;MAI9BlC;IAJ8B,CAAZ,CAAtB;;IAMA,IAAI,CAACuB,IAAD,IAASA,IAAI,CAAClB,MAAL,KAAgB,CAA7B,EAAgC;MAC5B,OAAO0B,aAAP;IACH;;IACD,OAAO,IAAAI,eAAA,EAAU;MACbF,KAAK,EAAEF,aADM;MAEbR,IAFa;MAGbW,MAAM,EAAE;IAHK,CAAV,CAAP;EAKH,CAzCD;;EA2CA,OAAO;IACH3B,MADG;IAEHS,MAFG;IAGHE,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CArJM"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { Entity } from "dynamodb-toolbox";
|
|
3
|
-
|
|
3
|
+
interface CreateModelsStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
}
|
|
6
|
-
export declare const createModelsStorageOperations: (params:
|
|
6
|
+
export declare const createModelsStorageOperations: (params: CreateModelsStorageOperationsParams) => CmsModelStorageOperations;
|
|
7
|
+
export {};
|
|
@@ -17,15 +17,22 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
|
17
17
|
|
|
18
18
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
19
|
|
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
20
|
+
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; }
|
|
21
21
|
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
22
|
+
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; }
|
|
23
23
|
|
|
24
24
|
const createPartitionKey = params => {
|
|
25
25
|
const {
|
|
26
26
|
tenant,
|
|
27
27
|
locale
|
|
28
28
|
} = params;
|
|
29
|
+
|
|
30
|
+
if (!tenant) {
|
|
31
|
+
throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
|
|
32
|
+
} else if (!locale) {
|
|
33
|
+
throw new _error.default(`Missing locale variable when creating model partitionKey.`);
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
return `T#${tenant}#L#${locale}#CMS#CM`;
|
|
30
37
|
};
|
|
31
38
|
|
|
@@ -56,7 +63,7 @@ const createModelsStorageOperations = params => {
|
|
|
56
63
|
const keys = createKeys(model);
|
|
57
64
|
|
|
58
65
|
try {
|
|
59
|
-
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
|
|
66
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
|
|
60
67
|
TYPE: createType()
|
|
61
68
|
}));
|
|
62
69
|
return model;
|
|
@@ -71,21 +78,19 @@ const createModelsStorageOperations = params => {
|
|
|
71
78
|
|
|
72
79
|
const update = async params => {
|
|
73
80
|
const {
|
|
74
|
-
original,
|
|
75
81
|
model
|
|
76
82
|
} = params;
|
|
77
83
|
const keys = createKeys(model);
|
|
78
84
|
|
|
79
85
|
try {
|
|
80
|
-
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
|
|
86
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
|
|
81
87
|
TYPE: createType()
|
|
82
88
|
}));
|
|
83
89
|
return model;
|
|
84
90
|
} catch (ex) {
|
|
85
|
-
throw new _error.default(ex.
|
|
91
|
+
throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
|
|
86
92
|
error: ex,
|
|
87
93
|
model,
|
|
88
|
-
original,
|
|
89
94
|
keys
|
|
90
95
|
});
|
|
91
96
|
}
|
|
@@ -101,7 +106,7 @@ const createModelsStorageOperations = params => {
|
|
|
101
106
|
await entity.delete(keys);
|
|
102
107
|
return model;
|
|
103
108
|
} catch (ex) {
|
|
104
|
-
throw new _error.default(ex.
|
|
109
|
+
throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
|
|
105
110
|
error: ex,
|
|
106
111
|
model,
|
|
107
112
|
keys
|
|
@@ -119,7 +124,7 @@ const createModelsStorageOperations = params => {
|
|
|
119
124
|
});
|
|
120
125
|
return (0, _cleanup.cleanupItem)(entity, item);
|
|
121
126
|
} catch (ex) {
|
|
122
|
-
throw new _error.default(ex.
|
|
127
|
+
throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
123
128
|
error: ex,
|
|
124
129
|
keys
|
|
125
130
|
});
|
|
@@ -142,7 +147,7 @@ const createModelsStorageOperations = params => {
|
|
|
142
147
|
const items = await (0, _query.queryAll)(queryAllParams);
|
|
143
148
|
return (0, _cleanup.cleanupItems)(entity, items);
|
|
144
149
|
} catch (ex) {
|
|
145
|
-
throw new _error.default(ex.
|
|
150
|
+
throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
146
151
|
error: ex,
|
|
147
152
|
partitionKey: queryAllParams.partitionKey
|
|
148
153
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","WebinyError","createSortKey","modelId","createKeys","PK","SK","createType","createModelsStorageOperations","entity","create","model","keys","put","cleanupItem","TYPE","ex","error","update","message","code","deleteModel","delete","get","item","getRecord","list","where","queryAllParams","partitionKey","options","gte","items","queryAll","cleanupItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\n\ninterface PartitionKeysParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n } else if (!locale) {\n throw new WebinyError(`Missing locale variable when creating model partitionKey.`);\n }\n return `T#${tenant}#L#${locale}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: Entity<any>;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: ex,\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const item = await getRecord<CmsModel>({\n entity,\n keys\n });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n try {\n const items = await queryAll<CmsModel>(queryAllParams);\n\n return cleanupItems(entity, items);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;;;;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAyC;EAChE,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;;EACA,IAAI,CAACC,MAAL,EAAa;IACT,MAAM,IAAIE,cAAJ,CAAiB,2DAAjB,CAAN;EACH,CAFD,MAEO,IAAI,CAACD,MAAL,EAAa;IAChB,MAAM,IAAIC,cAAJ,CAAiB,2DAAjB,CAAN;EACH;;EACD,OAAQ,KAAIF,MAAO,MAAKC,MAAO,SAA/B;AACH,CARD;;AAaA,MAAME,aAAa,GAAIJ,MAAD,IAAmC;EACrD,OAAOA,MAAM,CAACK,OAAd;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIN,MAAD,IAAuD;EACtE,OAAO;IACHO,EAAE,EAAER,kBAAkB,CAACC,MAAD,CADnB;IAEHQ,EAAE,EAAEJ,aAAa,CAACJ,MAAD;EAFd,CAAP;AAIH,CALD;;AAOA,MAAMS,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAP;AACH,CAFD;;AAOO,MAAMC,6BAA6B,GACtCV,MADyC,IAEb;EAC5B,MAAM;IAAEW;EAAF,IAAaX,MAAnB;;EAEA,MAAMY,MAAM,GAAG,MAAOZ,MAAP,IAAyD;IACpE,MAAM;MAAEa;IAAF,IAAYb,MAAlB;IAEA,MAAMc,I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,CAvBD;;EAyBA,OAAO;IACHnB,MADG;IAEHQ,MAFG;IAGHI,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CA5HM"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CmsSettingsStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { Entity } from "dynamodb-toolbox";
|
|
3
|
-
|
|
3
|
+
interface CreateSettingsStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
}
|
|
6
|
-
export declare const createSettingsStorageOperations: (params:
|
|
6
|
+
export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => CmsSettingsStorageOperations;
|
|
7
|
+
export {};
|
|
@@ -15,9 +15,9 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
15
15
|
|
|
16
16
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
+
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; }
|
|
19
19
|
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
20
|
+
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; }
|
|
21
21
|
|
|
22
22
|
const convertToDbData = settings => {
|
|
23
23
|
return _objectSpread(_objectSpread({}, settings), {}, {
|
|
@@ -88,8 +88,7 @@ const createSettingsStorageOperations = params => {
|
|
|
88
88
|
|
|
89
89
|
const update = async params => {
|
|
90
90
|
const {
|
|
91
|
-
settings
|
|
92
|
-
original
|
|
91
|
+
settings
|
|
93
92
|
} = params;
|
|
94
93
|
const keys = createKeys(settings);
|
|
95
94
|
const dbSettings = convertToDbData(settings);
|
|
@@ -102,7 +101,6 @@ const createSettingsStorageOperations = params => {
|
|
|
102
101
|
error: ex,
|
|
103
102
|
settings,
|
|
104
103
|
dbSettings,
|
|
105
|
-
original,
|
|
106
104
|
keys
|
|
107
105
|
});
|
|
108
106
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["convertToDbData","settings","contentModelLastChange","toISOString","convertFromDbData","Date","createPartitionKey","tenant","locale","createSortKey","createKeys","params","PK","SK","createSettingsStorageOperations","entity","create","keys","dbSettings","put","ex","WebinyError","message","code","error","update","get","record","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSettings,\n CmsSettingsStorageOperations,\n CmsSettingsStorageOperationsCreateParams,\n CmsSettingsStorageOperationsGetParams,\n CmsSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CmsSettingsDb extends Omit<CmsSettings, \"contentModelLastChange\"> {\n contentModelLastChange: string;\n}\n\nconst convertToDbData = (settings: CmsSettings): CmsSettingsDb => {\n return {\n ...settings,\n contentModelLastChange: settings.contentModelLastChange.toISOString()\n };\n};\n\nconst convertFromDbData = (settings?: CmsSettingsDb): CmsSettings | null => {\n if (!settings) {\n return null;\n }\n let contentModelLastChange;\n try {\n contentModelLastChange = new Date(settings.contentModelLastChange);\n } catch {\n contentModelLastChange = new Date();\n }\n return {\n ...settings,\n contentModelLastChange\n };\n};\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nconst createPartitionKey = ({ tenant, locale }: PartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#CMS#SETTINGS`;\n};\n\nconst createSortKey = (): string => {\n return \"settings\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\ninterface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): CmsSettingsStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsSettingsStorageOperationsCreateParams) => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create settings.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSettingsStorageOperationsUpdateParams) => {\n const { settings } = params;\n\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update settings.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSettingsStorageOperationsGetParams) => {\n const keys = createKeys(params);\n try {\n const record = await getRecord<CmsSettingsDb>({\n entity,\n keys\n });\n if (!record) {\n return null;\n }\n const settings = cleanupItem(entity, record) as CmsSettingsDb;\n return convertFromDbData(settings);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get settings.\",\n ex.code || \"GET_SETTINGS_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n get,\n update\n };\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;;;;;AAMA,MAAMA,eAAe,GAAIC,QAAD,IAA0C;EAC9D,uCACOA,QADP;IAEIC,sBAAsB,EAAED,QAAQ,CAACC,sBAAT,CAAgCC,WAAhC;EAF5B;AAIH,CALD;;AAOA,MAAMC,iBAAiB,GAAIH,QAAD,IAAkD;EACxE,IAAI,CAACA,QAAL,EAAe;IACX,OAAO,IAAP;EACH;;EACD,IAAIC,sBAAJ;;EACA,IAAI;IACAA,sBAAsB,GAAG,IAAIG,IAAJ,CAASJ,QAAQ,CAACC,sBAAlB,CAAzB;EACH,CAFD,CAEE,MAAM;IACJA,sBAAsB,GAAG,IAAIG,IAAJ,EAAzB;EACH;;EACD,uCACOJ,QADP;IAEIC;EAFJ;AAIH,CAdD;;AAqBA,MAAMI,kBAAkB,GAAG,CAAC;EAAEC,MAAF;EAAUC;AAAV,CAAD,KAAoD;EAC3E,OAAQ,KAAID,MAAO,MAAKC,MAAO,eAA/B;AACH,CAFD;;AAIA,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,UAAP;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIC,MAAD,IAAsC;EACrD,OAAO;IACHC,EAAE,EAAEN,kBAAkB,CAACK,MAAD,CADnB;IAEHE,EAAE,EAAEJ,aAAa;EAFd,CAAP;AAIH,CALD;;AAWO,MAAMK,+BAA+B,GACxCH,MAD2C,IAEZ;EAC/B,MAAM;IAAEI;EAAF,IAAaJ,MAAnB;;EAEA,MAAMK,MAAM,GAAG,MAAOL,MAAP,IAA4D;IACvE,MAAM;MAAEV;IAAF,IAAeU,MAArB;IACA,MAAMM,IAAI,GAAGP,UAAU,CAACT,QAAD,CAAvB;IAEA,MAAMiB,UAAyB,GAAGlB,eAAe,CAACC,QAAD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AAiB,CAACH,QAAD,CAAxB;IACH,CAVD,CAUE,OAAOmB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,yBADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,oBAFT,EAGF;QACIC,KAAK,EAAEJ,EADX;QAEIH;MAFJ,CAHE,CAAN;IAQH;EACJ,CAtBD;;EAwBA,OAAO;IACHD,MADG;IAEHU,GAFG;IAGHD;EAHG,CAAP;AAKH,CAvFM"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { Entity } from "dynamodb-toolbox";
|
|
3
|
-
|
|
3
|
+
interface CreateSystemStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
}
|
|
6
|
-
export declare const createSystemStorageOperations: (params:
|
|
6
|
+
export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => CmsSystemStorageOperations;
|
|
7
|
+
export {};
|
|
@@ -15,9 +15,9 @@ var _get = require("@webiny/db-dynamodb/utils/get");
|
|
|
15
15
|
|
|
16
16
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
+
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; }
|
|
19
19
|
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
20
|
+
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; }
|
|
21
21
|
|
|
22
22
|
const createPartitionKey = ({
|
|
23
23
|
tenant
|
|
@@ -60,8 +60,7 @@ const createSystemStorageOperations = params => {
|
|
|
60
60
|
|
|
61
61
|
const update = async params => {
|
|
62
62
|
const {
|
|
63
|
-
system
|
|
64
|
-
original
|
|
63
|
+
system
|
|
65
64
|
} = params;
|
|
66
65
|
const keys = createKeys(system);
|
|
67
66
|
|
|
@@ -72,7 +71,6 @@ const createSystemStorageOperations = params => {
|
|
|
72
71
|
throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
73
72
|
error: ex,
|
|
74
73
|
system,
|
|
75
|
-
original,
|
|
76
74
|
keys
|
|
77
75
|
});
|
|
78
76
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","tenant","toLowerCase","createSortKey","createKeys","params","PK","SK","createSystemStorageOperations","entity","create","system","keys","put","ex","WebinyError","message","code","error","update","get","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSystem,\n CmsSystemStorageOperations,\n CmsSystemStorageOperationsCreateParams,\n CmsSystemStorageOperationsGetParams,\n CmsSystemStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n}\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = ({ tenant }: PartitionKeyParams): string => {\n return `T#${tenant.toLowerCase()}#SYSTEM`;\n};\nconst createSortKey = (): string => {\n return \"CMS\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): CmsSystemStorageOperations => {\n const { entity } = params;\n\n const create = async ({ system }: CmsSystemStorageOperationsCreateParams) => {\n const keys = createKeys(system);\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create system.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSystemStorageOperationsUpdateParams) => {\n const { system } = params;\n\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update system.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSystemStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const system = await getRecord<CmsSystem>({\n entity,\n keys\n });\n return cleanupItem(entity, system);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get system.\",\n ex.code || \"GET_SYSTEM_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n update,\n get\n };\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;;;;;AASA,MAAMA,kBAAkB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAA4C;EACnE,OAAQ,KAAIA,MAAM,CAACC,WAAP,EAAqB,SAAjC;AACH,CAFD;;AAGA,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,KAAP;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIC,MAAD,IAAsC;EACrD,OAAO;IACHC,EAAE,EAAEN,kBA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MAFsC,CAArB,CAArB;MAIA,OAAO,IAAAU,oBAAA,EAAYb,MAAZ,EAAoBE,MAApB,CAAP;IACH,CAND,CAME,OAAOG,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,uBADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,kBAFT,EAGF;QACIC,KAAK,EAAEJ,EADX;QAEIF;MAFJ,CAHE,CAAN;IAQH;EACJ,CAnBD;;EAqBA,OAAO;IACHF,MADG;IAEHS,MAFG;IAGHC;EAHG,CAAP;AAKH,CA5EM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-ddb",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.8c4d9f045a",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-headless-cms",
|
|
@@ -21,33 +21,33 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/runtime": "7.
|
|
25
|
-
"@webiny/api-headless-cms": "0.0.0-
|
|
26
|
-
"@webiny/db-dynamodb": "0.0.0-
|
|
27
|
-
"@webiny/error": "0.0.0-
|
|
28
|
-
"@webiny/handler-db": "0.0.0-
|
|
29
|
-
"@webiny/utils": "0.0.0-
|
|
30
|
-
"aws-sdk": "2.
|
|
31
|
-
"dataloader": "2.
|
|
32
|
-
"dot-prop": "
|
|
33
|
-
"dynamodb-toolbox": "0.3.
|
|
24
|
+
"@babel/runtime": "7.18.9",
|
|
25
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.8c4d9f045a",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.8c4d9f045a",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.8c4d9f045a",
|
|
28
|
+
"@webiny/handler-db": "0.0.0-unstable.8c4d9f045a",
|
|
29
|
+
"@webiny/utils": "0.0.0-unstable.8c4d9f045a",
|
|
30
|
+
"aws-sdk": "2.1188.0",
|
|
31
|
+
"dataloader": "2.1.0",
|
|
32
|
+
"dot-prop": "6.0.1",
|
|
33
|
+
"dynamodb-toolbox": "0.3.5",
|
|
34
34
|
"jsonpack": "1.1.5",
|
|
35
|
-
"lodash
|
|
35
|
+
"lodash": "4.17.21"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@babel/cli": "^7.
|
|
39
|
-
"@babel/core": "^7.
|
|
40
|
-
"@babel/preset-env": "^7.
|
|
41
|
-
"@babel/preset-flow": "^7.
|
|
38
|
+
"@babel/cli": "^7.16.0",
|
|
39
|
+
"@babel/core": "^7.16.0",
|
|
40
|
+
"@babel/preset-env": "^7.16.4",
|
|
41
|
+
"@babel/preset-flow": "^7.16.0",
|
|
42
42
|
"@types/jsonpack": "^1.1.0",
|
|
43
|
-
"@webiny/cli": "^0.0.0-
|
|
44
|
-
"@webiny/plugins": "^0.0.0-
|
|
45
|
-
"@webiny/project-utils": "^0.0.0-
|
|
46
|
-
"jest": "^
|
|
43
|
+
"@webiny/cli": "^0.0.0-unstable.8c4d9f045a",
|
|
44
|
+
"@webiny/plugins": "^0.0.0-unstable.8c4d9f045a",
|
|
45
|
+
"@webiny/project-utils": "^0.0.0-unstable.8c4d9f045a",
|
|
46
|
+
"jest": "^28.1.0",
|
|
47
47
|
"jest-dynalite": "^3.2.0",
|
|
48
|
-
"jest-environment-node": "^
|
|
48
|
+
"jest-environment-node": "^27.2.4",
|
|
49
49
|
"ttypescript": "^1.5.12",
|
|
50
|
-
"typescript": "
|
|
50
|
+
"typescript": "4.7.4"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"build": "yarn webiny run build",
|
|
58
58
|
"watch": "yarn webiny run watch"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5f904a53a5956269bd80a9c084cc04f92b824d36"
|
|
61
61
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
3
|
+
export interface CreatePathCallableParams {
|
|
4
|
+
field: CmsModelField;
|
|
5
|
+
index?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface CreatePathCallable {
|
|
8
|
+
(params: CreatePathCallableParams): string;
|
|
9
|
+
}
|
|
10
|
+
export interface CmsEntryFieldFilterPathPluginParams {
|
|
11
|
+
fieldType: string;
|
|
12
|
+
fieldId?: string[];
|
|
13
|
+
path: string | CreatePathCallable;
|
|
14
|
+
}
|
|
15
|
+
export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
|
|
16
|
+
static readonly type: string;
|
|
17
|
+
private readonly config;
|
|
18
|
+
get fieldType(): string;
|
|
19
|
+
constructor(config: CmsEntryFieldFilterPathPluginParams);
|
|
20
|
+
canUse(field: CmsModelField): boolean;
|
|
21
|
+
createPath(params: CreatePathCallableParams): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CmsEntryFieldFilterPathPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
15
|
+
|
|
16
|
+
class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
|
|
17
|
+
get fieldType() {
|
|
18
|
+
return this.config.fieldType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super();
|
|
23
|
+
(0, _defineProperty2.default)(this, "config", void 0);
|
|
24
|
+
this.config = config;
|
|
25
|
+
this.name = `${this.constructor.type}-${this.config.fieldType}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
canUse(field) {
|
|
29
|
+
if (field.type !== this.config.fieldType) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const fieldId = this.config.fieldId;
|
|
34
|
+
|
|
35
|
+
if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return fieldId.includes(field.fieldId);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
createPath(params) {
|
|
43
|
+
if (typeof this.config.path === "function") {
|
|
44
|
+
return this.config.path(params);
|
|
45
|
+
} else if (typeof this.config.path === "string") {
|
|
46
|
+
return this.config.path;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new _error.default(`Missing path in "${this.name}" plugin.`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.CmsEntryFieldFilterPathPlugin = CmsEntryFieldFilterPathPlugin;
|
|
55
|
+
(0, _defineProperty2.default)(CmsEntryFieldFilterPathPlugin, "type", "cms-field-filter-path");
|
|
@@ -0,0 +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;\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: CmsModelField): 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,EAAgC;IACzC,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"}
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/types";
|
|
2
|
-
import { CmsModelField,
|
|
2
|
+
import { CmsModelField, HeadlessCmsStorageOperations as BaseHeadlessCmsStorageOperations } from "@webiny/api-headless-cms/types";
|
|
3
3
|
import { DynamoDBTypes, TableConstructor } from "dynamodb-toolbox/dist/classes/Table";
|
|
4
4
|
import { EntityAttributeConfig, EntityCompositeAttributes } from "dynamodb-toolbox/dist/classes/Entity";
|
|
5
5
|
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
@@ -25,36 +25,6 @@ export interface CmsFieldFilterValueTransformPlugin extends Plugin {
|
|
|
25
25
|
*/
|
|
26
26
|
transform: (params: CmsFieldFilterValueTransformParams) => any;
|
|
27
27
|
}
|
|
28
|
-
interface CmsFieldFilterPathParams {
|
|
29
|
-
/**
|
|
30
|
-
* A field for which we are creating the value path.
|
|
31
|
-
*/
|
|
32
|
-
field: CmsModelField;
|
|
33
|
-
/**
|
|
34
|
-
* If value is an array we will need index position.
|
|
35
|
-
* It is up to the developer to add.
|
|
36
|
-
*/
|
|
37
|
-
index?: number | string;
|
|
38
|
-
}
|
|
39
|
-
export interface CmsFieldFilterPathPlugin extends Plugin {
|
|
40
|
-
/**
|
|
41
|
-
* A plugin type.
|
|
42
|
-
*/
|
|
43
|
-
type: "cms-field-filter-path";
|
|
44
|
-
/**
|
|
45
|
-
* A field type this plugin is for.
|
|
46
|
-
*/
|
|
47
|
-
fieldType: string;
|
|
48
|
-
/**
|
|
49
|
-
* A field id this plugin is for.
|
|
50
|
-
* It is meant for targeting only specific fields in a certain type.
|
|
51
|
-
*/
|
|
52
|
-
fieldId?: string[];
|
|
53
|
-
/**
|
|
54
|
-
* Get a path for given field.
|
|
55
|
-
*/
|
|
56
|
-
createPath: (params: CmsFieldFilterPathParams) => string;
|
|
57
|
-
}
|
|
58
28
|
export declare type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;
|
|
59
29
|
export declare type Attributes = Record<string, AttributeDefinition>;
|
|
60
30
|
export declare enum ENTITIES {
|
|
@@ -70,7 +40,6 @@ export interface TableModifier {
|
|
|
70
40
|
export interface StorageOperationsFactoryParams {
|
|
71
41
|
documentClient: DocumentClient;
|
|
72
42
|
table?: TableModifier;
|
|
73
|
-
modelFieldToGraphQLPlugins: CmsModelFieldToGraphQLPlugin[];
|
|
74
43
|
attributes?: Record<ENTITIES, Attributes>;
|
|
75
44
|
plugins?: Plugin[] | Plugin[][];
|
|
76
45
|
}
|