@takeshape/schema 11.144.1 → 11.154.1

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 (537) hide show
  1. package/examples/latest/all-fields-shapes-inline.json +1 -1
  2. package/examples/latest/all-fields-shapes.json +1 -1
  3. package/examples/latest/betzino.json +1 -1
  4. package/examples/latest/blog-schema.json +1 -1
  5. package/examples/latest/brewery-schema.json +1 -1
  6. package/examples/latest/chat-agent-schema.json +1 -1
  7. package/examples/latest/clear-cache-schema.json +1 -1
  8. package/examples/latest/complex-project-schema.json +1 -1
  9. package/examples/latest/complex-schema.json +1 -1
  10. package/examples/latest/edit-schema.json +1 -1
  11. package/examples/latest/frank-and-fred-schema.json +1 -1
  12. package/examples/latest/generate-agent-schema.json +1 -1
  13. package/examples/latest/klirr-schema.json +1 -1
  14. package/examples/latest/layers/rick-and-morty-layer.json +1 -1
  15. package/examples/latest/layers/shopify-layer-2023-01.json +1 -1
  16. package/examples/latest/layers/shopify-storefront-2023-04.json +1 -1
  17. package/examples/latest/layers/wordpress-2024-01.json +1 -1
  18. package/examples/latest/massive-schema.json +1 -1
  19. package/examples/latest/mill-components-schema.json +1 -1
  20. package/examples/latest/nested-shape-arrays.json +1 -1
  21. package/examples/latest/one-earth.json +1 -1
  22. package/examples/latest/pet-oneof-array.json +1 -1
  23. package/examples/latest/post-schema.json +1 -1
  24. package/examples/latest/pruned-shopify-product-schema.json +1 -1
  25. package/examples/latest/rag-example.json +1 -1
  26. package/examples/latest/real-world-schema.json +1 -1
  27. package/examples/latest/recursive-repeater-schema.json +1 -1
  28. package/examples/latest/recursive-schema.json +1 -1
  29. package/examples/latest/rick-and-morty-ast.json +1 -1
  30. package/examples/latest/rick-and-morty-graphql.json +1 -1
  31. package/examples/latest/rick-and-morty-rest.json +1 -1
  32. package/examples/latest/rick-and-morty-user-schema.json +1 -1
  33. package/examples/latest/rick-and-morty-with-indexing.json +1 -1
  34. package/examples/latest/schema-where-filter.json +1 -1
  35. package/examples/latest/schema-with-repeater-draftjs.json +1 -1
  36. package/examples/latest/schema-with-rick-and-morty.json +1 -1
  37. package/examples/latest/shape-books-v3_2_0.json +1 -1
  38. package/examples/latest/shape-books.json +1 -1
  39. package/examples/latest/shape-editor-schema-edited.json +1 -1
  40. package/examples/latest/shape-editor-schema-initial.json +1 -1
  41. package/examples/latest/shapedb-crud-every-prop-type.json +1 -1
  42. package/examples/latest/shopify-lookbook.json +1 -1
  43. package/examples/latest/shopify-product-2022-07.json +1 -1
  44. package/examples/latest/shopify-product-2023-04.json +1 -1
  45. package/examples/latest/shopify-store-with-widget.json +1 -1
  46. package/examples/latest/stripe-product-runtime-schema.json +1 -1
  47. package/examples/latest/stripe-starter-resolved.json +1 -1
  48. package/examples/latest/user-schema-no-required.json +1 -1
  49. package/examples/latest/user-schema-with-defaults.json +1 -1
  50. package/examples/latest/valvoline-ai-demo.json +1461 -1421
  51. package/examples/latest/vector-search-schema.json +1 -1
  52. package/package.json +10 -9
  53. package/dist/agents.d.ts +0 -62
  54. package/dist/agents.js +0 -338
  55. package/dist/api-version.d.ts +0 -5
  56. package/dist/api-version.js +0 -17
  57. package/dist/auth-schemas.d.ts +0 -128
  58. package/dist/auth-schemas.js +0 -7
  59. package/dist/auth-utils.d.ts +0 -5
  60. package/dist/auth-utils.js +0 -6
  61. package/dist/builtin-schema.d.ts +0 -18
  62. package/dist/builtin-schema.js +0 -683
  63. package/dist/constants.d.ts +0 -1
  64. package/dist/constants.js +0 -1
  65. package/dist/content-schema-transform.d.ts +0 -35
  66. package/dist/content-schema-transform.js +0 -162
  67. package/dist/create-input-schema.d.ts +0 -9
  68. package/dist/create-input-schema.js +0 -68
  69. package/dist/enum.d.ts +0 -2
  70. package/dist/enum.js +0 -9
  71. package/dist/flatten-templates.d.ts +0 -2
  72. package/dist/flatten-templates.js +0 -20
  73. package/dist/get-is-leaf.d.ts +0 -3
  74. package/dist/get-is-leaf.js +0 -56
  75. package/dist/index.d.ts +0 -62
  76. package/dist/index.js +0 -59
  77. package/dist/interfaces.d.ts +0 -14
  78. package/dist/interfaces.js +0 -86
  79. package/dist/layers/layers.d.ts +0 -26
  80. package/dist/layers/layers.js +0 -301
  81. package/dist/layers/refs.d.ts +0 -102
  82. package/dist/layers/refs.js +0 -220
  83. package/dist/layers/type-utils.d.ts +0 -59
  84. package/dist/layers/type-utils.js +0 -118
  85. package/dist/layers/visitor.d.ts +0 -5
  86. package/dist/layers/visitor.js +0 -38
  87. package/dist/migration/index.d.ts +0 -73
  88. package/dist/migration/index.js +0 -103
  89. package/dist/migration/to/v3.0.0.d.ts +0 -4
  90. package/dist/migration/to/v3.0.0.js +0 -212
  91. package/dist/migration/to/v3.1.0.d.ts +0 -4
  92. package/dist/migration/to/v3.1.0.js +0 -194
  93. package/dist/migration/to/v3.10.0.d.ts +0 -4
  94. package/dist/migration/to/v3.10.0.js +0 -67
  95. package/dist/migration/to/v3.11.0.d.ts +0 -4
  96. package/dist/migration/to/v3.11.0.js +0 -85
  97. package/dist/migration/to/v3.12.3.d.ts +0 -4
  98. package/dist/migration/to/v3.12.3.js +0 -87
  99. package/dist/migration/to/v3.13.0.d.ts +0 -4
  100. package/dist/migration/to/v3.13.0.js +0 -17
  101. package/dist/migration/to/v3.17.0.d.ts +0 -4
  102. package/dist/migration/to/v3.17.0.js +0 -22
  103. package/dist/migration/to/v3.18.0.d.ts +0 -4
  104. package/dist/migration/to/v3.18.0.js +0 -64
  105. package/dist/migration/to/v3.18.1.d.ts +0 -4
  106. package/dist/migration/to/v3.18.1.js +0 -12
  107. package/dist/migration/to/v3.18.2.d.ts +0 -4
  108. package/dist/migration/to/v3.18.2.js +0 -19
  109. package/dist/migration/to/v3.20.0.d.ts +0 -4
  110. package/dist/migration/to/v3.20.0.js +0 -24
  111. package/dist/migration/to/v3.22.0.d.ts +0 -4
  112. package/dist/migration/to/v3.22.0.js +0 -25
  113. package/dist/migration/to/v3.24.0.d.ts +0 -4
  114. package/dist/migration/to/v3.24.0.js +0 -11
  115. package/dist/migration/to/v3.25.0.d.ts +0 -4
  116. package/dist/migration/to/v3.25.0.js +0 -11
  117. package/dist/migration/to/v3.3.0.d.ts +0 -4
  118. package/dist/migration/to/v3.3.0.js +0 -13
  119. package/dist/migration/to/v3.31.0.d.ts +0 -4
  120. package/dist/migration/to/v3.31.0.js +0 -38
  121. package/dist/migration/to/v3.32.0.d.ts +0 -4
  122. package/dist/migration/to/v3.32.0.js +0 -59
  123. package/dist/migration/to/v3.34.0.d.ts +0 -6
  124. package/dist/migration/to/v3.34.0.js +0 -111
  125. package/dist/migration/to/v3.36.0.d.ts +0 -4
  126. package/dist/migration/to/v3.36.0.js +0 -22
  127. package/dist/migration/to/v3.39.0.d.ts +0 -4
  128. package/dist/migration/to/v3.39.0.js +0 -45
  129. package/dist/migration/to/v3.40.0.d.ts +0 -4
  130. package/dist/migration/to/v3.40.0.js +0 -26
  131. package/dist/migration/to/v3.46.0.d.ts +0 -4
  132. package/dist/migration/to/v3.46.0.js +0 -35
  133. package/dist/migration/to/v3.57.0.d.ts +0 -4
  134. package/dist/migration/to/v3.57.0.js +0 -18
  135. package/dist/migration/to/v3.9.0.d.ts +0 -4
  136. package/dist/migration/to/v3.9.0.js +0 -79
  137. package/dist/migration/types.d.ts +0 -26
  138. package/dist/migration/types.js +0 -3
  139. package/dist/migration/utils.d.ts +0 -2
  140. package/dist/migration/utils.js +0 -6
  141. package/dist/mocks.d.ts +0 -14
  142. package/dist/mocks.js +0 -58
  143. package/dist/models/agent.d.ts +0 -3
  144. package/dist/models/agent.js +0 -29
  145. package/dist/models/project-schema.d.ts +0 -18
  146. package/dist/models/project-schema.js +0 -119
  147. package/dist/models/query.d.ts +0 -3
  148. package/dist/models/query.js +0 -38
  149. package/dist/models/runtime-schema.d.ts +0 -9
  150. package/dist/models/runtime-schema.js +0 -20
  151. package/dist/models/shape.d.ts +0 -4
  152. package/dist/models/shape.js +0 -36
  153. package/dist/models/types.d.ts +0 -36
  154. package/dist/models/types.js +0 -1
  155. package/dist/models/user-schema.d.ts +0 -7
  156. package/dist/models/user-schema.js +0 -9
  157. package/dist/patterns.d.ts +0 -12
  158. package/dist/patterns.js +0 -1
  159. package/dist/project-schema/index.d.ts +0 -211
  160. package/dist/project-schema/index.js +0 -83
  161. package/dist/project-schema/latest.d.ts +0 -2619
  162. package/dist/project-schema/latest.js +0 -7
  163. package/dist/project-schema/migrate.d.ts +0 -4
  164. package/dist/project-schema/migrate.js +0 -218
  165. package/dist/project-schema/v1.0.0.d.ts +0 -299
  166. package/dist/project-schema/v1.0.0.js +0 -7
  167. package/dist/project-schema/v3.0.0.d.ts +0 -478
  168. package/dist/project-schema/v3.0.0.js +0 -7
  169. package/dist/project-schema/v3.1.0.d.ts +0 -621
  170. package/dist/project-schema/v3.1.0.js +0 -7
  171. package/dist/project-schema/v3.10.0.d.ts +0 -1201
  172. package/dist/project-schema/v3.10.0.js +0 -7
  173. package/dist/project-schema/v3.11.0.d.ts +0 -1210
  174. package/dist/project-schema/v3.11.0.js +0 -7
  175. package/dist/project-schema/v3.12.0.d.ts +0 -1214
  176. package/dist/project-schema/v3.12.0.js +0 -7
  177. package/dist/project-schema/v3.12.1.d.ts +0 -1273
  178. package/dist/project-schema/v3.12.1.js +0 -7
  179. package/dist/project-schema/v3.12.2.d.ts +0 -1283
  180. package/dist/project-schema/v3.12.2.js +0 -7
  181. package/dist/project-schema/v3.12.3.d.ts +0 -1306
  182. package/dist/project-schema/v3.12.3.js +0 -7
  183. package/dist/project-schema/v3.13.0.d.ts +0 -1317
  184. package/dist/project-schema/v3.13.0.js +0 -7
  185. package/dist/project-schema/v3.13.1.d.ts +0 -1412
  186. package/dist/project-schema/v3.13.1.js +0 -7
  187. package/dist/project-schema/v3.14.0.d.ts +0 -1436
  188. package/dist/project-schema/v3.14.0.js +0 -7
  189. package/dist/project-schema/v3.15.0.d.ts +0 -1458
  190. package/dist/project-schema/v3.15.0.js +0 -7
  191. package/dist/project-schema/v3.16.0.d.ts +0 -1470
  192. package/dist/project-schema/v3.16.0.js +0 -7
  193. package/dist/project-schema/v3.17.0.d.ts +0 -1467
  194. package/dist/project-schema/v3.17.0.js +0 -7
  195. package/dist/project-schema/v3.17.1.d.ts +0 -1468
  196. package/dist/project-schema/v3.17.1.js +0 -7
  197. package/dist/project-schema/v3.18.0.d.ts +0 -1333
  198. package/dist/project-schema/v3.18.0.js +0 -7
  199. package/dist/project-schema/v3.18.1.d.ts +0 -1332
  200. package/dist/project-schema/v3.18.1.js +0 -7
  201. package/dist/project-schema/v3.18.2.d.ts +0 -1332
  202. package/dist/project-schema/v3.18.2.js +0 -7
  203. package/dist/project-schema/v3.19.0.d.ts +0 -1336
  204. package/dist/project-schema/v3.19.0.js +0 -7
  205. package/dist/project-schema/v3.2.0.d.ts +0 -632
  206. package/dist/project-schema/v3.2.0.js +0 -7
  207. package/dist/project-schema/v3.20.0.d.ts +0 -1336
  208. package/dist/project-schema/v3.20.0.js +0 -7
  209. package/dist/project-schema/v3.21.0.d.ts +0 -1338
  210. package/dist/project-schema/v3.21.0.js +0 -7
  211. package/dist/project-schema/v3.22.0.d.ts +0 -1344
  212. package/dist/project-schema/v3.22.0.js +0 -7
  213. package/dist/project-schema/v3.23.0.d.ts +0 -1376
  214. package/dist/project-schema/v3.23.0.js +0 -7
  215. package/dist/project-schema/v3.24.0.d.ts +0 -1364
  216. package/dist/project-schema/v3.24.0.js +0 -7
  217. package/dist/project-schema/v3.25.0.d.ts +0 -1363
  218. package/dist/project-schema/v3.25.0.js +0 -7
  219. package/dist/project-schema/v3.26.0.d.ts +0 -1388
  220. package/dist/project-schema/v3.26.0.js +0 -7
  221. package/dist/project-schema/v3.27.0.d.ts +0 -1397
  222. package/dist/project-schema/v3.27.0.js +0 -7
  223. package/dist/project-schema/v3.28.0.d.ts +0 -1416
  224. package/dist/project-schema/v3.28.0.js +0 -7
  225. package/dist/project-schema/v3.29.0.d.ts +0 -1423
  226. package/dist/project-schema/v3.29.0.js +0 -7
  227. package/dist/project-schema/v3.3.0.d.ts +0 -632
  228. package/dist/project-schema/v3.3.0.js +0 -7
  229. package/dist/project-schema/v3.30.0.d.ts +0 -1416
  230. package/dist/project-schema/v3.30.0.js +0 -7
  231. package/dist/project-schema/v3.31.0.d.ts +0 -1448
  232. package/dist/project-schema/v3.31.0.js +0 -7
  233. package/dist/project-schema/v3.32.0.d.ts +0 -1439
  234. package/dist/project-schema/v3.32.0.js +0 -7
  235. package/dist/project-schema/v3.33.0.d.ts +0 -1445
  236. package/dist/project-schema/v3.33.0.js +0 -7
  237. package/dist/project-schema/v3.34.0.d.ts +0 -1445
  238. package/dist/project-schema/v3.34.0.js +0 -7
  239. package/dist/project-schema/v3.35.0.d.ts +0 -1464
  240. package/dist/project-schema/v3.35.0.js +0 -7
  241. package/dist/project-schema/v3.36.0.d.ts +0 -1470
  242. package/dist/project-schema/v3.36.0.js +0 -7
  243. package/dist/project-schema/v3.37.0.d.ts +0 -1522
  244. package/dist/project-schema/v3.37.0.js +0 -7
  245. package/dist/project-schema/v3.38.0.d.ts +0 -1522
  246. package/dist/project-schema/v3.38.0.js +0 -7
  247. package/dist/project-schema/v3.39.0.d.ts +0 -1529
  248. package/dist/project-schema/v3.39.0.js +0 -7
  249. package/dist/project-schema/v3.4.0.d.ts +0 -624
  250. package/dist/project-schema/v3.4.0.js +0 -7
  251. package/dist/project-schema/v3.40.0.d.ts +0 -1530
  252. package/dist/project-schema/v3.40.0.js +0 -7
  253. package/dist/project-schema/v3.41.0.d.ts +0 -1530
  254. package/dist/project-schema/v3.41.0.js +0 -7
  255. package/dist/project-schema/v3.42.0.d.ts +0 -1534
  256. package/dist/project-schema/v3.42.0.js +0 -7
  257. package/dist/project-schema/v3.43.0.d.ts +0 -1536
  258. package/dist/project-schema/v3.43.0.js +0 -7
  259. package/dist/project-schema/v3.44.0.d.ts +0 -1621
  260. package/dist/project-schema/v3.44.0.js +0 -7
  261. package/dist/project-schema/v3.45.0.d.ts +0 -1650
  262. package/dist/project-schema/v3.45.0.js +0 -7
  263. package/dist/project-schema/v3.46.0.d.ts +0 -1703
  264. package/dist/project-schema/v3.46.0.js +0 -7
  265. package/dist/project-schema/v3.47.0.d.ts +0 -1736
  266. package/dist/project-schema/v3.47.0.js +0 -7
  267. package/dist/project-schema/v3.48.0.d.ts +0 -2208
  268. package/dist/project-schema/v3.48.0.js +0 -7
  269. package/dist/project-schema/v3.49.0.d.ts +0 -2217
  270. package/dist/project-schema/v3.49.0.js +0 -7
  271. package/dist/project-schema/v3.5.0.d.ts +0 -649
  272. package/dist/project-schema/v3.5.0.js +0 -7
  273. package/dist/project-schema/v3.5.1.d.ts +0 -649
  274. package/dist/project-schema/v3.5.1.js +0 -7
  275. package/dist/project-schema/v3.50.0.d.ts +0 -2269
  276. package/dist/project-schema/v3.50.0.js +0 -7
  277. package/dist/project-schema/v3.51.0.d.ts +0 -2269
  278. package/dist/project-schema/v3.51.0.js +0 -7
  279. package/dist/project-schema/v3.52.0.d.ts +0 -2269
  280. package/dist/project-schema/v3.52.0.js +0 -7
  281. package/dist/project-schema/v3.53.0.d.ts +0 -2350
  282. package/dist/project-schema/v3.53.0.js +0 -7
  283. package/dist/project-schema/v3.54.0.d.ts +0 -2369
  284. package/dist/project-schema/v3.54.0.js +0 -7
  285. package/dist/project-schema/v3.55.0.d.ts +0 -2369
  286. package/dist/project-schema/v3.55.0.js +0 -7
  287. package/dist/project-schema/v3.56.0.d.ts +0 -2405
  288. package/dist/project-schema/v3.56.0.js +0 -7
  289. package/dist/project-schema/v3.57.0.d.ts +0 -2601
  290. package/dist/project-schema/v3.57.0.js +0 -7
  291. package/dist/project-schema/v3.58.0.d.ts +0 -2601
  292. package/dist/project-schema/v3.58.0.js +0 -7
  293. package/dist/project-schema/v3.59.0.d.ts +0 -2619
  294. package/dist/project-schema/v3.59.0.js +0 -7
  295. package/dist/project-schema/v3.6.0.d.ts +0 -658
  296. package/dist/project-schema/v3.6.0.js +0 -7
  297. package/dist/project-schema/v3.7.0.d.ts +0 -961
  298. package/dist/project-schema/v3.7.0.js +0 -7
  299. package/dist/project-schema/v3.8.0.d.ts +0 -979
  300. package/dist/project-schema/v3.8.0.js +0 -7
  301. package/dist/project-schema/v3.9.0.d.ts +0 -1178
  302. package/dist/project-schema/v3.9.0.js +0 -7
  303. package/dist/project-schema/v4.0.0.d.ts +0 -1328
  304. package/dist/project-schema/v4.0.0.js +0 -7
  305. package/dist/refs.d.ts +0 -218
  306. package/dist/refs.js +0 -616
  307. package/dist/relationships.d.ts +0 -40
  308. package/dist/relationships.js +0 -302
  309. package/dist/resolvers/ai/abort-agent-message-args.d.ts +0 -16
  310. package/dist/resolvers/ai/abort-agent-message-args.js +0 -13
  311. package/dist/resolvers/ai/abort-agent-message-response.d.ts +0 -39
  312. package/dist/resolvers/ai/abort-agent-message-response.js +0 -19
  313. package/dist/resolvers/ai/agent-chat-args.d.ts +0 -17
  314. package/dist/resolvers/ai/agent-chat-args.js +0 -14
  315. package/dist/resolvers/ai/agent-chat-payload.d.ts +0 -35
  316. package/dist/resolvers/ai/agent-chat-payload.js +0 -26
  317. package/dist/resolvers/ai/agent-chat-response.d.ts +0 -289
  318. package/dist/resolvers/ai/agent-chat-response.js +0 -21
  319. package/dist/resolvers/ai/agent-generate-args.d.ts +0 -17
  320. package/dist/resolvers/ai/agent-generate-args.js +0 -14
  321. package/dist/resolvers/ai/agent-message-input.d.ts +0 -73
  322. package/dist/resolvers/ai/agent-message-input.js +0 -39
  323. package/dist/resolvers/ai/agent-message-output.d.ts +0 -169
  324. package/dist/resolvers/ai/agent-message-output.js +0 -77
  325. package/dist/resolvers/ai/agent-message-payload.d.ts +0 -507
  326. package/dist/resolvers/ai/agent-message-payload.js +0 -156
  327. package/dist/resolvers/ai/agent-run-mode.d.ts +0 -7
  328. package/dist/resolvers/ai/agent-run-mode.js +0 -9
  329. package/dist/resolvers/ai/agent-session-payload.d.ts +0 -515
  330. package/dist/resolvers/ai/agent-session-payload.js +0 -175
  331. package/dist/resolvers/ai/create-agent-session-response.d.ts +0 -199
  332. package/dist/resolvers/ai/create-agent-session-response.js +0 -9
  333. package/dist/resolvers/ai/embedding-search.d.ts +0 -54
  334. package/dist/resolvers/ai/embedding-search.js +0 -46
  335. package/dist/resolvers/ai/get-agent-message-args.d.ts +0 -16
  336. package/dist/resolvers/ai/get-agent-message-args.js +0 -13
  337. package/dist/resolvers/ai/get-agent-message-response.d.ts +0 -805
  338. package/dist/resolvers/ai/get-agent-message-response.js +0 -63
  339. package/dist/resolvers/ai/inspect-agent-args.d.ts +0 -16
  340. package/dist/resolvers/ai/inspect-agent-args.js +0 -13
  341. package/dist/resolvers/ai/inspect-agent-response.d.ts +0 -504
  342. package/dist/resolvers/ai/inspect-agent-response.js +0 -48
  343. package/dist/resolvers/ai/send-agent-feedback-args.d.ts +0 -52
  344. package/dist/resolvers/ai/send-agent-feedback-args.js +0 -16
  345. package/dist/resolvers/ai/send-agent-message-args.d.ts +0 -48
  346. package/dist/resolvers/ai/send-agent-message-args.js +0 -36
  347. package/dist/resolvers/ai/send-agent-message-response.d.ts +0 -353
  348. package/dist/resolvers/ai/send-agent-message-response.js +0 -51
  349. package/dist/resolvers/ai/types.d.ts +0 -6
  350. package/dist/resolvers/ai/types.js +0 -1
  351. package/dist/resolvers/takeshape/assets/asset-image-meta.d.ts +0 -79
  352. package/dist/resolvers/takeshape/assets/asset-image-meta.js +0 -98
  353. package/dist/resolvers/takeshape/assets/asset-image-params.d.ts +0 -901
  354. package/dist/resolvers/takeshape/assets/asset-image-params.js +0 -726
  355. package/dist/resolvers/takeshape/assets/asset-image.d.ts +0 -17
  356. package/dist/resolvers/takeshape/assets/asset-image.js +0 -15
  357. package/dist/resolvers/takeshape/assets/asset.d.ts +0 -125
  358. package/dist/resolvers/takeshape/assets/asset.js +0 -107
  359. package/dist/resolvers/takeshape/assets/constants.d.ts +0 -11
  360. package/dist/resolvers/takeshape/assets/constants.js +0 -11
  361. package/dist/resolvers/takeshape/builtins/constants.d.ts +0 -1
  362. package/dist/resolvers/takeshape/builtins/constants.js +0 -1
  363. package/dist/runtime-schema.d.ts +0 -6
  364. package/dist/runtime-schema.js +0 -85
  365. package/dist/scalars.d.ts +0 -2
  366. package/dist/scalars.js +0 -4
  367. package/dist/schema-transform.d.ts +0 -19
  368. package/dist/schema-transform.js +0 -74
  369. package/dist/schema-util.d.ts +0 -266
  370. package/dist/schema-util.js +0 -1127
  371. package/dist/schemas/auth-schemas.json +0 -374
  372. package/dist/schemas/index.d.ts +0 -4
  373. package/dist/schemas/index.js +0 -170
  374. package/dist/schemas/project-schema/experimental-2025-07.json +0 -1297
  375. package/dist/schemas/project-schema/latest.d.ts +0 -180
  376. package/dist/schemas/project-schema/latest.js +0 -11
  377. package/dist/schemas/project-schema/latest.json +0 -4846
  378. package/dist/schemas/project-schema/meta-schema-v1.0.0.json +0 -193
  379. package/dist/schemas/project-schema/meta-schema-v3.0.0.json +0 -608
  380. package/dist/schemas/project-schema/meta-schema-v3.1.0.json +0 -608
  381. package/dist/schemas/project-schema/meta-schema-v3.2.0.json +0 -612
  382. package/dist/schemas/project-schema/meta-schema-v3.3.0.json +0 -612
  383. package/dist/schemas/project-schema/meta-schema-v3.4.0.json +0 -637
  384. package/dist/schemas/project-schema/meta-schema-v3.5.0.json +0 -626
  385. package/dist/schemas/project-schema/meta-schema-v3.5.1.json +0 -626
  386. package/dist/schemas/project-schema/meta-schema-v3.6.0.json +0 -629
  387. package/dist/schemas/project-schema/meta-schema-v3.7.0.json +0 -1137
  388. package/dist/schemas/project-schema/meta-schema-v3.8.0.json +0 -1137
  389. package/dist/schemas/project-schema/meta-schema-v3.9.0.json +0 -1477
  390. package/dist/schemas/project-schema/v1.0.0.json +0 -321
  391. package/dist/schemas/project-schema/v3.0.0.json +0 -414
  392. package/dist/schemas/project-schema/v3.1.0.json +0 -572
  393. package/dist/schemas/project-schema/v3.10.0.json +0 -2097
  394. package/dist/schemas/project-schema/v3.11.0.json +0 -2141
  395. package/dist/schemas/project-schema/v3.12.0.json +0 -2144
  396. package/dist/schemas/project-schema/v3.12.1.json +0 -2282
  397. package/dist/schemas/project-schema/v3.12.2.json +0 -2304
  398. package/dist/schemas/project-schema/v3.12.3.json +0 -2357
  399. package/dist/schemas/project-schema/v3.13.0.json +0 -2377
  400. package/dist/schemas/project-schema/v3.14.0.json +0 -2385
  401. package/dist/schemas/project-schema/v3.15.0.json +0 -2365
  402. package/dist/schemas/project-schema/v3.16.0.json +0 -2373
  403. package/dist/schemas/project-schema/v3.17.0.json +0 -2378
  404. package/dist/schemas/project-schema/v3.17.1.json +0 -2380
  405. package/dist/schemas/project-schema/v3.18.0.json +0 -2356
  406. package/dist/schemas/project-schema/v3.18.1.json +0 -2357
  407. package/dist/schemas/project-schema/v3.18.2.json +0 -2357
  408. package/dist/schemas/project-schema/v3.19.0.json +0 -2369
  409. package/dist/schemas/project-schema/v3.2.0.json +0 -580
  410. package/dist/schemas/project-schema/v3.20.0.json +0 -2369
  411. package/dist/schemas/project-schema/v3.21.0.json +0 -2376
  412. package/dist/schemas/project-schema/v3.22.0.json +0 -2381
  413. package/dist/schemas/project-schema/v3.23.0.json +0 -2456
  414. package/dist/schemas/project-schema/v3.24.0.json +0 -2556
  415. package/dist/schemas/project-schema/v3.25.0.json +0 -2552
  416. package/dist/schemas/project-schema/v3.26.0.json +0 -2599
  417. package/dist/schemas/project-schema/v3.27.0.json +0 -2611
  418. package/dist/schemas/project-schema/v3.28.0.json +0 -2656
  419. package/dist/schemas/project-schema/v3.29.0.json +0 -2670
  420. package/dist/schemas/project-schema/v3.3.0.json +0 -581
  421. package/dist/schemas/project-schema/v3.30.0.json +0 -2656
  422. package/dist/schemas/project-schema/v3.31.0.json +0 -2714
  423. package/dist/schemas/project-schema/v3.32.0.json +0 -2708
  424. package/dist/schemas/project-schema/v3.33.0.json +0 -2715
  425. package/dist/schemas/project-schema/v3.34.0.json +0 -2715
  426. package/dist/schemas/project-schema/v3.35.0.json +0 -2748
  427. package/dist/schemas/project-schema/v3.36.0.json +0 -2756
  428. package/dist/schemas/project-schema/v3.37.0.json +0 -2821
  429. package/dist/schemas/project-schema/v3.38.0.json +0 -2819
  430. package/dist/schemas/project-schema/v3.39.0.json +0 -2827
  431. package/dist/schemas/project-schema/v3.4.0.json +0 -571
  432. package/dist/schemas/project-schema/v3.40.0.json +0 -2830
  433. package/dist/schemas/project-schema/v3.41.0.json +0 -2830
  434. package/dist/schemas/project-schema/v3.42.0.json +0 -2835
  435. package/dist/schemas/project-schema/v3.43.0.json +0 -2841
  436. package/dist/schemas/project-schema/v3.44.0.json +0 -3013
  437. package/dist/schemas/project-schema/v3.45.0.json +0 -3064
  438. package/dist/schemas/project-schema/v3.46.0.json +0 -3136
  439. package/dist/schemas/project-schema/v3.47.0.json +0 -3189
  440. package/dist/schemas/project-schema/v3.48.0.json +0 -3196
  441. package/dist/schemas/project-schema/v3.49.0.json +0 -3239
  442. package/dist/schemas/project-schema/v3.5.0.json +0 -571
  443. package/dist/schemas/project-schema/v3.5.1.json +0 -571
  444. package/dist/schemas/project-schema/v3.50.0.json +0 -3320
  445. package/dist/schemas/project-schema/v3.51.0.json +0 -3326
  446. package/dist/schemas/project-schema/v3.52.0.json +0 -3326
  447. package/dist/schemas/project-schema/v3.53.0.json +0 -3476
  448. package/dist/schemas/project-schema/v3.54.0.json +0 -3512
  449. package/dist/schemas/project-schema/v3.55.0.json +0 -3515
  450. package/dist/schemas/project-schema/v3.56.0.json +0 -3530
  451. package/dist/schemas/project-schema/v3.57.0.json +0 -4815
  452. package/dist/schemas/project-schema/v3.58.0.json +0 -4815
  453. package/dist/schemas/project-schema/v3.59.0.json +0 -4846
  454. package/dist/schemas/project-schema/v3.6.0.json +0 -587
  455. package/dist/schemas/project-schema/v3.7.0.json +0 -587
  456. package/dist/schemas/project-schema/v3.8.0.json +0 -604
  457. package/dist/schemas/project-schema/v3.9.0.json +0 -604
  458. package/dist/schemas/project-schema/v4.0.0.json +0 -2316
  459. package/dist/schemas/project-schema.json +0 -214
  460. package/dist/service-dependencies.d.ts +0 -13
  461. package/dist/service-dependencies.js +0 -165
  462. package/dist/services/services.d.ts +0 -31
  463. package/dist/services/services.js +0 -145
  464. package/dist/services/types.d.ts +0 -11
  465. package/dist/services/types.js +0 -1
  466. package/dist/services/util.d.ts +0 -16
  467. package/dist/services/util.js +0 -36
  468. package/dist/shape-paths.d.ts +0 -7
  469. package/dist/shape-paths.js +0 -28
  470. package/dist/taxonomies.d.ts +0 -15
  471. package/dist/taxonomies.js +0 -24
  472. package/dist/template-shapes/index.d.ts +0 -7
  473. package/dist/template-shapes/index.js +0 -33
  474. package/dist/template-shapes/names.d.ts +0 -10
  475. package/dist/template-shapes/names.js +0 -21
  476. package/dist/template-shapes/templates.d.ts +0 -32
  477. package/dist/template-shapes/templates.js +0 -316
  478. package/dist/template-shapes/types.d.ts +0 -15
  479. package/dist/template-shapes/types.js +0 -7
  480. package/dist/template-shapes/where.d.ts +0 -37
  481. package/dist/template-shapes/where.js +0 -400
  482. package/dist/types/index.d.ts +0 -3
  483. package/dist/types/index.js +0 -2
  484. package/dist/types/transforms.d.ts +0 -15
  485. package/dist/types/transforms.js +0 -1
  486. package/dist/types/types.d.ts +0 -200
  487. package/dist/types/types.js +0 -10
  488. package/dist/types/utils.d.ts +0 -112
  489. package/dist/types/utils.js +0 -269
  490. package/dist/unions.d.ts +0 -14
  491. package/dist/unions.js +0 -77
  492. package/dist/util/ai-tools.d.ts +0 -2
  493. package/dist/util/ai-tools.js +0 -14
  494. package/dist/util/api-indexing.d.ts +0 -9
  495. package/dist/util/api-indexing.js +0 -57
  496. package/dist/util/coerce-value.d.ts +0 -9
  497. package/dist/util/coerce-value.js +0 -32
  498. package/dist/util/detect-cycles.d.ts +0 -7
  499. package/dist/util/detect-cycles.js +0 -45
  500. package/dist/util/expressions.d.ts +0 -34
  501. package/dist/util/expressions.js +0 -350
  502. package/dist/util/find-shape-at-path.d.ts +0 -21
  503. package/dist/util/find-shape-at-path.js +0 -53
  504. package/dist/util/form-config.d.ts +0 -11
  505. package/dist/util/form-config.js +0 -62
  506. package/dist/util/get-conflicting-properties.d.ts +0 -6
  507. package/dist/util/get-conflicting-properties.js +0 -55
  508. package/dist/util/get-return-shape.d.ts +0 -4
  509. package/dist/util/get-return-shape.js +0 -30
  510. package/dist/util/has-arg.d.ts +0 -6
  511. package/dist/util/has-arg.js +0 -25
  512. package/dist/util/is-asset-property.d.ts +0 -3
  513. package/dist/util/is-asset-property.js +0 -11
  514. package/dist/util/mcp.d.ts +0 -8
  515. package/dist/util/mcp.js +0 -21
  516. package/dist/util/merge.d.ts +0 -15
  517. package/dist/util/merge.js +0 -254
  518. package/dist/util/patch-schema.d.ts +0 -8
  519. package/dist/util/patch-schema.js +0 -51
  520. package/dist/util/query-field-path.d.ts +0 -9
  521. package/dist/util/query-field-path.js +0 -23
  522. package/dist/util/shapes.d.ts +0 -5
  523. package/dist/util/shapes.js +0 -22
  524. package/dist/validate/ai.d.ts +0 -6
  525. package/dist/validate/ai.js +0 -183
  526. package/dist/validate/errors.d.ts +0 -3
  527. package/dist/validate/errors.js +0 -20
  528. package/dist/validate/types.d.ts +0 -1
  529. package/dist/validate/types.js +0 -1
  530. package/dist/validate/util.d.ts +0 -3
  531. package/dist/validate/util.js +0 -28
  532. package/dist/validate/validate.d.ts +0 -80
  533. package/dist/validate/validate.js +0 -1058
  534. package/dist/versions.d.ts +0 -4
  535. package/dist/versions.js +0 -4
  536. package/dist/workflows.d.ts +0 -14
  537. package/dist/workflows.js +0 -66
