@takeshape/schema 12.1.1 → 12.1.5

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 (514) hide show
  1. package/dist/agents.d.ts +62 -0
  2. package/dist/agents.js +346 -0
  3. package/dist/api-version.d.ts +5 -0
  4. package/dist/api-version.js +17 -0
  5. package/dist/auth-schemas.d.ts +144 -0
  6. package/dist/auth-schemas.js +7 -0
  7. package/dist/auth-utils.d.ts +19 -0
  8. package/dist/auth-utils.js +26 -0
  9. package/dist/builtin-schema.d.ts +18 -0
  10. package/dist/builtin-schema.js +710 -0
  11. package/dist/constants.d.ts +1 -0
  12. package/dist/constants.js +1 -0
  13. package/dist/content-schema-transform.d.ts +35 -0
  14. package/dist/content-schema-transform.js +162 -0
  15. package/dist/create-input-schema.d.ts +9 -0
  16. package/dist/create-input-schema.js +68 -0
  17. package/dist/enum.d.ts +2 -0
  18. package/dist/enum.js +9 -0
  19. package/dist/flatten-templates.d.ts +2 -0
  20. package/dist/flatten-templates.js +20 -0
  21. package/dist/get-is-leaf.d.ts +3 -0
  22. package/dist/get-is-leaf.js +56 -0
  23. package/dist/index.d.ts +64 -0
  24. package/dist/index.js +61 -0
  25. package/dist/interfaces.d.ts +14 -0
  26. package/dist/interfaces.js +86 -0
  27. package/dist/layers/layers.d.ts +26 -0
  28. package/dist/layers/layers.js +301 -0
  29. package/dist/layers/refs.d.ts +102 -0
  30. package/dist/layers/refs.js +220 -0
  31. package/dist/layers/type-utils.d.ts +59 -0
  32. package/dist/layers/type-utils.js +118 -0
  33. package/dist/layers/visitor.d.ts +5 -0
  34. package/dist/layers/visitor.js +38 -0
  35. package/dist/migration/index.d.ts +79 -0
  36. package/dist/migration/index.js +110 -0
  37. package/dist/migration/to/v3.0.0.d.ts +4 -0
  38. package/dist/migration/to/v3.0.0.js +212 -0
  39. package/dist/migration/to/v3.1.0.d.ts +4 -0
  40. package/dist/migration/to/v3.1.0.js +194 -0
  41. package/dist/migration/to/v3.10.0.d.ts +4 -0
  42. package/dist/migration/to/v3.10.0.js +67 -0
  43. package/dist/migration/to/v3.11.0.d.ts +4 -0
  44. package/dist/migration/to/v3.11.0.js +85 -0
  45. package/dist/migration/to/v3.12.3.d.ts +4 -0
  46. package/dist/migration/to/v3.12.3.js +87 -0
  47. package/dist/migration/to/v3.13.0.d.ts +4 -0
  48. package/dist/migration/to/v3.13.0.js +17 -0
  49. package/dist/migration/to/v3.17.0.d.ts +4 -0
  50. package/dist/migration/to/v3.17.0.js +22 -0
  51. package/dist/migration/to/v3.18.0.d.ts +4 -0
  52. package/dist/migration/to/v3.18.0.js +64 -0
  53. package/dist/migration/to/v3.18.1.d.ts +4 -0
  54. package/dist/migration/to/v3.18.1.js +12 -0
  55. package/dist/migration/to/v3.18.2.d.ts +4 -0
  56. package/dist/migration/to/v3.18.2.js +19 -0
  57. package/dist/migration/to/v3.20.0.d.ts +4 -0
  58. package/dist/migration/to/v3.20.0.js +24 -0
  59. package/dist/migration/to/v3.22.0.d.ts +4 -0
  60. package/dist/migration/to/v3.22.0.js +25 -0
  61. package/dist/migration/to/v3.24.0.d.ts +4 -0
  62. package/dist/migration/to/v3.24.0.js +11 -0
  63. package/dist/migration/to/v3.25.0.d.ts +4 -0
  64. package/dist/migration/to/v3.25.0.js +11 -0
  65. package/dist/migration/to/v3.3.0.d.ts +4 -0
  66. package/dist/migration/to/v3.3.0.js +13 -0
  67. package/dist/migration/to/v3.31.0.d.ts +4 -0
  68. package/dist/migration/to/v3.31.0.js +38 -0
  69. package/dist/migration/to/v3.32.0.d.ts +4 -0
  70. package/dist/migration/to/v3.32.0.js +59 -0
  71. package/dist/migration/to/v3.34.0.d.ts +6 -0
  72. package/dist/migration/to/v3.34.0.js +111 -0
  73. package/dist/migration/to/v3.36.0.d.ts +4 -0
  74. package/dist/migration/to/v3.36.0.js +22 -0
  75. package/dist/migration/to/v3.39.0.d.ts +4 -0
  76. package/dist/migration/to/v3.39.0.js +45 -0
  77. package/dist/migration/to/v3.40.0.d.ts +4 -0
  78. package/dist/migration/to/v3.40.0.js +26 -0
  79. package/dist/migration/to/v3.46.0.d.ts +4 -0
  80. package/dist/migration/to/v3.46.0.js +35 -0
  81. package/dist/migration/to/v3.57.0.d.ts +4 -0
  82. package/dist/migration/to/v3.57.0.js +18 -0
  83. package/dist/migration/to/v3.60.0.d.ts +4 -0
  84. package/dist/migration/to/v3.60.0.js +129 -0
  85. package/dist/migration/to/v3.9.0.d.ts +4 -0
  86. package/dist/migration/to/v3.9.0.js +79 -0
  87. package/dist/migration/types.d.ts +26 -0
  88. package/dist/migration/types.js +3 -0
  89. package/dist/migration/utils.d.ts +2 -0
  90. package/dist/migration/utils.js +6 -0
  91. package/dist/mocks.d.ts +14 -0
  92. package/dist/mocks.js +58 -0
  93. package/dist/models/agent.d.ts +3 -0
  94. package/dist/models/agent.js +73 -0
  95. package/dist/models/project-schema.d.ts +28 -0
  96. package/dist/models/project-schema.js +186 -0
  97. package/dist/models/query.d.ts +3 -0
  98. package/dist/models/query.js +46 -0
  99. package/dist/models/runtime-schema.d.ts +9 -0
  100. package/dist/models/runtime-schema.js +20 -0
  101. package/dist/models/shape.d.ts +4 -0
  102. package/dist/models/shape.js +36 -0
  103. package/dist/models/tool.d.ts +4 -0
  104. package/dist/models/tool.js +147 -0
  105. package/dist/models/types.d.ts +97 -0
  106. package/dist/models/types.js +1 -0
  107. package/dist/models/user-schema.d.ts +7 -0
  108. package/dist/models/user-schema.js +9 -0
  109. package/dist/patterns.d.ts +12 -0
  110. package/dist/patterns.js +1 -0
  111. package/dist/project-schema/index.d.ts +229 -0
  112. package/dist/project-schema/index.js +89 -0
  113. package/dist/project-schema/latest.d.ts +2762 -0
  114. package/dist/project-schema/latest.js +7 -0
  115. package/dist/project-schema/migrate.d.ts +4 -0
  116. package/dist/project-schema/migrate.js +236 -0
  117. package/dist/project-schema/v1.0.0.d.ts +299 -0
  118. package/dist/project-schema/v1.0.0.js +7 -0
  119. package/dist/project-schema/v3.0.0.d.ts +478 -0
  120. package/dist/project-schema/v3.0.0.js +7 -0
  121. package/dist/project-schema/v3.1.0.d.ts +621 -0
  122. package/dist/project-schema/v3.1.0.js +7 -0
  123. package/dist/project-schema/v3.10.0.d.ts +1201 -0
  124. package/dist/project-schema/v3.10.0.js +7 -0
  125. package/dist/project-schema/v3.11.0.d.ts +1210 -0
  126. package/dist/project-schema/v3.11.0.js +7 -0
  127. package/dist/project-schema/v3.12.0.d.ts +1214 -0
  128. package/dist/project-schema/v3.12.0.js +7 -0
  129. package/dist/project-schema/v3.12.1.d.ts +1273 -0
  130. package/dist/project-schema/v3.12.1.js +7 -0
  131. package/dist/project-schema/v3.12.2.d.ts +1283 -0
  132. package/dist/project-schema/v3.12.2.js +7 -0
  133. package/dist/project-schema/v3.12.3.d.ts +1306 -0
  134. package/dist/project-schema/v3.12.3.js +7 -0
  135. package/dist/project-schema/v3.13.0.d.ts +1317 -0
  136. package/dist/project-schema/v3.13.0.js +7 -0
  137. package/dist/project-schema/v3.13.1.d.ts +1412 -0
  138. package/dist/project-schema/v3.13.1.js +7 -0
  139. package/dist/project-schema/v3.14.0.d.ts +1436 -0
  140. package/dist/project-schema/v3.14.0.js +7 -0
  141. package/dist/project-schema/v3.15.0.d.ts +1458 -0
  142. package/dist/project-schema/v3.15.0.js +7 -0
  143. package/dist/project-schema/v3.16.0.d.ts +1470 -0
  144. package/dist/project-schema/v3.16.0.js +7 -0
  145. package/dist/project-schema/v3.17.0.d.ts +1467 -0
  146. package/dist/project-schema/v3.17.0.js +7 -0
  147. package/dist/project-schema/v3.17.1.d.ts +1468 -0
  148. package/dist/project-schema/v3.17.1.js +7 -0
  149. package/dist/project-schema/v3.18.0.d.ts +1333 -0
  150. package/dist/project-schema/v3.18.0.js +7 -0
  151. package/dist/project-schema/v3.18.1.d.ts +1332 -0
  152. package/dist/project-schema/v3.18.1.js +7 -0
  153. package/dist/project-schema/v3.18.2.d.ts +1332 -0
  154. package/dist/project-schema/v3.18.2.js +7 -0
  155. package/dist/project-schema/v3.19.0.d.ts +1336 -0
  156. package/dist/project-schema/v3.19.0.js +7 -0
  157. package/dist/project-schema/v3.2.0.d.ts +632 -0
  158. package/dist/project-schema/v3.2.0.js +7 -0
  159. package/dist/project-schema/v3.20.0.d.ts +1336 -0
  160. package/dist/project-schema/v3.20.0.js +7 -0
  161. package/dist/project-schema/v3.21.0.d.ts +1338 -0
  162. package/dist/project-schema/v3.21.0.js +7 -0
  163. package/dist/project-schema/v3.22.0.d.ts +1344 -0
  164. package/dist/project-schema/v3.22.0.js +7 -0
  165. package/dist/project-schema/v3.23.0.d.ts +1376 -0
  166. package/dist/project-schema/v3.23.0.js +7 -0
  167. package/dist/project-schema/v3.24.0.d.ts +1364 -0
  168. package/dist/project-schema/v3.24.0.js +7 -0
  169. package/dist/project-schema/v3.25.0.d.ts +1363 -0
  170. package/dist/project-schema/v3.25.0.js +7 -0
  171. package/dist/project-schema/v3.26.0.d.ts +1388 -0
  172. package/dist/project-schema/v3.26.0.js +7 -0
  173. package/dist/project-schema/v3.27.0.d.ts +1397 -0
  174. package/dist/project-schema/v3.27.0.js +7 -0
  175. package/dist/project-schema/v3.28.0.d.ts +1416 -0
  176. package/dist/project-schema/v3.28.0.js +7 -0
  177. package/dist/project-schema/v3.29.0.d.ts +1423 -0
  178. package/dist/project-schema/v3.29.0.js +7 -0
  179. package/dist/project-schema/v3.3.0.d.ts +632 -0
  180. package/dist/project-schema/v3.3.0.js +7 -0
  181. package/dist/project-schema/v3.30.0.d.ts +1416 -0
  182. package/dist/project-schema/v3.30.0.js +7 -0
  183. package/dist/project-schema/v3.31.0.d.ts +1448 -0
  184. package/dist/project-schema/v3.31.0.js +7 -0
  185. package/dist/project-schema/v3.32.0.d.ts +1439 -0
  186. package/dist/project-schema/v3.32.0.js +7 -0
  187. package/dist/project-schema/v3.33.0.d.ts +1445 -0
  188. package/dist/project-schema/v3.33.0.js +7 -0
  189. package/dist/project-schema/v3.34.0.d.ts +1445 -0
  190. package/dist/project-schema/v3.34.0.js +7 -0
  191. package/dist/project-schema/v3.35.0.d.ts +1464 -0
  192. package/dist/project-schema/v3.35.0.js +7 -0
  193. package/dist/project-schema/v3.36.0.d.ts +1470 -0
  194. package/dist/project-schema/v3.36.0.js +7 -0
  195. package/dist/project-schema/v3.37.0.d.ts +1522 -0
  196. package/dist/project-schema/v3.37.0.js +7 -0
  197. package/dist/project-schema/v3.38.0.d.ts +1522 -0
  198. package/dist/project-schema/v3.38.0.js +7 -0
  199. package/dist/project-schema/v3.39.0.d.ts +1529 -0
  200. package/dist/project-schema/v3.39.0.js +7 -0
  201. package/dist/project-schema/v3.4.0.d.ts +624 -0
  202. package/dist/project-schema/v3.4.0.js +7 -0
  203. package/dist/project-schema/v3.40.0.d.ts +1530 -0
  204. package/dist/project-schema/v3.40.0.js +7 -0
  205. package/dist/project-schema/v3.41.0.d.ts +1530 -0
  206. package/dist/project-schema/v3.41.0.js +7 -0
  207. package/dist/project-schema/v3.42.0.d.ts +1534 -0
  208. package/dist/project-schema/v3.42.0.js +7 -0
  209. package/dist/project-schema/v3.43.0.d.ts +1536 -0
  210. package/dist/project-schema/v3.43.0.js +7 -0
  211. package/dist/project-schema/v3.44.0.d.ts +1621 -0
  212. package/dist/project-schema/v3.44.0.js +7 -0
  213. package/dist/project-schema/v3.45.0.d.ts +1650 -0
  214. package/dist/project-schema/v3.45.0.js +7 -0
  215. package/dist/project-schema/v3.46.0.d.ts +1703 -0
  216. package/dist/project-schema/v3.46.0.js +7 -0
  217. package/dist/project-schema/v3.47.0.d.ts +1736 -0
  218. package/dist/project-schema/v3.47.0.js +7 -0
  219. package/dist/project-schema/v3.48.0.d.ts +2208 -0
  220. package/dist/project-schema/v3.48.0.js +7 -0
  221. package/dist/project-schema/v3.49.0.d.ts +2217 -0
  222. package/dist/project-schema/v3.49.0.js +7 -0
  223. package/dist/project-schema/v3.5.0.d.ts +649 -0
  224. package/dist/project-schema/v3.5.0.js +7 -0
  225. package/dist/project-schema/v3.5.1.d.ts +649 -0
  226. package/dist/project-schema/v3.5.1.js +7 -0
  227. package/dist/project-schema/v3.50.0.d.ts +2269 -0
  228. package/dist/project-schema/v3.50.0.js +7 -0
  229. package/dist/project-schema/v3.51.0.d.ts +2269 -0
  230. package/dist/project-schema/v3.51.0.js +7 -0
  231. package/dist/project-schema/v3.52.0.d.ts +2269 -0
  232. package/dist/project-schema/v3.52.0.js +7 -0
  233. package/dist/project-schema/v3.53.0.d.ts +2350 -0
  234. package/dist/project-schema/v3.53.0.js +7 -0
  235. package/dist/project-schema/v3.54.0.d.ts +2369 -0
  236. package/dist/project-schema/v3.54.0.js +7 -0
  237. package/dist/project-schema/v3.55.0.d.ts +2369 -0
  238. package/dist/project-schema/v3.55.0.js +7 -0
  239. package/dist/project-schema/v3.56.0.d.ts +2405 -0
  240. package/dist/project-schema/v3.56.0.js +7 -0
  241. package/dist/project-schema/v3.57.0.d.ts +2601 -0
  242. package/dist/project-schema/v3.57.0.js +7 -0
  243. package/dist/project-schema/v3.58.0.d.ts +2601 -0
  244. package/dist/project-schema/v3.58.0.js +7 -0
  245. package/dist/project-schema/v3.59.0.d.ts +2650 -0
  246. package/dist/project-schema/v3.59.0.js +7 -0
  247. package/dist/project-schema/v3.6.0.d.ts +658 -0
  248. package/dist/project-schema/v3.6.0.js +7 -0
  249. package/dist/project-schema/v3.60.0.d.ts +2678 -0
  250. package/dist/project-schema/v3.60.0.js +7 -0
  251. package/dist/project-schema/v3.61.0.d.ts +2678 -0
  252. package/dist/project-schema/v3.61.0.js +7 -0
  253. package/dist/project-schema/v3.62.0.d.ts +2693 -0
  254. package/dist/project-schema/v3.62.0.js +7 -0
  255. package/dist/project-schema/v3.63.0.d.ts +2701 -0
  256. package/dist/project-schema/v3.63.0.js +7 -0
  257. package/dist/project-schema/v3.64.0.d.ts +2710 -0
  258. package/dist/project-schema/v3.64.0.js +7 -0
  259. package/dist/project-schema/v3.65.0.d.ts +2762 -0
  260. package/dist/project-schema/v3.65.0.js +7 -0
  261. package/dist/project-schema/v3.7.0.d.ts +961 -0
  262. package/dist/project-schema/v3.7.0.js +7 -0
  263. package/dist/project-schema/v3.8.0.d.ts +979 -0
  264. package/dist/project-schema/v3.8.0.js +7 -0
  265. package/dist/project-schema/v3.9.0.d.ts +1178 -0
  266. package/dist/project-schema/v3.9.0.js +7 -0
  267. package/dist/project-schema/v4.0.0.d.ts +1328 -0
  268. package/dist/project-schema/v4.0.0.js +7 -0
  269. package/dist/refs.d.ts +220 -0
  270. package/dist/refs.js +648 -0
  271. package/dist/relationships.d.ts +40 -0
  272. package/dist/relationships.js +302 -0
  273. package/dist/resolvers/ai/abort-agent-message-args.d.ts +16 -0
  274. package/dist/resolvers/ai/abort-agent-message-args.js +13 -0
  275. package/dist/resolvers/ai/abort-agent-message-response.d.ts +39 -0
  276. package/dist/resolvers/ai/abort-agent-message-response.js +19 -0
  277. package/dist/resolvers/ai/agent-attachment.d.ts +27 -0
  278. package/dist/resolvers/ai/agent-attachment.js +22 -0
  279. package/dist/resolvers/ai/agent-chat-args.d.ts +62 -0
  280. package/dist/resolvers/ai/agent-chat-args.js +30 -0
  281. package/dist/resolvers/ai/agent-chat-payload.d.ts +35 -0
  282. package/dist/resolvers/ai/agent-chat-payload.js +26 -0
  283. package/dist/resolvers/ai/agent-chat-response.d.ts +366 -0
  284. package/dist/resolvers/ai/agent-chat-response.js +21 -0
  285. package/dist/resolvers/ai/agent-generate-args.d.ts +62 -0
  286. package/dist/resolvers/ai/agent-generate-args.js +30 -0
  287. package/dist/resolvers/ai/agent-message-input.d.ts +73 -0
  288. package/dist/resolvers/ai/agent-message-input.js +39 -0
  289. package/dist/resolvers/ai/agent-message-output.d.ts +169 -0
  290. package/dist/resolvers/ai/agent-message-output.js +77 -0
  291. package/dist/resolvers/ai/agent-message-payload.d.ts +849 -0
  292. package/dist/resolvers/ai/agent-message-payload.js +167 -0
  293. package/dist/resolvers/ai/agent-run-mode.d.ts +8 -0
  294. package/dist/resolvers/ai/agent-run-mode.js +9 -0
  295. package/dist/resolvers/ai/agent-session-payload.d.ts +840 -0
  296. package/dist/resolvers/ai/agent-session-payload.js +218 -0
  297. package/dist/resolvers/ai/ai-usage-item.d.ts +70 -0
  298. package/dist/resolvers/ai/ai-usage-item.js +70 -0
  299. package/dist/resolvers/ai/create-agent-session-response.d.ts +276 -0
  300. package/dist/resolvers/ai/create-agent-session-response.js +9 -0
  301. package/dist/resolvers/ai/embedding-search.d.ts +54 -0
  302. package/dist/resolvers/ai/embedding-search.js +46 -0
  303. package/dist/resolvers/ai/get-agent-message-args.d.ts +16 -0
  304. package/dist/resolvers/ai/get-agent-message-args.js +13 -0
  305. package/dist/resolvers/ai/get-agent-message-response.d.ts +1253 -0
  306. package/dist/resolvers/ai/get-agent-message-response.js +79 -0
  307. package/dist/resolvers/ai/inspect-agent-args.d.ts +16 -0
  308. package/dist/resolvers/ai/inspect-agent-args.js +13 -0
  309. package/dist/resolvers/ai/inspect-agent-response.d.ts +631 -0
  310. package/dist/resolvers/ai/inspect-agent-response.js +48 -0
  311. package/dist/resolvers/ai/send-agent-feedback-args.d.ts +52 -0
  312. package/dist/resolvers/ai/send-agent-feedback-args.js +16 -0
  313. package/dist/resolvers/ai/send-agent-message-args.d.ts +48 -0
  314. package/dist/resolvers/ai/send-agent-message-args.js +36 -0
  315. package/dist/resolvers/ai/send-agent-message-response.d.ts +432 -0
  316. package/dist/resolvers/ai/send-agent-message-response.js +51 -0
  317. package/dist/resolvers/ai/types.d.ts +8 -0
  318. package/dist/resolvers/ai/types.js +1 -0
  319. package/dist/resolvers/takeshape/assets/asset-image-meta.d.ts +79 -0
  320. package/dist/resolvers/takeshape/assets/asset-image-meta.js +98 -0
  321. package/dist/resolvers/takeshape/assets/asset-image-params.d.ts +901 -0
  322. package/dist/resolvers/takeshape/assets/asset-image-params.js +726 -0
  323. package/dist/resolvers/takeshape/assets/asset-image.d.ts +17 -0
  324. package/dist/resolvers/takeshape/assets/asset-image.js +15 -0
  325. package/dist/resolvers/takeshape/assets/asset.d.ts +125 -0
  326. package/dist/resolvers/takeshape/assets/asset.js +107 -0
  327. package/dist/resolvers/takeshape/assets/constants.d.ts +11 -0
  328. package/dist/resolvers/takeshape/assets/constants.js +11 -0
  329. package/dist/resolvers/takeshape/builtins/constants.d.ts +1 -0
  330. package/dist/resolvers/takeshape/builtins/constants.js +1 -0
  331. package/dist/runtime-schema.d.ts +6 -0
  332. package/dist/runtime-schema.js +85 -0
  333. package/dist/scalars.d.ts +2 -0
  334. package/dist/scalars.js +4 -0
  335. package/dist/schema-transform.d.ts +19 -0
  336. package/dist/schema-transform.js +74 -0
  337. package/dist/schema-util.d.ts +266 -0
  338. package/dist/schema-util.js +1127 -0
  339. package/dist/schemas/auth-schemas.json +400 -0
  340. package/dist/schemas/index.d.ts +4 -0
  341. package/dist/schemas/index.js +182 -0
  342. package/dist/schemas/project-schema/experimental-2025-07.json +1297 -0
  343. package/dist/schemas/project-schema/latest.d.ts +245 -0
  344. package/dist/schemas/project-schema/latest.js +25 -0
  345. package/dist/schemas/project-schema/latest.json +5109 -0
  346. package/dist/schemas/project-schema/meta-schema-v1.0.0.json +193 -0
  347. package/dist/schemas/project-schema/meta-schema-v3.0.0.json +608 -0
  348. package/dist/schemas/project-schema/meta-schema-v3.1.0.json +608 -0
  349. package/dist/schemas/project-schema/meta-schema-v3.2.0.json +612 -0
  350. package/dist/schemas/project-schema/meta-schema-v3.3.0.json +612 -0
  351. package/dist/schemas/project-schema/meta-schema-v3.4.0.json +637 -0
  352. package/dist/schemas/project-schema/meta-schema-v3.5.0.json +626 -0
  353. package/dist/schemas/project-schema/meta-schema-v3.5.1.json +626 -0
  354. package/dist/schemas/project-schema/meta-schema-v3.6.0.json +629 -0
  355. package/dist/schemas/project-schema/meta-schema-v3.7.0.json +1137 -0
  356. package/dist/schemas/project-schema/meta-schema-v3.8.0.json +1137 -0
  357. package/dist/schemas/project-schema/meta-schema-v3.9.0.json +1477 -0
  358. package/dist/schemas/project-schema/v1.0.0.json +321 -0
  359. package/dist/schemas/project-schema/v3.0.0.json +414 -0
  360. package/dist/schemas/project-schema/v3.1.0.json +572 -0
  361. package/dist/schemas/project-schema/v3.10.0.json +2097 -0
  362. package/dist/schemas/project-schema/v3.11.0.json +2141 -0
  363. package/dist/schemas/project-schema/v3.12.0.json +2144 -0
  364. package/dist/schemas/project-schema/v3.12.1.json +2282 -0
  365. package/dist/schemas/project-schema/v3.12.2.json +2304 -0
  366. package/dist/schemas/project-schema/v3.12.3.json +2357 -0
  367. package/dist/schemas/project-schema/v3.13.0.json +2377 -0
  368. package/dist/schemas/project-schema/v3.14.0.json +2385 -0
  369. package/dist/schemas/project-schema/v3.15.0.json +2365 -0
  370. package/dist/schemas/project-schema/v3.16.0.json +2373 -0
  371. package/dist/schemas/project-schema/v3.17.0.json +2378 -0
  372. package/dist/schemas/project-schema/v3.17.1.json +2380 -0
  373. package/dist/schemas/project-schema/v3.18.0.json +2356 -0
  374. package/dist/schemas/project-schema/v3.18.1.json +2357 -0
  375. package/dist/schemas/project-schema/v3.18.2.json +2357 -0
  376. package/dist/schemas/project-schema/v3.19.0.json +2369 -0
  377. package/dist/schemas/project-schema/v3.2.0.json +580 -0
  378. package/dist/schemas/project-schema/v3.20.0.json +2369 -0
  379. package/dist/schemas/project-schema/v3.21.0.json +2376 -0
  380. package/dist/schemas/project-schema/v3.22.0.json +2381 -0
  381. package/dist/schemas/project-schema/v3.23.0.json +2456 -0
  382. package/dist/schemas/project-schema/v3.24.0.json +2556 -0
  383. package/dist/schemas/project-schema/v3.25.0.json +2552 -0
  384. package/dist/schemas/project-schema/v3.26.0.json +2599 -0
  385. package/dist/schemas/project-schema/v3.27.0.json +2611 -0
  386. package/dist/schemas/project-schema/v3.28.0.json +2656 -0
  387. package/dist/schemas/project-schema/v3.29.0.json +2670 -0
  388. package/dist/schemas/project-schema/v3.3.0.json +581 -0
  389. package/dist/schemas/project-schema/v3.30.0.json +2656 -0
  390. package/dist/schemas/project-schema/v3.31.0.json +2714 -0
  391. package/dist/schemas/project-schema/v3.32.0.json +2708 -0
  392. package/dist/schemas/project-schema/v3.33.0.json +2715 -0
  393. package/dist/schemas/project-schema/v3.34.0.json +2715 -0
  394. package/dist/schemas/project-schema/v3.35.0.json +2748 -0
  395. package/dist/schemas/project-schema/v3.36.0.json +2756 -0
  396. package/dist/schemas/project-schema/v3.37.0.json +2821 -0
  397. package/dist/schemas/project-schema/v3.38.0.json +2819 -0
  398. package/dist/schemas/project-schema/v3.39.0.json +2827 -0
  399. package/dist/schemas/project-schema/v3.4.0.json +571 -0
  400. package/dist/schemas/project-schema/v3.40.0.json +2830 -0
  401. package/dist/schemas/project-schema/v3.41.0.json +2830 -0
  402. package/dist/schemas/project-schema/v3.42.0.json +2835 -0
  403. package/dist/schemas/project-schema/v3.43.0.json +2841 -0
  404. package/dist/schemas/project-schema/v3.44.0.json +3013 -0
  405. package/dist/schemas/project-schema/v3.45.0.json +3064 -0
  406. package/dist/schemas/project-schema/v3.46.0.json +3136 -0
  407. package/dist/schemas/project-schema/v3.47.0.json +3189 -0
  408. package/dist/schemas/project-schema/v3.48.0.json +3196 -0
  409. package/dist/schemas/project-schema/v3.49.0.json +3239 -0
  410. package/dist/schemas/project-schema/v3.5.0.json +571 -0
  411. package/dist/schemas/project-schema/v3.5.1.json +571 -0
  412. package/dist/schemas/project-schema/v3.50.0.json +3320 -0
  413. package/dist/schemas/project-schema/v3.51.0.json +3326 -0
  414. package/dist/schemas/project-schema/v3.52.0.json +3326 -0
  415. package/dist/schemas/project-schema/v3.53.0.json +3476 -0
  416. package/dist/schemas/project-schema/v3.54.0.json +3512 -0
  417. package/dist/schemas/project-schema/v3.55.0.json +3515 -0
  418. package/dist/schemas/project-schema/v3.56.0.json +3530 -0
  419. package/dist/schemas/project-schema/v3.57.0.json +4815 -0
  420. package/dist/schemas/project-schema/v3.58.0.json +4815 -0
  421. package/dist/schemas/project-schema/v3.59.0.json +4912 -0
  422. package/dist/schemas/project-schema/v3.6.0.json +587 -0
  423. package/dist/schemas/project-schema/v3.60.0.json +4974 -0
  424. package/dist/schemas/project-schema/v3.61.0.json +4974 -0
  425. package/dist/schemas/project-schema/v3.62.0.json +5007 -0
  426. package/dist/schemas/project-schema/v3.63.0.json +5020 -0
  427. package/dist/schemas/project-schema/v3.64.0.json +5032 -0
  428. package/dist/schemas/project-schema/v3.65.0.json +5109 -0
  429. package/dist/schemas/project-schema/v3.7.0.json +587 -0
  430. package/dist/schemas/project-schema/v3.8.0.json +604 -0
  431. package/dist/schemas/project-schema/v3.9.0.json +604 -0
  432. package/dist/schemas/project-schema/v4.0.0.json +2316 -0
  433. package/dist/schemas/project-schema.json +232 -0
  434. package/dist/service-dependencies.d.ts +13 -0
  435. package/dist/service-dependencies.js +165 -0
  436. package/dist/services/services.d.ts +31 -0
  437. package/dist/services/services.js +145 -0
  438. package/dist/services/types.d.ts +11 -0
  439. package/dist/services/types.js +1 -0
  440. package/dist/services/util.d.ts +16 -0
  441. package/dist/services/util.js +36 -0
  442. package/dist/shape-paths.d.ts +7 -0
  443. package/dist/shape-paths.js +40 -0
  444. package/dist/taxonomies.d.ts +15 -0
  445. package/dist/taxonomies.js +24 -0
  446. package/dist/template-shapes/index.d.ts +7 -0
  447. package/dist/template-shapes/index.js +33 -0
  448. package/dist/template-shapes/names.d.ts +10 -0
  449. package/dist/template-shapes/names.js +21 -0
  450. package/dist/template-shapes/templates.d.ts +32 -0
  451. package/dist/template-shapes/templates.js +316 -0
  452. package/dist/template-shapes/types.d.ts +15 -0
  453. package/dist/template-shapes/types.js +7 -0
  454. package/dist/template-shapes/where.d.ts +37 -0
  455. package/dist/template-shapes/where.js +415 -0
  456. package/dist/types/index.d.ts +3 -0
  457. package/dist/types/index.js +2 -0
  458. package/dist/types/transforms.d.ts +15 -0
  459. package/dist/types/transforms.js +1 -0
  460. package/dist/types/types.d.ts +206 -0
  461. package/dist/types/types.js +10 -0
  462. package/dist/types/utils.d.ts +112 -0
  463. package/dist/types/utils.js +269 -0
  464. package/dist/unions.d.ts +14 -0
  465. package/dist/unions.js +77 -0
  466. package/dist/util/agent-utils.d.ts +2 -0
  467. package/dist/util/agent-utils.js +7 -0
  468. package/dist/util/api-indexing.d.ts +9 -0
  469. package/dist/util/api-indexing.js +57 -0
  470. package/dist/util/coerce-value.d.ts +9 -0
  471. package/dist/util/coerce-value.js +32 -0
  472. package/dist/util/detect-cycles.d.ts +7 -0
  473. package/dist/util/detect-cycles.js +45 -0
  474. package/dist/util/expressions.d.ts +34 -0
  475. package/dist/util/expressions.js +350 -0
  476. package/dist/util/find-shape-at-path.d.ts +21 -0
  477. package/dist/util/find-shape-at-path.js +53 -0
  478. package/dist/util/form-config.d.ts +11 -0
  479. package/dist/util/form-config.js +62 -0
  480. package/dist/util/get-conflicting-properties.d.ts +6 -0
  481. package/dist/util/get-conflicting-properties.js +55 -0
  482. package/dist/util/get-return-shape.d.ts +4 -0
  483. package/dist/util/get-return-shape.js +30 -0
  484. package/dist/util/graphql-string.d.ts +6 -0
  485. package/dist/util/graphql-string.js +75 -0
  486. package/dist/util/has-arg.d.ts +6 -0
  487. package/dist/util/has-arg.js +25 -0
  488. package/dist/util/is-asset-property.d.ts +3 -0
  489. package/dist/util/is-asset-property.js +11 -0
  490. package/dist/util/merge.d.ts +17 -0
  491. package/dist/util/merge.js +278 -0
  492. package/dist/util/patch-schema.d.ts +13 -0
  493. package/dist/util/patch-schema.js +89 -0
  494. package/dist/util/query-field-path.d.ts +9 -0
  495. package/dist/util/query-field-path.js +23 -0
  496. package/dist/util/shapes.d.ts +5 -0
  497. package/dist/util/shapes.js +22 -0
  498. package/dist/util/tools.d.ts +10 -0
  499. package/dist/util/tools.js +39 -0
  500. package/dist/validate/ai.d.ts +6 -0
  501. package/dist/validate/ai.js +221 -0
  502. package/dist/validate/errors.d.ts +3 -0
  503. package/dist/validate/errors.js +20 -0
  504. package/dist/validate/types.d.ts +43 -0
  505. package/dist/validate/types.js +1 -0
  506. package/dist/validate/util.d.ts +9 -0
  507. package/dist/validate/util.js +62 -0
  508. package/dist/validate/validate.d.ts +41 -0
  509. package/dist/validate/validate.js +1042 -0
  510. package/dist/versions.d.ts +4 -0
  511. package/dist/versions.js +4 -0
  512. package/dist/workflows.d.ts +14 -0
  513. package/dist/workflows.js +66 -0
  514. package/package.json +6 -6
