@webiny/api-headless-cms 0.0.0-unstable.9f53ea597d → 0.0.0-unstable.a4f3e4ea8b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/crud/contentEntry.crud.js +12 -39
  2. package/crud/contentEntry.crud.js.map +1 -1
  3. package/features/contentEntry/ContentEntriesFeature.js +4 -0
  4. package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
  5. package/features/contentEntry/CreateEntry/CreateEntryRepository.d.ts +4 -2
  6. package/features/contentEntry/CreateEntry/CreateEntryRepository.js +8 -3
  7. package/features/contentEntry/CreateEntry/CreateEntryRepository.js.map +1 -1
  8. package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +1 -2
  9. package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
  10. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.d.ts +4 -2
  11. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js +8 -3
  12. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js.map +1 -1
  13. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
  14. package/features/contentEntry/DeleteEntry/DeleteEntryRepository.d.ts +4 -2
  15. package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js +8 -3
  16. package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js.map +1 -1
  17. package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.d.ts +3 -1
  18. package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js +8 -3
  19. package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js.map +1 -1
  20. package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.d.ts +3 -1
  21. package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +9 -3
  22. package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
  23. package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.d.ts +4 -2
  24. package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js +7 -3
  25. package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js.map +1 -1
  26. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.d.ts +4 -4
  27. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js +8 -11
  28. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js.map +1 -1
  29. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.d.ts +4 -2
  30. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js +7 -3
  31. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js.map +1 -1
  32. package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.d.ts +4 -2
  33. package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js +7 -3
  34. package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js.map +1 -1
  35. package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.d.ts +4 -2
  36. package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js +7 -3
  37. package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js.map +1 -1
  38. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.d.ts +4 -2
  39. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js +7 -3
  40. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js.map +1 -1
  41. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.d.ts +4 -2
  42. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js +7 -3
  43. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js.map +1 -1
  44. package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.d.ts +4 -2
  45. package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js +7 -3
  46. package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js.map +1 -1
  47. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.d.ts +4 -2
  48. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js +7 -3
  49. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js.map +1 -1
  50. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.d.ts +4 -2
  51. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js +7 -3
  52. package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js.map +1 -1
  53. package/features/contentEntry/ListEntries/ListEntriesRepository.d.ts +4 -2
  54. package/features/contentEntry/ListEntries/ListEntriesRepository.js +7 -3
  55. package/features/contentEntry/ListEntries/ListEntriesRepository.js.map +1 -1
  56. package/features/contentEntry/MoveEntry/MoveEntryRepository.d.ts +4 -2
  57. package/features/contentEntry/MoveEntry/MoveEntryRepository.js +7 -3
  58. package/features/contentEntry/MoveEntry/MoveEntryRepository.js.map +1 -1
  59. package/features/contentEntry/PublishEntry/PublishEntryRepository.d.ts +4 -2
  60. package/features/contentEntry/PublishEntry/PublishEntryRepository.js +8 -3
  61. package/features/contentEntry/PublishEntry/PublishEntryRepository.js.map +1 -1
  62. package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
  63. package/features/contentEntry/RepublishEntry/RepublishEntryRepository.d.ts +4 -2
  64. package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js +8 -3
  65. package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js.map +1 -1
  66. package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.d.ts +4 -2
  67. package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js +8 -3
  68. package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js.map +1 -1
  69. package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.d.ts +4 -2
  70. package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js +8 -3
  71. package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js.map +1 -1
  72. package/features/contentEntry/UpdateEntry/UpdateEntryRepository.d.ts +4 -2
  73. package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js +8 -3
  74. package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js.map +1 -1
  75. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.d.ts +14 -0
  76. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js +34 -0
  77. package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js.map +1 -0
  78. package/features/contentEntry/UpdateRevision/abstractions.d.ts +10 -0
  79. package/features/contentEntry/UpdateRevision/abstractions.js +5 -0
  80. package/features/contentEntry/UpdateRevision/abstractions.js.map +1 -0
  81. package/features/contentEntry/UpdateRevision/feature.d.ts +4 -0
  82. package/features/contentEntry/UpdateRevision/feature.js +11 -0
  83. package/features/contentEntry/UpdateRevision/feature.js.map +1 -0
  84. package/features/contentEntry/UpdateRevision/index.d.ts +1 -0
  85. package/features/contentEntry/UpdateRevision/index.js +1 -0
  86. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts +2 -2
  87. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js +2 -2
  88. package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map +1 -1
  89. package/features/contentEntry/ensureItemIds.d.ts +13 -0
  90. package/features/contentEntry/ensureItemIds.js +22 -0
  91. package/features/contentEntry/ensureItemIds.js.map +1 -0
  92. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts +3 -1
  93. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js +8 -2
  94. package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
  95. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +3 -1
  96. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +8 -2
  97. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
  98. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +3 -1
  99. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +8 -2
  100. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
  101. package/features/contentModel/CreateModel/CreateModelRepository.d.ts +4 -2
  102. package/features/contentModel/CreateModel/CreateModelRepository.js +8 -4
  103. package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
  104. package/features/contentModel/CreateModel/CreateModelUseCase.js +2 -2
  105. package/features/contentModel/CreateModel/CreateModelUseCase.js.map +1 -1
  106. package/features/contentModel/CreateModel/abstractions.d.ts +1 -1
  107. package/features/contentModel/CreateModel/abstractions.js.map +1 -1
  108. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.d.ts +4 -2
  109. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +8 -4
  110. package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
  111. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -2
  112. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
  113. package/features/contentModel/CreateModelFrom/abstractions.d.ts +1 -1
  114. package/features/contentModel/CreateModelFrom/abstractions.js.map +1 -1
  115. package/features/contentModel/DeleteModel/DeleteModelRepository.d.ts +4 -2
  116. package/features/contentModel/DeleteModel/DeleteModelRepository.js +7 -3
  117. package/features/contentModel/DeleteModel/DeleteModelRepository.js.map +1 -1
  118. package/features/contentModel/UpdateModel/UpdateModelRepository.d.ts +4 -2
  119. package/features/contentModel/UpdateModel/UpdateModelRepository.js +8 -4
  120. package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
  121. package/features/contentModel/UpdateModel/UpdateModelUseCase.js +2 -2
  122. package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
  123. package/features/contentModel/UpdateModel/abstractions.d.ts +1 -1
  124. package/features/contentModel/UpdateModel/abstractions.js.map +1 -1
  125. package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +3 -2
  126. package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -1
  127. package/features/contentModelGroup/CreateGroup/CreateGroupRepository.d.ts +4 -2
  128. package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js +8 -4
  129. package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js.map +1 -1
  130. package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.d.ts +1 -3
  131. package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js +5 -7
  132. package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js.map +1 -1
  133. package/features/contentModelGroup/CreateGroup/abstractions.d.ts +1 -1
  134. package/features/contentModelGroup/CreateGroup/abstractions.js.map +1 -1
  135. package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.d.ts +4 -2
  136. package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js +7 -3
  137. package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js.map +1 -1
  138. package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.d.ts +4 -2
  139. package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js +8 -4
  140. package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js.map +1 -1
  141. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -2
  142. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
  143. package/features/contentModelGroup/UpdateGroup/abstractions.d.ts +1 -1
  144. package/features/contentModelGroup/UpdateGroup/abstractions.js.map +1 -1
  145. package/features/graphql/fields/base/DynamicZoneToGraphQL.js +7 -1
  146. package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
  147. package/features/graphql/fields/base/ObjectToGraphQL.js +6 -3
  148. package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
  149. package/features/graphql/fields/base/RefToGraphQL.js +17 -7
  150. package/features/graphql/fields/base/RefToGraphQL.js.map +1 -1
  151. package/features/modelBuilder/abstractions.d.ts +1 -2
  152. package/features/modelBuilder/abstractions.js.map +1 -1
  153. package/features/runtimeTenant/RuntimeTenant.d.ts +13 -0
  154. package/features/runtimeTenant/RuntimeTenant.js +22 -0
  155. package/features/runtimeTenant/RuntimeTenant.js.map +1 -0
  156. package/features/runtimeTenant/abstractions.d.ts +11 -0
  157. package/features/runtimeTenant/abstractions.js +5 -0
  158. package/features/runtimeTenant/abstractions.js.map +1 -0
  159. package/features/runtimeTenant/index.d.ts +2 -0
  160. package/features/runtimeTenant/index.js +2 -0
  161. package/features/sortMapper/SortMapper.js +2 -5
  162. package/features/sortMapper/SortMapper.js.map +1 -1
  163. package/features/storage/fields/ObjectStorageTransform.js +27 -7
  164. package/features/storage/fields/ObjectStorageTransform.js.map +1 -1
  165. package/features/validation/validators/PatternValidator.js +1 -1
  166. package/features/validation/validators/PatternValidator.js.map +1 -1
  167. package/features/whereMapper/WhereMapper.js +7 -5
  168. package/features/whereMapper/WhereMapper.js.map +1 -1
  169. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +15 -5
  170. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  171. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
  172. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  173. package/package.json +18 -18
  174. package/types/types.d.ts +4 -0
  175. package/types/types.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"features/graphql/fields/base/ObjectToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/ObjectToGraphQL.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst.js\";\nimport { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldToGraphQLRegistry } from \"../abstractions/CmsModelFieldToGraphQLRegistry.js\";\nimport type {\n CmsModel,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition,\n CmsModelObjectField\n} from \"~/types/index.js\";\nimport type { ValidateChildFieldsParams } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldAstNode, ICmsModelFieldToAst } from \"~/types/modelAst.js\";\nimport { createTypeFromFields } from \"~/utils/createTypeFromFields.js\";\n\ninterface CreateTypeNameParams {\n model: Pick<CmsModel, \"singularApiName\">;\n parents?: string[];\n field: CmsModelField;\n}\n\nconst createTypeName = (params: CreateTypeNameParams): string => {\n const { model, parents = [], field } = params;\n return [model.singularApiName]\n .concat(parents)\n .concat([field.fieldId])\n .filter(Boolean)\n .map(id => {\n return upperFirst(id);\n })\n .join(\"_\");\n};\n\ninterface CreateChildTypeDefsParams {\n model: Pick<CmsModel, \"singularApiName\">;\n field: CmsModelField;\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n endpointType: \"manage\" | \"read\";\n}\n\nconst createChildTypeDefs = (params: CreateChildTypeDefsParams): string => {\n const { field, fieldRegistry, model, endpointType } = params;\n const fields = field.settings?.fields || [];\n\n const typeName = createTypeName({\n model,\n field,\n parents: field.settings?.parents\n });\n\n const filters = fields\n .map(child => {\n const fieldImpl = fieldRegistry.get(child.type);\n if (!fieldImpl) {\n return null;\n }\n const api = endpointType === \"manage\" ? fieldImpl.manage : fieldImpl.read;\n const createListFilters = api.createListFilters;\n if (!createListFilters) {\n return null;\n }\n\n const filters = createListFilters({\n model,\n field: {\n ...child,\n settings: {\n ...child.settings,\n parents: (child.settings?.parents || []).concat([field.fieldId])\n }\n },\n fieldRegistry\n });\n if (!filters) {\n return null;\n }\n return filters;\n })\n .filter(Boolean)\n .join(\"\\n\");\n return `input ${typeName}WhereInput {\n ${filters || \"_empty: String\"}\n }\\n`;\n};\n\nconst createObjectListFilters = (\n field: CmsModelField,\n model: Pick<CmsModel, \"singularApiName\">\n): string => {\n const typeName = createTypeName({\n model,\n field,\n parents: field.settings?.parents\n });\n return `${field.fieldId}: ${typeName}WhereInput`;\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n field,\n models,\n model,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n models,\n typeOfType: \"type\",\n model,\n type: \"read\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n const childTypeDefs = createChildTypeDefs({\n model,\n field,\n fieldRegistry,\n endpointType: \"read\"\n });\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs: `${typeDefs}${childTypeDefs}`\n };\n }\n\n public createResolver({\n field,\n createFieldResolvers,\n graphQLType\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n if (!field.settings?.fields || field.settings.fields.length === 0) {\n return false;\n }\n\n const fieldType = `${graphQLType}_${upperFirst(field.fieldId)}`;\n\n const typeResolvers =\n createFieldResolvers({\n graphQLType: fieldType,\n fields: field.settings.fields\n }) || {};\n\n return {\n resolver: null,\n typeResolvers\n };\n }\n\n public createListFilters({ field, model }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createObjectListFilters(field, model);\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n typeOfType: \"type\",\n models,\n model,\n type: \"manage\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n const childTypeDefs = createChildTypeDefs({\n model,\n field,\n fieldRegistry,\n endpointType: \"manage\"\n });\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs: `${typeDefs}\\n${childTypeDefs}`\n };\n }\n\n public createInputField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n typeOfType: \"input\",\n models,\n model,\n type: \"manage\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs\n };\n }\n\n public createResolver({\n graphQLType,\n field,\n createFieldResolvers\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n if (!field.settings?.fields || field.settings.fields.length === 0) {\n return false;\n }\n const fieldType = `${graphQLType}_${upperFirst(field.fieldId)}`;\n const typeResolvers = createFieldResolvers({\n graphQLType: fieldType,\n fields: field.settings.fields\n });\n return {\n resolver: null,\n typeResolvers: typeResolvers || {}\n };\n }\n\n public createListFilters({ field, model }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createObjectListFilters(field, model);\n }\n}\n\nclass ObjectToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"object\";\n public readonly isSearchable: boolean = false;\n public readonly isSortable: boolean = false;\n public readonly isFullTextSearchable: boolean = false;\n\n public getReadApi(): CmsModelFieldToGraphQL.ReadApi {\n return this.read;\n }\n\n public getManageApi(): CmsModelFieldToGraphQL.ManageApi {\n return this.manage;\n }\n\n public validateChildFields(params: ValidateChildFieldsParams<CmsModelField>): void {\n const field = params.field as CmsModelObjectField;\n const originalField = params.originalField as CmsModelObjectField | undefined;\n params.validate({\n fields: field.settings?.fields ?? [],\n originalFields: originalField?.settings?.fields || []\n });\n }\n\n public getFieldAst(field: CmsModelField, converter: ICmsModelFieldToAst): CmsModelFieldAstNode {\n const objectField = field as CmsModelObjectField;\n const { fields = [], ...settings } = objectField.settings;\n return {\n type: \"field\",\n field: {\n ...objectField,\n settings: settings || {}\n },\n children: fields.map(f => converter.toAst(f))\n };\n }\n}\n\nexport const ObjectFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: ObjectToGraphQL,\n dependencies: []\n});\n"],"names":["createTypeName","params","model","parents","field","Boolean","id","upperFirst","createChildTypeDefs","fieldRegistry","endpointType","fields","typeName","filters","child","fieldImpl","api","createListFilters","createObjectListFilters","ReadApi","models","result","createTypeFromFields","fieldType","typeDefs","childTypeDefs","createFieldResolvers","graphQLType","typeResolvers","ManageApi","ObjectToGraphQL","originalField","converter","objectField","settings","f","ObjectFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;AAoBA,MAAMA,iBAAiB,CAACC;IACpB,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,EAAEC,KAAK,EAAE,GAAGH;IACvC,OAAO;QAACC,MAAM,eAAe;KAAC,CACzB,MAAM,CAACC,SACP,MAAM,CAAC;QAACC,MAAM,OAAO;KAAC,EACtB,MAA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B;YACvC,aAAaH;YACb,QAAQnB,MAAM,QAAQ,CAAC,MAAM;QACjC;QACA,OAAO;YACH,UAAU;YACV,eAAewB,iBAAiB,CAAC;QACrC;IACJ;IAEO,kBAAkB,EAAExB,KAAK,EAAEF,KAAK,EAA4C,EAAU;QACzF,OAAOgB,wBAAwBd,OAAOF;IAC1C;AACJ;AAEA,MAAM4B;IASK,aAA6C;QAChD,OAAO,IAAI,CAAC,IAAI;IACpB;IAEO,eAAiD;QACpD,OAAO,IAAI,CAAC,MAAM;IACtB;IAEO,oBAAoB7B,MAAgD,EAAQ;QAC/E,MAAMG,QAAQH,OAAO,KAAK;QAC1B,MAAM8B,gBAAgB9B,OAAO,aAAa;QAC1CA,OAAO,QAAQ,CAAC;YACZ,QAAQG,MAAM,QAAQ,EAAE,UAAU,EAAE;YACpC,gBAAgB2B,eAAe,UAAU,UAAU,EAAE;QACzD;IACJ;IAEO,YAAY3B,KAAoB,EAAE4B,SAA8B,EAAwB;QAC3F,MAAMC,cAAc7B;QACpB,MAAM,EAAEO,SAAS,EAAE,EAAE,GAAGuB,UAAU,GAAGD,YAAY,QAAQ;QACzD,OAAO;YACH,MAAM;YACN,OAAO;gBACH,GAAGA,WAAW;gBACd,UAAUC,YAAY,CAAC;YAC3B;YACA,UAAUvB,OAAO,GAAG,CAACwB,CAAAA,IAAKH,UAAU,KAAK,CAACG;QAC9C;IACJ;;aApCgB,IAAI,GAAG,IAAIhB;aACX,MAAM,GAAG,IAAIU;aAEb,SAAS,GAAsB;aAC/B,YAAY,GAAY;aACxB,UAAU,GAAY;aACtB,oBAAoB,GAAY;;AA+BpD;AAEO,MAAMO,uBAAuBC,uBAAuB,oBAAoB,CAAC;IAC5E,gBAAgBP;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/graphql/fields/base/ObjectToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/ObjectToGraphQL.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst.js\";\nimport { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldToGraphQLRegistry } from \"../abstractions/CmsModelFieldToGraphQLRegistry.js\";\nimport type {\n CmsModel,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition,\n CmsModelObjectField\n} from \"~/types/index.js\";\nimport type { ValidateChildFieldsParams } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldAstNode, ICmsModelFieldToAst } from \"~/types/modelAst.js\";\nimport { createTypeFromFields } from \"~/utils/createTypeFromFields.js\";\n\ninterface CreateTypeNameParams {\n model: Pick<CmsModel, \"singularApiName\">;\n parents?: string[];\n field: CmsModelField;\n}\n\nconst createTypeName = (params: CreateTypeNameParams): string => {\n const { model, parents = [], field } = params;\n return [model.singularApiName]\n .concat(parents)\n .concat([field.fieldId])\n .filter(Boolean)\n .map(id => {\n return upperFirst(id);\n })\n .join(\"_\");\n};\n\ninterface CreateChildTypeDefsParams {\n model: Pick<CmsModel, \"singularApiName\">;\n field: CmsModelField;\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n endpointType: \"manage\" | \"read\";\n}\n\nconst createChildTypeDefs = (params: CreateChildTypeDefsParams): string => {\n const { field, fieldRegistry, model, endpointType } = params;\n const fields = field.settings?.fields || [];\n\n const typeName = createTypeName({\n model,\n field,\n parents: field.settings?.parents\n });\n\n const filters = fields\n .map(child => {\n const fieldImpl = fieldRegistry.get(child.type);\n if (!fieldImpl) {\n return null;\n }\n const api = endpointType === \"manage\" ? fieldImpl.manage : fieldImpl.read;\n const createListFilters = api.createListFilters;\n if (!createListFilters) {\n return null;\n }\n\n const filters = createListFilters({\n model,\n field: {\n ...child,\n settings: {\n ...child.settings,\n parents: (child.settings?.parents || []).concat([field.fieldId])\n }\n },\n fieldRegistry\n });\n if (!filters) {\n return null;\n }\n return filters;\n })\n .filter(Boolean)\n .join(\"\\n\");\n return `input ${typeName}WhereInput {\n ${filters || \"_empty: String\"}\n }\\n`;\n};\n\nconst createObjectListFilters = (\n field: CmsModelField,\n model: Pick<CmsModel, \"singularApiName\">\n): string => {\n const typeName = createTypeName({\n model,\n field,\n parents: field.settings?.parents\n });\n return `${field.fieldId}: ${typeName}WhereInput`;\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n field,\n models,\n model,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n models,\n typeOfType: \"type\",\n model,\n type: \"read\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n const childTypeDefs = createChildTypeDefs({\n model,\n field,\n fieldRegistry,\n endpointType: \"read\"\n });\n\n const itemIdTypeDef = `\\nextend type ${fieldType} {\\n _id: ID\\n}\\n`;\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs: `${typeDefs}${childTypeDefs}${itemIdTypeDef}`\n };\n }\n\n public createResolver({\n field,\n createFieldResolvers,\n graphQLType\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n if (!field.settings?.fields || field.settings.fields.length === 0) {\n return false;\n }\n\n const fieldType = `${graphQLType}_${upperFirst(field.fieldId)}`;\n\n const typeResolvers =\n createFieldResolvers({\n graphQLType: fieldType,\n fields: field.settings.fields\n }) || {};\n\n return {\n resolver: null,\n typeResolvers\n };\n }\n\n public createListFilters({ field, model }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createObjectListFilters(field, model);\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n typeOfType: \"type\",\n models,\n model,\n type: \"manage\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n const childTypeDefs = createChildTypeDefs({\n model,\n field,\n fieldRegistry,\n endpointType: \"manage\"\n });\n\n const itemIdTypeDef = `\\nextend type ${fieldType} {\\n _id: ID\\n}\\n`;\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs: `${typeDefs}\\n${childTypeDefs}${itemIdTypeDef}`\n };\n }\n\n public createInputField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const result = createTypeFromFields({\n typeOfType: \"input\",\n models,\n model,\n type: \"manage\",\n typeNamePrefix: createTypeName({\n model,\n field,\n parents: field.settings?.parents\n }),\n fields: field.settings?.fields || [],\n fieldRegistry\n });\n if (!result) {\n return null;\n }\n const { fieldType, typeDefs } = result;\n\n const itemIdTypeDef = `\\nextend input ${fieldType} {\\n _id: ID\\n}\\n`;\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,\n typeDefs: `${typeDefs}${itemIdTypeDef}`\n };\n }\n\n public createResolver({\n graphQLType,\n field,\n createFieldResolvers\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n if (!field.settings?.fields || field.settings.fields.length === 0) {\n return false;\n }\n const fieldType = `${graphQLType}_${upperFirst(field.fieldId)}`;\n const typeResolvers = createFieldResolvers({\n graphQLType: fieldType,\n fields: field.settings.fields\n });\n return {\n resolver: null,\n typeResolvers: typeResolvers || {}\n };\n }\n\n public createListFilters({ field, model }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createObjectListFilters(field, model);\n }\n}\n\nclass ObjectToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"object\";\n public readonly isSearchable: boolean = false;\n public readonly isSortable: boolean = false;\n public readonly isFullTextSearchable: boolean = false;\n\n public getReadApi(): CmsModelFieldToGraphQL.ReadApi {\n return this.read;\n }\n\n public getManageApi(): CmsModelFieldToGraphQL.ManageApi {\n return this.manage;\n }\n\n public validateChildFields(params: ValidateChildFieldsParams<CmsModelField>): void {\n const field = params.field as CmsModelObjectField;\n const originalField = params.originalField as CmsModelObjectField | undefined;\n params.validate({\n fields: field.settings?.fields ?? [],\n originalFields: originalField?.settings?.fields || []\n });\n }\n\n public getFieldAst(field: CmsModelField, converter: ICmsModelFieldToAst): CmsModelFieldAstNode {\n const objectField = field as CmsModelObjectField;\n const { fields = [], ...settings } = objectField.settings;\n return {\n type: \"field\",\n field: {\n ...objectField,\n settings: settings || {}\n },\n children: fields.map(f => converter.toAst(f))\n };\n }\n}\n\nexport const ObjectFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: ObjectToGraphQL,\n dependencies: []\n});\n"],"names":["createTypeName","params","model","parents","field","Boolean","id","upperFirst","createChildTypeDefs","fieldRegistry","endpointType","fields","typeName","filters","child","fieldImpl","api","createListFilters","createObjectListFilters","ReadApi","models","result","createTypeFromFields","fieldType","typeDefs","childTypeDefs","itemIdTypeDef","createFieldResolvers","graphQLType","typeResolvers","ManageApi","ObjectToGraphQL","originalField","converter","objectField","settings","f","ObjectFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;AAoBA,MAAMA,iBAAiB,CAACC;IACpB,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,EAAEC,KAAK,EAAE,GAAGH;IACvC,OAAO;QAACC,MAAM,eAAe;KAAC,CACzB,MAAM,CAACC,SACP,MAAM,CAAC;QAACC,MAAM,OAAO;KAAC,EACtB,MAAM,CAACC,SACP,GAAG,CAACC,CAAAA,KACMC,WAAWD,KAErB,IAAI,CAAC;AACd;AASA,MAAME,sBAAsB,CAACP;IACzB,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
@@ -6,6 +6,7 @@ import { createGraphQLInputField } from "./utils/createGraphQLInputField.js";
6
6
  import { GetModelUseCase } from "../../../contentModel/GetModel/index.js";
7
7
  import { GetPublishedEntriesByIdsUseCase } from "../../../contentEntry/GetPublishedEntriesByIds/index.js";
8
8
  import { GetLatestEntriesByIdsUseCase } from "../../../contentEntry/GetLatestEntriesByIds/index.js";
9
+ import { Logger } from "@webiny/api-core/exports/api/logger.js";
9
10
  const createUnionTypeName = (model, field)=>`${model.singularApiName}_${createTypeName(field.fieldId)}`;
10
11
  const createListFilters = (fieldId)=>`
11
12
  ${fieldId}: RefFieldWhereInput
@@ -78,6 +79,7 @@ class ReadApi {
78
79
  const getModel = container.resolve(GetModelUseCase);
79
80
  const getPublishedByIds = container.resolve(GetPublishedEntriesByIdsUseCase);
80
81
  const getLatestByIds = container.resolve(GetLatestEntriesByIdsUseCase);
82
+ const logger = container.resolve(Logger);
81
83
  const initialValue = getValue(parent);
82
84
  if (!initialValue) return null;
83
85
  if (false === args.populate) return initialValue;
@@ -94,14 +96,18 @@ class ReadApi {
94
96
  const getters = Object.keys(entriesByModel).map(async (modelId)=>{
95
97
  const idList = entriesByModel[modelId];
96
98
  const modelResult = await getModel.execute(modelId);
99
+ if (modelResult.isFail()) {
100
+ logger.error(modelResult.error);
101
+ return [];
102
+ }
97
103
  const model = modelResult.value;
98
- let entries;
104
+ let entries = [];
99
105
  if (cms.READ) {
100
106
  const getPublishedResult = await getPublishedByIds.execute(model, idList);
101
- entries = getPublishedResult.value;
107
+ if (getPublishedResult.isOk()) entries = getPublishedResult.value;
102
108
  } else {
103
- const latestByIsResult = await getLatestByIds.execute(model, idList);
104
- entries = latestByIsResult.value;
109
+ const latestByIdsResult = await getLatestByIds.execute(model, idList);
110
+ if (latestByIdsResult.isOk()) entries = latestByIdsResult.value;
105
111
  }
106
112
  return appendTypename(entries, modelIdToTypeName.get(modelId));
107
113
  });
@@ -110,18 +116,22 @@ class ReadApi {
110
116
  }
111
117
  const value = initialValue;
112
118
  const modelResult = await getModel.execute(value.modelId);
119
+ if (modelResult.isFail()) {
120
+ logger.error(modelResult.error);
121
+ return null;
122
+ }
113
123
  const model = modelResult.value;
114
- let revisions;
124
+ let revisions = [];
115
125
  if (cms.READ) {
116
126
  const publishedByIdsResult = await getPublishedByIds.execute(model, [
117
127
  value.entryId
118
128
  ]);
119
- revisions = publishedByIdsResult.value;
129
+ if (publishedByIdsResult.isOk()) revisions = publishedByIdsResult.value;
120
130
  } else {
121
131
  const latestByIdsResult = await getLatestByIds.execute(model, [
122
132
  value.entryId
123
133
  ]);
124
- revisions = latestByIdsResult.value;
134
+ if (latestByIdsResult.isOk()) revisions = latestByIdsResult.value;
125
135
  }
126
136
  if (!revisions || 0 === revisions.length) return null;
127
137
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"features/graphql/fields/base/RefToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/RefToGraphQL.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type {\n CmsContext,\n CmsEntry,\n CmsModel,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition\n} from \"~/types/index.js\";\nimport type { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetPublishedEntriesByIdsUseCase } from \"~/features/contentEntry/GetPublishedEntriesByIds/index.js\";\nimport { GetLatestEntriesByIdsUseCase } from \"~/features/contentEntry/GetLatestEntriesByIds/index.js\";\n\ninterface RefFieldValue {\n /**\n * `id` is optional for backwards compatibility with records created before this property was introduced.\n */\n id?: string;\n entryId: string;\n modelId: string;\n}\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n};\n\nconst createListFilters = (fieldId: string): string => {\n return `\n ${fieldId}: RefFieldWhereInput\n `;\n};\n\nconst createFilteringTypeDef = () => {\n return `\n input RefFieldWhereInput {\n id: String\n id_not: String\n id_in: [String!]\n id_not_in: [String]\n entryId: String\n entryId_not: String\n entryId_in: [String!]\n entryId_not_in: [String!]\n modelId: String\n modelId_not: String\n modelId_in: [String!]\n modelId_not_in: [String!]\n }\n `;\n};\n\nconst appendTypename = (entries: CmsEntry[], typename: string): CmsEntry[] => {\n return entries.map(item => {\n return {\n ...item,\n __typename: typename\n };\n });\n};\n\nconst getFieldModels = (field: CmsModelField): Pick<CmsModel, \"modelId\">[] => {\n if (!field.settings || Array.isArray(field.settings.models) === false) {\n return [];\n }\n return field.settings.models as Pick<CmsModel, \"modelId\">[];\n};\n\nconst modelIdToTypeName = new Map<string, string>();\n\ninterface GetModelParams {\n models: CmsModel[];\n modelId: string;\n}\n\nconst getModel = (params: GetModelParams): CmsModel => {\n const { models, modelId } = params;\n const model = models.find(item => item.modelId === modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\n `Could not find model with ID \"${modelId}\" in the list of models.`,\n \"MODEL_NOT_FOUND\",\n { modelId }\n );\n};\n\nconst getModelSingularApiName = (params: GetModelParams): string => {\n return getModel(params).singularApiName;\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n model,\n field,\n models\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition {\n const fieldModels = field.settings?.models || [];\n const gqlType =\n fieldModels.length > 1\n ? createUnionTypeName(model, field)\n : getModelSingularApiName({ models, modelId: fieldModels[0].modelId });\n const typeDefs =\n fieldModels.length > 1\n ? `union ${gqlType} = ${getFieldModels(field)\n .map(({ modelId }) => getModelSingularApiName({ models, modelId }))\n .join(\" | \")}`\n : \"\";\n\n return {\n fields:\n field.fieldId +\n `(populate: Boolean = true): ${field.list ? `[${gqlType}!]` : gqlType}`,\n typeDefs\n };\n }\n\n public createListFilters({ field }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createListFilters(field.fieldId);\n }\n\n public createResolver({\n field,\n models\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n const fieldModels = field.settings?.models || [];\n for (const item of fieldModels) {\n modelIdToTypeName.set(\n item.modelId,\n getModelSingularApiName({ models, modelId: item.modelId })\n );\n }\n\n const getValue = (parent: any): RefFieldValue | RefFieldValue[] => {\n if (parent.values) {\n return parent.values[field.fieldId];\n }\n return parent[field.fieldId];\n };\n\n /* @ts-expect-error Mixed return types for createResolver. */\n return async (parent: CmsEntry, args: any, context: CmsContext) => {\n const { cms, container } = context;\n\n const getModel = container.resolve(GetModelUseCase);\n const getPublishedByIds = container.resolve(GetPublishedEntriesByIdsUseCase);\n const getLatestByIds = container.resolve(GetLatestEntriesByIdsUseCase);\n\n const initialValue = getValue(parent);\n\n if (!initialValue) {\n return null;\n }\n if (args.populate === false) {\n return initialValue;\n }\n\n if (field.list) {\n const referenceFieldValues = initialValue as RefFieldValue[];\n if (\n Array.isArray(referenceFieldValues) === false ||\n referenceFieldValues.length === 0\n ) {\n return [];\n }\n\n const entriesByModel = referenceFieldValues.reduce(\n (collection, ref) => {\n if (!collection[ref.modelId]) {\n collection[ref.modelId] = [];\n } else if (collection[ref.modelId].includes(ref.entryId) === true) {\n return collection;\n }\n collection[ref.modelId].push(ref.entryId);\n return collection;\n },\n {} as Record<string, string[]>\n );\n\n const getters = Object.keys(entriesByModel).map(async modelId => {\n const idList = entriesByModel[modelId];\n const modelResult = await getModel.execute(modelId);\n const model = modelResult.value;\n\n let entries: CmsEntry[];\n if (cms.READ) {\n const getPublishedResult = await getPublishedByIds.execute(model, idList);\n entries = getPublishedResult.value;\n } else {\n const latestByIsResult = await getLatestByIds.execute(model, idList);\n entries = latestByIsResult.value;\n }\n return appendTypename(entries, modelIdToTypeName.get(modelId)!);\n });\n\n const references = await Promise.all(getters).then((results: CmsEntry[][]) => {\n return results.reduce((result, item) => {\n return result.concat(item);\n }, []);\n });\n\n return referenceFieldValues\n .map(v => {\n return references.find(ref => ref.entryId === v.entryId);\n })\n .filter(Boolean);\n }\n\n const value = initialValue as RefFieldValue;\n const modelResult = await getModel.execute(value.modelId);\n const model = modelResult.value;\n\n let revisions: CmsEntry[];\n if (cms.READ) {\n const publishedByIdsResult = await getPublishedByIds.execute(model, [\n value.entryId\n ]);\n revisions = publishedByIdsResult.value;\n } else {\n const latestByIdsResult = await getLatestByIds.execute(model, [value.entryId]);\n revisions = latestByIdsResult.value;\n }\n\n if (!revisions || revisions.length === 0) {\n return null;\n }\n return {\n ...revisions[0],\n __typename: modelIdToTypeName.get(value.modelId)\n };\n };\n }\n\n public createSchema(): GraphQLSchemaDefinition<CmsContext> {\n return {\n typeDefs: createFilteringTypeDef(),\n resolvers: {}\n };\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n if (field.list) {\n return `${field.fieldId}: [RefField!]`;\n }\n return `${field.fieldId}: RefField`;\n }\n\n public createInputField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n return createGraphQLInputField(field, \"RefFieldInput\");\n }\n\n public createListFilters({ field }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createListFilters(field.fieldId);\n }\n\n public createSchema(): GraphQLSchemaDefinition<CmsContext> {\n return {\n typeDefs: /* GraphQL */ `\n type RefField {\n modelId: String!\n entryId: ID!\n id: ID!\n }\n\n input RefFieldInput {\n modelId: String!\n id: RevisionId!\n }\n\n ${createFilteringTypeDef()}\n `,\n resolvers: {\n RefField: {\n entryId: (parent: RefFieldValue) => {\n const { id } = parseIdentifier(parent.entryId || parent.id);\n return id;\n },\n id: (parent: RefFieldValue) => {\n return parent.id || parent.entryId;\n }\n }\n }\n };\n }\n}\n\nclass RefToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"ref\";\n public readonly isSearchable: boolean = true;\n public readonly isSortable: boolean = false;\n public readonly isFullTextSearchable: boolean = false;\n\n public getReadApi(): CmsModelFieldToGraphQL.ReadApi {\n return this.read;\n }\n\n public getManageApi(): CmsModelFieldToGraphQL.ManageApi {\n return this.manage;\n }\n}\n\nexport const RefFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: RefToGraphQL,\n dependencies: []\n});\n"],"names":["createUnionTypeName","model","field","createTypeName","createListFilters","fieldId","createFilteringTypeDef","appendTypename","entries","typename","item","getFieldModels","Array","modelIdToTypeName","Map","getModel","params","models","modelId","WebinyError","getModelSingularApiName","ReadApi","fieldModels","gqlType","typeDefs","getValue","parent","args","context","cms","container","GetModelUseCase","getPublishedByIds","GetPublishedEntriesByIdsUseCase","getLatestByIds","GetLatestEntriesByIdsUseCase","initialValue","referenceFieldValues","entriesByModel","collection","ref","getters","Object","idList","modelResult","getPublishedResult","latestByIsResult","references","Promise","results","result","v","Boolean","value","revisions","publishedByIdsResult","latestByIdsResult","ManageApi","createGraphQLInputField","id","parseIdentifier","RefToGraphQL","RefFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;;;;;;AA2BA,MAAMA,sBAAsB,CAACC,OAAiBC,QACnC,GAAGD,MAAM,eAAe,CAAC,CAAC,EAAEE,eAAeD,MAAM,OAAO,GAAG;AAGtE,MAAME,oBAAoB,CAACC,UAChB,CAAC;QACJ,EAAEA,QAAQ;IACd,CAAC;AAGL,MAAMC,yBAAyB,IACpB,CAAC;;;;;;;;;;;;;;;IAeR,CAAC;AAGL,MAAMC,iBAAiB,CAACC,SAAqBC,WAClCD,QAAQ,GAAG,CAACE,CAAAA,OACR;YACH,GAAGA,IAAI;YACP,YAAYD;QAChB;AAIR,MAAME,iBAAiB,CAACT;IACpB,IAAI,CAACA,MAAM,QAAQ,IAAIU,AAAyC,UAAzCA,MAAM,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GraphQL.js","sources":["../../../../../src/features/graphql/fields/base/RefToGraphQL.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type {\n CmsContext,\n CmsEntry,\n CmsModel,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition\n} from \"~/types/index.js\";\nimport type { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\nimport { GetPublishedEntriesByIdsUseCase } from \"~/features/contentEntry/GetPublishedEntriesByIds/index.js\";\nimport { GetLatestEntriesByIdsUseCase } from \"~/features/contentEntry/GetLatestEntriesByIds/index.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\n\ninterface RefFieldValue {\n /**\n * `id` is optional for backwards compatibility with records created before this property was introduced.\n */\n id?: string;\n entryId: string;\n modelId: string;\n}\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n};\n\nconst createListFilters = (fieldId: string): string => {\n return `\n ${fieldId}: RefFieldWhereInput\n `;\n};\n\nconst createFilteringTypeDef = () => {\n return `\n input RefFieldWhereInput {\n id: String\n id_not: String\n id_in: [String!]\n id_not_in: [String]\n entryId: String\n entryId_not: String\n entryId_in: [String!]\n entryId_not_in: [String!]\n modelId: String\n modelId_not: String\n modelId_in: [String!]\n modelId_not_in: [String!]\n }\n `;\n};\n\nconst appendTypename = (entries: CmsEntry[], typename: string): CmsEntry[] => {\n return entries.map(item => {\n return {\n ...item,\n __typename: typename\n };\n });\n};\n\nconst getFieldModels = (field: CmsModelField): Pick<CmsModel, \"modelId\">[] => {\n if (!field.settings || Array.isArray(field.settings.models) === false) {\n return [];\n }\n return field.settings.models as Pick<CmsModel, \"modelId\">[];\n};\n\nconst modelIdToTypeName = new Map<string, string>();\n\ninterface GetModelParams {\n models: CmsModel[];\n modelId: string;\n}\n\nconst getModel = (params: GetModelParams): CmsModel => {\n const { models, modelId } = params;\n const model = models.find(item => item.modelId === modelId);\n if (model) {\n return model;\n }\n throw new WebinyError(\n `Could not find model with ID \"${modelId}\" in the list of models.`,\n \"MODEL_NOT_FOUND\",\n { modelId }\n );\n};\n\nconst getModelSingularApiName = (params: GetModelParams): string => {\n return getModel(params).singularApiName;\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n model,\n field,\n models\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition {\n const fieldModels = field.settings?.models || [];\n const gqlType =\n fieldModels.length > 1\n ? createUnionTypeName(model, field)\n : getModelSingularApiName({ models, modelId: fieldModels[0].modelId });\n const typeDefs =\n fieldModels.length > 1\n ? `union ${gqlType} = ${getFieldModels(field)\n .map(({ modelId }) => getModelSingularApiName({ models, modelId }))\n .join(\" | \")}`\n : \"\";\n\n return {\n fields:\n field.fieldId +\n `(populate: Boolean = true): ${field.list ? `[${gqlType}!]` : gqlType}`,\n typeDefs\n };\n }\n\n public createListFilters({ field }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createListFilters(field.fieldId);\n }\n\n public createResolver({\n field,\n models\n }: CmsModelFieldToGraphQL.ResolverParams): CmsModelFieldToGraphQL.Resolver {\n const fieldModels = field.settings?.models || [];\n for (const item of fieldModels) {\n modelIdToTypeName.set(\n item.modelId,\n getModelSingularApiName({ models, modelId: item.modelId })\n );\n }\n\n const getValue = (parent: any): RefFieldValue | RefFieldValue[] => {\n if (parent.values) {\n return parent.values[field.fieldId];\n }\n return parent[field.fieldId];\n };\n\n /* @ts-expect-error Mixed return types for createResolver. */\n return async (parent: CmsEntry, args: any, context: CmsContext) => {\n const { cms, container } = context;\n\n const getModel = container.resolve(GetModelUseCase);\n const getPublishedByIds = container.resolve(GetPublishedEntriesByIdsUseCase);\n const getLatestByIds = container.resolve(GetLatestEntriesByIdsUseCase);\n const logger = container.resolve(Logger);\n\n const initialValue = getValue(parent);\n\n if (!initialValue) {\n return null;\n }\n if (args.populate === false) {\n return initialValue;\n }\n\n if (field.list) {\n const referenceFieldValues = initialValue as RefFieldValue[];\n if (\n Array.isArray(referenceFieldValues) === false ||\n referenceFieldValues.length === 0\n ) {\n return [];\n }\n\n const entriesByModel = referenceFieldValues.reduce<Record<string, string[]>>(\n (collection, ref) => {\n if (!collection[ref.modelId]) {\n collection[ref.modelId] = [];\n } else if (collection[ref.modelId].includes(ref.entryId) === true) {\n return collection;\n }\n collection[ref.modelId].push(ref.entryId);\n return collection;\n },\n {}\n );\n\n const getters = Object.keys(entriesByModel).map(async modelId => {\n const idList = entriesByModel[modelId];\n const modelResult = await getModel.execute(modelId);\n if (modelResult.isFail()) {\n logger.error(modelResult.error);\n return [];\n }\n const model = modelResult.value;\n\n let entries: CmsEntry[] = [];\n if (cms.READ) {\n const getPublishedResult = await getPublishedByIds.execute(model, idList);\n if (getPublishedResult.isOk()) {\n entries = getPublishedResult.value;\n }\n } else {\n const latestByIdsResult = await getLatestByIds.execute(model, idList);\n if (latestByIdsResult.isOk()) {\n entries = latestByIdsResult.value;\n }\n }\n return appendTypename(entries, modelIdToTypeName.get(modelId)!);\n });\n\n const references = await Promise.all(getters).then((results: CmsEntry[][]) => {\n return results.reduce((result, item) => {\n return result.concat(item);\n }, []);\n });\n\n return referenceFieldValues\n .map(v => {\n return references.find(ref => ref.entryId === v.entryId);\n })\n .filter(Boolean);\n }\n\n const value = initialValue as RefFieldValue;\n const modelResult = await getModel.execute(value.modelId);\n if (modelResult.isFail()) {\n logger.error(modelResult.error);\n return null;\n }\n const model = modelResult.value;\n\n let revisions: CmsEntry[] = [];\n if (cms.READ) {\n const publishedByIdsResult = await getPublishedByIds.execute(model, [\n value.entryId\n ]);\n if (publishedByIdsResult.isOk()) {\n revisions = publishedByIdsResult.value;\n }\n } else {\n const latestByIdsResult = await getLatestByIds.execute(model, [value.entryId]);\n if (latestByIdsResult.isOk()) {\n revisions = latestByIdsResult.value;\n }\n }\n\n if (!revisions || revisions.length === 0) {\n return null;\n }\n return {\n ...revisions[0],\n __typename: modelIdToTypeName.get(value.modelId)\n };\n };\n }\n\n public createSchema(): GraphQLSchemaDefinition<CmsContext> {\n return {\n typeDefs: createFilteringTypeDef(),\n resolvers: {}\n };\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n if (field.list) {\n return `${field.fieldId}: [RefField!]`;\n }\n return `${field.fieldId}: RefField`;\n }\n\n public createInputField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n return createGraphQLInputField(field, \"RefFieldInput\");\n }\n\n public createListFilters({ field }: CmsModelFieldToGraphQL.ListFiltersParams): string {\n return createListFilters(field.fieldId);\n }\n\n public createSchema(): GraphQLSchemaDefinition<CmsContext> {\n return {\n typeDefs: /* GraphQL */ `\n type RefField {\n modelId: String!\n entryId: ID!\n id: ID!\n }\n\n input RefFieldInput {\n modelId: String!\n id: RevisionId!\n }\n\n ${createFilteringTypeDef()}\n `,\n resolvers: {\n RefField: {\n entryId: (parent: RefFieldValue) => {\n const { id } = parseIdentifier(parent.entryId || parent.id);\n return id;\n },\n id: (parent: RefFieldValue) => {\n return parent.id || parent.entryId;\n }\n }\n }\n };\n }\n}\n\nclass RefToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"ref\";\n public readonly isSearchable: boolean = true;\n public readonly isSortable: boolean = false;\n public readonly isFullTextSearchable: boolean = false;\n\n public getReadApi(): CmsModelFieldToGraphQL.ReadApi {\n return this.read;\n }\n\n public getManageApi(): CmsModelFieldToGraphQL.ManageApi {\n return this.manage;\n }\n}\n\nexport const RefFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: RefToGraphQL,\n dependencies: []\n});\n"],"names":["createUnionTypeName","model","field","createTypeName","createListFilters","fieldId","createFilteringTypeDef","appendTypename","entries","typename","item","getFieldModels","Array","modelIdToTypeName","Map","getModel","params","models","modelId","WebinyError","getModelSingularApiName","ReadApi","fieldModels","gqlType","typeDefs","getValue","parent","args","context","cms","container","GetModelUseCase","getPublishedByIds","GetPublishedEntriesByIdsUseCase","getLatestByIds","GetLatestEntriesByIdsUseCase","logger","Logger","initialValue","referenceFieldValues","entriesByModel","collection","ref","getters","Object","idList","modelResult","getPublishedResult","latestByIdsResult","references","Promise","results","result","v","Boolean","value","revisions","publishedByIdsResult","ManageApi","createGraphQLInputField","id","parseIdentifier","RefToGraphQL","RefFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;;;;;;;AA4BA,MAAMA,sBAAsB,CAACC,OAAiBC,QACnC,GAAGD,MAAM,eAAe,CAAC,CAAC,EAAEE,eAAeD,MAAM,OAAO,GAAG;AAGtE,MAAME,oBAAoB,CAACC,UAChB,CAAC;QACJ,EAAEA,QAAQ;IACd,CAAC;AAGL,MAAMC,yBAAyB,IACpB,CAAC;;;;;;;;;;;;;;;IAeR,CAAC;AAGL,MAAMC,iBAAiB,CAACC,SAAqBC,WAClCD,QAAQ,GAAG,CAACE,CAAAA,OACR;YACH,GAAGA,IAAI;YACP,YAAYD;QAChB;AAIR,MAAME,iBAAiB,CAACT;IACpB,IAAI,CAACA,MAAM,QAAQ,IAAIU,AAAyC,UAAzCA,MAAM,OAAO,CAACV,MAAM,QAAQ,CAAC,MAAM,GACtD,OAAO,EAAE;IAEb,OAAOA,MAAM,QAAQ,CAAC,MAAM;AAChC;AAEA,MAAMW,oBAAoB,IAAIC;AAO9B,MAAMC,wBAAW,CAACC;IACd,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGF;IAC5B,MAAMf,QAAQgB,OAAO,IAAI,CAACP,CAAAA,OAAQA,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AAoBC,uBAAuB,oBAAoB,CAAC;IACzE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -7,8 +7,7 @@ import type { IModelBuilderPrivateInput, IModelBuilderPublicInput } from "./mode
7
7
  */
8
8
  export interface IModelSettings {
9
9
  aiEntryWizard?: boolean;
10
- previewPrefix?: string;
11
- previewSlug?: string;
10
+ previewPath?: string;
12
11
  [key: string]: any;
13
12
  }
14
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"features/modelBuilder/abstractions.js","sources":["../../../src/features/modelBuilder/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { PrivateModelBuilder } from \"./models/PrivateModelBuilder.js\";\nimport type { PublicModelBuilder } from \"./models/PublicModelBuilder.js\";\nimport type { IModelBuilderPrivateInput, IModelBuilderPublicInput } from \"./models/ModelBuilder.js\";\n\n/**\n * Augmentable model settings interface.\n * External packages can extend this via module augmentation.\n */\nexport interface IModelSettings {\n aiEntryWizard?: boolean;\n previewPrefix?: string;\n previewSlug?: string;\n [key: string]: any;\n}\n\n/**\n * Augmentable field builder registry. Provides access to all registered field types.\n */\nexport interface IFieldBuilderRegistry {\n /**\n * Mark the next field creation as an extension.\n * When extending, the registry will create a temporary builder marked with _extendMode,\n * and BaseModelBuilder will merge its operations into the existing field.\n */\n extend(): this;\n\n // Field types will be added via module augmentation by field type implementations\n // Example: text(): ITextFieldBuilder;\n}\n\n/**\n * @internal Do not export this abstraction. We don't want external developers to use it.\n */\nexport const FieldBuilderRegistry =\n createAbstraction<FieldBuilderRegistry.Interface>(\"FieldBuilderRegistry\");\n\nexport namespace FieldBuilderRegistry {\n export interface Interface extends IFieldBuilderRegistry {}\n}\n\n/**\n * Unified Model abstraction\n * External developers implement this to provide both public and private models\n */\n\nexport interface IModelBuilder {\n private(input: IModelBuilderPrivateInput): PrivateModelBuilder;\n public(input: IModelBuilderPublicInput): PublicModelBuilder;\n}\n\nexport interface IModelFactory {\n execute(builder: IModelBuilder): Promise<PrivateModelBuilder[] | PublicModelBuilder[]>;\n}\n\n/** Provide code-defined content models. */\nexport const ModelFactory = createAbstraction<IModelFactory>(\"Cms/ModelFactory\");\nexport namespace ModelFactory {\n export type Interface = IModelFactory;\n export type Return = Promise<PrivateModelBuilder[] | PublicModelBuilder[]>;\n export type Builder = IModelBuilder;\n export type FieldBuilder = FieldBuilderRegistry.Interface;\n}\n"],"names":["FieldBuilderRegistry","createAbstraction","ModelFactory"],"mappings":";AAkCO,MAAMA,uBACTC,kBAAkD;AAqB/C,MAAMC,eAAeD,kBAAiC"}
1
+ {"version":3,"file":"features/modelBuilder/abstractions.js","sources":["../../../src/features/modelBuilder/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { PrivateModelBuilder } from \"./models/PrivateModelBuilder.js\";\nimport type { PublicModelBuilder } from \"./models/PublicModelBuilder.js\";\nimport type { IModelBuilderPrivateInput, IModelBuilderPublicInput } from \"./models/ModelBuilder.js\";\n\n/**\n * Augmentable model settings interface.\n * External packages can extend this via module augmentation.\n */\nexport interface IModelSettings {\n aiEntryWizard?: boolean;\n previewPath?: string;\n [key: string]: any;\n}\n\n/**\n * Augmentable field builder registry. Provides access to all registered field types.\n */\nexport interface IFieldBuilderRegistry {\n /**\n * Mark the next field creation as an extension.\n * When extending, the registry will create a temporary builder marked with _extendMode,\n * and BaseModelBuilder will merge its operations into the existing field.\n */\n extend(): this;\n\n // Field types will be added via module augmentation by field type implementations\n // Example: text(): ITextFieldBuilder;\n}\n\n/**\n * @internal Do not export this abstraction. We don't want external developers to use it.\n */\nexport const FieldBuilderRegistry =\n createAbstraction<FieldBuilderRegistry.Interface>(\"FieldBuilderRegistry\");\n\nexport namespace FieldBuilderRegistry {\n export interface Interface extends IFieldBuilderRegistry {}\n}\n\n/**\n * Unified Model abstraction\n * External developers implement this to provide both public and private models\n */\n\nexport interface IModelBuilder {\n private(input: IModelBuilderPrivateInput): PrivateModelBuilder;\n public(input: IModelBuilderPublicInput): PublicModelBuilder;\n}\n\nexport interface IModelFactory {\n execute(builder: IModelBuilder): Promise<PrivateModelBuilder[] | PublicModelBuilder[]>;\n}\n\n/** Provide code-defined content models. */\nexport const ModelFactory = createAbstraction<IModelFactory>(\"Cms/ModelFactory\");\nexport namespace ModelFactory {\n export type Interface = IModelFactory;\n export type Return = Promise<PrivateModelBuilder[] | PublicModelBuilder[]>;\n export type Builder = IModelBuilder;\n export type FieldBuilder = FieldBuilderRegistry.Interface;\n}\n"],"names":["FieldBuilderRegistry","createAbstraction","ModelFactory"],"mappings":";AAiCO,MAAMA,uBACTC,kBAAkD;AAqB/C,MAAMC,eAAeD,kBAAiC"}
@@ -0,0 +1,13 @@
1
+ import { RuntimeTenant as Abstraction } from "./abstractions.js";
2
+ import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
3
+ declare class RuntimeTenantImpl implements Abstraction.Interface {
4
+ private tenantContext;
5
+ constructor(tenantContext: TenantContext.Interface);
6
+ assign<T extends {
7
+ tenant: string;
8
+ }>(obj: T): T;
9
+ }
10
+ export declare const RuntimeTenant: typeof RuntimeTenantImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IRuntimeTenant>;
12
+ };
13
+ export {};
@@ -0,0 +1,22 @@
1
+ import { RuntimeTenant } from "./abstractions.js";
2
+ import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
3
+ class RuntimeTenantImpl {
4
+ constructor(tenantContext){
5
+ this.tenantContext = tenantContext;
6
+ }
7
+ assign(obj) {
8
+ return structuredClone({
9
+ ...obj,
10
+ tenant: this.tenantContext.getTenant().id
11
+ });
12
+ }
13
+ }
14
+ const RuntimeTenant_RuntimeTenant = RuntimeTenant.createImplementation({
15
+ implementation: RuntimeTenantImpl,
16
+ dependencies: [
17
+ TenantContext
18
+ ]
19
+ });
20
+ export { RuntimeTenant_RuntimeTenant as RuntimeTenant };
21
+
22
+ //# sourceMappingURL=RuntimeTenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/runtimeTenant/RuntimeTenant.js","sources":["../../../src/features/runtimeTenant/RuntimeTenant.ts"],"sourcesContent":["import { RuntimeTenant as Abstraction } from \"./abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/exports/api/tenancy.js\";\n\nclass RuntimeTenantImpl implements Abstraction.Interface {\n public constructor(private tenantContext: TenantContext.Interface) {}\n\n public assign<T extends { tenant: string }>(obj: T): T {\n return structuredClone({ ...obj, tenant: this.tenantContext.getTenant().id });\n }\n}\n\nexport const RuntimeTenant = Abstraction.createImplementation({\n implementation: RuntimeTenantImpl,\n dependencies: [TenantContext]\n});\n"],"names":["RuntimeTenantImpl","tenantContext","obj","structuredClone","RuntimeTenant","Abstraction","TenantContext"],"mappings":";;AAGA,MAAMA;IACF,YAA2BC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,OAAqCC,GAAM,EAAK;QACnD,OAAOC,gBAAgB;YAAE,GAAGD,GAAG;YAAE,QAAQ,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAAC;IAC/E;AACJ;AAEO,MAAME,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBL;IAChB,cAAc;QAACM;KAAc;AACjC"}
@@ -0,0 +1,11 @@
1
+ interface HasTenant {
2
+ tenant: string;
3
+ }
4
+ export interface IRuntimeTenant {
5
+ assign<T extends HasTenant>(obj: T): T;
6
+ }
7
+ export declare const RuntimeTenant: import("@webiny/di").Abstraction<IRuntimeTenant>;
8
+ export declare namespace RuntimeTenant {
9
+ type Interface = IRuntimeTenant;
10
+ }
11
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const RuntimeTenant = createAbstraction("Cms/RuntimeTenant");
3
+ export { RuntimeTenant };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/runtimeTenant/abstractions.js","sources":["../../../src/features/runtimeTenant/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\ninterface HasTenant {\n tenant: string;\n}\n\nexport interface IRuntimeTenant {\n assign<T extends HasTenant>(obj: T): T;\n}\n\nexport const RuntimeTenant = createAbstraction<IRuntimeTenant>(\"Cms/RuntimeTenant\");\n\nexport namespace RuntimeTenant {\n export type Interface = IRuntimeTenant;\n}\n"],"names":["RuntimeTenant","createAbstraction"],"mappings":";AAUO,MAAMA,gBAAgBC,kBAAkC"}
@@ -0,0 +1,2 @@
1
+ export { RuntimeTenant } from "./abstractions.js";
2
+ export { RuntimeTenant as RuntimeTenantImplementation } from "./RuntimeTenant.js";
@@ -0,0 +1,2 @@
1
+ export { RuntimeTenant } from "./abstractions.js";
2
+ export { RuntimeTenant as RuntimeTenantImplementation } from "./RuntimeTenant.js";
@@ -4,10 +4,7 @@ class SortImpl {
4
4
  const { fields: modelFields, input } = params;
5
5
  if (!input) return;
6
6
  const fields = modelFields.map((field)=>field.fieldId);
7
- const isField = (key)=>{
8
- const field = key.split("_")[0];
9
- return fields.includes(field);
10
- };
7
+ const isField = (key)=>fields.includes(key);
11
8
  return this.mapSort({
12
9
  input,
13
10
  isField
@@ -16,7 +13,7 @@ class SortImpl {
16
13
  mapSort(params) {
17
14
  const { input, isField } = params;
18
15
  return input.map((sort)=>{
19
- const match = sort.match(/^(values_)?([a-zA-Z][a-zA-Z0-9]*)_(ASC|DESC)$/);
16
+ const match = sort.match(/^(values_)?([a-zA-Z][a-zA-Z0-9_]*)_(ASC|DESC)$/);
20
17
  if (!match) return null;
21
18
  const [, hasValues, field, direction] = match;
22
19
  if (hasValues) return sort;
@@ -1 +1 @@
1
- {"version":3,"file":"features/sortMapper/SortMapper.js","sources":["../../../src/features/sortMapper/SortMapper.ts"],"sourcesContent":["/**\n * Used to map sorting for custom CMS Models.\n */\nimport { type CmsEntryListSort } from \"~/types/types.js\";\nimport { CmsSortMapper, ICmsSortMapperParams } from \"./abstractions.js\";\n\ninterface IMapSortParams {\n input: CmsEntryListSort;\n isField: (key: string) => boolean;\n}\n\nclass SortImpl implements CmsSortMapper.Interface {\n map(params: ICmsSortMapperParams): CmsEntryListSort | undefined {\n const { fields: modelFields, input } = params;\n if (!input) {\n return undefined;\n }\n\n const fields = modelFields.map(field => {\n return field.fieldId;\n });\n\n const isField = (key: string): boolean => {\n const field = key.split(\"_\")[0];\n return fields.includes(field);\n };\n\n return this.mapSort({\n input,\n isField\n });\n }\n\n private mapSort(params: IMapSortParams): CmsEntryListSort {\n const { input, isField } = params;\n\n return input\n .map(sort => {\n const match = sort.match(/^(values_)?([a-zA-Z][a-zA-Z0-9]*)_(ASC|DESC)$/);\n if (!match) {\n return null;\n }\n\n const [, hasValues, field, direction] = match;\n\n if (hasValues) {\n return sort;\n }\n\n if (isField(field)) {\n return `values_${field}_${direction}` as unknown as CmsEntryListSort[0];\n }\n\n return sort;\n })\n .filter((item): item is CmsEntryListSort[0] => !!item);\n }\n}\n\nexport const SortMapper = CmsSortMapper.createImplementation({\n implementation: SortImpl,\n dependencies: []\n});\n"],"names":["SortImpl","params","modelFields","input","fields","field","isField","key","sort","match","hasValues","direction","item","SortMapper","CmsSortMapper"],"mappings":";AAWA,MAAMA;IACF,IAAIC,MAA4B,EAAgC;QAC5D,MAAM,EAAE,QAAQC,WAAW,EAAEC,KAAK,EAAE,GAAGF;QACvC,IAAI,CAACE,OACD;QAGJ,MAAMC,SAASF,YAAY,GAAG,CAACG,CAAAA,QACpBA,MAAM,OAAO;QAGxB,MAAMC,UAAU,CAACC;YACb,MAAMF,QAAQE,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;YAC/B,OAAOH,OAAO,QAAQ,CAACC;QAC3B;QAEA,OAAO,IAAI,CAAC,OAAO,CAAC;YAChBF;YACAG;QACJ;IACJ;IAEQ,QAAQL,MAAsB,EAAoB;QACtD,MAAM,EAAEE,KAAK,EAAEG,OAAO,EAAE,GAAGL;QAE3B,OAAOE,MACF,GAAG,CAACK,CAAAA;YACD,MAAMC,QAAQD,KAAK,KAAK,CAAC;YACzB,IAAI,CAACC,OACD,OAAO;YAGX,MAAM,GAAGC,WAAWL,OAAOM,UAAU,GAAGF;YAExC,IAAIC,WACA,OAAOF;YAGX,IAAIF,QAAQD,QACR,OAAO,CAAC,OAAO,EAAEA,MAAM,CAAC,EAAEM,WAAW;YAGzC,OAAOH;QACX,GACC,MAAM,CAAC,CAACI,OAAsC,CAAC,CAACA;IACzD;AACJ;AAEO,MAAMC,aAAaC,cAAc,oBAAoB,CAAC;IACzD,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/sortMapper/SortMapper.js","sources":["../../../src/features/sortMapper/SortMapper.ts"],"sourcesContent":["/**\n * Used to map sorting for custom CMS Models.\n */\nimport { type CmsEntryListSort } from \"~/types/types.js\";\nimport { CmsSortMapper, ICmsSortMapperParams } from \"./abstractions.js\";\n\ninterface IMapSortParams {\n input: CmsEntryListSort;\n isField: (key: string) => boolean;\n}\n\nclass SortImpl implements CmsSortMapper.Interface {\n map(params: ICmsSortMapperParams): CmsEntryListSort | undefined {\n const { fields: modelFields, input } = params;\n if (!input) {\n return undefined;\n }\n\n const fields = modelFields.map(field => {\n return field.fieldId;\n });\n\n /*\n * `mapSort` has already stripped the direction, so what arrives here is a bare fieldId and\n * is compared whole. Taking the segment before the first `_` would fail every fieldId that\n * contains one: `on_sale` would be looked up as `on`.\n */\n const isField = (key: string): boolean => {\n return fields.includes(key);\n };\n\n return this.mapSort({\n input,\n isField\n });\n }\n\n private mapSort(params: IMapSortParams): CmsEntryListSort {\n const { input, isField } = params;\n\n return input\n .map(sort => {\n // `_` is allowed inside the fieldId: excluding it made `on_sale_DESC` unmatchable,\n // and an unmatched directive is dropped from the sort entirely.\n const match = sort.match(/^(values_)?([a-zA-Z][a-zA-Z0-9_]*)_(ASC|DESC)$/);\n if (!match) {\n return null;\n }\n\n const [, hasValues, field, direction] = match;\n\n if (hasValues) {\n return sort;\n }\n\n if (isField(field)) {\n return `values_${field}_${direction}` as unknown as CmsEntryListSort[0];\n }\n\n return sort;\n })\n .filter((item): item is CmsEntryListSort[0] => !!item);\n }\n}\n\nexport const SortMapper = CmsSortMapper.createImplementation({\n implementation: SortImpl,\n dependencies: []\n});\n"],"names":["SortImpl","params","modelFields","input","fields","field","isField","key","sort","match","hasValues","direction","item","SortMapper","CmsSortMapper"],"mappings":";AAWA,MAAMA;IACF,IAAIC,MAA4B,EAAgC;QAC5D,MAAM,EAAE,QAAQC,WAAW,EAAEC,KAAK,EAAE,GAAGF;QACvC,IAAI,CAACE,OACD;QAGJ,MAAMC,SAASF,YAAY,GAAG,CAACG,CAAAA,QACpBA,MAAM,OAAO;QAQxB,MAAMC,UAAU,CAACC,MACNH,OAAO,QAAQ,CAACG;QAG3B,OAAO,IAAI,CAAC,OAAO,CAAC;YAChBJ;YACAG;QACJ;IACJ;IAEQ,QAAQL,MAAsB,EAAoB;QACtD,MAAM,EAAEE,KAAK,EAAEG,OAAO,EAAE,GAAGL;QAE3B,OAAOE,MACF,GAAG,CAACK,CAAAA;YAGD,MAAMC,QAAQD,KAAK,KAAK,CAAC;YACzB,IAAI,CAACC,OACD,OAAO;YAGX,MAAM,GAAGC,WAAWL,OAAOM,UAAU,GAAGF;YAExC,IAAIC,WACA,OAAOF;YAGX,IAAIF,QAAQD,QACR,OAAO,CAAC,OAAO,EAAEA,MAAM,CAAC,EAAEM,WAAW;YAGzC,OAAOH;QACX,GACC,MAAM,CAAC,CAACI,OAAsC,CAAC,CAACA;IACzD;AACJ;AAEO,MAAMC,aAAaC,cAAc,oBAAoB,CAAC;IACzD,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
@@ -26,20 +26,30 @@ class StorageTransformImpl {
26
26
  const { value, field, getStorageTransform, model } = params;
27
27
  if (!value) return null;
28
28
  const fields = field.settings?.fields || [];
29
- if (field.list) return await p_map(value, (value)=>processValue({
30
- sourceValue: value,
29
+ if (field.list) return await p_map(value, async (itemValue)=>{
30
+ const processed = await processValue({
31
+ sourceValue: itemValue,
31
32
  getStorageTransform,
32
33
  model,
33
34
  operation: "toStorage",
34
35
  fields
35
- }));
36
- return await processValue({
36
+ });
37
+ return itemValue._id ? {
38
+ _id: itemValue._id,
39
+ ...processed
40
+ } : processed;
41
+ });
42
+ const processed = await processValue({
37
43
  sourceValue: value,
38
44
  getStorageTransform,
39
45
  model,
40
46
  operation: "toStorage",
41
47
  fields
42
48
  });
49
+ return value._id ? {
50
+ _id: value._id,
51
+ ...processed
52
+ } : processed;
43
53
  }
44
54
  async fromStorage(params) {
45
55
  const { field, value: input, getStorageTransform, model } = params;
@@ -47,21 +57,31 @@ class StorageTransformImpl {
47
57
  const fields = field.settings?.fields || [];
48
58
  if (field.list) {
49
59
  const values = input;
50
- return await Promise.all(values.map(async (value)=>await processValue({
60
+ return await Promise.all(values.map(async (value)=>{
61
+ const processed = await processValue({
51
62
  sourceValue: value,
52
63
  getStorageTransform,
53
64
  model,
54
65
  operation: "fromStorage",
55
66
  fields
56
- })));
67
+ });
68
+ return value._id ? {
69
+ _id: value._id,
70
+ ...processed
71
+ } : processed;
72
+ }));
57
73
  }
58
- return await processValue({
74
+ const processed = await processValue({
59
75
  sourceValue: input,
60
76
  getStorageTransform,
61
77
  model,
62
78
  operation: "fromStorage",
63
79
  fields
64
80
  });
81
+ return input._id ? {
82
+ _id: input._id,
83
+ ...processed
84
+ } : processed;
65
85
  }
66
86
  constructor(){
67
87
  this.fieldType = "object";
@@ -1 +1 @@
1
- {"version":3,"file":"features/storage/fields/ObjectStorageTransform.js","sources":["../../../../src/features/storage/fields/ObjectStorageTransform.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport pMap from \"p-map\";\nimport type { CmsModel, CmsModelField } from \"~/types/index.js\";\nimport { StorageTransform } from \"../abstractions/StorageTransform.js\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\ninterface ProcessValueParams {\n fields: CmsModelField[];\n sourceValue: GenericRecord;\n getStorageTransform: (fieldType: string) => StorageTransform.Interface;\n model: CmsModel;\n operation: \"toStorage\" | \"fromStorage\";\n}\ninterface ProcessValue {\n (params: ProcessValueParams): Promise<GenericRecord>;\n}\n\nconst processValue: ProcessValue = async params => {\n const { fields, sourceValue, getStorageTransform, model, operation } = params;\n return await pReduce(\n fields,\n async (values, field) => {\n const baseType = getBaseFieldType(field);\n const storageTransform = getStorageTransform(baseType);\n if (!storageTransform) {\n throw new Error(`Missing storage transform for field type \"${baseType}\".`);\n }\n const input = sourceValue[field.fieldId];\n const value = await storageTransform[operation]({\n model,\n field,\n value: input,\n getStorageTransform\n });\n return { ...values, [field.fieldId]: value };\n },\n {}\n );\n};\n\nclass StorageTransformImpl implements StorageTransform.Interface {\n public readonly fieldType = \"object\";\n\n public async toStorage(\n params: StorageTransform.ToStorageParams\n ): StorageTransform.ToStorageResponse {\n const { value, field, getStorageTransform, model } = params;\n if (!value) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n return await pMap(value as GenericRecord[], value =>\n processValue({\n sourceValue: value,\n getStorageTransform,\n model,\n operation: \"toStorage\",\n fields\n })\n );\n }\n\n return await processValue({\n sourceValue: value,\n getStorageTransform,\n model,\n operation: \"toStorage\",\n fields\n });\n }\n\n public async fromStorage(\n params: StorageTransform.FromStorageParams\n ): StorageTransform.FromStorageResponse {\n const { field, value: input, getStorageTransform, model } = params;\n if (!input) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n const values = input as GenericRecord[];\n\n return await Promise.all(\n values.map(async value => {\n return await processValue({\n sourceValue: value,\n getStorageTransform,\n model,\n operation: \"fromStorage\",\n fields\n });\n })\n );\n }\n\n return await processValue({\n sourceValue: input,\n getStorageTransform,\n model,\n operation: \"fromStorage\",\n fields\n });\n }\n}\n\nexport const ObjectStorageTransform = StorageTransform.createImplementation({\n implementation: StorageTransformImpl,\n dependencies: []\n});\n"],"names":["processValue","params","fields","sourceValue","getStorageTransform","model","operation","pReduce","values","field","baseType","getBaseFieldType","storageTransform","Error","input","value","StorageTransformImpl","pMap","Promise","ObjectStorageTransform","StorageTransform"],"mappings":";;;;AAkBA,MAAMA,eAA6B,OAAMC;IACrC,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGL;IACvE,OAAO,MAAMM,SACTL,QACA,OAAOM,QAAQC;QACX,MAAMC,WAAWC,iBAAiBF;QAClC,MAAMG,mBAAmBR,oBAAoBM;QAC7C,IAAI,CAACE,kBACD,MAAM,IAAIC,MAAM,CAAC,0CAA0C,EAAEH,SAAS,EAAE,CAAC;QAE7E,MAAMI,QAAQX,WAAW,CAACM,MAAM,OAAO,CAAC;QACxC,MAAMM,QAAQ,MAAMH,gBAAgB,CAACN,UAAU,CAAC;YAC5CD;YACAI;YACA,OAAOK;YACPV;QACJ;QACA,OAAO;YAAE,GAAGI,MAAM;YAAE,CAACC,MAAM,OAAO,CAAC,EAAEM;QAAM;IAC/C,GACA,CAAC;AAET;AAEA,MAAMC;IAGF,MAAa,UACTf,MAAwC,EACN;QAClC,MAAM,EAAEc,KAAK,EAAEN,KAAK,EAAEL,mBAAmB,EAAEC,KAAK,EAAE,GAAGJ;QACrD,IAAI,CAACc,OACD,OAAO;QAGX,MAAMb,SAAUO,MAAM,QAAQ,EAAE,UAAU,EAAE;QAE5C,IAAIA,MAAM,IAAI,EACV,OAAO,MAAMQ,MAAKF,OAA0BA,CAAAA,QACxCf,aAAa;gBACT,aAAae;gBACbX;gBACAC;gBACA,WAAW;gBACXH;YACJ;QAIR,OAAO,MAAMF,aAAa;YACtB,aAAae;YACbX;YACAC;YACA,WAAW;YACXH;QACJ;IACJ;IAEA,MAAa,YACTD,MAA0C,EACN;QACpC,MAAM,EAAEQ,KAAK,EAAE,OAAOK,KAAK,EAAEV,mBAAmB,EAAEC,KAAK,EAAE,GAAGJ;QAC5D,IAAI,CAACa,OACD,OAAO;QAGX,MAAMZ,SAAUO,MAAM,QAAQ,EAAE,UAAU,EAAE;QAE5C,IAAIA,MAAM,IAAI,EAAE;YACZ,MAAMD,SAASM;YAEf,OAAO,MAAMI,QAAQ,GAAG,CACpBV,OAAO,GAAG,CAAC,OAAMO,QACN,MAAMf,aAAa;oBACtB,aAAae;oBACbX;oBACAC;oBACA,WAAW;oBACXH;gBACJ;QAGZ;QAEA,OAAO,MAAMF,aAAa;YACtB,aAAac;YACbV;YACAC;YACA,WAAW;YACXH;QACJ;IACJ;;aAlEgB,SAAS,GAAG;;AAmEhC;AAEO,MAAMiB,yBAAyBC,iBAAiB,oBAAoB,CAAC;IACxE,gBAAgBJ;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/storage/fields/ObjectStorageTransform.js","sources":["../../../../src/features/storage/fields/ObjectStorageTransform.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport pMap from \"p-map\";\nimport type { CmsModel, CmsModelField } from \"~/types/index.js\";\nimport { StorageTransform } from \"../abstractions/StorageTransform.js\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\ninterface ProcessValueParams {\n fields: CmsModelField[];\n sourceValue: GenericRecord;\n getStorageTransform: (fieldType: string) => StorageTransform.Interface;\n model: CmsModel;\n operation: \"toStorage\" | \"fromStorage\";\n}\ninterface ProcessValue {\n (params: ProcessValueParams): Promise<GenericRecord>;\n}\n\nconst processValue: ProcessValue = async params => {\n const { fields, sourceValue, getStorageTransform, model, operation } = params;\n return await pReduce(\n fields,\n async (values, field) => {\n const baseType = getBaseFieldType(field);\n const storageTransform = getStorageTransform(baseType);\n if (!storageTransform) {\n throw new Error(`Missing storage transform for field type \"${baseType}\".`);\n }\n const input = sourceValue[field.fieldId];\n const value = await storageTransform[operation]({\n model,\n field,\n value: input,\n getStorageTransform\n });\n return { ...values, [field.fieldId]: value };\n },\n {}\n );\n};\n\nclass StorageTransformImpl implements StorageTransform.Interface {\n public readonly fieldType = \"object\";\n\n public async toStorage(\n params: StorageTransform.ToStorageParams\n ): StorageTransform.ToStorageResponse {\n const { value, field, getStorageTransform, model } = params;\n if (!value) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n return await pMap(value as GenericRecord[], async itemValue => {\n const processed = await processValue({\n sourceValue: itemValue,\n getStorageTransform,\n model,\n operation: \"toStorage\",\n fields\n });\n return itemValue._id ? { _id: itemValue._id, ...processed } : processed;\n });\n }\n\n const processed = await processValue({\n sourceValue: value,\n getStorageTransform,\n model,\n operation: \"toStorage\",\n fields\n });\n return value._id ? { _id: value._id, ...processed } : processed;\n }\n\n public async fromStorage(\n params: StorageTransform.FromStorageParams\n ): StorageTransform.FromStorageResponse {\n const { field, value: input, getStorageTransform, model } = params;\n if (!input) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n const values = input as GenericRecord[];\n\n return await Promise.all(\n values.map(async value => {\n const processed = await processValue({\n sourceValue: value,\n getStorageTransform,\n model,\n operation: \"fromStorage\",\n fields\n });\n return value._id ? { _id: value._id, ...processed } : processed;\n })\n );\n }\n\n const processed = await processValue({\n sourceValue: input,\n getStorageTransform,\n model,\n operation: \"fromStorage\",\n fields\n });\n return input._id ? { _id: input._id, ...processed } : processed;\n }\n}\n\nexport const ObjectStorageTransform = StorageTransform.createImplementation({\n implementation: StorageTransformImpl,\n dependencies: []\n});\n"],"names":["processValue","params","fields","sourceValue","getStorageTransform","model","operation","pReduce","values","field","baseType","getBaseFieldType","storageTransform","Error","input","value","StorageTransformImpl","pMap","itemValue","processed","Promise","ObjectStorageTransform","StorageTransform"],"mappings":";;;;AAkBA,MAAMA,eAA6B,OAAMC;IACrC,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAAGL;IACvE,OAAO,MAAMM,SACTL,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,UAAU,EAAE;QAE5C,IAAIA,MAAM,IAAI,EAAE;YACZ,MAAMD,SAASM;YAEf,OAAO,MAAMM,QAAQ,GAAG,CACpBZ,OAAO,GAAG,CAAC,OAAMO;gBACb,MAAMI,YAAY,MAAMnB,aAAa;oBACjC,aAAae;oBACbX;oBACAC;oBACA,WAAW;oBACXH;gBACJ;gBACA,OAAOa,MAAM,GAAG,GAAG;oBAAE,KAAKA,MAAM,GAAG;oBAAE,GAAGI,SAAS;gBAAC,IAAIA;YAC1D;QAER;QAEA,MAAMA,YAAY,MAAMnB,aAAa;YACjC,aAAac;YACbV;YACAC;YACA,WAAW;YACXH;QACJ;QACA,OAAOY,MAAM,GAAG,GAAG;YAAE,KAAKA,MAAM,GAAG;YAAE,GAAGK,SAAS;QAAC,IAAIA;IAC1D;;aAtEgB,SAAS,GAAG;;AAuEhC;AAEO,MAAME,yBAAyBC,iBAAiB,oBAAoB,CAAC;IACxE,gBAAgBN;IAChB,cAAc,EAAE;AACpB"}
@@ -15,7 +15,7 @@ class PatternValidatorImpl {
15
15
  if (patternValidator) pattern = patternValidator.pattern;
16
16
  }
17
17
  if (!pattern) return true;
18
- return new RegExp(pattern.regex, pattern.flags).test(value);
18
+ return new RegExp(pattern.regex, pattern.flags || void 0).test(value);
19
19
  }
20
20
  }
21
21
  const PatternValidator = CmsModelFieldValidator.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"features/validation/validators/PatternValidator.js","sources":["../../../../src/features/validation/validators/PatternValidator.ts"],"sourcesContent":["import { CmsModelFieldValidator } from \"../abstractions/CmsModelFieldValidator.js\";\nimport { CmsModelFieldPatternValidatorRegistry } from \"../abstractions/CmsModelFieldPatternValidatorRegistry.js\";\nimport type { CmsModelFieldValidatorValidateParams } from \"~/types/types.js\";\n\nclass PatternValidatorImpl implements CmsModelFieldValidator.Interface {\n public readonly name = \"pattern\";\n\n public constructor(\n private readonly patternRegistry: CmsModelFieldPatternValidatorRegistry.Interface\n ) {}\n\n public async validate({\n value,\n validator\n }: CmsModelFieldValidatorValidateParams): Promise<boolean> {\n if (typeof value !== \"string\" || !value) {\n return true;\n }\n\n const { settings } = validator;\n\n let pattern;\n if (settings?.preset === \"custom\") {\n pattern = settings;\n } else if (settings?.preset) {\n const patternValidator = this.patternRegistry.get(settings.preset);\n if (patternValidator) {\n pattern = patternValidator.pattern;\n }\n }\n\n if (!pattern) {\n return true;\n }\n\n return new RegExp(pattern.regex, pattern.flags).test(value);\n }\n}\n\nexport const PatternValidator = CmsModelFieldValidator.createImplementation({\n implementation: PatternValidatorImpl,\n dependencies: [CmsModelFieldPatternValidatorRegistry]\n});\n"],"names":["PatternValidatorImpl","patternRegistry","value","validator","settings","pattern","patternValidator","RegExp","PatternValidator","CmsModelFieldValidator","CmsModelFieldPatternValidatorRegistry"],"mappings":";;AAIA,MAAMA;IAGF,YACqBC,eAAgE,CACnF;aADmBA,eAAe,GAAfA;aAHL,IAAI,GAAG;IAIpB;IAEH,MAAa,SAAS,EAClBC,KAAK,EACLC,SAAS,EAC0B,EAAoB;QACvD,IAAI,AAAiB,YAAjB,OAAOD,SAAsB,CAACA,OAC9B,OAAO;QAGX,MAAM,EAAEE,QAAQ,EAAE,GAAGD;QAErB,IAAIE;QACJ,IAAID,UAAU,WAAW,UACrBC,UAAUD;aACP,IAAIA,UAAU,QAAQ;YACzB,MAAME,mBAAmB,IAAI,CAAC,eAAe,CAAC,GAAG,CAACF,SAAS,MAAM;YACjE,IAAIE,kBACAD,UAAUC,iBAAiB,OAAO;QAE1C;QAEA,IAAI,CAACD,SACD,OAAO;QAGX,OAAO,IAAIE,OAAOF,QAAQ,KAAK,EAAEA,QAAQ,KAAK,EAAE,IAAI,CAACH;IACzD;AACJ;AAEO,MAAMM,mBAAmBC,uBAAuB,oBAAoB,CAAC;IACxE,gBAAgBT;IAChB,cAAc;QAACU;KAAsC;AACzD"}
1
+ {"version":3,"file":"features/validation/validators/PatternValidator.js","sources":["../../../../src/features/validation/validators/PatternValidator.ts"],"sourcesContent":["import { CmsModelFieldValidator } from \"../abstractions/CmsModelFieldValidator.js\";\nimport { CmsModelFieldPatternValidatorRegistry } from \"../abstractions/CmsModelFieldPatternValidatorRegistry.js\";\nimport type { CmsModelFieldValidatorValidateParams } from \"~/types/types.js\";\n\nclass PatternValidatorImpl implements CmsModelFieldValidator.Interface {\n public readonly name = \"pattern\";\n\n public constructor(\n private readonly patternRegistry: CmsModelFieldPatternValidatorRegistry.Interface\n ) {}\n\n public async validate({\n value,\n validator\n }: CmsModelFieldValidatorValidateParams): Promise<boolean> {\n if (typeof value !== \"string\" || !value) {\n return true;\n }\n\n const { settings } = validator;\n\n let pattern;\n if (settings?.preset === \"custom\") {\n pattern = settings;\n } else if (settings?.preset) {\n const patternValidator = this.patternRegistry.get(settings.preset);\n if (patternValidator) {\n pattern = patternValidator.pattern;\n }\n }\n\n if (!pattern) {\n return true;\n }\n\n return new RegExp(pattern.regex, pattern.flags || undefined).test(value);\n }\n}\n\nexport const PatternValidator = CmsModelFieldValidator.createImplementation({\n implementation: PatternValidatorImpl,\n dependencies: [CmsModelFieldPatternValidatorRegistry]\n});\n"],"names":["PatternValidatorImpl","patternRegistry","value","validator","settings","pattern","patternValidator","RegExp","undefined","PatternValidator","CmsModelFieldValidator","CmsModelFieldPatternValidatorRegistry"],"mappings":";;AAIA,MAAMA;IAGF,YACqBC,eAAgE,CACnF;aADmBA,eAAe,GAAfA;aAHL,IAAI,GAAG;IAIpB;IAEH,MAAa,SAAS,EAClBC,KAAK,EACLC,SAAS,EAC0B,EAAoB;QACvD,IAAI,AAAiB,YAAjB,OAAOD,SAAsB,CAACA,OAC9B,OAAO;QAGX,MAAM,EAAEE,QAAQ,EAAE,GAAGD;QAErB,IAAIE;QACJ,IAAID,UAAU,WAAW,UACrBC,UAAUD;aACP,IAAIA,UAAU,QAAQ;YACzB,MAAME,mBAAmB,IAAI,CAAC,eAAe,CAAC,GAAG,CAACF,SAAS,MAAM;YACjE,IAAIE,kBACAD,UAAUC,iBAAiB,OAAO;QAE1C;QAEA,IAAI,CAACD,SACD,OAAO;QAGX,OAAO,IAAIE,OAAOF,QAAQ,KAAK,EAAEA,QAAQ,KAAK,IAAIG,QAAW,IAAI,CAACN;IACtE;AACJ;AAEO,MAAMO,mBAAmBC,uBAAuB,oBAAoB,CAAC;IACxE,gBAAgBV;IAChB,cAAc;QAACW;KAAsC;AACzD"}
@@ -9,11 +9,8 @@ class WhereMapperImpl {
9
9
  map(params) {
10
10
  const { fields: modelFields, input } = params;
11
11
  if (!input) return;
12
- const fields = modelFields.map((field)=>field.fieldId);
13
- const isField = (key)=>{
14
- const field = key.split("_")[0];
15
- return fields.includes(field);
16
- };
12
+ const fields = modelFields.map((field)=>field.fieldId).sort((a, b)=>b.length - a.length);
13
+ const isField = (key)=>fields.some((fieldId)=>key === fieldId || key.startsWith(`${fieldId}_`));
17
14
  return this.mapWhere({
18
15
  input,
19
16
  isField
@@ -33,6 +30,11 @@ class WhereMapperImpl {
33
30
  }));
34
31
  continue;
35
32
  }
33
+ if ("values" === key && isPlainObject(value)) {
34
+ if (!out.values) out.values = {};
35
+ Object.assign(out.values, value);
36
+ continue;
37
+ }
36
38
  if (isField(key)) {
37
39
  if (!out.values) out.values = {};
38
40
  out.values[key] = value;
@@ -1 +1 @@
1
- {"version":3,"file":"features/whereMapper/WhereMapper.js","sources":["../../../src/features/whereMapper/WhereMapper.ts"],"sourcesContent":["/**\n * Used to map a model with custom schema with fields in a root to values object.\n * eg. File Manager File model has \"title\" and \"tags\" fields in the root, but they should be\n * mapped to \"values.title\" and \"values.tags\" when creating the entry.\n */\nimport { GenericRecord } from \"@webiny/api/types.js\";\nimport { CmsEntryListWhere } from \"~/types/types.js\";\nimport { CmsWhereMapper, ICmsWhereMapperParams } from \"./abstractions.js\";\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (!value || typeof value !== \"object\") {\n return false;\n } else if (Array.isArray(value)) {\n return false;\n }\n return true;\n};\n\nconst isLogicalKey = (key: string): key is \"AND\" | \"OR\" => {\n return key === \"AND\" || key === \"OR\";\n};\n\ninterface IMapNodeWhereParams {\n input: GenericRecord;\n isField: (key: string) => boolean;\n}\n\nclass WhereMapperImpl implements CmsWhereMapper.Interface {\n map<T extends GenericRecord>(params: ICmsWhereMapperParams<T>): CmsEntryListWhere | undefined {\n const { fields: modelFields, input } = params;\n if (!input) {\n return undefined;\n }\n\n const fields = modelFields.map(field => {\n return field.fieldId;\n });\n\n const isField = (key: string): boolean => {\n const field = key.split(\"_\")[0];\n return fields.includes(field);\n };\n\n return this.mapWhere({\n input,\n isField\n });\n }\n\n private mapWhere(params: IMapNodeWhereParams) {\n const { input, isField } = params;\n const out: CmsEntryListWhere = {};\n\n const keys = Object.keys(input) as (keyof typeof out)[];\n if (keys.length === 0) {\n return out;\n }\n\n for (const key of keys) {\n const value = input[key];\n\n if (isLogicalKey(key)) {\n if (Array.isArray(value)) {\n out[key] = value.filter(isPlainObject).map(child => {\n return this.mapWhere({\n input: child,\n isField\n });\n });\n }\n continue;\n } else if (isField(key)) {\n if (!out.values) {\n out.values = {};\n }\n out.values[key] = value;\n continue;\n }\n\n out[key] = value;\n }\n\n return out;\n }\n}\n\nexport const WhereMapper = CmsWhereMapper.createImplementation({\n implementation: WhereMapperImpl,\n dependencies: []\n});\n"],"names":["isPlainObject","value","Array","isLogicalKey","key","WhereMapperImpl","params","modelFields","input","fields","field","isField","out","keys","Object","child","WhereMapper","CmsWhereMapper"],"mappings":";AASA,MAAMA,gBAAgB,CAACC;IACnB,IAAI,CAACA,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO;IACJ,IAAIC,MAAM,OAAO,CAACD,QACrB,OAAO;IAEX,OAAO;AACX;AAEA,MAAME,eAAe,CAACC,MACXA,AAAQ,UAARA,OAAiBA,AAAQ,SAARA;AAQ5B,MAAMC;IACF,IAA6BC,MAAgC,EAAiC;QAC1F,MAAM,EAAE,QAAQC,WAAW,EAAEC,KAAK,EAAE,GAAGF;QACvC,IAAI,CAACE,OACD;QAGJ,MAAMC,SAASF,YAAY,GAAG,CAACG,CAAAA,QACpBA,MAAM,OAAO;QAGxB,MAAMC,UAAU,CAACP;YACb,MAAMM,QAAQN,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;YAC/B,OAAOK,OAAO,QAAQ,CAACC;QAC3B;QAEA,OAAO,IAAI,CAAC,QAAQ,CAAC;YACjBF;YACAG;QACJ;IACJ;IAEQ,SAASL,MAA2B,EAAE;QAC1C,MAAM,EAAEE,KAAK,EAAEG,OAAO,EAAE,GAAGL;QAC3B,MAAMM,MAAyB,CAAC;QAEhC,MAAMC,OAAOC,OAAO,IAAI,CAACN;QACzB,IAAIK,AAAgB,MAAhBA,KAAK,MAAM,EACX,OAAOD;QAGX,KAAK,MAAMR,OAAOS,KAAM;YACpB,MAAMZ,QAAQO,KAAK,CAACJ,IAAI;YAExB,IAAID,aAAaC,MAAM;gBACnB,IAAIF,MAAM,OAAO,CAACD,QACdW,GAAG,CAACR,IAAI,GAAGH,MAAM,MAAM,CAACD,eAAe,GAAG,CAACe,CAAAA,QAChC,IAAI,CAAC,QAAQ,CAAC;wBACjB,OAAOA;wBACPJ;oBACJ;gBAGR;YACJ;YAAO,IAAIA,QAAQP,MAAM;gBACrB,IAAI,CAACQ,IAAI,MAAM,EACXA,IAAI,MAAM,GAAG,CAAC;gBAElBA,IAAI,MAAM,CAACR,IAAI,GAAGH;gBAClB;YACJ;YAEAW,GAAG,CAACR,IAAI,GAAGH;QACf;QAEA,OAAOW;IACX;AACJ;AAEO,MAAMI,cAAcC,eAAe,oBAAoB,CAAC;IAC3D,gBAAgBZ;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/whereMapper/WhereMapper.js","sources":["../../../src/features/whereMapper/WhereMapper.ts"],"sourcesContent":["/**\n * Used to map a model with custom schema with fields in a root to values object.\n * eg. File Manager File model has \"title\" and \"tags\" fields in the root, but they should be\n * mapped to \"values.title\" and \"values.tags\" when creating the entry.\n */\nimport { GenericRecord } from \"@webiny/api/types.js\";\nimport { CmsEntryListWhere } from \"~/types/types.js\";\nimport { CmsWhereMapper, ICmsWhereMapperParams } from \"./abstractions.js\";\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n if (!value || typeof value !== \"object\") {\n return false;\n } else if (Array.isArray(value)) {\n return false;\n }\n return true;\n};\n\nconst isLogicalKey = (key: string): key is \"AND\" | \"OR\" => {\n return key === \"AND\" || key === \"OR\";\n};\n\ninterface IMapNodeWhereParams {\n input: GenericRecord;\n isField: (key: string) => boolean;\n}\n\nclass WhereMapperImpl implements CmsWhereMapper.Interface {\n map<T extends GenericRecord>(params: ICmsWhereMapperParams<T>): CmsEntryListWhere | undefined {\n const { fields: modelFields, input } = params;\n if (!input) {\n return undefined;\n }\n\n /*\n * Longest fieldId first, so a key is attributed to the longest field it could belong to.\n * Taking the segment before the first `_` misreads any fieldId that contains one:\n * `on_sale_contains` resolves to a field named `on`, which does not exist, so the filter\n * silently stays at the top level and the CMS rejects it. Longest-first also keeps a model\n * with both `price` and `price_range` from being mis-routed.\n */\n const fields = modelFields.map(field => field.fieldId).sort((a, b) => b.length - a.length);\n\n const isField = (key: string): boolean => {\n return fields.some(fieldId => key === fieldId || key.startsWith(`${fieldId}_`));\n };\n\n return this.mapWhere({\n input,\n isField\n });\n }\n\n private mapWhere(params: IMapNodeWhereParams) {\n const { input, isField } = params;\n const out: CmsEntryListWhere = {};\n\n const keys = Object.keys(input) as (keyof typeof out)[];\n if (keys.length === 0) {\n return out;\n }\n\n for (const key of keys) {\n const value = input[key];\n\n if (isLogicalKey(key)) {\n if (Array.isArray(value)) {\n out[key] = value.filter(isPlainObject).map(child => {\n return this.mapWhere({\n input: child,\n isField\n });\n });\n }\n continue;\n } else if (key === \"values\" && isPlainObject(value)) {\n /*\n * A caller that already nested its model fields is taken at its word. Merged rather\n * than assigned, so an explicit `values` object and flat field keys can coexist:\n * assigning would drop whichever of the two arrived first.\n */\n if (!out.values) {\n out.values = {};\n }\n Object.assign(out.values, value);\n continue;\n } else if (isField(key)) {\n if (!out.values) {\n out.values = {};\n }\n out.values[key] = value;\n continue;\n }\n\n out[key] = value;\n }\n\n return out;\n }\n}\n\nexport const WhereMapper = CmsWhereMapper.createImplementation({\n implementation: WhereMapperImpl,\n dependencies: []\n});\n"],"names":["isPlainObject","value","Array","isLogicalKey","key","WhereMapperImpl","params","modelFields","input","fields","field","a","b","isField","fieldId","out","keys","Object","child","WhereMapper","CmsWhereMapper"],"mappings":";AASA,MAAMA,gBAAgB,CAACC;IACnB,IAAI,CAACA,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO;IACJ,IAAIC,MAAM,OAAO,CAACD,QACrB,OAAO;IAEX,OAAO;AACX;AAEA,MAAME,eAAe,CAACC,MACXA,AAAQ,UAARA,OAAiBA,AAAQ,SAARA;AAQ5B,MAAMC;IACF,IAA6BC,MAAgC,EAAiC;QAC1F,MAAM,EAAE,QAAQC,WAAW,EAAEC,KAAK,EAAE,GAAGF;QACvC,IAAI,CAACE,OACD;QAUJ,MAAMC,SAASF,YAAY,GAAG,CAACG,CAAAA,QAASA,MAAM,OAAO,EAAE,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAE,MAAM,GAAGD,EAAE,MAAM;QAEzF,MAAME,UAAU,CAACT,MACNK,OAAO,IAAI,CAACK,CAAAA,UAAWV,QAAQU,WAAWV,IAAI,UAAU,CAAC,GAAGU,QAAQ,CAAC,CAAC;QAGjF,OAAO,IAAI,CAAC,QAAQ,CAAC;YACjBN;YACAK;QACJ;IACJ;IAEQ,SAASP,MAA2B,EAAE;QAC1C,MAAM,EAAEE,KAAK,EAAEK,OAAO,EAAE,GAAGP;QAC3B,MAAMS,MAAyB,CAAC;QAEhC,MAAMC,OAAOC,OAAO,IAAI,CAACT;QACzB,IAAIQ,AAAgB,MAAhBA,KAAK,MAAM,EACX,OAAOD;QAGX,KAAK,MAAMX,OAAOY,KAAM;YACpB,MAAMf,QAAQO,KAAK,CAACJ,IAAI;YAExB,IAAID,aAAaC,MAAM;gBACnB,IAAIF,MAAM,OAAO,CAACD,QACdc,GAAG,CAACX,IAAI,GAAGH,MAAM,MAAM,CAACD,eAAe,GAAG,CAACkB,CAAAA,QAChC,IAAI,CAAC,QAAQ,CAAC;wBACjB,OAAOA;wBACPL;oBACJ;gBAGR;YACJ;YAAO,IAAIT,AAAQ,aAARA,OAAoBJ,cAAcC,QAAQ;gBAMjD,IAAI,CAACc,IAAI,MAAM,EACXA,IAAI,MAAM,GAAG,CAAC;gBAElBE,OAAO,MAAM,CAACF,IAAI,MAAM,EAAEd;gBAC1B;YACJ;YAAO,IAAIY,QAAQT,MAAM;gBACrB,IAAI,CAACW,IAAI,MAAM,EACXA,IAAI,MAAM,GAAG,CAAC;gBAElBA,IAAI,MAAM,CAACX,IAAI,GAAGH;gBAClB;YACJ;YAEAc,GAAG,CAACX,IAAI,GAAGH;QACf;QAEA,OAAOc;IACX;AACJ;AAEO,MAAMI,cAAcC,eAAe,oBAAoB,CAAC;IAC3D,gBAAgBf;IAChB,cAAc,EAAE;AACpB"}
@@ -47,7 +47,10 @@ class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlug
47
47
  Object.assign(values, converted);
48
48
  return values;
49
49
  }, {
50
- _templateId: template.id
50
+ _templateId: template.id,
51
+ ...value._id ? {
52
+ _id: value._id
53
+ } : {}
51
54
  });
52
55
  }
53
56
  convertFromStorage(params) {
@@ -61,7 +64,7 @@ class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlug
61
64
  templates,
62
65
  converterCollection,
63
66
  value: item
64
- }))
67
+ })).filter(Boolean)
65
68
  };
66
69
  }
67
70
  if (Array.isArray(value)) throw new error(`Dynamic zone field "${field.fieldId}" is expecting a non-array value.`, "DYNAMIC_ZONE_EXPECTING_NON_ARRAY_VALUE", {
@@ -82,8 +85,12 @@ class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlug
82
85
  if (null == value) return;
83
86
  const { _templateId } = value;
84
87
  const template = templates.find((t)=>t.id === _templateId);
85
- if (!template) throw new error("Unknown template - converting from storage.", "UNKNOWN_TEMPLATE", {
86
- templateId: _templateId
88
+ if (!template) return void console.warn({
89
+ message: "Unknown template - converting from storage.",
90
+ code: "UNKNOWN_TEMPLATE",
91
+ data: {
92
+ templateId: _templateId
93
+ }
87
94
  });
88
95
  return template.fields.reduce((values, field)=>{
89
96
  const converter = converterCollection.getConverter(field.type);
@@ -94,7 +101,10 @@ class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlug
94
101
  Object.assign(values, converted);
95
102
  return values;
96
103
  }, {
97
- _templateId: template.id
104
+ _templateId: template.id,
105
+ ...value._id ? {
106
+ _id: value._id
107
+ } : {}
98
108
  });
99
109
  }
100
110
  constructor(...args){