@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 @@
1
+ {"version":3,"file":"JsonQueryAstFactory.js","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":[],"mappings":";;;;;;;;AAcO,MAAM,oBAAoB;AAAA,EAChC,YACkB,SACA,YACh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AAA,EACrE;AACA,SAAO,CAAC,GAAG,OAAO,QAAQ;AAC3B;AAEA,MAAM,cAAc,CAAC,MAAe,UAA4B;AAC/D,MAAI,KAAK,gBAAgB,MAAM,aAAa;AAC3C,UAAM,IAAI,MAAM,qCAAqC,KAAK,YAAY,IAAI,QAAQ,MAAM,YAAY,IAAI,EAAE;AAAA,EAC3G;AACA,MAAI,KAAK,SAAS,MAAM,MAAM;AAC7B,UAAM,IAAI,MAAM,4CAA4C,KAAK,IAAI,QAAQ,MAAM,IAAI,EAAE;AAAA,EAC1F;AACA,MAAI,gBAAgB,cAAc,iBAAiB,YAAY;AAC9D,QAAI,CAAC,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,IAAI,WAAW,KAAK,MAAM,KAAK,OAAO,QAAQ,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI;AAAA,EAC3F;AACA,SAAO;AACR;"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const graphqlJson = require("@contember/graphql-json");
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ class JsonTypeRegistry {
8
+ constructor(resolvers, extensions, scalars) {
9
+ this.resolvers = resolvers;
10
+ this.extensions = extensions;
11
+ this.scalars = scalars;
12
+ __publicField(this, "types", {});
13
+ __publicField(this, "pending", []);
14
+ }
15
+ has(name) {
16
+ return name in this.types;
17
+ }
18
+ object(name, createFields, interfaces = [], description) {
19
+ if (this.types[name]) {
20
+ return name;
21
+ }
22
+ const fields = {};
23
+ this.types[name] = description !== void 0 ? [graphqlJson.TypeKind.OBJECT, fields, interfaces, description] : [graphqlJson.TypeKind.OBJECT, fields, interfaces];
24
+ for (const interfaceName of interfaces) {
25
+ this.addPossibleType(interfaceName, name);
26
+ }
27
+ this.pending.push(() => this.addOutputFields(name, fields, createFields()));
28
+ return name;
29
+ }
30
+ interface(name, createFields) {
31
+ if (this.types[name]) {
32
+ return name;
33
+ }
34
+ const fields = {};
35
+ this.types[name] = [graphqlJson.TypeKind.INTERFACE, fields, [], []];
36
+ this.pending.push(() => this.addOutputFields(name, fields, createFields()));
37
+ return name;
38
+ }
39
+ union(name, possibleTypes) {
40
+ if (!this.types[name]) {
41
+ this.types[name] = [graphqlJson.TypeKind.UNION, possibleTypes];
42
+ }
43
+ return name;
44
+ }
45
+ inputObject(name, createFields) {
46
+ if (this.types[name]) {
47
+ return name;
48
+ }
49
+ const fields = {};
50
+ this.types[name] = [graphqlJson.TypeKind.INPUT_OBJECT, fields];
51
+ this.pending.push(() => Object.assign(fields, createFields()));
52
+ return name;
53
+ }
54
+ enum(name, values) {
55
+ if (!this.types[name]) {
56
+ const enumValues = {};
57
+ for (const value of values) {
58
+ enumValues[value] = [value];
59
+ }
60
+ this.types[name] = [graphqlJson.TypeKind.ENUM, enumValues];
61
+ }
62
+ return name;
63
+ }
64
+ scalar(name, implementation, description) {
65
+ var _a;
66
+ if (!this.types[name]) {
67
+ this.types[name] = graphqlJson.isSpecifiedScalarTypeName(name) ? graphqlJson.specifiedScalarTypes[name] : description !== void 0 ? [graphqlJson.TypeKind.SCALAR, description] : [graphqlJson.TypeKind.SCALAR];
68
+ }
69
+ if (implementation) {
70
+ (_a = this.scalars)[name] ?? (_a[name] = implementation);
71
+ }
72
+ return name;
73
+ }
74
+ /** Creates the fields of the registered types, including the types that creates; yields after each type. */
75
+ *fillPending() {
76
+ for (let i = 0; i < this.pending.length; i++) {
77
+ this.pending[i]();
78
+ yield;
79
+ }
80
+ this.pending.length = 0;
81
+ }
82
+ /**
83
+ * The types the schema consists of, collected the way graphql-js collects them (`GraphQLSchema` constructor):
84
+ * `includedTypes` first, then everything `roots` reach, depth-first. The order is what introspection and the
85
+ * printed schema list, so it stays the order graphql-js produced. Providers create some types speculatively
86
+ * (e.g. an input that the allowed operations then filter out); unreachable ones are left out.
87
+ * Returns a new record: deleting from a large object would turn it into a slow dictionary.
88
+ * Yields after each collected type.
89
+ */
90
+ *collectReachableTypes(includedTypes, roots, otherTypes) {
91
+ const reachable = new Set(includedTypes);
92
+ const getType = (name) => this.types[name] ?? otherTypes[name];
93
+ const collect = function* (name) {
94
+ const names = [[name]];
95
+ const positions = [0];
96
+ while (names.length > 0) {
97
+ const top = names.length - 1;
98
+ const next = names[top][positions[top]++];
99
+ if (next === void 0) {
100
+ names.pop();
101
+ positions.pop();
102
+ continue;
103
+ }
104
+ const type = reachable.has(next) ? void 0 : getType(next);
105
+ if (!type) {
106
+ continue;
107
+ }
108
+ reachable.add(next);
109
+ names.push(getReferencedTypes(type));
110
+ positions.push(0);
111
+ yield;
112
+ }
113
+ };
114
+ for (const name of includedTypes) {
115
+ reachable.delete(name);
116
+ yield* collect(name);
117
+ }
118
+ for (const root of roots) {
119
+ yield* collect(root);
120
+ }
121
+ const types = {};
122
+ for (const name of reachable) {
123
+ const type = getType(name);
124
+ if (!type) {
125
+ continue;
126
+ }
127
+ if (type[0] === graphqlJson.TypeKind.INTERFACE && type[3].some((it) => !reachable.has(it))) {
128
+ const possibleTypes = type[3].filter((it) => reachable.has(it));
129
+ types[name] = type[4] !== void 0 ? [graphqlJson.TypeKind.INTERFACE, type[1], type[2], possibleTypes, type[4]] : [graphqlJson.TypeKind.INTERFACE, type[1], type[2], possibleTypes];
130
+ } else {
131
+ types[name] = type;
132
+ }
133
+ }
134
+ return types;
135
+ }
136
+ addPossibleType(interfaceName, typeName) {
137
+ const interfaceType = this.types[interfaceName];
138
+ if (!interfaceType || interfaceType[0] !== graphqlJson.TypeKind.INTERFACE) {
139
+ throw new Error(`Interface ${interfaceName} must be registered before ${typeName}`);
140
+ }
141
+ interfaceType[3].push(typeName);
142
+ }
143
+ addOutputFields(typeName, target, fields) {
144
+ var _a, _b, _c, _d;
145
+ for (const [fieldName, field] of Object.entries(fields)) {
146
+ target[fieldName] = field.deprecationReason !== void 0 ? [field.type, field.args ?? null, field.description, field.deprecationReason] : field.description !== void 0 ? [field.type, field.args ?? null, field.description] : [field.type, field.args ?? null];
147
+ if (field.resolve) {
148
+ (_b = (_a = this.resolvers)[typeName] ?? (_a[typeName] = {}))[fieldName] ?? (_b[fieldName] = field.resolve);
149
+ }
150
+ if (field.extensions) {
151
+ (_d = (_c = this.extensions)[typeName] ?? (_c[typeName] = {}))[fieldName] ?? (_d[fieldName] = field.extensions);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ const getReferencedTypes = (type) => {
157
+ const names = [];
158
+ switch (type[0]) {
159
+ case graphqlJson.TypeKind.OBJECT:
160
+ case graphqlJson.TypeKind.INTERFACE:
161
+ names.push(...type[2]);
162
+ for (const fieldName in type[1]) {
163
+ const field = type[1][fieldName];
164
+ if (!field) {
165
+ continue;
166
+ }
167
+ names.push(field[0][1]);
168
+ for (const argName in field[1]) {
169
+ const arg = field[1][argName];
170
+ if (arg) {
171
+ names.push(arg[0][1]);
172
+ }
173
+ }
174
+ }
175
+ break;
176
+ case graphqlJson.TypeKind.UNION:
177
+ names.push(...type[1]);
178
+ break;
179
+ case graphqlJson.TypeKind.INPUT_OBJECT:
180
+ for (const fieldName in type[1]) {
181
+ const field = type[1][fieldName];
182
+ if (field) {
183
+ names.push(field[0][1]);
184
+ }
185
+ }
186
+ break;
187
+ }
188
+ return names;
189
+ };
190
+ const inputField = (type, description) => description !== void 0 ? [type, void 0, description] : [type];
191
+ const TypeRefPattern = {
192
+ named: 0,
193
+ // T
194
+ nonNull: 1,
195
+ // T!
196
+ list: 2,
197
+ // [T]
198
+ listOfNonNull: 3,
199
+ // [T!]
200
+ nonNullListOfNonNull: 5,
201
+ // [T!]!
202
+ nonNullListOfNonNullListOfNonNull: 13
203
+ // [[T!]!]!
204
+ };
205
+ const namedRef = (name) => [TypeRefPattern.named, name];
206
+ const nonNullRef = (name) => [TypeRefPattern.nonNull, name];
207
+ const listRef = (name) => [TypeRefPattern.list, name];
208
+ const listOfNonNullRef = (name) => [TypeRefPattern.listOfNonNull, name];
209
+ const nonNullListOfNonNullRef = (name) => [TypeRefPattern.nonNullListOfNonNull, name];
210
+ const nonNullListOfNonNullListOfNonNullRef = (name) => [TypeRefPattern.nonNullListOfNonNullListOfNonNull, name];
211
+ const toNonNull = (ref) => {
212
+ switch (ref[0]) {
213
+ case TypeRefPattern.named:
214
+ return [TypeRefPattern.nonNull, ref[1]];
215
+ case TypeRefPattern.listOfNonNull:
216
+ return [TypeRefPattern.nonNullListOfNonNull, ref[1]];
217
+ default:
218
+ throw new Error(`Cannot wrap type ref pattern ${ref[0]} in non-null`);
219
+ }
220
+ };
221
+ exports.JsonTypeRegistry = JsonTypeRegistry;
222
+ exports.inputField = inputField;
223
+ exports.listOfNonNullRef = listOfNonNullRef;
224
+ exports.listRef = listRef;
225
+ exports.namedRef = namedRef;
226
+ exports.nonNullListOfNonNullListOfNonNullRef = nonNullListOfNonNullListOfNonNullRef;
227
+ exports.nonNullListOfNonNullRef = nonNullListOfNonNullRef;
228
+ exports.nonNullRef = nonNullRef;
229
+ exports.toNonNull = toNonNull;
230
+ //# sourceMappingURL=JsonTypeRegistry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonTypeRegistry.cjs","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonTypeRegistry.ts"],"sourcesContent":["import {\n\tArgument,\n\tEnumValue,\n\tField,\n\tInputField,\n\tisSpecifiedScalarTypeName,\n\tResolverFn,\n\tResolverMap,\n\tScalarImplementation,\n\tspecifiedScalarTypes,\n\tType,\n\tTypeKind,\n\tTypeRef,\n} from '@contember/graphql-json'\nimport { Context } from '../types.js'\n\nexport type FieldExtensions = Record<string, unknown>\n\nexport interface JsonOutputField {\n\ttype: TypeRef\n\targs?: Record<string, Argument>\n\tresolve?: ResolverFn<unknown, Context>\n\textensions?: FieldExtensions\n\tdescription?: string\n\tdeprecationReason?: string\n}\n\n/**\n * Collects the JSON types of one content schema. Types are referenced by name, so a type is registered before its\n * fields are created - a recursive reference (e.g. `Where.and`) then only resolves the name.\n * Fields are created later, by `fillPending`: one type at a time, so that a build can pause between them instead of\n * running the whole graph a single entity reaches in one go.\n * Resolvers, field extensions and scalars go to maps shared by all schemas of the model; the first registration wins.\n */\nexport class JsonTypeRegistry {\n\tpublic readonly types: Record<string, Type> = {}\n\tprivate readonly pending: (() => void)[] = []\n\n\tconstructor(\n\t\tpublic readonly resolvers: ResolverMap<Context>,\n\t\tpublic readonly extensions: Record<string, Record<string, FieldExtensions>>,\n\t\tpublic readonly scalars: Record<string, ScalarImplementation>,\n\t) {}\n\n\tpublic has(name: string): boolean {\n\t\treturn name in this.types\n\t}\n\n\tpublic object(\n\t\tname: string,\n\t\tcreateFields: () => Record<string, JsonOutputField>,\n\t\tinterfaces: string[] = [],\n\t\tdescription?: string,\n\t): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, Field> = {}\n\t\tthis.types[name] = description !== undefined ? [TypeKind.OBJECT, fields, interfaces, description] : [TypeKind.OBJECT, fields, interfaces]\n\t\tfor (const interfaceName of interfaces) {\n\t\t\tthis.addPossibleType(interfaceName, name)\n\t\t}\n\t\tthis.pending.push(() => this.addOutputFields(name, fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic interface(name: string, createFields: () => Record<string, JsonOutputField>): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, Field> = {}\n\t\tthis.types[name] = [TypeKind.INTERFACE, fields, [], []]\n\t\tthis.pending.push(() => this.addOutputFields(name, fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic union(name: string, possibleTypes: string[]): string {\n\t\tif (!this.types[name]) {\n\t\t\tthis.types[name] = [TypeKind.UNION, possibleTypes]\n\t\t}\n\t\treturn name\n\t}\n\n\tpublic inputObject(name: string, createFields: () => Record<string, InputField>): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, InputField> = {}\n\t\tthis.types[name] = [TypeKind.INPUT_OBJECT, fields]\n\t\tthis.pending.push(() => Object.assign(fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic enum(name: string, values: readonly string[]): string {\n\t\tif (!this.types[name]) {\n\t\t\tconst enumValues: Record<string, EnumValue> = {}\n\t\t\tfor (const value of values) {\n\t\t\t\tenumValues[value] = [value]\n\t\t\t}\n\t\t\tthis.types[name] = [TypeKind.ENUM, enumValues]\n\t\t}\n\t\treturn name\n\t}\n\n\tpublic scalar(name: string, implementation: ScalarImplementation | undefined, description?: string): string {\n\t\tif (!this.types[name]) {\n\t\t\tthis.types[name] = isSpecifiedScalarTypeName(name)\n\t\t\t\t? specifiedScalarTypes[name]\n\t\t\t\t: description !== undefined\n\t\t\t\t? [TypeKind.SCALAR, description]\n\t\t\t\t: [TypeKind.SCALAR]\n\t\t}\n\t\tif (implementation) {\n\t\t\tthis.scalars[name] ??= implementation\n\t\t}\n\t\treturn name\n\t}\n\n\t/** Creates the fields of the registered types, including the types that creates; yields after each type. */\n\tpublic *fillPending(): Generator<void, void> {\n\t\t// the queue grows while it is processed\n\t\tfor (let i = 0; i < this.pending.length; i++) {\n\t\t\tthis.pending[i]()\n\t\t\tyield\n\t\t}\n\t\tthis.pending.length = 0\n\t}\n\n\t/**\n\t * The types the schema consists of, collected the way graphql-js collects them (`GraphQLSchema` constructor):\n\t * `includedTypes` first, then everything `roots` reach, depth-first. The order is what introspection and the\n\t * printed schema list, so it stays the order graphql-js produced. Providers create some types speculatively\n\t * (e.g. an input that the allowed operations then filter out); unreachable ones are left out.\n\t * Returns a new record: deleting from a large object would turn it into a slow dictionary.\n\t * Yields after each collected type.\n\t */\n\tpublic *collectReachableTypes(\n\t\tincludedTypes: readonly string[],\n\t\troots: readonly string[],\n\t\totherTypes: Record<string, Type>,\n\t): Generator<void, Record<string, Type>> {\n\t\tconst reachable = new Set<string>(includedTypes)\n\t\tconst getType = (name: string): Type | undefined => this.types[name] ?? otherTypes[name]\n\t\t// an explicit stack instead of recursion keeps the pre-order of a recursive walk and can pause after any type\n\t\tconst collect = function*(name: string): Generator<void, void> {\n\t\t\tconst names: (readonly string[])[] = [[name]]\n\t\t\tconst positions: number[] = [0]\n\t\t\twhile (names.length > 0) {\n\t\t\t\tconst top = names.length - 1\n\t\t\t\tconst next = names[top][positions[top]++]\n\t\t\t\tif (next === undefined) {\n\t\t\t\t\tnames.pop()\n\t\t\t\t\tpositions.pop()\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst type = reachable.has(next) ? undefined : getType(next)\n\t\t\t\tif (!type) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treachable.add(next)\n\t\t\t\tnames.push(getReferencedTypes(type))\n\t\t\t\tpositions.push(0)\n\t\t\t\tyield\n\t\t\t}\n\t\t}\n\t\t// graphql-js seeds the set with the included types and re-adds each one, which moves it to the end\n\t\tfor (const name of includedTypes) {\n\t\t\treachable.delete(name)\n\t\t\tyield* collect(name)\n\t\t}\n\t\tfor (const root of roots) {\n\t\t\tyield* collect(root)\n\t\t}\n\n\t\tconst types: Record<string, Type> = {}\n\t\tfor (const name of reachable) {\n\t\t\tconst type = getType(name)\n\t\t\tif (!type) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// replaced, not mutated: extension types are shared between schemas\n\t\t\tif (type[0] === TypeKind.INTERFACE && type[3].some(it => !reachable.has(it))) {\n\t\t\t\tconst possibleTypes = type[3].filter(it => reachable.has(it))\n\t\t\t\ttypes[name] = type[4] !== undefined\n\t\t\t\t\t? [TypeKind.INTERFACE, type[1], type[2], possibleTypes, type[4]]\n\t\t\t\t\t: [TypeKind.INTERFACE, type[1], type[2], possibleTypes]\n\t\t\t} else {\n\t\t\t\ttypes[name] = type\n\t\t\t}\n\t\t}\n\t\treturn types\n\t}\n\n\tprivate addPossibleType(interfaceName: string, typeName: string): void {\n\t\tconst interfaceType = this.types[interfaceName]\n\t\tif (!interfaceType || interfaceType[0] !== TypeKind.INTERFACE) {\n\t\t\tthrow new Error(`Interface ${interfaceName} must be registered before ${typeName}`)\n\t\t}\n\t\tinterfaceType[3].push(typeName)\n\t}\n\n\tprivate addOutputFields(typeName: string, target: Record<string, Field>, fields: Record<string, JsonOutputField>): void {\n\t\tfor (const [fieldName, field] of Object.entries(fields)) {\n\t\t\ttarget[fieldName] = field.deprecationReason !== undefined\n\t\t\t\t? [field.type, field.args ?? null, field.description, field.deprecationReason]\n\t\t\t\t: field.description !== undefined\n\t\t\t\t? [field.type, field.args ?? null, field.description]\n\t\t\t\t: [field.type, field.args ?? null]\n\t\t\tif (field.resolve) {\n\t\t\t\t;(this.resolvers[typeName] ??= {})[fieldName] ??= field.resolve\n\t\t\t}\n\t\t\tif (field.extensions) {\n\t\t\t\t;(this.extensions[typeName] ??= {})[fieldName] ??= field.extensions\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** The names a type refers to, in the order graphql-js visits them: interfaces, then each field's type and arguments. */\nconst getReferencedTypes = (type: Type): string[] => {\n\tconst names: string[] = []\n\tswitch (type[0]) {\n\t\tcase TypeKind.OBJECT:\n\t\tcase TypeKind.INTERFACE:\n\t\t\tnames.push(...type[2])\n\t\t\tfor (const fieldName in type[1]) {\n\t\t\t\tconst field = type[1][fieldName]\n\t\t\t\tif (!field) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tnames.push(field[0][1])\n\t\t\t\tfor (const argName in field[1]) {\n\t\t\t\t\tconst arg = field[1][argName]\n\t\t\t\t\tif (arg) {\n\t\t\t\t\t\tnames.push(arg[0][1])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t\tcase TypeKind.UNION:\n\t\t\tnames.push(...type[1])\n\t\t\tbreak\n\t\tcase TypeKind.INPUT_OBJECT:\n\t\t\tfor (const fieldName in type[1]) {\n\t\t\t\tconst field = type[1][fieldName]\n\t\t\t\tif (field) {\n\t\t\t\t\tnames.push(field[0][1])\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n\treturn names\n}\n\n/** An input field without a default value; the description is left out of the tuple when there is none. */\nexport const inputField = (type: TypeRef, description: string | undefined): InputField =>\n\tdescription !== undefined ? [type, undefined, description] : [type]\n\n/** Wrap patterns of graphql-json `TypeRef`, named after the SDL they produce. */\nconst TypeRefPattern = {\n\tnamed: 0, // T\n\tnonNull: 1, // T!\n\tlist: 2, // [T]\n\tlistOfNonNull: 3, // [T!]\n\tnonNullListOfNonNull: 5, // [T!]!\n\tnonNullListOfNonNullListOfNonNull: 13, // [[T!]!]!\n} as const\n\nexport const namedRef = (name: string): TypeRef => [TypeRefPattern.named, name]\nexport const nonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNull, name]\nexport const listRef = (name: string): TypeRef => [TypeRefPattern.list, name]\nexport const listOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.listOfNonNull, name]\nexport const nonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNull, name]\nexport const nonNullListOfNonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNullListOfNonNull, name]\n\n/** `T` → `T!`, `[T!]` → `[T!]!` */\nexport const toNonNull = (ref: TypeRef): TypeRef => {\n\tswitch (ref[0]) {\n\t\tcase TypeRefPattern.named:\n\t\t\treturn [TypeRefPattern.nonNull, ref[1]]\n\t\tcase TypeRefPattern.listOfNonNull:\n\t\t\treturn [TypeRefPattern.nonNullListOfNonNull, ref[1]]\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot wrap type ref pattern ${ref[0]} in non-null`)\n\t}\n}\n"],"names":["TypeKind","isSpecifiedScalarTypeName","specifiedScalarTypes"],"mappings":";;;;;;AAkCO,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;AAAA,IACZ,KAAK,eAAe;AACnB,aAAO,CAAC,eAAe,SAAS,IAAI,CAAC,CAAC;AAAA,IACvC,KAAK,eAAe;AACnB,aAAO,CAAC,eAAe,sBAAsB,IAAI,CAAC,CAAC;AAAA,IACpD;AACC,YAAM,IAAI,MAAM,gCAAgC,IAAI,CAAC,CAAC,cAAc;AAAA,EAAA;AAEvE;;;;;;;;;;"}
@@ -0,0 +1,230 @@
1
+ import { TypeKind, specifiedScalarTypes, isSpecifiedScalarTypeName } from "@contember/graphql-json";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ class JsonTypeRegistry {
6
+ constructor(resolvers, extensions, scalars) {
7
+ this.resolvers = resolvers;
8
+ this.extensions = extensions;
9
+ this.scalars = scalars;
10
+ __publicField(this, "types", {});
11
+ __publicField(this, "pending", []);
12
+ }
13
+ has(name) {
14
+ return name in this.types;
15
+ }
16
+ object(name, createFields, interfaces = [], description) {
17
+ if (this.types[name]) {
18
+ return name;
19
+ }
20
+ const fields = {};
21
+ this.types[name] = description !== void 0 ? [TypeKind.OBJECT, fields, interfaces, description] : [TypeKind.OBJECT, fields, interfaces];
22
+ for (const interfaceName of interfaces) {
23
+ this.addPossibleType(interfaceName, name);
24
+ }
25
+ this.pending.push(() => this.addOutputFields(name, fields, createFields()));
26
+ return name;
27
+ }
28
+ interface(name, createFields) {
29
+ if (this.types[name]) {
30
+ return name;
31
+ }
32
+ const fields = {};
33
+ this.types[name] = [TypeKind.INTERFACE, fields, [], []];
34
+ this.pending.push(() => this.addOutputFields(name, fields, createFields()));
35
+ return name;
36
+ }
37
+ union(name, possibleTypes) {
38
+ if (!this.types[name]) {
39
+ this.types[name] = [TypeKind.UNION, possibleTypes];
40
+ }
41
+ return name;
42
+ }
43
+ inputObject(name, createFields) {
44
+ if (this.types[name]) {
45
+ return name;
46
+ }
47
+ const fields = {};
48
+ this.types[name] = [TypeKind.INPUT_OBJECT, fields];
49
+ this.pending.push(() => Object.assign(fields, createFields()));
50
+ return name;
51
+ }
52
+ enum(name, values) {
53
+ if (!this.types[name]) {
54
+ const enumValues = {};
55
+ for (const value of values) {
56
+ enumValues[value] = [value];
57
+ }
58
+ this.types[name] = [TypeKind.ENUM, enumValues];
59
+ }
60
+ return name;
61
+ }
62
+ scalar(name, implementation, description) {
63
+ var _a;
64
+ if (!this.types[name]) {
65
+ this.types[name] = isSpecifiedScalarTypeName(name) ? specifiedScalarTypes[name] : description !== void 0 ? [TypeKind.SCALAR, description] : [TypeKind.SCALAR];
66
+ }
67
+ if (implementation) {
68
+ (_a = this.scalars)[name] ?? (_a[name] = implementation);
69
+ }
70
+ return name;
71
+ }
72
+ /** Creates the fields of the registered types, including the types that creates; yields after each type. */
73
+ *fillPending() {
74
+ for (let i = 0; i < this.pending.length; i++) {
75
+ this.pending[i]();
76
+ yield;
77
+ }
78
+ this.pending.length = 0;
79
+ }
80
+ /**
81
+ * The types the schema consists of, collected the way graphql-js collects them (`GraphQLSchema` constructor):
82
+ * `includedTypes` first, then everything `roots` reach, depth-first. The order is what introspection and the
83
+ * printed schema list, so it stays the order graphql-js produced. Providers create some types speculatively
84
+ * (e.g. an input that the allowed operations then filter out); unreachable ones are left out.
85
+ * Returns a new record: deleting from a large object would turn it into a slow dictionary.
86
+ * Yields after each collected type.
87
+ */
88
+ *collectReachableTypes(includedTypes, roots, otherTypes) {
89
+ const reachable = new Set(includedTypes);
90
+ const getType = (name) => this.types[name] ?? otherTypes[name];
91
+ const collect = function* (name) {
92
+ const names = [[name]];
93
+ const positions = [0];
94
+ while (names.length > 0) {
95
+ const top = names.length - 1;
96
+ const next = names[top][positions[top]++];
97
+ if (next === void 0) {
98
+ names.pop();
99
+ positions.pop();
100
+ continue;
101
+ }
102
+ const type = reachable.has(next) ? void 0 : getType(next);
103
+ if (!type) {
104
+ continue;
105
+ }
106
+ reachable.add(next);
107
+ names.push(getReferencedTypes(type));
108
+ positions.push(0);
109
+ yield;
110
+ }
111
+ };
112
+ for (const name of includedTypes) {
113
+ reachable.delete(name);
114
+ yield* collect(name);
115
+ }
116
+ for (const root of roots) {
117
+ yield* collect(root);
118
+ }
119
+ const types = {};
120
+ for (const name of reachable) {
121
+ const type = getType(name);
122
+ if (!type) {
123
+ continue;
124
+ }
125
+ if (type[0] === TypeKind.INTERFACE && type[3].some((it) => !reachable.has(it))) {
126
+ const possibleTypes = type[3].filter((it) => reachable.has(it));
127
+ types[name] = type[4] !== void 0 ? [TypeKind.INTERFACE, type[1], type[2], possibleTypes, type[4]] : [TypeKind.INTERFACE, type[1], type[2], possibleTypes];
128
+ } else {
129
+ types[name] = type;
130
+ }
131
+ }
132
+ return types;
133
+ }
134
+ addPossibleType(interfaceName, typeName) {
135
+ const interfaceType = this.types[interfaceName];
136
+ if (!interfaceType || interfaceType[0] !== TypeKind.INTERFACE) {
137
+ throw new Error(`Interface ${interfaceName} must be registered before ${typeName}`);
138
+ }
139
+ interfaceType[3].push(typeName);
140
+ }
141
+ addOutputFields(typeName, target, fields) {
142
+ var _a, _b, _c, _d;
143
+ for (const [fieldName, field] of Object.entries(fields)) {
144
+ target[fieldName] = field.deprecationReason !== void 0 ? [field.type, field.args ?? null, field.description, field.deprecationReason] : field.description !== void 0 ? [field.type, field.args ?? null, field.description] : [field.type, field.args ?? null];
145
+ if (field.resolve) {
146
+ (_b = (_a = this.resolvers)[typeName] ?? (_a[typeName] = {}))[fieldName] ?? (_b[fieldName] = field.resolve);
147
+ }
148
+ if (field.extensions) {
149
+ (_d = (_c = this.extensions)[typeName] ?? (_c[typeName] = {}))[fieldName] ?? (_d[fieldName] = field.extensions);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ const getReferencedTypes = (type) => {
155
+ const names = [];
156
+ switch (type[0]) {
157
+ case TypeKind.OBJECT:
158
+ case TypeKind.INTERFACE:
159
+ names.push(...type[2]);
160
+ for (const fieldName in type[1]) {
161
+ const field = type[1][fieldName];
162
+ if (!field) {
163
+ continue;
164
+ }
165
+ names.push(field[0][1]);
166
+ for (const argName in field[1]) {
167
+ const arg = field[1][argName];
168
+ if (arg) {
169
+ names.push(arg[0][1]);
170
+ }
171
+ }
172
+ }
173
+ break;
174
+ case TypeKind.UNION:
175
+ names.push(...type[1]);
176
+ break;
177
+ case TypeKind.INPUT_OBJECT:
178
+ for (const fieldName in type[1]) {
179
+ const field = type[1][fieldName];
180
+ if (field) {
181
+ names.push(field[0][1]);
182
+ }
183
+ }
184
+ break;
185
+ }
186
+ return names;
187
+ };
188
+ const inputField = (type, description) => description !== void 0 ? [type, void 0, description] : [type];
189
+ const TypeRefPattern = {
190
+ named: 0,
191
+ // T
192
+ nonNull: 1,
193
+ // T!
194
+ list: 2,
195
+ // [T]
196
+ listOfNonNull: 3,
197
+ // [T!]
198
+ nonNullListOfNonNull: 5,
199
+ // [T!]!
200
+ nonNullListOfNonNullListOfNonNull: 13
201
+ // [[T!]!]!
202
+ };
203
+ const namedRef = (name) => [TypeRefPattern.named, name];
204
+ const nonNullRef = (name) => [TypeRefPattern.nonNull, name];
205
+ const listRef = (name) => [TypeRefPattern.list, name];
206
+ const listOfNonNullRef = (name) => [TypeRefPattern.listOfNonNull, name];
207
+ const nonNullListOfNonNullRef = (name) => [TypeRefPattern.nonNullListOfNonNull, name];
208
+ const nonNullListOfNonNullListOfNonNullRef = (name) => [TypeRefPattern.nonNullListOfNonNullListOfNonNull, name];
209
+ const toNonNull = (ref) => {
210
+ switch (ref[0]) {
211
+ case TypeRefPattern.named:
212
+ return [TypeRefPattern.nonNull, ref[1]];
213
+ case TypeRefPattern.listOfNonNull:
214
+ return [TypeRefPattern.nonNullListOfNonNull, ref[1]];
215
+ default:
216
+ throw new Error(`Cannot wrap type ref pattern ${ref[0]} in non-null`);
217
+ }
218
+ };
219
+ export {
220
+ JsonTypeRegistry,
221
+ inputField,
222
+ listOfNonNullRef,
223
+ listRef,
224
+ namedRef,
225
+ nonNullListOfNonNullListOfNonNullRef,
226
+ nonNullListOfNonNullRef,
227
+ nonNullRef,
228
+ toNonNull
229
+ };
230
+ //# sourceMappingURL=JsonTypeRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonTypeRegistry.js","sources":["../../../../../packages/engine-content-api/src/schema-json/JsonTypeRegistry.ts"],"sourcesContent":["import {\n\tArgument,\n\tEnumValue,\n\tField,\n\tInputField,\n\tisSpecifiedScalarTypeName,\n\tResolverFn,\n\tResolverMap,\n\tScalarImplementation,\n\tspecifiedScalarTypes,\n\tType,\n\tTypeKind,\n\tTypeRef,\n} from '@contember/graphql-json'\nimport { Context } from '../types.js'\n\nexport type FieldExtensions = Record<string, unknown>\n\nexport interface JsonOutputField {\n\ttype: TypeRef\n\targs?: Record<string, Argument>\n\tresolve?: ResolverFn<unknown, Context>\n\textensions?: FieldExtensions\n\tdescription?: string\n\tdeprecationReason?: string\n}\n\n/**\n * Collects the JSON types of one content schema. Types are referenced by name, so a type is registered before its\n * fields are created - a recursive reference (e.g. `Where.and`) then only resolves the name.\n * Fields are created later, by `fillPending`: one type at a time, so that a build can pause between them instead of\n * running the whole graph a single entity reaches in one go.\n * Resolvers, field extensions and scalars go to maps shared by all schemas of the model; the first registration wins.\n */\nexport class JsonTypeRegistry {\n\tpublic readonly types: Record<string, Type> = {}\n\tprivate readonly pending: (() => void)[] = []\n\n\tconstructor(\n\t\tpublic readonly resolvers: ResolverMap<Context>,\n\t\tpublic readonly extensions: Record<string, Record<string, FieldExtensions>>,\n\t\tpublic readonly scalars: Record<string, ScalarImplementation>,\n\t) {}\n\n\tpublic has(name: string): boolean {\n\t\treturn name in this.types\n\t}\n\n\tpublic object(\n\t\tname: string,\n\t\tcreateFields: () => Record<string, JsonOutputField>,\n\t\tinterfaces: string[] = [],\n\t\tdescription?: string,\n\t): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, Field> = {}\n\t\tthis.types[name] = description !== undefined ? [TypeKind.OBJECT, fields, interfaces, description] : [TypeKind.OBJECT, fields, interfaces]\n\t\tfor (const interfaceName of interfaces) {\n\t\t\tthis.addPossibleType(interfaceName, name)\n\t\t}\n\t\tthis.pending.push(() => this.addOutputFields(name, fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic interface(name: string, createFields: () => Record<string, JsonOutputField>): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, Field> = {}\n\t\tthis.types[name] = [TypeKind.INTERFACE, fields, [], []]\n\t\tthis.pending.push(() => this.addOutputFields(name, fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic union(name: string, possibleTypes: string[]): string {\n\t\tif (!this.types[name]) {\n\t\t\tthis.types[name] = [TypeKind.UNION, possibleTypes]\n\t\t}\n\t\treturn name\n\t}\n\n\tpublic inputObject(name: string, createFields: () => Record<string, InputField>): string {\n\t\tif (this.types[name]) {\n\t\t\treturn name\n\t\t}\n\t\tconst fields: Record<string, InputField> = {}\n\t\tthis.types[name] = [TypeKind.INPUT_OBJECT, fields]\n\t\tthis.pending.push(() => Object.assign(fields, createFields()))\n\t\treturn name\n\t}\n\n\tpublic enum(name: string, values: readonly string[]): string {\n\t\tif (!this.types[name]) {\n\t\t\tconst enumValues: Record<string, EnumValue> = {}\n\t\t\tfor (const value of values) {\n\t\t\t\tenumValues[value] = [value]\n\t\t\t}\n\t\t\tthis.types[name] = [TypeKind.ENUM, enumValues]\n\t\t}\n\t\treturn name\n\t}\n\n\tpublic scalar(name: string, implementation: ScalarImplementation | undefined, description?: string): string {\n\t\tif (!this.types[name]) {\n\t\t\tthis.types[name] = isSpecifiedScalarTypeName(name)\n\t\t\t\t? specifiedScalarTypes[name]\n\t\t\t\t: description !== undefined\n\t\t\t\t? [TypeKind.SCALAR, description]\n\t\t\t\t: [TypeKind.SCALAR]\n\t\t}\n\t\tif (implementation) {\n\t\t\tthis.scalars[name] ??= implementation\n\t\t}\n\t\treturn name\n\t}\n\n\t/** Creates the fields of the registered types, including the types that creates; yields after each type. */\n\tpublic *fillPending(): Generator<void, void> {\n\t\t// the queue grows while it is processed\n\t\tfor (let i = 0; i < this.pending.length; i++) {\n\t\t\tthis.pending[i]()\n\t\t\tyield\n\t\t}\n\t\tthis.pending.length = 0\n\t}\n\n\t/**\n\t * The types the schema consists of, collected the way graphql-js collects them (`GraphQLSchema` constructor):\n\t * `includedTypes` first, then everything `roots` reach, depth-first. The order is what introspection and the\n\t * printed schema list, so it stays the order graphql-js produced. Providers create some types speculatively\n\t * (e.g. an input that the allowed operations then filter out); unreachable ones are left out.\n\t * Returns a new record: deleting from a large object would turn it into a slow dictionary.\n\t * Yields after each collected type.\n\t */\n\tpublic *collectReachableTypes(\n\t\tincludedTypes: readonly string[],\n\t\troots: readonly string[],\n\t\totherTypes: Record<string, Type>,\n\t): Generator<void, Record<string, Type>> {\n\t\tconst reachable = new Set<string>(includedTypes)\n\t\tconst getType = (name: string): Type | undefined => this.types[name] ?? otherTypes[name]\n\t\t// an explicit stack instead of recursion keeps the pre-order of a recursive walk and can pause after any type\n\t\tconst collect = function*(name: string): Generator<void, void> {\n\t\t\tconst names: (readonly string[])[] = [[name]]\n\t\t\tconst positions: number[] = [0]\n\t\t\twhile (names.length > 0) {\n\t\t\t\tconst top = names.length - 1\n\t\t\t\tconst next = names[top][positions[top]++]\n\t\t\t\tif (next === undefined) {\n\t\t\t\t\tnames.pop()\n\t\t\t\t\tpositions.pop()\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst type = reachable.has(next) ? undefined : getType(next)\n\t\t\t\tif (!type) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treachable.add(next)\n\t\t\t\tnames.push(getReferencedTypes(type))\n\t\t\t\tpositions.push(0)\n\t\t\t\tyield\n\t\t\t}\n\t\t}\n\t\t// graphql-js seeds the set with the included types and re-adds each one, which moves it to the end\n\t\tfor (const name of includedTypes) {\n\t\t\treachable.delete(name)\n\t\t\tyield* collect(name)\n\t\t}\n\t\tfor (const root of roots) {\n\t\t\tyield* collect(root)\n\t\t}\n\n\t\tconst types: Record<string, Type> = {}\n\t\tfor (const name of reachable) {\n\t\t\tconst type = getType(name)\n\t\t\tif (!type) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// replaced, not mutated: extension types are shared between schemas\n\t\t\tif (type[0] === TypeKind.INTERFACE && type[3].some(it => !reachable.has(it))) {\n\t\t\t\tconst possibleTypes = type[3].filter(it => reachable.has(it))\n\t\t\t\ttypes[name] = type[4] !== undefined\n\t\t\t\t\t? [TypeKind.INTERFACE, type[1], type[2], possibleTypes, type[4]]\n\t\t\t\t\t: [TypeKind.INTERFACE, type[1], type[2], possibleTypes]\n\t\t\t} else {\n\t\t\t\ttypes[name] = type\n\t\t\t}\n\t\t}\n\t\treturn types\n\t}\n\n\tprivate addPossibleType(interfaceName: string, typeName: string): void {\n\t\tconst interfaceType = this.types[interfaceName]\n\t\tif (!interfaceType || interfaceType[0] !== TypeKind.INTERFACE) {\n\t\t\tthrow new Error(`Interface ${interfaceName} must be registered before ${typeName}`)\n\t\t}\n\t\tinterfaceType[3].push(typeName)\n\t}\n\n\tprivate addOutputFields(typeName: string, target: Record<string, Field>, fields: Record<string, JsonOutputField>): void {\n\t\tfor (const [fieldName, field] of Object.entries(fields)) {\n\t\t\ttarget[fieldName] = field.deprecationReason !== undefined\n\t\t\t\t? [field.type, field.args ?? null, field.description, field.deprecationReason]\n\t\t\t\t: field.description !== undefined\n\t\t\t\t? [field.type, field.args ?? null, field.description]\n\t\t\t\t: [field.type, field.args ?? null]\n\t\t\tif (field.resolve) {\n\t\t\t\t;(this.resolvers[typeName] ??= {})[fieldName] ??= field.resolve\n\t\t\t}\n\t\t\tif (field.extensions) {\n\t\t\t\t;(this.extensions[typeName] ??= {})[fieldName] ??= field.extensions\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** The names a type refers to, in the order graphql-js visits them: interfaces, then each field's type and arguments. */\nconst getReferencedTypes = (type: Type): string[] => {\n\tconst names: string[] = []\n\tswitch (type[0]) {\n\t\tcase TypeKind.OBJECT:\n\t\tcase TypeKind.INTERFACE:\n\t\t\tnames.push(...type[2])\n\t\t\tfor (const fieldName in type[1]) {\n\t\t\t\tconst field = type[1][fieldName]\n\t\t\t\tif (!field) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tnames.push(field[0][1])\n\t\t\t\tfor (const argName in field[1]) {\n\t\t\t\t\tconst arg = field[1][argName]\n\t\t\t\t\tif (arg) {\n\t\t\t\t\t\tnames.push(arg[0][1])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t\tcase TypeKind.UNION:\n\t\t\tnames.push(...type[1])\n\t\t\tbreak\n\t\tcase TypeKind.INPUT_OBJECT:\n\t\t\tfor (const fieldName in type[1]) {\n\t\t\t\tconst field = type[1][fieldName]\n\t\t\t\tif (field) {\n\t\t\t\t\tnames.push(field[0][1])\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak\n\t}\n\treturn names\n}\n\n/** An input field without a default value; the description is left out of the tuple when there is none. */\nexport const inputField = (type: TypeRef, description: string | undefined): InputField =>\n\tdescription !== undefined ? [type, undefined, description] : [type]\n\n/** Wrap patterns of graphql-json `TypeRef`, named after the SDL they produce. */\nconst TypeRefPattern = {\n\tnamed: 0, // T\n\tnonNull: 1, // T!\n\tlist: 2, // [T]\n\tlistOfNonNull: 3, // [T!]\n\tnonNullListOfNonNull: 5, // [T!]!\n\tnonNullListOfNonNullListOfNonNull: 13, // [[T!]!]!\n} as const\n\nexport const namedRef = (name: string): TypeRef => [TypeRefPattern.named, name]\nexport const nonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNull, name]\nexport const listRef = (name: string): TypeRef => [TypeRefPattern.list, name]\nexport const listOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.listOfNonNull, name]\nexport const nonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNull, name]\nexport const nonNullListOfNonNullListOfNonNullRef = (name: string): TypeRef => [TypeRefPattern.nonNullListOfNonNullListOfNonNull, name]\n\n/** `T` → `T!`, `[T!]` → `[T!]!` */\nexport const toNonNull = (ref: TypeRef): TypeRef => {\n\tswitch (ref[0]) {\n\t\tcase TypeRefPattern.named:\n\t\t\treturn [TypeRefPattern.nonNull, ref[1]]\n\t\tcase TypeRefPattern.listOfNonNull:\n\t\t\treturn [TypeRefPattern.nonNullListOfNonNull, ref[1]]\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot wrap type ref pattern ${ref[0]} in non-null`)\n\t}\n}\n"],"names":[],"mappings":";;;;AAkCO,MAAM,iBAAiB;AAAA,EAI7B,YACiB,WACA,YACA,SACf;AAHe,SAAA,YAAA;AACA,SAAA,aAAA;AACA,SAAA,UAAA;AANjB,kBAAA,MAAgB,SAA8B,EAAC;AAC/C,kBAAA,MAAiB,WAA0B,EAAC;AAAA,EAMzC;AAAA,EAEI,IAAI,MAAuB;AACjC,WAAO,QAAQ,KAAK;AAAA,EACrB;AAAA,EAEO,OACN,MACA,cACA,aAAuB,CAAA,GACvB,aACS;AACT,QAAI,KAAK,MAAM,IAAI,GAAG;AACrB,aAAO;AAAA,IACR;AACA,UAAM,SAAgC,CAAA;AACtC,SAAK,MAAM,IAAI,IAAI,gBAAgB,SAAY,CAAC,SAAS,QAAQ,QAAQ,YAAY,WAAW,IAAI,CAAC,SAAS,QAAQ,QAAQ,UAAU;AACxI,eAAW,iBAAiB,YAAY;AACvC,WAAK,gBAAgB,eAAe,IAAI;AAAA,IACzC;AACA,SAAK,QAAQ,KAAK,MAAM,KAAK,gBAAgB,MAAM,QAAQ,aAAA,CAAc,CAAC;AAC1E,WAAO;AAAA,EACR;AAAA,EAEO,UAAU,MAAc,cAA6D;AAC3F,QAAI,KAAK,MAAM,IAAI,GAAG;AACrB,aAAO;AAAA,IACR;AACA,UAAM,SAAg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SAA0B,CAAC,eAAe,SAAS,IAAI;AAC3E,MAAM,UAAU,CAAC,SAA0B,CAAC,eAAe,MAAM,IAAI;AACrE,MAAM,mBAAmB,CAAC,SAA0B,CAAC,eAAe,eAAe,IAAI;AACvF,MAAM,0BAA0B,CAAC,SAA0B,CAAC,eAAe,sBAAsB,IAAI;AACrG,MAAM,uCAAuC,CAAC,SAA0B,CAAC,eAAe,mCAAmC,IAAI;AAG/H,MAAM,YAAY,CAAC,QAA0B;AACnD,UAAQ,IAAI,CAAC,GAAA;AAAA,IACZ,KAAK,eAAe;AACnB,aAAO,CAAC,eAAe,SAAS,IAAI,CAAC,CAAC;AAAA,IACvC,KAAK,eAAe;AACnB,aAAO,CAAC,eAAe,sBAAsB,IAAI,CAAC,CAAC;AAAA,IACpD;AACC,YAAM,IAAI,MAAM,gCAAgC,IAAI,CAAC,CAAC,cAAc;AAAA,EAAA;AAEvE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ResolveInfoUtils.cjs","sources":["../../../../../packages/engine-content-api/src/utils/ResolveInfoUtils.ts"],"sourcesContent":["import { FieldNode as GraphQlFieldNode, GraphQLResolveInfo, SelectionSetNode } from 'graphql'\n\nexport class ResolveInfoUtils {\n\tpublic static extractFieldNode(info: GraphQLResolveInfo): GraphQlFieldNode {\n\t\tconst newGraphQlFieldNodes = [...info.fieldNodes]\n\t\twhile (newGraphQlFieldNodes.length > 1) {\n\t\t\tnewGraphQlFieldNodes.push(\n\t\t\t\tResolveInfoUtils.mergeFieldNodes(\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn newGraphQlFieldNodes[0]\n\t}\n\n\tprivate static mergeFieldNodes(dest: GraphQlFieldNode, src: GraphQlFieldNode): GraphQlFieldNode {\n\t\treturn {\n\t\t\t...dest,\n\t\t\tselectionSet: {\n\t\t\t\t...(dest.selectionSet as SelectionSetNode),\n\t\t\t\tselections: [\n\t\t\t\t\t...(dest.selectionSet ? dest.selectionSet.selections : []),\n\t\t\t\t\t...(src.selectionSet ? src.selectionSet.selections : []),\n\t\t\t\t],\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,iBAAiB,MAA4C;AAC1E,UAAM,uBAAuB,CAAC,GAAG,KAAK,UAAU;AAChD,WAAO,qBAAqB,SAAS,GAAG;AACvC,2BAAqB;AAAA,QACpB,iBAAiB;AAAA,UAChB,qBAAqB,IAAA;AAAA,UACrB,qBAAqB,IAAA;AAAA,QAAI;AAAA,MAC1B;AAAA,IAEF;AACA,WAAO,qBAAqB,CAAC;AAAA,EAC9B;AAAA,EAEA,OAAe,gBAAgB,MAAwB,KAAyC;AAC/F,WAAO;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAI,KAAK;AAAA,QACT,YAAY;AAAA,UACX,GAAI,KAAK,eAAe,KAAK,aAAa,aAAa,CAAA;AAAA,UACvD,GAAI,IAAI,eAAe,IAAI,aAAa,aAAa,CAAA;AAAA,QAAC;AAAA,MACvD;AAAA,IACD;AAAA,EAEF;AACD;;"}
1
+ {"version":3,"file":"ResolveInfoUtils.cjs","sources":["../../../../../packages/engine-content-api/src/utils/ResolveInfoUtils.ts"],"sourcesContent":["import { FieldNode as GraphQlFieldNode, SelectionSetNode } from 'graphql'\n\nexport class ResolveInfoUtils {\n\tpublic static extractFieldNode(info: { readonly fieldNodes: readonly GraphQlFieldNode[] }): GraphQlFieldNode {\n\t\tconst newGraphQlFieldNodes = [...info.fieldNodes]\n\t\twhile (newGraphQlFieldNodes.length > 1) {\n\t\t\tnewGraphQlFieldNodes.push(\n\t\t\t\tResolveInfoUtils.mergeFieldNodes(\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn newGraphQlFieldNodes[0]\n\t}\n\n\tprivate static mergeFieldNodes(dest: GraphQlFieldNode, src: GraphQlFieldNode): GraphQlFieldNode {\n\t\treturn {\n\t\t\t...dest,\n\t\t\tselectionSet: {\n\t\t\t\t...(dest.selectionSet as SelectionSetNode),\n\t\t\t\tselections: [\n\t\t\t\t\t...(dest.selectionSet ? dest.selectionSet.selections : []),\n\t\t\t\t\t...(src.selectionSet ? src.selectionSet.selections : []),\n\t\t\t\t],\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,iBAAiB,MAA8E;AAC5G,UAAM,uBAAuB,CAAC,GAAG,KAAK,UAAU;AAChD,WAAO,qBAAqB,SAAS,GAAG;AACvC,2BAAqB;AAAA,QACpB,iBAAiB;AAAA,UAChB,qBAAqB,IAAA;AAAA,UACrB,qBAAqB,IAAA;AAAA,QAAI;AAAA,MAC1B;AAAA,IAEF;AACA,WAAO,qBAAqB,CAAC;AAAA,EAC9B;AAAA,EAEA,OAAe,gBAAgB,MAAwB,KAAyC;AAC/F,WAAO;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAI,KAAK;AAAA,QACT,YAAY;AAAA,UACX,GAAI,KAAK,eAAe,KAAK,aAAa,aAAa,CAAA;AAAA,UACvD,GAAI,IAAI,eAAe,IAAI,aAAa,aAAa,CAAA;AAAA,QAAC;AAAA,MACvD;AAAA,IACD;AAAA,EAEF;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ResolveInfoUtils.js","sources":["../../../../../packages/engine-content-api/src/utils/ResolveInfoUtils.ts"],"sourcesContent":["import { FieldNode as GraphQlFieldNode, GraphQLResolveInfo, SelectionSetNode } from 'graphql'\n\nexport class ResolveInfoUtils {\n\tpublic static extractFieldNode(info: GraphQLResolveInfo): GraphQlFieldNode {\n\t\tconst newGraphQlFieldNodes = [...info.fieldNodes]\n\t\twhile (newGraphQlFieldNodes.length > 1) {\n\t\t\tnewGraphQlFieldNodes.push(\n\t\t\t\tResolveInfoUtils.mergeFieldNodes(\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn newGraphQlFieldNodes[0]\n\t}\n\n\tprivate static mergeFieldNodes(dest: GraphQlFieldNode, src: GraphQlFieldNode): GraphQlFieldNode {\n\t\treturn {\n\t\t\t...dest,\n\t\t\tselectionSet: {\n\t\t\t\t...(dest.selectionSet as SelectionSetNode),\n\t\t\t\tselections: [\n\t\t\t\t\t...(dest.selectionSet ? dest.selectionSet.selections : []),\n\t\t\t\t\t...(src.selectionSet ? src.selectionSet.selections : []),\n\t\t\t\t],\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,iBAAiB,MAA4C;AAC1E,UAAM,uBAAuB,CAAC,GAAG,KAAK,UAAU;AAChD,WAAO,qBAAqB,SAAS,GAAG;AACvC,2BAAqB;AAAA,QACpB,iBAAiB;AAAA,UAChB,qBAAqB,IAAA;AAAA,UACrB,qBAAqB,IAAA;AAAA,QAAI;AAAA,MAC1B;AAAA,IAEF;AACA,WAAO,qBAAqB,CAAC;AAAA,EAC9B;AAAA,EAEA,OAAe,gBAAgB,MAAwB,KAAyC;AAC/F,WAAO;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAI,KAAK;AAAA,QACT,YAAY;AAAA,UACX,GAAI,KAAK,eAAe,KAAK,aAAa,aAAa,CAAA;AAAA,UACvD,GAAI,IAAI,eAAe,IAAI,aAAa,aAAa,CAAA;AAAA,QAAC;AAAA,MACvD;AAAA,IACD;AAAA,EAEF;AACD;"}
1
+ {"version":3,"file":"ResolveInfoUtils.js","sources":["../../../../../packages/engine-content-api/src/utils/ResolveInfoUtils.ts"],"sourcesContent":["import { FieldNode as GraphQlFieldNode, SelectionSetNode } from 'graphql'\n\nexport class ResolveInfoUtils {\n\tpublic static extractFieldNode(info: { readonly fieldNodes: readonly GraphQlFieldNode[] }): GraphQlFieldNode {\n\t\tconst newGraphQlFieldNodes = [...info.fieldNodes]\n\t\twhile (newGraphQlFieldNodes.length > 1) {\n\t\t\tnewGraphQlFieldNodes.push(\n\t\t\t\tResolveInfoUtils.mergeFieldNodes(\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t\tnewGraphQlFieldNodes.pop() as GraphQlFieldNode,\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\t\treturn newGraphQlFieldNodes[0]\n\t}\n\n\tprivate static mergeFieldNodes(dest: GraphQlFieldNode, src: GraphQlFieldNode): GraphQlFieldNode {\n\t\treturn {\n\t\t\t...dest,\n\t\t\tselectionSet: {\n\t\t\t\t...(dest.selectionSet as SelectionSetNode),\n\t\t\t\tselections: [\n\t\t\t\t\t...(dest.selectionSet ? dest.selectionSet.selections : []),\n\t\t\t\t\t...(src.selectionSet ? src.selectionSet.selections : []),\n\t\t\t\t],\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,iBAAiB,MAA8E;AAC5G,UAAM,uBAAuB,CAAC,GAAG,KAAK,UAAU;AAChD,WAAO,qBAAqB,SAAS,GAAG;AACvC,2BAAqB;AAAA,QACpB,iBAAiB;AAAA,UAChB,qBAAqB,IAAA;AAAA,UACrB,qBAAqB,IAAA;AAAA,QAAI;AAAA,MAC1B;AAAA,IAEF;AACA,WAAO,qBAAqB,CAAC;AAAA,EAC9B;AAAA,EAEA,OAAe,gBAAgB,MAAwB,KAAyC;AAC/F,WAAO;AAAA,MACN,GAAG;AAAA,MACH,cAAc;AAAA,QACb,GAAI,KAAK;AAAA,QACT,YAAY;AAAA,UACX,GAAI,KAAK,eAAe,KAAK,aAAa,aAAa,CAAA;AAAA,UACvD,GAAI,IAAI,eAAe,IAAI,aAAa,aAAa,CAAA;AAAA,QAAC;AAAA,MACvD;AAAA,IACD;AAAA,EAEF;AACD;"}
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schemaUtils = require("@contember/schema-utils");
4
+ const uniqueWhereFields = /* @__PURE__ */ new WeakMap();
4
5
  const getFieldsForUniqueWhere = (schema, entity) => {
6
+ const cached = uniqueWhereFields.get(entity);
7
+ if (cached) {
8
+ return cached;
9
+ }
10
+ const fields = createFieldsForUniqueWhere(schema, entity);
11
+ uniqueWhereFields.set(entity, fields);
12
+ return fields;
13
+ };
14
+ const createFieldsForUniqueWhere = (schema, entity) => {
5
15
  const relations = Object.values(
6
16
  schemaUtils.acceptEveryFieldVisitor(schema, entity, {
7
17
  visitColumn: () => void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"uniqueWhereFields.cjs","sources":["../../../../../packages/engine-content-api/src/utils/uniqueWhereFields.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { Model } from '@contember/schema'\n\ntype SingleUnique = readonly string[]\nexport const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...entity.unique.map(it => it.fields), ...relations]\n}\n"],"names":["acceptEveryFieldVisitor"],"mappings":";;;AAIO,MAAM,0BAA0B,CAAC,QAAsB,WAAoD;AACjH,QAAM,YAAY,OAAO;AAAA,IACxBA,YAAAA,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,EAAA,EACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC9E;;"}
1
+ {"version":3,"file":"uniqueWhereFields.cjs","sources":["../../../../../packages/engine-content-api/src/utils/uniqueWhereFields.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { Model } from '@contember/schema'\n\ntype SingleUnique = readonly string[]\n\n// depends on the entity alone; schema builds ask for it per relation and role, requests per unique where\nconst uniqueWhereFields = new WeakMap<Model.Entity, readonly SingleUnique[]>()\n\nexport const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst cached = uniqueWhereFields.get(entity)\n\tif (cached) {\n\t\treturn cached\n\t}\n\tconst fields = createFieldsForUniqueWhere(schema, entity)\n\tuniqueWhereFields.set(entity, fields)\n\treturn fields\n}\n\nconst createFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...entity.unique.map(it => it.fields), ...relations]\n}\n"],"names":["acceptEveryFieldVisitor"],"mappings":";;;AAMA,MAAM,wCAAwB,QAAA;AAEvB,MAAM,0BAA0B,CAAC,QAAsB,WAAoD;AACjH,QAAM,SAAS,kBAAkB,IAAI,MAAM;AAC3C,MAAI,QAAQ;AACX,WAAO;AAAA,EACR;AACA,QAAM,SAAS,2BAA2B,QAAQ,MAAM;AACxD,oBAAkB,IAAI,QAAQ,MAAM;AACpC,SAAO;AACR;AAEA,MAAM,6BAA6B,CAAC,QAAsB,WAAoD;AAC7G,QAAM,YAAY,OAAO;AAAA,IACxBA,YAAAA,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,EAAA,EACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC9E;;"}
@@ -1,5 +1,15 @@
1
1
  import { acceptEveryFieldVisitor } from "@contember/schema-utils";
2
+ const uniqueWhereFields = /* @__PURE__ */ new WeakMap();
2
3
  const getFieldsForUniqueWhere = (schema, entity) => {
4
+ const cached = uniqueWhereFields.get(entity);
5
+ if (cached) {
6
+ return cached;
7
+ }
8
+ const fields = createFieldsForUniqueWhere(schema, entity);
9
+ uniqueWhereFields.set(entity, fields);
10
+ return fields;
11
+ };
12
+ const createFieldsForUniqueWhere = (schema, entity) => {
3
13
  const relations = Object.values(
4
14
  acceptEveryFieldVisitor(schema, entity, {
5
15
  visitColumn: () => void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"uniqueWhereFields.js","sources":["../../../../../packages/engine-content-api/src/utils/uniqueWhereFields.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { Model } from '@contember/schema'\n\ntype SingleUnique = readonly string[]\nexport const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...entity.unique.map(it => it.fields), ...relations]\n}\n"],"names":[],"mappings":";AAIO,MAAM,0BAA0B,CAAC,QAAsB,WAAoD;AACjH,QAAM,YAAY,OAAO;AAAA,IACxB,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,EAAA,EACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC9E;"}
1
+ {"version":3,"file":"uniqueWhereFields.js","sources":["../../../../../packages/engine-content-api/src/utils/uniqueWhereFields.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { Model } from '@contember/schema'\n\ntype SingleUnique = readonly string[]\n\n// depends on the entity alone; schema builds ask for it per relation and role, requests per unique where\nconst uniqueWhereFields = new WeakMap<Model.Entity, readonly SingleUnique[]>()\n\nexport const getFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst cached = uniqueWhereFields.get(entity)\n\tif (cached) {\n\t\treturn cached\n\t}\n\tconst fields = createFieldsForUniqueWhere(schema, entity)\n\tuniqueWhereFields.set(entity, fields)\n\treturn fields\n}\n\nconst createFieldsForUniqueWhere = (schema: Model.Schema, entity: Model.Entity): readonly (SingleUnique)[] => {\n\tconst relations = Object.values(\n\t\tacceptEveryFieldVisitor<undefined | [string]>(schema, entity, {\n\t\t\tvisitColumn: () => undefined,\n\t\t\tvisitManyHasManyInverse: () => undefined,\n\t\t\tvisitManyHasManyOwning: () => undefined,\n\t\t\tvisitOneHasMany: ({ relation }) => [relation.name],\n\t\t\tvisitManyHasOne: () => undefined,\n\t\t\tvisitOneHasOneInverse: ({ relation }) => [relation.name],\n\t\t\tvisitOneHasOneOwning: ({ relation }) => [relation.name],\n\t\t}),\n\t).filter((it): it is [string] => !!it)\n\n\treturn [[entity.primary], ...entity.unique.map(it => it.fields), ...relations]\n}\n"],"names":[],"mappings":";AAMA,MAAM,wCAAwB,QAAA;AAEvB,MAAM,0BAA0B,CAAC,QAAsB,WAAoD;AACjH,QAAM,SAAS,kBAAkB,IAAI,MAAM;AAC3C,MAAI,QAAQ;AACX,WAAO;AAAA,EACR;AACA,QAAM,SAAS,2BAA2B,QAAQ,MAAM;AACxD,oBAAkB,IAAI,QAAQ,MAAM;AACpC,SAAO;AACR;AAEA,MAAM,6BAA6B,CAAC,QAAsB,WAAoD;AAC7G,QAAM,YAAY,OAAO;AAAA,IACxB,wBAA8C,QAAQ,QAAQ;AAAA,MAC7D,aAAa,MAAM;AAAA,MACnB,yBAAyB,MAAM;AAAA,MAC/B,wBAAwB,MAAM;AAAA,MAC9B,iBAAiB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACjD,iBAAiB,MAAM;AAAA,MACvB,uBAAuB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,MACvD,sBAAsB,CAAC,EAAE,eAAe,CAAC,SAAS,IAAI;AAAA,IAAA,CACtD;AAAA,EAAA,EACA,OAAO,CAAC,OAAuB,CAAC,CAAC,EAAE;AAErC,SAAO,CAAC,CAAC,OAAO,OAAO,GAAG,GAAG,OAAO,OAAO,IAAI,CAAA,OAAM,GAAG,MAAM,GAAG,GAAG,SAAS;AAC9E;"}