@bleedingdev/modern-js-plugin-bff 3.5.0-ultramodern.3 → 3.5.0-ultramodern.31

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 (316) hide show
  1. package/dist/cjs/cli/compress.js +52 -0
  2. package/dist/cjs/cli/generator.js +149 -0
  3. package/dist/cjs/cli/prefix.js +50 -0
  4. package/dist/cjs/cli/watch.js +51 -0
  5. package/dist/cjs/cli.js +11 -130
  6. package/dist/cjs/runtime/data-platform/batch/queue.js +287 -0
  7. package/dist/cjs/runtime/data-platform/batch/request.js +98 -0
  8. package/dist/cjs/runtime/data-platform/batch/response.js +67 -0
  9. package/dist/cjs/runtime/data-platform/batch/telemetry.js +67 -0
  10. package/dist/cjs/runtime/data-platform/batch/url.js +69 -0
  11. package/dist/cjs/runtime/data-platform/batch-transport.js +59 -0
  12. package/dist/cjs/runtime/data-platform/codec.js +155 -0
  13. package/dist/cjs/runtime/data-platform/index.js +30 -633
  14. package/dist/cjs/runtime/data-platform/invalidation.js +61 -0
  15. package/dist/cjs/runtime/data-platform/trace.js +73 -0
  16. package/dist/cjs/runtime/data-platform/types.js +48 -0
  17. package/dist/cjs/runtime/data-platform/validation.js +178 -0
  18. package/dist/cjs/runtime/effect/adapter/constants.js +44 -0
  19. package/dist/cjs/runtime/effect/adapter/cross-project-policy.js +61 -0
  20. package/dist/cjs/runtime/effect/adapter/entry.js +77 -0
  21. package/dist/cjs/runtime/effect/adapter/error-response.js +79 -0
  22. package/dist/cjs/runtime/effect/adapter/handler.js +53 -0
  23. package/dist/cjs/runtime/effect/adapter.js +20 -154
  24. package/dist/cjs/runtime/effect/backend-federation/entry.js +99 -0
  25. package/dist/cjs/runtime/effect/backend-federation/load.js +57 -0
  26. package/dist/cjs/runtime/effect/backend-federation/plugin.js +53 -0
  27. package/dist/cjs/runtime/effect/backend-federation/remotes.js +50 -0
  28. package/dist/cjs/runtime/effect/backend-federation/runtime.js +64 -0
  29. package/dist/cjs/runtime/effect/backend-federation/types.js +18 -0
  30. package/dist/cjs/runtime/effect/backend-federation/utils.js +48 -0
  31. package/dist/cjs/runtime/effect/backend-federation-manifest/errors.js +83 -0
  32. package/dist/cjs/runtime/effect/backend-federation-manifest/index.js +55 -0
  33. package/dist/cjs/runtime/effect/backend-federation-manifest/load.js +74 -0
  34. package/dist/cjs/runtime/effect/backend-federation-manifest/metadata.js +101 -0
  35. package/dist/cjs/runtime/effect/backend-federation-manifest/reference.js +117 -0
  36. package/dist/cjs/runtime/effect/backend-federation-manifest/remote.js +68 -0
  37. package/dist/cjs/runtime/effect/backend-federation-manifest/types.js +18 -0
  38. package/dist/cjs/runtime/effect/backend-federation-manifest/validation.js +108 -0
  39. package/dist/cjs/runtime/effect/backend-federation-manifest.js +62 -0
  40. package/dist/cjs/runtime/effect/backend-federation.js +61 -0
  41. package/dist/cjs/runtime/effect/dispatch.js +116 -0
  42. package/dist/cjs/runtime/effect/edge.js +58 -69
  43. package/dist/cjs/runtime/effect/endpoint-contracts.js +7 -12
  44. package/dist/cjs/runtime/effect/entry-shape.js +87 -0
  45. package/dist/cjs/runtime/effect/handler/batch-handler.js +161 -0
  46. package/dist/cjs/runtime/effect/handler/batch.js +195 -0
  47. package/dist/cjs/runtime/effect/handler/definition.js +101 -0
  48. package/dist/cjs/runtime/effect/handler/envelope.js +104 -0
  49. package/dist/cjs/runtime/effect/handler/http.js +96 -0
  50. package/dist/cjs/runtime/effect/handler/openapi.js +57 -0
  51. package/dist/cjs/runtime/effect/handler/routing.js +100 -0
  52. package/dist/cjs/runtime/effect/handler/rpc.js +63 -0
  53. package/dist/cjs/runtime/effect/handler/types.js +43 -0
  54. package/dist/cjs/runtime/effect/handler.js +37 -529
  55. package/dist/cjs/runtime/effect/index.js +91 -15
  56. package/dist/cjs/runtime/effect/module.js +23 -80
  57. package/dist/cjs/runtime/effect/rpcSerialization.js +54 -0
  58. package/dist/cjs/runtime/effect-client/batch.js +73 -0
  59. package/dist/cjs/runtime/effect-client/envelope.js +145 -0
  60. package/dist/cjs/runtime/effect-client/guards.js +44 -0
  61. package/dist/cjs/runtime/effect-client/index.js +6 -16
  62. package/dist/cjs/runtime/effect-client/request-context.js +64 -0
  63. package/dist/cjs/runtime/effect-client/request.js +66 -0
  64. package/dist/cjs/runtime/effect-client/runtime.js +12 -178
  65. package/dist/cjs/runtime/effect-client/types.js +18 -0
  66. package/dist/cjs/runtime/safe-failure.js +2 -1
  67. package/dist/cjs/utils/client-generator/files.js +152 -0
  68. package/dist/cjs/utils/client-generator/generate.js +138 -0
  69. package/dist/cjs/utils/client-generator/index.js +83 -0
  70. package/dist/cjs/utils/client-generator/package-json.js +132 -0
  71. package/dist/cjs/utils/client-generator/write-package.js +125 -0
  72. package/dist/cjs/utils/clientGenerator.js +26 -303
  73. package/dist/cjs/utils/effect-client-generator/generator.js +64 -0
  74. package/dist/cjs/utils/effect-client-generator/index.js +51 -0
  75. package/dist/cjs/utils/effect-client-generator/paths.js +73 -0
  76. package/dist/cjs/utils/effect-client-generator/rendering.js +231 -0
  77. package/dist/cjs/utils/effect-client-generator/runtime.js +84 -0
  78. package/dist/cjs/utils/effect-client-generator/types.js +18 -0
  79. package/dist/cjs/utils/effectClientGenerator.js +5 -262
  80. package/dist/esm/cli/compress.mjs +14 -0
  81. package/dist/esm/cli/generator.mjs +98 -0
  82. package/dist/esm/cli/prefix.mjs +9 -0
  83. package/dist/esm/cli/watch.mjs +13 -0
  84. package/dist/esm/cli.mjs +7 -121
  85. package/dist/esm/runtime/data-platform/batch/queue.mjs +246 -0
  86. package/dist/esm/runtime/data-platform/batch/request.mjs +45 -0
  87. package/dist/esm/runtime/data-platform/batch/response.mjs +23 -0
  88. package/dist/esm/runtime/data-platform/batch/telemetry.mjs +23 -0
  89. package/dist/esm/runtime/data-platform/batch/url.mjs +25 -0
  90. package/dist/esm/runtime/data-platform/batch-transport.mjs +12 -0
  91. package/dist/esm/runtime/data-platform/codec.mjs +90 -0
  92. package/dist/esm/runtime/data-platform/index.mjs +6 -610
  93. package/dist/esm/runtime/data-platform/invalidation.mjs +20 -0
  94. package/dist/esm/runtime/data-platform/trace.mjs +29 -0
  95. package/dist/esm/runtime/data-platform/types.mjs +4 -0
  96. package/dist/esm/runtime/data-platform/validation.mjs +128 -0
  97. package/dist/esm/runtime/effect/adapter/constants.mjs +6 -0
  98. package/dist/esm/runtime/effect/adapter/cross-project-policy.mjs +23 -0
  99. package/dist/esm/runtime/effect/adapter/entry.mjs +29 -0
  100. package/dist/esm/runtime/effect/adapter/error-response.mjs +41 -0
  101. package/dist/esm/runtime/effect/adapter/handler.mjs +15 -0
  102. package/dist/esm/runtime/effect/adapter.mjs +21 -145
  103. package/dist/esm/runtime/effect/backend-federation/entry.mjs +61 -0
  104. package/dist/esm/runtime/effect/backend-federation/load.mjs +19 -0
  105. package/dist/esm/runtime/effect/backend-federation/plugin.mjs +15 -0
  106. package/dist/esm/runtime/effect/backend-federation/remotes.mjs +12 -0
  107. package/dist/esm/runtime/effect/backend-federation/runtime.mjs +26 -0
  108. package/dist/esm/runtime/effect/backend-federation/types.mjs +0 -0
  109. package/dist/esm/runtime/effect/backend-federation/utils.mjs +7 -0
  110. package/dist/esm/runtime/effect/backend-federation-manifest/errors.mjs +32 -0
  111. package/dist/esm/runtime/effect/backend-federation-manifest/index.mjs +4 -0
  112. package/dist/esm/runtime/effect/backend-federation-manifest/load.mjs +36 -0
  113. package/dist/esm/runtime/effect/backend-federation-manifest/metadata.mjs +42 -0
  114. package/dist/esm/runtime/effect/backend-federation-manifest/reference.mjs +76 -0
  115. package/dist/esm/runtime/effect/backend-federation-manifest/remote.mjs +30 -0
  116. package/dist/esm/runtime/effect/backend-federation-manifest/types.mjs +0 -0
  117. package/dist/esm/runtime/effect/backend-federation-manifest/validation.mjs +64 -0
  118. package/dist/esm/runtime/effect/backend-federation-manifest.mjs +1 -0
  119. package/dist/esm/runtime/effect/backend-federation.mjs +4 -0
  120. package/dist/esm/runtime/effect/dispatch.mjs +63 -0
  121. package/dist/esm/runtime/effect/edge.mjs +17 -63
  122. package/dist/esm/runtime/effect/endpoint-contracts.mjs +7 -12
  123. package/dist/esm/runtime/effect/entry-shape.mjs +36 -0
  124. package/dist/esm/runtime/effect/handler/batch-handler.mjs +123 -0
  125. package/dist/esm/runtime/effect/handler/batch.mjs +124 -0
  126. package/dist/esm/runtime/effect/handler/definition.mjs +60 -0
  127. package/dist/esm/runtime/effect/handler/envelope.mjs +63 -0
  128. package/dist/esm/runtime/effect/handler/http.mjs +58 -0
  129. package/dist/esm/runtime/effect/handler/openapi.mjs +19 -0
  130. package/dist/esm/runtime/effect/handler/routing.mjs +50 -0
  131. package/dist/esm/runtime/effect/handler/rpc.mjs +22 -0
  132. package/dist/esm/runtime/effect/handler/types.mjs +5 -0
  133. package/dist/esm/runtime/effect/handler.mjs +7 -502
  134. package/dist/esm/runtime/effect/index.mjs +3 -0
  135. package/dist/esm/runtime/effect/module.mjs +23 -80
  136. package/dist/esm/runtime/effect/rpcSerialization.mjs +16 -0
  137. package/dist/esm/runtime/effect-client/batch.mjs +35 -0
  138. package/dist/esm/runtime/effect-client/envelope.mjs +104 -0
  139. package/dist/esm/runtime/effect-client/guards.mjs +3 -0
  140. package/dist/esm/runtime/effect-client/index.mjs +5 -15
  141. package/dist/esm/runtime/effect-client/request-context.mjs +23 -0
  142. package/dist/esm/runtime/effect-client/request.mjs +28 -0
  143. package/dist/esm/runtime/effect-client/runtime.mjs +12 -178
  144. package/dist/esm/runtime/effect-client/types.mjs +0 -0
  145. package/dist/esm/runtime/safe-failure.mjs +2 -1
  146. package/dist/esm/utils/client-generator/files.mjs +68 -0
  147. package/dist/esm/utils/client-generator/generate.mjs +88 -0
  148. package/dist/esm/utils/client-generator/index.mjs +4 -0
  149. package/dist/esm/utils/client-generator/package-json.mjs +78 -0
  150. package/dist/esm/utils/client-generator/write-package.mjs +74 -0
  151. package/dist/esm/utils/clientGenerator.mjs +2 -293
  152. package/dist/esm/utils/effect-client-generator/generator.mjs +23 -0
  153. package/dist/esm/utils/effect-client-generator/index.mjs +3 -0
  154. package/dist/esm/utils/effect-client-generator/paths.mjs +25 -0
  155. package/dist/esm/utils/effect-client-generator/rendering.mjs +180 -0
  156. package/dist/esm/utils/effect-client-generator/runtime.mjs +33 -0
  157. package/dist/esm/utils/effect-client-generator/types.mjs +0 -0
  158. package/dist/esm/utils/effectClientGenerator.mjs +1 -249
  159. package/dist/esm-node/cli/compress.mjs +15 -0
  160. package/dist/esm-node/cli/generator.mjs +99 -0
  161. package/dist/esm-node/cli/prefix.mjs +10 -0
  162. package/dist/esm-node/cli/watch.mjs +14 -0
  163. package/dist/esm-node/cli.mjs +7 -121
  164. package/dist/esm-node/runtime/data-platform/batch/queue.mjs +247 -0
  165. package/dist/esm-node/runtime/data-platform/batch/request.mjs +46 -0
  166. package/dist/esm-node/runtime/data-platform/batch/response.mjs +24 -0
  167. package/dist/esm-node/runtime/data-platform/batch/telemetry.mjs +24 -0
  168. package/dist/esm-node/runtime/data-platform/batch/url.mjs +26 -0
  169. package/dist/esm-node/runtime/data-platform/batch-transport.mjs +13 -0
  170. package/dist/esm-node/runtime/data-platform/codec.mjs +91 -0
  171. package/dist/esm-node/runtime/data-platform/index.mjs +6 -610
  172. package/dist/esm-node/runtime/data-platform/invalidation.mjs +21 -0
  173. package/dist/esm-node/runtime/data-platform/trace.mjs +30 -0
  174. package/dist/esm-node/runtime/data-platform/types.mjs +5 -0
  175. package/dist/esm-node/runtime/data-platform/validation.mjs +129 -0
  176. package/dist/esm-node/runtime/effect/adapter/constants.mjs +7 -0
  177. package/dist/esm-node/runtime/effect/adapter/cross-project-policy.mjs +24 -0
  178. package/dist/esm-node/runtime/effect/adapter/entry.mjs +30 -0
  179. package/dist/esm-node/runtime/effect/adapter/error-response.mjs +42 -0
  180. package/dist/esm-node/runtime/effect/adapter/handler.mjs +16 -0
  181. package/dist/esm-node/runtime/effect/adapter.mjs +21 -145
  182. package/dist/esm-node/runtime/effect/backend-federation/entry.mjs +62 -0
  183. package/dist/esm-node/runtime/effect/backend-federation/load.mjs +20 -0
  184. package/dist/esm-node/runtime/effect/backend-federation/plugin.mjs +16 -0
  185. package/dist/esm-node/runtime/effect/backend-federation/remotes.mjs +13 -0
  186. package/dist/esm-node/runtime/effect/backend-federation/runtime.mjs +27 -0
  187. package/dist/esm-node/runtime/effect/backend-federation/types.mjs +1 -0
  188. package/dist/esm-node/runtime/effect/backend-federation/utils.mjs +8 -0
  189. package/dist/esm-node/runtime/effect/backend-federation-manifest/errors.mjs +33 -0
  190. package/dist/esm-node/runtime/effect/backend-federation-manifest/index.mjs +5 -0
  191. package/dist/esm-node/runtime/effect/backend-federation-manifest/load.mjs +37 -0
  192. package/dist/esm-node/runtime/effect/backend-federation-manifest/metadata.mjs +43 -0
  193. package/dist/esm-node/runtime/effect/backend-federation-manifest/reference.mjs +77 -0
  194. package/dist/esm-node/runtime/effect/backend-federation-manifest/remote.mjs +31 -0
  195. package/dist/esm-node/runtime/effect/backend-federation-manifest/types.mjs +1 -0
  196. package/dist/esm-node/runtime/effect/backend-federation-manifest/validation.mjs +65 -0
  197. package/dist/esm-node/runtime/effect/backend-federation-manifest.mjs +2 -0
  198. package/dist/esm-node/runtime/effect/backend-federation.mjs +5 -0
  199. package/dist/esm-node/runtime/effect/dispatch.mjs +64 -0
  200. package/dist/esm-node/runtime/effect/edge.mjs +17 -63
  201. package/dist/esm-node/runtime/effect/endpoint-contracts.mjs +7 -12
  202. package/dist/esm-node/runtime/effect/entry-shape.mjs +37 -0
  203. package/dist/esm-node/runtime/effect/handler/batch-handler.mjs +124 -0
  204. package/dist/esm-node/runtime/effect/handler/batch.mjs +125 -0
  205. package/dist/esm-node/runtime/effect/handler/definition.mjs +61 -0
  206. package/dist/esm-node/runtime/effect/handler/envelope.mjs +64 -0
  207. package/dist/esm-node/runtime/effect/handler/http.mjs +59 -0
  208. package/dist/esm-node/runtime/effect/handler/openapi.mjs +20 -0
  209. package/dist/esm-node/runtime/effect/handler/routing.mjs +51 -0
  210. package/dist/esm-node/runtime/effect/handler/rpc.mjs +23 -0
  211. package/dist/esm-node/runtime/effect/handler/types.mjs +6 -0
  212. package/dist/esm-node/runtime/effect/handler.mjs +7 -502
  213. package/dist/esm-node/runtime/effect/index.mjs +3 -0
  214. package/dist/esm-node/runtime/effect/module.mjs +23 -80
  215. package/dist/esm-node/runtime/effect/rpcSerialization.mjs +17 -0
  216. package/dist/esm-node/runtime/effect-client/batch.mjs +36 -0
  217. package/dist/esm-node/runtime/effect-client/envelope.mjs +105 -0
  218. package/dist/esm-node/runtime/effect-client/guards.mjs +4 -0
  219. package/dist/esm-node/runtime/effect-client/index.mjs +5 -15
  220. package/dist/esm-node/runtime/effect-client/request-context.mjs +24 -0
  221. package/dist/esm-node/runtime/effect-client/request.mjs +29 -0
  222. package/dist/esm-node/runtime/effect-client/runtime.mjs +12 -178
  223. package/dist/esm-node/runtime/effect-client/types.mjs +1 -0
  224. package/dist/esm-node/runtime/safe-failure.mjs +2 -1
  225. package/dist/esm-node/utils/client-generator/files.mjs +69 -0
  226. package/dist/esm-node/utils/client-generator/generate.mjs +89 -0
  227. package/dist/esm-node/utils/client-generator/index.mjs +5 -0
  228. package/dist/esm-node/utils/client-generator/package-json.mjs +79 -0
  229. package/dist/esm-node/utils/client-generator/write-package.mjs +75 -0
  230. package/dist/esm-node/utils/clientGenerator.mjs +2 -293
  231. package/dist/esm-node/utils/effect-client-generator/generator.mjs +24 -0
  232. package/dist/esm-node/utils/effect-client-generator/index.mjs +4 -0
  233. package/dist/esm-node/utils/effect-client-generator/paths.mjs +26 -0
  234. package/dist/esm-node/utils/effect-client-generator/rendering.mjs +181 -0
  235. package/dist/esm-node/utils/effect-client-generator/runtime.mjs +35 -0
  236. package/dist/esm-node/utils/effect-client-generator/types.mjs +1 -0
  237. package/dist/esm-node/utils/effectClientGenerator.mjs +2 -251
  238. package/dist/types/cli/compress.d.ts +2 -0
  239. package/dist/types/cli/generator.d.ts +7 -0
  240. package/dist/types/cli/prefix.d.ts +2 -0
  241. package/dist/types/cli/watch.d.ts +1 -0
  242. package/dist/types/cli.d.ts +0 -1
  243. package/dist/types/runtime/data-platform/batch/queue.d.ts +25 -0
  244. package/dist/types/runtime/data-platform/batch/request.d.ts +13 -0
  245. package/dist/types/runtime/data-platform/batch/response.d.ts +4 -0
  246. package/dist/types/runtime/data-platform/batch/telemetry.d.ts +4 -0
  247. package/dist/types/runtime/data-platform/batch/url.d.ts +4 -0
  248. package/dist/types/runtime/data-platform/batch-transport.d.ts +3 -0
  249. package/dist/types/runtime/data-platform/codec.d.ts +17 -0
  250. package/dist/types/runtime/data-platform/index.d.ts +7 -191
  251. package/dist/types/runtime/data-platform/invalidation.d.ts +8 -0
  252. package/dist/types/runtime/data-platform/trace.d.ts +4 -0
  253. package/dist/types/runtime/data-platform/types.d.ts +146 -0
  254. package/dist/types/runtime/data-platform/validation.d.ts +29 -0
  255. package/dist/types/runtime/effect/adapter/constants.d.ts +1 -0
  256. package/dist/types/runtime/effect/adapter/cross-project-policy.d.ts +4 -0
  257. package/dist/types/runtime/effect/adapter/entry.d.ts +2 -0
  258. package/dist/types/runtime/effect/adapter/error-response.d.ts +2 -0
  259. package/dist/types/runtime/effect/adapter/handler.d.ts +4 -0
  260. package/dist/types/runtime/effect/adapter.d.ts +4 -13
  261. package/dist/types/runtime/effect/backend-federation/entry.d.ts +2 -0
  262. package/dist/types/runtime/effect/backend-federation/load.d.ts +2 -0
  263. package/dist/types/runtime/effect/backend-federation/plugin.d.ts +3 -0
  264. package/dist/types/runtime/effect/backend-federation/remotes.d.ts +2 -0
  265. package/dist/types/runtime/effect/backend-federation/runtime.d.ts +3 -0
  266. package/dist/types/runtime/effect/backend-federation/types.d.ts +58 -0
  267. package/dist/types/runtime/effect/backend-federation/utils.d.ts +2 -0
  268. package/dist/types/runtime/effect/backend-federation-manifest/errors.d.ts +11 -0
  269. package/dist/types/runtime/effect/backend-federation-manifest/index.d.ts +6 -0
  270. package/dist/types/runtime/effect/backend-federation-manifest/load.d.ts +3 -0
  271. package/dist/types/runtime/effect/backend-federation-manifest/metadata.d.ts +18 -0
  272. package/dist/types/runtime/effect/backend-federation-manifest/reference.d.ts +3 -0
  273. package/dist/types/runtime/effect/backend-federation-manifest/remote.d.ts +3 -0
  274. package/dist/types/runtime/effect/backend-federation-manifest/types.d.ts +51 -0
  275. package/dist/types/runtime/effect/backend-federation-manifest/validation.d.ts +5 -0
  276. package/dist/types/runtime/effect/backend-federation-manifest.d.ts +1 -0
  277. package/dist/types/runtime/effect/backend-federation.d.ts +6 -0
  278. package/dist/types/runtime/effect/dispatch.d.ts +17 -0
  279. package/dist/types/runtime/effect/edge.d.ts +9 -8
  280. package/dist/types/runtime/effect/endpoint-contracts.d.ts +2 -2
  281. package/dist/types/runtime/effect/entry-shape.d.ts +31 -0
  282. package/dist/types/runtime/effect/handler/batch-handler.d.ts +11 -0
  283. package/dist/types/runtime/effect/handler/batch.d.ts +17 -0
  284. package/dist/types/runtime/effect/handler/definition.d.ts +17 -0
  285. package/dist/types/runtime/effect/handler/envelope.d.ts +13 -0
  286. package/dist/types/runtime/effect/handler/http.d.ts +14 -0
  287. package/dist/types/runtime/effect/handler/openapi.d.ts +4 -0
  288. package/dist/types/runtime/effect/handler/routing.d.ts +5 -0
  289. package/dist/types/runtime/effect/handler/rpc.d.ts +7 -0
  290. package/dist/types/runtime/effect/handler/types.d.ts +148 -0
  291. package/dist/types/runtime/effect/handler.d.ts +4 -190
  292. package/dist/types/runtime/effect/index.d.ts +3 -0
  293. package/dist/types/runtime/effect/rpcSerialization.d.ts +3 -0
  294. package/dist/types/runtime/effect-client/batch.d.ts +2 -0
  295. package/dist/types/runtime/effect-client/envelope.d.ts +15 -0
  296. package/dist/types/runtime/effect-client/guards.d.ts +2 -0
  297. package/dist/types/runtime/effect-client/index.d.ts +1 -1
  298. package/dist/types/runtime/effect-client/request-context.d.ts +3 -0
  299. package/dist/types/runtime/effect-client/request.d.ts +1 -0
  300. package/dist/types/runtime/effect-client/runtime.d.ts +2 -68
  301. package/dist/types/runtime/effect-client/types.d.ts +68 -0
  302. package/dist/types/utils/client-generator/files.d.ts +28 -0
  303. package/dist/types/utils/client-generator/generate.d.ts +26 -0
  304. package/dist/types/utils/client-generator/index.d.ts +7 -0
  305. package/dist/types/utils/client-generator/package-json.d.ts +16 -0
  306. package/dist/types/utils/client-generator/write-package.d.ts +6 -0
  307. package/dist/types/utils/clientGenerator.d.ts +2 -37
  308. package/dist/types/utils/crossProjectServerPolicy.d.ts +3 -2
  309. package/dist/types/utils/effect-client-generator/generator.d.ts +10 -0
  310. package/dist/types/utils/effect-client-generator/index.d.ts +4 -0
  311. package/dist/types/utils/effect-client-generator/paths.d.ts +5 -0
  312. package/dist/types/utils/effect-client-generator/rendering.d.ts +4 -0
  313. package/dist/types/utils/effect-client-generator/runtime.d.ts +8 -0
  314. package/dist/types/utils/effect-client-generator/types.d.ts +26 -0
  315. package/dist/types/utils/effectClientGenerator.d.ts +2 -41
  316. package/package.json +26 -14
