@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
@@ -3,7 +3,7 @@
3
3
  * in api-reference › Types). They're always in the schema, unless the block
4
4
  * map declares the same key, which replaces the built-in.
5
5
  */
6
- import { lazySchema, resolvableRef, sectionRef } from "./typeToSchema";
6
+ import { lazySchema, resolvableRef, sectionRef } from "./typeToSchema.ts";
7
7
 
8
8
  export type ManifestGroup = "sections" | "matchers" | "loaders" | "pages" | "redirects" | "content";
9
9
 
@@ -12,21 +12,22 @@
12
12
  */
13
13
  import fs from "node:fs";
14
14
  import path from "node:path";
15
- import { SCHEMA_FORMAT } from "../../../protocol/types";
16
- import { BUILT_IN_BLOCKS, LEGACY_ALIASES } from "../builtins";
17
- import { CliError, type DecoPaths, packageVersion } from "../root";
15
+ import { SCHEMA_FORMAT } from "../../../protocol/types.ts";
16
+ import { BUILT_IN_BLOCKS, LEGACY_ALIASES } from "../builtins.ts";
17
+ import { CliError, type DecoPaths, packageVersion } from "../root.ts";
18
18
  import {
19
19
  BUILT_IN_GROUPS,
20
20
  builtInDefinition,
21
21
  flatDefinition,
22
22
  legacyMultivariateValue,
23
23
  type ManifestGroup,
24
- } from "./builtinSchemas";
25
- import { createTsProject, type TsNode as Node, type TsType as Type } from "./tsProgram";
24
+ } from "./builtinSchemas.ts";
25
+ import { createTsProject, type TsNode as Node, type TsType as Type } from "./tsProgram.ts";
26
26
  import {
27
27
  awaitedOf,
28
28
  getJsDocTags,
29
29
  isDescriptorType,
30
+ isFreeFormMap,
30
31
  isJsxType,
31
32
  nonNullable,
32
33
  RESOLVABLE_KEY,
@@ -35,7 +36,7 @@ import {
35
36
  stableFileId,
36
37
  toBase64,
37
38
  typeToJsonSchema,
38
- } from "./typeToSchema";
39
+ } from "./typeToSchema.ts";
39
40
 
