@decocms/blocks 8.1.0-next.1 → 8.1.0-next.3

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 (392) hide show
  1. package/bin/deco.js +5 -12
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +4 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/protocol/assets.d.ts +46 -0
  7. package/dist/protocol/assets.d.ts.map +1 -0
  8. package/dist/protocol/assets.js +105 -0
  9. package/dist/protocol/assets.js.map +1 -0
  10. package/dist/protocol/canonical.d.ts +8 -0
  11. package/dist/protocol/canonical.d.ts.map +1 -0
  12. package/dist/protocol/canonical.js +8 -0
  13. package/dist/protocol/canonical.js.map +1 -0
  14. package/dist/protocol/ciphertext.d.ts +7 -0
  15. package/dist/protocol/ciphertext.d.ts.map +1 -0
  16. package/dist/protocol/ciphertext.js +7 -0
  17. package/dist/protocol/ciphertext.js.map +1 -0
  18. package/dist/protocol/client.d.ts +54 -0
  19. package/dist/protocol/client.d.ts.map +1 -0
  20. package/dist/protocol/client.js +104 -0
  21. package/dist/protocol/client.js.map +1 -0
  22. package/dist/protocol/conformance/cases/assets.d.ts +3 -0
  23. package/dist/protocol/conformance/cases/assets.d.ts.map +1 -0
  24. package/dist/protocol/conformance/cases/assets.js +71 -0
  25. package/dist/protocol/conformance/cases/assets.js.map +1 -0
  26. package/dist/protocol/conformance/cases/guards.d.ts +3 -0
  27. package/dist/protocol/conformance/cases/guards.d.ts.map +1 -0
  28. package/dist/protocol/conformance/cases/guards.js +265 -0
  29. package/dist/protocol/conformance/cases/guards.js.map +1 -0
  30. package/dist/protocol/conformance/cases/reads.d.ts +3 -0
  31. package/dist/protocol/conformance/cases/reads.d.ts.map +1 -0
  32. package/dist/protocol/conformance/cases/reads.js +140 -0
  33. package/dist/protocol/conformance/cases/reads.js.map +1 -0
  34. package/dist/protocol/conformance/cases/types.d.ts +9 -0
  35. package/dist/protocol/conformance/cases/types.d.ts.map +1 -0
  36. package/dist/protocol/conformance/cases/types.js +2 -0
  37. package/dist/protocol/conformance/cases/types.js.map +1 -0
  38. package/dist/protocol/conformance/cases/wire.d.ts +3 -0
  39. package/dist/protocol/conformance/cases/wire.d.ts.map +1 -0
  40. package/dist/protocol/conformance/cases/wire.js +130 -0
  41. package/dist/protocol/conformance/cases/wire.js.map +1 -0
  42. package/dist/protocol/conformance/cases/writes.d.ts +3 -0
  43. package/dist/protocol/conformance/cases/writes.d.ts.map +1 -0
  44. package/dist/protocol/conformance/cases/writes.js +278 -0
  45. package/dist/protocol/conformance/cases/writes.js.map +1 -0
  46. package/dist/protocol/conformance/contentHashFixtures.d.ts +51 -0
  47. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -0
  48. package/dist/protocol/conformance/contentHashFixtures.js +94 -0
  49. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -0
  50. package/dist/protocol/conformance/context.d.ts +100 -0
  51. package/dist/protocol/conformance/context.d.ts.map +1 -0
  52. package/dist/protocol/conformance/context.js +155 -0
  53. package/dist/protocol/conformance/context.js.map +1 -0
  54. package/dist/protocol/conformance/index.d.ts +32 -0
  55. package/dist/protocol/conformance/index.d.ts.map +1 -0
  56. package/dist/protocol/conformance/index.js +90 -0
  57. package/dist/protocol/conformance/index.js.map +1 -0
  58. package/dist/protocol/errors.d.ts +85 -0
  59. package/dist/protocol/errors.d.ts.map +1 -0
  60. package/dist/protocol/errors.js +62 -0
  61. package/dist/protocol/errors.js.map +1 -0
  62. package/dist/protocol/index.d.ts +28 -0
  63. package/dist/protocol/index.d.ts.map +1 -0
  64. package/dist/protocol/index.js +28 -0
  65. package/dist/protocol/index.js.map +1 -0
  66. package/dist/protocol/keys.d.ts +101 -0
  67. package/dist/protocol/keys.d.ts.map +1 -0
  68. package/dist/protocol/keys.js +223 -0
  69. package/dist/protocol/keys.js.map +1 -0
  70. package/dist/protocol/params.d.ts +10 -0
  71. package/dist/protocol/params.d.ts.map +1 -0
  72. package/dist/protocol/params.js +54 -0
  73. package/dist/protocol/params.js.map +1 -0
  74. package/dist/protocol/secrets.d.ts +22 -0
  75. package/dist/protocol/secrets.d.ts.map +1 -0
  76. package/dist/protocol/secrets.js +200 -0
  77. package/dist/protocol/secrets.js.map +1 -0
  78. package/dist/protocol/server/assets.d.ts +20 -0
  79. package/dist/protocol/server/assets.d.ts.map +1 -0
  80. package/dist/protocol/server/assets.js +77 -0
  81. package/dist/protocol/server/assets.js.map +1 -0
  82. package/dist/protocol/server/auth.d.ts +31 -0
  83. package/dist/protocol/server/auth.d.ts.map +1 -0
  84. package/dist/protocol/server/auth.js +32 -0
  85. package/dist/protocol/server/auth.js.map +1 -0
  86. package/dist/protocol/server/bodyCache.d.ts +28 -0
  87. package/dist/protocol/server/bodyCache.d.ts.map +1 -0
  88. package/dist/protocol/server/bodyCache.js +75 -0
  89. package/dist/protocol/server/bodyCache.js.map +1 -0
  90. package/dist/protocol/server/content.d.ts +44 -0
  91. package/dist/protocol/server/content.d.ts.map +1 -0
  92. package/dist/protocol/server/content.js +132 -0
  93. package/dist/protocol/server/content.js.map +1 -0
  94. package/dist/protocol/server/core.d.ts +63 -0
  95. package/dist/protocol/server/core.d.ts.map +1 -0
  96. package/dist/protocol/server/core.js +77 -0
  97. package/dist/protocol/server/core.js.map +1 -0
  98. package/dist/protocol/server/handler.d.ts +5 -0
  99. package/dist/protocol/server/handler.d.ts.map +1 -0
  100. package/dist/protocol/server/handler.js +70 -0
  101. package/dist/protocol/server/handler.js.map +1 -0
  102. package/dist/protocol/server/http.d.ts +24 -0
  103. package/dist/protocol/server/http.d.ts.map +1 -0
  104. package/dist/protocol/server/http.js +133 -0
  105. package/dist/protocol/server/http.js.map +1 -0
  106. package/dist/protocol/server/index.d.ts +11 -0
  107. package/dist/protocol/server/index.d.ts.map +1 -0
  108. package/dist/protocol/server/index.js +9 -0
  109. package/dist/protocol/server/index.js.map +1 -0
  110. package/dist/protocol/server/methods/apply.d.ts +4 -0
  111. package/dist/protocol/server/methods/apply.d.ts.map +1 -0
  112. package/dist/protocol/server/methods/apply.js +275 -0
  113. package/dist/protocol/server/methods/apply.js.map +1 -0
  114. package/dist/protocol/server/methods/read.d.ts +14 -0
  115. package/dist/protocol/server/methods/read.d.ts.map +1 -0
  116. package/dist/protocol/server/methods/read.js +132 -0
  117. package/dist/protocol/server/methods/read.js.map +1 -0
  118. package/dist/protocol/server/rpc.d.ts +7 -0
  119. package/dist/protocol/server/rpc.d.ts.map +1 -0
  120. package/dist/protocol/server/rpc.js +115 -0
  121. package/dist/protocol/server/rpc.js.map +1 -0
  122. package/dist/protocol/storage/fs/hash.d.ts +8 -0
  123. package/dist/protocol/storage/fs/hash.d.ts.map +1 -0
  124. package/dist/protocol/storage/fs/hash.js +20 -0
  125. package/dist/protocol/storage/fs/hash.js.map +1 -0
  126. package/dist/protocol/storage/fs/index.d.ts +30 -0
  127. package/dist/protocol/storage/fs/index.d.ts.map +1 -0
  128. package/dist/protocol/storage/fs/index.js +301 -0
  129. package/dist/protocol/storage/fs/index.js.map +1 -0
  130. package/dist/protocol/storage/fs/lock.d.ts +8 -0
  131. package/dist/protocol/storage/fs/lock.d.ts.map +1 -0
  132. package/dist/protocol/storage/fs/lock.js +61 -0
  133. package/dist/protocol/storage/fs/lock.js.map +1 -0
  134. package/dist/protocol/storage/fs/transaction.d.ts +19 -0
  135. package/dist/protocol/storage/fs/transaction.d.ts.map +1 -0
  136. package/dist/protocol/storage/fs/transaction.js +174 -0
  137. package/dist/protocol/storage/fs/transaction.js.map +1 -0
  138. package/dist/protocol/storage/fs/unsupported.d.ts +10 -0
  139. package/dist/protocol/storage/fs/unsupported.d.ts.map +1 -0
  140. package/dist/protocol/storage/fs/unsupported.js +4 -0
  141. package/dist/protocol/storage/fs/unsupported.js.map +1 -0
  142. package/dist/protocol/storage/memory.d.ts +40 -0
  143. package/dist/protocol/storage/memory.d.ts.map +1 -0
  144. package/dist/protocol/storage/memory.js +179 -0
  145. package/dist/protocol/storage/memory.js.map +1 -0
  146. package/dist/protocol/storage.d.ts +178 -0
  147. package/dist/protocol/storage.d.ts.map +1 -0
  148. package/dist/protocol/storage.js +29 -0
  149. package/dist/protocol/storage.js.map +1 -0
  150. package/dist/protocol/types.d.ts +194 -0
  151. package/dist/protocol/types.d.ts.map +1 -0
  152. package/dist/protocol/types.js +31 -0
  153. package/dist/protocol/types.js.map +1 -0
  154. package/dist/v8/analytics.d.ts +31 -0
  155. package/dist/v8/analytics.d.ts.map +1 -0
  156. package/dist/v8/analytics.js +46 -0
  157. package/dist/v8/analytics.js.map +1 -0
  158. package/dist/v8/background.d.ts +26 -0
  159. package/dist/v8/background.d.ts.map +1 -0
  160. package/dist/v8/background.js +95 -0
  161. package/dist/v8/background.js.map +1 -0
  162. package/dist/v8/builtins/data.d.ts +15 -0
  163. package/dist/v8/builtins/data.d.ts.map +1 -0
  164. package/dist/v8/builtins/data.js +18 -0
  165. package/dist/v8/builtins/data.js.map +1 -0
  166. package/dist/v8/builtins/index.d.ts +9 -0
  167. package/dist/v8/builtins/index.d.ts.map +1 -0
  168. package/dist/v8/builtins/index.js +24 -0
  169. package/dist/v8/builtins/index.js.map +1 -0
  170. package/dist/v8/builtins/lazy.d.ts +17 -0
  171. package/dist/v8/builtins/lazy.d.ts.map +1 -0
  172. package/dist/v8/builtins/lazy.js +13 -0
  173. package/dist/v8/builtins/lazy.js.map +1 -0
  174. package/dist/v8/builtins/legacy.d.ts +41 -0
  175. package/dist/v8/builtins/legacy.d.ts.map +1 -0
  176. package/dist/v8/builtins/legacy.js +62 -0
  177. package/dist/v8/builtins/legacy.js.map +1 -0
  178. package/dist/v8/builtins/matchers.d.ts +19 -0
  179. package/dist/v8/builtins/matchers.d.ts.map +1 -0
  180. package/dist/v8/builtins/matchers.js +24 -0
  181. package/dist/v8/builtins/matchers.js.map +1 -0
  182. package/dist/v8/builtins/multivariate.d.ts +15 -0
  183. package/dist/v8/builtins/multivariate.d.ts.map +1 -0
  184. package/dist/v8/builtins/multivariate.js +18 -0
  185. package/dist/v8/builtins/multivariate.js.map +1 -0
  186. package/dist/v8/builtins/secret.d.ts +7 -0
  187. package/dist/v8/builtins/secret.d.ts.map +1 -0
  188. package/dist/v8/builtins/secret.js +68 -0
  189. package/dist/v8/builtins/secret.js.map +1 -0
  190. package/dist/v8/canonical.d.ts +70 -0
  191. package/dist/v8/canonical.d.ts.map +1 -0
  192. package/dist/v8/canonical.js +130 -0
  193. package/dist/v8/canonical.js.map +1 -0
  194. package/dist/v8/ciphertext.d.ts +58 -0
  195. package/dist/v8/ciphertext.d.ts.map +1 -0
  196. package/dist/v8/ciphertext.js +134 -0
  197. package/dist/v8/ciphertext.js.map +1 -0
  198. package/dist/v8/cli/builtins.d.ts +11 -0
  199. package/dist/v8/cli/builtins.d.ts.map +1 -0
  200. package/dist/v8/cli/builtins.js +18 -0
  201. package/dist/v8/cli/builtins.js.map +1 -0
  202. package/dist/v8/cli/check/index.d.ts +41 -0
  203. package/dist/v8/cli/check/index.d.ts.map +1 -0
  204. package/dist/v8/cli/check/index.js +713 -0
  205. package/dist/v8/cli/check/index.js.map +1 -0
  206. package/dist/v8/cli/check/messages.d.ts +24 -0
  207. package/dist/v8/cli/check/messages.d.ts.map +1 -0
  208. package/dist/v8/cli/check/messages.js +150 -0
  209. package/dist/v8/cli/check/messages.js.map +1 -0
  210. package/dist/v8/cli/content.d.ts +60 -0
  211. package/dist/v8/cli/content.d.ts.map +1 -0
  212. package/dist/v8/cli/content.js +231 -0
  213. package/dist/v8/cli/content.js.map +1 -0
  214. package/dist/v8/cli/index.d.ts +18 -0
  215. package/dist/v8/cli/index.d.ts.map +1 -0
  216. package/dist/v8/cli/index.js +18 -0
  217. package/dist/v8/cli/index.js.map +1 -0
  218. package/dist/v8/cli/log.d.ts +9 -0
  219. package/dist/v8/cli/log.d.ts.map +1 -0
  220. package/dist/v8/cli/log.js +11 -0
  221. package/dist/v8/cli/log.js.map +1 -0
  222. package/dist/v8/cli/main.d.ts +2 -0
  223. package/dist/v8/cli/main.d.ts.map +1 -0
  224. package/dist/v8/cli/main.js +9 -0
  225. package/dist/v8/cli/main.js.map +1 -0
  226. package/dist/v8/cli/root.d.ts +28 -0
  227. package/dist/v8/cli/root.d.ts.map +1 -0
  228. package/dist/v8/cli/root.js +64 -0
  229. package/dist/v8/cli/root.js.map +1 -0
  230. package/dist/v8/cli/run.d.ts +13 -0
  231. package/dist/v8/cli/run.d.ts.map +1 -0
  232. package/dist/v8/cli/run.js +210 -0
  233. package/dist/v8/cli/run.js.map +1 -0
  234. package/dist/v8/cli/schema/builtinSchemas.d.ts +22 -0
  235. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -0
  236. package/dist/v8/cli/schema/builtinSchemas.js +213 -0
  237. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -0
  238. package/dist/v8/cli/schema/generate.d.ts +50 -0
  239. package/dist/v8/cli/schema/generate.d.ts.map +1 -0
  240. package/dist/v8/cli/schema/generate.js +415 -0
  241. package/dist/v8/cli/schema/generate.js.map +1 -0
  242. package/dist/v8/cli/schema/index.d.ts +21 -0
  243. package/dist/v8/cli/schema/index.d.ts.map +1 -0
  244. package/dist/v8/cli/schema/index.js +51 -0
  245. package/dist/v8/cli/schema/index.js.map +1 -0
  246. package/dist/v8/cli/schema/tsProgram.d.ts +126 -0
  247. package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -0
  248. package/dist/v8/cli/schema/tsProgram.js +435 -0
  249. package/dist/v8/cli/schema/tsProgram.js.map +1 -0
  250. package/dist/v8/cli/schema/typeToSchema.d.ts +94 -0
  251. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -0
  252. package/dist/v8/cli/schema/typeToSchema.js +752 -0
  253. package/dist/v8/cli/schema/typeToSchema.js.map +1 -0
  254. package/dist/v8/cli/serve/server.d.ts +31 -0
  255. package/dist/v8/cli/serve/server.d.ts.map +1 -0
  256. package/dist/v8/cli/serve/server.js +247 -0
  257. package/dist/v8/cli/serve/server.js.map +1 -0
  258. package/dist/v8/cli/watch.d.ts +20 -0
  259. package/dist/v8/cli/watch.d.ts.map +1 -0
  260. package/dist/v8/cli/watch.js +79 -0
  261. package/dist/v8/cli/watch.js.map +1 -0
  262. package/dist/v8/client.d.ts +20 -0
  263. package/dist/v8/client.d.ts.map +1 -0
  264. package/dist/v8/client.js +115 -0
  265. package/dist/v8/client.js.map +1 -0
  266. package/dist/v8/cms.d.ts +9 -0
  267. package/dist/v8/cms.d.ts.map +1 -0
  268. package/dist/v8/cms.js +217 -0
  269. package/dist/v8/cms.js.map +1 -0
  270. package/dist/v8/content.d.ts +51 -0
  271. package/dist/v8/content.d.ts.map +1 -0
  272. package/dist/v8/content.js +218 -0
  273. package/dist/v8/content.js.map +1 -0
  274. package/dist/v8/draft.d.ts +48 -0
  275. package/dist/v8/draft.d.ts.map +1 -0
  276. package/dist/v8/draft.js +195 -0
  277. package/dist/v8/draft.js.map +1 -0
  278. package/dist/v8/errors.d.ts +21 -0
  279. package/dist/v8/errors.d.ts.map +1 -0
  280. package/dist/v8/errors.js +39 -0
  281. package/dist/v8/errors.js.map +1 -0
  282. package/dist/v8/fetch.d.ts +26 -0
  283. package/dist/v8/fetch.d.ts.map +1 -0
  284. package/dist/v8/fetch.js +98 -0
  285. package/dist/v8/fetch.js.map +1 -0
  286. package/dist/v8/identity.d.ts +19 -0
  287. package/dist/v8/identity.d.ts.map +1 -0
  288. package/dist/v8/identity.js +54 -0
  289. package/dist/v8/identity.js.map +1 -0
  290. package/dist/v8/index.d.ts +11 -0
  291. package/dist/v8/index.d.ts.map +1 -0
  292. package/dist/v8/index.js +10 -0
  293. package/dist/v8/index.js.map +1 -0
  294. package/dist/v8/json.d.ts +19 -0
  295. package/dist/v8/json.d.ts.map +1 -0
  296. package/dist/v8/json.js +65 -0
  297. package/dist/v8/json.js.map +1 -0
  298. package/dist/v8/matchRoute.d.ts +30 -0
  299. package/dist/v8/matchRoute.d.ts.map +1 -0
  300. package/dist/v8/matchRoute.js +175 -0
  301. package/dist/v8/matchRoute.js.map +1 -0
  302. package/dist/v8/remoteLoader.d.ts +16 -0
  303. package/dist/v8/remoteLoader.d.ts.map +1 -0
  304. package/dist/v8/remoteLoader.js +427 -0
  305. package/dist/v8/remoteLoader.js.map +1 -0
  306. package/dist/v8/resolver.d.ts +34 -0
  307. package/dist/v8/resolver.d.ts.map +1 -0
  308. package/dist/v8/resolver.js +219 -0
  309. package/dist/v8/resolver.js.map +1 -0
  310. package/dist/v8/secrets.d.ts +9 -0
  311. package/dist/v8/secrets.d.ts.map +1 -0
  312. package/dist/v8/secrets.js +14 -0
  313. package/dist/v8/secrets.js.map +1 -0
  314. package/dist/v8/telemetry.d.ts +61 -0
  315. package/dist/v8/telemetry.d.ts.map +1 -0
  316. package/dist/v8/telemetry.js +460 -0
  317. package/dist/v8/telemetry.js.map +1 -0
  318. package/dist/v8/types.d.ts +226 -0
  319. package/dist/v8/types.d.ts.map +1 -0
  320. package/dist/v8/types.js +2 -0
  321. package/dist/v8/types.js.map +1 -0
  322. package/dist/v8/variants.d.ts +3 -0
  323. package/dist/v8/variants.d.ts.map +1 -0
  324. package/dist/v8/variants.js +65 -0
  325. package/dist/v8/variants.js.map +1 -0
  326. package/package.json +64 -18
  327. package/src/index.ts +1 -1
  328. package/src/protocol/canonical.ts +1 -1
  329. package/src/protocol/ciphertext.ts +1 -1
  330. package/src/protocol/client.ts +2 -2
  331. package/src/protocol/conformance/cases/assets.ts +3 -3
  332. package/src/protocol/conformance/cases/guards.ts +4 -4
  333. package/src/protocol/conformance/cases/reads.ts +4 -4
  334. package/src/protocol/conformance/cases/types.ts +1 -1
  335. package/src/protocol/conformance/cases/wire.ts +4 -4
  336. package/src/protocol/conformance/cases/writes.ts +4 -4
  337. package/src/protocol/conformance/contentHashFixtures.ts +57 -0
  338. package/src/protocol/conformance/context.ts +4 -4
  339. package/src/protocol/conformance/index.ts +15 -10
  340. package/src/protocol/index.ts +14 -7
  341. package/src/protocol/params.ts +2 -2
  342. package/src/protocol/secrets.ts +3 -3
  343. package/src/protocol/server/assets.ts +6 -6
  344. package/src/protocol/server/auth.ts +1 -1
  345. package/src/protocol/server/content.ts +5 -5
  346. package/src/protocol/server/core.ts +12 -6
  347. package/src/protocol/server/handler.ts +6 -6
  348. package/src/protocol/server/http.ts +1 -1
  349. package/src/protocol/server/index.ts +3 -3
  350. package/src/protocol/server/methods/apply.ts +9 -9
  351. package/src/protocol/server/methods/read.ts +5 -5
  352. package/src/protocol/server/rpc.ts +6 -6
  353. package/src/protocol/storage/fs/index.ts +7 -7
  354. package/src/protocol/storage/fs/lock.ts +1 -1
  355. package/src/protocol/storage/fs/unsupported.ts +2 -2
  356. package/src/protocol/storage/memory.ts +4 -4
  357. package/src/protocol/storage.ts +1 -1
  358. package/src/v8/analytics.ts +2 -2
  359. package/src/v8/builtins/data.ts +1 -1
  360. package/src/v8/builtins/index.ts +6 -6
  361. package/src/v8/builtins/lazy.ts +1 -1
  362. package/src/v8/builtins/legacy.ts +1 -1
  363. package/src/v8/builtins/multivariate.ts +1 -1
  364. package/src/v8/builtins/secret.ts +2 -2
  365. package/src/v8/canonical.ts +36 -0
  366. package/src/v8/cli/builtins.ts +2 -2
  367. package/src/v8/cli/check/index.ts +11 -11
  368. package/src/v8/cli/content.ts +6 -6
  369. package/src/v8/cli/index.ts +7 -7
  370. package/src/v8/cli/main.ts +1 -1
  371. package/src/v8/cli/run.ts +7 -7
  372. package/src/v8/cli/schema/builtinSchemas.ts +1 -1
  373. package/src/v8/cli/schema/generate.ts +8 -7
  374. package/src/v8/cli/schema/index.ts +4 -4
  375. package/src/v8/cli/schema/tsProgram.ts +18 -1
  376. package/src/v8/cli/schema/typeToSchema.ts +100 -4
  377. package/src/v8/cli/serve/server.ts +9 -9
  378. package/src/v8/client.ts +5 -5
  379. package/src/v8/cms.ts +23 -11
  380. package/src/v8/content.ts +58 -22
  381. package/src/v8/draft.ts +75 -6
  382. package/src/v8/errors.ts +1 -1
  383. package/src/v8/fetch.ts +1 -1
  384. package/src/v8/identity.ts +1 -1
  385. package/src/v8/index.ts +5 -5
  386. package/src/v8/matchRoute.ts +1 -1
  387. package/src/v8/remoteLoader.ts +246 -26
  388. package/src/v8/resolver.ts +6 -6
  389. package/src/v8/secrets.ts +1 -1
  390. package/src/v8/telemetry.ts +5 -5
  391. package/src/v8/types.ts +14 -1
  392. package/src/v8/variants.ts +61 -0
