@ecopages/core 0.2.0-alpha.22 → 0.2.0-alpha.24

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 (515) hide show
  1. package/package.json +93 -226
  2. package/src/adapters/abstract/application-adapter.test.ts +172 -0
  3. package/src/adapters/abstract/application-adapter.ts +379 -0
  4. package/src/adapters/abstract/router-adapter.ts +30 -0
  5. package/src/adapters/abstract/server-adapter.ts +79 -0
  6. package/src/adapters/bun/client-bridge.ts +62 -0
  7. package/src/adapters/bun/create-app.ts +180 -0
  8. package/src/adapters/bun/hmr-manager.test.ts +267 -0
  9. package/src/adapters/bun/hmr-manager.ts +406 -0
  10. package/src/adapters/bun/index.ts +2 -0
  11. package/src/adapters/bun/server-adapter.ts +500 -0
  12. package/src/adapters/bun/server-lifecycle.ts +124 -0
  13. package/src/adapters/create-app.test.ts +10 -0
  14. package/src/adapters/create-app.ts +91 -0
  15. package/src/adapters/index.ts +2 -0
  16. package/src/adapters/node/create-app.test.ts +53 -0
  17. package/src/adapters/node/create-app.ts +183 -0
  18. package/src/adapters/node/node-client-bridge.test.ts +198 -0
  19. package/src/adapters/node/node-client-bridge.ts +79 -0
  20. package/src/adapters/node/node-hmr-manager.test.ts +322 -0
  21. package/src/adapters/node/node-hmr-manager.ts +378 -0
  22. package/src/adapters/node/server-adapter.ts +502 -0
  23. package/src/adapters/node/static-content-server.test.ts +60 -0
  24. package/src/adapters/node/static-content-server.ts +239 -0
  25. package/src/adapters/shared/api-response.test.ts +97 -0
  26. package/src/adapters/shared/api-response.ts +104 -0
  27. package/src/adapters/shared/application-adapter.ts +199 -0
  28. package/src/adapters/shared/define-api-handler.ts +66 -0
  29. package/src/adapters/shared/explicit-static-route-matcher.test.ts +381 -0
  30. package/src/adapters/shared/explicit-static-route-matcher.ts +140 -0
  31. package/src/adapters/shared/file-route-middleware-pipeline.test.ts +90 -0
  32. package/src/adapters/shared/file-route-middleware-pipeline.ts +127 -0
  33. package/src/adapters/shared/fs-server-response-factory.test.ts +187 -0
  34. package/src/adapters/shared/fs-server-response-factory.ts +118 -0
  35. package/src/adapters/shared/fs-server-response-matcher.test.ts +285 -0
  36. package/src/adapters/shared/fs-server-response-matcher.ts +189 -0
  37. package/src/adapters/shared/hmr-entrypoint-registrar.ts +149 -0
  38. package/src/adapters/shared/hmr-html-response.ts +52 -0
  39. package/src/adapters/shared/hmr-manager.contract.test.ts +232 -0
  40. package/src/adapters/shared/hmr-manager.dispatch.test.ts +220 -0
  41. package/src/adapters/shared/render-context.test.ts +150 -0
  42. package/src/adapters/shared/render-context.ts +123 -0
  43. package/src/adapters/shared/runtime-bootstrap.ts +79 -0
  44. package/src/adapters/shared/server-adapter.test.ts +77 -0
  45. package/src/adapters/shared/server-adapter.ts +493 -0
  46. package/src/adapters/shared/server-route-handler.test.ts +110 -0
  47. package/src/adapters/shared/server-route-handler.ts +153 -0
  48. package/src/adapters/shared/server-static-builder.test.ts +338 -0
  49. package/src/adapters/shared/server-static-builder.ts +170 -0
  50. package/src/build/build-adapter-serialization.test.ts +281 -0
  51. package/src/build/build-adapter.test.ts +1240 -0
  52. package/src/build/build-adapter.ts +1012 -0
  53. package/src/build/build-manifest.ts +54 -0
  54. package/src/build/build-types.ts +83 -0
  55. package/src/build/dev-build-coordinator.ts +220 -0
  56. package/src/build/esbuild-build-adapter.ts +660 -0
  57. package/src/build/runtime-build-executor.test.ts +81 -0
  58. package/src/build/runtime-build-executor.ts +40 -0
  59. package/src/build/runtime-specifier-alias-plugin.test.ts +67 -0
  60. package/src/build/runtime-specifier-alias-plugin.ts +62 -0
  61. package/src/build/runtime-specifier-aliases.ts +135 -0
  62. package/src/config/config-builder.test.ts +443 -0
  63. package/src/config/config-builder.ts +742 -0
  64. package/src/config/config-builder.typecheck.test.ts +96 -0
  65. package/src/config/{constants.d.ts → constants.ts} +22 -13
  66. package/src/dev/sc-server.ts +143 -0
  67. package/src/eco/eco.browser.test.ts +43 -0
  68. package/src/eco/eco.browser.ts +118 -0
  69. package/src/eco/eco.test.ts +654 -0
  70. package/src/eco/eco.ts +205 -0
  71. package/src/eco/eco.types.ts +221 -0
  72. package/src/eco/eco.utils.test.ts +219 -0
  73. package/src/eco/eco.utils.ts +5 -0
  74. package/src/eco/global-injector-map.test.ts +42 -0
  75. package/src/eco/global-injector-map.ts +112 -0
  76. package/src/eco/lazy-injector-map.test.ts +66 -0
  77. package/src/eco/lazy-injector-map.ts +120 -0
  78. package/src/eco/module-dependencies.test.ts +30 -0
  79. package/src/eco/module-dependencies.ts +75 -0
  80. package/src/errors/http-error.test.ts +134 -0
  81. package/src/errors/http-error.ts +72 -0
  82. package/src/errors/{index.d.ts → index.ts} +2 -2
  83. package/src/errors/locals-access-error.ts +7 -0
  84. package/src/global/app-logger.ts +4 -0
  85. package/src/global/utils.test.ts +12 -0
  86. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
  87. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
  88. package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
  89. package/src/hmr/client/hmr-runtime.ts +160 -0
  90. package/src/hmr/hmr-strategy.test.ts +124 -0
  91. package/src/hmr/hmr-strategy.ts +177 -0
  92. package/src/hmr/hmr.postcss.test.e2e.ts +41 -0
  93. package/src/hmr/hmr.test.e2e.ts +66 -0
  94. package/src/hmr/strategies/default-hmr-strategy.ts +60 -0
  95. package/src/hmr/strategies/js-hmr-strategy.test.ts +335 -0
  96. package/src/hmr/strategies/js-hmr-strategy.ts +320 -0
  97. package/src/index.browser.ts +3 -0
  98. package/src/index.ts +15 -0
  99. package/src/integrations/ghtml/ghtml-renderer.test.ts +253 -0
  100. package/src/integrations/ghtml/ghtml-renderer.ts +97 -0
  101. package/src/integrations/ghtml/ghtml.constants.ts +1 -0
  102. package/src/integrations/ghtml/ghtml.plugin.ts +28 -0
  103. package/src/plugins/alias-resolver-plugin.test.ts +41 -0
  104. package/src/plugins/alias-resolver-plugin.ts +63 -0
  105. package/src/plugins/eco-component-meta-plugin.test.ts +406 -0
  106. package/src/plugins/eco-component-meta-plugin.ts +495 -0
  107. package/src/plugins/foreign-jsx-override-plugin.test.ts +65 -0
  108. package/src/plugins/foreign-jsx-override-plugin.ts +67 -0
  109. package/src/plugins/integration-plugin.test.ts +156 -0
  110. package/src/plugins/integration-plugin.ts +311 -0
  111. package/src/plugins/processor.test.ts +148 -0
  112. package/src/plugins/processor.ts +240 -0
  113. package/src/plugins/{runtime-capability.d.ts → runtime-capability.ts} +8 -3
  114. package/src/plugins/source-transform.test.ts +82 -0
  115. package/src/plugins/source-transform.ts +123 -0
  116. package/src/route-renderer/orchestration/boundary-planning.service.ts +146 -0
  117. package/src/route-renderer/orchestration/component-render-context.ts +318 -0
  118. package/src/route-renderer/orchestration/integration-renderer.test.ts +2088 -0
  119. package/src/route-renderer/orchestration/integration-renderer.ts +1285 -0
  120. package/src/route-renderer/orchestration/page-packaging.service.test.ts +76 -0
  121. package/src/route-renderer/orchestration/page-packaging.service.ts +85 -0
  122. package/src/route-renderer/orchestration/processed-asset-dedupe.ts +25 -0
  123. package/src/route-renderer/orchestration/queued-boundary-runtime.service.test.ts +319 -0
  124. package/src/route-renderer/orchestration/queued-boundary-runtime.service.ts +289 -0
  125. package/src/route-renderer/orchestration/render-execution.service.test.ts +196 -0
  126. package/src/route-renderer/orchestration/render-execution.service.ts +182 -0
  127. package/src/route-renderer/orchestration/render-output.utils.ts +302 -0
  128. package/src/route-renderer/orchestration/render-preparation.service.test.ts +569 -0
  129. package/src/route-renderer/orchestration/render-preparation.service.ts +508 -0
  130. package/src/route-renderer/orchestration/route-shell-composer.service.ts +162 -0
  131. package/src/route-renderer/orchestration/template-serialization.test.ts +110 -0
  132. package/src/route-renderer/orchestration/template-serialization.ts +117 -0
  133. package/src/route-renderer/page-loading/component-dependency-collection.ts +196 -0
  134. package/src/route-renderer/page-loading/declared-asset-collection.ts +156 -0
  135. package/src/route-renderer/page-loading/dependency-resolver.test.ts +665 -0
  136. package/src/route-renderer/page-loading/dependency-resolver.ts +150 -0
  137. package/src/route-renderer/page-loading/ecopages-virtual-imports.ts +75 -0
  138. package/src/route-renderer/page-loading/lazy-entry-collection.ts +167 -0
  139. package/src/route-renderer/page-loading/lazy-trigger-planning.ts +74 -0
  140. package/src/route-renderer/page-loading/module-declaration-aggregation.ts +60 -0
  141. package/src/route-renderer/page-loading/module-declaration-scripts.ts +16 -0
  142. package/src/route-renderer/page-loading/page-dependency-bundling.ts +205 -0
  143. package/src/route-renderer/page-loading/page-module-loader.test.ts +183 -0
  144. package/src/route-renderer/page-loading/page-module-loader.ts +184 -0
  145. package/src/route-renderer/route-renderer.ts +136 -0
  146. package/src/router/client/link-intent.test.browser.ts +51 -0
  147. package/src/router/client/link-intent.ts +92 -0
  148. package/src/router/client/navigation-coordinator.test.ts +237 -0
  149. package/src/router/client/navigation-coordinator.ts +453 -0
  150. package/src/router/server/fs-router-scanner.test.ts +83 -0
  151. package/src/router/server/fs-router-scanner.ts +224 -0
  152. package/src/router/server/fs-router.test.ts +214 -0
  153. package/src/router/server/fs-router.ts +122 -0
  154. package/src/services/assets/asset-processing-service/asset-dependency-keys.ts +66 -0
  155. package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +476 -0
  156. package/src/services/assets/asset-processing-service/asset-processing.service.ts +345 -0
  157. package/src/services/assets/asset-processing-service/asset.factory.test.ts +63 -0
  158. package/src/services/assets/asset-processing-service/asset.factory.ts +105 -0
  159. package/src/services/assets/asset-processing-service/assets.types.ts +125 -0
  160. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +74 -0
  161. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.ts +96 -0
  162. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +67 -0
  163. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.ts +78 -0
  164. package/src/services/assets/asset-processing-service/grouped-content-bundles.ts +104 -0
  165. package/src/services/assets/asset-processing-service/index.ts +5 -0
  166. package/src/services/assets/asset-processing-service/{processor.interface.d.ts → processor.interface.ts} +10 -5
  167. package/src/services/assets/asset-processing-service/processor.registry.ts +18 -0
  168. package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +59 -0
  169. package/src/services/assets/asset-processing-service/processors/base/base-processor.ts +83 -0
  170. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.ts +174 -0
  171. package/src/services/assets/asset-processing-service/processors/index.ts +5 -0
  172. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.test.ts +192 -0
  173. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.ts +134 -0
  174. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +326 -0
  175. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.ts +110 -0
  176. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +227 -0
  177. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.ts +87 -0
  178. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +261 -0
  179. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.ts +71 -0
  180. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.ts +81 -0
  181. package/src/services/assets/asset-processing-service/ungrouped-dependency-processing.ts +65 -0
  182. package/src/services/assets/browser-bundle.service.test.ts +66 -0
  183. package/src/services/assets/browser-bundle.service.ts +109 -0
  184. package/src/services/cache/cache.types.ts +126 -0
  185. package/src/services/cache/index.ts +18 -0
  186. package/src/services/cache/memory-cache-store.test.ts +225 -0
  187. package/src/services/cache/memory-cache-store.ts +130 -0
  188. package/src/services/cache/page-cache-service.test.ts +175 -0
  189. package/src/services/cache/page-cache-service.ts +202 -0
  190. package/src/services/cache/page-request-cache-coordinator.service.test.ts +79 -0
  191. package/src/services/cache/page-request-cache-coordinator.service.ts +131 -0
  192. package/src/services/html/html-rewriter-provider.service.test.ts +183 -0
  193. package/src/services/html/html-rewriter-provider.service.ts +104 -0
  194. package/src/services/html/html-transformer.service.test.ts +479 -0
  195. package/src/services/html/html-transformer.service.ts +275 -0
  196. package/src/services/invalidation/development-invalidation.service.test.ts +87 -0
  197. package/src/services/invalidation/development-invalidation.service.ts +262 -0
  198. package/src/services/module-loading/app-module-loader.service.ts +9 -0
  199. package/src/services/module-loading/app-server-module-transpiler.service.test.ts +130 -0
  200. package/src/services/module-loading/app-server-module-transpiler.service.ts +143 -0
  201. package/src/services/module-loading/host-module-loader-registry.ts +15 -0
  202. package/src/services/module-loading/{module-loading-types.d.ts → module-loading-types.ts} +1 -0
  203. package/src/services/module-loading/node-bootstrap-plugin.test.ts +335 -0
  204. package/src/services/module-loading/node-bootstrap-plugin.ts +297 -0
  205. package/src/services/module-loading/page-module-import.service.test.ts +504 -0
  206. package/src/services/module-loading/page-module-import.service.ts +252 -0
  207. package/src/services/module-loading/server-module-transpiler.service.test.ts +243 -0
  208. package/src/services/module-loading/server-module-transpiler.service.ts +104 -0
  209. package/src/services/module-loading/source-module-support.ts +19 -0
  210. package/src/services/runtime-state/dev-graph.service.ts +217 -0
  211. package/src/services/runtime-state/entrypoint-dependency-graph.service.ts +136 -0
  212. package/src/services/runtime-state/runtime-specifier-registry.service.ts +96 -0
  213. package/src/services/runtime-state/server-invalidation-state.service.ts +68 -0
  214. package/src/services/validation/schema-validation-service.test.ts +223 -0
  215. package/src/services/validation/schema-validation-service.ts +204 -0
  216. package/src/services/validation/{standard-schema.types.d.ts → standard-schema.types.ts} +20 -17
  217. package/src/static-site-generator/static-site-generator.test.ts +316 -0
  218. package/src/static-site-generator/static-site-generator.ts +462 -0
  219. package/src/types/internal-types.ts +242 -0
  220. package/src/types/public-types.ts +1443 -0
  221. package/src/utils/deep-merge.test.ts +114 -0
  222. package/src/utils/deep-merge.ts +47 -0
  223. package/src/utils/hash.ts +5 -0
  224. package/src/utils/html-escaping.ts +9 -0
  225. package/src/utils/invariant.test.ts +22 -0
  226. package/src/utils/invariant.ts +15 -0
  227. package/src/utils/locals-utils.ts +37 -0
  228. package/src/utils/parse-cli-args.test.ts +69 -0
  229. package/src/utils/parse-cli-args.ts +105 -0
  230. package/src/utils/path-utils.module.ts +14 -0
  231. package/src/utils/path-utils.test.ts +15 -0
  232. package/src/utils/resolve-work-dir.ts +45 -0
  233. package/src/utils/runtime.ts +44 -0
  234. package/src/utils/server-utils.module.ts +67 -0
  235. package/src/utils/server-utils.test.ts +38 -0
  236. package/src/watchers/project-watcher.integration.test.ts +337 -0
  237. package/src/watchers/project-watcher.test-helpers.ts +41 -0
  238. package/src/watchers/project-watcher.test.ts +768 -0
  239. package/src/watchers/project-watcher.ts +357 -0
  240. package/CHANGELOG.md +0 -51
  241. package/src/adapters/abstract/application-adapter.d.ts +0 -194
  242. package/src/adapters/abstract/application-adapter.js +0 -121
  243. package/src/adapters/abstract/router-adapter.d.ts +0 -26
  244. package/src/adapters/abstract/router-adapter.js +0 -5
  245. package/src/adapters/abstract/server-adapter.d.ts +0 -69
  246. package/src/adapters/abstract/server-adapter.js +0 -15
  247. package/src/adapters/bun/client-bridge.d.ts +0 -34
  248. package/src/adapters/bun/client-bridge.js +0 -48
  249. package/src/adapters/bun/create-app.d.ts +0 -52
  250. package/src/adapters/bun/create-app.js +0 -116
  251. package/src/adapters/bun/hmr-manager.d.ts +0 -143
  252. package/src/adapters/bun/hmr-manager.js +0 -333
  253. package/src/adapters/bun/index.d.ts +0 -2
  254. package/src/adapters/bun/index.js +0 -8
  255. package/src/adapters/bun/server-adapter.d.ts +0 -155
  256. package/src/adapters/bun/server-adapter.js +0 -374
  257. package/src/adapters/bun/server-lifecycle.d.ts +0 -63
  258. package/src/adapters/bun/server-lifecycle.js +0 -92
  259. package/src/adapters/create-app.d.ts +0 -20
  260. package/src/adapters/create-app.js +0 -66
  261. package/src/adapters/index.d.ts +0 -2
  262. package/src/adapters/index.js +0 -8
  263. package/src/adapters/node/create-app.d.ts +0 -18
  264. package/src/adapters/node/create-app.js +0 -149
  265. package/src/adapters/node/node-client-bridge.d.ts +0 -26
  266. package/src/adapters/node/node-client-bridge.js +0 -66
  267. package/src/adapters/node/node-hmr-manager.d.ts +0 -133
  268. package/src/adapters/node/node-hmr-manager.js +0 -311
  269. package/src/adapters/node/server-adapter.d.ts +0 -161
  270. package/src/adapters/node/server-adapter.js +0 -359
  271. package/src/adapters/node/static-content-server.d.ts +0 -60
  272. package/src/adapters/node/static-content-server.js +0 -194
  273. package/src/adapters/shared/api-response.d.ts +0 -52
  274. package/src/adapters/shared/api-response.js +0 -96
  275. package/src/adapters/shared/application-adapter.d.ts +0 -18
  276. package/src/adapters/shared/application-adapter.js +0 -90
  277. package/src/adapters/shared/define-api-handler.d.ts +0 -25
  278. package/src/adapters/shared/define-api-handler.js +0 -15
  279. package/src/adapters/shared/explicit-static-route-matcher.d.ts +0 -38
  280. package/src/adapters/shared/explicit-static-route-matcher.js +0 -103
  281. package/src/adapters/shared/file-route-middleware-pipeline.d.ts +0 -65
  282. package/src/adapters/shared/file-route-middleware-pipeline.js +0 -99
  283. package/src/adapters/shared/fs-server-response-factory.d.ts +0 -19
  284. package/src/adapters/shared/fs-server-response-factory.js +0 -97
  285. package/src/adapters/shared/fs-server-response-matcher.d.ts +0 -67
  286. package/src/adapters/shared/fs-server-response-matcher.js +0 -147
  287. package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +0 -55
  288. package/src/adapters/shared/hmr-entrypoint-registrar.js +0 -87
  289. package/src/adapters/shared/hmr-html-response.d.ts +0 -22
  290. package/src/adapters/shared/hmr-html-response.js +0 -32
  291. package/src/adapters/shared/render-context.d.ts +0 -15
  292. package/src/adapters/shared/render-context.js +0 -72
  293. package/src/adapters/shared/runtime-bootstrap.d.ts +0 -38
  294. package/src/adapters/shared/runtime-bootstrap.js +0 -43
  295. package/src/adapters/shared/server-adapter.d.ts +0 -97
  296. package/src/adapters/shared/server-adapter.js +0 -390
  297. package/src/adapters/shared/server-route-handler.d.ts +0 -89
  298. package/src/adapters/shared/server-route-handler.js +0 -111
  299. package/src/adapters/shared/server-static-builder.d.ts +0 -70
  300. package/src/adapters/shared/server-static-builder.js +0 -100
  301. package/src/build/build-adapter.d.ts +0 -239
  302. package/src/build/build-adapter.js +0 -642
  303. package/src/build/build-manifest.d.ts +0 -27
  304. package/src/build/build-manifest.js +0 -30
  305. package/src/build/build-types.d.ts +0 -57
  306. package/src/build/build-types.js +0 -0
  307. package/src/build/dev-build-coordinator.d.ts +0 -72
  308. package/src/build/dev-build-coordinator.js +0 -154
  309. package/src/build/esbuild-build-adapter.d.ts +0 -78
  310. package/src/build/esbuild-build-adapter.js +0 -505
  311. package/src/build/runtime-build-executor.d.ts +0 -14
  312. package/src/build/runtime-build-executor.js +0 -22
  313. package/src/build/runtime-specifier-alias-plugin.d.ts +0 -15
  314. package/src/build/runtime-specifier-alias-plugin.js +0 -35
  315. package/src/build/runtime-specifier-aliases.d.ts +0 -5
  316. package/src/build/runtime-specifier-aliases.js +0 -95
  317. package/src/config/config-builder.d.ts +0 -252
  318. package/src/config/config-builder.js +0 -603
  319. package/src/config/constants.js +0 -25
  320. package/src/dev/sc-server.d.ts +0 -30
  321. package/src/dev/sc-server.js +0 -111
  322. package/src/eco/eco.browser.d.ts +0 -2
  323. package/src/eco/eco.browser.js +0 -83
  324. package/src/eco/eco.d.ts +0 -9
  325. package/src/eco/eco.js +0 -85
  326. package/src/eco/eco.types.d.ts +0 -178
  327. package/src/eco/eco.types.js +0 -0
  328. package/src/eco/eco.utils.d.ts +0 -1
  329. package/src/eco/eco.utils.js +0 -10
  330. package/src/eco/global-injector-map.d.ts +0 -16
  331. package/src/eco/global-injector-map.js +0 -80
  332. package/src/eco/lazy-injector-map.d.ts +0 -8
  333. package/src/eco/lazy-injector-map.js +0 -70
  334. package/src/eco/module-dependencies.d.ts +0 -18
  335. package/src/eco/module-dependencies.js +0 -49
  336. package/src/errors/http-error.d.ts +0 -31
  337. package/src/errors/http-error.js +0 -50
  338. package/src/errors/index.js +0 -4
  339. package/src/errors/locals-access-error.d.ts +0 -4
  340. package/src/errors/locals-access-error.js +0 -9
  341. package/src/global/app-logger.d.ts +0 -2
  342. package/src/global/app-logger.js +0 -6
  343. package/src/hmr/client/hmr-runtime.d.ts +0 -5
  344. package/src/hmr/client/hmr-runtime.js +0 -109
  345. package/src/hmr/hmr-strategy.d.ts +0 -162
  346. package/src/hmr/hmr-strategy.js +0 -44
  347. package/src/hmr/hmr.postcss.test.e2e.d.ts +0 -1
  348. package/src/hmr/hmr.postcss.test.e2e.js +0 -31
  349. package/src/hmr/hmr.test.e2e.d.ts +0 -1
  350. package/src/hmr/hmr.test.e2e.js +0 -43
  351. package/src/hmr/strategies/default-hmr-strategy.d.ts +0 -43
  352. package/src/hmr/strategies/default-hmr-strategy.js +0 -34
  353. package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -139
  354. package/src/hmr/strategies/js-hmr-strategy.js +0 -178
  355. package/src/index.browser.d.ts +0 -3
  356. package/src/index.browser.js +0 -4
  357. package/src/index.d.ts +0 -6
  358. package/src/index.js +0 -21
  359. package/src/integrations/ghtml/ghtml-renderer.d.ts +0 -20
  360. package/src/integrations/ghtml/ghtml-renderer.js +0 -63
  361. package/src/integrations/ghtml/ghtml.constants.d.ts +0 -1
  362. package/src/integrations/ghtml/ghtml.constants.js +0 -4
  363. package/src/integrations/ghtml/ghtml.plugin.d.ts +0 -16
  364. package/src/integrations/ghtml/ghtml.plugin.js +0 -20
  365. package/src/plugins/alias-resolver-plugin.d.ts +0 -2
  366. package/src/plugins/alias-resolver-plugin.js +0 -53
  367. package/src/plugins/eco-component-meta-plugin.d.ts +0 -108
  368. package/src/plugins/eco-component-meta-plugin.js +0 -163
  369. package/src/plugins/foreign-jsx-override-plugin.d.ts +0 -31
  370. package/src/plugins/foreign-jsx-override-plugin.js +0 -35
  371. package/src/plugins/integration-plugin.d.ts +0 -219
  372. package/src/plugins/integration-plugin.js +0 -196
  373. package/src/plugins/processor.d.ts +0 -95
  374. package/src/plugins/processor.js +0 -136
  375. package/src/plugins/runtime-capability.js +0 -0
  376. package/src/plugins/source-transform.d.ts +0 -46
  377. package/src/plugins/source-transform.js +0 -71
  378. package/src/route-renderer/orchestration/boundary-planning.service.d.ts +0 -25
  379. package/src/route-renderer/orchestration/boundary-planning.service.js +0 -97
  380. package/src/route-renderer/orchestration/component-render-context.d.ts +0 -83
  381. package/src/route-renderer/orchestration/component-render-context.js +0 -147
  382. package/src/route-renderer/orchestration/integration-renderer.d.ts +0 -554
  383. package/src/route-renderer/orchestration/integration-renderer.js +0 -957
  384. package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +0 -89
  385. package/src/route-renderer/orchestration/queued-boundary-runtime.service.js +0 -155
  386. package/src/route-renderer/orchestration/render-execution.service.d.ts +0 -43
  387. package/src/route-renderer/orchestration/render-execution.service.js +0 -106
  388. package/src/route-renderer/orchestration/render-output.utils.d.ts +0 -46
  389. package/src/route-renderer/orchestration/render-output.utils.js +0 -65
  390. package/src/route-renderer/orchestration/render-preparation.service.d.ts +0 -120
  391. package/src/route-renderer/orchestration/render-preparation.service.js +0 -341
  392. package/src/route-renderer/orchestration/route-shell-composer.service.d.ts +0 -50
  393. package/src/route-renderer/orchestration/route-shell-composer.service.js +0 -81
  394. package/src/route-renderer/orchestration/template-serialization.d.ts +0 -38
  395. package/src/route-renderer/orchestration/template-serialization.js +0 -45
  396. package/src/route-renderer/page-loading/dependency-resolver.d.ts +0 -35
  397. package/src/route-renderer/page-loading/dependency-resolver.js +0 -444
  398. package/src/route-renderer/page-loading/page-module-loader.d.ts +0 -90
  399. package/src/route-renderer/page-loading/page-module-loader.js +0 -127
  400. package/src/route-renderer/route-renderer.d.ts +0 -67
  401. package/src/route-renderer/route-renderer.js +0 -103
  402. package/src/router/client/link-intent.js +0 -34
  403. package/src/router/client/link-intent.test.browser.d.ts +0 -1
  404. package/src/router/client/link-intent.test.browser.js +0 -43
  405. package/src/router/client/navigation-coordinator.d.ts +0 -149
  406. package/src/router/client/navigation-coordinator.js +0 -215
  407. package/src/router/server/fs-router-scanner.d.ts +0 -41
  408. package/src/router/server/fs-router-scanner.js +0 -161
  409. package/src/router/server/fs-router.d.ts +0 -26
  410. package/src/router/server/fs-router.js +0 -100
  411. package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +0 -120
  412. package/src/services/assets/asset-processing-service/asset-processing.service.js +0 -331
  413. package/src/services/assets/asset-processing-service/asset.factory.d.ts +0 -17
  414. package/src/services/assets/asset-processing-service/asset.factory.js +0 -82
  415. package/src/services/assets/asset-processing-service/assets.types.d.ts +0 -89
  416. package/src/services/assets/asset-processing-service/assets.types.js +0 -0
  417. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +0 -55
  418. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +0 -48
  419. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +0 -20
  420. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +0 -41
  421. package/src/services/assets/asset-processing-service/index.d.ts +0 -5
  422. package/src/services/assets/asset-processing-service/index.js +0 -5
  423. package/src/services/assets/asset-processing-service/processor.interface.js +0 -6
  424. package/src/services/assets/asset-processing-service/processor.registry.d.ts +0 -8
  425. package/src/services/assets/asset-processing-service/processor.registry.js +0 -15
  426. package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +0 -24
  427. package/src/services/assets/asset-processing-service/processors/base/base-processor.js +0 -64
  428. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +0 -17
  429. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +0 -72
  430. package/src/services/assets/asset-processing-service/processors/index.d.ts +0 -5
  431. package/src/services/assets/asset-processing-service/processors/index.js +0 -5
  432. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +0 -5
  433. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +0 -57
  434. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +0 -9
  435. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +0 -88
  436. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +0 -7
  437. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +0 -75
  438. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +0 -5
  439. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +0 -25
  440. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +0 -9
  441. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +0 -66
  442. package/src/services/assets/browser-bundle.service.d.ts +0 -32
  443. package/src/services/assets/browser-bundle.service.js +0 -33
  444. package/src/services/cache/cache.types.d.ts +0 -107
  445. package/src/services/cache/cache.types.js +0 -0
  446. package/src/services/cache/index.d.ts +0 -7
  447. package/src/services/cache/index.js +0 -7
  448. package/src/services/cache/memory-cache-store.d.ts +0 -42
  449. package/src/services/cache/memory-cache-store.js +0 -98
  450. package/src/services/cache/page-cache-service.d.ts +0 -70
  451. package/src/services/cache/page-cache-service.js +0 -152
  452. package/src/services/cache/page-request-cache-coordinator.service.d.ts +0 -75
  453. package/src/services/cache/page-request-cache-coordinator.service.js +0 -109
  454. package/src/services/html/html-rewriter-provider.service.d.ts +0 -37
  455. package/src/services/html/html-rewriter-provider.service.js +0 -68
  456. package/src/services/html/html-transformer.service.d.ts +0 -77
  457. package/src/services/html/html-transformer.service.js +0 -215
  458. package/src/services/invalidation/development-invalidation.service.d.ts +0 -74
  459. package/src/services/invalidation/development-invalidation.service.js +0 -190
  460. package/src/services/module-loading/app-module-loader.service.d.ts +0 -28
  461. package/src/services/module-loading/app-module-loader.service.js +0 -35
  462. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +0 -24
  463. package/src/services/module-loading/app-server-module-transpiler.service.js +0 -109
  464. package/src/services/module-loading/host-module-loader-registry.d.ts +0 -4
  465. package/src/services/module-loading/host-module-loader-registry.js +0 -15
  466. package/src/services/module-loading/module-loading-types.js +0 -0
  467. package/src/services/module-loading/node-bootstrap-plugin.d.ts +0 -42
  468. package/src/services/module-loading/node-bootstrap-plugin.js +0 -204
  469. package/src/services/module-loading/page-module-import.service.d.ts +0 -76
  470. package/src/services/module-loading/page-module-import.service.js +0 -173
  471. package/src/services/module-loading/server-module-transpiler.service.d.ts +0 -72
  472. package/src/services/module-loading/server-module-transpiler.service.js +0 -64
  473. package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
  474. package/src/services/runtime-state/dev-graph.service.js +0 -162
  475. package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +0 -41
  476. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -85
  477. package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +0 -69
  478. package/src/services/runtime-state/runtime-specifier-registry.service.js +0 -37
  479. package/src/services/runtime-state/server-invalidation-state.service.d.ts +0 -26
  480. package/src/services/runtime-state/server-invalidation-state.service.js +0 -35
  481. package/src/services/validation/schema-validation-service.d.ts +0 -122
  482. package/src/services/validation/schema-validation-service.js +0 -101
  483. package/src/services/validation/standard-schema.types.js +0 -0
  484. package/src/static-site-generator/static-site-generator.d.ts +0 -104
  485. package/src/static-site-generator/static-site-generator.js +0 -338
  486. package/src/types/internal-types.d.ts +0 -231
  487. package/src/types/internal-types.js +0 -0
  488. package/src/types/public-types.d.ts +0 -1219
  489. package/src/types/public-types.js +0 -0
  490. package/src/utils/deep-merge.d.ts +0 -14
  491. package/src/utils/deep-merge.js +0 -32
  492. package/src/utils/hash.d.ts +0 -1
  493. package/src/utils/hash.js +0 -7
  494. package/src/utils/html-escaping.d.ts +0 -7
  495. package/src/utils/html-escaping.js +0 -6
  496. package/src/utils/html.js +0 -4
  497. package/src/utils/invariant.d.ts +0 -5
  498. package/src/utils/invariant.js +0 -11
  499. package/src/utils/locals-utils.d.ts +0 -15
  500. package/src/utils/locals-utils.js +0 -24
  501. package/src/utils/parse-cli-args.d.ts +0 -27
  502. package/src/utils/parse-cli-args.js +0 -62
  503. package/src/utils/path-utils.module.d.ts +0 -5
  504. package/src/utils/path-utils.module.js +0 -14
  505. package/src/utils/resolve-work-dir.d.ts +0 -11
  506. package/src/utils/resolve-work-dir.js +0 -31
  507. package/src/utils/runtime.d.ts +0 -11
  508. package/src/utils/runtime.js +0 -40
  509. package/src/utils/server-utils.module.d.ts +0 -19
  510. package/src/utils/server-utils.module.js +0 -56
  511. package/src/watchers/project-watcher.d.ts +0 -136
  512. package/src/watchers/project-watcher.js +0 -275
  513. package/src/watchers/project-watcher.test-helpers.d.ts +0 -4
  514. package/src/watchers/project-watcher.test-helpers.js +0 -52
  515. /package/src/utils/{html.d.ts → html.ts} +0 -0
