@decocms/blocks 8.1.0-next.0 → 8.1.0-next.2

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 (490) 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 +22 -0
  47. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -0
  48. package/dist/protocol/conformance/contentHashFixtures.js +64 -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 +25 -0
  63. package/dist/protocol/index.d.ts.map +1 -0
  64. package/dist/protocol/index.js +25 -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 +42 -0
  191. package/dist/v8/canonical.d.ts.map +1 -0
  192. package/dist/v8/canonical.js +111 -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 +120 -0
  247. package/dist/v8/cli/schema/tsProgram.d.ts.map +1 -0
  248. package/dist/v8/cli/schema/tsProgram.js +418 -0
  249. package/dist/v8/cli/schema/tsProgram.js.map +1 -0
  250. package/dist/v8/cli/schema/typeToSchema.d.ts +81 -0
  251. package/dist/v8/cli/schema/typeToSchema.d.ts.map +1 -0
  252. package/dist/v8/cli/schema/typeToSchema.js +683 -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 +206 -0
  269. package/dist/v8/cms.js.map +1 -0
  270. package/dist/v8/content.d.ts +35 -0
  271. package/dist/v8/content.d.ts.map +1 -0
  272. package/dist/v8/content.js +183 -0
  273. package/dist/v8/content.js.map +1 -0
  274. package/dist/v8/draft.d.ts +44 -0
  275. package/dist/v8/draft.d.ts.map +1 -0
  276. package/dist/v8/draft.js +133 -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 +243 -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 +214 -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/package.json +65 -105
  323. package/src/index.ts +3 -13
  324. package/src/protocol/canonical.ts +1 -1
  325. package/src/protocol/ciphertext.ts +1 -1
  326. package/src/protocol/client.ts +2 -2
  327. package/src/protocol/conformance/cases/assets.ts +3 -3
  328. package/src/protocol/conformance/cases/guards.ts +4 -4
  329. package/src/protocol/conformance/cases/reads.ts +4 -4
  330. package/src/protocol/conformance/cases/types.ts +1 -1
  331. package/src/protocol/conformance/cases/wire.ts +4 -4
  332. package/src/protocol/conformance/cases/writes.ts +4 -4
  333. package/src/protocol/conformance/context.ts +4 -4
  334. package/src/protocol/conformance/index.ts +10 -10
  335. package/src/protocol/index.ts +6 -6
  336. package/src/protocol/params.ts +2 -2
  337. package/src/protocol/secrets.ts +3 -3
  338. package/src/protocol/server/assets.ts +6 -6
  339. package/src/protocol/server/auth.ts +1 -1
  340. package/src/protocol/server/content.ts +5 -5
  341. package/src/protocol/server/core.ts +12 -6
  342. package/src/protocol/server/handler.ts +6 -6
  343. package/src/protocol/server/http.ts +1 -1
  344. package/src/protocol/server/index.ts +3 -3
  345. package/src/protocol/server/methods/apply.ts +9 -9
  346. package/src/protocol/server/methods/read.ts +5 -5
  347. package/src/protocol/server/rpc.ts +6 -6
  348. package/src/protocol/storage/fs/index.ts +7 -7
  349. package/src/protocol/storage/fs/lock.ts +1 -1
  350. package/src/protocol/storage/fs/unsupported.ts +2 -2
  351. package/src/protocol/storage/memory.ts +5 -5
  352. package/src/protocol/storage.ts +1 -1
  353. package/src/v8/analytics.ts +2 -2
  354. package/src/v8/background.ts +3 -3
  355. package/src/v8/builtins/data.ts +1 -1
  356. package/src/v8/builtins/index.ts +6 -6
  357. package/src/v8/builtins/lazy.ts +1 -1
  358. package/src/v8/builtins/legacy.ts +2 -2
  359. package/src/v8/builtins/multivariate.ts +1 -1
  360. package/src/v8/builtins/secret.ts +2 -2
  361. package/src/v8/cli/builtins.ts +2 -2
  362. package/src/v8/cli/check/index.ts +11 -11
  363. package/src/v8/cli/content.ts +6 -6
  364. package/src/v8/cli/index.ts +8 -8
  365. package/src/v8/cli/main.ts +1 -1
  366. package/src/v8/cli/run.ts +7 -7
  367. package/src/v8/cli/schema/builtinSchemas.ts +1 -1
  368. package/src/v8/cli/schema/generate.ts +6 -6
  369. package/src/v8/cli/schema/index.ts +4 -4
  370. package/src/v8/cli/schema/tsProgram.ts +1 -1
  371. package/src/v8/cli/schema/typeToSchema.ts +24 -2
  372. package/src/v8/cli/serve/server.ts +9 -9
  373. package/src/v8/client.ts +5 -5
  374. package/src/v8/cms.ts +9 -9
  375. package/src/v8/content.ts +4 -4
  376. package/src/v8/draft.ts +1 -1
  377. package/src/v8/errors.ts +1 -1
  378. package/src/v8/fetch.ts +9 -28
  379. package/src/v8/identity.ts +1 -1
  380. package/src/v8/index.ts +5 -5
  381. package/src/v8/matchRoute.ts +1 -1
  382. package/src/v8/remoteLoader.ts +7 -7
  383. package/src/v8/resolver.ts +6 -6
  384. package/src/v8/secrets.ts +1 -1
  385. package/src/v8/telemetry.ts +6 -6
  386. package/src/cms/applySectionConventions.ts +0 -148
  387. package/src/cms/blockSource.ts +0 -228
  388. package/src/cms/client.ts +0 -85
  389. package/src/cms/deferredTrigger.ts +0 -58
  390. package/src/cms/draftSource.ts +0 -476
  391. package/src/cms/index.ts +0 -180
  392. package/src/cms/loadDecofileDirectory.ts +0 -89
  393. package/src/cms/loader.ts +0 -563
  394. package/src/cms/registry.ts +0 -264
  395. package/src/cms/renderJson.ts +0 -179
  396. package/src/cms/resolve.ts +0 -2583
  397. package/src/cms/schema.ts +0 -1219
  398. package/src/cms/sectionLoaderContext.ts +0 -113
  399. package/src/cms/sectionLoaders.ts +0 -686
  400. package/src/cms/sectionMixins.ts +0 -153
  401. package/src/flags/audience.ts +0 -56
  402. package/src/flags/everyone.ts +0 -29
  403. package/src/flags/flag.ts +0 -15
  404. package/src/flags/multivariate/image.ts +0 -11
  405. package/src/flags/multivariate/message.ts +0 -11
  406. package/src/flags/multivariate/page.ts +0 -16
  407. package/src/flags/multivariate/section.ts +0 -16
  408. package/src/flags/multivariate.ts +0 -1
  409. package/src/flags/types.ts +0 -59
  410. package/src/flags/utils/multivariate.ts +0 -20
  411. package/src/hooks/Image.tsx +0 -314
  412. package/src/hooks/JsonLd.tsx +0 -353
  413. package/src/hooks/LazySection.tsx +0 -121
  414. package/src/hooks/LiveControls.tsx +0 -144
  415. package/src/hooks/Picture.tsx +0 -127
  416. package/src/hooks/RenderSection.tsx +0 -91
  417. package/src/hooks/SectionErrorFallback.tsx +0 -97
  418. package/src/hooks/Stats.tsx +0 -134
  419. package/src/hooks/index.ts +0 -35
  420. package/src/hooks/useLoadMore.ts +0 -100
  421. package/src/matchers/builtins.ts +0 -459
  422. package/src/matchers/countryNames.ts +0 -104
  423. package/src/matchers/override.ts +0 -136
  424. package/src/matchers/posthog.ts +0 -154
  425. package/src/middleware/decoState.ts +0 -55
  426. package/src/middleware/healthMetrics.ts +0 -133
  427. package/src/middleware/hydrationContext.ts +0 -79
  428. package/src/middleware/index.ts +0 -88
  429. package/src/middleware/liveness.ts +0 -21
  430. package/src/middleware/observability.ts +0 -800
  431. package/src/middleware/validateSection.ts +0 -100
  432. package/src/preview/DraftPreviewBadge.tsx +0 -306
  433. package/src/preview/decoMark.ts +0 -11
  434. package/src/preview/index.ts +0 -8
  435. package/src/sdk/abTesting.ts +0 -556
  436. package/src/sdk/analytics.ts +0 -147
  437. package/src/sdk/cacheHeaders.ts +0 -633
  438. package/src/sdk/cacheStorage.ts +0 -287
  439. package/src/sdk/cachedLoader.ts +0 -556
  440. package/src/sdk/clx.ts +0 -5
  441. package/src/sdk/cn.ts +0 -28
  442. package/src/sdk/composite.ts +0 -114
  443. package/src/sdk/cookie.ts +0 -129
  444. package/src/sdk/crypto.ts +0 -199
  445. package/src/sdk/csp.ts +0 -59
  446. package/src/sdk/deepOmit.ts +0 -52
  447. package/src/sdk/detectDevice.ts +0 -45
  448. package/src/sdk/djb2.ts +0 -20
  449. package/src/sdk/encoding.ts +0 -44
  450. package/src/sdk/env.ts +0 -54
  451. package/src/sdk/experiments.ts +0 -314
  452. package/src/sdk/fetchCache.ts +0 -269
  453. package/src/sdk/fetchTimeout.ts +0 -58
  454. package/src/sdk/flags.ts +0 -138
  455. package/src/sdk/http.ts +0 -124
  456. package/src/sdk/index.ts +0 -97
  457. package/src/sdk/inflightTimeout.ts +0 -53
  458. package/src/sdk/instrumentedFetch.ts +0 -362
  459. package/src/sdk/invoke.ts +0 -298
  460. package/src/sdk/logger.ts +0 -304
  461. package/src/sdk/mergeCacheControl.ts +0 -150
  462. package/src/sdk/nonce.ts +0 -46
  463. package/src/sdk/normalizeUrls.ts +0 -91
  464. package/src/sdk/observability.ts +0 -116
  465. package/src/sdk/otel.ts +0 -1118
  466. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  467. package/src/sdk/otelAdapters.ts +0 -144
  468. package/src/sdk/otelHttpLog.ts +0 -419
  469. package/src/sdk/otelHttpMeter.ts +0 -532
  470. package/src/sdk/otelHttpTracer.ts +0 -543
  471. package/src/sdk/redirects.ts +0 -336
  472. package/src/sdk/requestContext.ts +0 -281
  473. package/src/sdk/requestContextStorage.browser.ts +0 -43
  474. package/src/sdk/requestContextStorage.ts +0 -35
  475. package/src/sdk/responseCache.ts +0 -82
  476. package/src/sdk/retry.ts +0 -45
  477. package/src/sdk/serverTimings.ts +0 -68
  478. package/src/sdk/signal.ts +0 -42
  479. package/src/sdk/sitemap.ts +0 -160
  480. package/src/sdk/urlRedaction.ts +0 -82
  481. package/src/sdk/urlUtils.ts +0 -183
  482. package/src/sdk/useDevice.ts +0 -89
  483. package/src/sdk/useDeviceContext.tsx +0 -108
  484. package/src/sdk/useId.ts +0 -7
  485. package/src/sdk/useScript.ts +0 -210
  486. package/src/sdk/useSuggestions.ts +0 -188
  487. package/src/sdk/wrapCaughtErrors.ts +0 -107
  488. package/src/setup.ts +0 -120
  489. package/src/types/index.ts +0 -53
  490. package/src/types/widgets.ts +0 -14
