@ecopages/core 0.8.0 → 0.10.0
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.
- package/README.md +2 -2
- package/package.json +14 -4
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +1 -1
- package/src/adapters/node/server-adapter.d.ts +1 -0
- package/src/adapters/node/server-adapter.js +4 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
- package/src/adapters/shared/hmr/hmr-manager.js +8 -4
- package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
- package/src/adapters/shared/http/api-request-pipeline.js +23 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
- package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
- package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
- package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
- package/src/adapters/shared/http/run-middleware-chain.js +108 -10
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +6 -21
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
- package/src/adapters/shared/runtime/server-static-builder.js +4 -1
- package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
- package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
- package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
- package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
- package/src/assets/app-browser-client-build.js +3 -0
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
- package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
- package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
- package/src/build/build-graph.d.ts +19 -2
- package/src/build/build-graph.js +19 -18
- package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
- package/src/build/cache/pages-unified-graph-build.js +14 -51
- package/src/build/cache/server-module-entries.d.ts +5 -9
- package/src/build/cache/server-module-entries.js +5 -58
- package/src/build/contracts/build-contracts.d.ts +15 -0
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/production-asset-ledger.d.ts +1 -1
- package/src/build/production-asset-ledger.js +4 -2
- package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
- package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
- package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
- package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
- package/src/build/runtime/build-request-policy.js +4 -1
- package/src/build/server/server-modules-manifest.d.ts +6 -1
- package/src/build/server/server-modules-manifest.js +10 -1
- package/src/build/server/view-reference.d.ts +9 -0
- package/src/build/server/view-reference.js +11 -0
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/cli.d.ts +14 -0
- package/src/cli.js +14 -0
- package/src/config/assembly/app-runtime.d.ts +13 -0
- package/src/config/assembly/app-runtime.js +2 -0
- package/src/config/assembly/finalize-config.js +13 -8
- package/src/config/internal-types.d.ts +0 -12
- package/src/config/resolve-eco-config-path.d.ts +2 -0
- package/src/config/resolve-eco-config-path.js +2 -1
- package/src/config/server-config-bundle.d.ts +0 -1
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +0 -12
- package/src/declarations.d.ts +2 -0
- package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
- package/src/dev/invalidation/development-invalidation.service.js +1 -11
- package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
- package/src/eco/discovered-dependencies.d.ts +5 -0
- package/src/eco/discovered-dependencies.js +9 -0
- package/src/eco/eco.browser.js +6 -26
- package/src/eco/eco.js +24 -16
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- package/src/eco/page-data-hooks.d.ts +27 -0
- package/src/eco/page-data-hooks.js +64 -0
- package/src/eco/page-layout-normalization.d.ts +2 -2
- package/src/hmr/client/hmr-runtime.js +1 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
- package/src/html/html-rewriter.d.ts +9 -7
- package/src/html/html-rewriter.js +26 -41
- package/src/html/html-transformer.service.d.ts +2 -2
- package/src/html/html-transformer.service.js +21 -15
- package/src/html-pages/html-page-module-scripts.js +2 -1
- package/src/html-pages/html-pages.plugin.d.ts +1 -1
- package/src/html-pages/html-pages.plugin.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/integration.d.ts +2 -2
- package/src/integration.js +2 -2
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- package/src/middleware/create-middleware.d.ts +41 -0
- package/src/middleware/create-middleware.js +72 -0
- package/src/plugins/component-import-discovery.d.ts +14 -1
- package/src/plugins/component-import-discovery.js +36 -16
- package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
- package/src/plugins/eco-component-meta-plugin.js +208 -44
- package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
- package/src/plugins/ecopages-virtual-imports.js +25 -0
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/integration-plugin.js +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
- package/src/plugins/tsconfig-import-resolver.js +7 -5
- package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
- package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
- package/src/route-renderer/explicit-view-render-preparation.js +63 -11
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
- package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
- package/src/route-renderer/orchestration/integration-renderer.js +83 -43
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
- package/src/route-renderer/page-declaration.d.ts +25 -0
- package/src/route-renderer/page-declaration.js +39 -0
- package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
- package/src/route-renderer/page-loading/component-declarations.js +77 -0
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
- package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
- package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
- package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
- package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
- package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
- package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
- package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
- package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
- package/src/route-renderer/page-loading/page-module-loader.js +66 -35
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
- package/src/router/server/pages-dir.d.ts +7 -0
- package/src/router/server/pages-dir.js +7 -0
- package/src/router/server/route-registry.d.ts +22 -10
- package/src/router/server/route-registry.js +54 -23
- package/src/router/server/segment-path-matcher.d.ts +29 -5
- package/src/router/server/segment-path-matcher.js +22 -19
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
- package/src/static-site-generator/static-site-generator.d.ts +17 -2
- package/src/static-site-generator/static-site-generator.js +52 -18
- package/src/types/contracts.d.ts +216 -160
- package/src/types/eco-api-types.d.ts +86 -51
- package/src/types/locals-brand.d.ts +9 -0
- package/src/types/locals-brand.js +9 -0
- package/src/types/middleware-types.d.ts +143 -0
- package/src/types/middleware-types.js +1 -0
- package/src/types/public-types.d.ts +3 -2
- package/src/utils/file-roles.d.ts +48 -0
- package/src/utils/file-roles.js +85 -0
- package/src/utils/node-builtin.d.ts +10 -0
- package/src/utils/node-builtin.js +13 -0
- package/src/watchers/project-watcher.js +2 -2
- package/src/build/contracts/server-only-specifier.d.ts +0 -8
- package/src/build/contracts/server-only-specifier.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
- package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
- package/src/utils/endpoint-file-extensions.d.ts +0 -11
- package/src/utils/endpoint-file-extensions.js +0 -13
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -34
package/src/types/contracts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import type { ComponentIdentity } from './component-identity.js';
|
|
3
|
+
import type { ApiMiddlewareEntry, ListLocals, PageMiddlewareEntry } from './middleware-types.js';
|
|
3
4
|
import type { ViewReference } from './view-reference.js';
|
|
4
5
|
import type { ApiResponseBuilder } from './api-response.js';
|
|
5
6
|
import type { AssetDefinition, ProcessedAsset } from './asset-types.js';
|
|
@@ -18,8 +19,6 @@ export type HmrStrategyContract = {
|
|
|
18
19
|
ownsDevTransformEntrypoint(sourcePath: string, variant?: string): boolean;
|
|
19
20
|
process(filePath: string): Promise<HmrAction>;
|
|
20
21
|
};
|
|
21
|
-
type RequiresKeys = keyof RequestLocals;
|
|
22
|
-
export type PageRequires<K extends RequiresKeys = RequiresKeys> = K | readonly K[];
|
|
23
22
|
export type GetPageDependenciesContext<T = Record<string, unknown>> = {
|
|
24
23
|
props: PagePropsFor<T>;
|
|
25
24
|
params?: PageParams;
|
|
@@ -33,6 +32,16 @@ export type PageDependenciesResult = FileOwnedDependencyContribution & {
|
|
|
33
32
|
};
|
|
34
33
|
export type GetPageDependencies<T = Record<string, unknown>> = (context: GetPageDependenciesContext<T>) => PageDependenciesResult | undefined | Promise<PageDependenciesResult | undefined>;
|
|
35
34
|
export type PageDependenciesInput<T = Record<string, unknown>> = EcoComponentDependencies | GetPageDependencies<T>;
|
|
35
|
+
/**
|
|
36
|
+
* What a Dynamic Page's dependency resolver receives.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* It has no `props`: the build plans a Dynamic Page without running its `props` hook, and the Page Browser Graph
|
|
40
|
+
* is cached by Params and Query alone, so request data must not decide its dependencies.
|
|
41
|
+
*/
|
|
42
|
+
export type GetDynamicPageDependenciesContext = Omit<GetPageDependenciesContext, 'props'>;
|
|
43
|
+
export type GetDynamicPageDependencies = (context: GetDynamicPageDependenciesContext) => PageDependenciesResult | undefined | Promise<PageDependenciesResult | undefined>;
|
|
44
|
+
export type DynamicPageDependenciesInput = EcoComponentDependencies | GetDynamicPageDependencies;
|
|
36
45
|
/**
|
|
37
46
|
* Runtime-agnostic incoming WebSocket frame.
|
|
38
47
|
*
|
|
@@ -73,7 +82,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
|
|
|
73
82
|
readonly kind: string;
|
|
74
83
|
readonly params: TParams;
|
|
75
84
|
readonly search: Readonly<PageQuery>;
|
|
76
|
-
readonly locals?:
|
|
85
|
+
readonly locals?: Record<string, unknown>;
|
|
77
86
|
}
|
|
78
87
|
/**
|
|
79
88
|
* Runtime-agnostic WebSocket socket view exposed to handlers.
|
|
@@ -190,15 +199,16 @@ export interface DefaultHmrContext {
|
|
|
190
199
|
*/
|
|
191
200
|
getSrcDir(): string;
|
|
192
201
|
/**
|
|
193
|
-
*
|
|
194
|
-
* Used to detect layout file changes that require full page reloads.
|
|
202
|
+
* True when the Route Registry holds `filePath` as a Page.
|
|
195
203
|
*/
|
|
196
|
-
|
|
204
|
+
isPageFile(filePath: string): boolean;
|
|
197
205
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
206
|
+
* True when a Page rendered in this session references `filePath` as a Layout.
|
|
207
|
+
*
|
|
208
|
+
* @remarks
|
|
209
|
+
* Layouts are known after route preparation, so a Layout no Page has rendered yet reports `false`.
|
|
200
210
|
*/
|
|
201
|
-
|
|
211
|
+
isLayoutFile(filePath: string): boolean;
|
|
202
212
|
/**
|
|
203
213
|
* Server-side module loader owned by the active app/runtime.
|
|
204
214
|
*/
|
|
@@ -541,9 +551,7 @@ export interface BrowserForeignChildHost {
|
|
|
541
551
|
/**
|
|
542
552
|
* Represents a page in EcoPages.
|
|
543
553
|
*/
|
|
544
|
-
export type PageProps<T = unknown> = T & StaticPageContext
|
|
545
|
-
locals?: RequestLocals;
|
|
546
|
-
};
|
|
554
|
+
export type PageProps<T = unknown> = T & StaticPageContext;
|
|
547
555
|
/**
|
|
548
556
|
* Page-level robots directives for the document head and sitemap filtering.
|
|
549
557
|
*
|
|
@@ -621,7 +629,7 @@ export interface PageHeadProps<T = EcoPagesElement> {
|
|
|
621
629
|
/**
|
|
622
630
|
* Represents the props for a route layout.
|
|
623
631
|
*/
|
|
624
|
-
export interface LayoutProps<T = EcoPagesElement>
|
|
632
|
+
export interface LayoutProps<T = EcoPagesElement> {
|
|
625
633
|
children: T;
|
|
626
634
|
}
|
|
627
635
|
/**
|
|
@@ -643,26 +651,49 @@ export interface HtmlTemplateProps<T = EcoPagesElement> extends PageHeadProps<T>
|
|
|
643
651
|
pageModuleUrl?: string;
|
|
644
652
|
}
|
|
645
653
|
/**
|
|
646
|
-
*
|
|
654
|
+
* A layout factory context whose `params`, `query` and `locals` are all optional, and whose `locals` has no keys.
|
|
655
|
+
*
|
|
656
|
+
* @remarks
|
|
657
|
+
* A shared layout entry whose factory takes it is accepted on any Page. An entry that reads locals annotates the
|
|
658
|
+
* ones it reads on its factory parameter instead, so only a Page whose middleware provides them accepts it. A
|
|
659
|
+
* factory written in `eco.page({ layout })` is typed with {@link LayoutRequestContext} or {@link LayoutBuildContext},
|
|
660
|
+
* from the Page's Cache Strategy and middleware list.
|
|
647
661
|
*/
|
|
648
662
|
export type LayoutPropsContext = {
|
|
649
663
|
params?: PageParams;
|
|
650
664
|
query?: PageQuery;
|
|
651
|
-
locals?:
|
|
665
|
+
locals?: {};
|
|
666
|
+
};
|
|
667
|
+
/**
|
|
668
|
+
* What a layout entry's `props` factory receives on a Static or revalidating Page: no request exists, so it has no
|
|
669
|
+
* `locals`.
|
|
670
|
+
*/
|
|
671
|
+
export type LayoutBuildContext = Omit<LayoutPropsContext, 'locals'>;
|
|
672
|
+
/**
|
|
673
|
+
* What a layout entry's `props` factory receives on a Dynamic Page.
|
|
674
|
+
*
|
|
675
|
+
* @typeParam TLocals - The Locals the Page's middleware provided, typed from its `middleware` list.
|
|
676
|
+
*/
|
|
677
|
+
export type LayoutRequestContext<TLocals = {}> = LayoutBuildContext & {
|
|
678
|
+
readonly locals: Readonly<TLocals>;
|
|
652
679
|
};
|
|
653
680
|
/**
|
|
654
681
|
* One normalized layout tier in a page layout stack (outer→inner), as stored on page config.
|
|
655
682
|
*/
|
|
656
683
|
export type EcoPageLayoutEntry = {
|
|
657
684
|
component: EcoComponent;
|
|
658
|
-
props?: (context:
|
|
685
|
+
props?: (context: LayoutRequestContext) => Record<string, unknown>;
|
|
659
686
|
};
|
|
660
687
|
/**
|
|
661
688
|
* A layout tier with a props factory, as written in `eco.page({ layout })`.
|
|
689
|
+
*
|
|
690
|
+
* @typeParam TContext - What the factory receives. `eco.page()` sets it from the Page, so a factory written inline
|
|
691
|
+
* reads the Page's typed `locals`; an entry shared by many Pages annotates the `locals` it reads on the factory
|
|
692
|
+
* parameter, and a Page whose middleware does not provide them does not compile.
|
|
662
693
|
*/
|
|
663
|
-
export type EcoPageLayoutEntrySpec<E = EcoPagesElement> = {
|
|
694
|
+
export type EcoPageLayoutEntrySpec<E = EcoPagesElement, TContext = LayoutPropsContext> = {
|
|
664
695
|
component: EcoLayoutComponent<E>;
|
|
665
|
-
props?: (context:
|
|
696
|
+
props?: (context: TContext) => Record<string, unknown>;
|
|
666
697
|
};
|
|
667
698
|
/**
|
|
668
699
|
* Layout declaration accepted by `eco.page()`: an `eco.layout()` result, a plain function typed with
|
|
@@ -673,7 +704,7 @@ export type EcoPageLayoutEntrySpec<E = EcoPagesElement> = {
|
|
|
673
704
|
* still assignable, so the type cannot prove that a layout renders `children`; layout composition checks that
|
|
674
705
|
* when it renders the page.
|
|
675
706
|
*/
|
|
676
|
-
export type EcoPageLayoutSpec<E = EcoPagesElement> = EcoLayoutComponent<E> | EcoPageLayoutEntrySpec<E>;
|
|
707
|
+
export type EcoPageLayoutSpec<E = EcoPagesElement, TContext = LayoutPropsContext> = EcoLayoutComponent<E> | EcoPageLayoutEntrySpec<E, TContext>;
|
|
677
708
|
/**
|
|
678
709
|
* One or more layout tiers for `eco.page({ layout })`.
|
|
679
710
|
*
|
|
@@ -681,7 +712,7 @@ export type EcoPageLayoutSpec<E = EcoPagesElement> = EcoLayoutComponent<E> | Eco
|
|
|
681
712
|
* When an array, order is **outer → inner** (outermost layout wraps all inner tiers).
|
|
682
713
|
* Normalized at factory time to `config.layouts` and `config.layoutEntries`.
|
|
683
714
|
*/
|
|
684
|
-
export type EcoPageLayouts<E = EcoPagesElement> = EcoPageLayoutSpec<E> | EcoPageLayoutSpec<E>[];
|
|
715
|
+
export type EcoPageLayouts<E = EcoPagesElement, TContext = LayoutPropsContext> = EcoPageLayoutSpec<E, TContext> | EcoPageLayoutSpec<E, TContext>[];
|
|
685
716
|
/**
|
|
686
717
|
* A layout component: an `eco.layout()` result or a plain function that takes {@link LayoutProps}.
|
|
687
718
|
*/
|
|
@@ -696,8 +727,8 @@ export type EcoHtmlComponent<T = EcoPagesElement> = EcoComponent<HtmlTemplatePro
|
|
|
696
727
|
* @remarks
|
|
697
728
|
* `status` is the HTTP status being rendered. `message` is the public `HttpError`
|
|
698
729
|
* text for 4xx page-pipeline failures; unmatched URLs omit it. `stack` is only
|
|
699
|
-
* passed for 5xx pages in development. Semantic error pages
|
|
700
|
-
*
|
|
730
|
+
* passed for 5xx pages in development. Semantic error pages render outside the page middleware pipeline, so their
|
|
731
|
+
* layout factories receive empty `locals`.
|
|
701
732
|
*/
|
|
702
733
|
export interface ErrorPageTemplateProps extends Omit<HtmlTemplateProps, 'children'> {
|
|
703
734
|
status: number;
|
|
@@ -721,17 +752,6 @@ export type PageParams = Record<string, string | string[]>;
|
|
|
721
752
|
* `z.union([z.string(), z.array(z.string())])`.
|
|
722
753
|
*/
|
|
723
754
|
export type PageQuery = Record<string, string | string[]>;
|
|
724
|
-
/**
|
|
725
|
-
* Request-scoped data that is only available during request-time rendering.
|
|
726
|
-
*
|
|
727
|
-
* Apps should augment this interface via module augmentation:
|
|
728
|
-
*
|
|
729
|
-
* declare module '@ecopages/core' {
|
|
730
|
-
* interface RequestLocals { session?: Session | null }
|
|
731
|
-
* }
|
|
732
|
-
*/
|
|
733
|
-
export interface RequestLocals {
|
|
734
|
-
}
|
|
735
755
|
/**
|
|
736
756
|
* Represents the context object for a static page.
|
|
737
757
|
*/
|
|
@@ -740,32 +760,9 @@ export type StaticPageContext = {
|
|
|
740
760
|
query?: PageQuery;
|
|
741
761
|
};
|
|
742
762
|
/**
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
* This is only populated during SSR. Static generation must not access locals.
|
|
746
|
-
*/
|
|
747
|
-
export type RequestPageContext = {
|
|
748
|
-
locals: RequestLocals;
|
|
749
|
-
};
|
|
750
|
-
/**
|
|
751
|
-
* Adds optional `locals` to a props type.
|
|
752
|
-
* Primarily used for layouts that may receive request-scoped data from middleware.
|
|
753
|
-
*
|
|
754
|
-
* @template P - The base props type
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* type MyLayoutProps = WithLocals<{ children: ReactNode }>;
|
|
759
|
-
* // { children: ReactNode; locals?: RequestLocals }
|
|
760
|
-
* ```
|
|
761
|
-
*/
|
|
762
|
-
export type WithLocals<P> = P & {
|
|
763
|
-
locals?: RequestLocals;
|
|
764
|
-
};
|
|
765
|
-
/**
|
|
766
|
-
* Represents the params for a static path.
|
|
763
|
+
* One page that `paths` lists at build.
|
|
767
764
|
*/
|
|
768
|
-
export type
|
|
765
|
+
export type PagePath = {
|
|
769
766
|
params: PageParams;
|
|
770
767
|
};
|
|
771
768
|
export type EcoPagesAppConfig = {
|
|
@@ -775,11 +772,9 @@ export type EcoPagesAppConfig = {
|
|
|
775
772
|
publicDir: string;
|
|
776
773
|
pagesDir: string;
|
|
777
774
|
includesDir: string;
|
|
778
|
-
layoutsDir: string;
|
|
779
775
|
distDir: string;
|
|
780
776
|
workDir: string;
|
|
781
777
|
templatesExt: string[];
|
|
782
|
-
componentsDir: string;
|
|
783
778
|
robotsTxt: {
|
|
784
779
|
preferences: Record<string, string[]>;
|
|
785
780
|
};
|
|
@@ -790,11 +785,9 @@ export type EcoPagesAppConfig = {
|
|
|
790
785
|
absolutePaths: {
|
|
791
786
|
config: string;
|
|
792
787
|
configModuleFiles: string[];
|
|
793
|
-
componentsDir: string;
|
|
794
788
|
distDir: string;
|
|
795
789
|
workDir: string;
|
|
796
790
|
includesDir: string;
|
|
797
|
-
layoutsDir: string;
|
|
798
791
|
pagesDir: string;
|
|
799
792
|
projectDir: string;
|
|
800
793
|
publicDir: string;
|
|
@@ -809,31 +802,60 @@ export type EcoPagesAppConfig = {
|
|
|
809
802
|
package?: string;
|
|
810
803
|
};
|
|
811
804
|
};
|
|
812
|
-
export type PagePropsFor<T> = T extends
|
|
805
|
+
export type PagePropsFor<T> = T extends GetProps<infer P> ? P & {
|
|
813
806
|
params?: PageParams;
|
|
814
807
|
query?: PageQuery;
|
|
815
808
|
} : T & {
|
|
816
809
|
params?: PageParams;
|
|
817
810
|
query?: PageQuery;
|
|
818
811
|
};
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
812
|
+
type PageRenderComponent<T> = EcoComponent<PagePropsFor<T>>;
|
|
813
|
+
type PageStaticsBase<T> = {
|
|
814
|
+
paths?: GetPaths;
|
|
822
815
|
metadata?: GetMetadata<T>;
|
|
816
|
+
middleware?: readonly PageMiddlewareEntry[];
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* A Cache Strategy that stores the rendered HTML, so no request exists when the `props` hook runs.
|
|
820
|
+
*/
|
|
821
|
+
export type StaticCacheStrategy = Exclude<CacheStrategy, 'dynamic'>;
|
|
822
|
+
/**
|
|
823
|
+
* What `eco.page()` keeps on a Static or revalidating Page: its `props` hook receives the build context.
|
|
824
|
+
*/
|
|
825
|
+
export type StaticPageStatics<T> = PageStaticsBase<T> & {
|
|
826
|
+
cache?: StaticCacheStrategy;
|
|
827
|
+
props?: GetProps<T>;
|
|
823
828
|
resolveDependencies?: GetPageDependencies<T>;
|
|
824
|
-
cache?: CacheStrategy;
|
|
825
|
-
requires?: PageRequires;
|
|
826
|
-
middleware?: FileRouteMiddleware[];
|
|
827
829
|
};
|
|
828
830
|
/**
|
|
829
|
-
*
|
|
831
|
+
* What `eco.page()` keeps on a Dynamic Page: its `props` hook is the request handler and receives the request
|
|
832
|
+
* context.
|
|
833
|
+
*/
|
|
834
|
+
export type DynamicPageStatics<T> = PageStaticsBase<T> & {
|
|
835
|
+
cache: 'dynamic';
|
|
836
|
+
props?: GetRequestProps<T>;
|
|
837
|
+
resolveDependencies?: GetDynamicPageDependencies;
|
|
838
|
+
};
|
|
839
|
+
export type StaticEcoPageComponent<T> = PageRenderComponent<T> & StaticPageStatics<T>;
|
|
840
|
+
export type DynamicEcoPageComponent<T> = PageRenderComponent<T> & DynamicPageStatics<T>;
|
|
841
|
+
/**
|
|
842
|
+
* A Page as `eco.page()` returns it.
|
|
843
|
+
*
|
|
844
|
+
* @remarks
|
|
845
|
+
* A union on `cache`, so a caller branches on it before calling the `props` or dependency hook, which receive
|
|
846
|
+
* different contexts.
|
|
847
|
+
*/
|
|
848
|
+
export type EcoPageComponent<T> = StaticEcoPageComponent<T> | DynamicEcoPageComponent<T>;
|
|
849
|
+
/**
|
|
850
|
+
* The function that lists the Params a page is known for at build time.
|
|
851
|
+
*
|
|
852
|
+
* @remarks
|
|
853
|
+
* Returns `[{ params }]` directly. The Cache Strategy decides what the build does with each entry.
|
|
830
854
|
*/
|
|
831
|
-
export type
|
|
855
|
+
export type GetPaths = (context: {
|
|
832
856
|
appConfig: EcoPagesAppConfig;
|
|
833
857
|
runtimeOrigin: string;
|
|
834
|
-
}) => Promise<
|
|
835
|
-
paths: StaticPath[];
|
|
836
|
-
}>;
|
|
858
|
+
}) => Promise<PagePath[]>;
|
|
837
859
|
/**
|
|
838
860
|
* The context object for the getMetadata function.
|
|
839
861
|
*/
|
|
@@ -846,22 +868,65 @@ export type GetMetadataContext<T = Record<string, unknown>> = Required<StaticPag
|
|
|
846
868
|
*/
|
|
847
869
|
export type GetMetadata<T = Record<string, unknown>> = (context: GetMetadataContext<T>) => PageMetadataProps | Promise<PageMetadataProps>;
|
|
848
870
|
/**
|
|
849
|
-
*
|
|
871
|
+
* What the `props` hook of a Static or revalidating Page receives. No request exists when it runs: at build, and
|
|
872
|
+
* when a revalidating Page regenerates.
|
|
850
873
|
*/
|
|
851
|
-
export type
|
|
852
|
-
|
|
874
|
+
export type PageBuildContext = {
|
|
875
|
+
params: PageParams;
|
|
853
876
|
appConfig: EcoPagesAppConfig;
|
|
854
877
|
runtimeOrigin: string;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
878
|
+
};
|
|
879
|
+
/**
|
|
880
|
+
* What the `props` hook of a Dynamic Page receives on each request.
|
|
881
|
+
*
|
|
882
|
+
* @typeParam TLocals - The Locals the Page's middleware provided, typed from its `middleware` list.
|
|
883
|
+
*/
|
|
884
|
+
export type PageRequestContext<TLocals = {}> = PageBuildContext & {
|
|
885
|
+
request: Request;
|
|
886
|
+
query: PageQuery;
|
|
887
|
+
readonly locals: Readonly<TLocals>;
|
|
888
|
+
};
|
|
889
|
+
/**
|
|
890
|
+
* The `props` hook of a Static or revalidating Page.
|
|
891
|
+
*
|
|
892
|
+
* @remarks
|
|
893
|
+
* Returns the props object directly. `paths` lists the Params known at build, and the hook receives each of them.
|
|
894
|
+
*/
|
|
895
|
+
export type GetProps<T> = ((context: PageBuildContext) => T | Promise<T>) & ((context: PageBuildContext) => WithoutRouteProps<T> | Promise<WithoutRouteProps<T>>);
|
|
896
|
+
/**
|
|
897
|
+
* Keys a Page's `props` hook may not return.
|
|
898
|
+
*
|
|
899
|
+
* @remarks
|
|
900
|
+
* The route sets them on what `render` receives, after the props, so a prop of the same name would never reach
|
|
901
|
+
* `render` while `metadata` read it.
|
|
902
|
+
*/
|
|
903
|
+
export type NoRouteProps = {
|
|
904
|
+
params?: never;
|
|
905
|
+
query?: never;
|
|
906
|
+
};
|
|
907
|
+
/**
|
|
908
|
+
* `T` with every object member barred from {@link NoRouteProps} keys.
|
|
909
|
+
*
|
|
910
|
+
* @remarks
|
|
911
|
+
* The props hook types pair it with a plain `T | Promise<T>` signature that infers `T`: inferring through this
|
|
912
|
+
* conditional would take one branch of a union return, and `null` or `undefined` returns pass unchanged. The
|
|
913
|
+
* conditional stays deferred for a type parameter, so a hook that returns a caller's generic `T` does not type-check
|
|
914
|
+
* against it; such a wrapper passes a concrete props type.
|
|
915
|
+
*/
|
|
916
|
+
type WithoutRouteProps<T> = T extends object ? T & NoRouteProps : T;
|
|
917
|
+
/**
|
|
918
|
+
* The `props` hook of a Dynamic Page: the Page's request handler, run on every request and never by the build.
|
|
919
|
+
*/
|
|
920
|
+
export type GetRequestProps<T, TLocals = {}> = ((context: PageRequestContext<TLocals>) => T | Promise<T>) & ((context: PageRequestContext<TLocals>) => WithoutRouteProps<T> | Promise<WithoutRouteProps<T>>);
|
|
858
921
|
/**
|
|
859
922
|
* Represents a page file in EcoPages.
|
|
923
|
+
*
|
|
924
|
+
* @remarks
|
|
925
|
+
* The Page declares its Cache Strategy on its default export; a module that still exports `cache` fails to load.
|
|
860
926
|
* @template T - The type of the page props.
|
|
861
927
|
*/
|
|
862
928
|
export type EcoPageFile<T = unknown> = T & {
|
|
863
929
|
default: EcoComponent<any, any>;
|
|
864
|
-
cache?: CacheStrategy;
|
|
865
930
|
};
|
|
866
931
|
/**
|
|
867
932
|
* The options for the route renderer.
|
|
@@ -870,7 +935,15 @@ export type RouteRendererOptions = {
|
|
|
870
935
|
file: string;
|
|
871
936
|
params?: PageParams;
|
|
872
937
|
query?: PageQuery;
|
|
873
|
-
locals
|
|
938
|
+
/** The request's locals store, as the Page's middleware left it. */
|
|
939
|
+
locals?: Record<string, unknown>;
|
|
940
|
+
/**
|
|
941
|
+
* The incoming request, set only for a request-time render of a Dynamic Page.
|
|
942
|
+
*
|
|
943
|
+
* @remarks
|
|
944
|
+
* A Dynamic Page's `props` hook receives it with `query` and `locals`, and cannot run without it.
|
|
945
|
+
*/
|
|
946
|
+
request?: Request;
|
|
874
947
|
/**
|
|
875
948
|
* Preloaded page module from request-time inspection.
|
|
876
949
|
*
|
|
@@ -886,12 +959,12 @@ export type RouteRendererOptions = {
|
|
|
886
959
|
*/
|
|
887
960
|
props?: Record<string, unknown>;
|
|
888
961
|
/**
|
|
889
|
-
* Skips the page's `
|
|
962
|
+
* Skips the page's `props` hook for this render.
|
|
890
963
|
* @remarks Set when the caller already holds the final props, as the caller of an
|
|
891
964
|
* explicit view does. `props` then replaces the hook's result instead of being
|
|
892
965
|
* merged into it, and metadata sees the same props.
|
|
893
966
|
*/
|
|
894
|
-
|
|
967
|
+
skipPropsHook?: boolean;
|
|
895
968
|
};
|
|
896
969
|
/**
|
|
897
970
|
* The body of the route renderer.
|
|
@@ -948,7 +1021,6 @@ export type IntegrationRendererRenderOptions<C = EcoPagesElement> = RouteRendere
|
|
|
948
1021
|
pagePackage?: PagePackageResult;
|
|
949
1022
|
pageProps?: Record<string, unknown>;
|
|
950
1023
|
cacheStrategy?: CacheStrategy;
|
|
951
|
-
pageLocals?: RequestLocals;
|
|
952
1024
|
};
|
|
953
1025
|
export type InternalIntegrationRendererRenderOptions<C = EcoPagesElement> = IntegrationRendererRenderOptions<C> & {
|
|
954
1026
|
sourceDependencyPaths?: readonly string[];
|
|
@@ -1154,19 +1226,9 @@ export interface ApiHandlerContext<TRequest extends Request = Request, TServer =
|
|
|
1154
1226
|
response: ApiResponseBuilder;
|
|
1155
1227
|
server: TServer;
|
|
1156
1228
|
/**
|
|
1157
|
-
*
|
|
1158
|
-
* Only valid during request-time handling (SSR/API). Must not be used for static generation.
|
|
1159
|
-
*/
|
|
1160
|
-
locals: RequestLocals;
|
|
1161
|
-
/**
|
|
1162
|
-
* Require one or more locals keys. If missing, executes `onMissing` to produce a terminating Response.
|
|
1229
|
+
* The locals the route's middleware provided, typed from its `middleware` list. Without one it has no keys.
|
|
1163
1230
|
*/
|
|
1164
|
-
|
|
1165
|
-
<K extends keyof RequestLocals>(key: K, onMissing: () => Response): Exclude<RequestLocals[K], null | undefined>;
|
|
1166
|
-
<K extends keyof RequestLocals>(keys: readonly K[], onMissing: () => Response): {
|
|
1167
|
-
[P in K]-?: Exclude<RequestLocals[P], null | undefined>;
|
|
1168
|
-
};
|
|
1169
|
-
};
|
|
1231
|
+
locals: {};
|
|
1170
1232
|
/**
|
|
1171
1233
|
* Services available to the API handler.
|
|
1172
1234
|
*/
|
|
@@ -1300,6 +1362,20 @@ export interface ApiHandlerContext<TRequest extends Request = Request, TServer =
|
|
|
1300
1362
|
*/
|
|
1301
1363
|
headers?: unknown;
|
|
1302
1364
|
}
|
|
1365
|
+
/**
|
|
1366
|
+
* The context a plain API middleware function receives.
|
|
1367
|
+
*/
|
|
1368
|
+
export interface ApiMiddlewareContext<TRequest extends Request = Request, TServer = any> extends Omit<ApiHandlerContext<TRequest, TServer>, 'locals'> {
|
|
1369
|
+
/**
|
|
1370
|
+
* The request's locals store.
|
|
1371
|
+
*
|
|
1372
|
+
* @remarks
|
|
1373
|
+
* A plain function may write a new key here and the later stages and the handler see it at runtime, but no type
|
|
1374
|
+
* carries what it writes: they read only what a `createMiddleware` stage provides. Overwriting or deleting a key
|
|
1375
|
+
* a stage provided with `next` makes this function's `next` throw, since readers are typed for that value.
|
|
1376
|
+
*/
|
|
1377
|
+
locals: Record<string, unknown>;
|
|
1378
|
+
}
|
|
1303
1379
|
/**
|
|
1304
1380
|
* Context available to file-route page middleware.
|
|
1305
1381
|
*
|
|
@@ -1307,68 +1383,37 @@ export interface ApiHandlerContext<TRequest extends Request = Request, TServer =
|
|
|
1307
1383
|
* response helpers, but final document rendering stays owned by the page route
|
|
1308
1384
|
* execution path. The query string is not parsed for page middleware; read it from `request.url`.
|
|
1309
1385
|
*/
|
|
1310
|
-
export interface FileRouteMiddlewareContext<TRequest extends Request = Request, TServer = any> extends Omit<
|
|
1386
|
+
export interface FileRouteMiddlewareContext<TRequest extends Request = Request, TServer = any> extends Omit<ApiMiddlewareContext<TRequest, TServer>, 'render' | 'renderPartial' | 'query'> {
|
|
1311
1387
|
}
|
|
1312
1388
|
/**
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1389
|
+
* The `next` of a plain middleware function. Call it to continue to the next middleware or the handler.
|
|
1390
|
+
*
|
|
1391
|
+
* @remarks
|
|
1392
|
+
* A plain function provides no locals. To provide typed locals to later stages and the handler, make the
|
|
1393
|
+
* middleware with `createMiddleware`.
|
|
1315
1394
|
*/
|
|
1316
1395
|
export type MiddlewareNext = () => Promise<Response>;
|
|
1317
1396
|
/**
|
|
1318
|
-
*
|
|
1397
|
+
* A plain middleware function for API routes.
|
|
1319
1398
|
* Receives the request context and a next function to continue the chain.
|
|
1320
1399
|
* Can short-circuit by returning a Response directly without calling next().
|
|
1321
1400
|
*
|
|
1322
1401
|
* @typeParam TRequest - Request type
|
|
1323
1402
|
* @typeParam TServer - Server type
|
|
1324
|
-
* @typeParam TContext - Extended context type, defaults to base ApiHandlerContext
|
|
1325
1403
|
*
|
|
1326
|
-
* @example
|
|
1404
|
+
* @example
|
|
1327
1405
|
* ```typescript
|
|
1328
1406
|
* const loggingMiddleware: Middleware = async (ctx, next) => {
|
|
1329
1407
|
* console.log(`${ctx.request.method} ${ctx.request.url}`);
|
|
1330
1408
|
* return next();
|
|
1331
1409
|
* };
|
|
1332
1410
|
* ```
|
|
1333
|
-
*
|
|
1334
|
-
* @example Middleware with extended context (use EcoMiddleware helper)
|
|
1335
|
-
* ```typescript
|
|
1336
|
-
* type AuthContext = ApiHandlerContext<Request, unknown> & { user: User };
|
|
1337
|
-
*
|
|
1338
|
-
* const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
|
|
1339
|
-
* const user = await authenticate(ctx.request);
|
|
1340
|
-
* if (!user) return ctx.response.status(401).json({ error: 'Unauthorized' });
|
|
1341
|
-
* ctx.user = user;
|
|
1342
|
-
* return next();
|
|
1343
|
-
* };
|
|
1344
|
-
* ```
|
|
1345
1411
|
*/
|
|
1346
|
-
export type Middleware<TRequest extends Request = Request, TServer = any
|
|
1412
|
+
export type Middleware<TRequest extends Request = Request, TServer = any> = (context: ApiMiddlewareContext<TRequest, TServer>, next: MiddlewareNext) => Promise<Response> | Response;
|
|
1347
1413
|
/**
|
|
1348
|
-
*
|
|
1349
|
-
*/
|
|
1350
|
-
export type FileRouteMiddleware<TRequest extends Request = Request, TServer = any, TContext extends FileRouteMiddlewareContext<TRequest, TServer> = FileRouteMiddlewareContext<TRequest, TServer>> = (context: TContext, next: MiddlewareNext) => Promise<Response> | Response;
|
|
1351
|
-
/**
|
|
1352
|
-
* Helper type for defining middleware with extended context.
|
|
1353
|
-
* Automatically infers TRequest and TServer from the provided context type.
|
|
1354
|
-
*
|
|
1355
|
-
* @typeParam TContext - The extended context type that includes TRequest and TServer
|
|
1356
|
-
*
|
|
1357
|
-
* @example
|
|
1358
|
-
* ```typescript
|
|
1359
|
-
* type AuthContext = ApiHandlerContext<Request, unknown> & {
|
|
1360
|
-
* session: { user: User };
|
|
1361
|
-
* };
|
|
1362
|
-
*
|
|
1363
|
-
* const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
|
|
1364
|
-
* const session = await authenticate(ctx.request);
|
|
1365
|
-
* if (!session) return Response.redirect('/login');
|
|
1366
|
-
* ctx.session = session;
|
|
1367
|
-
* return next();
|
|
1368
|
-
* };
|
|
1369
|
-
* ```
|
|
1414
|
+
* A plain middleware function for file-based page routes.
|
|
1370
1415
|
*/
|
|
1371
|
-
export type
|
|
1416
|
+
export type FileRouteMiddleware<TRequest extends Request = Request, TServer = any> = (context: FileRouteMiddlewareContext<TRequest, TServer>, next: MiddlewareNext) => Promise<Response> | Response;
|
|
1372
1417
|
/**
|
|
1373
1418
|
* The request methods an `ApiHandler` answers, in the order an endpoint's `Allow` header lists them.
|
|
1374
1419
|
*/
|
|
@@ -1443,7 +1488,7 @@ export interface ApiHandler<TPath extends string = string, TRequest extends Requ
|
|
|
1443
1488
|
method: ApiHandlerMethod;
|
|
1444
1489
|
handler: (context: ApiHandlerContext<TRequest, TServer>) => Promise<Response> | Response;
|
|
1445
1490
|
/** Optional middleware chain executed before the handler */
|
|
1446
|
-
middleware?: MiddlewareList
|
|
1491
|
+
middleware?: MiddlewareList;
|
|
1447
1492
|
/** Optional validation schemas for request body, query parameters, and headers */
|
|
1448
1493
|
schema?: {
|
|
1449
1494
|
body?: StandardSchema;
|
|
@@ -1464,34 +1509,45 @@ export type ErrorHandler<TRequest extends Request = Request, TServer = any> = (e
|
|
|
1464
1509
|
* @typeParam TMiddleware - The route's middleware; inferred as a tuple so the handler sees what each one adds
|
|
1465
1510
|
* @typeParam TSchema - The route's schema; each field it declares types the matching context field
|
|
1466
1511
|
*/
|
|
1467
|
-
export interface RouteOptions<
|
|
1512
|
+
export interface RouteOptions<TSchema extends RouteSchema = RouteSchema, TMiddleware extends MiddlewareList = MiddlewareList> {
|
|
1468
1513
|
middleware?: TMiddleware;
|
|
1469
1514
|
schema?: TSchema;
|
|
1470
1515
|
}
|
|
1471
1516
|
/**
|
|
1472
|
-
* A middleware list
|
|
1517
|
+
* A middleware list: middleware made by `createMiddleware` or `composeMiddleware`, and plain functions.
|
|
1473
1518
|
*
|
|
1474
1519
|
* @remarks
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
export type MiddlewareList<TRequest extends Request = Request, TServer = any> = readonly {
|
|
1483
|
-
middleware(context: ApiHandlerContext<TRequest, TServer>, next: MiddlewareNext): Promise<Response> | Response;
|
|
1484
|
-
}['middleware'][];
|
|
1485
|
-
/**
|
|
1486
|
-
* The context a list of middleware adds: the intersection of the context each one declares.
|
|
1520
|
+
* Declare it as a literal list or a `const` tuple, so each entry's locals are read in order. A list typed as a
|
|
1521
|
+
* plain array provides no locals. Put `middleware` before the handler so its locals type the handler.
|
|
1522
|
+
*/
|
|
1523
|
+
export type MiddlewareList = readonly ApiMiddlewareEntry[];
|
|
1524
|
+
declare const noMiddlewareList: unique symbol;
|
|
1525
|
+
/**
|
|
1526
|
+
* The list a route, group or handler infers when it declares no `middleware`.
|
|
1487
1527
|
*
|
|
1488
1528
|
* @remarks
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1529
|
+
* It must stay a supertype of an inline list, so the `(ctx, next) => ...` entries of one take their parameter
|
|
1530
|
+
* types from it, and it must differ from `MiddlewareList`, so a list annotated `MiddlewareList` by hand folds as a
|
|
1531
|
+
* plain array of unknown locals instead of keeping the group's keys. The optional brand gives both: every list is
|
|
1532
|
+
* assignable to it, and only this type is identical to it.
|
|
1491
1533
|
*/
|
|
1492
|
-
export type
|
|
1493
|
-
|
|
1494
|
-
|
|
1534
|
+
export type NoMiddlewareList = MiddlewareList & {
|
|
1535
|
+
readonly [noMiddlewareList]?: true;
|
|
1536
|
+
};
|
|
1537
|
+
/**
|
|
1538
|
+
* A context with the locals a middleware list provides, as seen by a handler or a group.
|
|
1539
|
+
*
|
|
1540
|
+
* @remarks
|
|
1541
|
+
* Later entries override earlier ones, and a route continues the locals of its group: the route's list folds onto
|
|
1542
|
+
* them, so a route entry of unknown locals leaves no group key proven either. A route that declares no list
|
|
1543
|
+
* infers {@link NoMiddlewareList} and keeps its group's locals.
|
|
1544
|
+
*/
|
|
1545
|
+
export type WithMiddlewareLocals<TContext extends {
|
|
1546
|
+
readonly locals: object;
|
|
1547
|
+
}, TList extends readonly unknown[]> = Omit<TContext, 'locals'> & {
|
|
1548
|
+
readonly locals: IsNoList<TList> extends true ? TContext['locals'] : ListLocals<TList, TContext['locals']>;
|
|
1549
|
+
};
|
|
1550
|
+
type IsNoList<TList> = (<T>() => T extends TList ? 1 : 2) extends <T>() => T extends NoMiddlewareList ? 1 : 2 ? true : false;
|
|
1495
1551
|
export interface RouteSchema {
|
|
1496
1552
|
body?: StandardSchema;
|
|
1497
1553
|
query?: StandardSchema;
|
|
@@ -1528,7 +1584,7 @@ type RouteSchemaField = keyof RouteSchema;
|
|
|
1528
1584
|
* `TRouteContext` has no inference site; passing it explicitly types a context that the route's
|
|
1529
1585
|
* middleware list does not declare.
|
|
1530
1586
|
*/
|
|
1531
|
-
export type RouteMethod<TReturn, TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> = <TSchema extends RouteSchema = RouteSchema, TRouteContext extends TContext = TContext, const TMiddleware extends MiddlewareList
|
|
1587
|
+
export type RouteMethod<TReturn, TRequest extends Request = Request, TServer = any, TContext extends ApiHandlerContext<TRequest, TServer> = ApiHandlerContext<TRequest, TServer>> = <TSchema extends RouteSchema = RouteSchema, TRouteContext extends TContext = TContext, const TMiddleware extends MiddlewareList = NoMiddlewareList>(path: string, handler: (context: RouteHandlerContext<TSchema, WithMiddlewareLocals<TRouteContext, TMiddleware>>) => Promise<Response> | Response, options?: RouteOptions<TSchema, TMiddleware>) => TReturn;
|
|
1532
1588
|
/**
|
|
1533
1589
|
* Builder for defining routes within a group, one method per HTTP method.
|
|
1534
1590
|
* Provides chainable methods for registering routes with shared prefix and middleware.
|