@@ -0,0 +1,301 @@
1
+ import { deepClone, isDefined, isRecord } from '@takeshape/util';
2
+ import set from 'lodash/set.js';
3
+ import uniq from 'lodash/uniq.js';
4
+ import minimatch from 'minimatch';
5
+ import { parseTemplateShape } from "../refs.js";
6
+ import { dereferenceSchema, getArgsReferenceWithPath, getRefOrItemsRef, parseReturnShape, refItemToString, splitAtRef } from "./refs.js";
7
+ import { isAllOfSchema, isObjectSchema, isOneOfSchema, isRefSchema } from "./type-utils.js";
8
+ import { visitSchemaProperties } from "./visitor.js";
9
+ const layerDefaults = {
10
+ namespace: '',
11
+ visibility: []
12
+ };
13
+ function filterMap(prefix, fields, filters) {
14
+ const result = {};
15
+ for (const [name, value] of Object.entries(fields)) {
16
+ for (const filter of filters) {
17
+ if (minimatch(`${prefix}.${name}`, filter)) {
18
+ result[name] = value;
19
+ }
20
+ }
21
+ }
22
+ return result;
23
+ }
24
+ function filterLayer(layerSchema, filters) {
25
+ return {
26
+ ...layerSchema,
27
+ queries: filterMap('queries', layerSchema.queries ?? {}, filters),
28
+ mutations: filterMap('mutations', layerSchema.mutations ?? {}, filters),
29
+ shapes: filterMap('shapes', layerSchema.shapes ?? {}, filters),
30
+ workflows: filterMap('workflows', layerSchema.workflows ?? {}, filters)
31
+ };
32
+ }
33
+ // TODO use non-versioned util eventually
34
+ export function isObjectSchemaV4_0_0(maybeObjectSchema) {
35
+ return maybeObjectSchema.type === 'object' && isRecord(maybeObjectSchema.properties);
36
+ }
37
+ function mergeShape(a, b) {
38
+ if (b.override === 'extend') {
39
+ if (isObjectSchemaV4_0_0(a.schema) && isObjectSchemaV4_0_0(b.schema)) {
40
+ const combinedRequired = uniq((a.schema.required ?? []).concat(b.schema.required ?? []));
41
+ const combinedSchema = {
42
+ type: 'object',
43
+ properties: {
44
+ ...a.schema.properties,
45
+ ...b.schema.properties
46
+ }
47
+ };
48
+ if (combinedRequired.length) {
49
+ combinedSchema.required = combinedRequired;
50
+ }
51
+ return { ...a, ...b, schema: combinedSchema };
52
+ }
53
+ }
54
+ return b;
55
+ }
56
+ function assignShapes(flattenedShapes, layerShapes) {
57
+ for (const [shapeName, shape] of Object.entries(layerShapes)) {
58
+ flattenedShapes[shapeName] = flattenedShapes[shapeName] ? mergeShape(flattenedShapes[shapeName], shape) : shape;
59
+ }
60
+ }
61
+ function addRef(refs, ref, predicate) {
62
+ if (ref && (!predicate || predicate(ref))) {
63
+ refs.push(ref);
64
+ }
65
+ }
66
+ /**
67
+ * Walk through a `ProjectSchema` and collect all the `ref`s.
68
+ */
69
+ export function getAllRefsInShapes(shapes, predicate) {
70
+ const items = [];
71
+ const shapeVisitor = (schema, schemaPath) => {
72
+ if (schema['@args'] && typeof schema['@args'] === 'object') {
73
+ visitSchemaProperties(schema['@args'], schemaPath.concat(['@args']), (argSchema, argPath) => {
74
+ addRef(items, getRefOrItemsRef(argSchema, argPath), predicate);
75
+ });
76
+ }
77
+ addRef(items, getArgsReferenceWithPath(schema, schemaPath), predicate);
78
+ const newPath = schema.items ? schemaPath.concat('items') : schemaPath;
79
+ const newSchema = schema.items ?? schema;
80
+ if (isRefSchema(newSchema)) {
81
+ addRef(items, getRefOrItemsRef(newSchema, newPath), predicate);
82
+ }
83
+ else if (isObjectSchema(newSchema) || isAllOfSchema(newSchema) || isOneOfSchema(newSchema)) {
84
+ visitSchemaProperties(newSchema, newPath, shapeVisitor);
85
+ }
86
+ };
87
+ for (const [shapeName, shape] of Object.entries(shapes)) {
88
+ visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], shapeVisitor);
89
+ }
90
+ return items;
91
+ }
92
+ /**
93
+ * Get all refs
94
+ */
95
+ export function getAllRefsInQuery(shapes, queryPath, query, predicate) {
96
+ const refItems = [];
97
+ const propertyVisitor = (propSchema, propSchemaPath) => {
98
+ addRef(refItems, getRefOrItemsRef(propSchema, propSchemaPath), predicate);
99
+ };
100
+ if (query.args && typeof query.args === 'string') {
101
+ addRef(refItems, getArgsReferenceWithPath(query, queryPath), predicate);
102
+ }
103
+ if (query.args && typeof query.args === 'object') {
104
+ visitSchemaProperties(dereferenceSchema(shapes, query.args), queryPath, propertyVisitor);
105
+ }
106
+ if (query.shape) {
107
+ const refItem = parseReturnShape(query.shape).ref;
108
+ if (refItem) {
109
+ addRef(refItems, {
110
+ ...refItem,
111
+ path: queryPath.concat(['shape'])
112
+ }, predicate);
113
+ }
114
+ }
115
+ return refItems;
116
+ }
117
+ /**
118
+ * Collect refs from `queries` or `mutations`.
119
+ */
120
+ export function getAllRefsInQueries(context, rootPropertyName, predicate) {
121
+ const refItems = [];
122
+ const rootPath = [rootPropertyName];
123
+ for (const [queryName, query] of Object.entries(context[rootPropertyName])) {
124
+ const queryPath = rootPath.concat([queryName]);
125
+ const queryRefs = getAllRefsInQuery(context.shapes, queryPath, query, predicate);
126
+ if (queryRefs.length) {
127
+ refItems.push(...queryRefs);
128
+ }
129
+ }
130
+ return refItems;
131
+ }
132
+ /**
133
+ * Get all refs in a ProjectSchema
134
+ * @param predicate return true to include the ref in
135
+ */
136
+ export function getAllRefs(projectSchema, predicate) {
137
+ return [
138
+ ...getAllRefsInShapes(projectSchema.shapes, predicate),
139
+ ...getAllRefsInQueries(projectSchema, 'queries', predicate),
140
+ ...getAllRefsInQueries(projectSchema, 'mutations', predicate)
141
+ ];
142
+ }
143
+ export function collectReferencedShapeNames(layerId, refSet) {
144
+ const addLayerId = (ref) => ({ ...ref, layerId });
145
+ const collect = (schema) => {
146
+ const args = schema['@args'];
147
+ if (args && typeof args === 'object') {
148
+ Object.values(args.properties).forEach(collect);
149
+ }
150
+ const argsRefItem = getArgsReferenceWithPath(schema);
151
+ if (argsRefItem) {
152
+ refSet.add(refItemToString(addLayerId(argsRefItem)));
153
+ }
154
+ const refItem = getRefOrItemsRef(schema);
155
+ if (refItem) {
156
+ refSet.add(refItemToString(addLayerId(refItem)));
157
+ }
158
+ };
159
+ return collect;
160
+ }
161
+ function collectServiceRefs(flattenedSchema, getLayer) {
162
+ const refs = new Set(getAllRefs(flattenedSchema, (refItem) => refItem.layerId !== 'local').map(refItemToString));
163
+ if (refs.size) {
164
+ for (const ref of refs) {
165
+ const [layerId, shapeName] = splitAtRef(ref);
166
+ if (layerId !== 'local') {
167
+ const layer = getLayer(layerId);
168
+ const shape = layer?.shapes?.[shapeName];
169
+ if (shape) {
170
+ visitSchemaProperties(shape.schema, ['schema'], collectReferencedShapeNames(layerId, refs));
171
+ }
172
+ }
173
+ }
174
+ }
175
+ return refs;
176
+ }
177
+ function ensureServiceLayer(flattenedSchema, layerId) {
178
+ flattenedSchema.serviceLayers ||= {};
179
+ let serviceLayer = flattenedSchema.serviceLayers[layerId];
180
+ if (!serviceLayer) {
181
+ serviceLayer = {
182
+ layerId,
183
+ schemaVersion: '4.0.0',
184
+ shapes: {},
185
+ queries: {},
186
+ mutations: {}
187
+ };
188
+ flattenedSchema.serviceLayers[layerId] = serviceLayer;
189
+ }
190
+ return serviceLayer;
191
+ }
192
+ function rewriteLayerId(localShapes, layerId, query) {
193
+ const newQuery = deepClone(query);
194
+ const propertyVisitor = (propSchema, propSchemaPath) => {
195
+ const ref = (propSchema.items ?? propSchema)['@ref'];
196
+ if (ref) {
197
+ const [argsLayerId, shapeName] = splitAtRef(ref);
198
+ if (argsLayerId === 'local' && !localShapes[shapeName]) {
199
+ const path = propSchemaPath.concat(propSchema.items ? ['items', '@ref'] : ['@ref']);
200
+ set(newQuery, path, `${layerId}:${shapeName}`);
201
+ }
202
+ }
203
+ };
204
+ if (query.args) {
205
+ if (typeof query.args === 'string') {
206
+ const [argsLayerId, shapeName] = splitAtRef(parseTemplateShape(query.args).shapeName);
207
+ if (argsLayerId === 'local' && !localShapes[shapeName]) {
208
+ newQuery.args = `${layerId}:${shapeName}`;
209
+ }
210
+ }
211
+ else {
212
+ visitSchemaProperties(query.args, ['args'], propertyVisitor);
213
+ }
214
+ }
215
+ if (typeof query.shape === 'string') {
216
+ const [argsLayerId, shapeName] = splitAtRef(parseTemplateShape(query.shape).shapeName);
217
+ if (argsLayerId === 'local' && !localShapes[shapeName]) {
218
+ newQuery.shape = `${layerId}:${shapeName}`;
219
+ }
220
+ }
221
+ else {
222
+ const ref = query.shape.items['@ref'];
223
+ if (ref) {
224
+ const [argsLayerId, shapeName] = splitAtRef(ref);
225
+ if (argsLayerId === 'local' && !localShapes[shapeName]) {
226
+ set(newQuery, ['shape', 'items', '@ref'], `${layerId}:${shapeName}`);
227
+ }
228
+ }
229
+ }
230
+ return newQuery;
231
+ }
232
+ function assignQueries(localShapes, queries, layerId, layerQueries) {
233
+ for (const [queryName, query] of Object.entries(layerQueries)) {
234
+ queries[queryName] = rewriteLayerId(localShapes, layerId, query);
235
+ }
236
+ }
237
+ export function flattenSchema(projectSchema, getLayer) {
238
+ const { layers, ...rest } = projectSchema;
239
+ const flattenedSchema = {
240
+ ...rest,
241
+ shapes: {},
242
+ queries: {},
243
+ mutations: {},
244
+ workflows: {},
245
+ forms: {}
246
+ };
247
+ const filteredLayers = layers
248
+ .reverse()
249
+ .map((layer) => {
250
+ const config = typeof layer === 'string' ? { ...layerDefaults, id: layer } : layer;
251
+ const layerSchema = getLayer(config.id);
252
+ if (!layerSchema) {
253
+ throw new Error(`Unable to flatten schema for project ${projectSchema.projectId}. Cannot get layer ${config.id}`);
254
+ }
255
+ return config.visibility?.length ? filterLayer(layerSchema, config.visibility) : undefined;
256
+ })
257
+ .filter(isDefined);
258
+ for (const filteredLayer of filteredLayers) {
259
+ const { layerId } = filteredLayer;
260
+ // Preserve original queries
261
+ if (projectSchema.services?.[layerId]) {
262
+ const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
263
+ if (serviceLayer.queries && filteredLayer.queries) {
264
+ Object.assign(serviceLayer.queries, filteredLayer.queries);
265
+ }
266
+ if (serviceLayer.mutations && filteredLayer.mutations) {
267
+ Object.assign(serviceLayer.mutations, filteredLayer.mutations);
268
+ }
269
+ }
270
+ if (filteredLayer.workflows) {
271
+ Object.assign(flattenedSchema.workflows, filteredLayer.workflows);
272
+ }
273
+ if (flattenedSchema.forms && filteredLayer.forms) {
274
+ Object.assign(flattenedSchema.forms, filteredLayer.forms);
275
+ }
276
+ if (filteredLayer.shapes) {
277
+ assignShapes(flattenedSchema.shapes, filteredLayer.shapes);
278
+ }
279
+ }
280
+ for (const filteredLayer of filteredLayers) {
281
+ if (filteredLayer.queries) {
282
+ assignQueries(flattenedSchema.shapes, flattenedSchema.queries, filteredLayer.layerId, filteredLayer.queries);
283
+ }
284
+ if (filteredLayer.mutations) {
285
+ assignQueries(flattenedSchema.shapes, flattenedSchema.mutations, filteredLayer.layerId, filteredLayer.mutations);
286
+ }
287
+ }
288
+ // Preserve original service schema shapes
289
+ for (const refStr of collectServiceRefs(flattenedSchema, getLayer)) {
290
+ const [layerId, shapeName] = splitAtRef(refStr);
291
+ if (layerId !== 'local') {
292
+ const shape = getLayer(layerId)?.shapes?.[shapeName];
293
+ if (shape) {
294
+ const serviceLayer = ensureServiceLayer(flattenedSchema, layerId);
295
+ serviceLayer.shapes ||= {};
296
+ serviceLayer.shapes[shapeName] = shape;
297
+ }
298
+ }
299
+ }
300
+ return flattenedSchema;
301
+ }
@@ -0,0 +1,102 @@
1
+ import type { Maybe } from '@takeshape/util';
2
+ import type { PropertySchemaV4_0_0, QueryJSONV4_0_0, ReturnShapeV4_0_0, ShapeJSONV4_0_0, ShapeMapV4_0_0 } from '../project-schema/index.ts';
3
+ import type { SchemaPath } from '../types/index.ts';
4
+ /**
5
+ * This interface describes a parsed `@ref` or `$ref`.
6
+ * The intended usage is to convert a schema with a ref to a RefItem which can then
7
+ * be passed to the various rich utilities in this file.
8
+ */
9
+ export type RefItem = {
10
+ typeName: string;
11
+ layerId: string;
12
+ template?: string;
13
+ };
14
+ /**
15
+ * Adds a schema path, needed when visiting a whole schema to report errors.
16
+ */
17
+ export type RefItemWithPath = {
18
+ path: SchemaPath;
19
+ } & RefItem;
20
+ /**
21
+ * Safely turn a "template" shape reference (`@args`, `args`, `shape`) into a `RefItem`
22
+ *
23
+ * @param context A partial project schema
24
+ * @param refExpression
25
+ * A ref expression might include "template" name and refer to a local or remote
26
+ * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.*
27
+ */
28
+ export declare function refExpressionToRefItem(refExpression: string): RefItem;
29
+ /**
30
+ * Sugar for converting a `refExpression` directly into a shape, without the
31
+ * intermediate `refItem`.
32
+ *
33
+ * @param context A partial project schema
34
+ * @param refExpression
35
+ * A ref expression might include "template" name and refer to a local or remote
36
+ * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.
37
+ */
38
+ export declare function refExpressionToShape(shapes: ShapeMapV4_0_0, refExpression: string): Maybe<ShapeJSONV4_0_0>;
39
+ /**
40
+ * Provided a service name and a referenced type. Supports 2 or 3 part
41
+ * references, e.g., `shopify:my-store:ProductInput` or `my-store:ProductInput`.
42
+ *
43
+ * @returns
44
+ * A 2 member array, where 0 is the service name, 1 is the referenced type.
45
+ */
46
+ export declare function splitAtRef(atRef: string): [string, string];
47
+ /**
48
+ * Parses and returns a typeName, serviceKey, and potentially a namespace for
49
+ * the type.
50
+ */
51
+ export declare function atRefToRefItem(atRef: string, template?: string): RefItem;
52
+ /**
53
+ * Given a content schema and project schema, finds a `@ref` or `$ref` and
54
+ * returns a `RefItem` suitable for loading a referenced schema...
55
+ */
56
+ export declare function getRef(refSchema: PropertySchemaV4_0_0): Maybe<RefItem>;
57
+ export declare function getRefWithPath(refSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
58
+ /**
59
+ * Tests for a `@ref` or `$ref` property directly on the passed schema.
60
+ *
61
+ * @param schema Any schema that might could have a ref property.
62
+ */
63
+ export declare function hasRefProperty(schema: PropertySchemaV4_0_0): boolean;
64
+ /**
65
+ * From a schema with a ref, will return the top-level ref, and potentially
66
+ * a ref item from a nested `items` property.
67
+ */
68
+ export declare function getRefOrItemsRef(refSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
69
+ /**
70
+ * Turns a `RefItem` into an `@ref`.
71
+ */
72
+ export declare function refItemToString(refItem: RefItem): string;
73
+ /**
74
+ * Get a Shape referenced by a `RefItem`.
75
+ */
76
+ export declare function refItemToShape(shapes: ShapeMapV4_0_0, refItem: RefItem): Maybe<ShapeJSONV4_0_0>;
77
+ /**
78
+ * Helper fn to omit `ref` props from the target schema, and then extend it with the source schema.
79
+ */
80
+ export declare const omitRefAndExtend: (targetSchema: PropertySchemaV4_0_0, sourceSchema: PropertySchemaV4_0_0) => import("lodash").Omit<PropertySchemaV4_0_0, "@ref" | "$ref"> & PropertySchemaV4_0_0;
81
+ /**
82
+ * If there is a $ref, this will insert a content schema from the top level
83
+ * in place of the reference.
84
+ */
85
+ export declare function followRef(shapes: ShapeMapV4_0_0, contentSchema: PropertySchemaV4_0_0): PropertySchemaV4_0_0;
86
+ /**
87
+ * Returns whether a schema has refs.
88
+ */
89
+ export declare function hasRef(contentSchema: PropertySchemaV4_0_0): boolean;
90
+ /**
91
+ * Returns whether a schema has refs which can be followed.
92
+ */
93
+ export declare function hasResolvableRef(shapes: ShapeMapV4_0_0, contentSchema: PropertySchemaV4_0_0): boolean;
94
+ export declare function getArgsReferenceWithPath(argsSchema: PropertySchemaV4_0_0 | QueryJSONV4_0_0, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
95
+ export declare function dereferenceSchema(shapes: ShapeMapV4_0_0, shapeOrFieldSchema: PropertySchemaV4_0_0, schemaPath?: SchemaPath): PropertySchemaV4_0_0;
96
+ export type ParsedReturnShape = {
97
+ isArray: boolean;
98
+ template?: string;
99
+ shapeName: string;
100
+ ref?: RefItem;
101
+ };
102
+ export declare function parseReturnShape(shape: ReturnShapeV4_0_0): ParsedReturnShape;
@@ -0,0 +1,220 @@
1
+ import { mergeWithArrayConcat } from '@takeshape/util';
2
+ import assign from 'lodash/fp/assign.js';
3
+ import omit from 'lodash/fp/omit.js';
4
+ import isEmpty from 'lodash/isEmpty.js';
5
+ import { parseTemplateShape } from "../refs.js";
6
+ import { isAllOfSchema, isOneOfSchema, isRefSchema } from "./type-utils.js";
7
+ /**
8
+ * Safely turn a "template" shape reference (`@args`, `args`, `shape`) into a `RefItem`
9
+ *
10
+ * @param context A partial project schema
11
+ * @param refExpression
12
+ * A ref expression might include "template" name and refer to a local or remote
13
+ * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.*
14
+ */
15
+ export function refExpressionToRefItem(refExpression) {
16
+ const { shapeName, template } = parseTemplateShape(refExpression);
17
+ return atRefToRefItem(shapeName, template);
18
+ }
19
+ /**
20
+ * Sugar for converting a `refExpression` directly into a shape, without the
21
+ * intermediate `refItem`.
22
+ *
23
+ * @param context A partial project schema
24
+ * @param refExpression
25
+ * A ref expression might include "template" name and refer to a local or remote
26
+ * shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.
27
+ */
28
+ export function refExpressionToShape(shapes, refExpression) {
29
+ return refItemToShape(shapes, refExpressionToRefItem(refExpression));
30
+ }
31
+ /**
32
+ * Provided a service name and a referenced type. Supports 2 or 3 part
33
+ * references, e.g., `shopify:my-store:ProductInput` or `my-store:ProductInput`.
34
+ *
35
+ * @returns
36
+ * A 2 member array, where 0 is the service name, 1 is the referenced type.
37
+ */
38
+ export function splitAtRef(atRef) {
39
+ const refParts = atRef.split(':');
40
+ if (refParts.length === 1) {
41
+ return ['local', atRef];
42
+ }
43
+ if (refParts.length === 2) {
44
+ return [refParts[0], refParts[1]];
45
+ }
46
+ throw new Error(`Invalid ref string ${atRef}`);
47
+ }
48
+ /**
49
+ * Parses and returns a typeName, serviceKey, and potentially a namespace for
50
+ * the type.
51
+ */
52
+ export function atRefToRefItem(atRef, template) {
53
+ const [serviceKey, typeName] = splitAtRef(atRef);
54
+ return {
55
+ typeName,
56
+ layerId: serviceKey,
57
+ template
58
+ };
59
+ }
60
+ /**
61
+ * Given a content schema and project schema, finds a `@ref` or `$ref` and
62
+ * returns a `RefItem` suitable for loading a referenced schema...
63
+ */
64
+ export function getRef(refSchema) {
65
+ if (refSchema['@ref']) {
66
+ // @ref: my-service:ShapeName
67
+ return atRefToRefItem(refSchema['@ref']);
68
+ }
69
+ }
70
+ export function getRefWithPath(refSchema, schemaPath = []) {
71
+ const refItem = getRef(refSchema);
72
+ if (refItem) {
73
+ return {
74
+ ...refItem,
75
+ path: schemaPath.concat(['@ref'])
76
+ };
77
+ }
78
+ }
79
+ /**
80
+ * Tests for a `@ref` or `$ref` property directly on the passed schema.
81
+ *
82
+ * @param schema Any schema that might could have a ref property.
83
+ */
84
+ export function hasRefProperty(schema) {
85
+ return Boolean(schema['@ref'] ?? schema.$ref);
86
+ }
87
+ /**
88
+ * From a schema with a ref, will return the top-level ref, and potentially
89
+ * a ref item from a nested `items` property.
90
+ */
91
+ export function getRefOrItemsRef(refSchema, schemaPath = []) {
92
+ const refItem = getRefWithPath(refSchema, schemaPath);
93
+ if (refItem) {
94
+ return refItem;
95
+ }
96
+ if (refSchema.items) {
97
+ return getRefOrItemsRef(refSchema.items, schemaPath.concat(['items']));
98
+ }
99
+ }
100
+ /**
101
+ * Turns a `RefItem` into an `@ref`.
102
+ */
103
+ export function refItemToString(refItem) {
104
+ return `${refItem.layerId}:${refItem.typeName}`;
105
+ }
106
+ /**
107
+ * Get a Shape referenced by a `RefItem`.
108
+ */
109
+ export function refItemToShape(shapes, refItem) {
110
+ return shapes[refItemToString(refItem)];
111
+ }
112
+ /**
113
+ * Helper fn to omit `ref` props from the target schema, and then extend it with the source schema.
114
+ */
115
+ export const omitRefAndExtend = (targetSchema, sourceSchema) => assign(omit(['@ref', '$ref'], targetSchema), sourceSchema);
116
+ /**
117
+ * If there is a $ref, this will insert a content schema from the top level
118
+ * in place of the reference.
119
+ */
120
+ export function followRef(shapes, contentSchema) {
121
+ const refItem = getRef(contentSchema);
122
+ if (refItem) {
123
+ const referencedSchema = refItemToShape(shapes, refItem)?.schema;
124
+ if (referencedSchema) {
125
+ return omitRefAndExtend(contentSchema, referencedSchema);
126
+ }
127
+ }
128
+ return contentSchema;
129
+ }
130
+ /**
131
+ * Returns whether a schema has refs.
132
+ */
133
+ export function hasRef(contentSchema) {
134
+ if (isRefSchema(contentSchema)) {
135
+ return true;
136
+ }
137
+ if (isAllOfSchema(contentSchema)) {
138
+ return Boolean(contentSchema.allOf.find(hasRef));
139
+ }
140
+ if (isOneOfSchema(contentSchema)) {
141
+ return Boolean(contentSchema.oneOf.find(hasRef));
142
+ }
143
+ return false;
144
+ }
145
+ /**
146
+ * Returns whether a schema has refs which can be followed.
147
+ */
148
+ export function hasResolvableRef(shapes, contentSchema) {
149
+ if (isRefSchema(contentSchema)) {
150
+ return Boolean(refItemToShape(shapes, getRef(contentSchema)));
151
+ }
152
+ if (isAllOfSchema(contentSchema)) {
153
+ return Boolean(contentSchema.allOf.find((s) => hasResolvableRef(shapes, s)));
154
+ }
155
+ if (isOneOfSchema(contentSchema)) {
156
+ return Boolean(contentSchema.oneOf.find((s) => hasResolvableRef(shapes, s)));
157
+ }
158
+ return false;
159
+ }
160
+ export function getArgsReferenceWithPath(argsSchema, schemaPath = []) {
161
+ const isQuery = 'args' in argsSchema;
162
+ const args = isQuery ? argsSchema.args : argsSchema['@args'];
163
+ const refItem = typeof args === 'string' ? refExpressionToRefItem(args) : undefined;
164
+ if (refItem) {
165
+ return {
166
+ ...refItem,
167
+ path: schemaPath.concat([isQuery ? 'args' : '@args'])
168
+ };
169
+ }
170
+ }
171
+ /*
172
+ * Helper fn to omit `allOf` props from the target schema, and then extend it with the source schema.
173
+ */
174
+ const omitAllOfAndExtend = (targetSchema, sourceSchema) => assign(omit(['allOf'], targetSchema), sourceSchema);
175
+ export function dereferenceSchema(shapes, shapeOrFieldSchema, schemaPath = []) {
176
+ const resolveAll = (resolveSchema, resolvePath) => {
177
+ try {
178
+ if (isAllOfSchema(resolveSchema)) {
179
+ const allOfSchema = resolveSchema.allOf
180
+ .map((stub, index) => resolveAll(stub, [...resolvePath, 'allOf', index]))
181
+ .reduce((prev, curr) => mergeWithArrayConcat(prev, curr), {});
182
+ return isEmpty(allOfSchema) ? undefined : omitAllOfAndExtend(resolveSchema, allOfSchema);
183
+ }
184
+ if (isRefSchema(resolveSchema)) {
185
+ const refItem = getRefWithPath(resolveSchema);
186
+ if (!refItem) {
187
+ throw new Error('ref could not be parsed');
188
+ }
189
+ const refSchema = refItemToShape(shapes, refItem);
190
+ if (refSchema) {
191
+ return resolveAll(omitRefAndExtend(resolveSchema, refSchema), refItem.path);
192
+ }
193
+ return;
194
+ }
195
+ return resolveSchema;
196
+ }
197
+ catch (err) {
198
+ throw new Error(`error at '${resolvePath.join('.')}', ${err.message}`);
199
+ }
200
+ };
201
+ return resolveAll(shapeOrFieldSchema, schemaPath) ?? shapeOrFieldSchema;
202
+ }
203
+ export function parseReturnShape(shape) {
204
+ if (typeof shape === 'object') {
205
+ if (isRefSchema(shape.items)) {
206
+ const ref = getRef(shape.items);
207
+ if (!ref) {
208
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid ref`);
209
+ }
210
+ return { isArray: true, ref, shapeName: refItemToString(ref) };
211
+ }
212
+ if (typeof shape.items.type !== 'string') {
213
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid type`);
214
+ }
215
+ return { isArray: true, shapeName: shape.items.type };
216
+ }
217
+ const ref = refExpressionToRefItem(shape);
218
+ const shapeName = refItemToString(ref);
219
+ return { isArray: false, shapeName, ref, template: ref.template };
220
+ }
@@ -0,0 +1,59 @@
1
+ import type { AllOfSchemaV4_0_0, AwsLambdaResolverV4_0_0, BasicResolverV4_0_0, ComposeResolverV4_0_0, DirectiveConfigV4_0_0, DirectiveMappingArrayV4_0_0, DirectiveMappingMapV4_0_0, GraphqlResolverV4_0_0, ObjectSchemaV4_0_0, OneOfSchemaV4_0_0, ParameterOpMappingV4_0_0, ParameterOpNestedV4_0_0, ParameterOpOpV4_0_0, ParameterOpV4_0_0, ParameterOpValueV4_0_0, ParameterSerializeContentOptionsV4_0_0, ParameterSerializeOptionsV4_0_0, ParameterSerializeStyleOptionsV4_0_0, PropertySchemaV4_0_0, RefSchemaLegacyV4_0_0, RefSchemaV4_0_0, RestResolverV4_0_0, ReturnShapeArraySchemaV4_0_0, TakeshapeResolverV4_0_0, UtilResolverV4_0_0 } from '../project-schema/index.ts';
2
+ /** Resolver Type Utils **/
3
+ /**
4
+ * Only tests that the shape is right, not that the name is correct. That's a job for the validator.
5
+ */
6
+ export declare function isBasicResolver(resolver: unknown): resolver is BasicResolverV4_0_0;
7
+ export declare function isComposeResolver(resolver: unknown): resolver is ComposeResolverV4_0_0;
8
+ export declare function isTakeshapeResolver(resolver: BasicResolverV4_0_0): resolver is TakeshapeResolverV4_0_0;
9
+ export declare function isGraphqlResolver(resolver: BasicResolverV4_0_0): resolver is GraphqlResolverV4_0_0;
10
+ export declare function isRestResolver(resolver: BasicResolverV4_0_0): resolver is RestResolverV4_0_0;
11
+ export declare function isAwsLambdaResolver(resolver: BasicResolverV4_0_0): resolver is AwsLambdaResolverV4_0_0;
12
+ export declare function isUtilResolver(resolver: BasicResolverV4_0_0): resolver is UtilResolverV4_0_0;
13
+ /** Directive Mapping Utils **/
14
+ /**
15
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingMap
16
+ */
17
+ export declare function isDirectiveMappingMap(maybeMap: DirectiveMappingMapV4_0_0 | DirectiveMappingArrayV4_0_0 | DirectiveConfigV4_0_0): maybeMap is DirectiveMappingMapV4_0_0;
18
+ /**
19
+ * Determine whether the ambiguous Directive structure is a DirectiveMappingArray
20
+ */
21
+ export declare function isDirectiveMappingArray(maybeArray: DirectiveMappingMapV4_0_0 | DirectiveMappingArrayV4_0_0 | DirectiveConfigV4_0_0): maybeArray is DirectiveMappingArrayV4_0_0;
22
+ /**
23
+ * Determine whether the ambiguous Directive structure is a DirectiveConfig array
24
+ */
25
+ export declare function isDirectiveConfig(maybeConfig: DirectiveMappingMapV4_0_0 | DirectiveMappingArrayV4_0_0 | DirectiveConfigV4_0_0): maybeConfig is DirectiveConfigV4_0_0;
26
+ /**
27
+ * Determine whether a ParameterSerializeOption is a content type serializer
28
+ */
29
+ export declare function isParameterSerializeContentOptions(maybeContent: ParameterSerializeOptionsV4_0_0): maybeContent is ParameterSerializeContentOptionsV4_0_0;
30
+ /**
31
+ * Determine whether an unknown variable is a `ParameterOp`
32
+ */
33
+ export declare function isParameterOp(maybeOp: unknown): maybeOp is ParameterOpV4_0_0;
34
+ /**
35
+ * Determine whether a `ParameterOp` is a `ParameterOpNested`
36
+ */
37
+ export declare function isParameterOpNested(maybeOp: ParameterOpV4_0_0): maybeOp is ParameterOpNestedV4_0_0;
38
+ /**
39
+ * Determine whether a `ParameterOp` is a `ParameterOpMapping`
40
+ */
41
+ export declare function isParameterOpMapping(maybeOp: ParameterOpV4_0_0): maybeOp is ParameterOpMappingV4_0_0;
42
+ /**
43
+ * Determine whether a `ParameterOp` is a `ParameterOpMapping`
44
+ */
45
+ export declare function isParameterOpValue(maybeOp: ParameterOpV4_0_0): maybeOp is ParameterOpValueV4_0_0;
46
+ /**
47
+ * Determine whether a `ParameterOp` is a `ParameterOpOp`
48
+ */
49
+ export declare function isParameterOpOp(maybeOp: ParameterOpV4_0_0): maybeOp is ParameterOpOpV4_0_0;
50
+ /**
51
+ * Determine whether a ParameterSerializeOption is a style serializer
52
+ */
53
+ export declare function isParameterSerializeStyleOptions(maybeStyle: ParameterSerializeOptionsV4_0_0): maybeStyle is ParameterSerializeStyleOptionsV4_0_0;
54
+ /** Typeguards for different types of shape schemas **/
55
+ export declare function isRefSchema(maybeRefSchema: PropertySchemaV4_0_0): maybeRefSchema is RefSchemaV4_0_0 | RefSchemaLegacyV4_0_0;
56
+ export declare function isAllOfSchema(schema: PropertySchemaV4_0_0): schema is AllOfSchemaV4_0_0;
57
+ export declare function isOneOfSchema(schema: PropertySchemaV4_0_0): schema is OneOfSchemaV4_0_0;
58
+ export declare function isArraySchema(schema: PropertySchemaV4_0_0): schema is ReturnShapeArraySchemaV4_0_0;
59
+ export declare function isObjectSchema(schema: PropertySchemaV4_0_0): schema is ObjectSchemaV4_0_0;