@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
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
* Type definitions for the eco namespace API
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import type { DependencyLazyTrigger, EcoComponent, EcoComponentDependencies, EcoHtmlComponent, EcoPageLayouts, EcoPagesElement, EcoPageComponent,
|
|
6
|
-
import type {
|
|
5
|
+
import type { DependencyLazyTrigger, EcoComponent, EcoComponentDependencies, EcoHtmlComponent, EcoPageLayouts, EcoPagesElement, EcoPageComponent, GetMetadata, GetPaths, GetProps, GetRequestProps, HtmlTemplateProps, LayoutBuildContext, LayoutProps, LayoutRequestContext, PagePropsFor, PageDependenciesInput, DynamicPageDependenciesInput, StaticCacheStrategy } from './contracts.js';
|
|
6
|
+
import type { ListLocals, PageMiddlewareEntry } from './middleware-types.js';
|
|
7
7
|
import type { ComponentIdentity } from './component-identity.js';
|
|
8
|
-
export type { EcoPageComponent, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, PageDependenciesInput, PageDependenciesResult, PagePropsFor,
|
|
9
|
-
type RequiresKeys = keyof RequestLocals;
|
|
8
|
+
export type { EcoPageComponent, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, PageDependenciesInput, PageDependenciesResult, PagePropsFor, } from './contracts.js';
|
|
10
9
|
/**
|
|
11
10
|
* Extracts the props type from one eco component.
|
|
12
11
|
*/
|
|
@@ -52,9 +51,6 @@ export type EcoEmbedProps<TComponent extends EcoComponent> = {
|
|
|
52
51
|
props: EmbedPropsOf<TComponent>;
|
|
53
52
|
children?: unknown;
|
|
54
53
|
};
|
|
55
|
-
type WithRequiredLocals<K extends keyof RequestLocals> = Omit<RequestLocals, K> & {
|
|
56
|
-
[P in K]-?: Exclude<RequestLocals[P], null | undefined>;
|
|
57
|
-
};
|
|
58
54
|
/**
|
|
59
55
|
* Lazy trigger options map directly to scripts-injector attributes.
|
|
60
56
|
* Only one trigger type can be active at a time.
|
|
@@ -89,79 +85,124 @@ export interface PageOptionsBase<T, E = EcoPagesElement> {
|
|
|
89
85
|
identity?: ComponentIdentity;
|
|
90
86
|
integration?: string;
|
|
91
87
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Define static paths for dynamic routes (e.g., [slug].tsx).
|
|
99
|
-
* Returns all possible paths that should be pre-rendered at build time.
|
|
100
|
-
*/
|
|
101
|
-
staticPaths?: GetStaticPaths;
|
|
102
|
-
/**
|
|
103
|
-
* Fetch data for the page at build time.
|
|
104
|
-
* Props returned here are passed to both render() and metadata().
|
|
88
|
+
* Lists the Params a dynamic route (e.g. `[slug].tsx`) is known for at build time, as `[{ params }]`.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* The Cache Strategy decides what the build does with each entry: `'static'` and `{ revalidate }` Pages render
|
|
92
|
+
* and write HTML for it, `'dynamic'` Pages plan a Page Browser Graph for it.
|
|
105
93
|
*/
|
|
106
|
-
|
|
94
|
+
paths?: GetPaths;
|
|
107
95
|
/**
|
|
108
96
|
* Generate page metadata (title, description, etc.).
|
|
109
97
|
*
|
|
110
98
|
* @remarks
|
|
111
|
-
* Props come from `
|
|
99
|
+
* Props come from `props`. Props passed into the render are overlaid
|
|
112
100
|
* and win when both set the same key. `metadata` sees the merged props.
|
|
113
101
|
*/
|
|
114
102
|
metadata?: GetMetadata<T>;
|
|
115
103
|
/**
|
|
116
|
-
*
|
|
104
|
+
* Renders the Page from what `props` returned, with the route's Params and Query.
|
|
117
105
|
*
|
|
118
|
-
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* It receives no `locals`: a Dynamic Page reads them in `props` and returns what `render` needs.
|
|
119
108
|
*/
|
|
120
|
-
|
|
121
|
-
render: (props: PagePropsFor<T> & Partial<RequestPageContext>) => E | Promise<E>;
|
|
109
|
+
render: (props: PagePropsFor<T>) => E | Promise<E>;
|
|
122
110
|
}
|
|
123
111
|
/**
|
|
124
|
-
* Page
|
|
112
|
+
* Options of a Static or revalidating Page. No request exists when its `props` hook runs, so the hook receives the
|
|
113
|
+
* build context and the Page takes no middleware.
|
|
125
114
|
*/
|
|
126
|
-
interface
|
|
115
|
+
export interface StaticPageOptions<T, E = EcoPagesElement> extends PageOptionsBase<T, E> {
|
|
127
116
|
/**
|
|
128
117
|
* Cache configuration for ISR (Incremental Static Regeneration).
|
|
129
118
|
* - `'static'`: Reuse until the next deploy (default); HTML is revalidated with ETag
|
|
130
|
-
* - `'dynamic'`: No caching, render on every request
|
|
131
119
|
* - `{ revalidate: number, tags?: string[] }`: Cache with time-based revalidation
|
|
132
120
|
*/
|
|
133
|
-
cache?:
|
|
121
|
+
cache?: StaticCacheStrategy;
|
|
134
122
|
middleware?: undefined;
|
|
123
|
+
/**
|
|
124
|
+
* The layout tiers that wrap the Page, outer to inner.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* An entry's `props` factory receives the Params and no `locals`: no request exists when a Static or revalidating
|
|
128
|
+
* Page renders.
|
|
129
|
+
*/
|
|
130
|
+
layout?: EcoPageLayouts<E, LayoutBuildContext>;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the page's props object. Props are passed to both render() and metadata().
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Receives each Params entry of `paths` at build, and the Params of the page again when a revalidating Page
|
|
136
|
+
* regenerates.
|
|
137
|
+
*/
|
|
138
|
+
props?: GetProps<T>;
|
|
139
|
+
/**
|
|
140
|
+
* Declares browser dependencies for the page, or resolves them per render after `props` are available.
|
|
141
|
+
*/
|
|
142
|
+
dependencies?: PageDependenciesInput<T>;
|
|
135
143
|
}
|
|
136
144
|
/**
|
|
137
|
-
*
|
|
145
|
+
* Options of a Dynamic Page, rendered on every request.
|
|
146
|
+
*
|
|
147
|
+
* @typeParam TLocals - The Locals its `props` hook reads. Without a `middleware` list it has no keys.
|
|
138
148
|
*/
|
|
139
|
-
interface
|
|
149
|
+
export interface DynamicPageOptions<T, E = EcoPagesElement, TLocals = {}> extends PageOptionsBase<T, E> {
|
|
140
150
|
/**
|
|
141
|
-
*
|
|
142
|
-
* Middleware runs on every request, so caching would bypass middleware effects.
|
|
151
|
+
* No caching: render on every request. Middleware requires it, since caching would bypass middleware effects.
|
|
143
152
|
*/
|
|
144
153
|
cache: 'dynamic';
|
|
154
|
+
/**
|
|
155
|
+
* The layout tiers that wrap the Page, outer to inner.
|
|
156
|
+
*
|
|
157
|
+
* @remarks
|
|
158
|
+
* An entry's `props` factory runs on the server for each request and reads the same `locals` as the `props`
|
|
159
|
+
* hook. What it returns reaches the browser for hydration.
|
|
160
|
+
*/
|
|
161
|
+
layout?: EcoPageLayouts<E, LayoutRequestContext<TLocals>>;
|
|
145
162
|
/**
|
|
146
163
|
* Request-time middleware for file-based routes.
|
|
147
164
|
* Runs before rendering and can short-circuit by returning a Response.
|
|
148
165
|
*/
|
|
149
|
-
middleware
|
|
166
|
+
middleware?: readonly PageMiddlewareEntry[];
|
|
167
|
+
/**
|
|
168
|
+
* The Page's request handler: it receives the request, its Params and Query, and the Locals its middleware
|
|
169
|
+
* provided, and returns the props `render` and `metadata` receive.
|
|
170
|
+
*
|
|
171
|
+
* @remarks
|
|
172
|
+
* It runs on every request and never at build. For a hydrated Page what it returns reaches the browser, so it
|
|
173
|
+
* returns only what the browser may see.
|
|
174
|
+
*/
|
|
175
|
+
props?: GetRequestProps<T, TLocals>;
|
|
176
|
+
/**
|
|
177
|
+
* Declares browser dependencies for the page, or resolves them from Params and Query.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* The resolver receives no `props`: the build plans the Page once per `paths` entry without running `props`.
|
|
181
|
+
*/
|
|
182
|
+
dependencies?: DynamicPageDependenciesInput;
|
|
150
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Page options with a `middleware` list whose locals type `locals` in `props` and in the layout entries.
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* `locals` is exactly what the list provides, a later entry overriding an earlier one.
|
|
189
|
+
*/
|
|
190
|
+
export type PageOptionsWithTypedLocals<T, E, M extends readonly PageMiddlewareEntry[]> = Omit<DynamicPageOptions<T, E, ListLocals<M>>, 'middleware'> & {
|
|
191
|
+
middleware: M;
|
|
192
|
+
};
|
|
151
193
|
/**
|
|
152
194
|
* Options for creating a page with eco.page()
|
|
153
195
|
*
|
|
154
|
-
* Define
|
|
196
|
+
* Define paths, props, and metadata inline. When using
|
|
155
197
|
* `middleware`, `cache` must be set to `'dynamic'` because middleware
|
|
156
198
|
* runs on every request and caching would bypass middleware effects.
|
|
199
|
+
* A Dynamic Page's `props` receives the request; a Static or revalidating Page's `props` receives only the build
|
|
200
|
+
* context.
|
|
157
201
|
*
|
|
158
202
|
* @template T - The props type for the page
|
|
159
203
|
* @template E - The element/return type (defaults to EcoPagesElement for Kita, use ReactNode for React)
|
|
160
204
|
*/
|
|
161
|
-
export type PageOptions<T, E = EcoPagesElement> =
|
|
162
|
-
export type PagePropsForWithLocals<T, K extends keyof RequestLocals | never = never> = PagePropsFor<T> & (K extends never ? Partial<RequestPageContext> : Omit<Partial<RequestPageContext>, 'locals'> & {
|
|
163
|
-
locals: WithRequiredLocals<Extract<K, keyof RequestLocals>>;
|
|
164
|
-
});
|
|
205
|
+
export type PageOptions<T, E = EcoPagesElement> = StaticPageOptions<T, E> | DynamicPageOptions<T, E>;
|
|
165
206
|
/**
|
|
166
207
|
* The eco namespace interface
|
|
167
208
|
*/
|
|
@@ -191,18 +232,12 @@ export interface Eco {
|
|
|
191
232
|
*/
|
|
192
233
|
layout: <E = EcoPagesElement, P extends LayoutProps<E> = LayoutProps<E>>(options: LayoutOptions<E, P>) => EcoComponent<P, E>;
|
|
193
234
|
/**
|
|
194
|
-
* Create a page component with type-safe props from `
|
|
195
|
-
* Returns an EcoPageComponent with attached
|
|
196
|
-
*
|
|
197
|
-
* If `requires` is provided, the `render` callback receives `locals` as required and non-null for the required keys.
|
|
235
|
+
* Create a page component with type-safe props from `props`.
|
|
236
|
+
* Returns an EcoPageComponent with attached paths, props, and metadata.
|
|
198
237
|
*/
|
|
199
238
|
page: {
|
|
200
|
-
<T = {}, E = EcoPagesElement>(options:
|
|
201
|
-
|
|
202
|
-
}): EcoPageComponent<T>;
|
|
203
|
-
<T = {}, E = EcoPagesElement, const K extends RequiresKeys = never>(options: Omit<PageOptions<T, E>, 'render' | 'requires'> & {
|
|
204
|
-
requires: PageRequires<K>;
|
|
205
|
-
render: (props: PagePropsForWithLocals<T, K>) => E | Promise<E>;
|
|
206
|
-
}): EcoPageComponent<T>;
|
|
239
|
+
<T = {}, E = EcoPagesElement, const M extends readonly PageMiddlewareEntry[] = readonly PageMiddlewareEntry[]>(options: PageOptionsWithTypedLocals<T, E, M>): EcoPageComponent<T>;
|
|
240
|
+
<T = {}, E = EcoPagesElement>(options: StaticPageOptions<T, E>): EcoPageComponent<T>;
|
|
241
|
+
<T = {}, E = EcoPagesElement>(options: DynamicPageOptions<T, E>): EcoPageComponent<T>;
|
|
207
242
|
};
|
|
208
243
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key of the brand a made middleware carries, typed with the locals it leaves available.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Only `createMiddleware` and `composeMiddleware` import it, and the package does not export it, so no other code
|
|
6
|
+
* can build an object with the brand: a literal `{}` cannot pose as a middleware that proves a local. A spread copy
|
|
7
|
+
* keeps the brand in its type but not the stages, so `flattenMiddleware` rejects it when the list is defined.
|
|
8
|
+
*/
|
|
9
|
+
export declare const localsBrand: unique symbol;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key of the brand a made middleware carries, typed with the locals it leaves available.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Only `createMiddleware` and `composeMiddleware` import it, and the package does not export it, so no other code
|
|
6
|
+
* can build an object with the brand: a literal `{}` cannot pose as a middleware that proves a local. A spread copy
|
|
7
|
+
* keeps the brand in its type but not the stages, so `flattenMiddleware` rejects it when the list is defined.
|
|
8
|
+
*/
|
|
9
|
+
export const localsBrand = Symbol('ecopages.middlewareLocals');
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { localsBrand } from './locals-brand.js';
|
|
2
|
+
import type { FileRouteMiddleware, FileRouteMiddlewareContext, Middleware } from './contracts.js';
|
|
3
|
+
declare const providedBrand: unique symbol;
|
|
4
|
+
declare const unknownLocals: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* What `next(locals)` resolves to: the response of the later stages, labelled with the locals it provided.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The label exists only in the types. It is `Omit<Response, 'clone'>` and not `Response` on purpose: when a
|
|
10
|
+
* stage returns both `next({ ... })` and a bare `Response`, TypeScript merges return types by subtype, and a
|
|
11
|
+
* `Response` subtype would be absorbed into plain `Response`, losing what was provided. Without `clone` it is
|
|
12
|
+
* no subtype, so both survive. The label is invariant in `TLocals` (a function from and to it), so
|
|
13
|
+
* `Provided<{ session }>` is not a subtype of `Provided<{}>`; otherwise a stage that returns `next({ session })`
|
|
14
|
+
* on one path and `next()` on another would be reduced to `{}` and lose `session`. At runtime it is a normal
|
|
15
|
+
* `Response`, and a helper that takes one needs a `Response`: mutate its headers and return it, do not cast.
|
|
16
|
+
*/
|
|
17
|
+
export type Provided<TLocals extends object> = Omit<Response, 'clone'> & {
|
|
18
|
+
readonly [providedBrand]: (locals: TLocals) => TLocals;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The `next` a stage calls to continue. Pass the locals the stage provides to later stages and to the handler.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Two overloads instead of one optional parameter: with `locals?: TLocals`, `next<{ session: Session }>()` and
|
|
25
|
+
* `next(cond ? { session } : undefined)` would both type-check while providing nothing at runtime.
|
|
26
|
+
*/
|
|
27
|
+
export interface ProvideNext {
|
|
28
|
+
(): Promise<Provided<{}>>;
|
|
29
|
+
<TLocals extends object>(locals: TLocals): Promise<Provided<TLocals>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What a stage returns: the result of `next(...)`, or a `Response` that stops the request.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* `any` accepts every provided shape; the shape each stage provides is read back from its own return type.
|
|
36
|
+
*/
|
|
37
|
+
export type StageResult = Provided<any> | Response;
|
|
38
|
+
/**
|
|
39
|
+
* The context a stage receives. `locals` holds what the stages before it provided.
|
|
40
|
+
*/
|
|
41
|
+
export type MiddlewareContext<TLocals extends object = {}> = Omit<FileRouteMiddlewareContext, 'locals'> & {
|
|
42
|
+
readonly locals: Readonly<TLocals>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* One stage: a function of the context and `next`.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam TIn - The locals provided by the stages before it
|
|
48
|
+
* @typeParam TResult - What it returns, inferred from the body
|
|
49
|
+
*/
|
|
50
|
+
export type MiddlewareStage<TIn extends object = {}, TResult extends StageResult | Promise<StageResult> = StageResult | Promise<StageResult>> = (context: MiddlewareContext<TIn>, next: ProvideNext) => TResult;
|
|
51
|
+
/**
|
|
52
|
+
* A middleware made by `createMiddleware` or `composeMiddleware`.
|
|
53
|
+
*
|
|
54
|
+
* @typeParam TLocals - Everything available after it runs: what it provides, and what the stages composed into
|
|
55
|
+
* it provide.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* The brand is required and keyed by a symbol the package does not export, so only `createMiddleware` and
|
|
59
|
+
* `composeMiddleware` make one. It is invariant in `TLocals`: a middleware cannot be upcast to one that proves
|
|
60
|
+
* fewer keys, such as `EcoMiddleware` (`{}`), and then listed where the fold would believe it provides nothing.
|
|
61
|
+
* Its runtime value is an identity function that nothing calls.
|
|
62
|
+
*/
|
|
63
|
+
export interface EcoMiddleware<TLocals extends object = {}> {
|
|
64
|
+
readonly [localsBrand]: (locals: TLocals) => TLocals;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An {@link EcoMiddleware} of any provided locals, for lists and constraints that accept every shape.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* `any` widens the check; each middleware's own locals are read back through {@link ListLocals}.
|
|
71
|
+
*/
|
|
72
|
+
export type AnyEcoMiddleware = EcoMiddleware<any>;
|
|
73
|
+
/**
|
|
74
|
+
* An entry of a `middleware` list: a made middleware, or an existing plain `(ctx, next)` function, which
|
|
75
|
+
* provides no locals.
|
|
76
|
+
*/
|
|
77
|
+
export type MiddlewareEntry = AnyEcoMiddleware | Middleware | FileRouteMiddleware;
|
|
78
|
+
/**
|
|
79
|
+
* An entry of an API route or group list. A plain function is typed with the context an API pipeline supplies, so
|
|
80
|
+
* an inline `(ctx, next) => ...` infers its parameters.
|
|
81
|
+
*/
|
|
82
|
+
export type ApiMiddlewareEntry = AnyEcoMiddleware | Middleware<Request, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* An entry of a page's `middleware` list. A plain function is typed with the context a page pipeline supplies,
|
|
85
|
+
* which carries no `query` or schema results.
|
|
86
|
+
*/
|
|
87
|
+
export type PageMiddlewareEntry = AnyEcoMiddleware | FileRouteMiddleware;
|
|
88
|
+
/**
|
|
89
|
+
* The form a stage takes once running: the pipeline supplies the context and a `next` that merges what a stage
|
|
90
|
+
* provides into `ctx.locals`.
|
|
91
|
+
*/
|
|
92
|
+
export type RuntimeMiddlewareStage = (context: never, next: never) => unknown;
|
|
93
|
+
/** What a stage returns with the locals it provided, or `{}` when it only returns a `Response`. */
|
|
94
|
+
export type ProvidedBy<TResult> = [Extract<TResult, Provided<any>>] extends [never] ? {} : ProvidedOf<Extract<TResult, Provided<any>>>;
|
|
95
|
+
type ProvidedOf<TResult> = TResult extends Provided<infer TLocals> ? TLocals : never;
|
|
96
|
+
type Simplify<T> = {
|
|
97
|
+
[K in keyof T]: T[K];
|
|
98
|
+
} & {};
|
|
99
|
+
/**
|
|
100
|
+
* Later keys override earlier ones, as the runtime merge does. A union on either side stays a union, so a
|
|
101
|
+
* stage that provides different keys on different paths keeps every earlier local.
|
|
102
|
+
*/
|
|
103
|
+
export type MergeLocals<TBefore, TAfter> = TBefore extends unknown ? TAfter extends unknown ? Simplify<Omit<TBefore, keyof TAfter> & TAfter> : never : never;
|
|
104
|
+
/**
|
|
105
|
+
* What a middleware of unknown locals provides, such as one typed {@link AnyEcoMiddleware}: it may overwrite any
|
|
106
|
+
* key, so it marks the fold instead of naming keys.
|
|
107
|
+
*/
|
|
108
|
+
type UnknownLocals = {
|
|
109
|
+
readonly [unknownLocals]: true;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* What a made middleware leaves available after it runs; nothing for a plain function, and
|
|
113
|
+
* {@link UnknownLocals} for a middleware whose locals are `any` or an index signature.
|
|
114
|
+
*/
|
|
115
|
+
export type TotalOf<TEntry> = TEntry extends EcoMiddleware<infer TLocals> ? 0 extends 1 & TLocals ? UnknownLocals : string extends keyof TLocals ? UnknownLocals : TLocals : {};
|
|
116
|
+
/** The locals before an entry of unknown provision: every key stays, typed `unknown`, so a direct read fails. */
|
|
117
|
+
type Unproven<TAcc> = TAcc extends unknown ? {
|
|
118
|
+
[K in keyof TAcc]: unknown;
|
|
119
|
+
} : never;
|
|
120
|
+
type Step<TAcc, TTotal> = [Extract<TTotal, UnknownLocals>] extends [never] ? MergeLocals<TAcc, TTotal> : Unproven<TAcc>;
|
|
121
|
+
/**
|
|
122
|
+
* The locals after a whole list runs, in order, starting from `TAcc`, the locals a group already provided.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* A list whose rest is not a fixed tuple, such as a spread array, may run its elements any number of times or
|
|
126
|
+
* not at all. Its elements can overwrite a key from before, so every key they may provide takes the union of
|
|
127
|
+
* the earlier type and theirs, and a key only they provide may be missing. An entry of unknown locals, such as
|
|
128
|
+
* one typed `AnyEcoMiddleware`, in the fixed part or the rest, may overwrite every key, so each key before it
|
|
129
|
+
* becomes `unknown`: nothing before it is proven, and only a later entry proves a key again.
|
|
130
|
+
*/
|
|
131
|
+
export type ListLocals<TList extends readonly unknown[], TAcc = {}> = TList extends readonly [
|
|
132
|
+
infer THead,
|
|
133
|
+
...infer TTail
|
|
134
|
+
] ? ListLocals<TTail, Step<TAcc, TotalOf<THead>>> : TList extends readonly [] ? Simplify<TAcc> : RestLocals<TAcc, TotalOf<TList[number]>>;
|
|
135
|
+
type RestLocals<TAcc, TElement> = [Extract<TElement, UnknownLocals>] extends [never] ? MaybeOverwritten<TAcc, TElement> : Simplify<Unproven<TAcc>>;
|
|
136
|
+
type MaybeOverwritten<TAcc, TElement> = TElement extends unknown ? Simplify<Omit<TAcc, keyof TElement> & {
|
|
137
|
+
[K in keyof TElement]: K extends keyof TAcc ? TAcc[K] | TElement[K] : TElement[K] | undefined;
|
|
138
|
+
}> : never;
|
|
139
|
+
/** A middleware, or an inline stage typed from the locals before it: one input of `composeMiddleware`. */
|
|
140
|
+
export type MiddlewareStageInput<TIn extends object> = AnyEcoMiddleware | MiddlewareStage<TIn>;
|
|
141
|
+
/** The locals after one more stage or middleware. */
|
|
142
|
+
export type MiddlewareLocalsAfter<TIn extends object, TStage> = TStage extends EcoMiddleware<infer TLocals> ? MergeLocals<TIn, TLocals> : TStage extends (...args: never) => infer TResult ? MergeLocals<TIn, ProvidedBy<Awaited<TResult>>> : TIn;
|
|
143
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { ApiHandler, ApiHandlerContext, BrowserForeignChildHost, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutEntrySpec, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent,
|
|
1
|
+
export type { ApiHandler, ApiHandlerContext, ApiMiddlewareContext, BrowserForeignChildHost, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, DynamicEcoPageComponent, DynamicPageDependenciesInput, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutEntrySpec, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetDynamicPageDependencies, GetDynamicPageDependenciesContext, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetPaths, GetProps, GetRequestProps, HtmlTemplateProps, LayoutProps, LayoutBuildContext, LayoutPropsContext, LayoutRequestContext, Middleware, MiddlewareList, WithMiddlewareLocals, MiddlewareNext, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageBuildContext, PageParams, PageQuery, PageRequestContext, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRobotsMetadata, RenderContext, RenderOptions, RouteGroupBuilder, RouteHandlerContext, RouteMethod, RouteOptions, RouteSchema, SitemapConfig, StaticCacheStrategy, StaticEcoPageComponent, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, PagePath, WebSocketCloseInfo, } from './contracts.js';
|
|
2
2
|
export type { ViewReference } from './view-reference.js';
|
|
3
3
|
export type { CacheConfig, CacheStrategy } from './cache-types.js';
|
|
4
|
-
export type { CallableComponentOf, ChildrenOf, ComponentOptions, Eco, EcoEmbedProps, EmbedPropsOf, HtmlOptions, LayoutOptions, LazyTrigger, PageOptions, PageOptionsBase,
|
|
4
|
+
export type { CallableComponentOf, ChildrenOf, ComponentOptions, Eco, EcoEmbedProps, EmbedPropsOf, HtmlOptions, LayoutOptions, LazyTrigger, DynamicPageOptions, PageOptions, PageOptionsBase, StaticPageOptions, PropsOf, ResultOf, } from './eco-api-types.js';
|
|
5
|
+
export type { AnyEcoMiddleware, EcoMiddleware, ListLocals, MergeLocals, MiddlewareContext, MiddlewareEntry, MiddlewareStage, ProvideNext, Provided, StageResult, } from './middleware-types.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare const FILE_ROLES: readonly ["api", "server", "script"];
|
|
2
|
+
type FileRole = (typeof FILE_ROLES)[number];
|
|
3
|
+
/** Suffixes that mark a file under the pages directory as an endpoint: `.api.ts`, `.api.tsx`, `.api.js`, `.api.jsx`. */
|
|
4
|
+
export declare const ENDPOINT_FILE_EXTENSIONS: readonly string[];
|
|
5
|
+
/** Every role suffix: `<name>.<role>.<ts|tsx|js|jsx>` for `api`, `server` and `script`. */
|
|
6
|
+
export declare const FILE_ROLE_SUFFIXES: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* Returns the role `file` declares by its name and the suffix that declares it, or `undefined` for a file with none.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* `api` is an endpoint, `server` a server-only module no browser module may reach, `script` a browser script.
|
|
12
|
+
* The last two are never Pages.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchRoleSuffix(file: string): {
|
|
15
|
+
role: FileRole;
|
|
16
|
+
suffix: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the role segment of `file` when it sits anywhere but directly before a script extension, as in
|
|
20
|
+
* `card.server.kita.tsx` or `nav.script.lit.tsx`, or `undefined` when the name has none or a well-formed one.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The name's first segment is never a role, so `server.tsx` and `api.ts` are ordinary names. A role segment
|
|
24
|
+
* followed by a template extension is ambiguous (a server-only file or a Page of that Integration), so it is
|
|
25
|
+
* rejected instead of read one way.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findMisplacedRole(file: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Whether `relativePath`, relative to the pages directory, has a segment starting with `_`.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* A private file or folder is never a route: `_layout.tsx`, `_card.tsx`, `_test/page.tsx`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isPrivatePath(relativePath: string): boolean;
|
|
35
|
+
/** The forms a role file name takes, for error messages. */
|
|
36
|
+
export declare function describeRoleForms(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether `specifier` names a `.server` module: `<name>.server`, with or without a script extension.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Ignores the query and fragment suffixes module resolver plugins add, so import pruning and browser
|
|
42
|
+
* resolution enforce the same boundary. `.mjs` and `.cjs` stay on the list because a package's published
|
|
43
|
+
* output may use them. A template extension after `.server` (`card.server.kita.tsx`) does not make a file
|
|
44
|
+
* server-only: the router rejects that name. This module has no runtime dependencies and is safe to import
|
|
45
|
+
* in the browser.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isServerOnlyModuleSpecifier(specifier: string): boolean;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const FILE_ROLES = ['api', 'server', 'script'];
|
|
2
|
+
/**
|
|
3
|
+
* The script extensions a role suffix may end in.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Never a template extension: a role file has no Integration owner, Layout or Cache Strategy, so
|
|
7
|
+
* config assembly rejects an Integration whose extensions end in a role suffix.
|
|
8
|
+
*/
|
|
9
|
+
const FILE_ROLE_SCRIPT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
|
|
10
|
+
function suffixesOf(role) {
|
|
11
|
+
return FILE_ROLE_SCRIPT_EXTENSIONS.map((extension) => `.${role}${extension}`);
|
|
12
|
+
}
|
|
13
|
+
/** Suffixes that mark a file under the pages directory as an endpoint: `.api.ts`, `.api.tsx`, `.api.js`, `.api.jsx`. */
|
|
14
|
+
export const ENDPOINT_FILE_EXTENSIONS = suffixesOf('api');
|
|
15
|
+
/** Every role suffix: `<name>.<role>.<ts|tsx|js|jsx>` for `api`, `server` and `script`. */
|
|
16
|
+
export const FILE_ROLE_SUFFIXES = FILE_ROLES.flatMap(suffixesOf);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the role `file` declares by its name and the suffix that declares it, or `undefined` for a file with none.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* `api` is an endpoint, `server` a server-only module no browser module may reach, `script` a browser script.
|
|
22
|
+
* The last two are never Pages.
|
|
23
|
+
*/
|
|
24
|
+
export function matchRoleSuffix(file) {
|
|
25
|
+
for (const role of FILE_ROLES) {
|
|
26
|
+
const suffix = suffixesOf(role).find((candidate) => file.endsWith(candidate));
|
|
27
|
+
if (suffix)
|
|
28
|
+
return { role, suffix };
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the role segment of `file` when it sits anywhere but directly before a script extension, as in
|
|
34
|
+
* `card.server.kita.tsx` or `nav.script.lit.tsx`, or `undefined` when the name has none or a well-formed one.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* The name's first segment is never a role, so `server.tsx` and `api.ts` are ordinary names. A role segment
|
|
38
|
+
* followed by a template extension is ambiguous (a server-only file or a Page of that Integration), so it is
|
|
39
|
+
* rejected instead of read one way.
|
|
40
|
+
*/
|
|
41
|
+
export function findMisplacedRole(file) {
|
|
42
|
+
const parts = (file.split('/').pop() ?? file).split('.');
|
|
43
|
+
const wellFormedIndex = FILE_ROLE_SCRIPT_EXTENSIONS.includes(`.${parts[parts.length - 1]}`) ? parts.length - 2 : -1;
|
|
44
|
+
for (let index = 1; index < parts.length; index += 1) {
|
|
45
|
+
const segment = parts[index] ?? '';
|
|
46
|
+
if (FILE_ROLES.includes(segment) && index !== wellFormedIndex) {
|
|
47
|
+
return segment;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether `relativePath`, relative to the pages directory, has a segment starting with `_`.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* A private file or folder is never a route: `_layout.tsx`, `_card.tsx`, `_test/page.tsx`.
|
|
57
|
+
*/
|
|
58
|
+
export function isPrivatePath(relativePath) {
|
|
59
|
+
return relativePath.split('/').some((segment) => segment.startsWith('_'));
|
|
60
|
+
}
|
|
61
|
+
/** The forms a role file name takes, for error messages. */
|
|
62
|
+
export function describeRoleForms() {
|
|
63
|
+
return FILE_ROLES.map((role) => `<name>.${role}.<ts|tsx|js|jsx>`).join(', ');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether `specifier` names a `.server` module: `<name>.server`, with or without a script extension.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Ignores the query and fragment suffixes module resolver plugins add, so import pruning and browser
|
|
70
|
+
* resolution enforce the same boundary. `.mjs` and `.cjs` stay on the list because a package's published
|
|
71
|
+
* output may use them. A template extension after `.server` (`card.server.kita.tsx`) does not make a file
|
|
72
|
+
* server-only: the router rejects that name. This module has no runtime dependencies and is safe to import
|
|
73
|
+
* in the browser.
|
|
74
|
+
*/
|
|
75
|
+
export function isServerOnlyModuleSpecifier(specifier) {
|
|
76
|
+
const queryStart = specifier.indexOf('?');
|
|
77
|
+
const fragmentStart = specifier.indexOf('#');
|
|
78
|
+
const suffixStart = Math.min(queryStart === -1 ? specifier.length : queryStart, fragmentStart === -1 ? specifier.length : fragmentStart);
|
|
79
|
+
const path = specifier.slice(0, suffixStart);
|
|
80
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
81
|
+
return [...FILE_ROLE_SCRIPT_EXTENSIONS, '.mjs', '.cjs', ''].some((extension) => {
|
|
82
|
+
const suffix = `.server${extension}`;
|
|
83
|
+
return name.length > suffix.length && name.endsWith(suffix);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Every specifier `node:module` lists as a built-in, without the `node:` prefix, subpaths such as `fs/promises` included. */
|
|
2
|
+
export declare const nodeBuiltinSpecifiers: ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Whether `specifier` names a Node built-in, with or without the `node:` prefix.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The one owner of this question: the browser guard and the React client graph both ask it. A package named like a
|
|
8
|
+
* subpath `builtinModules` does not list (`path-browserify`) is not a built-in.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isNodeBuiltinSpecifier(specifier: string): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { builtinModules } from 'node:module';
|
|
2
|
+
/** Every specifier `node:module` lists as a built-in, without the `node:` prefix, subpaths such as `fs/promises` included. */
|
|
3
|
+
export const nodeBuiltinSpecifiers = new Set(builtinModules);
|
|
4
|
+
/**
|
|
5
|
+
* Whether `specifier` names a Node built-in, with or without the `node:` prefix.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The one owner of this question: the browser guard and the React client graph both ask it. A package named like a
|
|
9
|
+
* subpath `builtinModules` does not list (`path-browserify`) is not a built-in.
|
|
10
|
+
*/
|
|
11
|
+
export function isNodeBuiltinSpecifier(specifier) {
|
|
12
|
+
return specifier.startsWith('node:') || nodeBuiltinSpecifiers.has(specifier);
|
|
13
|
+
}
|
|
@@ -402,8 +402,8 @@ export class ProjectWatcher {
|
|
|
402
402
|
const activeWorkspacePackageRoots = new Set(this.workspacePackageRoots.filter((root) => recordedWatchPaths.some((filePath) => isPathInside(filePath, root))));
|
|
403
403
|
const srcDir = this.appConfig.absolutePaths.srcDir;
|
|
404
404
|
const literalPaths = new Set([srcDir]);
|
|
405
|
-
const { pagesDir,
|
|
406
|
-
for (const sourceDir of [pagesDir,
|
|
405
|
+
const { pagesDir, includesDir, publicDir } = this.appConfig.absolutePaths;
|
|
406
|
+
for (const sourceDir of [pagesDir, includesDir, publicDir]) {
|
|
407
407
|
if (!isPathInside(sourceDir, srcDir) && fileSystem.exists(sourceDir)) {
|
|
408
408
|
literalPaths.add(sourceDir);
|
|
409
409
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @remarks
|
|
3
|
-
* Matches the `.server` naming convention with or without a file extension,
|
|
4
|
-
* ignoring query and fragment suffixes used by module resolver plugins,
|
|
5
|
-
* so import pruning and browser resolution enforce the same boundary.
|
|
6
|
-
* This module has no runtime dependencies and is safe to import in the browser.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isServerOnlyModuleSpecifier(specifier: string): boolean;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @remarks
|
|
3
|
-
* Matches the `.server` naming convention with or without a file extension,
|
|
4
|
-
* ignoring query and fragment suffixes used by module resolver plugins,
|
|
5
|
-
* so import pruning and browser resolution enforce the same boundary.
|
|
6
|
-
* This module has no runtime dependencies and is safe to import in the browser.
|
|
7
|
-
*/
|
|
8
|
-
export function isServerOnlyModuleSpecifier(specifier) {
|
|
9
|
-
const pathname = specifier.replace(/[?#].*$/, '');
|
|
10
|
-
return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(pathname);
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { decodeHtmlEntitiesUntilStable } from '../../../utils/html-entities.js';
|
|
2
|
-
export function normalizeUnresolvedMarkerArtifactHtml(html) {
|
|
3
|
-
return html.replace(/&(?:amp;)?lt;eco-marker\b[\s\S]*?&(?:amp;)?gt;&(?:amp;)?lt;\/eco-marker&(?:amp;)?gt;/g, (marker) => decodeHtmlEntitiesUntilStable(marker));
|
|
4
|
-
}
|
|
5
|
-
export function inspectUnresolvedMarkerArtifactHtml(html) {
|
|
6
|
-
const normalizedHtml = normalizeUnresolvedMarkerArtifactHtml(html);
|
|
7
|
-
return {
|
|
8
|
-
normalizedHtml,
|
|
9
|
-
hasUnresolvedMarkerArtifacts: normalizedHtml.includes('<eco-marker'),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { LocalsAccessError } from '../../../errors/locals-access-error.js';
|
|
2
|
-
/**
|
|
3
|
-
* Proxy that throws when dynamic route locals are accessed on non-dynamic pages.
|
|
4
|
-
*/
|
|
5
|
-
export function createPageLocalsProxy(filePath) {
|
|
6
|
-
const errorMessage = `[ecopages] Request locals are only available during request-time rendering with cache: 'dynamic'. Page: ${filePath}. If you meant to use locals here, set cache: 'dynamic' and provide locals from route middleware/handlers.`;
|
|
7
|
-
return new Proxy({}, {
|
|
8
|
-
get: () => {
|
|
9
|
-
throw new LocalsAccessError(errorMessage);
|
|
10
|
-
},
|
|
11
|
-
set: () => {
|
|
12
|
-
throw new LocalsAccessError(errorMessage);
|
|
13
|
-
},
|
|
14
|
-
has: () => {
|
|
15
|
-
throw new LocalsAccessError(errorMessage);
|
|
16
|
-
},
|
|
17
|
-
ownKeys: () => {
|
|
18
|
-
throw new LocalsAccessError(errorMessage);
|
|
19
|
-
},
|
|
20
|
-
deleteProperty: () => {
|
|
21
|
-
throw new LocalsAccessError(errorMessage);
|
|
22
|
-
},
|
|
23
|
-
defineProperty: () => {
|
|
24
|
-
throw new LocalsAccessError(errorMessage);
|
|
25
|
-
},
|
|
26
|
-
getOwnPropertyDescriptor: () => {
|
|
27
|
-
throw new LocalsAccessError(errorMessage);
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|