@@ -1,1127 +0,0 @@
1
- import { DEFAULT_ENTITLEMENTS, deepClone, ensureArray, pascalCase, visit } from '@takeshape/util';
2
- import curry from 'lodash/fp/curry.js';
3
- import orderBy from 'lodash/fp/orderBy.js';
4
- import isArray from 'lodash/isArray.js';
5
- import isString from 'lodash/isString.js';
6
- import keyBy from 'lodash/keyBy.js';
7
- import mapValues from 'lodash/mapValues.js';
8
- import uniq from 'lodash/uniq.js';
9
- import { AGENTS_SCHEMA_PATH, getAgentMap } from './agents.js';
10
- import { workflowsEnabled } from "./api-version.js";
11
- import { allBuiltInShapes, getBuiltInForms, getBuiltInShapes } from "./builtin-schema.js";
12
- import { SERVICE_OBJECT_PATTERN_NAME } from "./constants.js";
13
- import { createTemplateShapeName, dereferenceObjectSchema, dereferenceSchema, getRef, getRefOrItemsRef, getRefShapeName, isValidRefItem, parseRef, parseReturnShape, refItemToNamespacedShapeName, refItemToShape, refItemToShapeSchema, refToRefItem, returnShapeToSchema, serializePropertyRef } from "./refs.js";
14
- import { getArgsType, isAllOfSchema, isArraySchema, isCachedShape, isExtendsSchema, isGraphqlResolver, isModelShape, isObjectSchema, isOneOfSchema, isReferenceableShape, isRefSchema } from "./types/index.js";
15
- import { isUnionSchema } from "./unions.js";
16
- import { getArgs } from "./util/has-arg.js";
17
- import { mergeFormProperties, mergeSchemaProperties } from "./util/merge.js";
18
- import { CURRENT_API_VERSION, CURRENT_SCHEMA_VERSION } from "./versions.js";
19
- import { defaultWorkflow, getStatusField } from "./workflows.js";
20
- export function isBuiltinShape(ref) {
21
- const parsed = parseRef({}, ref);
22
- return Boolean(parsed.layerId === 'local' && allBuiltInShapes[parsed.shapeName]);
23
- }
24
- const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(allBuiltInShapes));
25
- export function isBuiltinQuery(name) {
26
- return builtInQueriesAndMutations.queries[name] !== undefined;
27
- }
28
- export function isBuiltinMutation(name) {
29
- return builtInQueriesAndMutations.mutations[name] !== undefined;
30
- }
31
- export function isBuiltinType(projectSchema, refSchema) {
32
- const shapeName = getRefShapeName(projectSchema, refSchema);
33
- return shapeName !== undefined && isBuiltinShape(shapeName);
34
- }
35
- export const schemaMetadataKeys = [
36
- '$comment',
37
- 'title',
38
- 'description',
39
- '@l10n',
40
- '@deprecationReason',
41
- '@tag',
42
- '@tags',
43
- '@syncLocaleStructure',
44
- '@sensitive'
45
- ];
46
- export const commonSchemaKeys = ['type', 'default', 'readOnly', ...schemaMetadataKeys];
47
- export const scalarSchemaKeys = [
48
- ...commonSchemaKeys,
49
- 'format',
50
- 'oneOf',
51
- 'multipleOf',
52
- 'maximum',
53
- 'exclusiveMaximum',
54
- 'minimum',
55
- 'exclusiveMinimum',
56
- 'maxLength',
57
- 'minLength',
58
- 'pattern'
59
- ];
60
- export const objectSchemaKeys = [...commonSchemaKeys, 'properties', 'required'];
61
- export const arraySchemaKeys = [
62
- ...commonSchemaKeys,
63
- 'items',
64
- 'additionalItems',
65
- 'maxItems',
66
- 'minItems',
67
- 'uniqueItems'
68
- ];
69
- export const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems'];
70
- // All properties except properties, items, additionalItems
71
- export const nonStructuralSchemaKeys = [
72
- ...scalarSchemaKeys,
73
- '@resolver',
74
- '@input',
75
- '@output',
76
- '@backreference',
77
- '@args',
78
- 'required',
79
- 'maxItems',
80
- 'minItems',
81
- 'uniqueItems'
82
- ];
83
- export function getServiceIdFieldName(serviceFieldName) {
84
- return `${serviceFieldName}Id`;
85
- }
86
- const generatorVersions = {
87
- [SERVICE_OBJECT_PATTERN_NAME]: '1'
88
- };
89
- export function getGeneratorVersion(generator) {
90
- return generatorVersions[generator];
91
- }
92
- // Follow refs to find the path between two shapes in a schema
93
- export function pathBetween(fromShape, toShape, projectSchema, depthLimit = 4) {
94
- if (fromShape.name === toShape.name) {
95
- return [];
96
- }
97
- const toShapeName = toShape.name;
98
- let shortestPath;
99
- let shortestPathLength = Number.MAX_SAFE_INTEGER;
100
- const pathBetweenHelper = (schema, pathSoFar, seen, depth) => {
101
- if (depth > depthLimit) {
102
- return;
103
- }
104
- if (schema.items) {
105
- pathBetweenHelper(schema.items, pathSoFar, seen, depth);
106
- return;
107
- }
108
- const refItem = getRef(projectSchema, schema);
109
- if (refItem) {
110
- const referenced = refItemToShape(projectSchema, refItem);
111
- if (referenced) {
112
- if (referenced.name === toShapeName && pathSoFar.length < shortestPathLength) {
113
- shortestPath = pathSoFar;
114
- shortestPathLength = pathSoFar.length;
115
- }
116
- else if (!seen.has(referenced.name)) {
117
- pathBetweenHelper(referenced.schema, pathSoFar, new Set([...seen, referenced.name]), depth);
118
- }
119
- }
120
- }
121
- else if (pathSoFar.length + 1 < shortestPathLength && (schema.oneOf ?? schema.allOf ?? schema.properties)) {
122
- if (schema.oneOf) {
123
- for (const itemSchema of schema.oneOf) {
124
- pathBetweenHelper(itemSchema, pathSoFar, seen, depth);
125
- }
126
- }
127
- else {
128
- for (const [propName, propSchema] of createSchemaPropertyList(projectSchema, schema).getNodes()) {
129
- pathBetweenHelper(propSchema, pathSoFar.concat(String(propName)), seen, depth + 1);
130
- }
131
- }
132
- }
133
- };
134
- pathBetweenHelper(fromShape.schema, [], new Set([fromShape.name]), 0);
135
- if (!shortestPath) {
136
- throw new Error(`No path between ${fromShape.name} and ${toShape.name}`);
137
- }
138
- return shortestPath;
139
- }
140
- export function getShapeQueriesAndMutations(shapes) {
141
- const queries = {};
142
- const mutations = {};
143
- for (const shape of ensureArray(shapes)) {
144
- const { name, model } = shape;
145
- const service = 'shapedb';
146
- if (model) {
147
- const isSingleton = model.type === 'single';
148
- queries[`get${name}`] = {
149
- shape: name,
150
- resolver: {
151
- name: 'shapedb:get',
152
- service,
153
- shapeName: name
154
- },
155
- description: `Get a ${name} by ID`,
156
- args: isSingleton
157
- ? createTemplateShapeName('TSGetSingletonArgs', name)
158
- : createTemplateShapeName('TSGetArgs', name)
159
- };
160
- mutations[`update${name}`] = {
161
- shape: createTemplateShapeName('UpdateResult', name),
162
- resolver: {
163
- name: 'shapedb:update',
164
- service,
165
- shapeName: name
166
- },
167
- description: `Update ${name}`,
168
- args: createTemplateShapeName('UpdateArgs', name)
169
- };
170
- if (!isSingleton) {
171
- queries[`get${name}List`] = {
172
- shape: createTemplateShapeName('PaginatedList', name),
173
- resolver: {
174
- name: 'shapedb:list',
175
- service,
176
- shapeName: name
177
- },
178
- description: `Returns a list ${name} in natural order.`,
179
- args: createTemplateShapeName('TSListArgs', name)
180
- };
181
- mutations[`create${name}`] = {
182
- shape: createTemplateShapeName('CreateResult', name),
183
- resolver: {
184
- name: 'shapedb:create',
185
- service,
186
- shapeName: name
187
- },
188
- description: `Create ${name}`,
189
- args: createTemplateShapeName('CreateArgs', name)
190
- };
191
- mutations[`duplicate${name}`] = {
192
- shape: createTemplateShapeName('DuplicateResult', name),
193
- resolver: {
194
- name: 'shapedb:duplicate',
195
- service,
196
- shapeName: name
197
- },
198
- description: `Duplicate ${name}`,
199
- args: createTemplateShapeName('DuplicateArgs', name)
200
- };
201
- mutations[`delete${name}`] = {
202
- shape: createTemplateShapeName('DeleteResult', name),
203
- resolver: {
204
- name: 'shapedb:delete',
205
- service,
206
- shapeName: name
207
- },
208
- description: `Delete ${name}`,
209
- args: createTemplateShapeName('DeleteArgs', name)
210
- };
211
- }
212
- }
213
- }
214
- return { queries, mutations };
215
- }
216
- export function getCommonBuiltInProperties(shape) {
217
- return {
218
- _id: {
219
- title: 'Id',
220
- type: 'string'
221
- },
222
- _shapeId: {
223
- type: 'string',
224
- title: 'Shape Id',
225
- enum: [shape.id]
226
- }
227
- };
228
- }
229
- export const DEFAULT_ID_FIELD = 'id';
230
- export function getIdField(obj) {
231
- return obj?.idField ?? DEFAULT_ID_FIELD;
232
- }
233
- /**
234
- * Get properties necessary for cached / remote data to work with the TSSearchable interface.
235
- */
236
- function getCachedBuiltInProperties(shape, properties) {
237
- const idField = getIdField(shape.cache);
238
- // TODO Implement `searchSummary` and `_shapeId` here, and remove `getRemoteShapeTSSearchableFields`
239
- return {
240
- _id: {
241
- title: 'Id',
242
- type: 'string',
243
- ...properties._id,
244
- ...(properties[idField]?.['@mapping'] ? { '@mapping': properties[idField]['@mapping'] } : {})
245
- }
246
- };
247
- }
248
- export function getModelBuiltInProperties(projectSchema, shape) {
249
- const apiVersion = projectSchema.apiVersion ?? CURRENT_API_VERSION;
250
- const showDeprecationReason = apiVersion !== '1';
251
- const properties = {
252
- _version: {
253
- title: 'Version',
254
- type: 'integer'
255
- },
256
- _shapeName: {
257
- title: 'Shape Name',
258
- type: 'string'
259
- },
260
- _createdAt: {
261
- title: 'Created',
262
- type: 'string',
263
- format: 'date-time'
264
- },
265
- _createdBy: {
266
- title: 'Created By',
267
- '@ref': 'local:TSUser',
268
- '@input': {
269
- type: 'string'
270
- },
271
- '@resolver': {
272
- name: 'takeshape:getUser',
273
- service: 'takeshape'
274
- }
275
- },
276
- _updatedAt: {
277
- title: 'Updated',
278
- type: 'string',
279
- format: 'date-time'
280
- },
281
- _updatedBy: {
282
- title: 'Updated By',
283
- '@ref': 'local:TSUser',
284
- '@input': {
285
- type: 'string'
286
- },
287
- '@resolver': {
288
- name: 'takeshape:getUser',
289
- service: 'takeshape'
290
- }
291
- },
292
- _schemaVersion: {
293
- title: 'Schema Version',
294
- type: 'number'
295
- },
296
- _enabled: {
297
- title: 'Enabled',
298
- type: 'boolean',
299
- ...(showDeprecationReason ? { '@deprecationReason': 'Use _status instead' } : {})
300
- },
301
- _enabledAt: {
302
- title: 'Enabled Date',
303
- type: 'string',
304
- format: 'date-time',
305
- ...(showDeprecationReason ? { '@deprecationReason': 'Use a custom date field instead' } : {})
306
- }
307
- };
308
- if (workflowsEnabled(apiVersion)) {
309
- return {
310
- ...properties,
311
- _status: {
312
- ...(projectSchema.workflows && getStatusField(projectSchema.workflows, shape))
313
- }
314
- };
315
- }
316
- return properties;
317
- }
318
- /**
319
- * Return all the built in property names,
320
- */
321
- export function getBuiltInPropertyNames(profile = BuiltInPropertiesProfile.Model) {
322
- const fakeShape = {
323
- id: 'shape-id'
324
- };
325
- let keys = [...Object.keys(getCommonBuiltInProperties(fakeShape))];
326
- if (profile === BuiltInPropertiesProfile.Model) {
327
- keys = [...keys, ...Object.keys(getModelBuiltInProperties({}, fakeShape))];
328
- }
329
- return new Set(keys);
330
- }
331
- export var BuiltInPropertiesProfile;
332
- (function (BuiltInPropertiesProfile) {
333
- BuiltInPropertiesProfile[BuiltInPropertiesProfile["Model"] = 0] = "Model";
334
- BuiltInPropertiesProfile[BuiltInPropertiesProfile["Cached"] = 1] = "Cached";
335
- BuiltInPropertiesProfile[BuiltInPropertiesProfile["None"] = 2] = "None";
336
- })(BuiltInPropertiesProfile || (BuiltInPropertiesProfile = {}));
337
- const BUILT_IN_PROPERTY_NAMES = {
338
- [BuiltInPropertiesProfile.Model]: getBuiltInPropertyNames(BuiltInPropertiesProfile.Model),
339
- [BuiltInPropertiesProfile.Cached]: getBuiltInPropertyNames(BuiltInPropertiesProfile.Cached),
340
- [BuiltInPropertiesProfile.None]: getBuiltInPropertyNames(BuiltInPropertiesProfile.None)
341
- };
342
- export const isBuiltInPropertyName = (name, profile = BuiltInPropertiesProfile.Model) => {
343
- return BUILT_IN_PROPERTY_NAMES[profile].has(name);
344
- };
345
- /**
346
- * Get the profile to use for loading built-in properties
347
- */
348
- function getBuiltInPropertiesProfile(shape) {
349
- if (isModelShape(shape)) {
350
- return BuiltInPropertiesProfile.Model;
351
- }
352
- if (isCachedShape(shape) || isReferenceableShape(shape)) {
353
- return BuiltInPropertiesProfile.Cached;
354
- }
355
- return BuiltInPropertiesProfile.None;
356
- }
357
- export function applyBuiltinPropertiesToShape(projectSchema, shape) {
358
- const profile = getBuiltInPropertiesProfile(shape);
359
- if (profile === BuiltInPropertiesProfile.None) {
360
- return shape;
361
- }
362
- const shapeObjectSchema = dereferenceObjectSchema(projectSchema, shape.schema, ['shapes', shape.name]);
363
- const { properties } = shapeObjectSchema;
364
- const commonProperties = getCommonBuiltInProperties(shape);
365
- const modelProperties = profile === BuiltInPropertiesProfile.Model ? getModelBuiltInProperties(projectSchema, shape) : undefined;
366
- const cachedProperties = profile === BuiltInPropertiesProfile.Cached ? getCachedBuiltInProperties(shape, properties) : undefined;
367
- return {
368
- ...shape,
369
- schema: {
370
- ...shapeObjectSchema,
371
- properties: {
372
- ...properties,
373
- ...commonProperties,
374
- ...modelProperties,
375
- ...cachedProperties
376
- }
377
- }
378
- };
379
- }
380
- // Dependencies of these built-in shapes are automatically added by getBuiltinsUsed
381
- const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TSStaticSite', 'TSUser'];
382
- /**
383
- * Get all built-in shapes that are depended on by the given project schema.
384
- * Required built-in shapes are always included.
385
- */
386
- export function getBuiltinsUsed(builtInShapes, projectSchema) {
387
- const builtinsUsed = {};
388
- const shapeNames = uniq(requiredBuiltinShapes.concat(getAllRefs(projectSchema, (refItem) => refItem.layerId === 'local' && isBuiltinShape(refItem.shapeName)).map((ref) => refItemToNamespacedShapeName(projectSchema, ref))));
389
- const schemaWithAllBuiltins = {
390
- ...emptySchema('project-id'),
391
- shapes: builtInShapes
392
- };
393
- for (const builtinShapeName of shapeNames) {
394
- if (builtInShapes[builtinShapeName]) {
395
- builtinsUsed[builtinShapeName] = builtInShapes[builtinShapeName];
396
- for (const depShapeName of getShapeDependencies(schemaWithAllBuiltins, builtInShapes[builtinShapeName])) {
397
- builtinsUsed[depShapeName] = builtInShapes[depShapeName];
398
- }
399
- }
400
- }
401
- return builtinsUsed;
402
- }
403
- export function applyDefaultsToSchema(projectSchema, options) {
404
- const optionsWithDefaults = {
405
- entitlements: DEFAULT_ENTITLEMENTS,
406
- ...options
407
- };
408
- const builtInShapes = getBuiltInShapes(optionsWithDefaults);
409
- const builtinsUsed = getBuiltinsUsed(builtInShapes, projectSchema);
410
- const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(builtInShapes));
411
- const builtInForms = getBuiltInForms(optionsWithDefaults);
412
- return {
413
- ...projectSchema,
414
- workflows: {
415
- ...projectSchema.workflows,
416
- ...(workflowsEnabled(projectSchema.apiVersion) && {
417
- default: defaultWorkflow
418
- })
419
- },
420
- queries: {
421
- ...builtInQueriesAndMutations.queries,
422
- ...projectSchema.queries
423
- },
424
- mutations: {
425
- ...builtInQueriesAndMutations.mutations,
426
- ...projectSchema.mutations
427
- },
428
- shapes: mapValues({ ...builtinsUsed, ...projectSchema.shapes }, (shape) => {
429
- const builtInShape = builtinsUsed[shape.name];
430
- if (builtInShape && builtInShape !== shape) {
431
- shape = {
432
- ...shape,
433
- schema: mergeSchemaProperties(dereferenceObjectSchema(projectSchema, shape.schema), dereferenceObjectSchema(projectSchema, builtInShape.schema))
434
- };
435
- }
436
- return applyBuiltinPropertiesToShape(projectSchema, shape);
437
- }),
438
- forms: mapValues({ ...builtInForms, ...projectSchema.forms }, (formsConfig, shapeName) => {
439
- const builtInFormsConfig = builtInForms[shapeName];
440
- if (builtInFormsConfig && builtInFormsConfig !== formsConfig) {
441
- formsConfig = {
442
- ...formsConfig,
443
- default: mergeFormProperties(formsConfig.default, builtInFormsConfig.default)
444
- };
445
- }
446
- return formsConfig;
447
- })
448
- };
449
- }
450
- export function getArgsReference(projectSchema, argsSchema) {
451
- const args = getArgs(argsSchema);
452
- if (args && typeof args === 'string') {
453
- // @args: ShapeName OR Namespace_TypeName
454
- return parseRef(projectSchema, args);
455
- }
456
- }
457
- export function getArgsReferenceWithPath(context, argsSchema, schemaPath = []) {
458
- const refItem = getArgsReference(context, argsSchema);
459
- if (refItem) {
460
- const argsType = getArgsType(argsSchema);
461
- return {
462
- ...refItem,
463
- path: schemaPath.concat([argsType])
464
- };
465
- }
466
- }
467
- export function getArgsShapeSchema(context, argsSchema) {
468
- const args = getArgs(argsSchema);
469
- if (args) {
470
- if (typeof args === 'string') {
471
- const refItem = getArgsReference(context, argsSchema);
472
- if (refItem) {
473
- return refItemToShapeSchema(context, refItem);
474
- }
475
- }
476
- else {
477
- return args;
478
- }
479
- }
480
- }
481
- const createShapeToPropertySchema = (projectSchema, definitions, definitionNames, { useShapeIdDiscriminator, additionalProperties }) => {
482
- const rewriteRefs = (shape) => {
483
- const handleSchema = (propSchema) => {
484
- // Unwrap array schema
485
- propSchema = propSchema.items ?? propSchema;
486
- if (isOneOfSchema(propSchema)) {
487
- const isUnion = isUnionSchema(propSchema);
488
- if (useShapeIdDiscriminator && isUnion) {
489
- propSchema.discriminator = {
490
- propertyName: '_shapeId'
491
- };
492
- propSchema.required = ['_shapeId'];
493
- }
494
- for (const schema of propSchema.oneOf) {
495
- handleSchema(schema);
496
- }
497
- return;
498
- }
499
- // Add workflow validation
500
- if (propSchema['@workflow']) {
501
- const workflowName = propSchema['@workflow'];
502
- const workflow = projectSchema.workflows[workflowName] || defaultWorkflow;
503
- propSchema.oneOf = workflow.steps.map((step) => ({
504
- enum: [step.key, step.name],
505
- title: step.title
506
- }));
507
- }
508
- const refItem = getRef(projectSchema, propSchema);
509
- if (refItem) {
510
- const shapeName = refItemToNamespacedShapeName(projectSchema, refItem);
511
- const shape = refItemToShape(projectSchema, refItem);
512
- if (shape) {
513
- delete propSchema['@ref'];
514
- propSchema.$ref = `#/definitions/${shapeName}`;
515
- if (!definitionNames.has(shapeName)) {
516
- definitionNames.add(shapeName);
517
- const rewritten = rewriteRefs(shape);
518
- if (isObjectSchema(rewritten)) {
519
- if (useShapeIdDiscriminator) {
520
- rewritten.properties._shapeId = {
521
- type: 'string',
522
- enum: [shape.id]
523
- };
524
- }
525
- if (additionalProperties !== undefined) {
526
- rewritten.additionalProperties = additionalProperties;
527
- }
528
- }
529
- definitions[shapeName] = rewritten;
530
- }
531
- }
532
- }
533
- };
534
- const shapeSchema = deepClone(shape.schema);
535
- if (isOneOfSchema(shapeSchema)) {
536
- handleSchema(shapeSchema);
537
- return shapeSchema;
538
- }
539
- if (shapeSchema.enum) {
540
- return shapeSchema;
541
- }
542
- // An empty object schema is valid, allowing anything, but will fail dereferencing
543
- if (!Object.keys(shapeSchema).length) {
544
- return shapeSchema;
545
- }
546
- const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, shapeSchema);
547
- if (shape.title) {
548
- shapeSchemaCopy.title = shape.title;
549
- }
550
- for (const schema of Object.values(shapeSchemaCopy.properties)) {
551
- handleSchema(schema);
552
- }
553
- if (additionalProperties !== undefined) {
554
- shapeSchemaCopy.additionalProperties = additionalProperties;
555
- }
556
- return shapeSchemaCopy;
557
- };
558
- return rewriteRefs;
559
- };
560
- export function shapeToPropertySchema(projectSchema, shape) {
561
- const definitions = {};
562
- const definitionNames = new Set();
563
- const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
564
- useShapeIdDiscriminator: true
565
- });
566
- return {
567
- ...convert(shape),
568
- definitions
569
- };
570
- }
571
- /**
572
- * Currently this is not 100% valid JSON schema, but its output can be used with createSchemaValidator
573
- */
574
- export function shapeToJsonSchema(projectSchema, shape) {
575
- const definitions = {};
576
- const definitionNames = new Set();
577
- const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
578
- useShapeIdDiscriminator: false,
579
- additionalProperties: false
580
- });
581
- return {
582
- $id: shape.id,
583
- ...convert(shape),
584
- definitions
585
- };
586
- }
587
- export function projectSchemaToJSONSchema(projectSchema) {
588
- const definitions = {};
589
- const definitionNames = new Set();
590
- const convert = createShapeToPropertySchema(projectSchema, definitions, definitionNames, {
591
- useShapeIdDiscriminator: false
592
- });
593
- for (const shape of Object.values(projectSchema.shapes)) {
594
- definitions[shape.name] = convert(shape);
595
- definitionNames.add(shape.name);
596
- }
597
- return {
598
- definitions
599
- };
600
- }
601
- export function getShapeDependencies(projectSchema, shape, predicate) {
602
- const shapeNames = new Set();
603
- const findDependencies = (schema) => {
604
- const shouldFollow = Boolean(!predicate || predicate(schema));
605
- if (shouldFollow) {
606
- const refItem = getRef(projectSchema, schema);
607
- if (refItem) {
608
- const refShape = refItemToShape(projectSchema, refItem);
609
- if (refShape && !shapeNames.has(refShape.name)) {
610
- shapeNames.add(refShape.name);
611
- findDependencies(dereferenceSchema(projectSchema, refShape.schema, ['shapes', refShape.name]));
612
- }
613
- }
614
- else if (isObjectSchema(schema) ||
615
- isAllOfSchema(schema) ||
616
- isOneOfSchema(schema) ||
617
- isExtendsSchema(schema) ||
618
- isArraySchema(schema)) {
619
- visitSchemaProperties(schema, [], findDependencies);
620
- }
621
- const args = schema['@args'];
622
- if (args) {
623
- findDependencies(typeof args === 'string' ? { '@ref': args } : args);
624
- }
625
- }
626
- return shouldFollow;
627
- };
628
- findDependencies(shape.schema);
629
- return [...shapeNames];
630
- }
631
- export function getRelevantShapes(projectSchema, params) {
632
- const { shapeIds, shapeNames, byId = false, includeDependencies = true } = params;
633
- if (Boolean(shapeNames?.length) || Boolean(shapeIds?.length)) {
634
- const ids = new Set(shapeIds);
635
- const names = new Set(shapeNames);
636
- const shapes = {};
637
- for (const shape of Object.values(projectSchema.shapes)) {
638
- if (ids.has(shape.id) || names.has(shape.name)) {
639
- const shapeNames = includeDependencies
640
- ? [shape.name].concat(getShapeDependencies(projectSchema, shape))
641
- : [shape.name];
642
- for (const shapeName of shapeNames) {
643
- const dependentShape = projectSchema.shapes[shapeName];
644
- shapes[byId ? dependentShape.id : dependentShape.name] = dependentShape;
645
- }
646
- }
647
- }
648
- return shapes;
649
- }
650
- return {};
651
- }
652
- export function visitSchemaProperties(root, path, callback) {
653
- const visitEach = (entries, path) => {
654
- for (const [name, propSchema] of entries) {
655
- const newPath = [...path, name];
656
- visit(propSchema, newPath);
657
- }
658
- };
659
- const visit = (schema, path) => {
660
- if (schema !== root && callback(schema, path) === false) {
661
- return;
662
- }
663
- if (isArraySchema(schema)) {
664
- visit(schema.items, [...path, 'items']);
665
- }
666
- else if (isObjectSchema(schema)) {
667
- visitEach(Object.entries(schema.properties), [...path, 'properties']);
668
- }
669
- else if (isExtendsSchema(schema)) {
670
- visitEach(Object.entries(schema.extends), [...path, 'extends']);
671
- }
672
- else if (isAllOfSchema(schema)) {
673
- visitEach(Object.entries(schema.allOf), [...path, 'allOf']);
674
- }
675
- else if (isOneOfSchema(schema)) {
676
- visitEach(Object.entries(schema.oneOf), [...path, 'oneOf']);
677
- }
678
- };
679
- visit(root, path);
680
- }
681
- export function visitShapeProperties(shapes, callback) {
682
- for (const [shapeName, shape] of Object.entries(shapes)) {
683
- visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], callback);
684
- }
685
- }
686
- function addRef(refs, ref, predicate) {
687
- if (ref && (!predicate || predicate(ref))) {
688
- refs.push(ref);
689
- }
690
- }
691
- /**
692
- * Walk through a `ProjectSchemaJSON` and collect all the `ref`s.
693
- */
694
- export function getAllRefsInShapes(projectSchema, predicate) {
695
- const items = [];
696
- const refPropNames = ['$ref', '@ref', '@args', 'args', 'interfaces'];
697
- visit(projectSchema.shapes, refPropNames, (interfaces, refPath) => {
698
- const propName = refPath[refPath.length - 1];
699
- const path = ['shapes', ...refPath];
700
- if (propName === 'interfaces' && isArray(interfaces)) {
701
- interfaces.forEach((interfaceRefExpression, index) => {
702
- addRef(items, {
703
- ...parseRef(projectSchema, interfaceRefExpression),
704
- path: [...path, index]
705
- }, predicate);
706
- });
707
- }
708
- // The client sometimes generates invalid schemas, like refs that are
709
- // undefined. Treat ref as unknown and toss those out.
710
- // See the `useShapeEditor > can deal with renames test`
711
- if (!isString(interfaces)) {
712
- return;
713
- }
714
- if (propName === '@ref') {
715
- addRef(items, { ...parseRef(projectSchema, interfaces), path }, predicate);
716
- }
717
- else if (propName === '$ref') {
718
- addRef(items, { ...refToRefItem(projectSchema, interfaces), path }, predicate);
719
- }
720
- else if (propName === '@args' || propName === 'args') {
721
- addRef(items, { ...parseRef(projectSchema, interfaces), path }, predicate);
722
- }
723
- });
724
- return items;
725
- }
726
- export function getRefsInAgents(context, predicate) {
727
- const refs = [];
728
- const agents = getAgentMap(context);
729
- if (agents) {
730
- for (const [agentKey, agent] of Object.entries(agents)) {
731
- const agentPath = [...AGENTS_SCHEMA_PATH, agentKey];
732
- agent.api.inputs.forEach((input, index) => {
733
- const ref = {
734
- ...parseRef(context, input.args),
735
- path: [...agentPath, 'api', 'inputs', index, 'args']
736
- };
737
- addRef(refs, ref, predicate);
738
- });
739
- for (const [stateKey, state] of Object.entries(agent.states)) {
740
- const statePath = [...agentPath, 'states', stateKey];
741
- if (state.execution.type === 'chat') {
742
- if (state.execution.artifact) {
743
- const ref = {
744
- ...parseRef(context, state.execution.artifact),
745
- path: [...statePath, 'execution', 'artifact']
746
- };
747
- addRef(refs, ref, predicate);
748
- }
749
- }
750
- else if (state.execution.type === 'generate') {
751
- if (state.execution.outputShape) {
752
- const ref = {
753
- ...parseRef(context, state.execution.outputShape),
754
- path: [...statePath, 'execution', 'outputShape']
755
- };
756
- addRef(refs, ref, predicate);
757
- }
758
- }
759
- }
760
- }
761
- }
762
- return refs;
763
- }
764
- /**
765
- * Get all refs
766
- */
767
- export function getAllRefsInQuery(projectSchema, queryPath, query, predicate) {
768
- const refItems = [];
769
- const propertyVisitor = (propSchema, propSchemaPath) => {
770
- addRef(refItems, getRefOrItemsRef(projectSchema, propSchema, propSchemaPath), predicate);
771
- };
772
- if (query.args && typeof query.args === 'string') {
773
- addRef(refItems, getArgsReferenceWithPath(projectSchema, query, queryPath), predicate);
774
- }
775
- if (query.args && typeof query.args === 'object') {
776
- visitSchemaProperties(query.args, [...queryPath, 'args'], propertyVisitor);
777
- }
778
- if (query.shape) {
779
- const { isArray, ref } = parseReturnShape(projectSchema, query.shape);
780
- if (ref) {
781
- addRef(refItems, {
782
- ...ref,
783
- path: queryPath.concat(isArray ? ['shape', 'items', '@ref'] : ['shape'])
784
- }, predicate);
785
- }
786
- }
787
- return refItems;
788
- }
789
- /**
790
- * Collect refs from `queries` or `mutations`.
791
- */
792
- export function getAllRefsInQueries(projectSchema, rootPropertyName, predicate) {
793
- const refItems = [];
794
- const rootPath = [rootPropertyName];
795
- for (const [queryName, query] of Object.entries(projectSchema[rootPropertyName])) {
796
- const queryPath = rootPath.concat([queryName]);
797
- const queryRefs = getAllRefsInQuery(projectSchema, queryPath, query, predicate);
798
- if (queryRefs.length) {
799
- refItems.push(...queryRefs);
800
- }
801
- }
802
- return refItems;
803
- }
804
- /**
805
- * Get all refs in a ProjectSchemaJSON
806
- * @param predicate return true to include the ref in
807
- */
808
- export function getAllRefs(projectSchema, predicate) {
809
- return [
810
- ...getAllRefsInShapes(projectSchema, predicate),
811
- ...getAllRefsInQueries(projectSchema, 'queries', predicate),
812
- ...getAllRefsInQueries(projectSchema, 'mutations', predicate),
813
- ...getRefsInAgents(projectSchema, predicate)
814
- ];
815
- }
816
- /**
817
- * Get all valid refs in a ProjectSchemaJSON
818
- * @param predicate return true to include the ref in
819
- */
820
- export function getAllValidRefs(projectSchema, predicate) {
821
- return getAllRefs(projectSchema, predicate).filter(isValidRefItem(projectSchema));
822
- }
823
- export function splitMapping(mapping) {
824
- const parts = mapping.split('.');
825
- return [parts[0], parts.slice(1).join('.')];
826
- }
827
- export function findMapping(schema, predicate) {
828
- const mapping = schema['@mapping'];
829
- if (Array.isArray(mapping)) {
830
- return mapping.find(predicate);
831
- }
832
- return mapping && predicate(mapping) ? mapping : undefined;
833
- }
834
- export function getFirstMapping(schema) {
835
- return Array.isArray(schema['@mapping']) ? schema['@mapping'][0] : schema['@mapping'];
836
- }
837
- /**
838
- * Find key for use storing data in ShapeDB or API Indexing this allows renaming of properties without db migration
839
- * Mapping must be using the shapedb service id
840
- * @param schema
841
- */
842
- export function getStorageKey(schema) {
843
- const first = findMapping(schema, (mapping) => mapping.startsWith('shapedb:'));
844
- return first ? splitMapping(first)[1] : undefined;
845
- }
846
- export function emptySchema(projectId) {
847
- return {
848
- projectId,
849
- defaultLocale: 'en-us',
850
- locales: ['en-us'],
851
- apiVersion: '2',
852
- schemaVersion: CURRENT_SCHEMA_VERSION,
853
- queries: {},
854
- mutations: {},
855
- shapes: {},
856
- workflows: {},
857
- forms: {}
858
- };
859
- }
860
- export function createLayerSchema(partialSchema) {
861
- return {
862
- schemaVersion: CURRENT_SCHEMA_VERSION,
863
- queries: {},
864
- mutations: {},
865
- shapes: {},
866
- ...partialSchema
867
- };
868
- }
869
- export function getShapesById(projectSchema) {
870
- return keyBy(Object.values(projectSchema.shapes), 'id');
871
- }
872
- /**
873
- * Walk through the project schema and return an array of all
874
- * referenced shape names that are in a service namespace.
875
- *
876
- * @param projectSchema A V3 project schema.
877
- *
878
- * @returns A `string` array with all the shapes that are in namespaces.
879
- */
880
- export function getAllNamespaceShapes(projectSchema) {
881
- const isServiceRef = (refItem) => refItem.layerId !== 'local';
882
- return uniq(getAllValidRefs(projectSchema, isServiceRef).map((ref) => refItemToNamespacedShapeName(projectSchema, ref)));
883
- }
884
- /**
885
- * Returns a list of all shape names in a service namespace, excluding any
886
- * that have been set directly in the project schema
887
- *
888
- * @todo It's unsound to discard dependencies in this way, should avoid
889
- * collisions with aliases or similar any remote shape that collides,
890
- * e.g., Shopify_Product -> Shopify_Product_2
891
- *
892
- * @param projectSchema A V3 project schema with remote service configs.
893
- *
894
- * @returns A `Set` of shape names.
895
- */
896
- export function getNamespacedShapeNameList(projectSchema) {
897
- const requiredShapeNames = new Set();
898
- // All the shape names
899
- const existingShapeNames = new Set(Object.keys(projectSchema.shapes));
900
- // All the referenced shape names with namespaces that belong to a service
901
- const namespacedShapeNames = new Set(getAllNamespaceShapes(projectSchema));
902
- // Add all namespaced shapes to the schema if they are not already present,
903
- // e.g. Shopify_Product
904
- for (const name of namespacedShapeNames) {
905
- if (!existingShapeNames.has(name)) {
906
- requiredShapeNames.add(name);
907
- }
908
- }
909
- return requiredShapeNames;
910
- }
911
- /**
912
- * Filter the service map to return only services passing the GraphQL Service
913
- * typeguard.
914
- *
915
- * @param serviceMap A service map.
916
- *
917
- * @returns A new map with the filtered list of services
918
- */
919
- export function filterGraphQLServiceMap(serviceMap) {
920
- const filtered = new Map();
921
- for (const [serviceKey, serviceConfig] of serviceMap) {
922
- if (serviceConfig.serviceType === 'graphql') {
923
- filtered.set(serviceKey, serviceConfig);
924
- }
925
- }
926
- return filtered;
927
- }
928
- /**
929
- * Creates a schema property list chainable fn, allowing you to manipulate and
930
- * iterate the properties in a schema.
931
- */
932
- export const createSchemaPropertyList = curry((context, shapeOrSchema) => {
933
- const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
934
- const schema = dereferenceSchema(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
935
- const propertyIterator = new Map(isObjectSchema(schema) ? Object.entries(schema.properties) : undefined);
936
- const defaultOrderByIteratees = [(n) => n[0]];
937
- const defaultOrderByOrders = ['asc'];
938
- const _orderBy = (iteratees = defaultOrderByIteratees, orders = defaultOrderByOrders) => {
939
- self._propertyIterator = new Map(orderBy(iteratees, orders, Array.from(self._propertyIterator)));
940
- return self;
941
- };
942
- const _sortWith = (comparator) => {
943
- self._propertyIterator = new Map(Array.from(self._propertyIterator).sort(comparator));
944
- return self;
945
- };
946
- const _sortByNamesWithList = (comparatorArray) => {
947
- // If no array is provided, the original sort is preserved
948
- if (comparatorArray) {
949
- self._propertyIterator = new Map(Array.from(self._propertyIterator)
950
- .filter(([name]) => comparatorArray.includes(name))
951
- .sort(([nameA], [nameB]) => {
952
- const indexA = comparatorArray.indexOf(nameA);
953
- const indexB = comparatorArray.indexOf(nameB);
954
- return ((indexA > -1 ? indexA : Number.POSITIVE_INFINITY) - (indexB > -1 ? indexB : Number.POSITIVE_INFINITY));
955
- }));
956
- }
957
- return self;
958
- };
959
- const _filterBy = (predicate) => {
960
- self._propertyIterator = new Map(Array.from(self._propertyIterator).filter(predicate));
961
- return self;
962
- };
963
- const _forEach = (iteratee) => {
964
- Array.from(self._propertyIterator).forEach(iteratee);
965
- return self;
966
- };
967
- const _getNodes = () => {
968
- return Array.from(self._propertyIterator);
969
- };
970
- const _getObject = () => {
971
- return Array.from(self._propertyIterator).reduce((curr, node) => Object.assign(curr, { [node[0]]: node[1] }), {});
972
- };
973
- const _getNames = () => {
974
- return Array.from(self._propertyIterator, ([name]) => name);
975
- };
976
- const _getValues = () => {
977
- return Array.from(self._propertyIterator, ([, value]) => value);
978
- };
979
- const self = {
980
- _propertyIterator: propertyIterator,
981
- orderBy: _orderBy,
982
- sortWith: _sortWith,
983
- sortByNamesWithList: _sortByNamesWithList,
984
- filterBy: _filterBy,
985
- forEach: _forEach,
986
- getNodes: _getNodes,
987
- getObject: _getObject,
988
- getNames: _getNames,
989
- getValues: _getValues
990
- };
991
- return self;
992
- });
993
- function isShape(shapeOrSchema) {
994
- return 'schema' in shapeOrSchema;
995
- }
996
- class SchemaPropertyAccessor {
997
- schema;
998
- properties;
999
- entries;
1000
- constructor(context, shapeOrSchema) {
1001
- const propSchema = isShape(shapeOrSchema) ? shapeOrSchema.schema : shapeOrSchema;
1002
- this.schema = dereferenceSchema(context, propSchema, isShape(shapeOrSchema) ? ['shapes', shapeOrSchema.name] : undefined);
1003
- this.entries = isObjectSchema(this.schema) ? Object.entries(this.schema.properties) : [];
1004
- this.properties = new Map(this.entries);
1005
- }
1006
- getValue(propertyName) {
1007
- return this.properties.get(propertyName);
1008
- }
1009
- findValue(predicate) {
1010
- return this.entries.find(predicate)?.[1];
1011
- }
1012
- findName(predicate) {
1013
- return this.entries.find(predicate)?.[0];
1014
- }
1015
- getKey(propertyName) {
1016
- const value = this.properties.get(propertyName);
1017
- if (value) {
1018
- return getStorageKey(value);
1019
- }
1020
- }
1021
- }
1022
- /**
1023
- * Creates a schema property accessor, allowing you to safely access schema
1024
- * properties.
1025
- */
1026
- export const createSchemaPropertyAccessor = curry((context, shapeOrSchema) => {
1027
- return new SchemaPropertyAccessor(context, shapeOrSchema);
1028
- });
1029
- function findQueryHelper(slice, shapeName, resolver, type) {
1030
- const schemaPath = type === 'query' ? 'queries' : 'mutations';
1031
- return Object.keys(slice[schemaPath]).find((queryName) => {
1032
- const queryOrMutation = slice[schemaPath][queryName];
1033
- return (queryOrMutation.resolver.name === resolver &&
1034
- queryOrMutation.resolver.shapeName === shapeName);
1035
- });
1036
- }
1037
- function ensureQueryHelper(slice, shapeName, resolver, type) {
1038
- const foundQuery = findQueryHelper(slice, shapeName, resolver, type);
1039
- if (!foundQuery) {
1040
- throw new Error(`Failed to find a "${resolver}" ${type} for shape "${shapeName}"`);
1041
- }
1042
- return foundQuery;
1043
- }
1044
- /**
1045
- * Find the query in the schema that corresponds to the given shape and resolver.
1046
- */
1047
- export const findQueryByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'query');
1048
- /**
1049
- * Find the query in the schema that corresponds to the given shape and resolver.
1050
- */
1051
- export const findMutationByShape = (projectSchema, shapeName, resolver) => findQueryHelper(projectSchema, shapeName, resolver, 'mutation');
1052
- /**
1053
- * Find the query in the schema that corresponds to the given shape and resolver.
1054
- * Throw an error if that query does not exist
1055
- */
1056
- export const ensureQueryByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'query');
1057
- /**
1058
- * Find the mutation in the schema that corresponds to the given shape and resolver.
1059
- * Throw an error if that mutation does not exist
1060
- */
1061
- export const ensureMutationByShape = (projectSchema, shapeName, resolver) => ensureQueryHelper(projectSchema, shapeName, resolver, 'mutation');
1062
- /**
1063
- * Find the query in the schema that corresponds to the given shape and resolver.
1064
- */
1065
- export const getDefaultMutationName = (shapeName, resolver) => {
1066
- const action = resolver.substring(resolver.indexOf(':') + 1);
1067
- return `${action}${shapeName}`;
1068
- };
1069
- export function createShape(name, schema, rest) {
1070
- return {
1071
- name,
1072
- id: name,
1073
- title: name,
1074
- schema,
1075
- ...rest
1076
- };
1077
- }
1078
- export function queryToPropertySchema(projectSchema, query) {
1079
- let mapping;
1080
- if (isGraphqlResolver(query.resolver)) {
1081
- mapping = serializePropertyRef({
1082
- layerId: query.resolver.service,
1083
- shapeName: 'Query',
1084
- propertyName: query.resolver.fieldName
1085
- });
1086
- }
1087
- return {
1088
- ...returnShapeToSchema(projectSchema, query.shape),
1089
- ...(mapping ? { '@mapping': mapping } : {}),
1090
- '@resolver': query.resolver,
1091
- '@args': query.args
1092
- };
1093
- }
1094
- export function getQueriesShape(projectSchema, operation) {
1095
- return createShape(pascalCase(operation), {
1096
- type: 'object',
1097
- properties: mapValues(projectSchema[operation === 'query' ? 'queries' : 'mutations'], (query) => queryToPropertySchema(projectSchema, query))
1098
- });
1099
- }
1100
- /**
1101
- * Return true if `schemaWithRef` is a ref to a shape named `shapeName`
1102
- */
1103
- export function schemaMatchesShapeName(workingCopy, propertySchema, shapeName) {
1104
- const arrayOfShapeRef = getRef(workingCopy, propertySchema);
1105
- return Boolean(arrayOfShapeRef && refItemToNamespacedShapeName(workingCopy, arrayOfShapeRef) === shapeName);
1106
- }
1107
- /**
1108
- * Return true if `shape` has a property that is an array of refs to `shapeName`
1109
- */
1110
- export const shapeHasArrayPropOfShape = (projectSchema, shape, shapeName) => {
1111
- if (shape && isObjectSchema(shape.schema)) {
1112
- for (const propName in shape.schema.properties) {
1113
- if (Object.hasOwn(shape.schema.properties, propName)) {
1114
- const propSchema = shape.schema.properties[propName];
1115
- if (propSchema.items &&
1116
- isRefSchema(propSchema.items) &&
1117
- schemaMatchesShapeName(projectSchema, propSchema.items, shapeName)) {
1118
- return true;
1119
- }
1120
- }
1121
- }
1122
- }
1123
- return false;
1124
- };
1125
- export const getQueryMapName = (type) => {
1126
- return type === 'query' ? 'queries' : 'mutations';
1127
- };