40
41
  const MANIFEST_GROUPS: ManifestGroup[] = [
41
42
  "sections",
@@ -283,7 +284,7 @@ export async function generateSchema(paths: DecoPaths): Promise<SchemaResult> {
283
284
  root,
284
285
  fitting(type) {
285
286
  const target = nonNullable(type);
286
- if (target.isAny() || target.isUnknown()) return [];
287
+ if (target.isAny() || target.isUnknown() || isFreeFormMap(target)) return [];
287
288
  const cached = fitCache.get(target.compilerType);
288
289
  if (cached) return cached;
289
290
  const keys = candidates
@@ -1,8 +1,8 @@
1
1
  import path from "node:path";
2
- import { writeIfChanged } from "../content";
3
- import { consoleReporter, type Reporter } from "../log";
4
- import { CliError, type DecoPaths, decoPaths, findDecoRoot } from "../root";
5
- import { generateSchema, type SchemaResult } from "./generate";
2
+ import { writeIfChanged } from "../content.ts";
3
+ import { consoleReporter, type Reporter } from "../log.ts";
4
+ import { CliError, type DecoPaths, decoPaths, findDecoRoot } from "../root.ts";
5
+ import { generateSchema, type SchemaResult } from "./generate.ts";
6
6
 
7
7
  export interface SchemaOptions {
8
8
  root?: string;
@@ -17,7 +17,7 @@
17
17
  import fs from "node:fs";
18
18
  import path from "node:path";
19
19
  import type * as TS from "typescript";
20
- import { CliError } from "../root";
20
+ import { CliError } from "../root.ts";
21
21
 
22
22
  type TypeScript = typeof TS;
23
23
 
@@ -321,6 +321,23 @@ export class TsNode {
321
321
  return t && typeof t === "object" && "kind" in t ? this.ctx.node(t) : undefined;
322
322
  }
323
323
 
324
+ /**
325
+ * The declarations of the type aliases a type annotation names, as written:
326
+ * `Kind` and `Kind | null` both give `Kind`'s. The checker drops the alias
327
+ * from `Kind | undefined`, so this is how a field finds its alias.
328
+ */
329
+ getAliasDeclarationTexts(): string[] {
330
+ const ts = this.ctx.ts;
331
+ const node = this.compilerNode as TS.TypeNode;
332
+ const members = ts.isUnionTypeNode(node) ? node.types : [node];
333
+ const texts: string[] = [];
334
+ for (const member of members) {
335
+ const decl = this.ctx.checker.getTypeFromTypeNode(member).aliasSymbol?.declarations?.[0];
336
+ if (decl) texts.push(decl.getText(decl.getSourceFile()));
337
+ }
338
+ return texts;
339
+ }
340
+
324
341
  /** Whether `other` is this node or inside it. */
325
342
  contains(other: TsNode): boolean {
326
343
  const a = this.compilerNode;
@@ -23,7 +23,7 @@
23
23
 
24
24
  import fs from "node:fs";
25
25
  import path from "node:path";
26
- import type { TsSymbol as MorphSymbol, TsType as Type } from "./tsProgram";
26
+ import type { TsSymbol as MorphSymbol, TsType as Type } from "./tsProgram.ts";
27
27
 
28
28
  export const RESOLVABLE_KEY = "Resolvable";
29
29
  export const SECTION_REF_KEY = "__SECTION_REF__";
@@ -123,9 +123,20 @@ function parseOptions(raw: string): { values: (string | number)[]; labels?: stri
123
123
  return labelled ? { values, labels } : { values };
124
124
  }
125
125
 
126
+ /**
127
+ * `@format` spellings that name a standard format under another name, kept
128
+ * from v7: `@format datetime` (Eitri's vocabulary) is the `date-time` picker,
129
+ * and `deco check` validates it as one.
130
+ */
131
+ const FORMAT_ALIASES: Record<string, string> = { datetime: "date-time" };
132
+
126
133
  function applyJsDocToSchema(schema: any, tags: Record<string, string>): void {
127
134
  for (const [tag, value] of Object.entries(tags)) {
128
135
  if (tag === "ignore") continue;
136
+ if (tag === "format") {
137
+ schema.format = FORMAT_ALIASES[value] ?? value;
138
+ continue;
139
+ }
129
140
  if (tag === "hide") {
130
141
  schema.hide = "true";
131
142
  continue;
@@ -324,6 +335,19 @@ export function nonNullable(type: Type): Type {
324
335
  return parts.length === 1 ? parts[0] : type.getNonNullableType();
325
336
  }
326
337
 
338
+ /**
339
+ * `Record<string, any>` and friends: a map of anything, which every block's
340
+ * output fits. It's a free-form value, not a place for a block, so the field
341
+ * doesn't offer the saved-block picker or list every block as a choice.
342
+ */
343
+ export function isFreeFormMap(type: Type): boolean {
344
+ const t = nonNullable(type);
345
+ if (!t.isObject() || t.getProperties().length > 0 || t.getCallSignatures().length > 0)
346
+ return false;
347
+ const value = t.getStringIndexType() ?? t.getNumberIndexType();
348
+ return value !== undefined && (value.isAny() || value.isUnknown());
349
+ }
350
+
327
351
  /** Types a block can fill: objects, arrays and intersections of objects, not primitives. */
328
352
  function isObjectLike(type: Type): boolean {
329
353
  const t = nonNullable(type);
@@ -434,10 +458,51 @@ function fieldSchema(
434
458
  }
435
459
 
436
460
  const schema = typeToJsonSchema(propType, new Set(visited), ctx);
461
+ orderEnumByHint(schema, typeHint);
437
462
  applyWidgetFormat(schema, typeHint);
438
463
  return schema;
439
464
  }
440
465
 
466
+ /**
467
+ * Literal values in the order `text` (the declaration as written) spells them.
468
+ * The checker orders a union's members by when it first met each literal,
469
+ * which another file can change, so `"a" | "b"` could come out as `["b", "a"]`.
470
+ * Values `text` doesn't spell all of keep the checker's order.
471
+ */
472
+ export function inDeclaredOrder<T extends string | number>(values: T[], text: string): T[] {
473
+ const at = values.map((value) => {
474
+ const spelled =
475
+ typeof value === "string"
476
+ ? [`"${value}"`, `'${value}'`, `\`${value}\``]
477
+ .map((q) => text.indexOf(q))
478
+ .filter((i) => i >= 0)
479
+ : [
480
+ ...text.matchAll(
481
+ new RegExp(`(?<![\\w.])${String(value).replace(".", "\\.")}(?![\\w.])`, "g"),
482
+ ),
483
+ ].map((m) => m.index ?? -1);
484
+ return spelled.length > 0 ? Math.min(...spelled) : -1;
485
+ });
486
+ if (at.some((i) => i < 0)) return values;
487
+ return values
488
+ .map((value, i) => ({ value, at: at[i] }))
489
+ .sort((a, b) => a.at - b.at)
490
+ .map((e) => e.value);
491
+ }
492
+
493
+ /** Reorder a literal select (or a list of them) by the field's annotation. */
494
+ function orderEnumByHint(schema: any, typeHint: string): void {
495
+ if (Array.isArray(schema?.enum)) schema.enum = inDeclaredOrder(schema.enum, typeHint);
496
+ else if (Array.isArray(schema?.items?.enum)) {
497
+ schema.items.enum = inDeclaredOrder(schema.items.enum, typeHint);
498
+ }
499
+ }
500
+
501
+ /** The declaration text of a type alias, for ordering its literal members. */
502
+ function aliasDeclarationText(type: Type): string {
503
+ return type.getAliasSymbol()?.getDeclarations()[0]?.getText() ?? "";
504
+ }
505
+
441
506
  /** The "plain value" branch of a field that blocks can fill. */
442
507
  function inlineSchema(type: Type, ctx: SchemaContext, visited: Set<string>): any {
443
508
  if (type.isArray()) {
@@ -514,12 +579,20 @@ export function typeToJsonSchema(
514
579
  }
515
580
  // String-literal unions and string enums: a select, written into the schema.
516
581
  if (nonNull.every((t) => t.isStringLiteral())) {
517
- const result: any = { type: "string", enum: nonNull.map((t) => t.getLiteralValue()) };
582
+ const values = nonNull.map((t) => t.getLiteralValue() as string);
583
+ const result: any = {
584
+ type: "string",
585
+ enum: inDeclaredOrder(values, aliasDeclarationText(type)),
586
+ };
518
587
  if (isNullable) result.nullable = true;
519
588
  return result;
520
589
  }
521
590
  if (nonNull.every((t) => t.isNumberLiteral())) {
522
- const result: any = { type: "number", enum: nonNull.map((t) => t.getLiteralValue()) };
591
+ const values = nonNull.map((t) => t.getLiteralValue() as number);
592
+ const result: any = {
593
+ type: "number",
594
+ enum: inDeclaredOrder(values, aliasDeclarationText(type)),
595
+ };
523
596
  if (isNullable) result.nullable = true;
524
597
  return result;
525
598
  }
@@ -630,6 +703,7 @@ export function typeToJsonSchema(
630
703
  }
631
704
 
632
705
  const schema = fieldSchema(propType, typeHint, ctx, visited);
706
+ if (typeNode) orderEnumByHint(schema, typeNode.getAliasDeclarationTexts().join("\n"));
633
707
  if (schema.anyOf && schema.anyOf[0]?.$ref === resolvableRef().$ref) {
634
708
  // A block-ref field: nullability lives on the wrapper.
635
709
  if (isNullableHint(optional, typeHint)) schema.nullable = true;
@@ -662,9 +736,14 @@ export function typeToJsonSchema(
662
736
  * A machine-independent id for a source file: relative to the app root, or
663
737
  * `<package name>/<path in package>` for a file in a dependency (including a
664
738
  * workspace package the checker reached through a symlink).
739
+ *
740
+ * A declaration file with a declaration map (`x.d.ts` + `x.d.ts.map`, as
741
+ * `tsc` emits into a package's dist/) is named after the source it was
742
+ * compiled from, so a type keeps one id whether the checker read the
743
+ * package's compiled `.d.ts` or its `.ts` source (the "source" condition).
665
744
  */
666
745
  export function stableFileId(filePath: string, root: string): string {
667
- const file = filePath.replace(/^file:\/+/, "/");
746
+ const file = sourceOfDeclaration(filePath.replace(/^file:\/+/, "/"));
668
747
  const nm = file.lastIndexOf("/node_modules/");
669
748
  if (nm >= 0) return file.slice(nm + "/node_modules/".length);
670
749
  const rel = path.relative(root, file).split(path.sep).join("/");
@@ -687,3 +766,20 @@ export function stableFileId(filePath: string, root: string): string {
687
766
  dir = parent;
688
767
  }
689
768
  }
769
+
770
+ /** The `.ts` file a `.d.ts` was emitted from, per its declaration map; else the file itself. */
771
+ function sourceOfDeclaration(file: string): string {
772
+ if (!/\.d\.[cm]?ts$/.test(file)) return file;
773
+ try {
774
+ const map = JSON.parse(fs.readFileSync(`${file}.map`, "utf8")) as {
775
+ sources?: unknown;
776
+ sourceRoot?: unknown;
777
+ };
778
+ const source = Array.isArray(map.sources) ? map.sources[0] : undefined;
779
+ if (typeof source !== "string") return file;
780
+ const sourceRoot = typeof map.sourceRoot === "string" ? map.sourceRoot : "";
781
+ return path.resolve(path.dirname(file), sourceRoot, source);
782
+ } catch {
783
+ return file;
784
+ }
785
+ }
@@ -20,15 +20,15 @@ import http from "node:http";
20
20
  import type { AddressInfo } from "node:net";
21
21
  import path from "node:path";
22
22
  import { Readable } from "node:stream";
23
- import { ErrorCode } from "../../../protocol/errors";
24
- import { blockNameFromFile } from "../../../protocol/keys";
25
- import { createContentHandler } from "../../../protocol/server";
26
- import { createAssetHandler } from "../../../protocol/server/assets";
27
- import type { ContentStorage } from "../../../protocol/storage";
28
- import { createFsStorage } from "../../../protocol/storage/fs";
29
- import { readSavedBlocks, writeContent } from "../content";
30
- import { consoleReporter, type Reporter } from "../log";
31
- import { CliError, decoPaths, findDecoRoot, packageVersion } from "../root";
23
+ import { ErrorCode } from "../../../protocol/errors.ts";
24
+ import { blockNameFromFile } from "../../../protocol/keys.ts";
25
+ import { createAssetHandler } from "../../../protocol/server/assets.ts";
26
+ import { createContentHandler } from "../../../protocol/server/index.ts";
27
+ import { createFsStorage } from "../../../protocol/storage/fs/index.ts";
28
+ import type { ContentStorage } from "../../../protocol/storage.ts";
29
+ import { readSavedBlocks, writeContent } from "../content.ts";
30
+ import { consoleReporter, type Reporter } from "../log.ts";
31
+ import { CliError, decoPaths, findDecoRoot, packageVersion } from "../root.ts";
32
32
 
33
33
  /** The site editor's origins: the browser origins allowed by default. */
34
34
  const STUDIO_ORIGINS = [
package/src/v8/client.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * A client: one revision, loaded on first use and read for the rest of its
3
3
  * life, plus a memo of block results. Create one per request.
4
4
  */
5
- import { errors, isResolutionError, ResolutionError } from "./errors";
6
- import { isBlock } from "./json";
7
- import { Resolver } from "./resolver";
8
- import type { ClientTelemetry } from "./telemetry";
5
+ import { errors, isResolutionError, ResolutionError } from "./errors.ts";
6
+ import { isBlock } from "./json.ts";
7
+ import { Resolver } from "./resolver.ts";
8
+ import type { ClientTelemetry } from "./telemetry.ts";
9
9
  import type {
10
10
  Block,
11
11
  Blocks,
@@ -15,7 +15,7 @@ import type {
15
15
  ResolveOptions,
16
16
  Result,
17
17
  Snapshot,
18
- } from "./types";
18
+ } from "./types.ts";
19
19
 
20
20
  interface ClientOptions {
21
21
  /** Loads this client's snapshot; called at most once. */
package/src/v8/cms.ts CHANGED
@@ -6,15 +6,17 @@
6
6
  * a package loaded twice (two bundles, a dev reload) still shares one content
7
7
  * cache. See /next/api-reference#one-instance-per-process.
8
8
  */
9
- import { runInBackground } from "./background";
10
- import { builtIns } from "./builtins/index";
11
- import { secretBlock } from "./builtins/secret";
12
- import { CMSClient } from "./client";
13
- import { ContentStore, isLoader, isSnapshot } from "./content";
14
- import { clearGlobals, contentIdentity, fnv1a, readEnv } from "./identity";
15
- import { remoteLoader, resetRemoteLoaders } from "./remoteLoader";
16
- import { resolveDestination, setCurrentTelemetry, TelemetryPipeline } from "./telemetry";
17
- import type { Blocks, Client, CMS, CMSConfig, Loader, Snapshot } from "./types";
9
+ import { runInBackground } from "./background.ts";
10
+ import { builtIns } from "./builtins/index.ts";
11
+ import { secretBlock } from "./builtins/secret.ts";
12
+ import { CMSClient } from "./client.ts";
13
+ import { ContentStore, isLoader, isSnapshot } from "./content.ts";
14
+ import { parseDraftPointer } from "./draft.ts";
15
+ import { clearGlobals, contentIdentity, fnv1a, readEnv } from "./identity.ts";
16
+ import { remoteLoader, resetRemoteLoaders } from "./remoteLoader.ts";
17
+ import { resolveDestination, setCurrentTelemetry, TelemetryPipeline } from "./telemetry.ts";
18
+ import type { Blocks, Client, CMS, CMSConfig, Loader, Snapshot } from "./types.ts";
19
+ import { forceVariants } from "./variants.ts";
18
20
 
19
21
  const INSTANCE_PREFIX = "decocms.blocks.cms:";
20
22
  const MIN_INTERVAL = 60_000;
@@ -39,7 +41,7 @@ class CMSInstance implements CMS {
39
41
  readonly #telemetry: TelemetryPipeline | undefined;
40
42
  #blocks: Blocks;
41
43
  /**
42
- * When the next check is due. The first is on the first `forRelease()`, not
44
+ * When the next check is due. The first is on the first `forRelease()` or `forDraft()`, not
43
45
  * at construction: Workers read `Date.now()` as 0 at module scope.
44
46
  */
45
47
  #nextCheck: number | undefined;
@@ -73,8 +75,18 @@ class CMSInstance implements CMS {
73
75
  );
74
76
  }
75
77
 
78
+ /**
79
+ * The draft, with the variants the pointer forces (even over a source with no
80
+ * drafts). A draft inherits local production, so it schedules the same
81
+ * background release check `forRelease()` does (never in front of the draft).
82
+ */
76
83
  forDraft(pointer: string): Client {
77
- return this.#client(() => this.#store.draft(pointer));
84
+ this.#scheduleUpdate();
85
+ const variants = parseDraftPointer(pointer)?.variants;
86
+ if (variants === undefined) return this.#client(() => this.#store.draft(pointer));
87
+ return this.#client(() =>
88
+ this.#store.draft(pointer).then((snapshot) => forceVariants(snapshot, variants)),
89
+ );
78
90
  }
79
91
 
80
92
  forRevision(revision: string): Client {
package/src/v8/content.ts CHANGED
@@ -7,13 +7,19 @@
7
7
  * revision string a client may hand back, so it must only ever reach published
8
8
  * content, never a draft someone loaded with a pointer.
9
9
  */
10
- import { formatDraftPointer, parseDraftPointer } from "./draft";
11
- import { errors, isResolutionError } from "./errors";
12
- import { isPlainObject } from "./json";
13
- import type { Loader, Snapshot } from "./types";
10
+ import { formatDraftPointer, parseDraftPointer } from "./draft.ts";
11
+ import { errors, isResolutionError } from "./errors.ts";
12
+ import { isPlainObject } from "./json.ts";
13
+ import type { Loader, Snapshot } from "./types.ts";
14
14
 
15
15
  const SERVED_REVISIONS = 16;
16
- const CACHED_DRAFTS = 32;
16
+ /** Composed drafts kept per CMS (see /next/studio-implementation's initial limits). */
17
+ const CACHED_DRAFTS = 3;
18
+ /**
19
+ * How long a loaded draft is reused before `load(pointer)` runs again, so a
20
+ * loader's own checks (a hosted grant's expiry) apply on a warm server too.
21
+ */
22
+ const DRAFT_TTL_MS = 60_000;
17
23
 
18
24
  export function isLoader(content: unknown): content is Loader {
19
25
  return (
@@ -36,7 +42,9 @@ export class ContentStore {
36
42
  #source: Snapshot | Loader;
37
43
  #release: Promise<Snapshot> | undefined;
38
44
  #updating: Promise<{ updated: boolean }> | undefined;
39
- readonly #drafts = new BoundedMap<string, Promise<Snapshot>>(CACHED_DRAFTS);
45
+ readonly #drafts = new BoundedMap<string, { pending: Promise<Snapshot>; at: number }>(
46
+ CACHED_DRAFTS,
47
+ );
40
48
  readonly #served = new BoundedMap<string, Snapshot>(SERVED_REVISIONS);
41
49
 
42
50
  constructor(source: Snapshot | Loader) {
@@ -70,8 +78,10 @@ export class ContentStore {
70
78
 
71
79
  /**
72
80
  * The draft a pointer names. A snapshot has no drafts and ignores the
73
- * pointer. A loader gets `load(pointer)` only for a pointer that parses;
74
- * anything else is `LOADER_FAILED`, never a silent fallback to the release.
81
+ * pointer. A loader gets `load(pointer)` only for a pointer that parses,
82
+ * formatted again without its `__variant` parameters (so every variant of
83
+ * one draft shares one load); anything else is `LOADER_FAILED`, never a
84
+ * silent fallback to the release. A loaded draft is reused for a minute.
75
85
  */
76
86
  draft(pointer: string): Promise<Snapshot> {
77
87
  const source = this.#source;
@@ -80,13 +90,20 @@ export class ContentStore {
80
90
  if (parsed === null) {
81
91
  return Promise.reject(errors.loaderFailed(`invalid draft pointer "${truncate(pointer)}"`));
82
92
  }
83
- const key = formatDraftPointer(parsed);
93
+ // The draft itself, without the variants a preview forces: those apply per client.
94
+ const key = formatDraftPointer({
95
+ host: parsed.host,
96
+ path: parsed.path,
97
+ version: parsed.version,
98
+ });
84
99
  const cached = this.#drafts.get(key);
85
- if (cached !== undefined) return cached;
86
- const pending = this.#load(source, pointer);
87
- this.#drafts.set(key, pending);
88
- pending.catch(() => this.#drafts.delete(key));
89
- return pending;
100
+ if (cached !== undefined && Date.now() - cached.at < DRAFT_TTL_MS) return cached.pending;
101
+ const entry = { pending: this.#load(source, key), at: Date.now() };
102
+ this.#drafts.set(key, entry);
103
+ entry.pending.catch(() => {
104
+ if (this.#drafts.get(key) === entry) this.#drafts.delete(key);
105
+ });
106
+ return entry.pending;
90
107
  }
91
108
 
92
109
  /** A release revision this store has served, or the release when it's unknown (drafts included). */
@@ -131,7 +148,9 @@ export class ContentStore {
131
148
  const previous = this.#source;
132
149
  if (source === previous) {
133
150
  // The same loader (a hosted remoteLoader that adopted new fallback content): re-read it.
151
+ // Cached drafts were layered over the old content, so they go too.
134
152
  this.#release = undefined;
153
+ this.#drafts.clear();
135
154
  return;
136
155
  }
137
156
  if (isSnapshot(previous)) this.#served.delete(previous.revision);
@@ -167,29 +186,46 @@ function truncate(value: string): string {
167
186
  return value.length > 80 ? `${value.slice(0, 80)}…` : value;
168
187
  }
169
188
 
170
- /** A Map that forgets its least recently set entry past `limit`. */
171
- class BoundedMap<K, V> {
189
+ /**
190
+ * A Map that forgets its least recently used entries past `limit`, counted by
191
+ * `size` (one per entry unless given).
192
+ */
193
+ export class BoundedMap<K, V> {
172
194
  readonly #map = new Map<K, V>();
173
- constructor(readonly limit: number) {}
195
+ #total = 0;
196
+ constructor(
197
+ readonly limit: number,
198
+ readonly size: (value: V) => number = () => 1,
199
+ ) {}
174
200
 
175
201
  get(key: K): V | undefined {
176
- return this.#map.get(key);
202
+ const value = this.#map.get(key);
203
+ if (value !== undefined) {
204
+ this.#map.delete(key);
205
+ this.#map.set(key, value);
206
+ }
207
+ return value;
177
208
  }
178
209
 
179
210
  set(key: K, value: V): void {
180
- this.#map.delete(key);
211
+ this.delete(key);
181
212
  this.#map.set(key, value);
182
- if (this.#map.size > this.limit) {
183
- const oldest = this.#map.keys().next();
184
- if (!oldest.done) this.#map.delete(oldest.value);
213
+ this.#total += this.size(value);
214
+ for (const [oldest, old] of this.#map) {
215
+ if (this.#total <= this.limit || oldest === key) break;
216
+ this.#map.delete(oldest);
217
+ this.#total -= this.size(old);
185
218
  }
186
219
  }
187
220
 
188
221
  delete(key: K): void {
222
+ if (!this.#map.has(key)) return;
223
+ this.#total -= this.size(this.#map.get(key) as V);
189
224
  this.#map.delete(key);
190
225
  }
191
226
 
192
227
  clear(): void {
193
228
  this.#map.clear();
229
+ this.#total = 0;
194
230
  }
195
231
  }
package/src/v8/draft.ts CHANGED
@@ -2,8 +2,12 @@
2
2
  * Draft pointers (see /next/api-reference#draft-pointers): the string
3
3
  * `<host[:port]><path[?query]>@<version>` that names a draft, and the two
4
4
  * helpers that carry one from a `?__draft=` link into a cookie.
5
+ *
6
+ * The query's reserved `__variant` parameters are the variants a preview
7
+ * forces (`<block>@<path>=<index>`, URL-encoded, one per multivariate); the
8
+ * parser lifts them out of `path` into `variants`.
5
9
  */
6
- import type { DraftPointer } from "./types";
10
+ import type { DraftPointer, ForcedVariant } from "./types.ts";
7
11
 
8
12
  /** The draft cookie's name, for frameworks whose cookie API has no Request (Next.js `cookies()`). */
9
13
  export const DRAFT_COOKIE = "deco-draft";
@@ -18,6 +22,8 @@ const VERSION_RE = /^[A-Za-z0-9._-]{1,64}$/;
18
22
  /** Rooted path with an optional query; no `@`, `#`, whitespace or scheme characters. */
19
23
  const PATH_RE = /^\/[A-Za-z0-9/_.%~=&?-]*$/;
20
24
  const MAX_POINTER_LENGTH = 4096;
25
+ const VARIANT_PARAM = "__variant=";
26
+ const INDEX_RE = /^(0|[1-9][0-9]{0,3})$/;
21
27
 
22
28
  /**
23
29
  * Parses a pointer, strictly: `null` on a scheme, a stray `@`, an unrooted
@@ -39,7 +45,12 @@ export function parseDraftPointer(raw: string | null | undefined): DraftPointer
39
45
  if (!PATH_RE.test(path) || path.startsWith("//")) return null;
40
46
 
41
47
  const host = normalizeHost(location.slice(0, slash));
42
- return host === null ? null : { host, path, version };
48
+ if (host === null) return null;
49
+ const split = splitVariants(path);
50
+ if (split === null) return null;
51
+ return split.variants.length === 0
52
+ ? { host, path, version }
53
+ : { host, path: split.path, version, variants: split.variants };
43
54
  }
44
55
 
45
56
  /**
@@ -48,12 +59,70 @@ export function parseDraftPointer(raw: string | null | undefined): DraftPointer
48
59
  * bad pointer is caught where it's built rather than where it's loaded.
49
60
  */
50
61
  export function formatDraftPointer(pointer: DraftPointer): string {
51
- const raw = `${pointer.host}${pointer.path}@${pointer.version}`;
52
- const parsed = parseDraftPointer(raw);
53
- if (parsed === null || parsed.path !== pointer.path || parsed.version !== pointer.version) {
62
+ const variants = pointer.variants ?? [];
63
+ const params = variants.map((variant) => VARIANT_PARAM + encodeVariant(variant));
64
+ const path =
65
+ params.length === 0
66
+ ? pointer.path
67
+ : `${pointer.path}${pointer.path.includes("?") ? "&" : "?"}${params.join("&")}`;
68
+ const parsed = parseDraftPointer(`${pointer.host}${path}@${pointer.version}`);
69
+ if (
70
+ parsed === null ||
71
+ parsed.path !== pointer.path ||
72
+ parsed.version !== pointer.version ||
73
+ JSON.stringify(parsed.variants ?? []) !== JSON.stringify(variants.map(plainVariant))
74
+ ) {
54
75
  throw new TypeError(`invalid draft pointer parts: ${JSON.stringify(pointer)}`);
55
76
  }
56
- return `${parsed.host}${parsed.path}@${parsed.version}`;
77
+ return `${parsed.host}${path}@${parsed.version}`;
78
+ }
79
+
80
+ /** The path without its `__variant` parameters, and the variants they force; `null` on a bad one. */
81
+ function splitVariants(path: string): { path: string; variants: ForcedVariant[] } | null {
82
+ const q = path.indexOf("?");
83
+ if (q === -1) return { path, variants: [] };
84
+ const kept: string[] = [];
85
+ const variants: ForcedVariant[] = [];
86
+ for (const param of path.slice(q + 1).split("&")) {
87
+ if (!param.startsWith(VARIANT_PARAM)) {
88
+ kept.push(param);
89
+ continue;
90
+ }
91
+ const variant = decodeVariant(param.slice(VARIANT_PARAM.length));
92
+ if (variant === null) return null;
93
+ variants.push(variant);
94
+ }
95
+ const base = path.slice(0, q);
96
+ return { path: kept.length === 0 ? base : `${base}?${kept.join("&")}`, variants };
97
+ }
98
+
99
+ /** `<block>@<path>=<index>`: the index after the last `=`, the block before the last `@`. */
100
+ function decodeVariant(encoded: string): ForcedVariant | null {
101
+ let raw: string;
102
+ try {
103
+ raw = decodeURIComponent(encoded);
104
+ } catch {
105
+ return null;
106
+ }
107
+ const eq = raw.lastIndexOf("=");
108
+ const at = raw.lastIndexOf("@", eq);
109
+ if (eq === -1 || at <= 0) return null;
110
+ const index = raw.slice(eq + 1);
111
+ const path = raw.slice(at + 1, eq);
112
+ if (!INDEX_RE.test(index) || (path !== "" && path.split(".").includes(""))) return null;
113
+ return { block: raw.slice(0, at), path, index: Number(index) };
114
+ }
115
+
116
+ function encodeVariant({ block, path, index }: ForcedVariant): string {
117
+ // encodeURIComponent leaves !'()* as they are; the pointer's path doesn't allow them.
118
+ return encodeURIComponent(`${block}@${path}=${index}`).replace(
119
+ /[!'()*]/g,
120
+ (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
121
+ );
122
+ }
123
+
124
+ function plainVariant({ block, path, index }: ForcedVariant): ForcedVariant {
125
+ return { block, path, index };
57
126
  }
58
127
 
59
128
  function normalizeHost(authority: string): string | null {
package/src/v8/errors.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CMSError, CMSErrorCode } from "./types";
1
+ import type { CMSError, CMSErrorCode } from "./types.ts";
2
2
 
3
3
  /**
4
4
  * The concrete {@link CMSError}. It extends `Error` so a lazy block can reject
package/src/v8/fetch.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * has no telemetry destination. Nothing about a request's body, headers or
10
10
  * query string is recorded.
11
11
  */
12
- import { currentTelemetry, describe, newTraceId } from "./telemetry";
12
+ import { currentTelemetry, describe, newTraceId } from "./telemetry.ts";
13
13
 
14
14
  interface InstrumentedFetchOptions {
15
15
  /** The provider label, e.g. "vtex", "acme-search". */
@@ -3,7 +3,7 @@
3
3
  * keys go into the global symbol registry, so they're derived from the
4
4
  * configuration and never carry a secret.
5
5
  */
6
- import type { Loader, Snapshot } from "./types";
6
+ import type { Loader, Snapshot } from "./types.ts";
7
7
 
8
8
  const OBJECT_IDS = Symbol.for("decocms.blocks.cms-loader-ids");
9
9