@@ -1,611 +1,7 @@
1
1
  import "node:module";
2
- import { parseTraceparent } from "@modern-js/create-request";
3
- import { trace as api_trace } from "@opentelemetry/api";
4
- const DATA_BATCH_TRANSPORT_OTEL_EVENT = 'modernjs.data.batch';
5
- function createDataBatchTransportTelemetryAttributes(event) {
6
- return {
7
- 'modernjs.data.batch.type': event.type,
8
- 'modernjs.data.batch.endpoint': event.endpoint,
9
- 'modernjs.data.batch.degraded': 'fallback' === event.type || 'disable' === event.type,
10
- ...event.batchId ? {
11
- 'modernjs.data.batch.id': event.batchId
12
- } : {},
13
- ...'number' == typeof event.size ? {
14
- 'modernjs.data.batch.size': event.size
15
- } : {},
16
- ...event.reason ? {
17
- 'modernjs.data.batch.reason': event.reason
18
- } : {}
19
- };
20
- }
21
- function emitDataBatchTransportEvent(onEvent, event) {
22
- onEvent?.(event);
23
- api_trace.getActiveSpan()?.addEvent(DATA_BATCH_TRANSPORT_OTEL_EVENT, createDataBatchTransportTelemetryAttributes(event));
24
- }
25
- const DEFAULT_DATA_ENVELOPE_HEADER = 'x-modernjs-data-envelope';
26
- const DEFAULT_DATA_BATCH_ENDPOINT = '/_data/batch';
27
- const DEFAULT_DATA_BATCH_HEADER = 'x-modernjs-data-batch';
28
- function isPlainObject(value) {
29
- if ('object' != typeof value || null === value || Array.isArray(value)) return false;
30
- const proto = Object.getPrototypeOf(value);
31
- return proto === Object.prototype || null === proto;
32
- }
33
- function canonicalize(value) {
34
- if (Array.isArray(value)) return value.map((item)=>canonicalize(item));
35
- if (isPlainObject(value)) return Object.keys(value).sort().reduce((acc, key)=>{
36
- acc[key] = canonicalize(value[key]);
37
- return acc;
38
- }, {});
39
- return value;
40
- }
41
- function stableStringify(value) {
42
- return JSON.stringify(canonicalize(value));
43
- }
44
- function encodeRequestEnvelopeHeader(envelope) {
45
- return encodeURIComponent(stableStringify(envelope));
46
- }
47
- function isRequestEnvelopeShape(value) {
48
- if (!isPlainObject(value)) return false;
49
- return 1 === value.protocolVersion && 'string' == typeof value.operationId && 'string' == typeof value.appNamespace && 'string' == typeof value.origin && 'string' == typeof value.scopeKey && 'string' == typeof value.inputHash && 'number' == typeof value.timestamp;
50
- }
51
- function decodeRequestEnvelopeHeader(value) {
52
- try {
53
- const decoded = decodeURIComponent(value);
54
- const parsed = JSON.parse(decoded);
55
- if (!isRequestEnvelopeShape(parsed)) return null;
56
- return parsed;
57
- } catch {
58
- return null;
59
- }
60
- }
61
- function hashString(value) {
62
- let hash = 0x811c9dc5;
63
- for(let index = 0; index < value.length; index++){
64
- hash ^= value.charCodeAt(index);
65
- hash = Math.imul(hash, 0x01000193);
66
- }
67
- return (hash >>> 0).toString(16).padStart(8, '0');
68
- }
69
- function sanitizeSegment(segment) {
70
- const normalized = segment.trim().replace(/[^a-zA-Z0-9_-]+/g, '_');
71
- return normalized.length > 0 ? normalized : 'unknown';
72
- }
73
- function normalizeOrigin(origin) {
74
- const normalized = origin.trim();
75
- try {
76
- const url = new URL(normalized);
77
- return `${url.protocol}//${url.host}`.toLowerCase();
78
- } catch {
79
- return normalized.toLowerCase();
80
- }
81
- }
82
- function normalizeOperationDescriptor(input) {
83
- return {
84
- appNamespace: sanitizeSegment(input.appNamespace),
85
- apiId: sanitizeSegment(input.apiId),
86
- group: sanitizeSegment(input.group),
87
- endpoint: sanitizeSegment(input.endpoint),
88
- schemaHash: input.schemaHash || null,
89
- version: input.version ?? 1
90
- };
91
- }
92
- function createOperationId(input) {
93
- const descriptor = normalizeOperationDescriptor(input);
94
- const readable = `${descriptor.appNamespace}.${descriptor.apiId}.${descriptor.group}.${descriptor.endpoint}.v${String(descriptor.version)}`;
95
- return `${readable}:${hashString(stableStringify(descriptor))}`;
96
- }
97
- function buildScopeKey(scope) {
98
- const canonical = {
99
- appNamespace: sanitizeSegment(scope.appNamespace),
100
- origin: normalizeOrigin(scope.origin),
101
- tenantId: scope.tenantId ?? null,
102
- userId: scope.userId ?? null,
103
- sessionId: scope.sessionId ?? null
104
- };
105
- return `${canonical.appNamespace}:${hashString(stableStringify(canonical))}`;
106
- }
107
- function buildQueryKey(input) {
108
- const canonical = {
109
- operationId: input.operationId,
110
- scopeKey: input.scopeKey,
111
- requestMode: input.requestMode ?? 'cache-first',
112
- requestInput: input.requestInput ?? null,
113
- selectionPlan: input.selectionPlan ?? null
114
- };
115
- return `${input.operationId}:${hashString(stableStringify(canonical))}`;
116
- }
117
- function isAllZeroHex(value) {
118
- return /^0+$/.test(value);
119
- }
120
- function isValidHex(value, length) {
121
- return value.length === length && /^[0-9a-f]+$/.test(value);
122
- }
123
- function parseTraceparentHeader(header) {
124
- return parseTraceparent(header) ?? null;
125
- }
126
- function formatTraceparentHeader(trace) {
127
- const traceId = trace.traceId.toLowerCase();
128
- const spanId = trace.spanId.toLowerCase();
129
- if (!isValidHex(traceId, 32) || !isValidHex(spanId, 16)) throw new Error('Invalid trace context: traceId/spanId format mismatch');
130
- if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) throw new Error('Invalid trace context: traceId/spanId cannot be zero');
131
- const flags = trace.sampled ? '01' : '00';
132
- return `00-${traceId}-${spanId}-${flags}`;
133
- }
134
- function deriveChildTraceContext(parent, childSpanId) {
135
- const normalizedSpanId = childSpanId.toLowerCase();
136
- if (!isValidHex(normalizedSpanId, 16) || isAllZeroHex(normalizedSpanId)) throw new Error('Invalid child span id');
137
- return {
138
- traceId: parent.traceId.toLowerCase(),
139
- spanId: normalizedSpanId,
140
- sampled: parent.sampled,
141
- parentSpanId: parent.spanId.toLowerCase()
142
- };
143
- }
144
- function validateSelectionPlan(plan, options = {}) {
145
- const maxDepthLimit = options.maxDepth ?? 8;
146
- const maxFieldsLimit = options.maxFields ?? 256;
147
- const allowedLeafPaths = options.allowedLeafPaths ? new Set(options.allowedLeafPaths) : null;
148
- const errors = [];
149
- let maxDepth = 0;
150
- let fieldCount = 0;
151
- const walk = (node, path)=>{
152
- if (!isPlainObject(node)) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" must be an object`);
153
- const keys = Object.keys(node);
154
- if (0 === keys.length) return void errors.push(`Selection node at "${path.join('.') || '<root>'}" cannot be empty`);
155
- for (const key of keys){
156
- fieldCount += 1;
157
- if (fieldCount > maxFieldsLimit) return void errors.push(`Selection has too many fields: ${String(fieldCount)} > ${String(maxFieldsLimit)}`);
158
- const nextPath = [
159
- ...path,
160
- key
161
- ];
162
- const depth = nextPath.length;
163
- if (depth > maxDepth) maxDepth = depth;
164
- if (depth > maxDepthLimit) return void errors.push(`Selection exceeds maxDepth at "${nextPath.join('.')}" (${String(depth)} > ${String(maxDepthLimit)})`);
165
- const value = node[key];
166
- if (true === value) {
167
- if (allowedLeafPaths && !allowedLeafPaths.has(nextPath.join('.'))) errors.push(`Unknown selected field "${nextPath.join('.')}"`);
168
- continue;
169
- }
170
- if (!isPlainObject(value)) {
171
- errors.push(`Invalid selection value at "${nextPath.join('.')}"; expected true or nested object`);
172
- continue;
173
- }
174
- walk(value, nextPath);
175
- }
176
- };
177
- walk(plan, []);
178
- return {
179
- ok: 0 === errors.length,
180
- errors,
181
- stats: {
182
- maxDepth,
183
- fieldCount
184
- }
185
- };
186
- }
187
- function createRequestEnvelope(input) {
188
- if (input.requireTraceContext && !input.traceContext) throw new Error('Trace context is required for this request envelope');
189
- const traceparent = input.traceContext ? formatTraceparentHeader(input.traceContext) : void 0;
190
- const envelope = {
191
- protocolVersion: input.protocolVersion ?? 1,
192
- operationId: createOperationId(input.operation),
193
- appNamespace: sanitizeSegment(input.scope.appNamespace),
194
- origin: normalizeOrigin(input.scope.origin),
195
- requestMode: input.requestMode ?? 'cache-first',
196
- mutationMode: input.mutationMode,
197
- scopeKey: buildScopeKey(input.scope),
198
- input: input.requestInput,
199
- inputHash: hashString(stableStringify(input.requestInput ?? null)),
200
- selectionPlan: input.selectionPlan,
201
- selectionHash: input.selectionPlan ? hashString(stableStringify(input.selectionPlan)) : void 0,
202
- traceparent,
203
- timestamp: input.timestamp ?? Date.now()
204
- };
205
- return envelope;
206
- }
207
- function validateRequestEnvelope(envelope, options = {}) {
208
- const errors = [];
209
- if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
210
- if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
211
- if (options.expectedOrigin) {
212
- const expectedOrigin = normalizeOrigin(options.expectedOrigin);
213
- if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
214
- }
215
- if (!envelope.operationId) errors.push('Missing operationId');
216
- if (!envelope.scopeKey) errors.push('Missing scopeKey');
217
- if (options.requireTraceContext && !envelope.traceparent) errors.push('Missing trace context');
218
- if (envelope.traceparent && !parseTraceparentHeader(envelope.traceparent)) errors.push('Invalid traceparent header');
219
- const computedInputHash = hashString(stableStringify(envelope.input ?? null));
220
- if (computedInputHash !== envelope.inputHash) errors.push('Input hash mismatch');
221
- if (envelope.selectionPlan) {
222
- const computedSelectionHash = hashString(stableStringify(envelope.selectionPlan));
223
- if (computedSelectionHash !== envelope.selectionHash) errors.push('Selection hash mismatch');
224
- }
225
- return {
226
- ok: 0 === errors.length,
227
- errors
228
- };
229
- }
230
- function createHydrationEnvelope(input) {
231
- const envelopeWithoutChecksum = {
232
- protocolVersion: input.protocolVersion ?? 1,
233
- runtimeVersion: input.runtimeVersion,
234
- appNamespace: sanitizeSegment(input.scope.appNamespace),
235
- origin: normalizeOrigin(input.scope.origin),
236
- createdAt: input.createdAt ?? Date.now(),
237
- payload: input.payload
238
- };
239
- const checksum = hashString(stableStringify(envelopeWithoutChecksum));
240
- return {
241
- ...envelopeWithoutChecksum,
242
- checksum
243
- };
244
- }
245
- function validateHydrationEnvelope(envelope, options = {}) {
246
- const errors = [];
247
- if (void 0 !== options.expectedProtocolVersion && envelope.protocolVersion !== options.expectedProtocolVersion) errors.push(`Protocol mismatch: expected ${String(options.expectedProtocolVersion)} but received ${String(envelope.protocolVersion)}`);
248
- if (options.expectedNamespace && envelope.appNamespace !== options.expectedNamespace) errors.push(`Namespace mismatch: expected ${options.expectedNamespace} but received ${envelope.appNamespace}`);
249
- if (options.expectedOrigin) {
250
- const expectedOrigin = normalizeOrigin(options.expectedOrigin);
251
- if (envelope.origin !== expectedOrigin) errors.push(`Origin mismatch: expected ${expectedOrigin} but received ${envelope.origin}`);
252
- }
253
- if (options.expectedRuntimeVersion && envelope.runtimeVersion !== options.expectedRuntimeVersion) errors.push(`Runtime version mismatch: expected ${options.expectedRuntimeVersion} but received ${envelope.runtimeVersion}`);
254
- const checksumBase = {
255
- protocolVersion: envelope.protocolVersion,
256
- runtimeVersion: envelope.runtimeVersion,
257
- appNamespace: envelope.appNamespace,
258
- origin: envelope.origin,
259
- createdAt: envelope.createdAt,
260
- payload: envelope.payload
261
- };
262
- const checksum = hashString(stableStringify(checksumBase));
263
- if (checksum !== envelope.checksum) errors.push('Hydration checksum mismatch');
264
- return {
265
- ok: 0 === errors.length,
266
- errors
267
- };
268
- }
269
- function createInvalidationEvent(input) {
270
- return {
271
- sourceNamespace: sanitizeSegment(input.sourceOperation.appNamespace),
272
- sourceOperationId: createOperationId(input.sourceOperation),
273
- scopeKey: buildScopeKey(input.sourceScope),
274
- targetNamespaces: input.targetNamespaces?.map((namespace)=>sanitizeSegment(namespace)),
275
- targetOperationIds: input.targetOperations?.map((operation)=>createOperationId(operation))
276
- };
277
- }
278
- function shouldApplyInvalidation(event, subscriber) {
279
- if (subscriber.scopeKey && subscriber.scopeKey !== event.scopeKey) return false;
280
- const sameNamespace = subscriber.namespace === event.sourceNamespace;
281
- const allowedCrossNamespace = true === subscriber.acceptCrossNamespace && event.targetNamespaces?.includes(subscriber.namespace) === true;
282
- if (!sameNamespace && !allowedCrossNamespace) return false;
283
- if (!subscriber.operationIds || 0 === subscriber.operationIds.length) return true;
284
- if (!event.targetOperationIds || 0 === event.targetOperationIds.length) return true;
285
- return subscriber.operationIds.some((operationId)=>event.targetOperationIds?.includes(operationId));
286
- }
287
- function resolveRuntimeOrigin() {
288
- if ("u" > typeof window && window.location && 'string' == typeof window.location.origin && window.location.origin) return window.location.origin;
289
- if ("u" > typeof globalThis && globalThis.location && 'string' == typeof globalThis.location?.origin) return globalThis.location.origin;
290
- return 'http://localhost';
291
- }
292
- function toAbsoluteUrl(input) {
293
- if (input instanceof URL) return input;
294
- if ("u" > typeof Request && input instanceof Request) return new URL(input.url);
295
- const value = String(input);
296
- try {
297
- return new URL(value);
298
- } catch {
299
- return new URL(value, resolveRuntimeOrigin());
300
- }
301
- }
302
- function normalizeBatchEndpoint(requestUrl, endpoint) {
303
- const value = endpoint || DEFAULT_DATA_BATCH_ENDPOINT;
304
- try {
305
- return new URL(value);
306
- } catch {
307
- return new URL(value, requestUrl.origin);
308
- }
309
- }
310
- function toHeaderRecord(headers) {
311
- if (!headers) return {};
312
- if (headers instanceof Headers) {
313
- const next = {};
314
- headers.forEach((value, key)=>{
315
- next[key.toLowerCase()] = value;
316
- });
317
- return next;
318
- }
319
- if (Array.isArray(headers)) return headers.reduce((acc, [key, value])=>{
320
- acc[String(key).toLowerCase()] = String(value);
321
- return acc;
322
- }, {});
323
- return Object.entries(headers).reduce((acc, [key, value])=>{
324
- if (void 0 === value) return acc;
325
- acc[String(key).toLowerCase()] = Array.isArray(value) ? value.join(', ') : String(value);
326
- return acc;
327
- }, {});
328
- }
329
- function isBatchResponseItem(value) {
330
- return isPlainObject(value) && 'string' == typeof value.id && 'number' == typeof value.status;
331
- }
332
- function isBatchResponsePayload(value) {
333
- return isPlainObject(value) && 1 === value.protocolVersion && 'string' == typeof value.batchId && 'number' == typeof value.receivedAt && Array.isArray(value.items) && value.items.every((item)=>isBatchResponseItem(item));
334
- }
335
- function measureTextBytes(value) {
336
- if ("u" > typeof TextEncoder) return new TextEncoder().encode(value).length;
337
- if ("u" > typeof Buffer) return Buffer.byteLength(value);
338
- return value.length;
339
- }
340
- function createBatchId() {
341
- const now = Date.now().toString(36);
342
- const random = Math.random().toString(16).slice(2, 10);
343
- return `batch_${now}_${random}`;
344
- }
345
- function normalizeMethod(method) {
346
- return (method || 'GET').toUpperCase();
347
- }
348
- function toRequestBody(initBody) {
349
- if ('string' == typeof initBody) return initBody;
350
- if ("u" > typeof URLSearchParams && initBody instanceof URLSearchParams) return initBody.toString();
351
- }
352
- function shouldBatchRequest(input) {
353
- if (input.requestUrl.href === input.batchEndpoint) return false;
354
- if ('off' === input.headers[DEFAULT_DATA_BATCH_HEADER]) return false;
355
- if (!input.allowedMethods.has(input.method)) return false;
356
- if (void 0 !== input.body) return false;
357
- return true;
358
- }
359
- async function parseResponseLikeCreateRequest(response) {
360
- const contentType = response.headers.get('content-type') || '';
361
- if (!response.ok) {
362
- let data = null;
363
- data = contentType.includes('application/json') ? await response.json() : await response.text();
364
- response.data = data;
365
- throw response;
366
- }
367
- if (contentType.includes('application/json') || contentType.includes('text/json')) return response.json();
368
- if (contentType.includes('text/html') || contentType.includes('text/plain')) return response.text();
369
- if (contentType.includes('application/x-www-form-urlencoded') || contentType.includes('multipart/form-data')) return response.formData();
370
- if (contentType.includes('application/octet-stream')) return response.arrayBuffer();
371
- if (contentType.includes('image/png')) return response;
372
- return response.text();
373
- }
374
- function ensureBucket(buckets, endpoint) {
375
- const existing = buckets.get(endpoint);
376
- if (existing) return existing;
377
- const next = {
378
- items: [],
379
- bytes: 0,
380
- timer: null,
381
- flushing: false
382
- };
383
- buckets.set(endpoint, next);
384
- return next;
385
- }
386
- function createDataBatchTransport(options = {}) {
387
- const fallbackFetch = 'function' == typeof fetch ? fetch.bind(globalThis) : void 0;
388
- const baseFetch = options.fetch || fallbackFetch;
389
- if (!baseFetch) throw new Error('createDataBatchTransport requires a fetch implementation');
390
- const flushIntervalMs = Math.max(0, options.flushIntervalMs ?? 8);
391
- const maxBatchSize = Math.max(1, options.maxBatchSize ?? 16);
392
- const maxBatchBytes = Math.max(1024, options.maxBatchBytes ?? 65536);
393
- const requestTimeoutMs = options.requestTimeoutMs;
394
- const allowedMethods = new Set((options.allowedMethods && options.allowedMethods.length > 0 ? options.allowedMethods : [
395
- 'GET'
396
- ]).map((method)=>method.toUpperCase()));
397
- const onEvent = options.onEvent;
398
- const buckets = new Map();
399
- const pendingByKey = new Map();
400
- const disabledEndpoints = new Set();
401
- const runSingle = async (request)=>{
402
- const response = await baseFetch(request.requestUrl, request.requestInit);
403
- return parseResponseLikeCreateRequest(response);
404
- };
405
- const settleRequests = async (items, runner)=>{
406
- await Promise.all(items.map(async (item)=>{
407
- try {
408
- const value = await runner(item);
409
- item.resolve(value);
410
- } catch (error) {
411
- item.reject(error);
412
- } finally{
413
- pendingByKey.delete(item.key);
414
- }
415
- }));
416
- };
417
- const flushBucket = async (endpoint)=>{
418
- const bucket = buckets.get(endpoint);
419
- if (!bucket || bucket.flushing) return;
420
- if (bucket.timer) {
421
- clearTimeout(bucket.timer);
422
- bucket.timer = null;
423
- }
424
- if (0 === bucket.items.length) return;
425
- bucket.flushing = true;
426
- const items = bucket.items;
427
- bucket.items = [];
428
- bucket.bytes = 0;
429
- if (1 === items.length || disabledEndpoints.has(endpoint)) {
430
- emitDataBatchTransportEvent(onEvent, {
431
- type: disabledEndpoints.has(endpoint) ? 'fallback' : 'flush',
432
- endpoint,
433
- size: items.length,
434
- reason: disabledEndpoints.has(endpoint) ? 'batch-disabled' : void 0
435
- });
436
- await settleRequests(items, runSingle);
437
- bucket.flushing = false;
438
- return;
439
- }
440
- const batchId = createBatchId();
441
- const payload = {
442
- protocolVersion: 1,
443
- batchId,
444
- sentAt: Date.now(),
445
- items: items.map((item)=>item.item)
446
- };
447
- emitDataBatchTransportEvent(onEvent, {
448
- type: 'flush',
449
- endpoint,
450
- batchId,
451
- size: items.length
452
- });
453
- const payloadJson = JSON.stringify(payload);
454
- const traceparent = items.find((item)=>'string' == typeof item.item.headers?.traceparent)?.item.headers?.traceparent || void 0;
455
- const requestInit = {
456
- method: 'POST',
457
- headers: {
458
- accept: 'application/json, */*;q=0.8',
459
- 'content-type': 'application/json; charset=utf-8',
460
- [DEFAULT_DATA_BATCH_HEADER]: '1',
461
- ...traceparent ? {
462
- traceparent
463
- } : {}
464
- },
465
- body: payloadJson
466
- };
467
- let timeoutHandle = null;
468
- try {
469
- const controller = requestTimeoutMs && requestTimeoutMs > 0 ? new AbortController() : void 0;
470
- if (controller) {
471
- requestInit.signal = controller.signal;
472
- timeoutHandle = setTimeout(()=>{
473
- controller.abort();
474
- emitDataBatchTransportEvent(onEvent, {
475
- type: 'fallback',
476
- endpoint,
477
- batchId,
478
- size: items.length,
479
- reason: 'batch-timeout'
480
- });
481
- }, requestTimeoutMs);
482
- }
483
- const response = await baseFetch(endpoint, requestInit);
484
- if (!response.ok) {
485
- if (404 === response.status || 405 === response.status) {
486
- disabledEndpoints.add(endpoint);
487
- emitDataBatchTransportEvent(onEvent, {
488
- type: 'disable',
489
- endpoint,
490
- batchId,
491
- reason: `batch-endpoint-unavailable-${String(response.status)}`
492
- });
493
- } else emitDataBatchTransportEvent(onEvent, {
494
- type: 'fallback',
495
- endpoint,
496
- batchId,
497
- size: items.length,
498
- reason: `batch-response-${String(response.status)}`
499
- });
500
- await settleRequests(items, runSingle);
501
- bucket.flushing = false;
502
- return;
503
- }
504
- const result = await response.json();
505
- if (!isBatchResponsePayload(result)) {
506
- emitDataBatchTransportEvent(onEvent, {
507
- type: 'fallback',
508
- endpoint,
509
- batchId,
510
- size: items.length,
511
- reason: 'invalid-batch-response'
512
- });
513
- await settleRequests(items, runSingle);
514
- bucket.flushing = false;
515
- return;
516
- }
517
- const itemMap = new Map();
518
- for (const item of result.items)itemMap.set(item.id, item);
519
- await settleRequests(items, async (request)=>{
520
- const resultItem = itemMap.get(request.item.id);
521
- if (!resultItem) return runSingle(request);
522
- const reconstructedResponse = new Response(resultItem.body ?? '', {
523
- status: resultItem.status,
524
- headers: resultItem.headers
525
- });
526
- return parseResponseLikeCreateRequest(reconstructedResponse);
527
- });
528
- } catch (error) {
529
- emitDataBatchTransportEvent(onEvent, {
530
- type: 'fallback',
531
- endpoint,
532
- batchId,
533
- size: items.length,
534
- reason: 'batch-transport-error'
535
- });
536
- await settleRequests(items, runSingle);
537
- } finally{
538
- if (timeoutHandle) clearTimeout(timeoutHandle);
539
- bucket.flushing = false;
540
- }
541
- };
542
- return (input, init)=>{
543
- const requestUrl = toAbsoluteUrl(input);
544
- const batchEndpointUrl = normalizeBatchEndpoint(requestUrl, options.endpoint);
545
- const endpoint = batchEndpointUrl.toString();
546
- const method = normalizeMethod(init?.method);
547
- const body = toRequestBody(init?.body ?? null);
548
- const headers = toHeaderRecord(init?.headers);
549
- const normalizedInit = {
550
- ...init,
551
- method,
552
- headers,
553
- body
554
- };
555
- if (disabledEndpoints.has(endpoint) || !shouldBatchRequest({
556
- method,
557
- body,
558
- headers,
559
- allowedMethods,
560
- batchEndpoint: endpoint,
561
- requestUrl
562
- })) return baseFetch(requestUrl.toString(), normalizedInit).then(parseResponseLikeCreateRequest);
563
- const item = {
564
- id: `${Date.now().toString(36)}_${Math.random().toString(16).slice(2, 8)}`,
565
- path: `${requestUrl.pathname}${requestUrl.search}`,
566
- method,
567
- headers,
568
- ...body ? {
569
- body
570
- } : {}
571
- };
572
- const key = stableStringify({
573
- endpoint,
574
- path: item.path,
575
- method: item.method,
576
- headers: item.headers,
577
- body: item.body ?? null
578
- });
579
- const existing = pendingByKey.get(key);
580
- if (existing) return existing;
581
- const size = measureTextBytes(stableStringify(item));
582
- const promise = new Promise((resolve, reject)=>{
583
- const bucket = ensureBucket(buckets, endpoint);
584
- const queued = {
585
- key,
586
- endpoint,
587
- requestUrl: requestUrl.toString(),
588
- requestInit: normalizedInit,
589
- item,
590
- size,
591
- resolve,
592
- reject
593
- };
594
- bucket.items.push(queued);
595
- bucket.bytes += size;
596
- emitDataBatchTransportEvent(onEvent, {
597
- type: 'enqueue',
598
- endpoint,
599
- size: bucket.items.length
600
- });
601
- if (bucket.items.length >= maxBatchSize || bucket.bytes >= maxBatchBytes) return void flushBucket(endpoint);
602
- if (!bucket.timer) bucket.timer = setTimeout(()=>{
603
- bucket.timer = null;
604
- flushBucket(endpoint);
605
- }, flushIntervalMs);
606
- });
607
- pendingByKey.set(key, promise);
608
- return promise;
609
- };
610
- }
611
- export { DATA_BATCH_TRANSPORT_OTEL_EVENT, DEFAULT_DATA_BATCH_ENDPOINT, DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER, buildQueryKey, buildScopeKey, createDataBatchTransport, createDataBatchTransportTelemetryAttributes, createHydrationEnvelope, createInvalidationEvent, createOperationId, createRequestEnvelope, decodeRequestEnvelopeHeader, deriveChildTraceContext, emitDataBatchTransportEvent, encodeRequestEnvelopeHeader, formatTraceparentHeader, normalizeOrigin, parseTraceparentHeader, shouldApplyInvalidation, stableStringify, validateHydrationEnvelope, validateRequestEnvelope, validateSelectionPlan };
2
+ export { DATA_BATCH_TRANSPORT_OTEL_EVENT, createDataBatchTransport, createDataBatchTransportTelemetryAttributes, emitDataBatchTransportEvent } from "./batch-transport.mjs";
3
+ export { buildQueryKey, buildScopeKey, createOperationId, decodeRequestEnvelopeHeader, encodeRequestEnvelopeHeader, normalizeOrigin, stableStringify } from "./codec.mjs";
4
+ export { createInvalidationEvent, shouldApplyInvalidation } from "./invalidation.mjs";
5
+ export { deriveChildTraceContext, formatTraceparentHeader, parseTraceparentHeader } from "./trace.mjs";
6
+ export { DEFAULT_DATA_BATCH_ENDPOINT, DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER } from "./types.mjs";
7
+ export { createHydrationEnvelope, createRequestEnvelope, validateHydrationEnvelope, validateRequestEnvelope, validateSelectionPlan } from "./validation.mjs";
@@ -0,0 +1,21 @@
1
+ import "node:module";
2
+ import { buildScopeKey, createOperationId, sanitizeSegment } from "./codec.mjs";
3
+ function createInvalidationEvent(input) {
4
+ return {
5
+ sourceNamespace: sanitizeSegment(input.sourceOperation.appNamespace),
6
+ sourceOperationId: createOperationId(input.sourceOperation),
7
+ scopeKey: buildScopeKey(input.sourceScope),
8
+ targetNamespaces: input.targetNamespaces?.map((namespace)=>sanitizeSegment(namespace)),
9
+ targetOperationIds: input.targetOperations?.map((operation)=>createOperationId(operation))
10
+ };
11
+ }
12
+ function shouldApplyInvalidation(event, subscriber) {
13
+ if (subscriber.scopeKey && subscriber.scopeKey !== event.scopeKey) return false;
14
+ const sameNamespace = subscriber.namespace === event.sourceNamespace;
15
+ const allowedCrossNamespace = true === subscriber.acceptCrossNamespace && event.targetNamespaces?.includes(subscriber.namespace) === true;
16
+ if (!sameNamespace && !allowedCrossNamespace) return false;
17
+ if (!subscriber.operationIds || 0 === subscriber.operationIds.length) return true;
18
+ if (!event.targetOperationIds || 0 === event.targetOperationIds.length) return true;
19
+ return subscriber.operationIds.some((operationId)=>event.targetOperationIds?.includes(operationId));
20
+ }
21
+ export { createInvalidationEvent, shouldApplyInvalidation };
@@ -0,0 +1,30 @@
1
+ import "node:module";
2
+ import { parseTraceparent } from "@modern-js/create-request";
3
+ function isAllZeroHex(value) {
4
+ return /^0+$/.test(value);
5
+ }
6
+ function isValidHex(value, length) {
7
+ return value.length === length && /^[0-9a-f]+$/.test(value);
8
+ }
9
+ function parseTraceparentHeader(header) {
10
+ return parseTraceparent(header) ?? null;
11
+ }
12
+ function formatTraceparentHeader(trace) {
13
+ const traceId = trace.traceId.toLowerCase();
14
+ const spanId = trace.spanId.toLowerCase();
15
+ if (!isValidHex(traceId, 32) || !isValidHex(spanId, 16)) throw new Error('Invalid trace context: traceId/spanId format mismatch');
16
+ if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) throw new Error('Invalid trace context: traceId/spanId cannot be zero');
17
+ const flags = trace.sampled ? '01' : '00';
18
+ return `00-${traceId}-${spanId}-${flags}`;
19
+ }
20
+ function deriveChildTraceContext(parent, childSpanId) {
21
+ const normalizedSpanId = childSpanId.toLowerCase();
22
+ if (!isValidHex(normalizedSpanId, 16) || isAllZeroHex(normalizedSpanId)) throw new Error('Invalid child span id');
23
+ return {
24
+ traceId: parent.traceId.toLowerCase(),
25
+ spanId: normalizedSpanId,
26
+ sampled: parent.sampled,
27
+ parentSpanId: parent.spanId.toLowerCase()
28
+ };
29
+ }
30
+ export { deriveChildTraceContext, formatTraceparentHeader, parseTraceparentHeader };
@@ -0,0 +1,5 @@
1
+ import "node:module";
2
+ const DEFAULT_DATA_ENVELOPE_HEADER = 'x-modernjs-data-envelope';
3
+ const DEFAULT_DATA_BATCH_ENDPOINT = '/_data/batch';
4
+ const DEFAULT_DATA_BATCH_HEADER = 'x-modernjs-data-batch';
5
+ export { DEFAULT_DATA_BATCH_ENDPOINT, DEFAULT_DATA_BATCH_HEADER, DEFAULT_DATA_ENVELOPE_HEADER };