@ecopages/core 0.2.0-alpha.9 → 0.2.1

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