@@ -0,0 +1,752 @@
1
+ /**
2
+ * TypeScript types to JSON Schema, in the site editor's dialect (the
3
+ * `deco-meta@1` format, which is today's `meta.gen.json`).
4
+ *
5
+ * Ported from the v7 generator (`@decocms/blocks-cli`'s
6
+ * `scripts/generate-schema.ts`: `typeToJsonSchema`, the JSDoc tag table and
7
+ * the widget aliases), so a type produces the same field it always has. What
8
+ * changed for the next major (spec: schema › From types to forms):
9
+ *
10
+ * - `ReactNode` / `ReactNode[]` are a choice of components (the section
11
+ * picker) instead of a hidden field.
12
+ * - An object field takes a plain value or any block whose function's awaited
13
+ * return type fits it, decided by TypeScript assignability, not by type
14
+ * name (spec: schema › Interchangeable blocks).
15
+ * - `Lazy<T>` is a `lazy` block whose `value` has the form of `T`.
16
+ * - `Secret` holds a `secret` block, never a plain string.
17
+ * - `@options` with a literal list becomes an `enum`; a function-backed list
18
+ * falls back to a text field, since the site editor never runs site code.
19
+ *
20
+ * The compiler is only imported as types here; `generate.ts` loads the
21
+ * app's `typescript` when `deco schema` runs.
22
+ */
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+ export const RESOLVABLE_KEY = "Resolvable";
26
+ export const SECTION_REF_KEY = "__SECTION_REF__";
27
+ /** Standard padded base64, matching the browser's `btoa()`. */
28
+ export function toBase64(value) {
29
+ return Buffer.from(value, "utf8").toString("base64");
30
+ }
31
+ export const resolvableRef = () => ({ $ref: `#/definitions/${RESOLVABLE_KEY}` });
32
+ export const sectionRef = () => ({ $ref: `#/definitions/${SECTION_REF_KEY}` });
33
+ // ---------------------------------------------------------------------------
34
+ // JSDoc tags (spec: schema › Widgets)
35
+ // ---------------------------------------------------------------------------
36
+ const NUMERIC_TAGS = new Set([
37
+ "maximum",
38
+ "minimum",
39
+ "exclusiveMaximum",
40
+ "exclusiveMinimum",
41
+ "multipleOf",
42
+ "maxLength",
43
+ "minLength",
44
+ "maxItems",
45
+ "minItems",
46
+ "maxProperties",
47
+ "minProperties",
48
+ ]);
49
+ const BOOLEAN_TAGS = new Set(["readOnly", "writeOnly", "deprecated", "uniqueItems"]);
50
+ export function getJsDocTags(symbol) {
51
+ const tags = {};
52
+ for (const decl of symbol.getDeclarations()) {
53
+ for (const doc of decl.getJsDocs()) {
54
+ const desc = doc.getDescription().trim();
55
+ if (desc)
56
+ tags.description = desc;
57
+ for (const tag of doc.getTags()) {
58
+ tags[tag.getTagName()] = tag.getCommentText()?.trim() || "true";
59
+ }
60
+ }
61
+ }
62
+ return tags;
63
+ }
64
+ /**
65
+ * Parse an `@options` value. A JSON list of strings, numbers, or
66
+ * `{ value, label }` objects is a static list; anything else (a loader path,
67
+ * a function name) is dynamic and can't be written into the schema.
68
+ */
69
+ function parseOptions(raw) {
70
+ let parsed;
71
+ try {
72
+ parsed = JSON.parse(raw);
73
+ }
74
+ catch {
75
+ return null;
76
+ }
77
+ if (!Array.isArray(parsed) || parsed.length === 0)
78
+ return null;
79
+ const values = [];
80
+ const labels = [];
81
+ let labelled = false;
82
+ for (const item of parsed) {
83
+ if (typeof item === "string" || typeof item === "number") {
84
+ values.push(item);
85
+ labels.push(String(item));
86
+ }
87
+ else if (item &&
88
+ typeof item === "object" &&
89
+ (typeof item.value === "string" || typeof item.value === "number")) {
90
+ values.push(item.value);
91
+ labels.push(typeof item.label === "string" ? item.label : String(item.value));
92
+ labelled ||= typeof item.label === "string";
93
+ }
94
+ else {
95
+ return null;
96
+ }
97
+ }
98
+ return labelled ? { values, labels } : { values };
99
+ }
100
+ /**
101
+ * `@format` spellings that name a standard format under another name, kept
102
+ * from v7: `@format datetime` (Eitri's vocabulary) is the `date-time` picker,
103
+ * and `deco check` validates it as one.
104
+ */
105
+ const FORMAT_ALIASES = { datetime: "date-time" };
106
+ function applyJsDocToSchema(schema, tags) {
107
+ for (const [tag, value] of Object.entries(tags)) {
108
+ if (tag === "ignore")
109
+ continue;
110
+ if (tag === "format") {
111
+ schema.format = FORMAT_ALIASES[value] ?? value;
112
+ continue;
113
+ }
114
+ if (tag === "hide") {
115
+ schema.hide = "true";
116
+ continue;
117
+ }
118
+ if (tag === "default") {
119
+ if (value === "true")
120
+ schema.default = true;
121
+ else if (value === "false")
122
+ schema.default = false;
123
+ else if (value === "null")
124
+ schema.default = null;
125
+ else if (!Number.isNaN(Number(value)) && value.trim() !== "")
126
+ schema.default = Number(value);
127
+ else {
128
+ try {
129
+ schema.default = JSON.parse(value);
130
+ }
131
+ catch {
132
+ schema.default = value;
133
+ }
134
+ }
135
+ continue;
136
+ }
137
+ if (tag === "examples") {
138
+ const lines = value
139
+ .split("\n")
140
+ .map((l) => l.trim())
141
+ .filter(Boolean);
142
+ if (lines.length > 1)
143
+ schema.examples = lines;
144
+ else {
145
+ try {
146
+ schema.examples = JSON.parse(value);
147
+ }
148
+ catch {
149
+ schema.examples = [value];
150
+ }
151
+ }
152
+ continue;
153
+ }
154
+ if (tag === "options") {
155
+ const options = parseOptions(value);
156
+ // Static lists become an enum the site editor shows as a select without
157
+ // asking the site. A dynamic list falls back to a plain text field.
158
+ if (options) {
159
+ schema.enum = options.values;
160
+ if (options.labels)
161
+ schema.enumNames = options.labels;
162
+ }
163
+ continue;
164
+ }
165
+ if (NUMERIC_TAGS.has(tag)) {
166
+ schema[tag] = Number(value);
167
+ continue;
168
+ }
169
+ if (BOOLEAN_TAGS.has(tag)) {
170
+ schema[tag] = value === "true";
171
+ continue;
172
+ }
173
+ // Everything else passes through as-is, matching the v7 generator: title,
174
+ // description, format, widget, icon, titleBy, mode, label, pattern, …
175
+ schema[tag] = value;
176
+ }
177
+ }
178
+ // ---------------------------------------------------------------------------
179
+ // Widget aliases (kept from v7: `image: ImageWidget` is an image picker)
180
+ // ---------------------------------------------------------------------------
181
+ const WIDGET_TYPE_FORMATS = {
182
+ ImageWidget: "image-uri",
183
+ VideoWidget: "video-uri",
184
+ HTMLWidget: "html",
185
+ RichText: "rich-text",
186
+ Color: "color",
187
+ TextArea: "textarea",
188
+ Code: "code",
189
+ DateTimeWidget: "date-time",
190
+ };
191
+ /** Apply the format of a widget alias named in `typeHint` to the right inner schema. */
192
+ function applyWidgetFormat(schema, typeHint) {
193
+ const format = Object.entries(WIDGET_TYPE_FORMATS).find(([alias]) => typeHint === alias || new RegExp(`\\b${alias}\\b`).test(typeHint))?.[1];
194
+ if (!format)
195
+ return;
196
+ if (schema.type === "string") {
197
+ schema.format ??= format;
198
+ }
199
+ else if (schema.type === "array" && schema.items?.type === "string") {
200
+ schema.items.format ??= format;
201
+ }
202
+ else if (Array.isArray(schema.anyOf)) {
203
+ for (const variant of schema.anyOf) {
204
+ if (variant.type === "string")
205
+ variant.format ??= format;
206
+ }
207
+ }
208
+ else if (!schema.type && !schema.$ref && !schema.anyOf) {
209
+ // A widget alias the checker couldn't resolve (remote import) came through as
210
+ // `any`; every widget alias is a string, so recover the intended widget.
211
+ schema.type = "string";
212
+ schema.format = format;
213
+ }
214
+ }
215
+ // ---------------------------------------------------------------------------
216
+ // Recognizing the framework's own types
217
+ // ---------------------------------------------------------------------------
218
+ const JSX_SYMBOLS = new Set([
219
+ "ReactNode",
220
+ "ReactElement",
221
+ "ReactPortal",
222
+ "VNode",
223
+ "ComponentChildren",
224
+ ]);
225
+ function typeNames(type) {
226
+ const names = [];
227
+ const alias = type.getAliasSymbol()?.getName();
228
+ if (alias)
229
+ names.push(alias);
230
+ const sym = type.getSymbol()?.getName();
231
+ if (sym)
232
+ names.push(sym);
233
+ return names;
234
+ }
235
+ /** `ReactNode`, `ReactElement`, `JSX.Element` and friends. */
236
+ /** A render descriptor (spec: rendering): `{ component: string; props: … }`. */
237
+ export function isDescriptorType(type) {
238
+ const check = (t) => {
239
+ const component = t.getProperty("component");
240
+ return component !== undefined && t.getProperty("props") !== undefined;
241
+ };
242
+ if (type.isUnion())
243
+ return type.getUnionTypes().every((t) => check(t));
244
+ return type.isObject() && check(type);
245
+ }
246
+ /**
247
+ * What a section renders to: JSX, or a render descriptor in data mode. A field
248
+ * of either type is a section picker.
249
+ */
250
+ function isSectionType(type) {
251
+ return isJsxType(type) || isDescriptorType(type);
252
+ }
253
+ export function isJsxType(type) {
254
+ if (typeNames(type).some((n) => JSX_SYMBOLS.has(n)))
255
+ return true;
256
+ const text = type.getText();
257
+ if (/(^|\.)Element$/.test(text) && /\bJSX\b/.test(text))
258
+ return true;
259
+ // A flattened `ReactNode` (it lost its alias): a union with an element member.
260
+ return (type.isUnion() &&
261
+ type
262
+ .getUnionTypes()
263
+ .some((member) => typeNames(member).some((n) => n === "ReactElement" || n === "ReactPortal")));
264
+ }
265
+ /**
266
+ * `Lazy<T>`: the `T`, or null for any other type. Only the `Lazy` alias
267
+ * counts, so a method like `onLoad: () => Promise<void>` stays a method
268
+ * (skipped) instead of becoming a lazy field. `typeHint`, the annotation as
269
+ * written, covers a checker that printed the alias away; the type must still
270
+ * have `Lazy`'s shape, a call with no parameters returning a promise of data.
271
+ */
272
+ function lazyInner(type, typeHint = "") {
273
+ const alias = type.getAliasSymbol();
274
+ if (alias?.getName() === "Lazy") {
275
+ const [arg] = type.getAliasTypeArguments();
276
+ if (arg)
277
+ return arg;
278
+ }
279
+ if (!/^(\w+\.)?Lazy\s*</.test(typeHint.trim()))
280
+ return null;
281
+ const signatures = type.getCallSignatures();
282
+ if (signatures.length !== 1 || type.getProperties().length > 0)
283
+ return null;
284
+ const [signature] = signatures;
285
+ if (signature.getParameters().length > 0)
286
+ return null;
287
+ const inner = awaitedOf(signature.getReturnType(), true);
288
+ if (!inner || inner.isVoid() || inner.isUndefined() || inner.isNever())
289
+ return null;
290
+ return inner;
291
+ }
292
+ /** `Secret`, from `@decocms/blocks` (`string & { readonly __secret: true }`). */
293
+ function isSecretType(type, typeHint = "") {
294
+ if (type.getAliasSymbol()?.getName() === "Secret")
295
+ return true;
296
+ if (/^(\w+\.)?Secret$/.test(typeHint.trim()))
297
+ return true;
298
+ return (type.isIntersection() &&
299
+ type.getIntersectionTypes().some((t) => t.getProperty("__secret") !== undefined));
300
+ }
301
+ /**
302
+ * The awaited type: `Promise<T>` is `T`. With `strict`, anything that isn't a
303
+ * promise returns null (used to recognize `() => Promise<T>`).
304
+ */
305
+ export function awaitedOf(type, strict = false) {
306
+ if (type.getSymbol()?.getName() === "Promise" || type.getAliasSymbol()?.getName() === "Promise") {
307
+ const [arg] = type.getTypeArguments();
308
+ return arg ?? null;
309
+ }
310
+ return strict ? null : type;
311
+ }
312
+ export function nonNullable(type) {
313
+ if (!type.isUnion())
314
+ return type;
315
+ const parts = type.getUnionTypes().filter((t) => !t.isNull() && !t.isUndefined());
316
+ return parts.length === 1 ? parts[0] : type.getNonNullableType();
317
+ }
318
+ /**
319
+ * `Record<string, any>` and friends: a map of anything, which every block's
320
+ * output fits. It's a free-form value, not a place for a block, so the field
321
+ * doesn't offer the saved-block picker or list every block as a choice.
322
+ */
323
+ export function isFreeFormMap(type) {
324
+ const t = nonNullable(type);
325
+ if (!t.isObject() || t.getProperties().length > 0 || t.getCallSignatures().length > 0)
326
+ return false;
327
+ const value = t.getStringIndexType() ?? t.getNumberIndexType();
328
+ return value !== undefined && (value.isAny() || value.isUnknown());
329
+ }
330
+ /** Types a block can fill: objects, arrays and intersections of objects, not primitives. */
331
+ function isObjectLike(type) {
332
+ const t = nonNullable(type);
333
+ if (t.isAny() || t.isUnknown() || t.isNever())
334
+ return false;
335
+ if (t.isString() || t.isNumber() || t.isBoolean() || t.isLiteral() || t.isBooleanLiteral()) {
336
+ return false;
337
+ }
338
+ if (t.isUnion()) {
339
+ // A union of objects (`A | B`) can be filled; a union with a primitive can't.
340
+ return t.getUnionTypes().every((u) => isObjectLike(u) || u.isNull() || u.isUndefined());
341
+ }
342
+ if (t.isIntersection()) {
343
+ return !t.getIntersectionTypes().some((p) => p.isString() || p.isNumber() || p.isBoolean());
344
+ }
345
+ return t.isArray() || t.isObject() || t.isInterface();
346
+ }
347
+ // ---------------------------------------------------------------------------
348
+ // The converter
349
+ // ---------------------------------------------------------------------------
350
+ const REACT_INTERNAL_PROPS = new Set([
351
+ "ref",
352
+ "then",
353
+ "catch",
354
+ "finally",
355
+ "$$typeof",
356
+ "_owner",
357
+ "_store",
358
+ ]);
359
+ // Platform types never configured in a form; collapsed to a hidden object.
360
+ const RUNTIME_INJECTED_TYPES = new Set([
361
+ "URL",
362
+ "URLSearchParams",
363
+ "Request",
364
+ "Response",
365
+ "Headers",
366
+ "AbortSignal",
367
+ "ReadableStream",
368
+ "WritableStream",
369
+ "Blob",
370
+ "File",
371
+ "FormData",
372
+ ]);
373
+ const titleCase = (name) => name.charAt(0).toUpperCase() + name.slice(1);
374
+ /** `Secret | undefined` → `Secret`: the annotation without its nullish members. */
375
+ function stripNullish(typeHint) {
376
+ return typeHint.replace(/\s*\|\s*(null|undefined)\b/g, "").trim();
377
+ }
378
+ function isNullableHint(optional, typeHint) {
379
+ return optional || /\bnull\b|\bundefined\b/.test(typeHint);
380
+ }
381
+ /** The schema of a `lazy` block whose value has the form `value`. */
382
+ export function lazySchema(value) {
383
+ return {
384
+ type: "object",
385
+ required: ["__resolveType", "value"],
386
+ properties: {
387
+ __resolveType: { type: "string", enum: ["lazy"], default: "lazy" },
388
+ value,
389
+ },
390
+ };
391
+ }
392
+ /** The schema of a `secret` block: a write-only field saved encrypted. */
393
+ function secretSchema() {
394
+ return {
395
+ type: "object",
396
+ format: "secret",
397
+ writeOnly: true,
398
+ required: ["__resolveType", "ciphertext"],
399
+ properties: {
400
+ __resolveType: { type: "string", enum: ["secret"], default: "secret" },
401
+ ciphertext: { type: "string" },
402
+ },
403
+ };
404
+ }
405
+ /**
406
+ * The schema of one field: everything a type means at a property position,
407
+ * before the property's own JSDoc and title are applied.
408
+ */
409
+ function fieldSchema(propType, typeHint, ctx, visited = new Set()) {
410
+ const lazy = lazyInner(nonNullable(propType), stripNullish(typeHint));
411
+ if (lazy)
412
+ return lazySchema(fieldSchema(lazy, lazy.getText(), ctx, visited));
413
+ if (isSecretType(nonNullable(propType), stripNullish(typeHint)))
414
+ return secretSchema();
415
+ if (ctx && isObjectLike(propType) && !isSectionType(nonNullable(propType))) {
416
+ const fits = ctx.fitting(propType);
417
+ if (fits.length > 0) {
418
+ const inner = nonNullable(propType);
419
+ const inline = inlineSchema(inner, ctx, visited);
420
+ return {
421
+ anyOf: [resolvableRef(), inline, ...fits.map((key) => ({ $ref: `#/definitions/${key}` }))],
422
+ };
423
+ }
424
+ }
425
+ const schema = typeToJsonSchema(propType, new Set(visited), ctx);
426
+ orderEnumByHint(schema, typeHint);
427
+ applyWidgetFormat(schema, typeHint);
428
+ return schema;
429
+ }
430
+ /**
431
+ * Literal values in the order `text` (the declaration as written) spells them.
432
+ * The checker orders a union's members by when it first met each literal,
433
+ * which another file can change, so `"a" | "b"` could come out as `["b", "a"]`.
434
+ * Values `text` doesn't spell all of keep the checker's order.
435
+ */
436
+ export function inDeclaredOrder(values, text) {
437
+ const at = values.map((value) => {
438
+ const spelled = typeof value === "string"
439
+ ? [`"${value}"`, `'${value}'`, `\`${value}\``]
440
+ .map((q) => text.indexOf(q))
441
+ .filter((i) => i >= 0)
442
+ : [
443
+ ...text.matchAll(new RegExp(`(?<![\\w.])${String(value).replace(".", "\\.")}(?![\\w.])`, "g")),
444
+ ].map((m) => m.index ?? -1);
445
+ return spelled.length > 0 ? Math.min(...spelled) : -1;
446
+ });
447
+ if (at.some((i) => i < 0))
448
+ return values;
449
+ return values
450
+ .map((value, i) => ({ value, at: at[i] }))
451
+ .sort((a, b) => a.at - b.at)
452
+ .map((e) => e.value);
453
+ }
454
+ /** Reorder a literal select (or a list of them) by the field's annotation. */
455
+ function orderEnumByHint(schema, typeHint) {
456
+ if (Array.isArray(schema?.enum))
457
+ schema.enum = inDeclaredOrder(schema.enum, typeHint);
458
+ else if (Array.isArray(schema?.items?.enum)) {
459
+ schema.items.enum = inDeclaredOrder(schema.items.enum, typeHint);
460
+ }
461
+ }
462
+ /** The declaration text of a type alias, for ordering its literal members. */
463
+ function aliasDeclarationText(type) {
464
+ return type.getAliasSymbol()?.getDeclarations()[0]?.getText() ?? "";
465
+ }
466
+ /** The "plain value" branch of a field that blocks can fill. */
467
+ function inlineSchema(type, ctx, visited) {
468
+ if (type.isArray()) {
469
+ const element = type.getArrayElementType();
470
+ const items = element
471
+ ? (ctx.namedDefinition(element) ?? typeToJsonSchema(element, new Set(visited), ctx))
472
+ : {};
473
+ return { type: "array", items, title: "Inline data" };
474
+ }
475
+ const named = ctx.namedDefinition(type);
476
+ return named
477
+ ? { ...named, title: "Inline data" }
478
+ : { ...typeToJsonSchema(type, new Set(visited), ctx), title: "Inline data" };
479
+ }
480
+ /**
481
+ * Whether a prop annotated `Section` / `Section[]` is v7's opaque Section type
482
+ * (`type Section = any`), a "pick any section" field, rather than a site type
483
+ * that happens to be called `Section`.
484
+ */
485
+ function isOpaqueSectionType(propType) {
486
+ let type = nonNullable(propType);
487
+ if (type.isArray())
488
+ type = type.getArrayElementType() ?? type;
489
+ return type.isAny() || type.isUnknown();
490
+ }
491
+ export function typeToJsonSchema(type, visited = new Set(), ctx) {
492
+ const typeText = type.getText();
493
+ if (visited.has(typeText))
494
+ return { type: "object" };
495
+ visited.add(typeText);
496
+ try {
497
+ if (type.isAny() || type.isUnknown())
498
+ return {};
499
+ // Structural blocks wherever the type appears, not only as a whole field:
500
+ // `Secret[]` is a list of secret blocks, `Lazy<T>[]` a list of lazy ones.
501
+ if (isSecretType(type))
502
+ return secretSchema();
503
+ const lazy = lazyInner(type);
504
+ if (lazy)
505
+ return lazySchema(fieldSchema(lazy, lazy.getText(), ctx, visited));
506
+ if (type.isArray()) {
507
+ const el = type.getArrayElementType();
508
+ return el
509
+ ? { type: "array", items: typeToJsonSchema(el, new Set(visited), ctx) }
510
+ : { type: "array" };
511
+ }
512
+ if (isSectionType(type))
513
+ return sectionRef();
514
+ if (type.isString() || type.isStringLiteral()) {
515
+ return type.isStringLiteral()
516
+ ? { type: "string", const: type.getLiteralValue() }
517
+ : { type: "string" };
518
+ }
519
+ if (type.isNumber() || type.isNumberLiteral())
520
+ return { type: "number" };
521
+ if (type.isBoolean() || type.isBooleanLiteral())
522
+ return { type: "boolean" };
523
+ if (type.isNull() || type.isUndefined())
524
+ return { type: "null" };
525
+ if (type.isUnion()) {
526
+ const parts = type.getUnionTypes();
527
+ const nonNull = parts.filter((t) => !t.isNull() && !t.isUndefined());
528
+ const isNullable = nonNull.length < parts.length;
529
+ if (nonNull.length === 1) {
530
+ const inner = typeToJsonSchema(nonNull[0], new Set(visited), ctx);
531
+ return isNullable ? { ...inner, nullable: true } : inner;
532
+ }
533
+ if (nonNull.every((t) => t.isBooleanLiteral())) {
534
+ return isNullable ? { type: "boolean", nullable: true } : { type: "boolean" };
535
+ }
536
+ // String-literal unions and string enums: a select, written into the schema.
537
+ if (nonNull.every((t) => t.isStringLiteral())) {
538
+ const values = nonNull.map((t) => t.getLiteralValue());
539
+ const result = {
540
+ type: "string",
541
+ enum: inDeclaredOrder(values, aliasDeclarationText(type)),
542
+ };
543
+ if (isNullable)
544
+ result.nullable = true;
545
+ return result;
546
+ }
547
+ if (nonNull.every((t) => t.isNumberLiteral())) {
548
+ const values = nonNull.map((t) => t.getLiteralValue());
549
+ const result = {
550
+ type: "number",
551
+ enum: inDeclaredOrder(values, aliasDeclarationText(type)),
552
+ };
553
+ if (isNullable)
554
+ result.nullable = true;
555
+ return result;
556
+ }
557
+ const anyOf = nonNull.map((t) => {
558
+ const schema = typeToJsonSchema(t, new Set(visited), ctx);
559
+ if (!schema.title && schema.type === "object") {
560
+ const symName = (t.getAliasSymbol() ?? t.getSymbol())?.getName();
561
+ if (symName && symName !== "__type" && symName !== "default" && symName !== "__object") {
562
+ schema.title = symName;
563
+ }
564
+ if (!schema.title && schema.properties) {
565
+ for (const v of Object.values(schema.properties)) {
566
+ if (v?.const !== undefined) {
567
+ schema.title = String(v.const);
568
+ break;
569
+ }
570
+ }
571
+ }
572
+ }
573
+ return schema;
574
+ });
575
+ const result = { anyOf };
576
+ if (isNullable)
577
+ result.nullable = true;
578
+ return result;
579
+ }
580
+ if (type.isIntersection()) {
581
+ const parts = type.getIntersectionTypes();
582
+ const primitive = parts.find((t) => t.isString() || t.isNumber() || t.isBoolean());
583
+ if (primitive)
584
+ return typeToJsonSchema(primitive, new Set(visited), ctx);
585
+ const merged = { type: "object", properties: {} };
586
+ const required = new Set();
587
+ for (const part of parts) {
588
+ const sub = typeToJsonSchema(part, new Set(visited), ctx);
589
+ if (sub?.type !== "object" || !sub.properties)
590
+ continue;
591
+ Object.assign(merged.properties, sub.properties);
592
+ for (const r of sub.required ?? [])
593
+ required.add(r);
594
+ for (const [k, v] of Object.entries(sub)) {
595
+ if (k === "type" || k === "properties" || k === "required")
596
+ continue;
597
+ if (!(k in merged))
598
+ merged[k] = v;
599
+ }
600
+ }
601
+ if (required.size > 0)
602
+ merged.required = [...required];
603
+ return merged;
604
+ }
605
+ if (type.isObject() || type.isInterface()) {
606
+ if (ctx?.shareNamed && type.compilerType !== ctx.shareNamed.rootType.compilerType) {
607
+ const shared = ctx.namedDefinition(type);
608
+ if (shared)
609
+ return shared;
610
+ }
611
+ const symName = type.getSymbol()?.getName();
612
+ if (symName && RUNTIME_INJECTED_TYPES.has(symName)) {
613
+ const declFile = type.getSymbol()?.getDeclarations()?.[0]?.getSourceFile().getFilePath();
614
+ if (declFile?.includes("typescript/lib/") || declFile?.includes("@types/")) {
615
+ return { type: "object", hide: "true" };
616
+ }
617
+ }
618
+ const stringIdx = type.getStringIndexType();
619
+ const numberIdx = type.getNumberIndexType();
620
+ if ((stringIdx || numberIdx) && type.getProperties().length === 0) {
621
+ return {
622
+ type: "object",
623
+ additionalProperties: typeToJsonSchema((stringIdx || numberIdx), new Set(visited), ctx),
624
+ };
625
+ }
626
+ const properties = {};
627
+ const required = [];
628
+ for (const prop of type.getProperties()) {
629
+ const name = prop.getName();
630
+ if (name.startsWith("_") || name.startsWith("$") || name === "@type")
631
+ continue;
632
+ if (REACT_INTERNAL_PROPS.has(name))
633
+ continue;
634
+ const decl = prop.getValueDeclaration() ?? prop.getDeclarations()[0];
635
+ if (!decl)
636
+ continue;
637
+ const propType = prop.getTypeAtLocation(decl);
638
+ const tags = getJsDocTags(prop);
639
+ if (tags.ignore)
640
+ continue;
641
+ // The annotation as written (`ImageWidget`, `Section[]`, `Secret`),
642
+ // before the checker resolves aliases away.
643
+ const typeNode = decl.getTypeNode();
644
+ const typeHint = typeNode ? typeNode.getText() : propType.getText();
645
+ const optional = prop.isOptional();
646
+ // Methods aren't data, but `Lazy<T>` (a function prop) is a field.
647
+ const callable = nonNullable(propType);
648
+ const isFunction = callable.getCallSignatures().length > 0 && callable.getProperties().length === 0;
649
+ if (isFunction && !lazyInner(nonNullable(propType), stripNullish(typeHint)))
650
+ continue;
651
+ // v7's opaque `Section` type: a section picker.
652
+ const baseHint = typeHint.replace(/\s*\|\s*(null|undefined)/g, "").trim();
653
+ if ((baseHint === "Section" || baseHint === "Section[]") && isOpaqueSectionType(propType)) {
654
+ const schema = baseHint.endsWith("[]")
655
+ ? { type: "array", items: sectionRef(), title: titleCase(name) }
656
+ : { ...sectionRef(), title: titleCase(name) };
657
+ if (isNullableHint(optional, typeHint))
658
+ schema.nullable = true;
659
+ applyJsDocToSchema(schema, tags);
660
+ properties[name] = schema;
661
+ if (!optional)
662
+ required.push(name);
663
+ continue;
664
+ }
665
+ const schema = fieldSchema(propType, typeHint, ctx, visited);
666
+ if (typeNode)
667
+ orderEnumByHint(schema, typeNode.getAliasDeclarationTexts().join("\n"));
668
+ if (schema.anyOf && schema.anyOf[0]?.$ref === resolvableRef().$ref) {
669
+ // A block-ref field: nullability lives on the wrapper.
670
+ if (isNullableHint(optional, typeHint))
671
+ schema.nullable = true;
672
+ }
673
+ if (schema.$ref === sectionRef().$ref && isNullableHint(optional, typeHint)) {
674
+ schema.nullable = true;
675
+ }
676
+ applyJsDocToSchema(schema, tags);
677
+ schema.title ??= titleCase(name);
678
+ properties[name] = schema;
679
+ // A hidden prop can't be filled in by an editor; requiring it would
680
+ // deadlock the form.
681
+ if (!optional && schema.hide !== "true")
682
+ required.push(name);
683
+ }
684
+ const result = { type: "object", properties };
685
+ if (required.length > 0)
686
+ result.required = required;
687
+ const ifaceSym = type.getAliasSymbol() ?? type.getSymbol();
688
+ if (ifaceSym)
689
+ applyJsDocToSchema(result, getJsDocTags(ifaceSym));
690
+ return result;
691
+ }
692
+ return { type: "string" };
693
+ }
694
+ finally {
695
+ visited.delete(typeText);
696
+ }
697
+ }
698
+ /**
699
+ * A machine-independent id for a source file: relative to the app root, or
700
+ * `<package name>/<path in package>` for a file in a dependency (including a
701
+ * workspace package the checker reached through a symlink).
702
+ *
703
+ * A declaration file with a declaration map (`x.d.ts` + `x.d.ts.map`, as
704
+ * `tsc` emits into a package's dist/) is named after the source it was
705
+ * compiled from, so a type keeps one id whether the checker read the
706
+ * package's compiled `.d.ts` or its `.ts` source (the "source" condition).
707
+ */
708
+ export function stableFileId(filePath, root) {
709
+ const file = sourceOfDeclaration(filePath.replace(/^file:\/+/, "/"));
710
+ const nm = file.lastIndexOf("/node_modules/");
711
+ if (nm >= 0)
712
+ return file.slice(nm + "/node_modules/".length);
713
+ const rel = path.relative(root, file).split(path.sep).join("/");
714
+ if (!rel.startsWith(".."))
715
+ return rel;
716
+ let dir = path.dirname(file);
717
+ for (;;) {
718
+ const manifest = path.join(dir, "package.json");
719
+ if (fs.existsSync(manifest)) {
720
+ try {
721
+ const name = JSON.parse(fs.readFileSync(manifest, "utf8")).name;
722
+ if (typeof name === "string") {
723
+ return `${name}/${path.relative(dir, file).split(path.sep).join("/")}`;
724
+ }
725
+ }
726
+ catch {
727
+ // unreadable manifest: keep walking
728
+ }
729
+ }
730
+ const parent = path.dirname(dir);
731
+ if (parent === dir)
732
+ return path.basename(file);
733
+ dir = parent;
734
+ }
735
+ }
736
+ /** The `.ts` file a `.d.ts` was emitted from, per its declaration map; else the file itself. */
737
+ function sourceOfDeclaration(file) {
738
+ if (!/\.d\.[cm]?ts$/.test(file))
739
+ return file;
740
+ try {
741
+ const map = JSON.parse(fs.readFileSync(`${file}.map`, "utf8"));
742
+ const source = Array.isArray(map.sources) ? map.sources[0] : undefined;
743
+ if (typeof source !== "string")
744
+ return file;
745
+ const sourceRoot = typeof map.sourceRoot === "string" ? map.sourceRoot : "";
746
+ return path.resolve(path.dirname(file), sourceRoot, source);
747
+ }
748
+ catch {
749
+ return file;
750
+ }
751
+ }
752
+ //# sourceMappingURL=typeToSchema.js.map