@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.9

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