@@ -1,1219 +0,0 @@
1
- import type { Readable } from 'node:stream';
2
- import type { ApiResponseBuilder } from '../adapters/shared/api-response.js';
3
- import type { BuildExecutor } from '../build/build-adapter.js';
4
- import type { EcoBuildPlugin } from '../build/build-types.js';
5
- import type { ComponentBoundaryRuntime } from '../route-renderer/orchestration/component-render-context.js';
6
- import type { EcoPageComponent } from '../eco/eco.types.js';
7
- import type { EcoPagesAppConfig } from './internal-types.js';
8
- import type { HmrStrategy } from '../hmr/hmr-strategy.js';
9
- import type { BrowserBundleExecutor } from '../services/assets/browser-bundle.service.js';
10
- import type { ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
11
- import type { CacheStats, CacheStrategy } from '../services/cache/cache.types.js';
12
- import type { InteractionEventsString as ScriptsInjectorInteractionEventsString } from '@ecopages/scripts-injector/types';
13
- export type { EcoPagesAppConfig } from './internal-types.js';
14
- export type { EcoPageComponent } from '../eco/eco.types.js';
15
- export type { ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
16
- import type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput } from '../services/validation/standard-schema.types.js';
17
- export type { StandardSchema, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaFailureResult, StandardSchemaIssue, InferOutput, ComponentBoundaryRuntime, };
18
- export type InteractionEventsString = ScriptsInjectorInteractionEventsString;
19
- export type DependencyLazyTrigger = {
20
- 'on:idle': true;
21
- } | {
22
- 'on:interaction': InteractionEventsString;
23
- } | {
24
- 'on:visible': true | string;
25
- };
26
- export type DependencyAttributes = Record<string, string>;
27
- export type EcoComponentStylesheetEntry = {
28
- src?: string;
29
- content?: string;
30
- attributes?: DependencyAttributes;
31
- };
32
- export type EcoComponentScriptEntry = {
33
- src?: string;
34
- content?: string;
35
- attributes?: DependencyAttributes;
36
- lazy?: DependencyLazyTrigger;
37
- ssr?: boolean;
38
- };
39
- export type ResolvedLazyScriptGroup = {
40
- lazy: DependencyLazyTrigger;
41
- scripts: string;
42
- };
43
- export type LazyTriggerRule = {
44
- 'on:idle': {
45
- scripts: string[];
46
- };
47
- } | {
48
- 'on:interaction': {
49
- value: string;
50
- scripts: string[];
51
- };
52
- } | {
53
- 'on:visible': {
54
- value?: string;
55
- scripts: string[];
56
- };
57
- };
58
- export type ResolvedLazyTrigger = {
59
- triggerId: string;
60
- rules: LazyTriggerRule[];
61
- };
62
- /**
63
- * Narrow interface for cache invalidation in API handlers.
64
- * Exposes only the methods needed for programmatic cache control.
65
- */
66
- export interface CacheInvalidator {
67
- /**
68
- * Invalidate all cached entries matching any of the provided tags.
69
- * @param tags - Array of tags to invalidate
70
- * @returns Number of entries invalidated
71
- */
72
- invalidateByTags(tags: string[]): Promise<number>;
73
- /**
74
- * Invalidate cached entries by exact path.
75
- * @param paths - Array of URL paths to invalidate
76
- * @returns Number of entries invalidated
77
- */
78
- invalidateByPaths(paths: string[]): Promise<number>;
79
- /**
80
- * Clear all cached entries.
81
- */
82
- clear(): Promise<void>;
83
- /**
84
- * Get cache statistics for debugging.
85
- */
86
- stats(): Promise<CacheStats>;
87
- }
88
- /**
89
- * Context interface for HMR strategies.
90
- * Provides access to watched files, registered bare-specifier mappings, and build configuration.
91
- */
92
- export interface DefaultHmrContext {
93
- /**
94
- * Map of registered entrypoints to their output URLs.
95
- */
96
- getWatchedFiles(): Map<string, string>;
97
- /**
98
- * Map of bare specifiers to runtime URLs for browser import resolution.
99
- */
100
- getSpecifierMap(): Map<string, string>;
101
- /**
102
- * Directory where HMR bundles are written.
103
- */
104
- getDistDir(): string;
105
- /**
106
- * Build plugins to use during bundling.
107
- */
108
- getPlugins(): EcoBuildPlugin[];
109
- /**
110
- * Absolute path to the source directory.
111
- */
112
- getSrcDir(): string;
113
- /**
114
- * Absolute path to the layouts directory.
115
- * Used to detect layout file changes that require full page reloads.
116
- */
117
- getLayoutsDir(): string;
118
- /**
119
- * Absolute path to the pages directory.
120
- * Used by plugins to identify page files for transformation.
121
- */
122
- getPagesDir(): string;
123
- /**
124
- * Build executor owned by the active app/runtime.
125
- */
126
- getBuildExecutor(): BuildExecutor;
127
- /**
128
- * Browser bundler owned by the active app/runtime.
129
- */
130
- getBrowserBundleService(): BrowserBundleExecutor;
131
- /**
132
- * Server-side module loader owned by the active app/runtime.
133
- */
134
- importServerModule<T = unknown>(filePath: string): Promise<T>;
135
- }
136
- /**
137
- * Represents an event broadcast to connected clients via the ClientBridge.
138
- */
139
- export type ClientBridgeEvent = {
140
- /**
141
- * Event type: 'reload' triggers full refresh, 'update' for JS modules, 'css-update' for stylesheets, 'layout-update' for layout changes
142
- */
143
- type: 'reload' | 'error' | 'update' | 'css-update' | 'layout-update';
144
- /**
145
- * Path to the changed file
146
- */
147
- path?: string;
148
- /**
149
- * Optional message for error or debug info
150
- */
151
- message?: string;
152
- /**
153
- * Timestamp for cache busting
154
- */
155
- timestamp?: number;
156
- };
157
- /**
158
- * Adapter-agnostic interface for broadcasting development events to connected clients.
159
- * Implemented by both the Bun and Node client bridges.
160
- */
161
- export interface IClientBridge {
162
- broadcast(event: ClientBridgeEvent): void;
163
- reload(): void;
164
- cssUpdate(path: string): void;
165
- update(path: string): void;
166
- error(message: string): void;
167
- subscriberCount: number;
168
- }
169
- /**
170
- * Interface for the HMR Manager.
171
- * Used by integration plugins to register entrypoints and strategies.
172
- */
173
- export interface IHmrManager {
174
- /**
175
- * Registers an integration-owned client entrypoint to be built and watched.
176
- *
177
- * @remarks
178
- * This path is strict: the owning integration must emit the expected `_hmr`
179
- * bundle. Missing output is treated as a development pipeline failure.
180
- */
181
- registerEntrypoint(entrypointPath: string): Promise<string>;
182
- /**
183
- * Registers a generic script asset entrypoint to be built and watched.
184
- *
185
- * @remarks
186
- * This path exists for non-page script assets that are not owned by a
187
- * framework integration. Unlike `registerEntrypoint()`, it may use the generic
188
- * script bundling path.
189
- */
190
- registerScriptEntrypoint(entrypointPath: string): Promise<string>;
191
- /**
192
- * Registers mappings from bare specifiers to runtime URLs.
193
- *
194
- * @remarks
195
- * This is the shared registration seam for integration-owned runtime alias
196
- * maps. The registry may later back a broader import-map-style facility, but
197
- * the mappings themselves remain integration-owned.
198
- */
199
- registerSpecifierMap(map: Record<string, string>): void;
200
- /**
201
- * Registers a custom HMR strategy.
202
- */
203
- registerStrategy(strategy: HmrStrategy): void;
204
- /**
205
- * Sets the build plugins to use during bundling.
206
- */
207
- setPlugins(plugins: EcoBuildPlugin[]): void;
208
- /**
209
- * Enables or disables HMR.
210
- */
211
- setEnabled(enabled: boolean): void;
212
- /**
213
- * Returns whether HMR is enabled.
214
- */
215
- isEnabled(): boolean;
216
- /**
217
- * Broadcasts an HMR event to connected clients.
218
- */
219
- broadcast(event: ClientBridgeEvent): void;
220
- /**
221
- * Gets the output URL for a registered entrypoint.
222
- */
223
- getOutputUrl(entrypointPath: string): string | undefined;
224
- /**
225
- * Gets the map of watched files.
226
- */
227
- getWatchedFiles(): Map<string, string>;
228
- /**
229
- * Gets the registered bare-specifier map.
230
- */
231
- getSpecifierMap(): Map<string, string>;
232
- /**
233
- * Gets the HMR dist directory.
234
- */
235
- getDistDir(): string;
236
- /**
237
- * Gets the build plugins.
238
- */
239
- getPlugins(): EcoBuildPlugin[];
240
- /**
241
- * Gets the default HMR context.
242
- */
243
- getDefaultContext(): DefaultHmrContext;
244
- /**
245
- * Handles a file change event.
246
- */
247
- handleFileChange(path: string): Promise<void>;
248
- }
249
- /**
250
- * Represents the dependencies for an EcoComponent.
251
- */
252
- export type EcoComponentDependencies = {
253
- stylesheets?: Array<string | EcoComponentStylesheetEntry>;
254
- scripts?: Array<string | EcoComponentScriptEntry>;
255
- /**
256
- * Browser module declarations resolved from node_modules.
257
- *
258
- * Supports grammar entries such as `react-aria-components{Table,Select}`
259
- * to express explicit module imports for client bundles.
260
- */
261
- modules?: string[];
262
- components?: EcoComponent[];
263
- };
264
- export type EcoPagesElement = string | Promise<string>;
265
- /**
266
- * Serializable child payloads accepted by cross-integration deferred rendering.
267
- *
268
- * This models the broad value shapes that EcoPages already flattens when a
269
- * foreign component boundary serializes its children for another integration.
270
- * It is intentionally transport-oriented rather than framework-native, so it
271
- * can be shared across Kita, Lit, React, and Ecopages JSX authoring surfaces
272
- * without coupling core types to any one renderer.
273
- */
274
- export type EcoChildren = string | Promise<string> | number | bigint | boolean | null | undefined | readonly EcoChildren[] | {
275
- strings: readonly string[];
276
- values?: readonly EcoChildren[];
277
- } | {
278
- [key: string]: EcoChildren;
279
- };
280
- /**
281
- * Represents the input configuration for EcoPages.
282
- */
283
- export type EcoPagesConfig = Omit<Partial<EcoPagesAppConfig>, 'baseUrl' | 'derivedPaths' | 'templatesExt' | 'integrationsDependencies'> & Pick<EcoPagesAppConfig, 'baseUrl' | 'rootDir'>;
284
- /**
285
- * Internal metadata injected by eco-component-meta-plugin.
286
- * Contains component file path and integration info for dependency resolution.
287
- * @internal
288
- */
289
- export interface EcoInjectedMeta {
290
- /** Hashed identifier for client-side use (doesn't expose file paths) */
291
- id: string;
292
- /** Full file path of the component (use path.dirname() to get directory) */
293
- file: string;
294
- /** The integration identifier (e.g., 'react', 'kitajs', 'lit', 'ghtml', 'mdx') */
295
- integration: string;
296
- }
297
- export type EcoComponentConfig = {
298
- /** @internal Injected by eco-component-meta-plugin */
299
- __eco?: EcoInjectedMeta;
300
- /**
301
- * Explicit integration override for this component.
302
- * When provided, this takes precedence over auto-detected integration metadata.
303
- */
304
- integration?: string;
305
- /**
306
- * The layout component to wrap this page during rendering.
307
- *
308
- * The layout receives the page content as `children` and is responsible for
309
- * providing the page structure (header, footer, navigation, etc.).
310
- *
311
- * For React pages with client-side routing, the layout also handles the router context.
312
- * Use `EcoRouter` and `PageContent` from `@ecopages/react-router` in layouts that
313
- * need SPA navigation support.
314
- *
315
- * @example
316
- * ```tsx
317
- * // Simple layout (no routing)
318
- * const Layout = ({ children }) => <main>{children}</main>;
319
- *
320
- * // Layout with SPA routing
321
- * const Layout = ({ children }) => (
322
- * <EcoRouter page={...} pageProps={...}>
323
- * <Header />
324
- * <PageContent />
325
- * </EcoRouter>
326
- * );
327
- *
328
- * // Page using the layout
329
- * const MyPage = () => <h1>Hello</h1>;
330
- * MyPage.config = { layout: Layout };
331
- * ```
332
- */
333
- layout?: EcoPageLayoutComponent<any>;
334
- dependencies?: EcoComponentDependencies;
335
- /**
336
- * Internal: Resolved lazy scripts grouped by trigger.
337
- * Set by the renderer, used by eco.component() for multi-trigger auto-wrapping.
338
- * @internal
339
- */
340
- _resolvedLazyScripts?: ResolvedLazyScriptGroup[];
341
- /**
342
- * Internal: Resolved lazy triggers for the global injector map.
343
- * Set by the renderer in the default full orchestration flow.
344
- * @internal
345
- */
346
- _resolvedLazyTriggers?: ResolvedLazyTrigger[];
347
- };
348
- /**
349
- * The base structure for any EcoPages component.
350
- */
351
- export type EcoComponentBase = {
352
- /**
353
- * The configuration options for the EcoComponent.
354
- */
355
- config?: EcoComponentConfig;
356
- /**
357
- * Static paths for dynamic routes (consolidated eco.page API).
358
- * @internal Used by the renderer to retrieve static paths from the page component.
359
- */
360
- staticPaths?: GetStaticPaths;
361
- /**
362
- * Static props fetcher (consolidated eco.page API).
363
- * @internal Used by the renderer to retrieve static props from the page component.
364
- */
365
- staticProps?: GetStaticProps<any>;
366
- /**
367
- * Metadata generator (consolidated eco.page API).
368
- * @internal Used by the renderer to retrieve metadata from the page component.
369
- */
370
- metadata?: GetMetadata<any>;
371
- };
372
- /**
373
- * Checks if a type is `any`.
374
- */
375
- export type IsAny<T> = 0 extends 1 & T ? true : false;
376
- /**
377
- * A function component type that is framework-agnostic.
378
- * Uses a broader signature to support both direct calls and HOC wrappers.
379
- */
380
- export type EcoFunctionComponent<P, R> = {
381
- (props: P, ...args: any[]): R;
382
- } & EcoComponentBase;
383
- /**
384
- * Represents an EcoComponent.
385
- *
386
- * It can be defined by passing the props type as the first generic,
387
- * or by passing the component type itself to infer the signature.
388
- *
389
- * @template T - The type of the props object or the component function itself.
390
- * @template C - The type of the rendered element.
391
- *
392
- * @example
393
- * //1. Simplest usage
394
- * export const MyComponent: EcoComponent<{prop1: string}> = ({prop1}) => {
395
- * return <div>...</div>;
396
- * };
397
- *
398
- * @example
399
- * // 2. Using with HOCs like MobX observer (passing the props type)
400
- * export const MyObservedComponent: EcoComponent<object> = observer(function MyObservedComponent() {
401
- * return <div>...</div>;
402
- * });
403
- *
404
- * @example
405
- * // 3. Passing the full function signature (Perfect for Generic Components)
406
- * export const Select: EcoComponent<<T extends object>(props: SelectProps<T>) => JSX.Element> = <T extends object>({
407
- * label,
408
- * items,
409
- * }: SelectProps<T>) => {
410
- * return <select>...</select>;
411
- * };
412
- */
413
- /**
414
- * A function component type that is framework-agnostic.
415
- * Uses a broader signature to support both direct calls and HOC wrappers.
416
- */
417
- export type EcoComponent<P = any, R = any> = IsAny<P> extends true ? EcoFunctionComponent<any, any> | EcoComponentBase : P extends (props: infer Props, ...args: any[]) => infer Return ? EcoFunctionComponent<Props, Return> : EcoFunctionComponent<P, R>;
418
- /**
419
- * Represents a page in EcoPages.
420
- */
421
- export type PageProps<T = unknown> = T & StaticPageContext & {
422
- locals?: RequestLocals;
423
- };
424
- /**
425
- * Represents the metadata for a page.
426
- */
427
- export interface PageMetadataProps {
428
- title: string;
429
- description: string;
430
- image?: string;
431
- url?: string;
432
- keywords?: string[];
433
- }
434
- /**
435
- * Represents the props for the head of a page.
436
- */
437
- export interface PageHeadProps<T = EcoPagesElement> {
438
- metadata: PageMetadataProps;
439
- dependencies?: EcoComponentDependencies;
440
- children?: T;
441
- }
442
- /**
443
- * Represents the props for a route layout.
444
- */
445
- export interface LayoutProps<T = EcoPagesElement> extends Partial<RequestPageContext> {
446
- children: T;
447
- }
448
- /**
449
- * Represents the props for the HTML template of a page.
450
- */
451
- export interface HtmlTemplateProps extends PageHeadProps {
452
- children: EcoPagesElement;
453
- language?: string;
454
- headContent?: EcoPagesElement;
455
- pageProps: Record<string, unknown>;
456
- }
457
- /**
458
- * Layout components accepted by pages.
459
- *
460
- * This preserves compatibility with existing `eco.component()` layouts while
461
- * also supporting semantic `eco.layout()` declarations.
462
- */
463
- export type EcoPageLayoutComponent<T = EcoPagesElement> = EcoLayoutComponent<T> | EcoComponent<any, T>;
464
- /**
465
- * Represents a layout component created with eco.layout().
466
- */
467
- export type EcoLayoutComponent<T = EcoPagesElement> = EcoComponent<LayoutProps<T>, T>;
468
- /**
469
- * Represents an HTML shell component created with eco.html().
470
- */
471
- export type EcoHtmlComponent<T = EcoPagesElement> = EcoComponent<HtmlTemplateProps, T>;
472
- /**
473
- * Represents the props for the error 404 template.
474
- */
475
- export interface Error404TemplateProps extends Omit<HtmlTemplateProps, 'children'> {
476
- message: string;
477
- stack?: string;
478
- }
479
- /**
480
- * Represents the parameters for a page.
481
- * The keys are strings, and the values can be either a string or an array of strings.
482
- */
483
- export type PageParams = Record<string, string | string[]>;
484
- /**
485
- * Represents a query object for a page.
486
- * The keys are strings and the values can be either a string or an array of strings.
487
- */
488
- export type PageQuery = Record<string, string | string[]>;
489
- /**
490
- * Request-scoped data that is only available during request-time rendering.
491
- *
492
- * Apps should augment this interface via module augmentation:
493
- *
494
- * declare module '@ecopages/core' {
495
- * interface RequestLocals { session?: Session | null }
496
- * }
497
- */
498
- export interface RequestLocals {
499
- }
500
- /**
501
- * Represents the context object for a static page.
502
- */
503
- export type StaticPageContext = {
504
- params?: PageParams;
505
- query?: PageQuery;
506
- };
507
- /**
508
- * Request-time page context.
509
- *
510
- * This is only populated during SSR. Static generation must not access locals.
511
- */
512
- export type RequestPageContext = {
513
- locals: RequestLocals;
514
- };
515
- /**
516
- * Adds optional `locals` to a props type.
517
- * Primarily used for layouts that may receive request-scoped data from middleware.
518
- *
519
- * @template P - The base props type
520
- *
521
- * @example
522
- * ```ts
523
- * type MyLayoutProps = WithLocals<{ children: ReactNode }>;
524
- * // { children: ReactNode; locals?: RequestLocals }
525
- * ```
526
- */
527
- export type WithLocals<P> = P & {
528
- locals?: RequestLocals;
529
- };
530
- /**
531
- * Represents the params for a static path.
532
- */
533
- export type StaticPath = {
534
- params: PageParams;
535
- };
536
- /**
537
- * The function that returns the static paths for a page.
538
- */
539
- export type GetStaticPaths = (context: {
540
- appConfig: EcoPagesAppConfig;
541
- runtimeOrigin: string;
542
- }) => Promise<{
543
- paths: StaticPath[];
544
- }>;
545
- /**
546
- * The context object for the getMetadata function.
547
- */
548
- export type GetMetadataContext<T = Record<string, unknown>> = Required<StaticPageContext> & {
549
- props: T;
550
- appConfig: EcoPagesAppConfig;
551
- };
552
- /**
553
- * The function that returns the metadata for a page.
554
- */
555
- export type GetMetadata<T = Record<string, unknown>> = (context: GetMetadataContext<T>) => PageMetadataProps | Promise<PageMetadataProps>;
556
- /**
557
- * The function that returns the static props for a page.
558
- */
559
- export type GetStaticProps<T> = (context: {
560
- pathname: StaticPath;
561
- appConfig: EcoPagesAppConfig;
562
- runtimeOrigin: string;
563
- }) => Promise<{
564
- props: T;
565
- }>;
566
- /**
567
- * Represents a page file in EcoPages.
568
- * @template T - The type of the page props.
569
- */
570
- export type EcoPageFile<T = unknown> = T & {
571
- default: EcoComponent<any, any>;
572
- getStaticPaths?: GetStaticPaths;
573
- getStaticProps?: GetStaticProps<Record<string, unknown>>;
574
- getMetadata?: GetMetadata;
575
- cache?: CacheStrategy;
576
- };
577
- /**
578
- * Represents a CSS processor.
579
- */
580
- export interface CssProcessor {
581
- /**
582
- * Processes a CSS file at the specified path.
583
- * @param path - The path to the CSS file.
584
- * @returns A promise that resolves to the processed CSS as a string.
585
- */
586
- processPath: (path: string, options?: any) => Promise<string>;
587
- /**
588
- * Processes a CSS string or buffer.
589
- * @param contents - The CSS contents as a string or buffer.
590
- * @returns A promise that resolves to the processed CSS as a string.
591
- */
592
- processStringOrBuffer: (contents: string | Buffer, options?: any) => Promise<string>;
593
- }
594
- /**
595
- * The options for the route renderer.
596
- */
597
- export type RouteRendererOptions = {
598
- file: string;
599
- params?: PageParams;
600
- query?: PageQuery;
601
- locals?: RequestLocals;
602
- };
603
- /**
604
- * The body of the route renderer.
605
- */
606
- export type RouteRendererBody = BodyInit | Readable;
607
- /**
608
- * Result of rendering a route, including body and optional cache configuration.
609
- */
610
- export type RouteRenderResult = {
611
- body: RouteRendererBody;
612
- /** Cache strategy from page component's eco.page({ cache }) option */
613
- cacheStrategy?: CacheStrategy;
614
- };
615
- /**
616
- * Represents the dependencies required for an integration plugin.
617
- * It combines the base integration plugin dependencies with specific integration plugin dependencies.
618
- */
619
- export type IntegrationPluginDependencies = BaseIntegrationPluginDependencies & SpecificIntegrationPluginDependencies;
620
- type BaseIntegrationPluginDependencies = {
621
- inline?: boolean;
622
- };
623
- /**
624
- * Represents the dependencies required for a specific integration plugin.
625
- * It can be one of the following types:
626
- * {@link ScriptImportIntegrationPluginDependencies}
627
- * {@link ScriptContentIntegrationPluginDependencies}
628
- * {@link StylesheetImportIntegrationPluginDependencies}
629
- * {@link StylesheetContentIntegrationPluginDependencies}
630
- */
631
- type SpecificIntegrationPluginDependencies = ScriptImportIntegrationPluginDependencies | ScriptContentIntegrationPluginDependencies | StylesheetImportIntegrationPluginDependencies | StylesheetContentIntegrationPluginDependencies;
632
- /**
633
- * Script dependencies for an integration plugin with an import path.
634
- */
635
- type ScriptImportIntegrationPluginDependencies = {
636
- kind: 'script';
637
- importPath: string;
638
- position?: 'head' | 'body';
639
- /** @default true */
640
- minify?: boolean;
641
- };
642
- /**
643
- * Script dependencies for an integration plugin with content.
644
- */
645
- type ScriptContentIntegrationPluginDependencies = {
646
- kind: 'script';
647
- content: string;
648
- position?: 'head' | 'body';
649
- /** @default true */
650
- minify?: boolean;
651
- };
652
- /**
653
- * Stylesheet dependencies for an integration plugin with an import path.
654
- */
655
- type StylesheetImportIntegrationPluginDependencies = {
656
- kind: 'stylesheet';
657
- importPath: string;
658
- };
659
- /**
660
- * Stylesheet dependencies for an integration plugin with content.
661
- */
662
- type StylesheetContentIntegrationPluginDependencies = {
663
- kind: 'stylesheet';
664
- content: string;
665
- };
666
- /**
667
- * The options for the integration renderer.
668
- */
669
- export type IntegrationRendererRenderOptions<C = EcoPagesElement> = RouteRendererOptions & {
670
- props?: Record<string, unknown>;
671
- metadata: PageMetadataProps;
672
- HtmlTemplate: EcoHtmlComponent<C>;
673
- Page: EcoComponent<PageProps, C>;
674
- Layout?: EcoPageLayoutComponent<any>;
675
- dependencies?: EcoComponentDependencies;
676
- resolvedDependencies: ProcessedAsset[];
677
- componentRender?: ComponentRenderResult;
678
- pageProps?: Record<string, unknown>;
679
- cacheStrategy?: CacheStrategy;
680
- pageLocals?: RequestLocals;
681
- boundaryPlan?: BoundaryPlan;
682
- };
683
- export type BoundaryValidationErrorCode = 'UNKNOWN_INTEGRATION_OWNER' | 'MISSING_COMPONENT_METADATA';
684
- export interface BoundaryValidationError {
685
- code: BoundaryValidationErrorCode;
686
- message: string;
687
- componentId?: string;
688
- componentFile?: string;
689
- integrationName?: string;
690
- }
691
- export type BoundaryPlanNodeSource = 'route' | 'page' | 'layout' | 'html-template' | 'dependency';
692
- export interface BoundaryOwnership {
693
- integrationName: string;
694
- componentId: string;
695
- componentFile?: string;
696
- isPageEntry: boolean;
697
- isForeignToParent: boolean;
698
- }
699
- export interface BoundaryPlanNode {
700
- id: string;
701
- source: BoundaryPlanNodeSource;
702
- ownership: BoundaryOwnership;
703
- children: BoundaryPlanNode[];
704
- declaredDependenciesValid: boolean;
705
- }
706
- export interface BoundaryPlan {
707
- root: BoundaryPlanNode;
708
- rendererNames: string[];
709
- foreignEdgeCount: number;
710
- hasValidationErrors: boolean;
711
- validationErrors: BoundaryValidationError[];
712
- }
713
- export type BoundaryAttachmentPolicy = {
714
- kind: 'none';
715
- } | {
716
- kind: 'first-element';
717
- };
718
- export interface BoundaryRenderPayload {
719
- html: string;
720
- assets: ProcessedAsset[];
721
- rootTag?: string;
722
- rootAttributes?: Record<string, string>;
723
- attachmentPolicy: BoundaryAttachmentPolicy;
724
- integrationName: string;
725
- }
726
- /**
727
- * Shared execution-scoped context threaded through component boundary renders.
728
- *
729
- * Integrations can extend this with renderer-local runtime keys, but the cache
730
- * and optional component instance identity are shared across all renderers.
731
- */
732
- export interface BaseIntegrationContext {
733
- rendererCache?: Map<string, unknown>;
734
- componentInstanceId?: string;
735
- }
736
- export interface ComponentRenderInput<TIntegrationContext extends BaseIntegrationContext = BaseIntegrationContext> {
737
- component: EcoComponent;
738
- props: Record<string, unknown>;
739
- children?: unknown;
740
- integrationContext?: TIntegrationContext;
741
- }
742
- export interface ComponentRenderResult {
743
- html: string;
744
- canAttachAttributes: boolean;
745
- rootTag?: string;
746
- integrationName: string;
747
- rootAttributes?: Record<string, string>;
748
- assets?: ProcessedAsset[];
749
- }
750
- /**
751
- * Represents a deep required type for a given object
752
- */
753
- export type DeepRequired<T> = Required<{
754
- [K in keyof T]: T[K] extends Required<T[K]> ? T[K] : DeepRequired<T[K]>;
755
- }>;
756
- /**
757
- * The Prettify helper is a utility type that takes an object type and makes the hover overlay more readable.
758
- */
759
- export type Prettify<T> = {
760
- [K in keyof T]: T[K];
761
- } & {};
762
- /**
763
- * Services available to API handlers.
764
- */
765
- export interface ApiHandlerServices {
766
- /**
767
- * Cache invalidation service.
768
- * Null when caching is disabled.
769
- */
770
- cache: CacheInvalidator | null;
771
- }
772
- /**
773
- * Options for rendering a view.
774
- */
775
- export interface RenderOptions {
776
- status?: number;
777
- headers?: HeadersInit;
778
- }
779
- /**
780
- * Options for JSON/HTML response helpers.
781
- */
782
- export interface ResponseOptions {
783
- status?: number;
784
- headers?: HeadersInit;
785
- }
786
- /**
787
- * Context for rendering views in route handlers.
788
- * Provides methods to render eco.page views and return formatted responses.
789
- */
790
- export interface RenderContext {
791
- /**
792
- * Render an eco.page view with full layout and includes.
793
- * @param view - The eco.page component to render
794
- * @param props - Props to pass to the view
795
- * @param options - Optional status code and headers
796
- */
797
- render<P = Record<string, unknown>>(view: EcoComponent<P>, props?: P, options?: RenderOptions): Promise<Response>;
798
- /**
799
- * Render an eco.page view without layout (for partials/fragments).
800
- * @param view - The eco.page component to render
801
- * @param props - Props to pass to the view
802
- * @param options - Optional status code and headers
803
- */
804
- renderPartial<P = Record<string, unknown>>(view: EcoComponent<P>, props: P, options?: RenderOptions): Promise<Response>;
805
- /**
806
- * Return a JSON response.
807
- * @param data - Data to serialize as JSON
808
- * @param options - Optional status code and headers
809
- */
810
- json(data: unknown, options?: ResponseOptions): Response;
811
- /**
812
- * Return an HTML response.
813
- * @param content - HTML string content
814
- * @param options - Optional status code and headers
815
- */
816
- html(content: string, options?: ResponseOptions): Response;
817
- }
818
- /**
819
- * Context provided to the API handler.
820
- */
821
- export interface ApiHandlerContext<TRequest extends Request = Request, TServer = any> extends RenderContext {
822
- request: TRequest;
823
- params: Record<string, string>;
824
- response: ApiResponseBuilder;
825
- server: TServer;
826
- /**
827
- * Request-scoped data store.
828
- * Only valid during request-time handling (SSR/API). Must not be used for static generation.
829
- */
830
- locals: RequestLocals;
831
- /**
832
- * Require one or more locals keys. If missing, executes `onMissing` to produce a terminating Response.
833
- */
834
- require: {
835
- <K extends keyof RequestLocals>(key: K, onMissing: () => Response): Exclude<RequestLocals[K], null | undefined>;
836
- <K extends keyof RequestLocals>(keys: readonly K[], onMissing: () => Response): {
837
- [P in K]-?: Exclude<RequestLocals[P], null | undefined>;
838
- };
839
- };
840
- /**
841
- * Services available to the API handler.
842
- */
843
- services: ApiHandlerServices;
844
- /**
845
- * Parsed and optionally validated request body.
846
- *
847
- * - Without schema: Contains the parsed JSON body as `unknown`
848
- * - With schema: Contains the validated and type-safe body data
849
- *
850
- * For raw access to the request body stream, use `ctx.request.body`.
851
- *
852
- * @example Without validation
853
- * ```typescript
854
- * app.post('/posts', async (ctx) => {
855
- * const data = ctx.body; // [unknown] - parsed JSON
856
- * return ctx.json({ received: data });
857
- * });
858
- * ```
859
- *
860
- * @example With validation
861
- * ```typescript
862
- * import { z } from 'zod';
863
- *
864
- * app.post('/posts', async (ctx) => {
865
- * const { title, author } = ctx.body; // [type-safe]
866
- * return ctx.json({ title, author });
867
- * }, {
868
- * schema: {
869
- * body: z.object({ title: z.string(), author: z.string() })
870
- * }
871
- * });
872
- * ```
873
- *
874
- * Validation runs before the handler executes. Invalid requests receive a 400 response.
875
- */
876
- body?: unknown;
877
- /**
878
- * Parsed and optionally validated query parameters.
879
- *
880
- * - Without schema: Contains the parsed query params as a string record
881
- * - With schema: Contains the validated and type-safe query data
882
- *
883
- * For raw access to query parameters, use `ctx.request.url` and parse manually.
884
- *
885
- * @example Pagination with type coercion
886
- * ```typescript
887
- * import { z } from 'zod';
888
- *
889
- * app.get('/posts', async (ctx) => {
890
- * const { page, limit, sortBy } = ctx.query;
891
- * // page: number, limit: number, sortBy: 'date' | 'title' | 'views'
892
- * return ctx.json({ page, limit, sortBy });
893
- * }, {
894
- * schema: {
895
- * query: z.object({
896
- * page: z.coerce.number().min(1).default(1),
897
- * limit: z.coerce.number().min(1).max(100).default(20),
898
- * sortBy: z.enum(['date', 'title', 'views']).default('date')
899
- * })
900
- * }
901
- * });
902
- * ```
903
- *
904
- * @example Search with filters
905
- * ```typescript
906
- * app.get('/search', async (ctx) => {
907
- * const { q, category } = ctx.query;
908
- * return ctx.json({ results: await search(q, category) });
909
- * }, {
910
- * schema: {
911
- * query: z.object({
912
- * q: z.string().min(2).max(100),
913
- * category: z.enum(['posts', 'users', 'comments']).optional()
914
- * })
915
- * }
916
- * });
917
- * ```
918
- */
919
- query?: unknown;
920
- /**
921
- * Parsed and optionally validated request headers.
922
- *
923
- * - Without schema: Contains the parsed headers as a string record
924
- * - With schema: Contains the validated and type-safe header data
925
- *
926
- * For raw access to headers, use `ctx.request.headers`.
927
- *
928
- * @example API key authentication
929
- * ```typescript
930
- * import { z } from 'zod';
931
- *
932
- * app.post('/api/webhooks', async (ctx) => {
933
- * const apiKey = ctx.headers['x-api-key'];
934
- * // apiKey is guaranteed to be a valid UUID
935
- * return ctx.json({ received: true });
936
- * }, {
937
- * schema: {
938
- * headers: z.object({
939
- * 'x-api-key': z.string().uuid()
940
- * })
941
- * }
942
- * });
943
- * ```
944
- *
945
- * @example Webhook signature validation
946
- * ```typescript
947
- * app.post('/webhooks/stripe', async (ctx) => {
948
- * const signature = ctx.headers['stripe-signature'];
949
- * // signature is guaranteed to exist
950
- * const isValid = verifyStripeSignature(ctx.body, signature);
951
- * return ctx.json({ verified: isValid });
952
- * }, {
953
- * schema: {
954
- * headers: z.object({
955
- * 'stripe-signature': z.string().min(1)
956
- * })
957
- * }
958
- * });
959
- * ```
960
- *
961
- * @example Content negotiation
962
- * ```typescript
963
- * app.post('/api/data', async (ctx) => {
964
- * const { accept } = ctx.headers;
965
- * if (accept === 'application/xml') {
966
- * return ctx.html(toXml(data), { headers: { 'Content-Type': 'application/xml' } });
967
- * }
968
- * return ctx.json(data);
969
- * }, {
970
- * schema: {
971
- * headers: z.object({
972
- * 'content-type': z.literal('application/json'),
973
- * accept: z.enum(['application/json', 'application/xml']).optional()
974
- * })
975
- * }
976
- * });
977
- * ```
978
- */
979
- headers?: unknown;
980
- }
981
- /**
982
- * Next function for middleware chain.
983
- * Call to continue to the next middleware or final handler.
984
- */
985
- export type MiddlewareNext = () => Promise<Response>;
986
- /**
987
- * Middleware function signature.
988
- * Receives the request context and a next function to continue the chain.
989
- * Can short-circuit by returning a Response directly without calling next().
990
- *
991
- * @typeParam TRequest - Request type
992
- * @typeParam TServer - Server type
993
- * @typeParam TContext - Extended context type, defaults to base ApiHandlerContext
994
- *
995
- * @example Basic middleware (no context extension)
996
- * ```typescript
997
- * const loggingMiddleware: Middleware = async (ctx, next) => {
998
- * console.log(`${ctx.request.method} ${ctx.request.url}`);
999
- * return next();
1000
- * };
1001
- * ```
1002
- *
1003
- * @example Middleware with extended context (use EcoMiddleware helper)
1004
- * ```typescript
1005
- * type AuthContext = ApiHandlerContext<BunRequest<string>, Server> & { user: User };
1006
- *
1007
- * const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
1008
- * const user = await authenticate(ctx.request);
1009
- * if (!user) return ctx.response.status(401).json({ error: 'Unauthorized' });
1010
- * ctx.user = user;
1011
- * return next();
1012
- * };
1013
- * ```
1014
- */
1015
- export type Middleware<TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> = (context: TContext, next: MiddlewareNext) => Promise<Response> | Response;
1016
- /**
1017
- * Helper type for defining middleware with extended context.
1018
- * Automatically infers TRequest and TServer from the provided context type.
1019
- *
1020
- * @typeParam TContext - The extended context type that includes TRequest and TServer
1021
- *
1022
- * @example
1023
- * ```typescript
1024
- * type AuthContext = ApiHandlerContext<BunRequest<string>, Server> & {
1025
- * session: { user: User };
1026
- * };
1027
- *
1028
- * const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
1029
- * const session = await authenticate(ctx.request);
1030
- * if (!session) return Response.redirect('/login');
1031
- * ctx.session = session;
1032
- * return next();
1033
- * };
1034
- * ```
1035
- */
1036
- export type EcoMiddleware<TContext extends ApiHandlerContext<any, any>> = TContext extends ApiHandlerContext<infer TRequest, infer TServer> ? Middleware<TRequest, TServer, TContext> : never;
1037
- /**
1038
- * Represents an API handler in EcoPages.
1039
- * Defines the path, method, handler function, optional middleware, and validation schemas.
1040
- *
1041
- * @example Basic handler
1042
- * ```typescript
1043
- * app.get('/users/:id', async (ctx) => {
1044
- * return ctx.json({ id: ctx.params.id });
1045
- * });
1046
- * ```
1047
- *
1048
- * @example With validation
1049
- * ```typescript
1050
- * import { z } from 'zod';
1051
- *
1052
- * app.post('/posts', async (ctx) => {
1053
- * const { title, content } = ctx.body;
1054
- * return ctx.json({ success: true, title, content });
1055
- * }, {
1056
- * schema: {
1057
- * body: z.object({
1058
- * title: z.string().min(3),
1059
- * content: z.string()
1060
- * })
1061
- * }
1062
- * });
1063
- * ```
1064
- *
1065
- * @example With middleware
1066
- * ```typescript
1067
- * const authMiddleware = async (ctx, next) => {
1068
- * if (!ctx.request.headers.get('authorization')) {
1069
- * return ctx.response.status(401).json({ error: 'Unauthorized' });
1070
- * }
1071
- * return next();
1072
- * };
1073
- *
1074
- * app.get('/protected', async (ctx) => {
1075
- * return ctx.json({ message: 'Secret data' });
1076
- * }, {
1077
- * middleware: [authMiddleware]
1078
- * });
1079
- * ```
1080
- *
1081
- * @example Multiple validations
1082
- * ```typescript
1083
- * import { z } from 'zod';
1084
- *
1085
- * app.post('/api/search', async (ctx) => {
1086
- * const { q, page } = ctx.query;
1087
- * const filters = ctx.body;
1088
- * return ctx.json({ query: q, page, filters });
1089
- * }, {
1090
- * schema: {
1091
- * query: z.object({ q: z.string(), page: z.string() }),
1092
- * body: z.object({ category: z.string().optional() })
1093
- * }
1094
- * });
1095
- * ```
1096
- */
1097
- export interface ApiHandler<TPath extends string = string, TRequest extends Request = Request, TServer = any> {
1098
- path: TPath;
1099
- method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
1100
- handler: (context: ApiHandlerContext<TRequest, TServer>) => Promise<Response> | Response;
1101
- /** Optional middleware chain executed before the handler */
1102
- middleware?: Middleware<TRequest, TServer, any>[];
1103
- /** Optional validation schemas for request body, query parameters, and headers */
1104
- schema?: {
1105
- body?: StandardSchema;
1106
- query?: StandardSchema;
1107
- headers?: StandardSchema;
1108
- params?: StandardSchema;
1109
- };
1110
- }
1111
- /**
1112
- * Global error handler for centralized error handling across all routes.
1113
- * Receives the error and full request context, returns a Response.
1114
- * Falls back to default handling if the handler itself throws.
1115
- */
1116
- export type ErrorHandler<TRequest extends Request = Request, TServer = any> = (error: unknown, context: ApiHandlerContext<TRequest, TServer>) => Promise<Response> | Response;
1117
- /**
1118
- * Options for route handlers.
1119
- */
1120
- export interface RouteOptions<TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> {
1121
- middleware?: Middleware<TRequest, TServer, TContext>[];
1122
- schema?: RouteSchema;
1123
- }
1124
- export interface RouteSchema {
1125
- body?: StandardSchema;
1126
- query?: StandardSchema;
1127
- headers?: StandardSchema;
1128
- params?: StandardSchema;
1129
- }
1130
- /**
1131
- * Helper type to extract inferred types from a schema, with fallback to unknown.
1132
- */
1133
- export type InferSchemaOutput<T> = T extends StandardSchema ? InferOutput<T> : unknown;
1134
- /**
1135
- * Context with typed body/query/headers based on the provided schema.
1136
- */
1137
- export type TypedApiHandlerContext<TSchema extends RouteSchema, TRequest extends Request = Request, TServer = any> = Omit<ApiHandlerContext<TRequest, TServer>, 'body' | 'query' | 'headers'> & {
1138
- body: InferSchemaOutput<TSchema['body']>;
1139
- query: InferSchemaOutput<TSchema['query']>;
1140
- headers: InferSchemaOutput<TSchema['headers']>;
1141
- params: InferSchemaOutput<TSchema['params']>;
1142
- };
1143
- /**
1144
- * Options for the group method.
1145
- *
1146
- * @typeParam TContext - Extended context type that middleware provides to handlers
1147
- *
1148
- * @example Group with auth middleware extending context
1149
- * ```typescript
1150
- * type AuthContext = ApiHandlerContext<BunRequest<string>, Server> & { user: User };
1151
- *
1152
- * app.group<AuthContext>('/api', (r) => {
1153
- * r.get('/profile', (ctx) => {
1154
- * // ctx.user is properly typed!
1155
- * return ctx.json({ name: ctx.user.name });
1156
- * });
1157
- * }, { middleware: [authMiddleware] });
1158
- * ```
1159
- */
1160
- export interface GroupOptions<TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> {
1161
- middleware?: Middleware<TRequest, TServer, TContext>[];
1162
- }
1163
- /**
1164
- * Context type that combines schema-typed fields with an extended base context.
1165
- * Used by RouteGroupBuilder to merge schema validation types with middleware-extended context.
1166
- * Note: Path parameter typing (e.g., :id -> params.id) comes from the TContext.request type.
1167
- */
1168
- export type TypedGroupHandlerContext<TSchema extends RouteSchema, TContext extends ApiHandlerContext<any, any>> = Omit<TContext, 'body' | 'query' | 'headers' | 'params'> & {
1169
- body: InferSchemaOutput<TSchema['body']>;
1170
- query: InferSchemaOutput<TSchema['query']>;
1171
- headers: InferSchemaOutput<TSchema['headers']>;
1172
- params: InferSchemaOutput<TSchema['params']>;
1173
- };
1174
- /**
1175
- * Builder interface for defining routes within a group.
1176
- * Provides chainable methods for registering routes with shared prefix and middleware.
1177
- *
1178
- * @typeParam TRequest - The request type
1179
- * @typeParam TServer - The server type
1180
- * @typeParam TContext - Extended context type from group middleware
1181
- */
1182
- export interface RouteGroupBuilder<TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> {
1183
- get<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1184
- schema?: TSchema;
1185
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1186
- post<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1187
- schema?: TSchema;
1188
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1189
- put<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1190
- schema?: TSchema;
1191
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1192
- delete<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1193
- schema?: TSchema;
1194
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1195
- patch<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1196
- schema?: TSchema;
1197
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1198
- options<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1199
- schema?: TSchema;
1200
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1201
- head<P extends string, TSchema extends RouteSchema = RouteSchema>(path: P, handler: (context: TypedGroupHandlerContext<TSchema, TContext>) => Promise<Response> | Response, options?: RouteOptions<TRequest, TServer, TContext> & {
1202
- schema?: TSchema;
1203
- }): RouteGroupBuilder<TRequest, TServer, TContext>;
1204
- }
1205
- /**
1206
- * A function that dynamically imports a view module.
1207
- * Used by app.static() to enable HMR in development.
1208
- */
1209
- export type ViewLoader<P = any> = () => Promise<{
1210
- default: EcoPageComponent<P>;
1211
- }>;
1212
- /**
1213
- * Represents a static route registered via app.static().
1214
- * Uses a loader function to enable HMR in development mode.
1215
- */
1216
- export interface StaticRoute<P = any> {
1217
- path: string;
1218
- loader: ViewLoader<P>;
1219
- }