@contember/engine-content-api 2.2.0-alpha.19 → 2.2.0-alpha.20

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 (273) hide show
  1. package/CLAUDE.md +12 -7
  2. package/dist/development/index.cjs +23 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +25 -2
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ExecutionContainer.cjs +4 -3
  7. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  8. package/dist/development/src/ExecutionContainer.js +4 -3
  9. package/dist/development/src/ExecutionContainer.js.map +1 -1
  10. package/dist/development/src/acl/Authorizator.cjs +6 -1
  11. package/dist/development/src/acl/Authorizator.cjs.map +1 -1
  12. package/dist/development/src/acl/Authorizator.js +6 -1
  13. package/dist/development/src/acl/Authorizator.js.map +1 -1
  14. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
  15. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
  16. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
  17. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
  18. package/dist/development/src/introspection/introspection.schema.cjs +2 -2
  19. package/dist/development/src/introspection/introspection.schema.cjs.map +1 -1
  20. package/dist/development/src/introspection/introspection.schema.js +2 -2
  21. package/dist/development/src/introspection/introspection.schema.js.map +1 -1
  22. package/dist/development/src/mapper/select/SelectHydrator.cjs +56 -15
  23. package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
  24. package/dist/development/src/mapper/select/SelectHydrator.js +56 -15
  25. package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
  26. package/dist/development/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  27. package/dist/development/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  28. package/dist/development/src/resolvers/MutationResolver.cjs +17 -39
  29. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  30. package/dist/development/src/resolvers/MutationResolver.js +18 -40
  31. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  32. package/dist/development/src/resolvers/ReadHelpers.cjs +4 -5
  33. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  34. package/dist/development/src/resolvers/ReadHelpers.js +4 -5
  35. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  36. package/dist/development/src/resolvers/ReadResolver.cjs +8 -17
  37. package/dist/development/src/resolvers/ReadResolver.cjs.map +1 -1
  38. package/dist/development/src/resolvers/ReadResolver.js +8 -17
  39. package/dist/development/src/resolvers/ReadResolver.js.map +1 -1
  40. package/dist/development/src/schema/GraphQlSchemaBuilder.cjs +16 -6
  41. package/dist/development/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  42. package/dist/development/src/schema/GraphQlSchemaBuilder.js +16 -6
  43. package/dist/development/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  44. package/dist/development/src/schema/MutationProvider.cjs +21 -8
  45. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  46. package/dist/development/src/schema/MutationProvider.js +21 -8
  47. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  48. package/dist/development/src/schema/QueryProvider.cjs +6 -6
  49. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  50. package/dist/development/src/schema/QueryProvider.js +6 -6
  51. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  52. package/dist/development/src/schema-json/GraphQLJsBridge.cjs +108 -0
  53. package/dist/development/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
  54. package/dist/development/src/schema-json/GraphQLJsBridge.js +108 -0
  55. package/dist/development/src/schema-json/GraphQLJsBridge.js.map +1 -0
  56. package/dist/development/src/schema-json/JsonColumnTypes.cjs +102 -0
  57. package/dist/development/src/schema-json/JsonColumnTypes.cjs.map +1 -0
  58. package/dist/development/src/schema-json/JsonColumnTypes.js +102 -0
  59. package/dist/development/src/schema-json/JsonColumnTypes.js.map +1 -0
  60. package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
  61. package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
  62. package/dist/development/src/schema-json/JsonContentSchemaBuilder.js +418 -0
  63. package/dist/development/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
  64. package/dist/development/src/schema-json/JsonContentSchemaShared.cjs +18 -0
  65. package/dist/development/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
  66. package/dist/development/src/schema-json/JsonContentSchemaShared.js +18 -0
  67. package/dist/development/src/schema-json/JsonContentSchemaShared.js.map +1 -0
  68. package/dist/development/src/schema-json/JsonEntityTypes.cjs +206 -0
  69. package/dist/development/src/schema-json/JsonEntityTypes.cjs.map +1 -0
  70. package/dist/development/src/schema-json/JsonEntityTypes.js +206 -0
  71. package/dist/development/src/schema-json/JsonEntityTypes.js.map +1 -0
  72. package/dist/development/src/schema-json/JsonFilterTypes.cjs +152 -0
  73. package/dist/development/src/schema-json/JsonFilterTypes.cjs.map +1 -0
  74. package/dist/development/src/schema-json/JsonFilterTypes.js +152 -0
  75. package/dist/development/src/schema-json/JsonFilterTypes.js.map +1 -0
  76. package/dist/development/src/schema-json/JsonInputTypes.cjs +256 -0
  77. package/dist/development/src/schema-json/JsonInputTypes.cjs.map +1 -0
  78. package/dist/development/src/schema-json/JsonInputTypes.js +256 -0
  79. package/dist/development/src/schema-json/JsonInputTypes.js.map +1 -0
  80. package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
  81. package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
  82. package/dist/development/src/schema-json/JsonIntrospectionExtension.js +36 -0
  83. package/dist/development/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
  84. package/dist/development/src/schema-json/JsonQueryAstFactory.cjs +107 -0
  85. package/dist/development/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
  86. package/dist/development/src/schema-json/JsonQueryAstFactory.js +107 -0
  87. package/dist/development/src/schema-json/JsonQueryAstFactory.js.map +1 -0
  88. package/dist/development/src/schema-json/JsonTypeRegistry.cjs +230 -0
  89. package/dist/development/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
  90. package/dist/development/src/schema-json/JsonTypeRegistry.js +230 -0
  91. package/dist/development/src/schema-json/JsonTypeRegistry.js.map +1 -0
  92. package/dist/development/src/utils/ResolveInfoUtils.cjs.map +1 -1
  93. package/dist/development/src/utils/ResolveInfoUtils.js.map +1 -1
  94. package/dist/development/src/utils/uniqueWhereFields.cjs +10 -0
  95. package/dist/development/src/utils/uniqueWhereFields.cjs.map +1 -1
  96. package/dist/development/src/utils/uniqueWhereFields.js +10 -0
  97. package/dist/development/src/utils/uniqueWhereFields.js.map +1 -1
  98. package/dist/production/index.cjs +23 -0
  99. package/dist/production/index.cjs.map +1 -1
  100. package/dist/production/index.js +25 -2
  101. package/dist/production/index.js.map +1 -1
  102. package/dist/production/src/ExecutionContainer.cjs +4 -3
  103. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  104. package/dist/production/src/ExecutionContainer.js +4 -3
  105. package/dist/production/src/ExecutionContainer.js.map +1 -1
  106. package/dist/production/src/acl/Authorizator.cjs +6 -1
  107. package/dist/production/src/acl/Authorizator.cjs.map +1 -1
  108. package/dist/production/src/acl/Authorizator.js +6 -1
  109. package/dist/production/src/acl/Authorizator.js.map +1 -1
  110. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
  111. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
  112. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
  113. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
  114. package/dist/production/src/introspection/introspection.schema.cjs +2 -2
  115. package/dist/production/src/introspection/introspection.schema.cjs.map +1 -1
  116. package/dist/production/src/introspection/introspection.schema.js +2 -2
  117. package/dist/production/src/introspection/introspection.schema.js.map +1 -1
  118. package/dist/production/src/mapper/select/SelectHydrator.cjs +56 -15
  119. package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
  120. package/dist/production/src/mapper/select/SelectHydrator.js +56 -15
  121. package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
  122. package/dist/production/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  123. package/dist/production/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  124. package/dist/production/src/resolvers/MutationResolver.cjs +17 -39
  125. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  126. package/dist/production/src/resolvers/MutationResolver.js +18 -40
  127. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  128. package/dist/production/src/resolvers/ReadHelpers.cjs +4 -5
  129. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  130. package/dist/production/src/resolvers/ReadHelpers.js +4 -5
  131. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  132. package/dist/production/src/resolvers/ReadResolver.cjs +8 -17
  133. package/dist/production/src/resolvers/ReadResolver.cjs.map +1 -1
  134. package/dist/production/src/resolvers/ReadResolver.js +8 -17
  135. package/dist/production/src/resolvers/ReadResolver.js.map +1 -1
  136. package/dist/production/src/schema/GraphQlSchemaBuilder.cjs +16 -6
  137. package/dist/production/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  138. package/dist/production/src/schema/GraphQlSchemaBuilder.js +16 -6
  139. package/dist/production/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  140. package/dist/production/src/schema/MutationProvider.cjs +21 -8
  141. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  142. package/dist/production/src/schema/MutationProvider.js +21 -8
  143. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  144. package/dist/production/src/schema/QueryProvider.cjs +6 -6
  145. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  146. package/dist/production/src/schema/QueryProvider.js +6 -6
  147. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  148. package/dist/production/src/schema-json/GraphQLJsBridge.cjs +108 -0
  149. package/dist/production/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
  150. package/dist/production/src/schema-json/GraphQLJsBridge.js +108 -0
  151. package/dist/production/src/schema-json/GraphQLJsBridge.js.map +1 -0
  152. package/dist/production/src/schema-json/JsonColumnTypes.cjs +102 -0
  153. package/dist/production/src/schema-json/JsonColumnTypes.cjs.map +1 -0
  154. package/dist/production/src/schema-json/JsonColumnTypes.js +102 -0
  155. package/dist/production/src/schema-json/JsonColumnTypes.js.map +1 -0
  156. package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
  157. package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
  158. package/dist/production/src/schema-json/JsonContentSchemaBuilder.js +418 -0
  159. package/dist/production/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
  160. package/dist/production/src/schema-json/JsonContentSchemaShared.cjs +18 -0
  161. package/dist/production/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
  162. package/dist/production/src/schema-json/JsonContentSchemaShared.js +18 -0
  163. package/dist/production/src/schema-json/JsonContentSchemaShared.js.map +1 -0
  164. package/dist/production/src/schema-json/JsonEntityTypes.cjs +206 -0
  165. package/dist/production/src/schema-json/JsonEntityTypes.cjs.map +1 -0
  166. package/dist/production/src/schema-json/JsonEntityTypes.js +206 -0
  167. package/dist/production/src/schema-json/JsonEntityTypes.js.map +1 -0
  168. package/dist/production/src/schema-json/JsonFilterTypes.cjs +152 -0
  169. package/dist/production/src/schema-json/JsonFilterTypes.cjs.map +1 -0
  170. package/dist/production/src/schema-json/JsonFilterTypes.js +152 -0
  171. package/dist/production/src/schema-json/JsonFilterTypes.js.map +1 -0
  172. package/dist/production/src/schema-json/JsonInputTypes.cjs +256 -0
  173. package/dist/production/src/schema-json/JsonInputTypes.cjs.map +1 -0
  174. package/dist/production/src/schema-json/JsonInputTypes.js +256 -0
  175. package/dist/production/src/schema-json/JsonInputTypes.js.map +1 -0
  176. package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
  177. package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
  178. package/dist/production/src/schema-json/JsonIntrospectionExtension.js +36 -0
  179. package/dist/production/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
  180. package/dist/production/src/schema-json/JsonQueryAstFactory.cjs +107 -0
  181. package/dist/production/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
  182. package/dist/production/src/schema-json/JsonQueryAstFactory.js +107 -0
  183. package/dist/production/src/schema-json/JsonQueryAstFactory.js.map +1 -0
  184. package/dist/production/src/schema-json/JsonTypeRegistry.cjs +230 -0
  185. package/dist/production/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
  186. package/dist/production/src/schema-json/JsonTypeRegistry.js +230 -0
  187. package/dist/production/src/schema-json/JsonTypeRegistry.js.map +1 -0
  188. package/dist/production/src/utils/ResolveInfoUtils.cjs.map +1 -1
  189. package/dist/production/src/utils/ResolveInfoUtils.js.map +1 -1
  190. package/dist/production/src/utils/uniqueWhereFields.cjs +10 -0
  191. package/dist/production/src/utils/uniqueWhereFields.cjs.map +1 -1
  192. package/dist/production/src/utils/uniqueWhereFields.js +10 -0
  193. package/dist/production/src/utils/uniqueWhereFields.js.map +1 -1
  194. package/dist/tests/src/test.d.ts +10 -2
  195. package/dist/tests/src/test.d.ts.map +1 -1
  196. package/dist/tests/src/testGraphql.d.ts +18 -5
  197. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  198. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  199. package/dist/types/ExecutionContainer.d.ts +1 -0
  200. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  201. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  202. package/dist/types/index.d.ts +1 -0
  203. package/dist/types/index.d.ts.map +1 -1
  204. package/dist/types/mapper/select/SelectHydrator.d.ts +4 -1
  205. package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
  206. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts +4 -3
  207. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  208. package/dist/types/resolvers/MutationResolver.d.ts +14 -11
  209. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  210. package/dist/types/resolvers/ReadHelpers.d.ts +1 -2
  211. package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
  212. package/dist/types/resolvers/ReadResolver.d.ts +8 -10
  213. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  214. package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
  215. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  216. package/dist/types/schema-json/GraphQLJsBridge.d.ts +12 -0
  217. package/dist/types/schema-json/GraphQLJsBridge.d.ts.map +1 -0
  218. package/dist/types/schema-json/JsonColumnTypes.d.ts +23 -0
  219. package/dist/types/schema-json/JsonColumnTypes.d.ts.map +1 -0
  220. package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts +56 -0
  221. package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts.map +1 -0
  222. package/dist/types/schema-json/JsonContentSchemaShared.d.ts +19 -0
  223. package/dist/types/schema-json/JsonContentSchemaShared.d.ts.map +1 -0
  224. package/dist/types/schema-json/JsonEntityTypes.d.ts +29 -0
  225. package/dist/types/schema-json/JsonEntityTypes.d.ts.map +1 -0
  226. package/dist/types/schema-json/JsonFilterTypes.d.ts +21 -0
  227. package/dist/types/schema-json/JsonFilterTypes.d.ts.map +1 -0
  228. package/dist/types/schema-json/JsonInputTypes.d.ts +36 -0
  229. package/dist/types/schema-json/JsonInputTypes.d.ts.map +1 -0
  230. package/dist/types/schema-json/JsonIntrospectionExtension.d.ts +5 -0
  231. package/dist/types/schema-json/JsonIntrospectionExtension.d.ts.map +1 -0
  232. package/dist/types/schema-json/JsonQueryAstFactory.d.ts +18 -0
  233. package/dist/types/schema-json/JsonQueryAstFactory.d.ts.map +1 -0
  234. package/dist/types/schema-json/JsonTypeRegistry.d.ts +57 -0
  235. package/dist/types/schema-json/JsonTypeRegistry.d.ts.map +1 -0
  236. package/dist/types/schema-json/index.d.ts +7 -0
  237. package/dist/types/schema-json/index.d.ts.map +1 -0
  238. package/dist/types/tsconfig.tsbuildinfo +1 -1
  239. package/dist/types/utils/ResolveInfoUtils.d.ts +4 -2
  240. package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
  241. package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
  242. package/package.json +11 -10
  243. package/src/ExecutionContainer.ts +5 -3
  244. package/src/acl/Authorizator.ts +7 -1
  245. package/src/index.ts +1 -0
  246. package/src/mapper/select/SelectHydrator.ts +72 -17
  247. package/src/resolvers/GraphQlQueryAstFactory.ts +2 -2
  248. package/src/resolvers/MutationResolver.ts +22 -45
  249. package/src/resolvers/ReadHelpers.ts +1 -4
  250. package/src/resolvers/ReadResolver.ts +7 -18
  251. package/src/schema/GraphQlSchemaBuilder.ts +18 -7
  252. package/src/schema/MutationProvider.ts +21 -8
  253. package/src/schema/QueryProvider.ts +6 -6
  254. package/src/schema-json/GraphQLJsBridge.ts +142 -0
  255. package/src/schema-json/JsonColumnTypes.ts +116 -0
  256. package/src/schema-json/JsonContentSchemaBuilder.ts +501 -0
  257. package/src/schema-json/JsonContentSchemaShared.ts +19 -0
  258. package/src/schema-json/JsonEntityTypes.ts +237 -0
  259. package/src/schema-json/JsonFilterTypes.ts +159 -0
  260. package/src/schema-json/JsonInputTypes.ts +305 -0
  261. package/src/schema-json/JsonIntrospectionExtension.ts +37 -0
  262. package/src/schema-json/JsonQueryAstFactory.ts +128 -0
  263. package/src/schema-json/JsonTypeRegistry.ts +286 -0
  264. package/src/schema-json/index.ts +6 -0
  265. package/src/tsconfig.json +1 -0
  266. package/src/utils/ResolveInfoUtils.ts +2 -2
  267. package/src/utils/uniqueWhereFields.ts +14 -0
  268. package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +2 -3
  269. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +44 -1
  270. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +25 -29
  271. package/tests/src/test.ts +44 -10
  272. package/tests/src/testGraphql.ts +43 -20
  273. package/tests/tsconfig.json +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"introspection.schema.js","sources":["../../../../../packages/engine-content-api/src/introspection/introspection.schema.ts"],"sourcesContent":["import { JSONType } from '@contember/graphql-utils'\n\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLFieldResolver,\n\tGraphQLInt,\n\tGraphQLInterfaceType,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n\tGraphQLUnionType,\n} from 'graphql'\n\nconst _RuleMessage = new GraphQLObjectType({\n\tname: '_RuleMessage',\n\tfields: {\n\t\ttext: { type: GraphQLString },\n\t},\n})\n\nconst _ValidatorArgument = new GraphQLObjectType({\n\tname: '_ValidatorArgument',\n\tfields: {\n\t\tvalidator: { type: new GraphQLNonNull(GraphQLInt) },\n\t},\n})\n\nconst _PathArgument = new GraphQLObjectType({\n\tname: '_PathArgument',\n\tfields: {\n\t\tpath: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _LiteralArgument = new GraphQLObjectType({\n\tname: '_LiteralArgument',\n\tfields: {\n\t\tvalue: { type: JSONType },\n\t},\n})\n\nconst _Argument = new GraphQLUnionType({\n\tname: '_Argument',\n\ttypes: [_ValidatorArgument, _PathArgument, _LiteralArgument],\n})\n\nconst _Validator = new GraphQLObjectType({\n\tname: '_Validator',\n\tfields: {\n\t\toperation: { type: new GraphQLNonNull(GraphQLString) },\n\t\targuments: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Argument))) },\n\t},\n})\n\nconst _Rule = new GraphQLObjectType({\n\tname: '_Rule',\n\tfields: {\n\t\tmessage: { type: _RuleMessage },\n\t\tvalidator: { type: new GraphQLNonNull(GraphQLInt) },\n\t},\n})\n\nconst _FieldInterface = new GraphQLInterfaceType({\n\tname: '_Field',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tnullable: { type: GraphQLBoolean },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _OrderByDirection = new GraphQLEnumType({\n\tname: '_OrderByDirection',\n\tvalues: {\n\t\tasc: {},\n\t\tdesc: {},\n\t},\n})\n\nconst _OrderBy = new GraphQLObjectType({\n\tname: '_OrderBy',\n\tfields: {\n\t\tpath: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t\tdirection: { type: new GraphQLNonNull(_OrderByDirection) },\n\t},\n})\n\nconst _OnDeleteBehaviour = new GraphQLEnumType({\n\tname: '_OnDeleteBehaviour',\n\tvalues: {\n\t\trestrict: {},\n\t\tcascade: {},\n\t\tsetNull: {},\n\t},\n})\n\nconst _RelationSide = new GraphQLEnumType({\n\tname: '_RelationSide',\n\tvalues: {\n\t\towning: {},\n\t\tinverse: {},\n\t},\n})\n\nconst _Relation = new GraphQLObjectType({\n\tname: '_Relation',\n\tinterfaces: [_FieldInterface],\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tside: { type: new GraphQLNonNull(_RelationSide) },\n\t\ttargetEntity: { type: new GraphQLNonNull(GraphQLString) },\n\t\townedBy: { type: GraphQLString },\n\t\tinversedBy: { type: GraphQLString },\n\t\tnullable: { type: GraphQLBoolean },\n\t\tonDelete: { type: _OnDeleteBehaviour },\n\t\torphanRemoval: { type: GraphQLBoolean },\n\t\torderBy: { type: new GraphQLList(new GraphQLNonNull(_OrderBy)) },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _Column = new GraphQLObjectType({\n\tname: '_Column',\n\tinterfaces: [_FieldInterface],\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tenumName: { type: GraphQLString },\n\t\tdefaultValue: { type: JSONType },\n\t\tnullable: { type: new GraphQLNonNull(GraphQLBoolean) },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _UniqueConstraint = new GraphQLObjectType({\n\tname: '_UniqueConstraint',\n\tfields: {\n\t\tfields: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _Entity = new GraphQLObjectType({\n\tname: '_Entity',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\tcustomPrimaryAllowed: { type: new GraphQLNonNull(GraphQLBoolean) },\n\t\tfields: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_FieldInterface))) },\n\t\tunique: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_UniqueConstraint))) },\n\t},\n})\n\nconst _Enum = new GraphQLObjectType({\n\tname: '_Enum',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalues: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _Schema = new GraphQLObjectType({\n\tname: '_Schema',\n\tfields: {\n\t\tenums: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Enum))) },\n\t\tentities: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Entity))) },\n\t},\n})\n\nexport const createSchemaConfig = (resolver?: GraphQLFieldResolver<any, any>): GraphQLSchemaConfig => {\n\treturn {\n\t\tquery: new GraphQLObjectType({\n\t\t\tname: 'Query',\n\t\t\tfields: {\n\t\t\t\tschema: {\n\t\t\t\t\ttype: _Schema,\n\t\t\t\t\tresolve: resolver,\n\t\t\t\t},\n\t\t\t},\n\t\t}),\n\t\ttypes: [_Column, _Relation],\n\t}\n}\n\nexport default new GraphQLSchema(createSchemaConfig())\n"],"names":[],"mappings":";;AAiBA,MAAM,eAAe,IAAI,kBAAkB;AAAA,EAC1C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,MAAM,EAAE,MAAM,cAAA;AAAA,EAAc;AAE9B,CAAC;AAED,MAAM,qBAAqB,IAAI,kBAAkB;AAAA,EAChD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,WAAW,EAAE,MAAM,IAAI,eAAe,UAAU,EAAA;AAAA,EAAE;AAEpD,CAAC;AAED,MAAM,gBAAgB,IAAI,kBAAkB;AAAA,EAC3C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,MAAM,EAAE,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,aAAa,CAAC,CAAC,EAAA;AAAA,EAAE;AAEvF,CAAC;AAED,MAAM,mBAAmB,IAAI,kBAAkB;AAAA,EAC9C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,OAAO,EAAE,MAAM,SAAA;AAAA,EAAS;AAE1B,CAAC;AAED,MAAM,YAAY,IAAI,iBAAiB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO,CAAC,oBAAoB,eAAe,gBAAgB;AAC5D,CAAC;AAED,MAAM,aAAa,IAAI,kBAAkB;AAAA,EACxC,MAAM;AAAA,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,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,KAAK,CAAC,CAAC,EAAA;AAAA,IAC5E,UAAU,EAAE,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,OAAO,CAAC,CAAC,EAAA;AAAA,EAAE;AAErF,CAAC;AAEM,MAAM,qBAAqB,CAAC,aAAmE;AACrG,SAAO;AAAA,IACN,OAAO,IAAI,kBAAkB;AAAA,MAC5B,MAAM;AAAA,MACN,QAAQ;AAAA,QACP,QAAQ;AAAA,UACP,MAAM;AAAA,UACN,SAAS;AAAA,QAAA;AAAA,MACV;AAAA,IACD,CACA;AAAA,IACD,OAAO,CAAC,SAAS,SAAS;AAAA,EAAA;AAE5B;AAEA,MAAA,uBAAe,IAAI,cAAc,oBAAoB;"}
