@webiny/api-headless-cms 5.33.5 → 5.34.0-beta.1
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/context.js +3 -7
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.d.ts +2 -2
- package/crud/contentEntry/afterDelete.js +2 -2
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.d.ts +2 -2
- package/crud/contentEntry/beforeCreate.js +2 -2
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.d.ts +2 -2
- package/crud/contentEntry/beforeUpdate.js +2 -2
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +3 -7
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +10 -11
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +11 -13
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +83 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +0 -2
- package/crud/contentEntry.crud.js +249 -269
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +3 -3
- package/crud/contentModel/afterCreate.js +5 -5
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.d.ts +3 -3
- package/crud/contentModel/afterCreateFrom.js +5 -5
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.d.ts +3 -3
- package/crud/contentModel/afterDelete.js +5 -5
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.d.ts +3 -3
- package/crud/contentModel/afterUpdate.js +5 -5
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +4 -4
- package/crud/contentModel/beforeCreate.js +10 -10
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +3 -3
- package/crud/contentModel/beforeDelete.js +6 -6
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +3 -3
- package/crud/contentModel/beforeUpdate.js +5 -5
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +5 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/models.js +12 -0
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/validateModel.js +1 -1
- package/crud/contentModel/validateModelFields.js +42 -34
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel.crud.js +222 -169
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
- package/crud/contentModelGroup/beforeCreate.js +3 -3
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
- package/crud/contentModelGroup/beforeDelete.js +3 -3
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
- package/crud/contentModelGroup/beforeUpdate.js +2 -2
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup.crud.js +87 -37
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/index.js +3 -7
- package/crud/index.js.map +1 -1
- package/crud/settings.crud.js +3 -8
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +63 -51
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +17 -19
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +27 -17
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +4 -8
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +1 -1
- package/graphql/schema/contentModels.js +18 -1
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +12 -14
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +4 -18
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +7 -10
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +3 -7
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.js +5 -3
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +5 -9
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +3 -7
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +3 -7
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +21 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +3 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +4 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +123 -73
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +23 -23
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.d.ts +7 -7
- package/modelManager/DefaultCmsModelManager.js +1 -1
- package/package.json +27 -28
- package/parameters/header.js +1 -1
- package/parameters/manual.js +7 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +1 -1
- package/plugins/CmsGroupPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +6 -2
- package/plugins/CmsModelPlugin.js +18 -13
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/storage/object.js +7 -8
- package/storage/object.js.map +1 -1
- package/types.d.ts +436 -164
- package/types.js +50 -9
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +5 -9
- package/upgrades/5.33.0/index.js.map +1 -1
- package/utils/converters/Converter.js +1 -1
- package/utils/converters/ConverterCollection.js +10 -8
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +3 -7
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +75 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +4 -2
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +17 -18
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterModelFields.js +5 -9
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/permissions.js +1 -5
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +1 -1
- package/utils/renderFields.js +3 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +8 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +12 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +3 -1
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +24 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +3 -1
- package/validators/index.js.map +1 -1
- package/validators/unique.js +1 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHeadlessCmsGraphQL","params","createPathParameterPlugin","createHeaderParameterPlugin","createContextParameterPlugin","baseCreateGraphQL","createHeadlessCmsContext","createContextPlugin","createDefaultModelManager","createCrud","createGraphQLFields","createFieldConverters","createValidators","createDefaultStorageTransform","createObjectStorageTransform","createUpgrades"],"sources":["index.ts"],"sourcesContent":["import { createGraphQL as baseCreateGraphQL, CreateGraphQLParams } from \"~/graphql\";\nimport { createUpgrades } from \"~/upgrades\";\nimport { createDefaultModelManager } from \"~/modelManager\";\nimport { createCrud, CrudParams } from \"~/crud\";\nimport { createGraphQLFields } from \"~/graphqlFields\";\nimport { createValidators } from \"~/validators\";\nimport { createDefaultStorageTransform } from \"~/storage/default\";\nimport { createObjectStorageTransform } from \"~/storage/object\";\nimport {\n createContextParameterPlugin,\n createHeaderParameterPlugin,\n createPathParameterPlugin\n} from \"~/parameters\";\nimport { createContextPlugin } from \"~/context\";\nimport {\n entryFieldFromStorageTransform,\n entryFromStorageTransform,\n entryToStorageTransform\n} from \"./utils/entryStorage\";\nimport { createFieldConverters } from \"~/fieldConverters\";\n\nexport type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;\nexport const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}) => {\n return [\n /**\n * PathParameter plugins are used to determine the type of the cms endpoint\n */\n createPathParameterPlugin(),\n createHeaderParameterPlugin(),\n createContextParameterPlugin(),\n /**\n * At this point we can create, or not create, CMS GraphQL Schema.\n */\n baseCreateGraphQL(params)\n ];\n};\n\nexport type ContentContextParams = CrudParams;\nexport const createHeadlessCmsContext = (params: ContentContextParams) => {\n return [\n /**\n * Context for all Lambdas - everything is loaded now.\n */\n createContextPlugin(),\n createDefaultModelManager(),\n /**\n *\n */\n createCrud(params),\n createGraphQLFields(),\n createFieldConverters(),\n createValidators(),\n createDefaultStorageTransform(),\n createObjectStorageTransform(),\n createUpgrades()\n ];\n};\nexport * from \"~/graphqlFields\";\nexport * from \"~/plugins\";\nexport { entryToStorageTransform, entryFieldFromStorageTransform, entryFromStorageTransform };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"names":["createHeadlessCmsGraphQL","params","createPathParameterPlugin","createHeaderParameterPlugin","createContextParameterPlugin","baseCreateGraphQL","createHeadlessCmsContext","createContextPlugin","createDefaultModelManager","createCrud","createGraphQLFields","createFieldConverters","createValidators","createDefaultStorageTransform","createObjectStorageTransform","createDynamicZoneStorageTransform","createUpgrades"],"sources":["index.ts"],"sourcesContent":["import { createGraphQL as baseCreateGraphQL, CreateGraphQLParams } from \"~/graphql\";\nimport { createUpgrades } from \"~/upgrades\";\nimport { createDefaultModelManager } from \"~/modelManager\";\nimport { createCrud, CrudParams } from \"~/crud\";\nimport { createGraphQLFields } from \"~/graphqlFields\";\nimport { createValidators } from \"~/validators\";\nimport { createDefaultStorageTransform } from \"~/storage/default\";\nimport { createObjectStorageTransform } from \"~/storage/object\";\nimport { createDynamicZoneStorageTransform } from \"~/graphqlFields/dynamicZone/dynamicZoneStorage\";\nimport {\n createContextParameterPlugin,\n createHeaderParameterPlugin,\n createPathParameterPlugin\n} from \"~/parameters\";\nimport { createContextPlugin } from \"~/context\";\nimport {\n entryFieldFromStorageTransform,\n entryFromStorageTransform,\n entryToStorageTransform\n} from \"./utils/entryStorage\";\nimport { createFieldConverters } from \"~/fieldConverters\";\n\nexport type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;\nexport const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}) => {\n return [\n /**\n * PathParameter plugins are used to determine the type of the cms endpoint\n */\n createPathParameterPlugin(),\n createHeaderParameterPlugin(),\n createContextParameterPlugin(),\n /**\n * At this point we can create, or not create, CMS GraphQL Schema.\n */\n baseCreateGraphQL(params)\n ];\n};\n\nexport type ContentContextParams = CrudParams;\nexport const createHeadlessCmsContext = (params: ContentContextParams) => {\n return [\n /**\n * Context for all Lambdas - everything is loaded now.\n */\n createContextPlugin(),\n createDefaultModelManager(),\n /**\n *\n */\n createCrud(params),\n createGraphQLFields(),\n createFieldConverters(),\n createValidators(),\n createDefaultStorageTransform(),\n createObjectStorageTransform(),\n createDynamicZoneStorageTransform(),\n createUpgrades()\n ];\n};\nexport * from \"~/graphqlFields\";\nexport * from \"~/plugins\";\nexport { entryToStorageTransform, entryFieldFromStorageTransform, entryFromStorageTransform };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAuDA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAtDA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AAwCA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AArCO,MAAMA,wBAAwB,GAAG,CAACC,MAAsC,GAAG,EAA1C,KAAiD;EACrF,OAAO;EACH;AACR;AACA;EACQ,IAAAC,qCAAA,GAJG,EAKH,IAAAC,uCAAA,GALG,EAMH,IAAAC,wCAAA,GANG;EAOH;AACR;AACA;EACQ,IAAAC,sBAAA,EAAkBJ,MAAlB,CAVG,CAAP;AAYH,CAbM;;;;AAgBA,MAAMK,wBAAwB,GAAIL,MAAD,IAAkC;EACtE,OAAO;EACH;AACR;AACA;EACQ,IAAAM,4BAAA,GAJG,EAKH,IAAAC,uCAAA,GALG;EAMH;AACR;AACA;EACQ,IAAAC,gBAAA,EAAWR,MAAX,CATG,EAUH,IAAAS,kCAAA,GAVG,EAWH,IAAAC,sCAAA,GAXG,EAYH,IAAAC,4BAAA,GAZG,EAaH,IAAAC,sCAAA,GAbG,EAcH,IAAAC,oCAAA,GAdG,EAeH,IAAAC,qDAAA,GAfG,EAgBH,IAAAC,wBAAA,GAhBG,CAAP;AAkBH,CAnBM"}
|
|
@@ -3,12 +3,12 @@ export declare class DefaultCmsModelManager implements CmsModelManager {
|
|
|
3
3
|
private readonly _context;
|
|
4
4
|
private readonly _model;
|
|
5
5
|
constructor(context: CmsContext, model: CmsModel);
|
|
6
|
-
create(data: CreateCmsEntryInput): Promise<import("../types").CmsEntry
|
|
6
|
+
create(data: CreateCmsEntryInput): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
7
7
|
delete(id: string): Promise<void>;
|
|
8
|
-
get(id: string): Promise<import("../types").CmsEntry
|
|
9
|
-
listPublished(params: CmsEntryListParams): Promise<[import("../types").CmsEntry[], import("../types").CmsEntryMeta]>;
|
|
10
|
-
listLatest(params: CmsEntryListParams): Promise<[import("../types").CmsEntry[], import("../types").CmsEntryMeta]>;
|
|
11
|
-
getPublishedByIds(ids: string[]): Promise<import("../types").CmsEntry[]>;
|
|
12
|
-
getLatestByIds(ids: string[]): Promise<import("../types").CmsEntry[]>;
|
|
13
|
-
update(id: string, data: UpdateCmsEntryInput): Promise<import("../types").CmsEntry
|
|
8
|
+
get(id: string): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
9
|
+
listPublished(params: CmsEntryListParams): Promise<[import("../types").CmsEntry<import("~/types").CmsEntryValues>[], import("../types").CmsEntryMeta]>;
|
|
10
|
+
listLatest(params: CmsEntryListParams): Promise<[import("../types").CmsEntry<import("~/types").CmsEntryValues>[], import("../types").CmsEntryMeta]>;
|
|
11
|
+
getPublishedByIds(ids: string[]): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>[]>;
|
|
12
|
+
getLatestByIds(ids: string[]): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>[]>;
|
|
13
|
+
update(id: string, data: UpdateCmsEntryInput): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.34.0-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms:base"
|
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
21
|
+
"@babel/runtime": "7.19.0",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
23
|
"@graphql-tools/schema": "7.1.5",
|
|
24
|
-
"@webiny/api": "5.
|
|
25
|
-
"@webiny/api-file-manager": "5.
|
|
26
|
-
"@webiny/api-i18n": "5.
|
|
27
|
-
"@webiny/api-i18n-ddb": "5.
|
|
28
|
-
"@webiny/api-security": "5.
|
|
29
|
-
"@webiny/api-tenancy": "5.
|
|
30
|
-
"@webiny/api-upgrade": "5.
|
|
31
|
-
"@webiny/error": "5.
|
|
32
|
-
"@webiny/handler": "5.
|
|
33
|
-
"@webiny/handler-aws": "5.
|
|
34
|
-
"@webiny/handler-db": "5.
|
|
35
|
-
"@webiny/handler-graphql": "5.
|
|
36
|
-
"@webiny/plugins": "5.
|
|
37
|
-
"@webiny/pubsub": "5.
|
|
38
|
-
"@webiny/utils": "5.
|
|
39
|
-
"@webiny/validation": "5.
|
|
24
|
+
"@webiny/api": "5.34.0-beta.1",
|
|
25
|
+
"@webiny/api-file-manager": "5.34.0-beta.1",
|
|
26
|
+
"@webiny/api-i18n": "5.34.0-beta.1",
|
|
27
|
+
"@webiny/api-i18n-ddb": "5.34.0-beta.1",
|
|
28
|
+
"@webiny/api-security": "5.34.0-beta.1",
|
|
29
|
+
"@webiny/api-tenancy": "5.34.0-beta.1",
|
|
30
|
+
"@webiny/api-upgrade": "5.34.0-beta.1",
|
|
31
|
+
"@webiny/error": "5.34.0-beta.1",
|
|
32
|
+
"@webiny/handler": "5.34.0-beta.1",
|
|
33
|
+
"@webiny/handler-aws": "5.34.0-beta.1",
|
|
34
|
+
"@webiny/handler-db": "5.34.0-beta.1",
|
|
35
|
+
"@webiny/handler-graphql": "5.34.0-beta.1",
|
|
36
|
+
"@webiny/plugins": "5.34.0-beta.1",
|
|
37
|
+
"@webiny/pubsub": "5.34.0-beta.1",
|
|
38
|
+
"@webiny/utils": "5.34.0-beta.1",
|
|
39
|
+
"@webiny/validation": "5.34.0-beta.1",
|
|
40
40
|
"code-frame": "5.0.0",
|
|
41
41
|
"commodo-fields-object": "1.0.6",
|
|
42
42
|
"dataloader": "2.1.0",
|
|
@@ -50,15 +50,14 @@
|
|
|
50
50
|
"slugify": "1.6.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@babel/cli": "^7.
|
|
54
|
-
"@babel/core": "^7.
|
|
55
|
-
"@babel/preset-env": "^7.
|
|
56
|
-
"@
|
|
57
|
-
"@webiny/api-
|
|
58
|
-
"@webiny/api-
|
|
59
|
-
"@webiny/
|
|
60
|
-
"@webiny/
|
|
61
|
-
"@webiny/project-utils": "^5.33.5",
|
|
53
|
+
"@babel/cli": "^7.19.3",
|
|
54
|
+
"@babel/core": "^7.19.3",
|
|
55
|
+
"@babel/preset-env": "^7.19.4",
|
|
56
|
+
"@webiny/api-security-so-ddb": "^5.34.0-beta.1",
|
|
57
|
+
"@webiny/api-tenancy-so-ddb": "^5.34.0-beta.1",
|
|
58
|
+
"@webiny/api-wcp": "^5.34.0-beta.1",
|
|
59
|
+
"@webiny/cli": "^5.34.0-beta.1",
|
|
60
|
+
"@webiny/project-utils": "^5.34.0-beta.1",
|
|
62
61
|
"apollo-graphql": "^0.9.5",
|
|
63
62
|
"get-yarn-workspaces": "^1.0.2",
|
|
64
63
|
"graphql": "^15.7.2",
|
|
@@ -78,5 +77,5 @@
|
|
|
78
77
|
"build": "yarn webiny run build",
|
|
79
78
|
"watch": "yarn webiny run watch"
|
|
80
79
|
},
|
|
81
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "1ee2a7338a865a67e24eb42d16bf0b6091195286"
|
|
82
81
|
}
|
package/parameters/header.js
CHANGED
package/parameters/manual.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createManualPlugin = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
14
14
|
var _CmsParametersPlugin = require("../plugins/CmsParametersPlugin");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/**
|
|
17
|
+
* This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.
|
|
18
|
+
*/
|
|
20
19
|
const createManualPlugin = params => {
|
|
21
20
|
return new _CmsParametersPlugin.CmsParametersPlugin(async () => {
|
|
22
21
|
const {
|
|
@@ -30,9 +29,9 @@ const createManualPlugin = params => {
|
|
|
30
29
|
if (!type && !locale) {
|
|
31
30
|
return null;
|
|
32
31
|
} else if (!type) {
|
|
33
|
-
throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE",
|
|
32
|
+
throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE", (0, _objectSpread2.default)({}, params));
|
|
34
33
|
} else if (!locale) {
|
|
35
|
-
throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE",
|
|
34
|
+
throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE", (0, _objectSpread2.default)({}, params));
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
return {
|
package/parameters/manual.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;;;;;AAGA;;AACA
|
|
1
|
+
{"version":3,"names":["createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAaO,MAAMA,kBAAkB,GAAIC,MAAD,IAAqD;EACnF,OAAO,IAAIC,wCAAJ,CAAwB,YAAY;IACvC,MAAM;MAAEC,YAAY,EAAEC,IAAhB;MAAsBC;IAAtB,IAAiCJ,MAAvC;IACA;AACR;AACA;;IACQ,IAAI,CAACG,IAAD,IAAS,CAACC,MAAd,EAAsB;MAClB,OAAO,IAAP;IACH,CAFD,MAEO,IAAI,CAACD,IAAL,EAAW;MACd,MAAM,IAAIE,cAAJ,CACD,gEADC,EAEF,yBAFE,kCAIKL,MAJL,EAAN;IAOH,CARM,MAQA,IAAI,CAACI,MAAL,EAAa;MAChB,MAAM,IAAIC,cAAJ,CACD,gEADC,EAEF,uBAFE,kCAIKL,MAJL,EAAN;IAOH;;IAED,OAAO;MACHG,IADG;MAEHC;IAFG,CAAP;EAIH,CA7BM,CAAP;AA8BH,CA/BM"}
|
package/parameters/path.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { CmsEntryValues, CmsModelFieldWithParent } from "../types";
|
|
3
3
|
import { ConverterCollection } from "../utils/converters/ConverterCollection";
|
|
4
|
-
export interface ConvertParams {
|
|
5
|
-
field:
|
|
4
|
+
export interface ConvertParams<F = CmsModelFieldWithParent> {
|
|
5
|
+
field: F;
|
|
6
6
|
value: any;
|
|
7
7
|
converterCollection: ConverterCollection;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CmsModelFieldConverterPlugin","Plugin"],"sources":["CmsModelFieldConverterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsEntryValues, CmsModelFieldWithParent } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\nexport interface ConvertParams {\n field:
|
|
1
|
+
{"version":3,"names":["CmsModelFieldConverterPlugin","Plugin"],"sources":["CmsModelFieldConverterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsEntryValues, CmsModelFieldWithParent } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\nexport interface ConvertParams<F = CmsModelFieldWithParent> {\n field: F;\n value: any;\n converterCollection: ConverterCollection;\n}\n\nexport abstract class CmsModelFieldConverterPlugin extends Plugin {\n public static override type = \"cms.field.converter\";\n\n public abstract getFieldType(): string;\n\n public abstract convertToStorage(params: ConvertParams): CmsEntryValues;\n public abstract convertFromStorage(params: ConvertParams): CmsEntryValues;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAUO,MAAeA,4BAAf,SAAoDC,eAApD,CAA2D;;;8BAA5CD,4B,UACY,qB"}
|
|
@@ -29,13 +29,17 @@ interface CmsModel extends Omit<CmsModelBase, "locale" | "tenant" | "webinyVersi
|
|
|
29
29
|
locale?: string;
|
|
30
30
|
tenant?: string;
|
|
31
31
|
}
|
|
32
|
+
interface CmsModelPluginOptions {
|
|
33
|
+
validateLayout?: boolean;
|
|
34
|
+
}
|
|
32
35
|
export declare class CmsModelPlugin extends Plugin {
|
|
33
36
|
static readonly type: string;
|
|
34
37
|
readonly contentModel: CmsModel;
|
|
35
|
-
|
|
38
|
+
private readonly options;
|
|
39
|
+
constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions);
|
|
36
40
|
private buildModel;
|
|
37
41
|
private buildFields;
|
|
38
42
|
private validateLayout;
|
|
39
43
|
}
|
|
40
|
-
export declare const createCmsModel: (model: CmsModelInput) => CmsModelPlugin;
|
|
44
|
+
export declare const createCmsModel: (model: CmsModelInput, options?: CmsModelPluginOptions) => CmsModelPlugin;
|
|
41
45
|
export {};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createCmsModel = exports.CmsModelPlugin = void 0;
|
|
9
9
|
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
13
|
|
|
12
14
|
var _plugins = require("@webiny/plugins");
|
|
@@ -17,22 +19,19 @@ var _createFieldStorageId = require("../crud/contentModel/createFieldStorageId")
|
|
|
17
19
|
|
|
18
20
|
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
19
21
|
|
|
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
|
-
|
|
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
|
-
|
|
24
22
|
class CmsModelPlugin extends _plugins.Plugin {
|
|
25
|
-
constructor(contentModel) {
|
|
23
|
+
constructor(contentModel, options) {
|
|
26
24
|
super();
|
|
27
25
|
(0, _defineProperty2.default)(this, "contentModel", void 0);
|
|
26
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
27
|
+
this.options = options || {};
|
|
28
28
|
this.contentModel = this.buildModel(contentModel);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
buildModel(input) {
|
|
32
|
-
const model =
|
|
32
|
+
const model = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
|
|
33
33
|
fields: this.buildFields(input, input.fields)
|
|
34
34
|
});
|
|
35
|
-
|
|
36
35
|
this.validateLayout(model);
|
|
37
36
|
return model;
|
|
38
37
|
}
|
|
@@ -130,12 +129,12 @@ class CmsModelPlugin extends _plugins.Plugin {
|
|
|
130
129
|
const childFields = ((_settings = settings) === null || _settings === void 0 ? void 0 : _settings.fields) || [];
|
|
131
130
|
|
|
132
131
|
if (input.type === "object" && childFields.length > 0) {
|
|
133
|
-
settings =
|
|
132
|
+
settings = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings || {}), {}, {
|
|
134
133
|
fields: this.buildFields(model, childFields)
|
|
135
134
|
});
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
const field =
|
|
137
|
+
const field = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
|
|
139
138
|
settings,
|
|
140
139
|
storageId
|
|
141
140
|
});
|
|
@@ -143,7 +142,6 @@ class CmsModelPlugin extends _plugins.Plugin {
|
|
|
143
142
|
* Add all relevant data to arrays.
|
|
144
143
|
*/
|
|
145
144
|
|
|
146
|
-
|
|
147
145
|
fields.push(field);
|
|
148
146
|
storageIdList.push(field.storageId);
|
|
149
147
|
fieldIdList.push(field.fieldId);
|
|
@@ -153,6 +151,13 @@ class CmsModelPlugin extends _plugins.Plugin {
|
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
validateLayout(model) {
|
|
154
|
+
/**
|
|
155
|
+
* Only skip validation if option.validateLayout was set as false, explicitly.
|
|
156
|
+
*/
|
|
157
|
+
if (this.options.validateLayout === false) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
156
161
|
for (const field of model.fields) {
|
|
157
162
|
let total = 0;
|
|
158
163
|
|
|
@@ -182,8 +187,8 @@ class CmsModelPlugin extends _plugins.Plugin {
|
|
|
182
187
|
exports.CmsModelPlugin = CmsModelPlugin;
|
|
183
188
|
(0, _defineProperty2.default)(CmsModelPlugin, "type", "cms-content-model");
|
|
184
189
|
|
|
185
|
-
const createCmsModel = model => {
|
|
186
|
-
return new CmsModelPlugin(model);
|
|
190
|
+
const createCmsModel = (model, options) => {
|
|
191
|
+
return new CmsModelPlugin(model, options);
|
|
187
192
|
};
|
|
188
193
|
|
|
189
194
|
exports.createCmsModel = createCmsModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CmsModelPlugin","Plugin","constructor","contentModel","buildModel","input","model","fields","buildFields","validateLayout","inputFields","length","WebinyError","modelId","storageIdList","fieldIdList","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","type","push","total","row","layout","count","filter","cell","id","createCmsModel"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\nimport lodashCamelCase from \"lodash/camelCase\";\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\ninterface CmsModelInput\n extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\" | \"fields\"> {\n fields: CmsModelFieldInput[];\n locale?: string;\n tenant?: string;\n}\ninterface CmsModel extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModel;\n\n constructor(contentModel: CmsModelInput) {\n super();\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModel {\n const model: CmsModel = {\n ...input,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId) === true) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId) === true) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-ignore\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModel): void {\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (model: CmsModelInput): CmsModelPlugin => {\n return new CmsModelPlugin(model);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAMA;;AACA;;AACA;;;;;;AAmCO,MAAMA,cAAN,SAA6BC,eAA7B,CAAoC;EAIvCC,WAAW,CAACC,YAAD,EAA8B;IACrC;IADqC;IAErC,KAAKA,YAAL,GAAoB,KAAKC,UAAL,CAAgBD,YAAhB,CAApB;EACH;;EAEOC,UAAU,CAACC,KAAD,EAAiC;IAC/C,MAAMC,KAAe,mCACdD,KADc;MAEjBE,MAAM,EAAE,KAAKC,WAAL,CAAiBH,KAAjB,EAAwBA,KAAK,CAACE,MAA9B;IAFS,EAArB;;IAIA,KAAKE,cAAL,CAAoBH,KAApB;IACA,OAAOA,KAAP;EACH;;EAEOE,WAAW,CACfF,KADe,EAEfI,WAFe,EAGI;IACnB,IAAIA,WAAW,CAACC,MAAZ,KAAuB,CAA3B,EAA8B;MAC1B,MAAM,IAAIC,cAAJ,CACD,yCAAwCN,KAAK,CAACO,OAAQ,IADrD,EAEF,gBAFE,EAGF;QACIP;MADJ,CAHE,CAAN;IAOH;;IACD,MAAMC,MAA2B,GAAG,EAApC;IACA,MAAMO,aAAuB,GAAG,EAAhC;IACA,MAAMC,WAAqB,GAAG,EAA9B;;IACA,KAAK,MAAMV,KAAX,IAAoBK,WAApB,EAAiC;MAAA;;MAC7B;AACZ;AACA;MACY,IAAI,CAAC,CAACL,KAAK,CAACW,OAAN,IAAiB,EAAlB,EAAsBC,IAAtB,EAAL,EAAmC;QAC/B,MAAM,IAAIL,cAA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AC5B,MAAMC,KAAK,GAAGF,GAAG,CAACG,MAAJ,CAAWC,IAAI,IAAIA,IAAI,KAAKf,KAAK,CAACgB,EAAlC,EAAsCvB,MAApD;QACAiB,KAAK,GAAGA,KAAK,GAAGG,KAAhB;MACH;;MACD,IAAIH,KAAK,KAAK,CAAd,EAAiB;QACb;MACH,CAFD,MAEO,IAAIA,KAAK,GAAG,CAAZ,EAAe;QAClB,MAAM,IAAIhB,cAAJ,CACD,UAASM,KAAK,CAACgB,EAAG,oCADjB,EAEF,2BAFE,EAGF;UACI5B,KADJ;UAEIY;QAFJ,CAHE,CAAN;MAQH;;MACD,MAAM,IAAIN,cAAJ,CACD,kBAAiBM,KAAK,CAACgB,EAAG,cADzB,EAEF,yBAFE,EAGF;QACI5B,KADJ;QAEIY;MAFJ,CAHE,CAAN;IAQH;EACJ;;AArLsC;;;8BAA9BlB,c,UACsC,mB;;AAuL5C,MAAMmC,cAAc,GAAI7B,KAAD,IAA0C;EACpE,OAAO,IAAIN,cAAJ,CAAmBM,KAAnB,CAAP;AACH,CAFM"}
|
|
1
|
+
{"version":3,"names":["CmsModelPlugin","Plugin","constructor","contentModel","options","buildModel","input","model","fields","buildFields","validateLayout","inputFields","length","WebinyError","modelId","storageIdList","fieldIdList","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","type","push","total","row","layout","count","filter","cell","id","createCmsModel"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\nimport lodashCamelCase from \"lodash/camelCase\";\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\ninterface CmsModelInput\n extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\" | \"fields\"> {\n fields: CmsModelFieldInput[];\n locale?: string;\n tenant?: string;\n}\ninterface CmsModel extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\ninterface CmsModelPluginOptions {\n validateLayout?: boolean;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModel;\n\n private readonly options: CmsModelPluginOptions;\n\n constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions) {\n super();\n this.options = options || {};\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModel {\n const model: CmsModel = {\n ...input,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId) === true) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId) === true) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-ignore\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModel): void {\n /**\n * Only skip validation if option.validateLayout was set as false, explicitly.\n */\n if (this.options.validateLayout === false) {\n return;\n }\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (\n model: CmsModelInput,\n options?: CmsModelPluginOptions\n): CmsModelPlugin => {\n return new CmsModelPlugin(model, options);\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAMA;;AACA;;AACA;;AAuCO,MAAMA,cAAN,SAA6BC,eAA7B,CAAoC;EAMvCC,WAAW,CAACC,YAAD,EAA8BC,OAA9B,EAA+D;IACtE;IADsE;IAAA;IAEtE,KAAKA,OAAL,GAAeA,OAAO,IAAI,EAA1B;IACA,KAAKD,YAAL,GAAoB,KAAKE,UAAL,CAAgBF,YAAhB,CAApB;EACH;;EAEOE,UAAU,CAACC,KAAD,EAAiC;IAC/C,MAAMC,KAAe,+DACdD,KADc;MAEjBE,MAAM,EAAE,KAAKC,WAAL,CAAiBH,KAAjB,EAAwBA,KAAK,CAACE,MAA9B;IAFS,EAArB;IAIA,KAAKE,cAAL,CAAoBH,KAApB;IACA,OAAOA,KAAP;EACH;;EAEOE,WAAW,CACfF,KADe,EAEfI,WAFe,EAGI;IACnB,IAAIA,WAAW,CAACC,MAAZ,KAAuB,CAA3B,EAA8B;MAC1B,MAAM,IAAIC,cAAJ,CACD,yCAAwCN,KAAK,CAACO,OAA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3
3
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
export interface ToStorageParams<T> {
|
|
4
|
+
export interface ToStorageParams<T, F extends CmsModelField> {
|
|
5
5
|
model: CmsModel;
|
|
6
|
-
field:
|
|
6
|
+
field: F;
|
|
7
7
|
value: T;
|
|
8
8
|
getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;
|
|
9
9
|
plugins: PluginsContainer;
|
|
10
10
|
}
|
|
11
|
-
export interface FromStorageParams<T> {
|
|
11
|
+
export interface FromStorageParams<T, F extends CmsModelField> {
|
|
12
12
|
model: CmsModel;
|
|
13
|
-
field:
|
|
13
|
+
field: Partial<F> & Pick<F, "id" | "fieldId" | "storageId" | "type" | "settings">;
|
|
14
14
|
value: T;
|
|
15
15
|
getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;
|
|
16
16
|
plugins: PluginsContainer;
|
|
17
17
|
}
|
|
18
|
-
export interface StorageTransformPluginParams<T, R> {
|
|
18
|
+
export interface StorageTransformPluginParams<T, R, F extends CmsModelField> {
|
|
19
19
|
name?: string;
|
|
20
20
|
fieldType: string;
|
|
21
|
-
toStorage: (params: ToStorageParams<T>) => Promise<R>;
|
|
22
|
-
fromStorage: (params: FromStorageParams<R>) => Promise<T>;
|
|
21
|
+
toStorage: (params: ToStorageParams<T, F>) => Promise<R>;
|
|
22
|
+
fromStorage: (params: FromStorageParams<R, F>) => Promise<T>;
|
|
23
23
|
}
|
|
24
|
-
export declare class StorageTransformPlugin<T = any, R = any> extends Plugin {
|
|
24
|
+
export declare class StorageTransformPlugin<T = any, R = any, F extends CmsModelField = CmsModelField> extends Plugin {
|
|
25
25
|
static readonly type: string;
|
|
26
26
|
get fieldType(): string;
|
|
27
27
|
private readonly config;
|
|
28
|
-
constructor(config: StorageTransformPluginParams<T, R>);
|
|
29
|
-
toStorage(params: ToStorageParams<T>): Promise<R>;
|
|
30
|
-
fromStorage(params: FromStorageParams<R>): Promise<T>;
|
|
28
|
+
constructor(config: StorageTransformPluginParams<T, R, F>);
|
|
29
|
+
toStorage(params: ToStorageParams<T, F>): Promise<R>;
|
|
30
|
+
fromStorage(params: FromStorageParams<R, F>): Promise<T>;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StorageTransformPlugin","Plugin","fieldType","config","constructor","name","toStorage","params","fromStorage"],"sources":["StorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModel, CmsModelField } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\nexport interface ToStorageParams<T> {\n model: CmsModel;\n field:
|
|
1
|
+
{"version":3,"names":["StorageTransformPlugin","Plugin","fieldType","config","constructor","name","toStorage","params","fromStorage"],"sources":["StorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModel, CmsModelField } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\nexport interface ToStorageParams<T, F extends CmsModelField> {\n model: CmsModel;\n field: F;\n value: T;\n getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;\n plugins: PluginsContainer;\n}\n\nexport interface FromStorageParams<T, F extends CmsModelField> {\n model: CmsModel;\n field: Partial<F> & Pick<F, \"id\" | \"fieldId\" | \"storageId\" | \"type\" | \"settings\">;\n value: T;\n getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;\n plugins: PluginsContainer;\n}\n\nexport interface StorageTransformPluginParams<T, R, F extends CmsModelField> {\n name?: string;\n fieldType: string;\n toStorage: (params: ToStorageParams<T, F>) => Promise<R>;\n fromStorage: (params: FromStorageParams<R, F>) => Promise<T>;\n}\nexport class StorageTransformPlugin<\n T = any,\n R = any,\n F extends CmsModelField = CmsModelField\n> extends Plugin {\n public static override readonly type: string = \"cms.storage.transform.plugin\";\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n private readonly config: StorageTransformPluginParams<T, R, F>;\n\n public constructor(config: StorageTransformPluginParams<T, R, F>) {\n super();\n this.name = config.name;\n this.config = config;\n }\n\n public toStorage(params: ToStorageParams<T, F>): Promise<R> {\n return this.config.toStorage(params);\n }\n\n public fromStorage(params: FromStorageParams<R, F>): Promise<T> {\n return this.config.fromStorage(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AA0BO,MAAMA,sBAAN,SAIGC,cAJH,CAIU;EAEO,IAATC,SAAS,GAAW;IAC3B,OAAO,KAAKC,MAAL,CAAYD,SAAnB;EACH;;EAIME,WAAW,CAACD,MAAD,EAAgD;IAC9D;IAD8D;IAE9D,KAAKE,IAAL,GAAYF,MAAM,CAACE,IAAnB;IACA,KAAKF,MAAL,GAAcA,MAAd;EACH;;EAEMG,SAAS,CAACC,MAAD,EAA4C;IACxD,OAAO,KAAKJ,MAAL,CAAYG,SAAZ,CAAsBC,MAAtB,CAAP;EACH;;EAEMC,WAAW,CAACD,MAAD,EAA8C;IAC5D,OAAO,KAAKJ,MAAL,CAAYK,WAAZ,CAAwBD,MAAxB,CAAP;EACH;;AApBY;;;8BAJJP,sB,UAKsC,8B"}
|
package/storage/object.js
CHANGED
|
@@ -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").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createObjectStorageTransform = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _pReduce = _interopRequireDefault(require("p-reduce"));
|
|
13
13
|
|
|
@@ -15,9 +15,7 @@ var _pMap = _interopRequireDefault(require("p-map"));
|
|
|
15
15
|
|
|
16
16
|
var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
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; }
|
|
18
|
+
var _getBaseFieldType = require("../utils/getBaseFieldType");
|
|
21
19
|
|
|
22
20
|
const processValue = async params => {
|
|
23
21
|
const {
|
|
@@ -29,10 +27,11 @@ const processValue = async params => {
|
|
|
29
27
|
operation
|
|
30
28
|
} = params;
|
|
31
29
|
return await (0, _pReduce.default)(fields, async (values, field) => {
|
|
32
|
-
const
|
|
30
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
31
|
+
const plugin = getStoragePlugin(baseType);
|
|
33
32
|
|
|
34
33
|
if (!plugin) {
|
|
35
|
-
throw new Error(`Missing storage plugin for field type "${
|
|
34
|
+
throw new Error(`Missing storage plugin for field type "${baseType}".`);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
const value = await plugin[operation]({
|
|
@@ -42,7 +41,7 @@ const processValue = async params => {
|
|
|
42
41
|
value: sourceValue[field.fieldId],
|
|
43
42
|
getStoragePlugin
|
|
44
43
|
});
|
|
45
|
-
return
|
|
44
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, values), {}, {
|
|
46
45
|
[field.fieldId]: value
|
|
47
46
|
});
|
|
48
47
|
}, {});
|
package/storage/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["processValue","params","fields","sourceValue","getStoragePlugin","plugins","model","operation","pReduce","values","field","
|
|
1
|
+
{"version":3,"names":["processValue","params","fields","sourceValue","getStoragePlugin","plugins","model","operation","pReduce","values","field","baseType","getBaseFieldType","plugin","Error","value","fieldId","createObjectStorageTransform","StorageTransformPlugin","name","fieldType","toStorage","settings","multipleValues","pMap","fromStorage"],"sources":["object.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport pMap from \"p-map\";\nimport { CmsModel, CmsModelField } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface ProcessValueParams {\n fields: CmsModelField[];\n sourceValue: Record<string, any>;\n getStoragePlugin: (fieldType: string) => StorageTransformPlugin;\n plugins: PluginsContainer;\n model: CmsModel;\n operation: \"toStorage\" | \"fromStorage\";\n}\ninterface ProcessValue {\n (params: ProcessValueParams): Promise<Record<string, any>>;\n}\n\nconst processValue: ProcessValue = async params => {\n const { fields, sourceValue, getStoragePlugin, plugins, model, operation } = params;\n return await pReduce(\n fields,\n async (values, field) => {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n if (!plugin) {\n throw new Error(`Missing storage plugin for field type \"${baseType}\".`);\n }\n const value = await plugin[operation]({\n plugins,\n model,\n field,\n value: sourceValue[field.fieldId],\n getStoragePlugin\n });\n return { ...values, [field.fieldId]: value };\n },\n {}\n );\n};\n\nexport const createObjectStorageTransform = (): StorageTransformPlugin => {\n return new StorageTransformPlugin({\n name: \"headless-cms.storage-transform.object.default\",\n fieldType: \"object\",\n toStorage: async ({ field, value, getStoragePlugin, model, plugins }) => {\n if (!value) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.multipleValues) {\n return await pMap(value as Record<string, any>[], value =>\n processValue({\n sourceValue: value,\n getStoragePlugin,\n model,\n plugins,\n operation: \"toStorage\",\n fields\n })\n );\n }\n\n return await processValue({\n sourceValue: value,\n getStoragePlugin,\n model,\n plugins,\n operation: \"toStorage\",\n fields\n });\n },\n fromStorage: async ({ field, value, getStoragePlugin, plugins, model }) => {\n if (!value) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.multipleValues) {\n return pMap(value as Record<string, any>[], value =>\n processValue({\n sourceValue: value,\n getStoragePlugin,\n model,\n plugins,\n operation: \"fromStorage\",\n fields\n })\n );\n }\n\n return processValue({\n sourceValue: value,\n getStoragePlugin,\n model,\n plugins,\n operation: \"fromStorage\",\n fields\n });\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAcA,MAAMA,YAA0B,GAAG,MAAMC,MAAN,IAAgB;EAC/C,MAAM;IAAEC,MAAF;IAAUC,WAAV;IAAuBC,gBAAvB;IAAyCC,OAAzC;IAAkDC,KAAlD;IAAyDC;EAAzD,IAAuEN,MAA7E;EACA,OAAO,MAAM,IAAAO,gBAAA,EACTN,MADS,EAET,OAAOO,MAAP,EAAeC,KAAf,KAAyB;IACrB,MAAMC,QAAQ,GAAG,IAAAC,kCAAA,EAAiBF,KAAjB,CAAjB;IACA,MAAMG,MAAM,GAAGT,gBAAgB,CAACO,QAAD,CAA/B;;IACA,IAAI,CAACE,MAAL,EAAa;MACT,MAAM,IAAIC,KAAJ,CAAW,0CAAyCH,QAAS,IAA7D,CAAN;IACH;;IACD,MAAMI,KAAK,GAAG,MAAMF,MAAM,CAACN,SAAD,CAAN,CAAkB;MAClCF,OADkC;MAElCC,KAFkC;MAGlCI,KAHkC;MAIlCK,KAAK,EAAEZ,WAAW,CAACO,KAAK,CAACM,OAAP,CAJgB;MAKlCZ;IALkC,CAAlB,CAApB;IAOA,mEAAYK,MAAZ;MAAoB,CAACC,KAAK,CAACM,OAAP,GAAiBD;IAArC;EACH,CAhBQ,EAiBT,EAjBS,CAAb;AAmBH,CArBD;;AAuBO,MAAME,4BAA4B,GAAG,MAA8B;EACtE,OAAO,IAAIC,8CAAJ,CAA2B;IAC9BC,IAAI,EAAE,+CADwB;IAE9BC,SAAS,EAAE,QAFmB;IAG9BC,SAAS,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