@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
@@ -0,0 +1,256 @@
1
+ import { Acl, Model, Input } from "@contember/schema";
2
+ import { getEntity, acceptFieldVisitor } from "@contember/schema-utils";
3
+ import { GqlTypeName, inputFieldDescription } from "../schema/utils.js";
4
+ import "graphql";
5
+ import { CreateEntityRelationAllowedOperationsVisitor } from "../schema/mutations/CreateEntityRelationAllowedOperationsVisitor.js";
6
+ import { ImplementationException } from "../exception.js";
7
+ import { EntityInputType } from "../schema/mutations/EntityInputProvider.js";
8
+ import { UpdateEntityRelationAllowedOperationsVisitor } from "../schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.js";
9
+ import "../schema/mutations/UpdateEntityRelationInputFieldVisitor.js";
10
+ import { namedRef, inputField, listOfNonNullRef, nonNullRef } from "./JsonTypeRegistry.js";
11
+ var __defProp = Object.defineProperty;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
+ class JsonInputTypes {
15
+ constructor(schema, authorizator, registry, columnTypes, filterTypes) {
16
+ this.schema = schema;
17
+ this.authorizator = authorizator;
18
+ this.registry = registry;
19
+ this.columnTypes = columnTypes;
20
+ this.filterTypes = filterTypes;
21
+ __publicField(this, "createAllowedOperationsVisitor");
22
+ __publicField(this, "updateAllowedOperationsVisitor");
23
+ __publicField(this, "inputs", /* @__PURE__ */ new Map());
24
+ __publicField(this, "relationInputs", /* @__PURE__ */ new Map());
25
+ this.createAllowedOperationsVisitor = new CreateEntityRelationAllowedOperationsVisitor(authorizator);
26
+ this.updateAllowedOperationsVisitor = new UpdateEntityRelationAllowedOperationsVisitor(authorizator);
27
+ }
28
+ getInput(operation, entityName, withoutRelation) {
29
+ const key = `${operation}\0${entityName}\0${withoutRelation ?? ""}`;
30
+ if (this.inputs.has(key)) {
31
+ return this.inputs.get(key);
32
+ }
33
+ const input = this.createInput(operation, entityName, withoutRelation);
34
+ this.inputs.set(key, input);
35
+ return input;
36
+ }
37
+ createInput(operation, entityName, withoutRelation) {
38
+ const entity = getEntity(this.schema, entityName);
39
+ if (entity.view) {
40
+ return void 0;
41
+ }
42
+ const aclOperation = operation === EntityInputType.create ? Acl.Operation.create : Acl.Operation.update;
43
+ if (this.authorizator.getEntityPermission(aclOperation, entity.name) === "no") {
44
+ return void 0;
45
+ }
46
+ const withoutSuffix = withoutRelation ? GqlTypeName`Without${withoutRelation}` : "";
47
+ const name = GqlTypeName`${entityName}${withoutSuffix}${operation}Input`;
48
+ return this.registry.inputObject(name, () => {
49
+ const fields = {};
50
+ for (const fieldName of Object.keys(entity.fields)) {
51
+ if (fieldName === withoutRelation) {
52
+ continue;
53
+ }
54
+ const field = operation === EntityInputType.create ? this.getCreateField(entity, fieldName) : this.getUpdateField(entity, fieldName);
55
+ if (field !== void 0) {
56
+ fields[fieldName] = field;
57
+ }
58
+ }
59
+ fields["_dummy_field_"] = [namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool))];
60
+ return fields;
61
+ });
62
+ }
63
+ getCreateField(entity, fieldName) {
64
+ return acceptFieldVisitor(this.schema, entity, fieldName, {
65
+ visitColumn: ({ column }) => {
66
+ if (entity.primary === column.name && !this.authorizator.isCustomPrimaryAllowed(entity.name)) {
67
+ return void 0;
68
+ }
69
+ if (this.authorizator.getFieldPermissions(Acl.Operation.create, entity.name, column.name) === "no") {
70
+ return void 0;
71
+ }
72
+ return inputField(this.columnTypes.getType(column).type, inputFieldDescription(column));
73
+ },
74
+ visitHasOne: (context) => {
75
+ const type = this.memoizeRelationInput("create", context, () => this.getCreateRelationInput(context, false));
76
+ return type === void 0 ? void 0 : inputField(namedRef(type), inputFieldDescription(context.relation));
77
+ },
78
+ visitHasMany: (context) => {
79
+ const type = this.memoizeRelationInput("create", context, () => this.getCreateRelationInput(context, true));
80
+ return type === void 0 ? void 0 : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation));
81
+ }
82
+ });
83
+ }
84
+ getUpdateField(entity, fieldName) {
85
+ return acceptFieldVisitor(this.schema, entity, fieldName, {
86
+ visitColumn: ({ column }) => {
87
+ if (entity.primary === column.name) {
88
+ return void 0;
89
+ }
90
+ if (this.authorizator.getFieldPermissions(Acl.Operation.update, entity.name, column.name) === "no") {
91
+ return void 0;
92
+ }
93
+ return inputField(this.columnTypes.getType(column).type, inputFieldDescription(column));
94
+ },
95
+ visitHasOne: (context) => {
96
+ const type = this.memoizeRelationInput("update", context, () => this.getUpdateHasOneRelationInput(context));
97
+ return type === void 0 ? void 0 : inputField(namedRef(type), inputFieldDescription(context.relation));
98
+ },
99
+ visitHasMany: (context) => {
100
+ const type = this.memoizeRelationInput("update", context, () => this.getUpdateHasManyRelationInput(context));
101
+ return type === void 0 ? void 0 : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation));
102
+ }
103
+ });
104
+ }
105
+ memoizeRelationInput(operation, { entity, relation }, create) {
106
+ const key = `${operation}\0${entity.name}\0${relation.name}`;
107
+ if (this.relationInputs.has(key)) {
108
+ return this.relationInputs.get(key);
109
+ }
110
+ const input = create();
111
+ this.relationInputs.set(key, input);
112
+ return input;
113
+ }
114
+ getCreateRelationInput({ entity, relation, targetEntity, targetRelation }, withAliasField) {
115
+ const allowedOperations = acceptFieldVisitor(this.schema, entity, relation.name, this.createAllowedOperationsVisitor);
116
+ const fields = {};
117
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name);
118
+ if (allowedOperations.includes(Input.CreateRelationOperation.connect) && uniqueWhere) {
119
+ fields[Input.CreateRelationOperation.connect] = [namedRef(uniqueWhere)];
120
+ }
121
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name);
122
+ if (allowedOperations.includes(Input.CreateRelationOperation.create) && createInput !== void 0) {
123
+ fields[Input.CreateRelationOperation.create] = [namedRef(createInput)];
124
+ }
125
+ if (allowedOperations.includes(Input.CreateRelationOperation.connectOrCreate) && uniqueWhere !== void 0 && createInput !== void 0) {
126
+ fields[Input.CreateRelationOperation.connectOrCreate] = [namedRef(this.getConnectOrCreateInput(entity, relation.name))];
127
+ }
128
+ if (Object.keys(fields).length === 0) {
129
+ return void 0;
130
+ }
131
+ if (withAliasField) {
132
+ fields.alias = [namedRef(this.columnTypes.getScalar(Model.ColumnType.String))];
133
+ }
134
+ return this.registry.inputObject(GqlTypeName`${entity.name}Create${relation.name}EntityRelationInput`, () => fields);
135
+ }
136
+ getUpdateHasOneRelationInput({ targetRelation, targetEntity, relation, entity }) {
137
+ const withoutRelation = targetRelation ? targetRelation.name : void 0;
138
+ const whereInput = this.getUniqueWhereInput(targetEntity);
139
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation);
140
+ const updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation);
141
+ const boolean = namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool));
142
+ const fields = this.filterAllowedOperations(entity, relation, {
143
+ [Input.UpdateRelationOperation.connect]: whereInput ? [namedRef(whereInput)] : void 0,
144
+ [Input.UpdateRelationOperation.create]: createInput ? [namedRef(createInput)] : void 0,
145
+ [Input.UpdateRelationOperation.connectOrCreate]: createInput && whereInput ? [namedRef(this.getConnectOrCreateInput(entity, relation.name))] : void 0,
146
+ [Input.UpdateRelationOperation.update]: updateInput ? [namedRef(updateInput)] : void 0,
147
+ [Input.UpdateRelationOperation.upsert]: updateInput && createInput ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({
148
+ update: [nonNullRef(updateInput)],
149
+ create: [nonNullRef(createInput)]
150
+ })))] : void 0,
151
+ [Input.UpdateRelationOperation.disconnect]: [boolean],
152
+ [Input.UpdateRelationOperation.delete]: [boolean]
153
+ });
154
+ if (Object.keys(fields).length === 0) {
155
+ return void 0;
156
+ }
157
+ return this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields);
158
+ }
159
+ getUpdateHasManyRelationInput({ entity, relation, targetEntity, targetRelation }) {
160
+ const withoutRelation = targetRelation ? targetRelation.name : void 0;
161
+ const whereInput = this.getUniqueWhereInput(targetEntity);
162
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation);
163
+ const updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation);
164
+ const create = createInput ? [namedRef(createInput)] : void 0;
165
+ const update = updateInput && whereInput ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}RelationInput`, () => ({
166
+ by: [nonNullRef(whereInput)],
167
+ data: [nonNullRef(updateInput)]
168
+ })))] : void 0;
169
+ const upsert = updateInput && createInput && whereInput ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({
170
+ by: [nonNullRef(whereInput)],
171
+ update: [nonNullRef(updateInput)],
172
+ create: [nonNullRef(createInput)]
173
+ })))] : void 0;
174
+ const connect = whereInput ? [namedRef(whereInput)] : void 0;
175
+ const connectOrCreate = createInput && whereInput ? [namedRef(this.getConnectOrCreateInput(entity, relation.name))] : void 0;
176
+ const fields = this.filterAllowedOperations(entity, relation, {
177
+ [Input.UpdateRelationOperation.create]: create,
178
+ [Input.UpdateRelationOperation.update]: update,
179
+ [Input.UpdateRelationOperation.upsert]: upsert,
180
+ [Input.UpdateRelationOperation.connect]: connect,
181
+ [Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,
182
+ [Input.UpdateRelationOperation.disconnect]: connect,
183
+ [Input.UpdateRelationOperation.delete]: connect
184
+ });
185
+ if (Object.keys(fields).length === 0) {
186
+ return void 0;
187
+ }
188
+ const string = namedRef(this.columnTypes.getScalar(Model.ColumnType.String));
189
+ const setItemFields = this.filterAllowedOperations(entity, relation, {
190
+ [Input.UpdateRelationOperation.create]: create,
191
+ [Input.UpdateRelationOperation.connect]: connect,
192
+ [Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,
193
+ [Input.UpdateRelationOperation.update]: update,
194
+ [Input.UpdateRelationOperation.upsert]: upsert
195
+ });
196
+ const canReadTarget = this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) !== "no";
197
+ if (canReadTarget && Object.keys(setItemFields).length > 0) {
198
+ const setItem = this.registry.inputObject(GqlTypeName`${entity.name}Set${relation.name}ItemRelationInput`, () => ({
199
+ ...setItemFields,
200
+ alias: [string]
201
+ }));
202
+ fields[Input.UpdateRelationOperation.set] = [listOfNonNullRef(setItem)];
203
+ if (this.getAllowedOperations(entity, relation).includes(Input.UpdateRelationOperation.delete)) {
204
+ const strategies = [Input.OrphanRemovalStrategy.disconnect, Input.OrphanRemovalStrategy.delete];
205
+ fields.orphanStrategy = [namedRef(this.registry.enum("OrphanRemovalStrategy", strategies))];
206
+ }
207
+ }
208
+ fields.alias = [string];
209
+ return this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields);
210
+ }
211
+ getConnectOrCreateInput(entity, relationName) {
212
+ return acceptFieldVisitor(this.schema, entity, relationName, {
213
+ visitColumn: () => {
214
+ throw new ImplementationException();
215
+ },
216
+ visitRelation: ({ targetEntity, targetRelation, relation }) => {
217
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name);
218
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name);
219
+ if (!uniqueWhere || !createInput) {
220
+ throw new ImplementationException();
221
+ }
222
+ return this.registry.inputObject(GqlTypeName`${entity.name}ConnectOrCreate${relation.name}RelationInput`, () => ({
223
+ connect: [nonNullRef(uniqueWhere)],
224
+ create: [nonNullRef(createInput)]
225
+ }));
226
+ }
227
+ });
228
+ }
229
+ getUniqueWhereInput(targetEntity) {
230
+ if (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === "no") {
231
+ return void 0;
232
+ }
233
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name);
234
+ if (!uniqueWhere) {
235
+ throw new ImplementationException();
236
+ }
237
+ return uniqueWhere;
238
+ }
239
+ getAllowedOperations(entity, relation) {
240
+ return acceptFieldVisitor(this.schema, entity, relation.name, this.updateAllowedOperationsVisitor);
241
+ }
242
+ filterAllowedOperations(entity, relation, fields) {
243
+ const allowedOperations = this.getAllowedOperations(entity, relation);
244
+ const result = {};
245
+ for (const [key, value] of Object.entries(fields)) {
246
+ if (value !== void 0 && allowedOperations.includes(key)) {
247
+ result[key] = value;
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+ }
253
+ export {
254
+ JsonInputTypes
255
+ };
256
+ //# sourceMappingURL=JsonInputTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonInputTypes.js","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonInputTypes.ts"],"sourcesContent":["import { Acl, Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getEntity } from '@contember/schema-utils'\nimport { InputField } from '@contember/graphql-json'\nimport { Authorizator } from '../acl/index.js'\nimport { GqlTypeName, inputFieldDescription } from '../schema/utils.js'\nimport {\n\tCreateEntityRelationAllowedOperationsVisitor,\n\tEntityInputType,\n\tUpdateEntityRelationAllowedOperationsVisitor,\n} from '../schema/mutations/index.js'\nimport { ImplementationException } from '../exception.js'\nimport { JsonColumnTypes } from './JsonColumnTypes.js'\nimport { JsonFilterTypes } from './JsonFilterTypes.js'\nimport { inputField, JsonTypeRegistry, listOfNonNullRef, namedRef, nonNullRef } from './JsonTypeRegistry.js'\n\n/** JSON counterpart of `EntityInputProvider` and the create/update input visitors in `schema/mutations`. */\nexport class JsonInputTypes {\n\tprivate readonly createAllowedOperationsVisitor: CreateEntityRelationAllowedOperationsVisitor\n\tprivate readonly updateAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor\n\t/**\n\t * Inputs by their arguments. Every `Without<relation>` variant of an input asks again for the relation inputs of\n\t * its fields, and every relation input for the inputs of its target; on real models that repeated work dominated.\n\t */\n\tprivate readonly inputs = new Map<string, string | undefined>()\n\tprivate readonly relationInputs = new Map<string, string | undefined>()\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly registry: JsonTypeRegistry,\n\t\tprivate readonly columnTypes: JsonColumnTypes,\n\t\tprivate readonly filterTypes: JsonFilterTypes,\n\t) {\n\t\tthis.createAllowedOperationsVisitor = new CreateEntityRelationAllowedOperationsVisitor(authorizator)\n\t\tthis.updateAllowedOperationsVisitor = new UpdateEntityRelationAllowedOperationsVisitor(authorizator)\n\t}\n\n\tpublic getInput(operation: EntityInputType, entityName: string, withoutRelation?: string): string | undefined {\n\t\tconst key = `${operation}\\0${entityName}\\0${withoutRelation ?? ''}`\n\t\tif (this.inputs.has(key)) {\n\t\t\treturn this.inputs.get(key)\n\t\t}\n\t\tconst input = this.createInput(operation, entityName, withoutRelation)\n\t\tthis.inputs.set(key, input)\n\t\treturn input\n\t}\n\n\tprivate createInput(operation: EntityInputType, entityName: string, withoutRelation: string | undefined): string | undefined {\n\t\tconst entity = getEntity(this.schema, entityName)\n\t\tif (entity.view) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst aclOperation = operation === EntityInputType.create ? Acl.Operation.create : Acl.Operation.update\n\t\tif (this.authorizator.getEntityPermission(aclOperation, entity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst withoutSuffix = withoutRelation ? GqlTypeName`Without${withoutRelation}` : ''\n\t\tconst name = GqlTypeName`${entityName}${withoutSuffix}${operation}Input`\n\t\treturn this.registry.inputObject(name, () => {\n\t\t\tconst fields: Record<string, InputField> = {}\n\t\t\tfor (const fieldName of Object.keys(entity.fields)) {\n\t\t\t\tif (fieldName === withoutRelation) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst field = operation === EntityInputType.create\n\t\t\t\t\t? this.getCreateField(entity, fieldName)\n\t\t\t\t\t: this.getUpdateField(entity, fieldName)\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\tfields[fieldName] = field\n\t\t\t\t}\n\t\t\t}\n\t\t\tfields['_dummy_field_'] = [namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool))]\n\t\t\treturn fields\n\t\t})\n\t}\n\n\tprivate getCreateField(entity: Model.Entity, fieldName: string): InputField | undefined {\n\t\treturn acceptFieldVisitor<InputField | undefined>(this.schema, entity, fieldName, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\tif (entity.primary === column.name && !this.authorizator.isCustomPrimaryAllowed(entity.name)) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif (this.authorizator.getFieldPermissions(Acl.Operation.create, entity.name, column.name) === 'no') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn inputField(this.columnTypes.getType(column).type, inputFieldDescription(column))\n\t\t\t},\n\t\t\tvisitHasOne: context => {\n\t\t\t\tconst type = this.memoizeRelationInput('create', context, () => this.getCreateRelationInput(context, false))\n\t\t\t\treturn type === undefined ? undefined : inputField(namedRef(type), inputFieldDescription(context.relation))\n\t\t\t},\n\t\t\tvisitHasMany: context => {\n\t\t\t\tconst type = this.memoizeRelationInput('create', context, () => this.getCreateRelationInput(context, true))\n\t\t\t\treturn type === undefined ? undefined : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation))\n\t\t\t},\n\t\t})\n\t}\n\n\tprivate getUpdateField(entity: Model.Entity, fieldName: string): InputField | undefined {\n\t\treturn acceptFieldVisitor<InputField | undefined>(this.schema, entity, fieldName, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\tif (entity.primary === column.name) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif (this.authorizator.getFieldPermissions(Acl.Operation.update, entity.name, column.name) === 'no') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn inputField(this.columnTypes.getType(column).type, inputFieldDescription(column))\n\t\t\t},\n\t\t\tvisitHasOne: context => {\n\t\t\t\tconst type = this.memoizeRelationInput('update', context, () => this.getUpdateHasOneRelationInput(context))\n\t\t\t\treturn type === undefined ? undefined : inputField(namedRef(type), inputFieldDescription(context.relation))\n\t\t\t},\n\t\t\tvisitHasMany: context => {\n\t\t\t\tconst type = this.memoizeRelationInput('update', context, () => this.getUpdateHasManyRelationInput(context))\n\t\t\t\treturn type === undefined ? undefined : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation))\n\t\t\t},\n\t\t})\n\t}\n\n\tprivate memoizeRelationInput(\n\t\toperation: 'create' | 'update',\n\t\t{ entity, relation }: Model.AnyRelationContext,\n\t\tcreate: () => string | undefined,\n\t): string | undefined {\n\t\tconst key = `${operation}\\0${entity.name}\\0${relation.name}`\n\t\tif (this.relationInputs.has(key)) {\n\t\t\treturn this.relationInputs.get(key)\n\t\t}\n\t\tconst input = create()\n\t\tthis.relationInputs.set(key, input)\n\t\treturn input\n\t}\n\n\tprivate getCreateRelationInput(\n\t\t{ entity, relation, targetEntity, targetRelation }: Model.AnyRelationContext,\n\t\twithAliasField: boolean,\n\t): string | undefined {\n\t\tconst allowedOperations = acceptFieldVisitor(this.schema, entity, relation.name, this.createAllowedOperationsVisitor)\n\t\tconst fields: Record<string, InputField> = {}\n\n\t\tconst uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (allowedOperations.includes(Input.CreateRelationOperation.connect) && uniqueWhere) {\n\t\t\tfields[Input.CreateRelationOperation.connect] = [namedRef(uniqueWhere)]\n\t\t}\n\t\tconst createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name)\n\t\tif (allowedOperations.includes(Input.CreateRelationOperation.create) && createInput !== undefined) {\n\t\t\tfields[Input.CreateRelationOperation.create] = [namedRef(createInput)]\n\t\t}\n\t\tif (allowedOperations.includes(Input.CreateRelationOperation.connectOrCreate) && uniqueWhere !== undefined && createInput !== undefined) {\n\t\t\tfields[Input.CreateRelationOperation.connectOrCreate] = [namedRef(this.getConnectOrCreateInput(entity, relation.name))]\n\t\t}\n\t\tif (Object.keys(fields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (withAliasField) {\n\t\t\tfields.alias = [namedRef(this.columnTypes.getScalar(Model.ColumnType.String))]\n\t\t}\n\t\treturn this.registry.inputObject(GqlTypeName`${entity.name}Create${relation.name}EntityRelationInput`, () => fields)\n\t}\n\n\tprivate getUpdateHasOneRelationInput({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext): string | undefined {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\t\tconst whereInput = this.getUniqueWhereInput(targetEntity)\n\t\tconst createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation)\n\t\tconst updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation)\n\t\tconst boolean = namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool))\n\n\t\tconst fields = this.filterAllowedOperations(entity, relation, {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput ? [namedRef(whereInput)] : undefined,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput ? [namedRef(createInput)] : undefined,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: createInput && whereInput\n\t\t\t\t? [namedRef(this.getConnectOrCreateInput(entity, relation.name))]\n\t\t\t\t: undefined,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput ? [namedRef(updateInput)] : undefined,\n\t\t\t[Input.UpdateRelationOperation.upsert]: updateInput && createInput\n\t\t\t\t? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({\n\t\t\t\t\tupdate: [nonNullRef(updateInput)],\n\t\t\t\t\tcreate: [nonNullRef(createInput)],\n\t\t\t\t})))]\n\t\t\t\t: undefined,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: [boolean],\n\t\t\t[Input.UpdateRelationOperation.delete]: [boolean],\n\t\t})\n\t\tif (Object.keys(fields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields)\n\t}\n\n\tprivate getUpdateHasManyRelationInput({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext): string | undefined {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\t\tconst whereInput = this.getUniqueWhereInput(targetEntity)\n\t\tconst createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation)\n\t\tconst updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation)\n\n\t\tconst create: InputField | undefined = createInput ? [namedRef(createInput)] : undefined\n\t\tconst update: InputField | undefined = updateInput && whereInput\n\t\t\t? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}RelationInput`, () => ({\n\t\t\t\tby: [nonNullRef(whereInput)],\n\t\t\t\tdata: [nonNullRef(updateInput)],\n\t\t\t})))]\n\t\t\t: undefined\n\t\tconst upsert: InputField | undefined = updateInput && createInput && whereInput\n\t\t\t? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({\n\t\t\t\tby: [nonNullRef(whereInput)],\n\t\t\t\tupdate: [nonNullRef(updateInput)],\n\t\t\t\tcreate: [nonNullRef(createInput)],\n\t\t\t})))]\n\t\t\t: undefined\n\t\tconst connect: InputField | undefined = whereInput ? [namedRef(whereInput)] : undefined\n\t\tconst connectOrCreate: InputField | undefined = createInput && whereInput\n\t\t\t? [namedRef(this.getConnectOrCreateInput(entity, relation.name))]\n\t\t\t: undefined\n\n\t\tconst fields = this.filterAllowedOperations(entity, relation, {\n\t\t\t[Input.UpdateRelationOperation.create]: create,\n\t\t\t[Input.UpdateRelationOperation.update]: update,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsert,\n\t\t\t[Input.UpdateRelationOperation.connect]: connect,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: connect,\n\t\t\t[Input.UpdateRelationOperation.delete]: connect,\n\t\t})\n\t\tif (Object.keys(fields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst string = namedRef(this.columnTypes.getScalar(Model.ColumnType.String))\n\n\t\t// `set` replaces the whole collection with the positive operations; orphans are removed via `orphanStrategy`.\n\t\tconst setItemFields = this.filterAllowedOperations(entity, relation, {\n\t\t\t[Input.UpdateRelationOperation.create]: create,\n\t\t\t[Input.UpdateRelationOperation.connect]: connect,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,\n\t\t\t[Input.UpdateRelationOperation.update]: update,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsert,\n\t\t})\n\t\t// Orphans are found by diffing the current members read through the target's read predicate, so a role that\n\t\t// cannot read the target would see an empty collection and `set` could only add: it is not offered at all.\n\t\tconst canReadTarget = this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) !== 'no'\n\t\tif (canReadTarget && Object.keys(setItemFields).length > 0) {\n\t\t\tconst setItem = this.registry.inputObject(GqlTypeName`${entity.name}Set${relation.name}ItemRelationInput`, () => ({\n\t\t\t\t...setItemFields,\n\t\t\t\talias: [string],\n\t\t\t}))\n\t\t\tfields[Input.UpdateRelationOperation.set] = [listOfNonNullRef(setItem)]\n\t\t\t// only offered when the role may delete the target, `disconnect` is the default\n\t\t\tif (this.getAllowedOperations(entity, relation).includes(Input.UpdateRelationOperation.delete)) {\n\t\t\t\tconst strategies = [Input.OrphanRemovalStrategy.disconnect, Input.OrphanRemovalStrategy.delete]\n\t\t\t\tfields.orphanStrategy = [namedRef(this.registry.enum('OrphanRemovalStrategy', strategies))]\n\t\t\t}\n\t\t}\n\t\tfields.alias = [string]\n\t\treturn this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields)\n\t}\n\n\tprivate getConnectOrCreateInput(entity: Model.Entity, relationName: string): string {\n\t\treturn acceptFieldVisitor<string>(this.schema, entity, relationName, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tthrow new ImplementationException()\n\t\t\t},\n\t\t\tvisitRelation: ({ targetEntity, targetRelation, relation }) => {\n\t\t\t\tconst uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)\n\t\t\t\tconst createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name)\n\t\t\t\tif (!uniqueWhere || !createInput) {\n\t\t\t\t\tthrow new ImplementationException()\n\t\t\t\t}\n\t\t\t\treturn this.registry.inputObject(GqlTypeName`${entity.name}ConnectOrCreate${relation.name}RelationInput`, () => ({\n\t\t\t\t\tconnect: [nonNullRef(uniqueWhere)],\n\t\t\t\t\tcreate: [nonNullRef(createInput)],\n\t\t\t\t}))\n\t\t\t},\n\t\t})\n\t}\n\n\tprivate getUniqueWhereInput(targetEntity: Model.Entity): string | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n\n\tprivate getAllowedOperations(entity: Model.Entity, relation: Model.Relation): readonly Input.UpdateRelationOperation[] {\n\t\treturn acceptFieldVisitor(this.schema, entity, relation.name, this.updateAllowedOperationsVisitor)\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tfields: Record<string, InputField | undefined>,\n\t): Record<string, InputField> {\n\t\tconst allowedOperations: readonly string[] = this.getAllowedOperations(entity, relation)\n\t\tconst result: Record<string, InputField> = {}\n\t\tfor (const [key, value] of Object.entries(fields)) {\n\t\t\tif (value !== undefined && allowedOperations.includes(key)) {\n\t\t\t\tresult[key] = value\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgBO,MAAM,eAAe;AAAA,EAU3B,YACkB,QACA,cACA,UACA,aACA,aAChB;AALgB,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAdlB,kBAAA,MAAiB,gCAAA;AACjB,kBAAA,MAAiB,gCAAA;AAKjB,kBAAA,MAAiB,8BAAa,IAAA,CAAgC;AAC9D,kBAAA,MAAiB,sCAAqB,IAAA,CAAgC;AASrE,SAAK,iCAAiC,IAAI,6CAA6C,YAAY;AACnG,SAAK,iCAAiC,IAAI,6CAA6C,YAAY;AAAA,EACpG;AAAA,EAEO,SAAS,WAA4B,YAAoB,iBAA8C;AAC7G,UAAM,MAAM,GAAG,SAAS,KAAK,UAAU,KAAK,mBAAmB,EAAE;AACjE,QAAI,KAAK,OAAO,IAAI,GAAG,GAAG;AACzB,aAAO,KAAK,OAAO,IAAI,GAAG;AAAA,IAC3B;AACA,UAAM,QAAQ,KAAK,YAAY,WAAW,YAAY,eAAe;AACrE,SAAK,OAAO,IAAI,KAAK,KAAK;AAC1B,WAAO;AAAA,EACR;AAAA,EAEQ,YAAY,WAA4B,YAAoB,iBAAyD;AAC5H,UAAM,SAAS,UAAU,KAAK,QAAQ,UAAU;AAChD,QAAI,OAAO,MAAM;AAChB,aAAO;AAAA,IACR;AACA,UAAM,eAAe,cAAc,gBAAgB,SAAS,IAAI,UAAU,SAAS,IAAI,UAAU;AACjG,QAAI,KAAK,aAAa,oBAAoB,cAAc,OAAO,IAAI,MAAM,MAAM;AAC9E,aAAO;AAAA,IACR;AACA,UAAM,gBAAgB,kBAAkB,qBAAqB,eAAe,KAAK;AACjF,UAAM,OAAO,cAAc,UAA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 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const graphql = require("graphql");
4
+ const graphqlJson = require("@contember/graphql-json");
5
+ const introspection_schema = require("../introspection/introspection.schema.cjs");
6
+ const GraphQLJsBridge = require("./GraphQLJsBridge.cjs");
7
+ let introspectionTypes;
8
+ const getIntrospectionTypes = () => {
9
+ introspectionTypes ?? (introspectionTypes = graphqlJson.buildSchema(graphql.printSchema(introspection_schema.default)));
10
+ return introspectionTypes;
11
+ };
12
+ const createJsonIntrospectionExtension = (introspectionSchemaFactory) => {
13
+ const { q: queryTypeName, t: allTypes } = getIntrospectionTypes();
14
+ const queryType = allTypes[queryTypeName];
15
+ if (!queryType || queryType[0] !== graphqlJson.TypeKind.OBJECT) {
16
+ throw new Error("Introspection schema has no query type");
17
+ }
18
+ const schemaField = queryType[1].schema;
19
+ if (!schemaField) {
20
+ throw new Error("Introspection schema has no schema field");
21
+ }
22
+ const types = Object.fromEntries(Object.entries(allTypes).filter(([name]) => name !== queryTypeName));
23
+ return {
24
+ types,
25
+ includedTypes: (introspection_schema.createSchemaConfig().types ?? []).map((it) => it.name),
26
+ scalars: GraphQLJsBridge.getCustomScalars(introspection_schema.default),
27
+ queries: {
28
+ schema: {
29
+ type: schemaField[0],
30
+ resolve: () => introspectionSchemaFactory.create()
31
+ }
32
+ }
33
+ };
34
+ };
35
+ exports.createJsonIntrospectionExtension = createJsonIntrospectionExtension;
36
+ //# sourceMappingURL=JsonIntrospectionExtension.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonIntrospectionExtension.cjs","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonIntrospectionExtension.ts"],"sourcesContent":["import { printSchema } from 'graphql'\nimport { buildSchema, Schema, TypeKind } from '@contember/graphql-json'\nimport introspectionSchema, { createSchemaConfig } from '../introspection/introspection.schema.js'\nimport { IntrospectionSchemaFactory } from '../introspection/index.js'\nimport { JsonSchemaExtension } from './JsonContentSchemaBuilder.js'\nimport { getCustomScalars } from './GraphQLJsBridge.js'\n\nlet introspectionTypes: Schema | undefined\nconst getIntrospectionTypes = (): Schema => {\n\tintrospectionTypes ??= buildSchema(printSchema(introspectionSchema))\n\treturn introspectionTypes\n}\n\n/** The `schema` query of the content API. Its types are static, so they are converted from graphql-js once. */\nexport const createJsonIntrospectionExtension = (introspectionSchemaFactory: IntrospectionSchemaFactory): JsonSchemaExtension => {\n\tconst { q: queryTypeName, t: allTypes } = getIntrospectionTypes()\n\tconst queryType = allTypes[queryTypeName]\n\tif (!queryType || queryType[0] !== TypeKind.OBJECT) {\n\t\tthrow new Error('Introspection schema has no query type')\n\t}\n\tconst schemaField = queryType[1].schema\n\tif (!schemaField) {\n\t\tthrow new Error('Introspection schema has no schema field')\n\t}\n\tconst types = Object.fromEntries(Object.entries(allTypes).filter(([name]) => name !== queryTypeName))\n\treturn {\n\t\ttypes,\n\t\tincludedTypes: (createSchemaConfig().types ?? []).map(it => it.name),\n\t\tscalars: getCustomScalars(introspectionSchema),\n\t\tqueries: {\n\t\t\tschema: {\n\t\t\t\ttype: schemaField[0],\n\t\t\t\tresolve: () => introspectionSchemaFactory.create(),\n\t\t\t},\n\t\t},\n\t}\n}\n"],"names":["buildSchema","printSchema","introspectionSchema","TypeKind","createSchemaConfig","getCustomScalars"],"mappings":";;;;;;AAOA,IAAI;AACJ,MAAM,wBAAwB,MAAc;AAC3C,yBAAA,qBAAuBA,YAAAA,YAAYC,QAAAA,YAAYC,qBAAAA,OAAmB,CAAC;AACnE,SAAO;AACR;AAGO,MAAM,mCAAmC,CAAC,+BAAgF;AAChI,QAAM,EAAE,GAAG,eAAe,GAAG,SAAA,IAAa,sBAAA;AAC1C,QAAM,YAAY,SAAS,aAAa;AACxC,MAAI,CAAC,aAAa,UAAU,CAAC,MAAMC,YAAAA,SAAS,QAAQ;AACnD,UAAM,IAAI,MAAM,wCAAwC;AAAA,EACzD;AACA,QAAM,cAAc,UAAU,CAAC,EAAE;AACjC,MAAI,CAAC,aAAa;AACjB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC3D;AACA,QAAM,QAAQ,OAAO,YAAY,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,MAAM,SAAS,aAAa,CAAC;AACpG,SAAO;AAAA,IACN;AAAA,IACA,gBAAgBC,0CAAqB,SAAS,CAAA,GAAI,IAAI,CAAA,OAAM,GAAG,IAAI;AAAA,IACnE,SAASC,gBAAAA,iBAAiBH,4BAAmB;AAAA,IAC7C,SAAS;AAAA,MACR,QAAQ;AAAA,QACP,MAAM,YAAY,CAAC;AAAA,QACnB,SAAS,MAAM,2BAA2B,OAAA;AAAA,MAAO;AAAA,IAClD;AAAA,EACD;AAEF;;"}
@@ -0,0 +1,36 @@
1
+ import { printSchema } from "graphql";
2
+ import { TypeKind, buildSchema } from "@contember/graphql-json";
3
+ import introspectionSchema, { createSchemaConfig } from "../introspection/introspection.schema.js";
4
+ import { getCustomScalars } from "./GraphQLJsBridge.js";
5
+ let introspectionTypes;
6
+ const getIntrospectionTypes = () => {
7
+ introspectionTypes ?? (introspectionTypes = buildSchema(printSchema(introspectionSchema)));
8
+ return introspectionTypes;
9
+ };
10
+ const createJsonIntrospectionExtension = (introspectionSchemaFactory) => {
11
+ const { q: queryTypeName, t: allTypes } = getIntrospectionTypes();
12
+ const queryType = allTypes[queryTypeName];
13
+ if (!queryType || queryType[0] !== TypeKind.OBJECT) {
14
+ throw new Error("Introspection schema has no query type");
15
+ }
16
+ const schemaField = queryType[1].schema;
17
+ if (!schemaField) {
18
+ throw new Error("Introspection schema has no schema field");
19
+ }
20
+ const types = Object.fromEntries(Object.entries(allTypes).filter(([name]) => name !== queryTypeName));
21
+ return {
22
+ types,
23
+ includedTypes: (createSchemaConfig().types ?? []).map((it) => it.name),
24
+ scalars: getCustomScalars(introspectionSchema),
25
+ queries: {
26
+ schema: {
27
+ type: schemaField[0],
28
+ resolve: () => introspectionSchemaFactory.create()
29
+ }
30
+ }
31
+ };
32
+ };
33
+ export {
34
+ createJsonIntrospectionExtension
35
+ };
36
+ //# sourceMappingURL=JsonIntrospectionExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonIntrospectionExtension.js","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonIntrospectionExtension.ts"],"sourcesContent":["import { printSchema } from 'graphql'\nimport { buildSchema, Schema, TypeKind } from '@contember/graphql-json'\nimport introspectionSchema, { createSchemaConfig } from '../introspection/introspection.schema.js'\nimport { IntrospectionSchemaFactory } from '../introspection/index.js'\nimport { JsonSchemaExtension } from './JsonContentSchemaBuilder.js'\nimport { getCustomScalars } from './GraphQLJsBridge.js'\n\nlet introspectionTypes: Schema | undefined\nconst getIntrospectionTypes = (): Schema => {\n\tintrospectionTypes ??= buildSchema(printSchema(introspectionSchema))\n\treturn introspectionTypes\n}\n\n/** The `schema` query of the content API. Its types are static, so they are converted from graphql-js once. */\nexport const createJsonIntrospectionExtension = (introspectionSchemaFactory: IntrospectionSchemaFactory): JsonSchemaExtension => {\n\tconst { q: queryTypeName, t: allTypes } = getIntrospectionTypes()\n\tconst queryType = allTypes[queryTypeName]\n\tif (!queryType || queryType[0] !== TypeKind.OBJECT) {\n\t\tthrow new Error('Introspection schema has no query type')\n\t}\n\tconst schemaField = queryType[1].schema\n\tif (!schemaField) {\n\t\tthrow new Error('Introspection schema has no schema field')\n\t}\n\tconst types = Object.fromEntries(Object.entries(allTypes).filter(([name]) => name !== queryTypeName))\n\treturn {\n\t\ttypes,\n\t\tincludedTypes: (createSchemaConfig().types ?? []).map(it => it.name),\n\t\tscalars: getCustomScalars(introspectionSchema),\n\t\tqueries: {\n\t\t\tschema: {\n\t\t\t\ttype: schemaField[0],\n\t\t\t\tresolve: () => introspectionSchemaFactory.create(),\n\t\t\t},\n\t\t},\n\t}\n}\n"],"names":[],"mappings":";;;;AAOA,IAAI;AACJ,MAAM,wBAAwB,MAAc;AAC3C,yBAAA,qBAAuB,YAAY,YAAY,mBAAmB,CAAC;AACnE,SAAO;AACR;AAGO,MAAM,mCAAmC,CAAC,+BAAgF;AAChI,QAAM,EAAE,GAAG,eAAe,GAAG,SAAA,IAAa,sBAAA;AAC1C,QAAM,YAAY,SAAS,aAAa;AACxC,MAAI,CAAC,aAAa,UAAU,CAAC,MAAM,SAAS,QAAQ;AACnD,UAAM,IAAI,MAAM,wCAAwC;AAAA,EACzD;AACA,QAAM,cAAc,UAAU,CAAC,EAAE;AACjC,MAAI,CAAC,aAAa;AACjB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC3D;AACA,QAAM,QAAQ,OAAO,YAAY,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,MAAM,SAAS,aAAa,CAAC;AACpG,SAAO;AAAA,IACN;AAAA,IACA,gBAAgB,qBAAqB,SAAS,CAAA,GAAI,IAAI,CAAA,OAAM,GAAG,IAAI;AAAA,IACnE,SAAS,iBAAiB,mBAAmB;AAAA,IAC7C,SAAS;AAAA,MACR,QAAQ;AAAA,QACP,MAAM,YAAY,CAAC;AAAA,QACnB,SAAS,MAAM,2BAA2B,OAAA;AAAA,MAAO;AAAA,IAClD;AAAA,EACD;AAEF;"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const graphql = require("graphql");
4
+ const graphqlJson = require("@contember/graphql-json");
5
+ const ResolveInfoUtils = require("../utils/ResolveInfoUtils.cjs");
6
+ require("@contember/schema-utils");
7
+ require("@contember/schema");
8
+ const FieldNode = require("../inputProcessing/FieldNode.cjs");
9
+ const ObjectNode = require("../inputProcessing/ObjectNode.cjs");
10
+ const node_util = require("node:util");
11
+ class JsonQueryAstFactory {
12
+ constructor(scalars, extensions) {
13
+ this.scalars = scalars;
14
+ this.extensions = extensions;
15
+ }
16
+ create(info, filter) {
17
+ const node = ResolveInfoUtils.ResolveInfoUtils.extractFieldNode(info);
18
+ const result = this.createFromNode(info, info.parentType, node, [], filter ?? (() => true));
19
+ if (!(result instanceof ObjectNode.ObjectNode)) {
20
+ throw new Error(`JsonQueryAstFactory: field ${info.parentType}.${info.fieldName} has no selection`);
21
+ }
22
+ return result;
23
+ }
24
+ createFromNode(info, parentTypeName, node, path, filter) {
25
+ if (!filter(node, path)) {
26
+ return null;
27
+ }
28
+ const name = node.name.value;
29
+ const alias = node.alias ? node.alias.value : name;
30
+ if (!node.selectionSet) {
31
+ return new FieldNode.FieldNode(name, alias, {});
32
+ }
33
+ const field = this.getCompositeType(info.schema, parentTypeName)[1][name];
34
+ if (!field) {
35
+ throw new Error(`JsonQueryAstFactory: unknown field ${parentTypeName}.${name}`);
36
+ }
37
+ const fieldTypeName = field[0][1];
38
+ const fieldType = info.schema.t[fieldTypeName];
39
+ if (!fieldType || fieldType[0] !== graphqlJson.TypeKind.OBJECT) {
40
+ throw new Error(`JsonQueryAstFactory: ${fieldTypeName} is not an object type`);
41
+ }
42
+ const fields = this.processSelectionSet(info, fieldTypeName, node.selectionSet, [...path, alias], filter);
43
+ return new ObjectNode.ObjectNode(
44
+ name,
45
+ alias,
46
+ fields,
47
+ graphqlJson.getArgumentValues(info.schema, field, node, info.variableValues, this.scalars),
48
+ this.extensions[parentTypeName]?.[name] ?? {},
49
+ path
50
+ );
51
+ }
52
+ processSelectionSet(info, parentTypeName, selectionSet, path, filter) {
53
+ const fields = [];
54
+ for (const subNode of selectionSet.selections) {
55
+ if (subNode.kind === graphql.Kind.FIELD) {
56
+ const field = this.createFromNode(info, parentTypeName, subNode, path, filter);
57
+ if (field !== null) {
58
+ fields.push(field);
59
+ }
60
+ } else if (subNode.kind === graphql.Kind.FRAGMENT_SPREAD) {
61
+ const fragmentDefinition = info.fragments[subNode.name.value];
62
+ if (!fragmentDefinition) {
63
+ throw new Error(`JsonQueryAstFactory: Fragment definition ${subNode.name.value} not found`);
64
+ }
65
+ const typeName = fragmentDefinition.typeCondition.name.value;
66
+ this.getCompositeType(info.schema, typeName);
67
+ fields.push(...this.processSelectionSet(info, typeName, fragmentDefinition.selectionSet, path, filter));
68
+ } else {
69
+ throw new Error("InlineFragment are not supported yet");
70
+ }
71
+ }
72
+ return mergeFieldList(fields);
73
+ }
74
+ getCompositeType(schema, typeName) {
75
+ const type = schema.t[typeName];
76
+ if (!type || type[0] !== graphqlJson.TypeKind.OBJECT && type[0] !== graphqlJson.TypeKind.INTERFACE) {
77
+ throw new Error("JsonQueryAstFactory: subfield is expected to be an object or interface type");
78
+ }
79
+ return type;
80
+ }
81
+ }
82
+ const mergeFieldList = (nodes) => {
83
+ const result = /* @__PURE__ */ new Map();
84
+ for (const node of nodes) {
85
+ const existing = result.get(node.alias);
86
+ result.set(node.alias, existing ? mergeFields(existing, node) : node);
87
+ }
88
+ return [...result.values()];
89
+ };
90
+ const mergeFields = (left, right) => {
91
+ if (left.constructor !== right.constructor) {
92
+ throw new Error(`JsonQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`);
93
+ }
94
+ if (left.name !== right.name) {
95
+ throw new Error(`JsonQueryAstFactory: incompatible fields ${left.name} and ${right.name}`);
96
+ }
97
+ if (left instanceof ObjectNode.ObjectNode && right instanceof ObjectNode.ObjectNode) {
98
+ if (!node_util.isDeepStrictEqual(left.args, right.args)) {
99
+ throw new Error(`JsonQueryAstFactory: incompatible args`);
100
+ }
101
+ const fields = mergeFieldList([...left.fields, ...right.fields]);
102
+ return new ObjectNode.ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path);
103
+ }
104
+ return left;
105
+ };
106
+ exports.JsonQueryAstFactory = JsonQueryAstFactory;
107
+ //# sourceMappingURL=JsonQueryAstFactory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonQueryAstFactory.cjs","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonQueryAstFactory.ts"],"sourcesContent":["import { FieldNode as GraphQlFieldNode, Kind, SelectionSetNode } from 'graphql'\nimport { getArgumentValues, InterfaceType, ObjectType, ResolveInfo, ScalarMap, Schema, TypeKind } from '@contember/graphql-json'\nimport { FieldNode, ObjectNode } from '../inputProcessing/index.js'\nimport { isDeepStrictEqual } from 'node:util'\nimport { ResolveInfoUtils } from '../utils/index.js'\nimport { FieldExtensions } from './JsonTypeRegistry.js'\nimport type { NodeFilter } from '../resolvers/GraphQlQueryAstFactory.js'\n\ntype AnyNode = ObjectNode | FieldNode\n\n/**\n * Turns the resolved field into Contember's query tree. The schema comes from the resolve info, so one factory\n * serves every role schema of a model.\n */\nexport class JsonQueryAstFactory {\n\tconstructor(\n\t\tprivate readonly scalars: ScalarMap,\n\t\tprivate readonly extensions: Record<string, Record<string, FieldExtensions>>,\n\t) {}\n\n\tpublic create<Args = any>(info: ResolveInfo, filter?: NodeFilter): ObjectNode<Args> {\n\t\tconst node = ResolveInfoUtils.extractFieldNode(info)\n\t\tconst result = this.createFromNode(info, info.parentType, node, [], filter ?? (() => true))\n\t\tif (!(result instanceof ObjectNode)) {\n\t\t\tthrow new Error(`JsonQueryAstFactory: field ${info.parentType}.${info.fieldName} has no selection`)\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate createFromNode(\n\t\tinfo: ResolveInfo,\n\t\tparentTypeName: string,\n\t\tnode: GraphQlFieldNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode | 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 = this.getCompositeType(info.schema, parentTypeName)[1][name]\n\t\tif (!field) {\n\t\t\tthrow new Error(`JsonQueryAstFactory: unknown field ${parentTypeName}.${name}`)\n\t\t}\n\t\tconst fieldTypeName = field[0][1]\n\t\tconst fieldType = info.schema.t[fieldTypeName]\n\t\tif (!fieldType || fieldType[0] !== TypeKind.OBJECT) {\n\t\t\tthrow new Error(`JsonQueryAstFactory: ${fieldTypeName} is not an object type`)\n\t\t}\n\t\tconst fields = this.processSelectionSet(info, fieldTypeName, node.selectionSet, [...path, alias], filter)\n\t\treturn new ObjectNode(\n\t\t\tname,\n\t\t\talias,\n\t\t\tfields,\n\t\t\tgetArgumentValues(info.schema, field, node, info.variableValues, this.scalars),\n\t\t\tthis.extensions[parentTypeName]?.[name] ?? {},\n\t\t\tpath,\n\t\t)\n\t}\n\n\tprivate processSelectionSet(\n\t\tinfo: ResolveInfo,\n\t\tparentTypeName: string,\n\t\tselectionSet: SelectionSetNode,\n\t\tpath: string[],\n\t\tfilter: NodeFilter,\n\t): AnyNode[] {\n\t\tconst fields: AnyNode[] = []\n\t\tfor (const subNode of selectionSet.selections) {\n\t\t\tif (subNode.kind === Kind.FIELD) {\n\t\t\t\tconst field = this.createFromNode(info, parentTypeName, subNode, path, filter)\n\t\t\t\tif (field !== null) {\n\t\t\t\t\tfields.push(field)\n\t\t\t\t}\n\t\t\t} else if (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(`JsonQueryAstFactory: 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\tthis.getCompositeType(info.schema, typeName)\n\t\t\t\tfields.push(...this.processSelectionSet(info, typeName, fragmentDefinition.selectionSet, path, filter))\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 mergeFieldList(fields)\n\t}\n\n\tprivate getCompositeType(schema: Schema, typeName: string): ObjectType | InterfaceType {\n\t\tconst type = schema.t[typeName]\n\t\tif (!type || (type[0] !== TypeKind.OBJECT && type[0] !== TypeKind.INTERFACE)) {\n\t\t\tthrow new Error('JsonQueryAstFactory: subfield is expected to be an object or interface type')\n\t\t}\n\t\treturn type\n\t}\n}\n\nconst mergeFieldList = (nodes: AnyNode[]): AnyNode[] => {\n\t// a Map, so aliases such as `toString` or `__proto__` do not hit Object.prototype\n\tconst result = new Map<string, AnyNode>()\n\tfor (const node of nodes) {\n\t\tconst existing = result.get(node.alias)\n\t\tresult.set(node.alias, existing ? mergeFields(existing, node) : node)\n\t}\n\treturn [...result.values()]\n}\n\nconst mergeFields = (left: AnyNode, right: AnyNode): AnyNode => {\n\tif (left.constructor !== right.constructor) {\n\t\tthrow new Error(`JsonQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)\n\t}\n\tif (left.name !== right.name) {\n\t\tthrow new Error(`JsonQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)\n\t}\n\tif (left instanceof ObjectNode && right instanceof ObjectNode) {\n\t\tif (!isDeepStrictEqual(left.args, right.args)) {\n\t\t\tthrow new Error(`JsonQueryAstFactory: incompatible args`)\n\t\t}\n\t\tconst fields = mergeFieldList([...left.fields, ...right.fields])\n\t\treturn new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)\n\t}\n\treturn left\n}\n"],"names":["ResolveInfoUtils","ObjectNode","FieldNode","TypeKind","getArgumentValues","Kind","isDeepStrictEqual"],"mappings":";;;;;;;;;;AAcO,MAAM,oBAAoB;AAAA,EAChC,YACkB,SACA,YAChB;AAFgB,SAAA,UAAA;AACA,SAAA,aAAA;AAAA,EACf;AAAA,EAEI,OAAmB,MAAmB,QAAuC;AACnF,UAAM,OAAOA,iBAAAA,iBAAiB,iBAAiB,IAAI;AACnD,UAAM,SAAS,KAAK,eAAe,MAAM,KAAK,YAAY,MAAM,CAAA,GAAI,WAAW,MAAM,KAAK;AAC1F,QAAI,EAAE,kBAAkBC,WAAAA,aAAa;AACpC,YAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,IAAI,KAAK,SAAS,mBAAmB;AAAA,IACnG;AACA,WAAO;AAAA,EACR;AAAA,EAEQ,eACP,MACA,gBACA,MACA,MACA,QACiB;AACjB,QAAI,CAAC,OAAO,MAAM,IAAI,GAAG;AACxB,aAAO;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BA,uBAAY;AAC9D,QAAI,CAACK,UAAAA,kBAAkB,KAAK,MAAM,MAAM,IAAI,GAAG;AAC9C,YAAM,IAAI,MAAM,wCAAwC;AAAA,IACzD;AACA,UAAM,SAAS,eAAe,CAAC,GAAG,KAAK,QAAQ,GAAG,MAAM,MAAM,CAAC;AAC/D,WAAO,IAAIL,WAAAA,WAAW,KAAK,MAAM,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,EAC3F;AACA,SAAO;AACR;;"}
@@ -0,0 +1,107 @@
1
+ import { Kind } from "graphql";
2
+ import { TypeKind, getArgumentValues } from "@contember/graphql-json";
3
+ import { ResolveInfoUtils } from "../utils/ResolveInfoUtils.js";
4
+ import "@contember/schema-utils";
5
+ import "@contember/schema";
6
+ import { FieldNode } from "../inputProcessing/FieldNode.js";
7
+ import { ObjectNode } from "../inputProcessing/ObjectNode.js";
8
+ import { isDeepStrictEqual } from "node:util";
9
+ class JsonQueryAstFactory {
10
+ constructor(scalars, extensions) {
11
+ this.scalars = scalars;
12
+ this.extensions = extensions;
13
+ }
14
+ create(info, filter) {
15
+ const node = ResolveInfoUtils.extractFieldNode(info);
16
+ const result = this.createFromNode(info, info.parentType, node, [], filter ?? (() => true));
17
+ if (!(result instanceof ObjectNode)) {
18
+ throw new Error(`JsonQueryAstFactory: field ${info.parentType}.${info.fieldName} has no selection`);
19
+ }
20
+ return result;
21
+ }
22
+ createFromNode(info, parentTypeName, node, path, filter) {
23
+ if (!filter(node, path)) {
24
+ return null;
25
+ }
26
+ const name = node.name.value;
27
+ const alias = node.alias ? node.alias.value : name;
28
+ if (!node.selectionSet) {
29
+ return new FieldNode(name, alias, {});
30
+ }
31
+ const field = this.getCompositeType(info.schema, parentTypeName)[1][name];
32
+ if (!field) {
33
+ throw new Error(`JsonQueryAstFactory: unknown field ${parentTypeName}.${name}`);
34
+ }
35
+ const fieldTypeName = field[0][1];
36
+ const fieldType = info.schema.t[fieldTypeName];
37
+ if (!fieldType || fieldType[0] !== TypeKind.OBJECT) {
38
+ throw new Error(`JsonQueryAstFactory: ${fieldTypeName} is not an object type`);
39
+ }
40
+ const fields = this.processSelectionSet(info, fieldTypeName, node.selectionSet, [...path, alias], filter);
41
+ return new ObjectNode(
42
+ name,
43
+ alias,
44
+ fields,
45
+ getArgumentValues(info.schema, field, node, info.variableValues, this.scalars),
46
+ this.extensions[parentTypeName]?.[name] ?? {},
47
+ path
48
+ );
49
+ }
50
+ processSelectionSet(info, parentTypeName, selectionSet, path, filter) {
51
+ const fields = [];
52
+ for (const subNode of selectionSet.selections) {
53
+ if (subNode.kind === Kind.FIELD) {
54
+ const field = this.createFromNode(info, parentTypeName, subNode, path, filter);
55
+ if (field !== null) {
56
+ fields.push(field);
57
+ }
58
+ } else if (subNode.kind === Kind.FRAGMENT_SPREAD) {
59
+ const fragmentDefinition = info.fragments[subNode.name.value];
60
+ if (!fragmentDefinition) {
61
+ throw new Error(`JsonQueryAstFactory: Fragment definition ${subNode.name.value} not found`);
62
+ }
63
+ const typeName = fragmentDefinition.typeCondition.name.value;
64
+ this.getCompositeType(info.schema, typeName);
65
+ fields.push(...this.processSelectionSet(info, typeName, fragmentDefinition.selectionSet, path, filter));
66
+ } else {
67
+ throw new Error("InlineFragment are not supported yet");
68
+ }
69
+ }
70
+ return mergeFieldList(fields);
71
+ }
72
+ getCompositeType(schema, typeName) {
73
+ const type = schema.t[typeName];
74
+ if (!type || type[0] !== TypeKind.OBJECT && type[0] !== TypeKind.INTERFACE) {
75
+ throw new Error("JsonQueryAstFactory: subfield is expected to be an object or interface type");
76
+ }
77
+ return type;
78
+ }
79
+ }
80
+ const mergeFieldList = (nodes) => {
81
+ const result = /* @__PURE__ */ new Map();
82
+ for (const node of nodes) {
83
+ const existing = result.get(node.alias);
84
+ result.set(node.alias, existing ? mergeFields(existing, node) : node);
85
+ }
86
+ return [...result.values()];
87
+ };
88
+ const mergeFields = (left, right) => {
89
+ if (left.constructor !== right.constructor) {
90
+ throw new Error(`JsonQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`);
91
+ }
92
+ if (left.name !== right.name) {
93
+ throw new Error(`JsonQueryAstFactory: incompatible fields ${left.name} and ${right.name}`);
94
+ }
95
+ if (left instanceof ObjectNode && right instanceof ObjectNode) {
96
+ if (!isDeepStrictEqual(left.args, right.args)) {
97
+ throw new Error(`JsonQueryAstFactory: incompatible args`);
98
+ }
99
+ const fields = mergeFieldList([...left.fields, ...right.fields]);
100
+ return new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path);
101
+ }
102
+ return left;
103
+ };
104
+ export {
105
+ JsonQueryAstFactory
106
+ };
107
+ //# sourceMappingURL=JsonQueryAstFactory.js.map