1
+ {"version":3,"file":"introspection.schema.js","sources":["../../../../../packages/engine-content-api/src/introspection/introspection.schema.ts"],"sourcesContent":["import { JSONType } from '@contember/graphql-utils'\n\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLFieldResolver,\n\tGraphQLInt,\n\tGraphQLInterfaceType,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n\tGraphQLUnionType,\n} from 'graphql'\n\nconst _RuleMessage = new GraphQLObjectType({\n\tname: '_RuleMessage',\n\tfields: {\n\t\ttext: { type: GraphQLString },\n\t},\n})\n\nconst _ValidatorArgument = new GraphQLObjectType({\n\tname: '_ValidatorArgument',\n\tfields: {\n\t\tvalidator: { type: new GraphQLNonNull(GraphQLInt) },\n\t},\n})\n\nconst _PathArgument = new GraphQLObjectType({\n\tname: '_PathArgument',\n\tfields: {\n\t\tpath: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _LiteralArgument = new GraphQLObjectType({\n\tname: '_LiteralArgument',\n\tfields: {\n\t\tvalue: { type: JSONType },\n\t},\n})\n\nconst _Argument = new GraphQLUnionType({\n\tname: '_Argument',\n\ttypes: [_ValidatorArgument, _PathArgument, _LiteralArgument],\n})\n\nconst _Validator = new GraphQLObjectType({\n\tname: '_Validator',\n\tfields: {\n\t\toperation: { type: new GraphQLNonNull(GraphQLString) },\n\t\targuments: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Argument))) },\n\t},\n})\n\nconst _Rule = new GraphQLObjectType({\n\tname: '_Rule',\n\tfields: {\n\t\tmessage: { type: _RuleMessage },\n\t\tvalidator: { type: new GraphQLNonNull(GraphQLInt) },\n\t},\n})\n\nconst _FieldInterface = new GraphQLInterfaceType({\n\tname: '_Field',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tnullable: { type: GraphQLBoolean },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _OrderByDirection = new GraphQLEnumType({\n\tname: '_OrderByDirection',\n\tvalues: {\n\t\tasc: {},\n\t\tdesc: {},\n\t},\n})\n\nconst _OrderBy = new GraphQLObjectType({\n\tname: '_OrderBy',\n\tfields: {\n\t\tpath: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t\tdirection: { type: new GraphQLNonNull(_OrderByDirection) },\n\t},\n})\n\nconst _OnDeleteBehaviour = new GraphQLEnumType({\n\tname: '_OnDeleteBehaviour',\n\tvalues: {\n\t\trestrict: {},\n\t\tcascade: {},\n\t\tsetNull: {},\n\t},\n})\n\nconst _RelationSide = new GraphQLEnumType({\n\tname: '_RelationSide',\n\tvalues: {\n\t\towning: {},\n\t\tinverse: {},\n\t},\n})\n\nconst _Relation = new GraphQLObjectType({\n\tname: '_Relation',\n\tinterfaces: [_FieldInterface],\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tside: { type: new GraphQLNonNull(_RelationSide) },\n\t\ttargetEntity: { type: new GraphQLNonNull(GraphQLString) },\n\t\townedBy: { type: GraphQLString },\n\t\tinversedBy: { type: GraphQLString },\n\t\tnullable: { type: GraphQLBoolean },\n\t\tonDelete: { type: _OnDeleteBehaviour },\n\t\torphanRemoval: { type: GraphQLBoolean },\n\t\torderBy: { type: new GraphQLList(new GraphQLNonNull(_OrderBy)) },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _Column = new GraphQLObjectType({\n\tname: '_Column',\n\tinterfaces: [_FieldInterface],\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\ttype: { type: new GraphQLNonNull(GraphQLString) },\n\t\tenumName: { type: GraphQLString },\n\t\tdefaultValue: { type: JSONType },\n\t\tnullable: { type: new GraphQLNonNull(GraphQLBoolean) },\n\t\trules: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Rule))) },\n\t\tvalidators: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Validator))) },\n\t},\n})\n\nconst _UniqueConstraint = new GraphQLObjectType({\n\tname: '_UniqueConstraint',\n\tfields: {\n\t\tfields: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _Entity = new GraphQLObjectType({\n\tname: '_Entity',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\tcustomPrimaryAllowed: { type: new GraphQLNonNull(GraphQLBoolean) },\n\t\tfields: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_FieldInterface))) },\n\t\tunique: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_UniqueConstraint))) },\n\t},\n})\n\nconst _Enum = new GraphQLObjectType({\n\tname: '_Enum',\n\tfields: {\n\t\tname: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalues: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) },\n\t},\n})\n\nconst _Schema = new GraphQLObjectType({\n\tname: '_Schema',\n\tfields: {\n\t\tenums: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Enum))) },\n\t\tentities: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(_Entity))) },\n\t},\n})\n\nexport const createSchemaConfig = (resolver?: GraphQLFieldResolver<any, any>): GraphQLSchemaConfig => {\n\treturn {\n\t\tquery: new GraphQLObjectType({\n\t\t\tname: 'Query',\n\t\t\tfields: {\n\t\t\t\tschema: {\n\t\t\t\t\ttype: _Schema,\n\t\t\t\t\tresolve: resolver,\n\t\t\t\t},\n\t\t\t},\n\t\t}),\n\t\ttypes: [_Column, _Relation],\n\t}\n}\n\nexport default new GraphQLSchema(createSchemaConfig())\n"],"names":[],"mappings":";;AAiBA,MAAM,eAAe,IAAI,kBAAkB;AAAA,EAC1C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,MAAM,EAAE,MAAM,cAAA;AAAA,EAAc;AAE9B,CAAC;AAED,MAAM,qBAAqB,IAAI,kBAAkB;AAAA,EAChD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,WAAW,EAAE,MAAM,IAAI,eAAe,UAAU,EAAA;AAAA,EAAE;AAEpD,CAAC;AAED,MAAM,gBAAgB,IAAI,kBAAkB;AAAA,EAC3C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,MAAM,EAAE,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,aAAa,CAAC,CAAC,EAAA;AAAA,EAAE;AAEvF,CAAC;AAED,MAAM,mBAAmB,IAAI,kBAAkB;AAAA,EAC9C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,OAAO,EAAE,MAAM,SAAA;AAAA,EAAS;AAE1B,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,eAAe,IAAI,YAAY,IAAI,eAAe,aAAa,CAAC,CAAC,EAAA;AAAA,EAAE;AAEzF,CAAC;AAED,MAAM,UAAU,IAAI,kBAAkB;AAAA,EACrC,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,OAAO,EAAE,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,KAAK,CAAC,CAAC,EAAA;AAAA,IAC5E,UAAU,EAAE,MAAM,IAAI,eAAe,IAAI,YAAY,IAAI,eAAe,OAAO,CAAC,CAAC,EAAA;AAAA,EAAE;AAErF,CAAC;AAEM,MAAM,qBAAqB,CAAC,aAAmE;AACrG,SAAO;AAAA,IACN,OAAO,IAAI,kBAAkB;AAAA,MAC5B,MAAM;AAAA,MACN,QAAQ;AAAA,QACP,QAAQ;AAAA,UACP,MAAM;AAAA,UACN,SAAS;AAAA,QAAA;AAAA,MACV;AAAA,IACD,CACA;AAAA,IACD,OAAO,CAAC,SAAS,SAAS;AAAA,EAAA;AAE5B;AAEA,MAAA,sBAAe,IAAI,cAAc,oBAAoB;"}
@@ -7,6 +7,13 @@ const Database = require("@contember/database");
7
7
  var __defProp = Object.defineProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