@@ -1,556 +0,0 @@
1
- /**
2
- * Server-side loader caching with stale-while-revalidate + stale-if-error.
3
- *
4
- * Caches commerce loader results in memory and optional app-provided storage.
5
- * Supports:
6
- * - Single-flight dedup (identical concurrent requests share one fetch)
7
- * - SWR: serve stale immediately, refresh in background
8
- * - SIE: on origin error, fall back to stale entry within a configurable window
9
- *
10
- * Can be configured with explicit options or by passing a cache profile name
11
- * (e.g. "product") which derives timing from the unified profile system.
12
- */
13
-
14
- import {
15
- recordCacheMetric,
16
- recordCacheSizeMetric,
17
- recordLoaderError,
18
- recordLoaderMetric,
19
- withTracing,
20
- } from "../middleware/observability";
21
- import { type CacheProfileName, loaderCacheOptions } from "./cacheHeaders";
22
- import { cacheBackground, createCacheStore, getCacheStorageContext } from "./cacheStorage";
23
- import { withInflightTimeout } from "./inflightTimeout";
24
- import { RequestContext } from "./requestContext";
25
-
26
- // Build-time constant injected by `decoVitePlugin()` (see @decocms/tanstack's
27
- // vite plugin) — the same commit-SHA/deploy token the edge Cache API uses as
28
- // its `__v` cache-key version. Declared here with a `typeof` guard so it's
29
- // inert where the define is not applied (Node tests, non-plugin builds). Same
30
- // pattern already used in `../cms/blockSource.ts`.
31
- declare const __DECO_BUILD_HASH__: string | undefined;
32
-
33
- // Include the build version even when called outside the TanStack worker. The
34
- // request-scoped store additionally separates sites, content revisions and segments.
35
- const BUILD =
36
- typeof __DECO_BUILD_HASH__ !== "undefined" && __DECO_BUILD_HASH__ ? __DECO_BUILD_HASH__ : "";
37
-
38
- /**
39
- * `maxAge` above this (10 min) is almost always a mistake for a commerce loader:
40
- * upstream (catalog/price/stock) changes then take that long to propagate and a
41
- * redeploy is the only fast lever. Warned once per loader name.
42
- */
43
- const LONG_MAXAGE_WARN = 600_000;
44
- const warnedLongMaxAge = new Set<string>();
45
-
46
- export type CachePolicy = "no-store" | "no-cache" | "stale-while-revalidate";
47
-
48
- export interface CachedLoaderOptions {
49
- policy: CachePolicy;
50
- /** Max age in milliseconds before an entry is considered stale. Default: 60_000 (1 min). */
51
- maxAge?: number;
52
- /** How long to serve stale on origin error, in ms. Default: 0 (no error fallback). */
53
- staleIfError?: number;
54
- /** Maximum stale-while-revalidate window in ms. Default: 5 minutes. */
55
- staleWhileRevalidate?: number;
56
- /** Key function to generate a cache key from loader props. Default: JSON.stringify. */
57
- keyFn?: (props: unknown) => string;
58
- }
59
-
60
- /**
61
- * The `@decocms/apps` loader/action module shape: a `default` loader plus the
62
- * optional `cache` / `cacheKey` exports Fresh loaders ship with.
63
- *
64
- * export const cache = "stale-while-revalidate";
65
- * export const cacheKey = (props, req) => `${new URL(req.url).pathname}...`;
66
- *
67
- * `cache` is the OPT-IN: absent (or `"no-store"`) means the loader runs on every
68
- * invocation, matching `@decocms/apps`' default. Any other value opts the loader
69
- * into single-flight dedup (concurrent identical calls in one render collapse to
70
- * one upstream call — the #339 N+1 fix). `cacheKey` computes the dedup identity
71
- * from `(props, req)`; returning `null` means "do not dedup, run fresh".
72
- */
73
- export interface LoaderModule<TProps = any, TResult = any> {
74
- default: (props: TProps, req?: Request) => Promise<TResult>;
75
- cache?: CachePolicy | { maxAge: number };
76
- cacheKey?: (props: TProps, req?: Request) => string | null;
77
- }
78
-
79
- interface CacheEntry<T = unknown> {
80
- value: T;
81
- createdAt: number;
82
- refreshing: boolean;
83
- /** Estimated payload size in bytes (UTF-16 length of JSON.stringify). */
84
- estimatedBytes: number;
85
- }
86
-
87
- const DEFAULT_MAX_AGE = 60_000;
88
-
89
- /**
90
- * Byte-cap for the in-memory loader cache. Default 32 MB — comfortably below
91
- * the Cloudflare Workers 128 MB isolate limit even when other caches (router,
92
- * VTEX fetch cache, V8 heap) are also resident.
93
- *
94
- * Override via env: `DECO_LOADER_CACHE_MAX_BYTES=67108864` (64 MB).
95
- *
96
- * Switched from entry-count to byte-based eviction because PLP payloads
97
- * (~0.5–2 MB each) blew past 128 MB at well under the previous 500-entry cap.
98
- */
99
- const DEFAULT_MAX_CACHE_BYTES = 32 * 1024 * 1024;
100
-
101
- function resolveMaxBytes(): number {
102
- const env = typeof globalThis.process !== "undefined" ? globalThis.process.env : undefined;
103
- const raw = env?.DECO_LOADER_CACHE_MAX_BYTES;
104
- if (!raw) return DEFAULT_MAX_CACHE_BYTES;
105
- const parsed = Number.parseInt(raw, 10);
106
- return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_MAX_CACHE_BYTES;
107
- }
108
-
109
- let maxCacheBytes = resolveMaxBytes();
110
-
111
- /**
112
- * Override the loader cache byte cap at runtime.
113
- *
114
- * The `DECO_LOADER_CACHE_MAX_BYTES` env override above only lands when the
115
- * Worker's `compatibility_date` is new enough for `nodejs_compat` to populate
116
- * `process.env`. Verified in workerd: with `2024-09-23` it is empty both at
117
- * module scope and inside the handler; with `2025-06-01` it is populated. Sites
118
- * pinned to an older date — a common thing to do, since the date also gates
119
- * behaviour flags they may have tuned deliberately — had a documented knob that
120
- * silently did nothing.
121
- *
122
- * Call this from the site's `setup.ts`, before any loader is wrapped.
123
- *
124
- * Sizing note: the cap is per ISOLATE, not per site, and a Worker isolate has
125
- * 128 MB total, shared with the bundle, the V8 heap and the render working set.
126
- * Setting it at or near 128 MB does not give headroom — it removes the ceiling.
127
- */
128
- export function setLoaderCacheMaxBytes(bytes: number): void {
129
- if (!Number.isFinite(bytes) || bytes <= 0) return;
130
- maxCacheBytes = bytes;
131
- }
132
-
133
- /** Current byte cap — exported for diagnostics and tests. */
134
- export function getLoaderCacheMaxBytes(): number {
135
- return maxCacheBytes;
136
- }
137
-
138
- const cache = createCacheStore<CacheEntry>(
139
- "loaders",
140
- Infinity,
141
- Infinity,
142
- (entry) => entry.estimatedBytes,
143
- );
144
-
145
- // Bumped by clearLoaderCache(). A loader invocation captures this at entry and
146
- // only writes its result back if the generation is unchanged when it settles —
147
- // so a purge (e.g. POST /_cache/purge-loaders) that lands while a loader is
148
- // in flight can't be silently undone by that in-flight loader repopulating a
149
- // just-cleared entry with pre-purge data.
150
- let cacheGeneration = 0;
151
-
152
- // Floor each entry at 512 bytes so we never accumulate unbounded zero-cost
153
- // entries when a loader legitimately returns `undefined` or an empty object
154
- // — `JSON.stringify(undefined) === undefined` and the eviction loop would
155
- // otherwise never reclaim them. JSON-length also under-counts V8's actual
156
- // retention (structured objects retain 2–5× the JSON byte size); the 32 MB
157
- // cap is conservative enough that this approximation is fine for an OOM
158
- // safety net, but real RSS at the cap can land around 64–160 MB on
159
- // object-heavy payloads.
160
- const MIN_ENTRY_BYTES = 512;
161
-
162
- function estimateBytes(value: unknown): number {
163
- try {
164
- // UTF-16 string length is an order-of-magnitude estimate of the bytes the
165
- // object retains in V8 (V8 keeps a structured representation, not JSON).
166
- // The absolute value is less important than the relative pressure signal.
167
- const len = JSON.stringify(value)?.length ?? 0;
168
- return Math.max(len, MIN_ENTRY_BYTES);
169
- } catch {
170
- // Circular refs / non-serializable values: fall back to a fixed budget so
171
- // the entry still counts against the cap.
172
- return 1024;
173
- }
174
- }
175
-
176
- /**
177
- * The single write path into the cache — both the cold-miss and the SWR
178
- * background-refresh callers route through here, which is why the size metric
179
- * is emitted at this chokepoint rather than at each call site.
180
- */
181
- function setCacheEntry<T>(key: string, entry: CacheEntry<T>, name: string, retention: number) {
182
- recordCacheSizeMetric(entry.estimatedBytes, name);
183
- cache.set(key, entry, entry.createdAt + retention);
184
- }
185
-
186
- function deleteCacheEntry(key: string) {
187
- cache.delete(key);
188
- }
189
-
190
- function evictIfNeeded() {
191
- let cacheBytes = cache.estimatedBytes;
192
- if (cacheBytes <= maxCacheBytes) return;
193
- const oldest = [...cache.entries()].sort((a, b) => a[1].createdAt - b[1].createdAt);
194
- for (const [key, entry] of oldest) {
195
- deleteCacheEntry(key);
196
- cacheBytes -= entry.estimatedBytes;
197
- if (cacheBytes <= maxCacheBytes) break;
198
- }
199
- }
200
-
201
- const inflightRequests = new Map<string, Promise<unknown>>();
202
-
203
- function resolveOptions(
204
- optionsOrProfile: CachedLoaderOptions | CacheProfileName,
205
- ): CachedLoaderOptions {
206
- if (typeof optionsOrProfile === "string") {
207
- return loaderCacheOptions(optionsOrProfile);
208
- }
209
- return optionsOrProfile;
210
- }
211
-
212
- /**
213
- * Wraps a loader function with server-side caching, single-flight dedup,
214
- * and stale-if-error resilience.
215
- *
216
- * Accepts either explicit options or a cache profile name:
217
- *
218
- * @example
219
- * ```ts
220
- * // Profile-driven (recommended):
221
- * const cachedPDP = createCachedLoader("vtex/productDetailsPage", pdpLoader, "product");
222
- *
223
- * // Explicit options (when loader needs different timing than its profile):
224
- * const cachedSuggestions = createCachedLoader("vtex/suggestions", suggestionsLoader, {
225
- * policy: "stale-while-revalidate",
226
- * maxAge: 120_000,
227
- * staleIfError: 300_000,
228
- * });
229
- * ```
230
- */
231
- export function createCachedLoader<TProps, TResult>(
232
- name: string,
233
- loaderFn: (props: TProps) => Promise<TResult>,
234
- optionsOrProfile: CachedLoaderOptions | CacheProfileName,
235
- ): (props: TProps) => Promise<TResult> {
236
- const resolved = resolveOptions(optionsOrProfile);
237
- const {
238
- policy,
239
- maxAge = DEFAULT_MAX_AGE,
240
- staleIfError = 0,
241
- staleWhileRevalidate = 300_000,
242
- keyFn = JSON.stringify,
243
- } = resolved;
244
-
245
- const env = typeof globalThis.process !== "undefined" ? globalThis.process.env : undefined;
246
- const isDev = env?.DECO_CACHE_DISABLE === "true" || env?.NODE_ENV === "development";
247
-
248
- if (policy !== "no-store" && maxAge > LONG_MAXAGE_WARN && !warnedLongMaxAge.has(name)) {
249
- warnedLongMaxAge.add(name);
250
- console.warn(
251
- `[cachedLoader] ${name}: maxAge=${Math.round(maxAge / 1000)}s is very long — ` +
252
- `upstream changes take that long to propagate. Prefer a short window and use ` +
253
- `short TTLs for shared storage; the purge-loaders endpoint clears memory only.`,
254
- );
255
- }
256
-
257
- if (policy === "no-store") return loaderFn;
258
-
259
- return async (props: TProps): Promise<TResult> => {
260
- const cacheKey = cache.key(`${BUILD}::${name}::${keyFn(props)}`);
261
- const retention =
262
- maxAge +
263
- Math.max(staleIfError, policy === "stale-while-revalidate" ? staleWhileRevalidate : 0);
264
- // Snapshot the cache generation; a purge during this invocation bumps it,
265
- // and the deferred writes below skip repopulating a just-cleared entry.
266
- const gen = cacheGeneration;
267
-
268
- const inflight = inflightRequests.get(cacheKey);
269
- if (inflight) {
270
- // Treat in-flight dedup as a cache hit — avoided the origin call.
271
- recordCacheMetric(true, name, undefined, "cachedLoader");
272
- const start = performance.now();
273
- return inflight.then((r) => {
274
- recordLoaderMetric(name, performance.now() - start, "HIT");
275
- return r as TResult;
276
- });
277
- }
278
-
279
- if (isDev) {
280
- // Dev mode: no caching, but still useful to count attempts.
281
- recordCacheMetric(false, name, undefined, "cachedLoader");
282
- const devStart = performance.now();
283
- const promise = withInflightTimeout(
284
- withTracing("deco.cachedLoader", () => loaderFn(props), {
285
- "deco.loader": name,
286
- "deco.cache.policy": "no-cache-dev",
287
- }),
288
- `cachedLoader:dev ${cacheKey}`,
289
- )
290
- .then((r) => {
291
- recordLoaderMetric(name, performance.now() - devStart, "BYPASS");
292
- return r;
293
- })
294
- .catch((err) => {
295
- recordLoaderMetric(name, performance.now() - devStart, "BYPASS");
296
- recordLoaderError(name);
297
- throw err;
298
- })
299
- .finally(() => inflightRequests.delete(cacheKey));
300
- inflightRequests.set(cacheKey, promise);
301
- return promise;
302
- }
303
-
304
- let entry = cache.get(cacheKey) as CacheEntry<TResult> | undefined;
305
- if (!entry && getCacheStorageContext()?.storage) {
306
- entry = (await cache.read(cacheKey)) as CacheEntry<TResult> | undefined;
307
- evictIfNeeded();
308
- }
309
- // Another caller may have started the origin fetch while storage was being read.
310
- const pending = inflightRequests.get(cacheKey);
311
- if (pending) return pending as Promise<TResult>;
312
- const now = Date.now();
313
- const isStale = entry ? now - entry.createdAt > maxAge : true;
314
-
315
- if (policy === "no-cache") {
316
- if (entry && !isStale) {
317
- recordCacheMetric(true, name, "HIT", "cachedLoader");
318
- recordLoaderMetric(name, 0, "HIT");
319
- return entry.value;
320
- }
321
- }
322
-
323
- if (policy === "stale-while-revalidate") {
324
- if (entry && !isStale) {
325
- recordCacheMetric(true, name, "HIT", "cachedLoader");
326
- recordLoaderMetric(name, 0, "HIT");
327
- return entry.value;
328
- }
329
-
330
- if (
331
- entry &&
332
- isStale &&
333
- now - entry.createdAt <= maxAge + staleWhileRevalidate &&
334
- !entry.refreshing
335
- ) {
336
- // Stale-while-revalidate hit: serve stale, refresh in background.
337
- recordCacheMetric(true, name, "STALE-HIT", "cachedLoader");
338
- recordLoaderMetric(name, 0, "STALE-HIT");
339
- entry.refreshing = true;
340
- cacheBackground(
341
- Promise.resolve()
342
- .then(() => loaderFn(props))
343
- .then((result) => {
344
- // Skip the write if a purge cleared the cache mid-refresh — otherwise
345
- // we'd re-insert pre-purge data the purge was meant to drop.
346
- if (gen !== cacheGeneration) return;
347
- setCacheEntry(
348
- cacheKey,
349
- {
350
- value: result,
351
- createdAt: Date.now(),
352
- refreshing: false,
353
- estimatedBytes: estimateBytes(result),
354
- },
355
- name,
356
- retention,
357
- );
358
- evictIfNeeded();
359
- })
360
- .catch(() => {
361
- // Background refresh failed — entry stays stale.
362
- // If past the SIE window, evict so we don't serve indefinitely stale data.
363
- entry.refreshing = false;
364
- if (staleIfError > 0 && now - entry.createdAt > maxAge + staleIfError) {
365
- deleteCacheEntry(cacheKey);
366
- }
367
- }),
368
- );
369
- return entry.value;
370
- }
371
-
372
- if (entry && now - entry.createdAt <= maxAge + staleWhileRevalidate) {
373
- // A background refresh is already running in this isolate.
374
- recordCacheMetric(true, name, "STALE-HIT", "cachedLoader");
375
- recordLoaderMetric(name, 0, "STALE-HIT");
376
- return entry.value;
377
- }
378
- }
379
-
380
- // Cache miss — emit metric, then run loader inside a span so individual
381
- // slow loaders are visible in traces.
382
- recordCacheMetric(false, name, "MISS", "cachedLoader");
383
- const loaderStart = performance.now();
384
- const promise = withInflightTimeout(
385
- withTracing("deco.cachedLoader", () => loaderFn(props), {
386
- "deco.loader": name,
387
- "deco.cache.policy": policy,
388
- }),
389
- `cachedLoader ${cacheKey}`,
390
- )
391
- .then((result) => {
392
- recordLoaderMetric(name, performance.now() - loaderStart, "MISS");
393
- // Skip caching if a purge landed while this loader was in flight — still
394
- // return the fresh value to the caller, just don't persist a raced entry.
395
- if (gen === cacheGeneration) {
396
- setCacheEntry(
397
- cacheKey,
398
- {
399
- value: result,
400
- createdAt: Date.now(),
401
- refreshing: false,
402
- estimatedBytes: estimateBytes(result),
403
- },
404
- name,
405
- retention,
406
- );
407
- evictIfNeeded();
408
- }
409
- return result;
410
- })
411
- .catch((err) => {
412
- // SIE fallback: if we have a stale entry within the error window, return it
413
- if (staleIfError > 0 && entry) {
414
- const age = Date.now() - entry.createdAt;
415
- if (age < maxAge + staleIfError) {
416
- console.warn(
417
- `[cachedLoader] ${name}: origin error, serving stale entry (age=${Math.round(age / 1000)}s, sie=${Math.round(staleIfError / 1000)}s)`,
418
- );
419
- recordLoaderMetric(name, performance.now() - loaderStart, "STALE-ERROR");
420
- return entry.value;
421
- }
422
- }
423
- recordLoaderMetric(name, performance.now() - loaderStart, "MISS");
424
- recordLoaderError(name);
425
- throw err;
426
- })
427
- .finally(() => inflightRequests.delete(cacheKey));
428
-
429
- inflightRequests.set(cacheKey, promise);
430
- return promise;
431
- };
432
- }
433
-
434
- // ---------------------------------------------------------------------------
435
- // Module loader dedup (the `@decocms/apps` cache/cacheKey convention)
436
- //
437
- // Distinct from `createCachedLoader` above (VTEX's byte-capped SWR cache): the
438
- // module path is DEDUP-ONLY. A loader that opts in via `export const cache`
439
- // gets single-flight — concurrent identical invocations in one render (N
440
- // sections referencing the same loader) share one upstream call — but nothing
441
- // is retained past settlement, so there is zero cross-request staleness. This
442
- // is the deliberately-conservative fix for the #339 N+1 (2–3× product GraphQL
443
- // per PDP render) without the SWR machinery's stale-serving semantics.
444
- // ---------------------------------------------------------------------------
445
-
446
- const moduleInflight = new Map<string, Promise<unknown>>();
447
-
448
- /**
449
- * Wrap an `@decocms/apps`-shaped loader module so its `cache`/`cacheKey` exports
450
- * drive single-flight dedup. Loaders without a `cache` export (or `"no-store"`)
451
- * are returned unwrapped — they run on every call, matching apps' default.
452
- *
453
- * The dedup key is `${name}::${cacheKey(props, req)}`; `req` comes from the
454
- * caller or, on the CMS-resolution path (which passes only props), from
455
- * `RequestContext.current` — both execute inside the same AsyncLocalStorage
456
- * scope. `cacheKey` returning `null`, or `req` being unavailable when `cacheKey`
457
- * needs it, falls back to running fresh / keying on `JSON.stringify(props)`.
458
- */
459
- export function createCachedLoaderFromModule<TProps, TResult>(
460
- name: string,
461
- mod: LoaderModule<TProps, TResult>,
462
- ): (props: TProps, req?: Request) => Promise<TResult> {
463
- const policy: CachePolicy =
464
- typeof mod.cache === "string"
465
- ? mod.cache
466
- : mod.cache && typeof mod.cache === "object"
467
- ? "stale-while-revalidate"
468
- : "no-store";
469
-
470
- // Only `stale-while-revalidate` (or `{ maxAge }`) opts into dedup — matching
471
- // `@decocms/apps`/deco, where `no-store` (the default) and `no-cache` both
472
- // bypass single-flight and run on every call. Return unwrapped otherwise.
473
- if (policy !== "stale-while-revalidate") return mod.default;
474
-
475
- const cacheKeyFn = mod.cacheKey;
476
-
477
- return (props: TProps, req?: Request): Promise<TResult> => {
478
- const request = req ?? RequestContext.current?.request ?? undefined;
479
-
480
- let keyPart: string | null;
481
- if (cacheKeyFn) {
482
- // A cacheKey that dereferences `req` (e.g. `new URL(req.url)`) would throw
483
- // when the request is unavailable — fall back to props-hash dedup instead.
484
- keyPart = request ? cacheKeyFn(props, request) : JSON.stringify(props);
485
- } else {
486
- keyPart = JSON.stringify(props);
487
- }
488
-
489
- // Explicit null → the loader declared this call uncacheable: run fresh.
490
- if (keyPart === null) return mod.default(props, req);
491
-
492
- const key = cache.key(`${BUILD}::${name}::${keyPart}`);
493
- const existing = moduleInflight.get(key) as Promise<TResult> | undefined;
494
- if (existing) return existing;
495
-
496
- const promise = Promise.resolve(mod.default(props, req)).finally(() => {
497
- moduleInflight.delete(key);
498
- });
499
- moduleInflight.set(key, promise);
500
- return promise;
501
- };
502
- }
503
-
504
- /**
505
- * Registry entry factory for generated loader maps (`.deco/loaders.gen.ts`).
506
- * Lazily imports the loader module on first call, then delegates to a memoized
507
- * `createCachedLoaderFromModule` wrapper so `cache`/`cacheKey` exports take
508
- * effect. Keeps generated code a one-liner while the dedup logic stays here,
509
- * unit-tested, in the framework.
510
- */
511
- export function createLoaderEntry<TProps = any, TResult = any>(
512
- name: string,
513
- importFn: () => Promise<LoaderModule<TProps, TResult>>,
514
- ): (props: TProps, req?: Request) => Promise<TResult> {
515
- // Memoize the import+build PROMISE (not the resolved wrapper) so concurrent
516
- // first-calls — exactly the N-sections-per-render case — share one import
517
- // instead of racing into N. Reset on failure so a transient import error can
518
- // retry rather than poisoning the entry forever.
519
- let wrappedPromise: Promise<(props: TProps, req?: Request) => Promise<TResult>> | undefined;
520
- return (props: TProps, req?: Request): Promise<TResult> => {
521
- if (!wrappedPromise) {
522
- wrappedPromise = importFn()
523
- .then((mod) => createCachedLoaderFromModule(name, mod))
524
- .catch((err) => {
525
- wrappedPromise = undefined;
526
- throw err;
527
- });
528
- }
529
- return wrappedPromise.then((wrapped) => wrapped(props, req));
530
- };
531
- }
532
-
533
- /**
534
- * Clear all cached entries in THIS isolate. Used both by decofile hot-reload
535
- * (`@decocms/blocks-admin`) and by the `POST /_cache/purge-loaders` route — an
536
- * memory eviction hook. Shared storage entries expire by TTL and may hydrate
537
- * memory again. Deployment/content scopes prevent reuse across versions. Bumps the cache
538
- * generation so any loader in flight at purge time won't repopulate a cleared
539
- * entry with pre-purge data.
540
- */
541
- export function clearLoaderCache() {
542
- cache.clear();
543
- inflightRequests.clear();
544
- moduleInflight.clear();
545
- cacheGeneration++;
546
- }
547
-
548
- /** Get cache stats for diagnostics. */
549
- export function getLoaderCacheStats() {
550
- return {
551
- entries: cache.size,
552
- inflight: inflightRequests.size,
553
- estimatedBytes: cache.estimatedBytes,
554
- maxBytes: maxCacheBytes,
555
- };
556
- }
package/src/sdk/clx.ts DELETED
@@ -1,5 +0,0 @@
1
- /** Filter out nullable values, join and minify class names */
2
- export const clx = (...args: (string | null | undefined | false)[]) =>
3
- args.filter(Boolean).join(" ").replace(/\s\s+/g, " ");
4
-
5
- export default clx;
package/src/sdk/cn.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * `cn(...inputs)` — the canonical Tailwind class-name combinator
3
- * (clsx + tailwind-merge). Every storefront we audited shipped a
4
- * site-local copy of this; we promote it to the framework so sites
5
- * can drop the duplicate.
6
- *
7
- * Behaviour:
8
- * - Accepts the full `clsx` input format (strings, objects, arrays,
9
- * conditionals, falsy values).
10
- * - De-duplicates conflicting Tailwind utilities via `tailwind-merge`
11
- * (e.g. `cn("p-2", "p-4")` → `"p-4"`).
12
- *
13
- * The simpler `clx` (no tailwind-merge, just `filter+join`) is still
14
- * exported from `@decocms/start/sdk/clx` for cases where you want to
15
- * keep the literal class string. Re-exported here so a single import
16
- * covers both.
17
- */
18
-
19
- import { clsx, type ClassValue } from "clsx";
20
- import { twMerge } from "tailwind-merge";
21
-
22
- export { clx } from "./clx";
23
-
24
- export function cn(...inputs: ClassValue[]): string {
25
- return twMerge(clsx(inputs));
26
- }
27
-
28
- export type { ClassValue };