9
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ const setOwnValue = (object, key, value) => {
11
+ if (key === "__proto__") {
12
+ Object.defineProperty(object, key, { value, enumerable: true, configurable: true, writable: true });
13
+ } else {
14
+ object[key] = value;
15
+ }
16
+ };
10
17
  class SelectHydrator {
11
18
  constructor(memoryBudget) {
12
19
  this.memoryBudget = memoryBudget;
@@ -47,29 +54,63 @@ class SelectHydrator {
47
54
  const resolved = await this.resolveDataPromises();
48
55
  this.chargeRows(rows.length, resolved.length);
49
56
  this.formattedDates = 0;
50
- const hydrated = rows.map((row) => this.hydrateRow(row, resolved));
57
+ const layout = this.createRowLayout(resolved);
58
+ const hydrated = rows.map((row) => this.hydrateObject(row, layout));
51
59
  this.memoryBudget?.addHydrationBytes(this.formattedDates * 72);
52
60
  return hydrated;
53
61
  }
54
- hydrateRow(row, resolvedData) {
55
- const result = {};
56
- for (let columnPath of this.columns) {
57
- const path = [...columnPath.path.path];
58
- const last = path.pop();
59
- const currentObject = path.reduce((obj, part) => obj[part] = obj[part] || {}, result);
60
- currentObject[last] = this.formatValue(columnPath.getValue(row));
62
+ /** Every row has the same shape, so the paths are resolved once instead of per row and column. */
63
+ createRowLayout(resolvedData) {
64
+ const layout = /* @__PURE__ */ new Map();
65
+ for (const { path, getValue } of this.columns) {
66
+ const parts = path.path;
67
+ let current = layout;
68
+ for (const part of parts.slice(0, -1)) {
69
+ const existing = current.get(part);
70
+ if (existing?.type === "object") {
71
+ current = existing.layout;
72
+ } else {
73
+ const nested = /* @__PURE__ */ new Map();
74
+ current.set(part, { type: "object", layout: nested });
75
+ current = nested;
76
+ }
77
+ }
78
+ current.set(parts[parts.length - 1], { type: "column", getValue });
61
79
  }
62
- for (let { path, getParentValue, data, defaultValue } of resolvedData) {
63
- const pathTmp = [...path.path];
64
- const last = pathTmp.pop();
65
- const currentObject = pathTmp.reduce((obj, part) => obj?.[part] || void 0, result);
66
- const parentValue = getParentValue(row);
67
- if (currentObject) {
68
- currentObject[last] = (parentValue ? data[parentValue] : void 0) || defaultValue;
80
+ for (const relation of resolvedData) {
81
+ const parts = relation.path.path;
82
+ let current = layout;
83
+ for (const part of parts.slice(0, -1)) {
84
+ const existing = current.get(part);
85
+ current = existing?.type === "object" ? existing.layout : void 0;
86
+ if (!current) {
87
+ break;
88
+ }
69
89
  }
90
+ current?.set(parts[parts.length - 1], { type: "relation", relation });
91
+ }
92
+ return layout;
93
+ }
94
+ hydrateObject(row, layout) {
95
+ const result = {};
96
+ for (const [key, entry] of layout) {
97
+ setOwnValue(result, key, this.hydrateEntry(row, entry));
70
98
  }
71
99
  return result;
72
100
  }
101
+ hydrateEntry(row, entry) {
102
+ switch (entry.type) {
103
+ case "column":
104
+ return this.formatValue(entry.getValue(row));
105
+ case "object":
106
+ return this.hydrateObject(row, entry.layout);
107
+ case "relation": {
108
+ const { getParentValue, data, defaultValue } = entry.relation;
109
+ const parentValue = getParentValue(row);
110
+ return (parentValue && Object.hasOwn(data, parentValue) ? data[parentValue] : void 0) || defaultValue;
111
+ }
112
+ }
113
+ }
73
114
  async resolveDataPromises() {
74
115
  const results = await Promise.allSettled(this.promises.map(async (it) => ({
75
116
  defaultValue: it.defaultValue,
@@ -1 +1 @@
1
- {"version":3,"file":"SelectHydrator.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/SelectHydrator.ts"],"sourcesContent":["import { Path } from './Path.js'\nimport { Value } from '@contember/schema'\nimport { getFulfilledValues, getRejections } from '../../utils/index.js'\nimport { logger } from '@contember/logger'\nimport { RequestMemoryBudget, RequestMemoryBudgetExceededError } from '@contember/database'\n\ntype DataPromises = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: Promise<SelectNestedData>\n\tdefaultValue: SelectNestedDefaultValue\n}\n\ntype ResolvedData = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: SelectNestedData\n\tdefaultValue: SelectNestedDefaultValue\n}\n\nexport type ColumnValueGetter<T extends Value.FieldValue = Value.FieldValue> = (row: SelectRow) => T\n\ntype Column = {\n\tpath: Path\n\tgetValue: ColumnValueGetter\n}\n\nexport class SelectHydrator {\n\tprivate columns: Column[] = []\n\tprivate promises: DataPromises[] = []\n\tprivate formattedDates = 0\n\n\tconstructor(private readonly memoryBudget?: RequestMemoryBudget) {}\n\n\tpublic addColumn(path: Path, getValue: ColumnValueGetter) {\n\t\tthis.columns.push({ path, getValue })\n\t}\n\n\tpublic addPromise(\n\t\tpath: Path,\n\t\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>,\n\t\tdata: Promise<SelectNestedData>,\n\t\tdefaultValue: SelectNestedDefaultValue,\n\t) {\n\t\tthis.promises.push({ path, getParentValue, data, defaultValue })\n\t}\n\n\tpublic async hydrateGroups(rows: SelectRow[], groupBy: string): Promise<SelectGroupedObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tconst result: SelectGroupedObjects = {}\n\t\trows.forEach((row, index) => {\n\t\t\tconst key = row[groupBy] as Value.PrimaryValue\n\t\t\tif (!result[key]) {\n\t\t\t\tresult[key] = []\n\t\t\t}\n\t\t\tresult[key].push(hydrated[index])\n\t\t})\n\t\treturn result\n\t}\n\n\tpublic async hydrateAll(rows: SelectRow[]): Promise<SelectResultObject[]>\n\tpublic async hydrateAll(rows: SelectRow[], indexBy: string): Promise<SelectIndexedResultObjects>\n\n\tpublic async hydrateAll(\n\t\trows: SelectRow[],\n\t\tindexBy?: string,\n\t): Promise<SelectResultObject[] | SelectIndexedResultObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tif (indexBy) {\n\t\t\tconst result: SelectIndexedResultObjects = {}\n\t\t\trows.forEach((row, index) => {\n\t\t\t\tresult[row[indexBy] as Value.PrimaryValue] = hydrated[index]\n\t\t\t})\n\t\t\treturn result\n\t\t}\n\t\treturn hydrated\n\t}\n\n\tprivate async hydrateRows(rows: SelectRow[]): Promise<SelectResultObject[]> {\n\t\tconst resolved = await this.resolveDataPromises()\n\t\tthis.chargeRows(rows.length, resolved.length)\n\t\tthis.formattedDates = 0\n\t\tconst hydrated = rows.map(row => this.hydrateRow(row, resolved))\n\t\t// A formatted Date is a new string; their count is known only after the rows are built.\n\t\tthis.memoryBudget?.addHydrationBytes(this.formattedDates * 72)\n\t\treturn hydrated\n\t}\n\n\tprivate hydrateRow(row: SelectRow, resolvedData: ResolvedData[]): SelectResultObject {\n\t\tconst result: SelectResultObject = {}\n\n\t\tfor (let columnPath of this.columns) {\n\t\t\tconst path = [...columnPath.path.path]\n\t\t\tconst last: string = path.pop() as string\n\t\t\tconst currentObject = path.reduce<any>((obj, part) => (obj[part] = obj[part] || {}), result)\n\n\t\t\tcurrentObject[last] = this.formatValue(columnPath.getValue(row))\n\t\t}\n\n\t\tfor (let { path, getParentValue, data, defaultValue } of resolvedData) {\n\t\t\tconst pathTmp = [...path.path]\n\t\t\tconst last = pathTmp.pop() as string\n\t\t\tconst currentObject = pathTmp.reduce<any>((obj, part) => (obj?.[part]) || undefined, result)\n\t\t\tconst parentValue = getParentValue(row)\n\t\t\tif (currentObject) {\n\t\t\t\tcurrentObject[last] = (parentValue ? data[parentValue] : undefined) || defaultValue\n\t\t\t}\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate async resolveDataPromises(): Promise<ResolvedData[]> {\n\t\tconst results = await Promise.allSettled(this.promises.map(async (it): Promise<ResolvedData> => ({\n\t\t\tdefaultValue: it.defaultValue,\n\t\t\tgetParentValue: it.getParentValue,\n\t\t\tpath: it.path,\n\t\t\tdata: await it.data,\n\t\t})))\n\t\tconst failures = getRejections(results)\n\t\tif (failures.length > 0) {\n\t\t\t// Budget exhaustion aborts every in-flight sibling query; those rejections are expected.\n\t\t\tfailures.slice(1)\n\t\t\t\t.filter(e => !(e instanceof RequestMemoryBudgetExceededError))\n\t\t\t\t.forEach(e => logger.error(e, { loc: 'SelectHydrator' }))\n\t\t\tthrow failures[0]\n\t\t}\n\n\t\treturn getFulfilledValues(results)\n\t}\n\n\tprivate formatValue(value: any) {\n\t\tif (value instanceof Date) {\n\t\t\tthis.formattedDates++\n\t\t\treturn value.toISOString()\n\t\t}\n\t\treturn value\n\t}\n\n\t// The row shape is fixed by the columns, so all rows are charged at once, before any of them is allocated.\n\tprivate chargeRows(rowCount: number, relationCount: number): void {\n\t\tif (!this.memoryBudget || rowCount === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst nestedObjects = new Set<string>()\n\t\tfor (const { path } of this.columns) {\n\t\t\tfor (let depth = 1; depth < path.path.length; depth++) {\n\t\t\t\tnestedObjects.add(path.path.slice(0, depth).join('.'))\n\t\t\t}\n\t\t}\n\t\tconst rowBytes = 40 + this.columns.length * 16 + nestedObjects.size * 48 + relationCount * 16\n\t\tthis.memoryBudget.addHydrationBytes(rowCount * rowBytes)\n\t}\n}\n\nexport type SelectRow = { [key: string]: Value.FieldValue }\nexport type SelectResultObject = Value.Object\nexport type SelectIndexedResultObjects = { [key: string]: SelectResultObject }\nexport type SelectGroupedObjects = { [groupingKey: string]: SelectResultObject[] }\nexport type SelectNestedData = SelectGroupedObjects | SelectIndexedResultObjects\nexport type SelectNestedDefaultValue = [] | null\n"],"names":["getRejections","RequestMemoryBudgetExceededError","logger","getFulfilledValues"],"mappings":";;;;;;;;;AA2BO,MAAM,eAAe;AAAA,EAK3B,YAA6B,cAAoC;AAApC,SAAA,eAAA;AAJ7B,kBAAA,MAAQ,WAAoB,EAAC;AAC7B,kBAAA,MAAQ,YAA2B,EAAC;AACpC,kBAAA,MAAQ,kBAAiB,CAAA;AAAA,EAEyC;AAAA,EAE3D,UAAU,MAAY,UAA6B;AACzD,SAAK,QAAQ,KAAK,EAAE,MAAM,UAAU;AAAA,EACrC;AAAA,EAEO,WACN,MACA,gBACA,MACA,cACC;AACD,SAAK,SAAS,KAAK,EAAE,MAAM,gBAAgB,MAAM,cAAc;AAAA,EAChE;AAAA,EAEA,MAAa,cAAc,MAAmB,SAAgD;AAC7F,UAAM,WAAW,MAAM,KAAK,YAAY,IAAI;AAC5C,UAAM,SAA+B,CAAA;AACrC,SAAK,QAAQ,CAAC,KAAK,UAAU;AAC5B,YAAM,MAAM,IAAI,OAAO;AACvB,UAAI,CAAC,OAAO,GAAG,GAAG;AACjB,eAAO,GAAG,IAAI,CAAA;AAAA,MACf;AACA,aAAO,GAAG,EAAE,KAAK,SAAS,KAAK,CAAC;AAAA,IACjC,CAAC;AACD,WAAO;AAAA,EACR;AAAA,EAKA,MAAa,WACZ,MACA,SAC6D;AAC7D,UAAM,WAAW,MAAM,KAAK,YAAY,IAAI;AAC5C,QAAI,SAAS;AACZ,YAAM,SAAqC,CAAA;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AO,QAA+B;AAAA,MAChG,cAAc,GAAG;AAAA,MACjB,gBAAgB,GAAG;AAAA,MACnB,MAAM,GAAG;AAAA,MACT,MAAM,MAAM,GAAG;AAAA,IAAA,EACd,CAAC;AACH,UAAM,WAAWA,SAAAA,cAAc,OAAO;AACtC,QAAI,SAAS,SAAS,GAAG;AAExB,eAAS,MAAM,CAAC,EACd,OAAO,CAAA,MAAK,EAAE,aAAaC,0CAAiC,EAC5D,QAAQ,CAAA,MAAKC,OAAAA,OAAO,MAAM,GAAG,EAAE,KAAK,iBAAA,CAAkB,CAAC;AACzD,YAAM,SAAS,CAAC;AAAA,IACjB;AAEA,WAAOC,SAAAA,mBAAmB,OAAO;AAAA,EAClC;AAAA,EAEQ,YAAY,OAAY;AAC/B,QAAI,iBAAiB,MAAM;AAC1B,WAAK;AACL,aAAO,MAAM,YAAA;AAAA,IACd;AACA,WAAO;AAAA,EACR;AAAA;AAAA,EAGQ,WAAW,UAAkB,eAA6B;AACjE,QAAI,CAAC,KAAK,gBAAgB,aAAa,GAAG;AACzC;AAAA,IACD;AACA,UAAM,oCAAoB,IAAA;AAC1B,eAAW,EAAE,UAAU,KAAK,SAAS;AACpC,eAAS,QAAQ,GAAG,QAAQ,KAAK,KAAK,QAAQ,SAAS;AACtD,sBAAc,IAAI,KAAK,KAAK,MAAM,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,MACtD;AAAA,IACD;AACA,UAAM,WAAW,KAAK,KAAK,QAAQ,SAAS,KAAK,cAAc,OAAO,KAAK,gBAAgB;AAC3F,SAAK,aAAa,kBAAkB,WAAW,QAAQ;AAAA,EACxD;AACD;;"}
1
+ {"version":3,"file":"SelectHydrator.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/SelectHydrator.ts"],"sourcesContent":["import { Path } from './Path.js'\nimport { Value } from '@contember/schema'\nimport { getFulfilledValues, getRejections } from '../../utils/index.js'\nimport { logger } from '@contember/logger'\nimport { RequestMemoryBudget, RequestMemoryBudgetExceededError } from '@contember/database'\n\ntype DataPromises = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: Promise<SelectNestedData>\n\tdefaultValue: SelectNestedDefaultValue\n}\n\ntype ResolvedData = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: SelectNestedData\n\tdefaultValue: SelectNestedDefaultValue\n}\n\nexport type ColumnValueGetter<T extends Value.FieldValue = Value.FieldValue> = (row: SelectRow) => T\n\ntype Column = {\n\tpath: Path\n\tgetValue: ColumnValueGetter\n}\n\n/** Keys are field aliases, i.e. chosen by the client. */\ntype RowLayout = Map<string, RowLayoutEntry>\n\ntype RowLayoutEntry =\n\t| { readonly type: 'column'; readonly getValue: ColumnValueGetter }\n\t| { readonly type: 'object'; readonly layout: RowLayout }\n\t| { readonly type: 'relation'; readonly relation: ResolvedData }\n\ntype HydratedObject = { [key: string]: Value.FieldValue }\n\n/** An alias may be `__proto__`, which a plain assignment would turn into a prototype change. */\nconst setOwnValue = (object: HydratedObject, key: string, value: Value.FieldValue): void => {\n\tif (key === '__proto__') {\n\t\tObject.defineProperty(object, key, { value, enumerable: true, configurable: true, writable: true })\n\t} else {\n\t\tobject[key] = value\n\t}\n}\n\nexport class SelectHydrator {\n\tprivate columns: Column[] = []\n\tprivate promises: DataPromises[] = []\n\tprivate formattedDates = 0\n\n\tconstructor(private readonly memoryBudget?: RequestMemoryBudget) {}\n\n\tpublic addColumn(path: Path, getValue: ColumnValueGetter) {\n\t\tthis.columns.push({ path, getValue })\n\t}\n\n\tpublic addPromise(\n\t\tpath: Path,\n\t\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>,\n\t\tdata: Promise<SelectNestedData>,\n\t\tdefaultValue: SelectNestedDefaultValue,\n\t) {\n\t\tthis.promises.push({ path, getParentValue, data, defaultValue })\n\t}\n\n\tpublic async hydrateGroups(rows: SelectRow[], groupBy: string): Promise<SelectGroupedObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tconst result: SelectGroupedObjects = {}\n\t\trows.forEach((row, index) => {\n\t\t\tconst key = row[groupBy] as Value.PrimaryValue\n\t\t\tif (!result[key]) {\n\t\t\t\tresult[key] = []\n\t\t\t}\n\t\t\tresult[key].push(hydrated[index])\n\t\t})\n\t\treturn result\n\t}\n\n\tpublic async hydrateAll(rows: SelectRow[]): Promise<SelectResultObject[]>\n\tpublic async hydrateAll(rows: SelectRow[], indexBy: string): Promise<SelectIndexedResultObjects>\n\n\tpublic async hydrateAll(\n\t\trows: SelectRow[],\n\t\tindexBy?: string,\n\t): Promise<SelectResultObject[] | SelectIndexedResultObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tif (indexBy) {\n\t\t\tconst result: SelectIndexedResultObjects = {}\n\t\t\trows.forEach((row, index) => {\n\t\t\t\tresult[row[indexBy] as Value.PrimaryValue] = hydrated[index]\n\t\t\t})\n\t\t\treturn result\n\t\t}\n\t\treturn hydrated\n\t}\n\n\tprivate async hydrateRows(rows: SelectRow[]): Promise<SelectResultObject[]> {\n\t\tconst resolved = await this.resolveDataPromises()\n\t\tthis.chargeRows(rows.length, resolved.length)\n\t\tthis.formattedDates = 0\n\t\tconst layout = this.createRowLayout(resolved)\n\t\tconst hydrated = rows.map(row => this.hydrateObject(row, layout))\n\t\t// A formatted Date is a new string; their count is known only after the rows are built.\n\t\tthis.memoryBudget?.addHydrationBytes(this.formattedDates * 72)\n\t\treturn hydrated\n\t}\n\n\t/** Every row has the same shape, so the paths are resolved once instead of per row and column. */\n\tprivate createRowLayout(resolvedData: ResolvedData[]): RowLayout {\n\t\tconst layout: RowLayout = new Map()\n\n\t\tfor (const { path, getValue } of this.columns) {\n\t\t\tconst parts = path.path\n\t\t\tlet current = layout\n\t\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\t\tconst existing = current.get(part)\n\t\t\t\tif (existing?.type === 'object') {\n\t\t\t\t\tcurrent = existing.layout\n\t\t\t\t} else {\n\t\t\t\t\tconst nested: RowLayout = new Map()\n\t\t\t\t\tcurrent.set(part, { type: 'object', layout: nested })\n\t\t\t\t\tcurrent = nested\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent.set(parts[parts.length - 1], { type: 'column', getValue })\n\t\t}\n\n\t\t// a relation lands only in an object the columns created\n\t\tfor (const relation of resolvedData) {\n\t\t\tconst parts = relation.path.path\n\t\t\tlet current: RowLayout | undefined = layout\n\t\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\t\tconst existing: RowLayoutEntry | undefined = current.get(part)\n\t\t\t\tcurrent = existing?.type === 'object' ? existing.layout : undefined\n\t\t\t\tif (!current) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent?.set(parts[parts.length - 1], { type: 'relation', relation })\n\t\t}\n\n\t\treturn layout\n\t}\n\n\tprivate hydrateObject(row: SelectRow, layout: RowLayout): SelectResultObject {\n\t\tconst result: HydratedObject = {}\n\t\tfor (const [key, entry] of layout) {\n\t\t\tsetOwnValue(result, key, this.hydrateEntry(row, entry))\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate hydrateEntry(row: SelectRow, entry: RowLayoutEntry): Value.FieldValue {\n\t\tswitch (entry.type) {\n\t\t\tcase 'column':\n\t\t\t\treturn this.formatValue(entry.getValue(row))\n\t\t\tcase 'object':\n\t\t\t\treturn this.hydrateObject(row, entry.layout)\n\t\t\tcase 'relation': {\n\t\t\t\tconst { getParentValue, data, defaultValue } = entry.relation\n\t\t\t\tconst parentValue = getParentValue(row)\n\t\t\t\treturn (parentValue && Object.hasOwn(data, parentValue) ? data[parentValue] : undefined) || defaultValue\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async resolveDataPromises(): Promise<ResolvedData[]> {\n\t\tconst results = await Promise.allSettled(this.promises.map(async (it): Promise<ResolvedData> => ({\n\t\t\tdefaultValue: it.defaultValue,\n\t\t\tgetParentValue: it.getParentValue,\n\t\t\tpath: it.path,\n\t\t\tdata: await it.data,\n\t\t})))\n\t\tconst failures = getRejections(results)\n\t\tif (failures.length > 0) {\n\t\t\t// Budget exhaustion aborts every in-flight sibling query; those rejections are expected.\n\t\t\tfailures.slice(1)\n\t\t\t\t.filter(e => !(e instanceof RequestMemoryBudgetExceededError))\n\t\t\t\t.forEach(e => logger.error(e, { loc: 'SelectHydrator' }))\n\t\t\tthrow failures[0]\n\t\t}\n\n\t\treturn getFulfilledValues(results)\n\t}\n\n\tprivate formatValue(value: any) {\n\t\tif (value instanceof Date) {\n\t\t\tthis.formattedDates++\n\t\t\treturn value.toISOString()\n\t\t}\n\t\treturn value\n\t}\n\n\t// The row shape is fixed by the columns, so all rows are charged at once, before any of them is allocated.\n\tprivate chargeRows(rowCount: number, relationCount: number): void {\n\t\tif (!this.memoryBudget || rowCount === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst nestedObjects = new Set<string>()\n\t\tfor (const { path } of this.columns) {\n\t\t\tfor (let depth = 1; depth < path.path.length; depth++) {\n\t\t\t\tnestedObjects.add(path.path.slice(0, depth).join('.'))\n\t\t\t}\n\t\t}\n\t\tconst rowBytes = 40 + this.columns.length * 16 + nestedObjects.size * 48 + relationCount * 16\n\t\tthis.memoryBudget.addHydrationBytes(rowCount * rowBytes)\n\t}\n}\n\nexport type SelectRow = { [key: string]: Value.FieldValue }\nexport type SelectResultObject = Value.Object\nexport type SelectIndexedResultObjects = { [key: string]: SelectResultObject }\nexport type SelectGroupedObjects = { [groupingKey: string]: SelectResultObject[] }\nexport type SelectNestedData = SelectGroupedObjects | SelectIndexedResultObjects\nexport type SelectNestedDefaultValue = [] | null\n"],"names":["getRejections","RequestMemoryBudgetExceededError","logger","getFulfilledValues"],"mappings":";;;;;;;;;AAsCA,MAAM,cAAc,CAAC,QAAwB,KAAa,UAAkC;AAC3F,MAAI,QAAQ,aAAa;AACxB,WAAO,eAAe,QAAQ,KAAK,EAAE,OAAO,YAAY,MAAM,cAAc,MAAM,UAAU,KAAA,CAAM;AAAA,EACnG,OAAO;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,SAAS;AACtD,sBAAc,IAAI,KAAK,KAAK,MAAM,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,MACtD;AAAA,IACD;AACA,UAAM,WAAW,KAAK,KAAK,QAAQ,SAAS,KAAK,cAAc,OAAO,KAAK,gBAAgB;AAC3F,SAAK,aAAa,kBAAkB,WAAW,QAAQ;AAAA,EACxD;AACD;;"}
@@ -5,6 +5,13 @@ import { RequestMemoryBudgetExceededError } from "@contember/database";
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ const setOwnValue = (object, key, value) => {
9
+ if (key === "__proto__") {
10
+ Object.defineProperty(object, key, { value, enumerable: true, configurable: true, writable: true });
11
+ } else {
12
+ object[key] = value;
13
+ }
14
+ };
8
15
  class SelectHydrator {
9
16
  constructor(memoryBudget) {
10
17
  this.memoryBudget = memoryBudget;
@@ -45,29 +52,63 @@ class SelectHydrator {
45
52
  const resolved = await this.resolveDataPromises();
46
53
  this.chargeRows(rows.length, resolved.length);
47
54
  this.formattedDates = 0;
48
- const hydrated = rows.map((row) => this.hydrateRow(row, resolved));
55
+ const layout = this.createRowLayout(resolved);
56
+ const hydrated = rows.map((row) => this.hydrateObject(row, layout));
49
57
  this.memoryBudget?.addHydrationBytes(this.formattedDates * 72);
50
58
  return hydrated;
51
59
  }
52
- hydrateRow(row, resolvedData) {
53
- const result = {};
54
- for (let columnPath of this.columns) {
55
- const path = [...columnPath.path.path];
56
- const last = path.pop();
57
- const currentObject = path.reduce((obj, part) => obj[part] = obj[part] || {}, result);
58
- currentObject[last] = this.formatValue(columnPath.getValue(row));
60
+ /** Every row has the same shape, so the paths are resolved once instead of per row and column. */
61
+ createRowLayout(resolvedData) {
62
+ const layout = /* @__PURE__ */ new Map();
63
+ for (const { path, getValue } of this.columns) {
64
+ const parts = path.path;
65
+ let current = layout;
66
+ for (const part of parts.slice(0, -1)) {
67
+ const existing = current.get(part);
68
+ if (existing?.type === "object") {
69
+ current = existing.layout;
70
+ } else {
71
+ const nested = /* @__PURE__ */ new Map();
72
+ current.set(part, { type: "object", layout: nested });
73
+ current = nested;
74
+ }
75
+ }
76
+ current.set(parts[parts.length - 1], { type: "column", getValue });
59
77
  }
60
- for (let { path, getParentValue, data, defaultValue } of resolvedData) {
61
- const pathTmp = [...path.path];
62
- const last = pathTmp.pop();
63
- const currentObject = pathTmp.reduce((obj, part) => obj?.[part] || void 0, result);
64
- const parentValue = getParentValue(row);
65
- if (currentObject) {
66
- currentObject[last] = (parentValue ? data[parentValue] : void 0) || defaultValue;
78
+ for (const relation of resolvedData) {
79
+ const parts = relation.path.path;
80
+ let current = layout;
81
+ for (const part of parts.slice(0, -1)) {
82
+ const existing = current.get(part);
83
+ current = existing?.type === "object" ? existing.layout : void 0;
84
+ if (!current) {
85
+ break;
86
+ }
67
87
  }
88
+ current?.set(parts[parts.length - 1], { type: "relation", relation });
89
+ }
90
+ return layout;
91
+ }
92
+ hydrateObject(row, layout) {
93
+ const result = {};
94
+ for (const [key, entry] of layout) {
95
+ setOwnValue(result, key, this.hydrateEntry(row, entry));
68
96
  }
69
97
  return result;
70
98
  }
99
+ hydrateEntry(row, entry) {
100
+ switch (entry.type) {
101
+ case "column":
102
+ return this.formatValue(entry.getValue(row));
103
+ case "object":
104
+ return this.hydrateObject(row, entry.layout);
105
+ case "relation": {
106
+ const { getParentValue, data, defaultValue } = entry.relation;
107
+ const parentValue = getParentValue(row);
108
+ return (parentValue && Object.hasOwn(data, parentValue) ? data[parentValue] : void 0) || defaultValue;
109
+ }
110
+ }
111
+ }
71
112
  async resolveDataPromises() {
72
113
  const results = await Promise.allSettled(this.promises.map(async (it) => ({
73
114
  defaultValue: it.defaultValue,
@@ -1 +1 @@
1
- {"version":3,"file":"SelectHydrator.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/SelectHydrator.ts"],"sourcesContent":["import { Path } from './Path.js'\nimport { Value } from '@contember/schema'\nimport { getFulfilledValues, getRejections } from '../../utils/index.js'\nimport { logger } from '@contember/logger'\nimport { RequestMemoryBudget, RequestMemoryBudgetExceededError } from '@contember/database'\n\ntype DataPromises = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: Promise<SelectNestedData>\n\tdefaultValue: SelectNestedDefaultValue\n}\n\ntype ResolvedData = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: SelectNestedData\n\tdefaultValue: SelectNestedDefaultValue\n}\n\nexport type ColumnValueGetter<T extends Value.FieldValue = Value.FieldValue> = (row: SelectRow) => T\n\ntype Column = {\n\tpath: Path\n\tgetValue: ColumnValueGetter\n}\n\nexport class SelectHydrator {\n\tprivate columns: Column[] = []\n\tprivate promises: DataPromises[] = []\n\tprivate formattedDates = 0\n\n\tconstructor(private readonly memoryBudget?: RequestMemoryBudget) {}\n\n\tpublic addColumn(path: Path, getValue: ColumnValueGetter) {\n\t\tthis.columns.push({ path, getValue })\n\t}\n\n\tpublic addPromise(\n\t\tpath: Path,\n\t\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>,\n\t\tdata: Promise<SelectNestedData>,\n\t\tdefaultValue: SelectNestedDefaultValue,\n\t) {\n\t\tthis.promises.push({ path, getParentValue, data, defaultValue })\n\t}\n\n\tpublic async hydrateGroups(rows: SelectRow[], groupBy: string): Promise<SelectGroupedObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tconst result: SelectGroupedObjects = {}\n\t\trows.forEach((row, index) => {\n\t\t\tconst key = row[groupBy] as Value.PrimaryValue\n\t\t\tif (!result[key]) {\n\t\t\t\tresult[key] = []\n\t\t\t}\n\t\t\tresult[key].push(hydrated[index])\n\t\t})\n\t\treturn result\n\t}\n\n\tpublic async hydrateAll(rows: SelectRow[]): Promise<SelectResultObject[]>\n\tpublic async hydrateAll(rows: SelectRow[], indexBy: string): Promise<SelectIndexedResultObjects>\n\n\tpublic async hydrateAll(\n\t\trows: SelectRow[],\n\t\tindexBy?: string,\n\t): Promise<SelectResultObject[] | SelectIndexedResultObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tif (indexBy) {\n\t\t\tconst result: SelectIndexedResultObjects = {}\n\t\t\trows.forEach((row, index) => {\n\t\t\t\tresult[row[indexBy] as Value.PrimaryValue] = hydrated[index]\n\t\t\t})\n\t\t\treturn result\n\t\t}\n\t\treturn hydrated\n\t}\n\n\tprivate async hydrateRows(rows: SelectRow[]): Promise<SelectResultObject[]> {\n\t\tconst resolved = await this.resolveDataPromises()\n\t\tthis.chargeRows(rows.length, resolved.length)\n\t\tthis.formattedDates = 0\n\t\tconst hydrated = rows.map(row => this.hydrateRow(row, resolved))\n\t\t// A formatted Date is a new string; their count is known only after the rows are built.\n\t\tthis.memoryBudget?.addHydrationBytes(this.formattedDates * 72)\n\t\treturn hydrated\n\t}\n\n\tprivate hydrateRow(row: SelectRow, resolvedData: ResolvedData[]): SelectResultObject {\n\t\tconst result: SelectResultObject = {}\n\n\t\tfor (let columnPath of this.columns) {\n\t\t\tconst path = [...columnPath.path.path]\n\t\t\tconst last: string = path.pop() as string\n\t\t\tconst currentObject = path.reduce<any>((obj, part) => (obj[part] = obj[part] || {}), result)\n\n\t\t\tcurrentObject[last] = this.formatValue(columnPath.getValue(row))\n\t\t}\n\n\t\tfor (let { path, getParentValue, data, defaultValue } of resolvedData) {\n\t\t\tconst pathTmp = [...path.path]\n\t\t\tconst last = pathTmp.pop() as string\n\t\t\tconst currentObject = pathTmp.reduce<any>((obj, part) => (obj?.[part]) || undefined, result)\n\t\t\tconst parentValue = getParentValue(row)\n\t\t\tif (currentObject) {\n\t\t\t\tcurrentObject[last] = (parentValue ? data[parentValue] : undefined) || defaultValue\n\t\t\t}\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate async resolveDataPromises(): Promise<ResolvedData[]> {\n\t\tconst results = await Promise.allSettled(this.promises.map(async (it): Promise<ResolvedData> => ({\n\t\t\tdefaultValue: it.defaultValue,\n\t\t\tgetParentValue: it.getParentValue,\n\t\t\tpath: it.path,\n\t\t\tdata: await it.data,\n\t\t})))\n\t\tconst failures = getRejections(results)\n\t\tif (failures.length > 0) {\n\t\t\t// Budget exhaustion aborts every in-flight sibling query; those rejections are expected.\n\t\t\tfailures.slice(1)\n\t\t\t\t.filter(e => !(e instanceof RequestMemoryBudgetExceededError))\n\t\t\t\t.forEach(e => logger.error(e, { loc: 'SelectHydrator' }))\n\t\t\tthrow failures[0]\n\t\t}\n\n\t\treturn getFulfilledValues(results)\n\t}\n\n\tprivate formatValue(value: any) {\n\t\tif (value instanceof Date) {\n\t\t\tthis.formattedDates++\n\t\t\treturn value.toISOString()\n\t\t}\n\t\treturn value\n\t}\n\n\t// The row shape is fixed by the columns, so all rows are charged at once, before any of them is allocated.\n\tprivate chargeRows(rowCount: number, relationCount: number): void {\n\t\tif (!this.memoryBudget || rowCount === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst nestedObjects = new Set<string>()\n\t\tfor (const { path } of this.columns) {\n\t\t\tfor (let depth = 1; depth < path.path.length; depth++) {\n\t\t\t\tnestedObjects.add(path.path.slice(0, depth).join('.'))\n\t\t\t}\n\t\t}\n\t\tconst rowBytes = 40 + this.columns.length * 16 + nestedObjects.size * 48 + relationCount * 16\n\t\tthis.memoryBudget.addHydrationBytes(rowCount * rowBytes)\n\t}\n}\n\nexport type SelectRow = { [key: string]: Value.FieldValue }\nexport type SelectResultObject = Value.Object\nexport type SelectIndexedResultObjects = { [key: string]: SelectResultObject }\nexport type SelectGroupedObjects = { [groupingKey: string]: SelectResultObject[] }\nexport type SelectNestedData = SelectGroupedObjects | SelectIndexedResultObjects\nexport type SelectNestedDefaultValue = [] | null\n"],"names":[],"mappings":";;;;;;;AA2BO,MAAM,eAAe;AAAA,EAK3B,YAA6B,cAAoC;AAAp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AC/B,QAAI,iBAAiB,MAAM;AAC1B,WAAK;AACL,aAAO,MAAM,YAAA;AAAA,IACd;AACA,WAAO;AAAA,EACR;AAAA;AAAA,EAGQ,WAAW,UAAkB,eAA6B;AACjE,QAAI,CAAC,KAAK,gBAAgB,aAAa,GAAG;AACzC;AAAA,IACD;AACA,UAAM,oCAAoB,IAAA;AAC1B,eAAW,EAAE,UAAU,KAAK,SAAS;AACpC,eAAS,QAAQ,GAAG,QAAQ,KAAK,KAAK,QAAQ,SAAS;AACtD,sBAAc,IAAI,KAAK,KAAK,MAAM,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,MACtD;AAAA,IACD;AACA,UAAM,WAAW,KAAK,KAAK,QAAQ,SAAS,KAAK,cAAc,OAAO,KAAK,gBAAgB;AAC3F,SAAK,aAAa,kBAAkB,WAAW,QAAQ;AAAA,EACxD;AACD;"}
1
+ {"version":3,"file":"SelectHydrator.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/SelectHydrator.ts"],"sourcesContent":["import { Path } from './Path.js'\nimport { Value } from '@contember/schema'\nimport { getFulfilledValues, getRejections } from '../../utils/index.js'\nimport { logger } from '@contember/logger'\nimport { RequestMemoryBudget, RequestMemoryBudgetExceededError } from '@contember/database'\n\ntype DataPromises = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: Promise<SelectNestedData>\n\tdefaultValue: SelectNestedDefaultValue\n}\n\ntype ResolvedData = {\n\tpath: Path\n\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>\n\tdata: SelectNestedData\n\tdefaultValue: SelectNestedDefaultValue\n}\n\nexport type ColumnValueGetter<T extends Value.FieldValue = Value.FieldValue> = (row: SelectRow) => T\n\ntype Column = {\n\tpath: Path\n\tgetValue: ColumnValueGetter\n}\n\n/** Keys are field aliases, i.e. chosen by the client. */\ntype RowLayout = Map<string, RowLayoutEntry>\n\ntype RowLayoutEntry =\n\t| { readonly type: 'column'; readonly getValue: ColumnValueGetter }\n\t| { readonly type: 'object'; readonly layout: RowLayout }\n\t| { readonly type: 'relation'; readonly relation: ResolvedData }\n\ntype HydratedObject = { [key: string]: Value.FieldValue }\n\n/** An alias may be `__proto__`, which a plain assignment would turn into a prototype change. */\nconst setOwnValue = (object: HydratedObject, key: string, value: Value.FieldValue): void => {\n\tif (key === '__proto__') {\n\t\tObject.defineProperty(object, key, { value, enumerable: true, configurable: true, writable: true })\n\t} else {\n\t\tobject[key] = value\n\t}\n}\n\nexport class SelectHydrator {\n\tprivate columns: Column[] = []\n\tprivate promises: DataPromises[] = []\n\tprivate formattedDates = 0\n\n\tconstructor(private readonly memoryBudget?: RequestMemoryBudget) {}\n\n\tpublic addColumn(path: Path, getValue: ColumnValueGetter) {\n\t\tthis.columns.push({ path, getValue })\n\t}\n\n\tpublic addPromise(\n\t\tpath: Path,\n\t\tgetParentValue: ColumnValueGetter<Value.PrimaryValue | null>,\n\t\tdata: Promise<SelectNestedData>,\n\t\tdefaultValue: SelectNestedDefaultValue,\n\t) {\n\t\tthis.promises.push({ path, getParentValue, data, defaultValue })\n\t}\n\n\tpublic async hydrateGroups(rows: SelectRow[], groupBy: string): Promise<SelectGroupedObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tconst result: SelectGroupedObjects = {}\n\t\trows.forEach((row, index) => {\n\t\t\tconst key = row[groupBy] as Value.PrimaryValue\n\t\t\tif (!result[key]) {\n\t\t\t\tresult[key] = []\n\t\t\t}\n\t\t\tresult[key].push(hydrated[index])\n\t\t})\n\t\treturn result\n\t}\n\n\tpublic async hydrateAll(rows: SelectRow[]): Promise<SelectResultObject[]>\n\tpublic async hydrateAll(rows: SelectRow[], indexBy: string): Promise<SelectIndexedResultObjects>\n\n\tpublic async hydrateAll(\n\t\trows: SelectRow[],\n\t\tindexBy?: string,\n\t): Promise<SelectResultObject[] | SelectIndexedResultObjects> {\n\t\tconst hydrated = await this.hydrateRows(rows)\n\t\tif (indexBy) {\n\t\t\tconst result: SelectIndexedResultObjects = {}\n\t\t\trows.forEach((row, index) => {\n\t\t\t\tresult[row[indexBy] as Value.PrimaryValue] = hydrated[index]\n\t\t\t})\n\t\t\treturn result\n\t\t}\n\t\treturn hydrated\n\t}\n\n\tprivate async hydrateRows(rows: SelectRow[]): Promise<SelectResultObject[]> {\n\t\tconst resolved = await this.resolveDataPromises()\n\t\tthis.chargeRows(rows.length, resolved.length)\n\t\tthis.formattedDates = 0\n\t\tconst layout = this.createRowLayout(resolved)\n\t\tconst hydrated = rows.map(row => this.hydrateObject(row, layout))\n\t\t// A formatted Date is a new string; their count is known only after the rows are built.\n\t\tthis.memoryBudget?.addHydrationBytes(this.formattedDates * 72)\n\t\treturn hydrated\n\t}\n\n\t/** Every row has the same shape, so the paths are resolved once instead of per row and column. */\n\tprivate createRowLayout(resolvedData: ResolvedData[]): RowLayout {\n\t\tconst layout: RowLayout = new Map()\n\n\t\tfor (const { path, getValue } of this.columns) {\n\t\t\tconst parts = path.path\n\t\t\tlet current = layout\n\t\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\t\tconst existing = current.get(part)\n\t\t\t\tif (existing?.type === 'object') {\n\t\t\t\t\tcurrent = existing.layout\n\t\t\t\t} else {\n\t\t\t\t\tconst nested: RowLayout = new Map()\n\t\t\t\t\tcurrent.set(part, { type: 'object', layout: nested })\n\t\t\t\t\tcurrent = nested\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent.set(parts[parts.length - 1], { type: 'column', getValue })\n\t\t}\n\n\t\t// a relation lands only in an object the columns created\n\t\tfor (const relation of resolvedData) {\n\t\t\tconst parts = relation.path.path\n\t\t\tlet current: RowLayout | undefined = layout\n\t\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\t\tconst existing: RowLayoutEntry | undefined = current.get(part)\n\t\t\t\tcurrent = existing?.type === 'object' ? existing.layout : undefined\n\t\t\t\tif (!current) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tcurrent?.set(parts[parts.length - 1], { type: 'relation', relation })\n\t\t}\n\n\t\treturn layout\n\t}\n\n\tprivate hydrateObject(row: SelectRow, layout: RowLayout): SelectResultObject {\n\t\tconst result: HydratedObject = {}\n\t\tfor (const [key, entry] of layout) {\n\t\t\tsetOwnValue(result, key, this.hydrateEntry(row, entry))\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate hydrateEntry(row: SelectRow, entry: RowLayoutEntry): Value.FieldValue {\n\t\tswitch (entry.type) {\n\t\t\tcase 'column':\n\t\t\t\treturn this.formatValue(entry.getValue(row))\n\t\t\tcase 'object':\n\t\t\t\treturn this.hydrateObject(row, entry.layout)\n\t\t\tcase 'relation': {\n\t\t\t\tconst { getParentValue, data, defaultValue } = entry.relation\n\t\t\t\tconst parentValue = getParentValue(row)\n\t\t\t\treturn (parentValue && Object.hasOwn(data, parentValue) ? data[parentValue] : undefined) || defaultValue\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async resolveDataPromises(): Promise<ResolvedData[]> {\n\t\tconst results = await Promise.allSettled(this.promises.map(async (it): Promise<ResolvedData> => ({\n\t\t\tdefaultValue: it.defaultValue,\n\t\t\tgetParentValue: it.getParentValue,\n\t\t\tpath: it.path,\n\t\t\tdata: await it.data,\n\t\t})))\n\t\tconst failures = getRejections(results)\n\t\tif (failures.length > 0) {\n\t\t\t// Budget exhaustion aborts every in-flight sibling query; those rejections are expected.\n\t\t\tfailures.slice(1)\n\t\t\t\t.filter(e => !(e instanceof RequestMemoryBudgetExceededError))\n\t\t\t\t.forEach(e => logger.error(e, { loc: 'SelectHydrator' }))\n\t\t\tthrow failures[0]\n\t\t}\n\n\t\treturn getFulfilledValues(results)\n\t}\n\n\tprivate formatValue(value: any) {\n\t\tif (value instanceof Date) {\n\t\t\tthis.formattedDates++\n\t\t\treturn value.toISOString()\n\t\t}\n\t\treturn value\n\t}\n\n\t// The row shape is fixed by the columns, so all rows are charged at once, before any of them is allocated.\n\tprivate chargeRows(rowCount: number, relationCount: number): void {\n\t\tif (!this.memoryBudget || rowCount === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst nestedObjects = new Set<string>()\n\t\tfor (const { path } of this.columns) {\n\t\t\tfor (let depth = 1; depth < path.path.length; depth++) {\n\t\t\t\tnestedObjects.add(path.path.slice(0, depth).join('.'))\n\t\t\t}\n\t\t}\n\t\tconst rowBytes = 40 + this.columns.length * 16 + nestedObjects.size * 48 + relationCount * 16\n\t\tthis.memoryBudget.addHydrationBytes(rowCount * rowBytes)\n\t}\n}\n\nexport type SelectRow = { [key: string]: Value.FieldValue }\nexport type SelectResultObject = Value.Object\nexport type SelectIndexedResultObjects = { [key: string]: SelectResultObject }\nexport type SelectGroupedObjects = { [groupingKey: string]: SelectResultObject[] }\nexport type SelectNestedData = SelectGroupedObjects | SelectIndexedResultObjects\nexport type SelectNestedDefaultValue = [] | null\n"],"names":[],"mappings":";;;;;;;AAsCA,MAAM,cAAc,CAAC,QAAwB,KAAa,UAAkC;AAC3F,MAAI,QAAQ,aAAa;AACxB,WAAO,eAAe,QAAQ,KAAK,EAAE,OAAO,YAAY,MAAM,cAAc,MAAM,UAAU,KAAA,CAAM;AAAA,EACnG,OAAO;AACN,WAAO,GAAG,IAAI;AAAA,EACf;AACD;AAEO,MAAM,eAAe;AAAA,EAK3B,YAA6B,cAAoC;AAApC,SAAA,eAAA;AAJ7B,kBAAA,MAAQ,WAAoB,EAAC;AAC7B,kBAAA,MAAQ,YAA2B,EAAC;AACpC,kBAAA,MAAQ,kBAAiB,CAAA;AAAA,EAEyC;AAAA,EAE3D,UAAU,MAAY,UAA6B;AACzD,SAAK,QAAQ,KAAK,EAAE,MAAM,UAAU;AAAA,EACrC;AAAA,EAEO,WACN,MACA,gBACA,MACA,cACC;AACD,SAAK,SAAS,KAAK,EAAE,MAAM,gBAAgB,MAAM,cAAc;AAAA,EAChE;AAAA,EAEA,MAAa,cAAc,MAAmB,SAAgD;AAC7F,UAAM,WAAW,MAAM,KAAK,YAAY,IAAI;AAC5C,UAAM,SAA+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G;AAAA,MACnB,MAAM,GAAG;AAAA,MACT,MAAM,MAAM,GAAG;AAAA,IAAA,EACd,CAAC;AACH,UAAM,WAAW,cAAc,OAAO;AACtC,QAAI,SAAS,SAAS,GAAG;AAExB,eAAS,MAAM,CAAC,EACd,OAAO,CAAA,MAAK,EAAE,aAAa,iCAAiC,EAC5D,QAAQ,CAAA,MAAK,OAAO,MAAM,GAAG,EAAE,KAAK,iBAAA,CAAkB,CAAC;AACzD,YAAM,SAAS,CAAC;AAAA,IACjB;AAEA,WAAO,mBAAmB,OAAO;AAAA,EAClC;AAAA,EAEQ,YAAY,OAAY;AAC/B,QAAI,iBAAiB,MAAM;AAC1B,WAAK;AACL,aAAO,MAAM,YAAA;AAAA,IACd;AACA,WAAO;AAAA,EACR;AAAA;AAAA,EAGQ,WAAW,UAAkB,eAA6B;AACjE,QAAI,CAAC,KAAK,gBAAgB,aAAa,GAAG;AACzC;AAAA,IACD;AACA,UAAM,oCAAoB,IAAA;AAC1B,eAAW,EAAE,UAAU,KAAK,SAAS;AACpC,eAAS,QAAQ,GAAG,QAAQ,KAAK,KAAK,QAAQ,SAAS;AACtD,sBAAc,IAAI,KAAK,KAAK,MAAM,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,MACtD;AAAA,IACD;AACA,UAAM,WAAW,KAAK,KAAK,QAAQ,SAAS,KAAK,cAAc,OAAO,KAAK,gBAAgB;AAC3F,SAAK,aAAa,kBAAkB,WAAW,QAAQ;AAAA,EACxD;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GraphQlQueryAstFactory.cjs","sources":["../../../../../packages/engine-content-api/src/resolvers/GraphQlQueryAstFactory.ts"],"sourcesContent":["import { isIt, ResolveInfoUtils } from '../utils/index.js'\nimport {\n\tFieldNode as GraphQlFieldNode,\n\tFragmentSpreadNode,\n\tgetArgumentValues,\n\tGraphQLInterfaceType,\n\tGraphQLObjectType,\n\tGraphQLOutputType,\n\tGraphQLResolveInfo,\n\tisInterfaceType,\n\tisListType,\n\tisNonNullType,\n\tisObjectType,\n\tKind,\n\tSelectionSetNode,\n} from 'graphql'\nimport { FieldNode, ObjectNode } from '../inputProcessing/index.js'\nimport { isDeepStrictEqual } from 'node:util'\n\ntype NodeFilter = (node: GraphQlFieldNode, path: string[]) => boolean\ntype AnyNode = ObjectNode | FieldNode\n\nexport class GraphQlQueryAstFactory {\n\tpublic create<Args = any>(info: GraphQLResolveInfo, filter?: NodeFilter): ObjectNode<Args> {\n\t\tconst node = ResolveInfoUtils.extractFieldNode(info)\n\t\tconst parentType = info.parentType\n\n\t\treturn this.createFromNode(info, parentType as GraphQLObjectType, node, [], filter || (() => true)) as ObjectNode\n\t}\n\n\tprivate createFromNode(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tnode: GraphQlFieldNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): ObjectNode | FieldNode | null {\n\t\tif (!filter(node, path)) {\n\t\t\treturn null\n\t\t}\n\t\tconst name = node.name.value\n\t\tconst alias = node.alias ? node.alias.value : name\n\t\tif (!node.selectionSet) {\n\t\t\treturn new FieldNode(name, alias, {})\n\t\t}\n\t\tconst field = parentType.getFields()[name]\n\t\tconst type = field.type\n\t\tconst resolvedType = GraphQlQueryAstFactory.resolveObjectType(type)\n\n\t\tconst fields: AnyNode[] = this.processSelectionSet(info, resolvedType, node.selectionSet, [...path, alias], filter)\n\n\t\treturn new ObjectNode(\n\t\t\tname,\n\t\t\talias,\n\t\t\tfields,\n\t\t\tgetArgumentValues(field, node, info.variableValues),\n\t\t\tfield.extensions || {},\n\t\t\tpath,\n\t\t)\n\t}\n\n\tprivate processSelectionSet(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tselectionSet: SelectionSetNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode[] {\n\t\tconst fields: ObjectNode | FieldNode[] = []\n\t\tfor (const subNode of selectionSet.selections) {\n\t\t\tif (isIt<GraphQlFieldNode>(subNode, 'kind', Kind.FIELD)) {\n\t\t\t\tconst field = this.createFromNode(info, parentType, subNode, path, filter)\n\t\t\t\tif (field === null) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields.push(field)\n\t\t\t} else if (isIt<FragmentSpreadNode>(subNode, 'kind', Kind.FRAGMENT_SPREAD)) {\n\t\t\t\tconst fragmentDefinition = info.fragments[subNode.name.value]\n\t\t\t\tif (!fragmentDefinition) {\n\t\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: Fragment definition ${subNode.name.value} not found`)\n\t\t\t\t}\n\t\t\t\tconst typeName = fragmentDefinition.typeCondition.name.value\n\t\t\t\tconst subField = info.schema.getType(typeName)\n\t\t\t\tif (!isObjectType(subField) && !isInterfaceType(subField)) {\n\t\t\t\t\tthrow new Error('GraphQlQueryAstFactory: subfield is expected to be GraphQLObjectType or GraphQLInterfaceType')\n\t\t\t\t}\n\t\t\t\tconst fragmentSelection = this.processSelectionSet(\n\t\t\t\t\tinfo,\n\t\t\t\t\tsubField,\n\t\t\t\t\tfragmentDefinition.selectionSet,\n\t\t\t\t\tpath,\n\t\t\t\t\tfilter,\n\t\t\t\t)\n\t\t\t\tfields.push(...fragmentSelection)\n\t\t\t} else {\n\t\t\t\tthrow new Error('InlineFragment are not supported yet')\n\t\t\t}\n\t\t}\n\t\treturn GraphQlQueryAstFactory.mergeFieldList(fields)\n\t}\n\n\tpublic static resolveObjectType(type: GraphQLOutputType): GraphQLObjectType {\n\t\tif (isObjectType(type)) {\n\t\t\treturn type\n\t\t}\n\t\tif (isListType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tif (isNonNullType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tthrow new Error(GraphQlQueryAstFactory.getValueType(type))\n\t}\n\n\tprivate static getValueType(val: any): string {\n\t\tif (typeof val === 'object' && val.constructor) {\n\t\t\treturn 'Object of type ' + val.constructor.name + ' is not supported'\n\t\t}\n\t\treturn typeof val + ' is not supported'\n\t}\n\n\tprivate static mergeFieldList(nodes: AnyNode[]): AnyNode[] {\n\t\tconst result: Record<string, AnyNode> = {}\n\t\tfor (const node of nodes) {\n\t\t\tresult[node.alias] = result[node.alias] ? GraphQlQueryAstFactory.mergeFields(result[node.alias], node) : node\n\t\t}\n\t\treturn Object.values(result)\n\t}\n\n\tprivate static mergeFields(left: AnyNode, right: AnyNode): AnyNode {\n\t\tif (left.constructor !== right.constructor) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)\n\t\t}\n\t\tif (left.name !== right.name) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)\n\t\t}\n\t\tif (left instanceof ObjectNode && right instanceof ObjectNode) {\n\t\t\tif (!isDeepStrictEqual(left.args, right.args)) {\n\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible args`)\n\t\t\t}\n\t\t\tconst fields = GraphQlQueryAstFactory.mergeFieldList([...left.fields, ...right.fields])\n\t\t\treturn new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)\n\t\t}\n\t\treturn left\n\t}\n}\n"],"names":["ResolveInfoUtils","FieldNode","ObjectNode","getArgumentValues","isIt","Kind","isObjectType","isInterfaceType","isListType","isNonNullType","isDeepStrictEqual"],"mappings":";;;;;;;;;;AAsBO,MAAM,uBAAuB;AAAA,EAC5B,OAAmB,MAA0B,QAAuC;AAC1F,UAAM,OAAOA,iBAAAA,iBAAiB,iBAAiB,IAAI;AACnD,UAAM,aAAa,KAAK;AAExB,WAAO,KAAK,eAAe,MAAM,YAAiC,MAAM,IAAI,WAAW,MAAM,KAAK;AAAA,EACnG;AAAA,EAEQ,eACP,MACA,YACA,MACA,MACA,QACgC;AAChC,QAAI,CAAC,OAAO,MAAM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,IAAI,EAAE;AAAA,IAC9G;AACA,QAAI,KAAK,SAAS,MAAM,MAAM;AAC7B,YAAM,IAAI,MAAM,+CAA+C,KAAK,IAAI,QAAQ,MAAM,IAAI,EAAE;AAAA,IAC7F;AACA,QAAI,gBAAgBP,WAAAA,cAAc,iBAAiBA,uBAAY;AAC9D,UAAI,CAACQ,UAAAA,kBAAkB,KAAK,MAAM,MAAM,IAAI,GAAG;AAC9C,cAAM,IAAI,MAAM,2CAA2C;AAAA,MAC5D;AACA,YAAM,SAAS,uBAAuB,eAAe,CAAC,GAAG,KAAK,QAAQ,GAAG,MAAM,MAAM,CAAC;AACtF,aAAO,IAAIR,WAAAA,WAAW,KAAK,MAAM,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,IAC3F;AACA,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"GraphQlQueryAstFactory.cjs","sources":["../../../../../packages/engine-content-api/src/resolvers/GraphQlQueryAstFactory.ts"],"sourcesContent":["import { isIt, ResolveInfoUtils } from '../utils/index.js'\nimport {\n\tFieldNode as GraphQlFieldNode,\n\tFragmentSpreadNode,\n\tgetArgumentValues,\n\tGraphQLInterfaceType,\n\tGraphQLObjectType,\n\tGraphQLOutputType,\n\tGraphQLResolveInfo,\n\tisInterfaceType,\n\tisListType,\n\tisNonNullType,\n\tisObjectType,\n\tKind,\n\tSelectionSetNode,\n} from 'graphql'\nimport { FieldNode, ObjectNode } from '../inputProcessing/index.js'\nimport { isDeepStrictEqual } from 'node:util'\n\nexport type NodeFilter = (node: GraphQlFieldNode, path: string[]) => boolean\ntype AnyNode = ObjectNode | FieldNode\n\nexport class GraphQlQueryAstFactory {\n\tpublic create<Args = any>(info: GraphQLResolveInfo, filter?: NodeFilter): ObjectNode<Args> {\n\t\tconst node = ResolveInfoUtils.extractFieldNode(info)\n\t\tconst parentType = info.parentType\n\n\t\treturn this.createFromNode(info, parentType as GraphQLObjectType, node, [], filter || (() => true)) as ObjectNode\n\t}\n\n\tprivate createFromNode(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tnode: GraphQlFieldNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): ObjectNode | FieldNode | null {\n\t\tif (!filter(node, path)) {\n\t\t\treturn null\n\t\t}\n\t\tconst name = node.name.value\n\t\tconst alias = node.alias ? node.alias.value : name\n\t\tif (!node.selectionSet) {\n\t\t\treturn new FieldNode(name, alias, {})\n\t\t}\n\t\tconst field = parentType.getFields()[name]\n\t\tconst type = field.type\n\t\tconst resolvedType = GraphQlQueryAstFactory.resolveObjectType(type)\n\n\t\tconst fields: AnyNode[] = this.processSelectionSet(info, resolvedType, node.selectionSet, [...path, alias], filter)\n\n\t\treturn new ObjectNode(\n\t\t\tname,\n\t\t\talias,\n\t\t\tfields,\n\t\t\tgetArgumentValues(field, node, info.variableValues),\n\t\t\tfield.extensions || {},\n\t\t\tpath,\n\t\t)\n\t}\n\n\tprivate processSelectionSet(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tselectionSet: SelectionSetNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode[] {\n\t\tconst fields: ObjectNode | FieldNode[] = []\n\t\tfor (const subNode of selectionSet.selections) {\n\t\t\tif (isIt<GraphQlFieldNode>(subNode, 'kind', Kind.FIELD)) {\n\t\t\t\tconst field = this.createFromNode(info, parentType, subNode, path, filter)\n\t\t\t\tif (field === null) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields.push(field)\n\t\t\t} else if (isIt<FragmentSpreadNode>(subNode, 'kind', Kind.FRAGMENT_SPREAD)) {\n\t\t\t\tconst fragmentDefinition = info.fragments[subNode.name.value]\n\t\t\t\tif (!fragmentDefinition) {\n\t\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: Fragment definition ${subNode.name.value} not found`)\n\t\t\t\t}\n\t\t\t\tconst typeName = fragmentDefinition.typeCondition.name.value\n\t\t\t\tconst subField = info.schema.getType(typeName)\n\t\t\t\tif (!isObjectType(subField) && !isInterfaceType(subField)) {\n\t\t\t\t\tthrow new Error('GraphQlQueryAstFactory: subfield is expected to be GraphQLObjectType or GraphQLInterfaceType')\n\t\t\t\t}\n\t\t\t\tconst fragmentSelection = this.processSelectionSet(\n\t\t\t\t\tinfo,\n\t\t\t\t\tsubField,\n\t\t\t\t\tfragmentDefinition.selectionSet,\n\t\t\t\t\tpath,\n\t\t\t\t\tfilter,\n\t\t\t\t)\n\t\t\t\tfields.push(...fragmentSelection)\n\t\t\t} else {\n\t\t\t\tthrow new Error('InlineFragment are not supported yet')\n\t\t\t}\n\t\t}\n\t\treturn GraphQlQueryAstFactory.mergeFieldList(fields)\n\t}\n\n\tpublic static resolveObjectType(type: GraphQLOutputType): GraphQLObjectType {\n\t\tif (isObjectType(type)) {\n\t\t\treturn type\n\t\t}\n\t\tif (isListType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tif (isNonNullType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tthrow new Error(GraphQlQueryAstFactory.getValueType(type))\n\t}\n\n\tprivate static getValueType(val: any): string {\n\t\tif (typeof val === 'object' && val.constructor) {\n\t\t\treturn 'Object of type ' + val.constructor.name + ' is not supported'\n\t\t}\n\t\treturn typeof val + ' is not supported'\n\t}\n\n\tpublic static mergeFieldList(nodes: AnyNode[]): AnyNode[] {\n\t\tconst result: Record<string, AnyNode> = {}\n\t\tfor (const node of nodes) {\n\t\t\tresult[node.alias] = result[node.alias] ? GraphQlQueryAstFactory.mergeFields(result[node.alias], node) : node\n\t\t}\n\t\treturn Object.values(result)\n\t}\n\n\tprivate static mergeFields(left: AnyNode, right: AnyNode): AnyNode {\n\t\tif (left.constructor !== right.constructor) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)\n\t\t}\n\t\tif (left.name !== right.name) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)\n\t\t}\n\t\tif (left instanceof ObjectNode && right instanceof ObjectNode) {\n\t\t\tif (!isDeepStrictEqual(left.args, right.args)) {\n\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible args`)\n\t\t\t}\n\t\t\tconst fields = GraphQlQueryAstFactory.mergeFieldList([...left.fields, ...right.fields])\n\t\t\treturn new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)\n\t\t}\n\t\treturn left\n\t}\n}\n"],"names":["ResolveInfoUtils","FieldNode","ObjectNode","getArgumentValues","isIt","Kind","isObjectType","isInterfaceType","isListType","isNonNullType","isDeepStrictEqual"],"mappings":";;;;;;;;;;AAsBO,MAAM,uBAAuB;AAAA,EAC5B,OAAmB,MAA0B,QAAuC;AAC1F,UAAM,OAAOA,iBAAAA,iBAAiB,iBAAiB,IAAI;AACnD,UAAM,aAAa,KAAK;AAExB,WAAO,KAAK,eAAe,MAAM,YAAiC,MAAM,IAAI,WAAW,MAAM,KAAK;AAAA,EACnG;AAAA,EAEQ,eACP,MACA,YACA,MACA,MACA,QACgC;AAChC,QAAI,CAAC,OAAO,MAAM,IAAI,GAAG;AACxB,aAAO;AAAA,IACR;AACA,UAAM,OAAO,KAAK,KAAK;AACvB,UAAM,QAAQ,KAAK,QAAQ,KAAK,MAAM,QAAQ;AAC9C,QAAI,CAAC,KAAK,cAAc;AACvB,aAAO,IAAIC,UAAAA,UAAU,MAAM,OAAO,CAAA,CAAE;AAAA,IACrC;AACA,UAAM,QAAQ,WAAW,UAAA,EAAY,IAAI;AACzC,UAAM,OAAO,MAAM;AACnB,UAAM,eAAe,uBAAuB,kBAAkB,IAAI;AAElE,UAAM,SAAoB,KAAK,oBAAoB,MAAM,cAAc,KAAK,cAAc,CAAC,GAAG,MAAM,KAAK,GAA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AAAA,WAAW,KAAK,MAAM,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,IAC3F;AACA,WAAO;AAAA,EACR;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GraphQlQueryAstFactory.js","sources":["../../../../../packages/engine-content-api/src/resolvers/GraphQlQueryAstFactory.ts"],"sourcesContent":["import { isIt, ResolveInfoUtils } from '../utils/index.js'\nimport {\n\tFieldNode as GraphQlFieldNode,\n\tFragmentSpreadNode,\n\tgetArgumentValues,\n\tGraphQLInterfaceType,\n\tGraphQLObjectType,\n\tGraphQLOutputType,\n\tGraphQLResolveInfo,\n\tisInterfaceType,\n\tisListType,\n\tisNonNullType,\n\tisObjectType,\n\tKind,\n\tSelectionSetNode,\n} from 'graphql'\nimport { FieldNode, ObjectNode } from '../inputProcessing/index.js'\nimport { isDeepStrictEqual } from 'node:util'\n\ntype NodeFilter = (node: GraphQlFieldNode, path: string[]) => boolean\ntype AnyNode = ObjectNode | FieldNode\n\nexport class GraphQlQueryAstFactory {\n\tpublic create<Args = any>(info: GraphQLResolveInfo, filter?: NodeFilter): ObjectNode<Args> {\n\t\tconst node = ResolveInfoUtils.extractFieldNode(info)\n\t\tconst parentType = info.parentType\n\n\t\treturn this.createFromNode(info, parentType as GraphQLObjectType, node, [], filter || (() => true)) as ObjectNode\n\t}\n\n\tprivate createFromNode(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tnode: GraphQlFieldNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): ObjectNode | FieldNode | null {\n\t\tif (!filter(node, path)) {\n\t\t\treturn null\n\t\t}\n\t\tconst name = node.name.value\n\t\tconst alias = node.alias ? node.alias.value : name\n\t\tif (!node.selectionSet) {\n\t\t\treturn new FieldNode(name, alias, {})\n\t\t}\n\t\tconst field = parentType.getFields()[name]\n\t\tconst type = field.type\n\t\tconst resolvedType = GraphQlQueryAstFactory.resolveObjectType(type)\n\n\t\tconst fields: AnyNode[] = this.processSelectionSet(info, resolvedType, node.selectionSet, [...path, alias], filter)\n\n\t\treturn new ObjectNode(\n\t\t\tname,\n\t\t\talias,\n\t\t\tfields,\n\t\t\tgetArgumentValues(field, node, info.variableValues),\n\t\t\tfield.extensions || {},\n\t\t\tpath,\n\t\t)\n\t}\n\n\tprivate processSelectionSet(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tselectionSet: SelectionSetNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode[] {\n\t\tconst fields: ObjectNode | FieldNode[] = []\n\t\tfor (const subNode of selectionSet.selections) {\n\t\t\tif (isIt<GraphQlFieldNode>(subNode, 'kind', Kind.FIELD)) {\n\t\t\t\tconst field = this.createFromNode(info, parentType, subNode, path, filter)\n\t\t\t\tif (field === null) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields.push(field)\n\t\t\t} else if (isIt<FragmentSpreadNode>(subNode, 'kind', Kind.FRAGMENT_SPREAD)) {\n\t\t\t\tconst fragmentDefinition = info.fragments[subNode.name.value]\n\t\t\t\tif (!fragmentDefinition) {\n\t\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: Fragment definition ${subNode.name.value} not found`)\n\t\t\t\t}\n\t\t\t\tconst typeName = fragmentDefinition.typeCondition.name.value\n\t\t\t\tconst subField = info.schema.getType(typeName)\n\t\t\t\tif (!isObjectType(subField) && !isInterfaceType(subField)) {\n\t\t\t\t\tthrow new Error('GraphQlQueryAstFactory: subfield is expected to be GraphQLObjectType or GraphQLInterfaceType')\n\t\t\t\t}\n\t\t\t\tconst fragmentSelection = this.processSelectionSet(\n\t\t\t\t\tinfo,\n\t\t\t\t\tsubField,\n\t\t\t\t\tfragmentDefinition.selectionSet,\n\t\t\t\t\tpath,\n\t\t\t\t\tfilter,\n\t\t\t\t)\n\t\t\t\tfields.push(...fragmentSelection)\n\t\t\t} else {\n\t\t\t\tthrow new Error('InlineFragment are not supported yet')\n\t\t\t}\n\t\t}\n\t\treturn GraphQlQueryAstFactory.mergeFieldList(fields)\n\t}\n\n\tpublic static resolveObjectType(type: GraphQLOutputType): GraphQLObjectType {\n\t\tif (isObjectType(type)) {\n\t\t\treturn type\n\t\t}\n\t\tif (isListType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tif (isNonNullType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tthrow new Error(GraphQlQueryAstFactory.getValueType(type))\n\t}\n\n\tprivate static getValueType(val: any): string {\n\t\tif (typeof val === 'object' && val.constructor) {\n\t\t\treturn 'Object of type ' + val.constructor.name + ' is not supported'\n\t\t}\n\t\treturn typeof val + ' is not supported'\n\t}\n\n\tprivate static mergeFieldList(nodes: AnyNode[]): AnyNode[] {\n\t\tconst result: Record<string, AnyNode> = {}\n\t\tfor (const node of nodes) {\n\t\t\tresult[node.alias] = result[node.alias] ? GraphQlQueryAstFactory.mergeFields(result[node.alias], node) : node\n\t\t}\n\t\treturn Object.values(result)\n\t}\n\n\tprivate static mergeFields(left: AnyNode, right: AnyNode): AnyNode {\n\t\tif (left.constructor !== right.constructor) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)\n\t\t}\n\t\tif (left.name !== right.name) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)\n\t\t}\n\t\tif (left instanceof ObjectNode && right instanceof ObjectNode) {\n\t\t\tif (!isDeepStrictEqual(left.args, right.args)) {\n\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible args`)\n\t\t\t}\n\t\t\tconst fields = GraphQlQueryAstFactory.mergeFieldList([...left.fields, ...right.fields])\n\t\t\treturn new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)\n\t\t}\n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AK,GAAG,IAAI,IAAI;AAAA,IAC1G;AACA,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAAA,EAEA,OAAe,YAAY,MAAe,OAAyB;AAClE,QAAI,KAAK,gBAAgB,MAAM,aAAa;AAC3C,YAAM,IAAI,MAAM,wCAAwC,KAAK,YAAY,IAAI,QAAQ,MAAM,YAAY,IAAI,EAAE;AAAA,IAC9G;AACA,QAAI,KAAK,SAAS,MAAM,MAAM;AAC7B,YAAM,IAAI,MAAM,+CAA+C,KAAK,IAAI,QAAQ,MAAM,IAAI,EAAE;AAAA,IAC7F;AACA,QAAI,gBAAgB,cAAc,iBAAiB,YAAY;AAC9D,UAAI,CAAC,kBAAkB,KAAK,MAAM,MAAM,IAAI,GAAG;AAC9C,cAAM,IAAI,MAAM,2CAA2C;AAAA,MAC5D;AACA,YAAM,SAAS,uBAAuB,eAAe,CAAC,GAAG,KAAK,QAAQ,GAAG,MAAM,MAAM,CAAC;AACtF,aAAO,IAAI,WAAW,KAAK,MAAM,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,IAC3F;AACA,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"GraphQlQueryAstFactory.js","sources":["../../../../../packages/engine-content-api/src/resolvers/GraphQlQueryAstFactory.ts"],"sourcesContent":["import { isIt, ResolveInfoUtils } from '../utils/index.js'\nimport {\n\tFieldNode as GraphQlFieldNode,\n\tFragmentSpreadNode,\n\tgetArgumentValues,\n\tGraphQLInterfaceType,\n\tGraphQLObjectType,\n\tGraphQLOutputType,\n\tGraphQLResolveInfo,\n\tisInterfaceType,\n\tisListType,\n\tisNonNullType,\n\tisObjectType,\n\tKind,\n\tSelectionSetNode,\n} from 'graphql'\nimport { FieldNode, ObjectNode } from '../inputProcessing/index.js'\nimport { isDeepStrictEqual } from 'node:util'\n\nexport type NodeFilter = (node: GraphQlFieldNode, path: string[]) => boolean\ntype AnyNode = ObjectNode | FieldNode\n\nexport class GraphQlQueryAstFactory {\n\tpublic create<Args = any>(info: GraphQLResolveInfo, filter?: NodeFilter): ObjectNode<Args> {\n\t\tconst node = ResolveInfoUtils.extractFieldNode(info)\n\t\tconst parentType = info.parentType\n\n\t\treturn this.createFromNode(info, parentType as GraphQLObjectType, node, [], filter || (() => true)) as ObjectNode\n\t}\n\n\tprivate createFromNode(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tnode: GraphQlFieldNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): ObjectNode | FieldNode | null {\n\t\tif (!filter(node, path)) {\n\t\t\treturn null\n\t\t}\n\t\tconst name = node.name.value\n\t\tconst alias = node.alias ? node.alias.value : name\n\t\tif (!node.selectionSet) {\n\t\t\treturn new FieldNode(name, alias, {})\n\t\t}\n\t\tconst field = parentType.getFields()[name]\n\t\tconst type = field.type\n\t\tconst resolvedType = GraphQlQueryAstFactory.resolveObjectType(type)\n\n\t\tconst fields: AnyNode[] = this.processSelectionSet(info, resolvedType, node.selectionSet, [...path, alias], filter)\n\n\t\treturn new ObjectNode(\n\t\t\tname,\n\t\t\talias,\n\t\t\tfields,\n\t\t\tgetArgumentValues(field, node, info.variableValues),\n\t\t\tfield.extensions || {},\n\t\t\tpath,\n\t\t)\n\t}\n\n\tprivate processSelectionSet(\n\t\tinfo: GraphQLResolveInfo,\n\t\tparentType: GraphQLObjectType | GraphQLInterfaceType,\n\t\tselectionSet: SelectionSetNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode[] {\n\t\tconst fields: ObjectNode | FieldNode[] = []\n\t\tfor (const subNode of selectionSet.selections) {\n\t\t\tif (isIt<GraphQlFieldNode>(subNode, 'kind', Kind.FIELD)) {\n\t\t\t\tconst field = this.createFromNode(info, parentType, subNode, path, filter)\n\t\t\t\tif (field === null) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfields.push(field)\n\t\t\t} else if (isIt<FragmentSpreadNode>(subNode, 'kind', Kind.FRAGMENT_SPREAD)) {\n\t\t\t\tconst fragmentDefinition = info.fragments[subNode.name.value]\n\t\t\t\tif (!fragmentDefinition) {\n\t\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: Fragment definition ${subNode.name.value} not found`)\n\t\t\t\t}\n\t\t\t\tconst typeName = fragmentDefinition.typeCondition.name.value\n\t\t\t\tconst subField = info.schema.getType(typeName)\n\t\t\t\tif (!isObjectType(subField) && !isInterfaceType(subField)) {\n\t\t\t\t\tthrow new Error('GraphQlQueryAstFactory: subfield is expected to be GraphQLObjectType or GraphQLInterfaceType')\n\t\t\t\t}\n\t\t\t\tconst fragmentSelection = this.processSelectionSet(\n\t\t\t\t\tinfo,\n\t\t\t\t\tsubField,\n\t\t\t\t\tfragmentDefinition.selectionSet,\n\t\t\t\t\tpath,\n\t\t\t\t\tfilter,\n\t\t\t\t)\n\t\t\t\tfields.push(...fragmentSelection)\n\t\t\t} else {\n\t\t\t\tthrow new Error('InlineFragment are not supported yet')\n\t\t\t}\n\t\t}\n\t\treturn GraphQlQueryAstFactory.mergeFieldList(fields)\n\t}\n\n\tpublic static resolveObjectType(type: GraphQLOutputType): GraphQLObjectType {\n\t\tif (isObjectType(type)) {\n\t\t\treturn type\n\t\t}\n\t\tif (isListType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tif (isNonNullType(type)) {\n\t\t\treturn GraphQlQueryAstFactory.resolveObjectType(type.ofType)\n\t\t}\n\t\tthrow new Error(GraphQlQueryAstFactory.getValueType(type))\n\t}\n\n\tprivate static getValueType(val: any): string {\n\t\tif (typeof val === 'object' && val.constructor) {\n\t\t\treturn 'Object of type ' + val.constructor.name + ' is not supported'\n\t\t}\n\t\treturn typeof val + ' is not supported'\n\t}\n\n\tpublic static mergeFieldList(nodes: AnyNode[]): AnyNode[] {\n\t\tconst result: Record<string, AnyNode> = {}\n\t\tfor (const node of nodes) {\n\t\t\tresult[node.alias] = result[node.alias] ? GraphQlQueryAstFactory.mergeFields(result[node.alias], node) : node\n\t\t}\n\t\treturn Object.values(result)\n\t}\n\n\tprivate static mergeFields(left: AnyNode, right: AnyNode): AnyNode {\n\t\tif (left.constructor !== right.constructor) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)\n\t\t}\n\t\tif (left.name !== right.name) {\n\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)\n\t\t}\n\t\tif (left instanceof ObjectNode && right instanceof ObjectNode) {\n\t\t\tif (!isDeepStrictEqual(left.args, right.args)) {\n\t\t\t\tthrow new Error(`GraphQlQueryAstFactory: incompatible args`)\n\t\t\t}\n\t\t\tconst fields = GraphQlQueryAstFactory.mergeFieldList([...left.fields, ...right.fields])\n\t\t\treturn new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)\n\t\t}\n\t\treturn left\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAsBO,MAAM,uBAAuB;AAAA,EAC5B,OAAmB,MAA0B,QAAuC;AAC1F,UAAM,OAAO,iBAAiB,iBAAiB,IAAI;AACnD,UAAM,aAAa,KAAK;AAExB,WAAO,KAAK,eAAe,MAAM,YAAiC,MAAM,IAAI,WAAW,MAAM,KAAK;AAAA,EACnG;AAAA,EAEQ,eACP,MACA,YACA,MACA,MACA,QACgC;AAChC,QAAI,CAAC,OAAO,MAAM,IAAI,GAAG;AACxB,aAAO;AAAA,IACR;AACA,UAAM,OAAO,KAAK,KAAK;AACvB,UAAM,QAAQ,KAAK,QAAQ,KAAK,MAAM,QAAQ;AAC9C,QAAI,CAAC,KAAK,cAAc;AACvB,aAAO,IAAI,UAAU,MAAM,OAAO,CAAA,CAAE;AAAA,IACrC;AACA,UAAM,QAAQ,WAAW,UAAA,EAAY,IAAI;AACzC,UAAM,OAAO,MAAM;AACnB,UAAM,eAAe,uBAAuB,kBAAkB,IAAI;AAElE,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QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,IAC3F;AACA,WAAO;AAAA,EACR;AACD;"}
@@ -18,29 +18,27 @@ require("../extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.cjs");
18
18
  require("graphql");
19
19
  require("../schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs");
20
20
  require("@contember/graphql-utils");
21
+ const ValidationResolver = require("./ValidationResolver.cjs");
22
+ const ReadHelpers = require("./ReadHelpers.cjs");
21
23
  const OperationExtension = require("../schema/OperationExtension.cjs");
22
24
  require("../extensions/paginatedHasMany/PaginatedHasManyFieldProvider.cjs");
23
25
  require("@contember/dic");
24
26
  require("../mapper/select/optimizer/WhereOptimizer.cjs");
25
- const GraphQlQueryAstFactory = require("./GraphQlQueryAstFactory.cjs");
26
- const ValidationResolver = require("./ValidationResolver.cjs");
27
- const ReadHelpers = require("./ReadHelpers.cjs");
27
+ require("node:util");
28
28
  require("@contember/schema-definition");
29
29
  require("../input-validation/ValidationContext.cjs");
30
30
  require("../input-validation/ValidationEvaluation.cjs");
31
+ const transactionQueryAstFilter = (node, path) => path.length === 1 && !["ok", "validation", "errorMessage", "errors"].includes(node.name.value) || path.length === 2 && node.name.value === "node" || path.length > 2 || path.length === 0 || path.length > 1 && path[1] === "query";
32
+ const mutationResultQueryAstFilter = (node, path) => path.length !== 1 || node.name.value === "node";
31
33
  class MutationResolver {
32
- constructor(schema2, mapperFactory, inputValidator, graphqlQueryAstFactory, schemaDatabaseMetadata) {
34
+ constructor(schema2, mapperFactory, inputValidator, schemaDatabaseMetadata) {
33
35
  this.schema = schema2;
34
36
  this.mapperFactory = mapperFactory;
35
37
  this.inputValidator = inputValidator;
36
- this.graphqlQueryAstFactory = graphqlQueryAstFactory;
37
38
  this.schemaDatabaseMetadata = schemaDatabaseMetadata;
38
39
  }
39
- async resolveTransaction(info, options) {
40
- const queryAst = this.graphqlQueryAstFactory.create(info, (node, path) => {
41
- return path.length === 1 && !["ok", "validation", "errorMessage", "errors"].includes(node.name.value) || path.length === 2 && node.name.value === "node" || path.length > 2 || path.length === 0 || path.length > 1 && path[1] === "query";
42
- });
43
- const fields = GraphQlQueryAstFactory.GraphQlQueryAstFactory.resolveObjectType(info.returnType).getFields();
40
+ /** `queryAst` must be created with `transactionQueryAstFilter`. */
41
+ async resolveTransaction(queryAst, options) {
44
42
  const mutationFields = queryAst.fields.filter((field) => field.name !== "query" && field.name !== "__typename");
45
43
  const prefixErrors = (errors, field) => errors.map((it) => ({
46
44
  ...it,
@@ -65,11 +63,7 @@ class MutationResolver {
65
63
  if (!(field instanceof ObjectNode.ObjectNode)) {
66
64
  throw new exception.ImplementationException();
67
65
  }
68
- const fieldConfig = fields[field.name];
69
- if (!fieldConfig) {
70
- throw new exception.ImplementationException();
71
- }
72
- const meta = OperationExtension.readOperationMeta(fieldConfig.extensions);
66
+ const meta = OperationExtension.readOperationMeta(field.extensions);
73
67
  const result = await (() => {
74
68
  switch (meta.operation) {
75
69
  case OperationExtension.Operation.create:
@@ -121,19 +115,11 @@ class MutationResolver {
121
115
  if (!(field instanceof ObjectNode.ObjectNode)) {
122
116
  throw new exception.ImplementationException();
123
117
  }
124
- const fieldConfig = fields[field.name];
125
- if (!fieldConfig) {
126
- throw new exception.ImplementationException();
127
- }
128
118
  if (field.name === "query") {
129
- trxResult[field.alias] = await ReadHelpers.executeReadOperations(
130
- field,
131
- GraphQlQueryAstFactory.GraphQlQueryAstFactory.resolveObjectType(fieldConfig.type).getFields(),
132
- mapper
133
- );
119
+ trxResult[field.alias] = await ReadHelpers.executeReadOperations(field, mapper);
134
120
  continue;
135
121
  }
136
- const meta = OperationExtension.readOperationMeta(fieldConfig.extensions);
122
+ const meta = OperationExtension.readOperationMeta(field.extensions);
137
123
  logger.logger.debug("MutationResolver: Resolving a field", { field: field.alias });
138
124
  const result = await (() => {
139
125
  switch (meta.operation) {
@@ -187,8 +173,7 @@ class MutationResolver {
187
173
  ...Object.fromEntries(mutationFields.map((field) => [field.alias, { ...failure, node: null }]))
188
174
  }));
189
175
  }
190
- async resolveUpdate(entity, info) {
191
- const queryAst = this.createQueryAst(info);
176
+ async resolveUpdate(entity, queryAst) {
192
177
  return this.transaction(async (mapper) => {
193
178
  const validation = await this.validateUpdate(mapper, entity, queryAst);
194
179
  if (validation !== null) {
@@ -229,8 +214,7 @@ class MutationResolver {
229
214
  ...nodes
230
215
  };
231
216
  }
232
- async resolveCreate(entity, info) {
233
- const queryAst = this.createQueryAst(info);
217
+ async resolveCreate(entity, queryAst) {
234
218
  return this.transaction(async (mapper) => {
235
219
  const validation = await this.validateCreate(mapper, entity, queryAst);
236
220
  if (validation !== null) {
@@ -275,8 +259,7 @@ class MutationResolver {
275
259
  ...nodes
276
260
  };
277
261
  }
278
- async resolveUpsert(entity, info) {
279
- const queryAst = this.createQueryAst(info);
262
+ async resolveUpsert(entity, queryAst) {
280
263
  return this.transaction(async (mapper) => {
281
264
  const validation = await this.validateUpsert(mapper, entity, queryAst);
282
265
  if (validation !== null) {
@@ -336,8 +319,7 @@ class MutationResolver {
336
319
  ...nodes
337
320
  };
338
321
  }
339
- async resolveDelete(entity, info) {
340
- const queryAst = this.createQueryAst(info);
322
+ async resolveDelete(entity, queryAst) {
341
323
  return this.transaction(async (mapper) => {
342
324
  return await this.resolveDeleteInternal(mapper, entity, queryAst);
343
325
  });
@@ -353,12 +335,6 @@ class MutationResolver {
353
335
  return { ok: false, errors, errorMessage: this.stringifyExecutionErrors(errors) };
354
336
  }
355
337
  }
356
- createQueryAst(info) {
357
- const queryAst = this.graphqlQueryAstFactory.create(info, (node, path) => {
358
- return path.length !== 1 || node.name.value === "node";
359
- });
360
- return queryAst;
361
- }
362
338
  async resolveResultNodes(mapper, entity, where, queryAst) {
363
339
  const nodeQuery = queryAst.findFieldByName("node");
364
340
  let nodes = {};
@@ -524,4 +500,6 @@ class MutationResolver {
524
500
  }
525
501
  }
526
502
  exports.MutationResolver = MutationResolver;
503
+ exports.mutationResultQueryAstFilter = mutationResultQueryAstFilter;
504
+ exports.transactionQueryAstFilter = transactionQueryAstFilter;
527
505
  //# sourceMappingURL=MutationResolver.cjs.map