@bleedingdev/modern-js-renderer-core 0.0.0-bootstrap → 3.9.3-ultramodern.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/abort.js +65 -0
  3. package/dist/cjs/adapter.js +62 -0
  4. package/dist/cjs/data/body.js +78 -0
  5. package/dist/cjs/data/client.js +409 -0
  6. package/dist/cjs/data/codec.js +168 -0
  7. package/dist/cjs/data/index.js +125 -0
  8. package/dist/cjs/data/private.js +77 -0
  9. package/dist/cjs/data/routes.js +149 -0
  10. package/dist/cjs/data/server.js +791 -0
  11. package/dist/cjs/data/static.js +110 -0
  12. package/dist/cjs/data/tree.js +231 -0
  13. package/dist/cjs/data/types.js +56 -0
  14. package/dist/cjs/document.js +184 -0
  15. package/dist/cjs/entry-client.js +142 -0
  16. package/dist/cjs/entry-server.js +253 -0
  17. package/dist/cjs/federation.js +80 -0
  18. package/dist/cjs/identity.js +120 -0
  19. package/dist/cjs/index.js +46 -0
  20. package/dist/cjs/localization.js +48 -0
  21. package/dist/cjs/router.js +293 -0
  22. package/dist/cjs/server/assets.js +56 -0
  23. package/dist/cjs/server/dispatch.js +351 -0
  24. package/dist/cjs/server/index.js +57 -0
  25. package/dist/cjs/server/types.js +18 -0
  26. package/dist/cjs/server/worker.js +73 -0
  27. package/dist/cjs/session/cache.js +172 -0
  28. package/dist/cjs/session/index.js +63 -0
  29. package/dist/cjs/session/request.js +269 -0
  30. package/dist/cjs/session/types.js +18 -0
  31. package/dist/esm/abort.mjs +27 -0
  32. package/dist/esm/adapter.mjs +21 -0
  33. package/dist/esm/data/body.mjs +40 -0
  34. package/dist/esm/data/client.mjs +368 -0
  35. package/dist/esm/data/codec.mjs +112 -0
  36. package/dist/esm/data/index.mjs +7 -0
  37. package/dist/esm/data/private.mjs +39 -0
  38. package/dist/esm/data/routes.mjs +108 -0
  39. package/dist/esm/data/server.mjs +723 -0
  40. package/dist/esm/data/static.mjs +51 -0
  41. package/dist/esm/data/tree.mjs +193 -0
  42. package/dist/esm/data/types.mjs +6 -0
  43. package/dist/esm/document.mjs +131 -0
  44. package/dist/esm/entry-client.mjs +104 -0
  45. package/dist/esm/entry-server.mjs +215 -0
  46. package/dist/esm/federation.mjs +36 -0
  47. package/dist/esm/identity.mjs +63 -0
  48. package/dist/esm/index.mjs +1 -0
  49. package/dist/esm/localization.mjs +10 -0
  50. package/dist/esm/router.mjs +225 -0
  51. package/dist/esm/server/assets.mjs +15 -0
  52. package/dist/esm/server/dispatch.mjs +307 -0
  53. package/dist/esm/server/index.mjs +3 -0
  54. package/dist/esm/server/types.mjs +0 -0
  55. package/dist/esm/server/worker.mjs +35 -0
  56. package/dist/esm/session/cache.mjs +116 -0
  57. package/dist/esm/session/index.mjs +3 -0
  58. package/dist/esm/session/request.mjs +231 -0
  59. package/dist/esm/session/types.mjs +0 -0
  60. package/dist/esm-node/abort.mjs +28 -0
  61. package/dist/esm-node/adapter.mjs +22 -0
  62. package/dist/esm-node/data/body.mjs +41 -0
  63. package/dist/esm-node/data/client.mjs +369 -0
  64. package/dist/esm-node/data/codec.mjs +113 -0
  65. package/dist/esm-node/data/index.mjs +8 -0
  66. package/dist/esm-node/data/private.mjs +40 -0
  67. package/dist/esm-node/data/routes.mjs +109 -0
  68. package/dist/esm-node/data/server.mjs +724 -0
  69. package/dist/esm-node/data/static.mjs +52 -0
  70. package/dist/esm-node/data/tree.mjs +194 -0
  71. package/dist/esm-node/data/types.mjs +7 -0
  72. package/dist/esm-node/document.mjs +132 -0
  73. package/dist/esm-node/entry-client.mjs +105 -0
  74. package/dist/esm-node/entry-server.mjs +216 -0
  75. package/dist/esm-node/federation.mjs +37 -0
  76. package/dist/esm-node/identity.mjs +64 -0
  77. package/dist/esm-node/index.mjs +2 -0
  78. package/dist/esm-node/localization.mjs +11 -0
  79. package/dist/esm-node/router.mjs +226 -0
  80. package/dist/esm-node/server/assets.mjs +16 -0
  81. package/dist/esm-node/server/dispatch.mjs +308 -0
  82. package/dist/esm-node/server/index.mjs +4 -0
  83. package/dist/esm-node/server/types.mjs +1 -0
  84. package/dist/esm-node/server/worker.mjs +36 -0
  85. package/dist/esm-node/session/cache.mjs +117 -0
  86. package/dist/esm-node/session/index.mjs +4 -0
  87. package/dist/esm-node/session/request.mjs +232 -0
  88. package/dist/esm-node/session/types.mjs +1 -0
  89. package/dist/types/abort.d.ts +6 -0
  90. package/dist/types/adapter.d.ts +195 -0
  91. package/dist/types/data/body.d.ts +2 -0
  92. package/dist/types/data/client.d.ts +17 -0
  93. package/dist/types/data/codec.d.ts +14 -0
  94. package/dist/types/data/index.d.ts +8 -0
  95. package/dist/types/data/private.d.ts +6 -0
  96. package/dist/types/data/routes.d.ts +28 -0
  97. package/dist/types/data/server.d.ts +59 -0
  98. package/dist/types/data/static.d.ts +31 -0
  99. package/dist/types/data/tree.d.ts +3 -0
  100. package/dist/types/data/types.d.ts +104 -0
  101. package/dist/types/document.d.ts +76 -0
  102. package/dist/types/entry-client.d.ts +53 -0
  103. package/dist/types/entry-server.d.ts +63 -0
  104. package/dist/types/federation.d.ts +56 -0
  105. package/dist/types/identity.d.ts +27 -0
  106. package/dist/types/index.d.ts +1 -0
  107. package/dist/types/localization.d.ts +58 -0
  108. package/dist/types/router.d.ts +201 -0
  109. package/dist/types/server/assets.d.ts +14 -0
  110. package/dist/types/server/dispatch.d.ts +11 -0
  111. package/dist/types/server/index.d.ts +4 -0
  112. package/dist/types/server/types.d.ts +64 -0
  113. package/dist/types/server/worker.d.ts +25 -0
  114. package/dist/types/session/cache.d.ts +25 -0
  115. package/dist/types/session/index.d.ts +4 -0
  116. package/dist/types/session/request.d.ts +8 -0
  117. package/dist/types/session/types.d.ts +48 -0
  118. package/package.json +159 -4
  119. package/src/abort.ts +40 -0
  120. package/src/adapter.ts +255 -0
  121. package/src/data/body.ts +43 -0
  122. package/src/data/client.ts +501 -0
  123. package/src/data/codec.ts +247 -0
  124. package/src/data/index.ts +8 -0
  125. package/src/data/private.ts +68 -0
  126. package/src/data/routes.ts +201 -0
  127. package/src/data/server.ts +977 -0
  128. package/src/data/static.ts +105 -0
  129. package/src/data/tree.ts +244 -0
  130. package/src/data/types.ts +98 -0
  131. package/src/document.ts +338 -0
  132. package/src/entry-client.ts +236 -0
  133. package/src/entry-server.ts +393 -0
  134. package/src/federation.ts +111 -0
  135. package/src/identity.ts +128 -0
  136. package/src/index.ts +7 -0
  137. package/src/localization.ts +77 -0
  138. package/src/router.ts +475 -0
  139. package/src/server/assets.ts +60 -0
  140. package/src/server/dispatch.ts +523 -0
  141. package/src/server/index.ts +16 -0
  142. package/src/server/types.ts +94 -0
  143. package/src/server/worker.ts +94 -0
  144. package/src/session/cache.ts +177 -0
  145. package/src/session/index.ts +11 -0
  146. package/src/session/request.ts +324 -0
  147. package/src/session/types.ts +60 -0
@@ -0,0 +1,104 @@
1
+ import type { RendererIdentity } from '../identity.js';
2
+ export declare const DATA_PROTOCOL_VERSION: 1;
3
+ export declare const DATA_CONTENT_TYPE = "application/vnd.ultramodern.data+json";
4
+ export declare const DATA_STREAM_CONTENT_TYPE = "application/vnd.ultramodern.data-stream+json";
5
+ export declare const LOADER_ID_PARAM = "__loader";
6
+ export declare const DIRECT_PARAM = "__ssrDirect";
7
+ export type DataOperation = 'loader' | 'action';
8
+ export type DataHeaders = [string, string][];
9
+ export interface DataResponseMetadata {
10
+ status: number;
11
+ statusText: string;
12
+ headers: DataHeaders;
13
+ cachePolicy: 'no-store' | 'private' | 'public';
14
+ }
15
+ export interface PublicDataError {
16
+ name: string;
17
+ message: string;
18
+ stack?: string;
19
+ }
20
+ export type DataOutcome = {
21
+ kind: 'success';
22
+ value: unknown;
23
+ response: DataResponseMetadata;
24
+ } | {
25
+ kind: 'redirect';
26
+ location: string;
27
+ response: DataResponseMetadata;
28
+ } | {
29
+ kind: 'not-found';
30
+ value: unknown;
31
+ thrown: boolean;
32
+ response: DataResponseMetadata;
33
+ } | {
34
+ kind: 'error';
35
+ error: PublicDataError;
36
+ data?: unknown;
37
+ thrown: boolean;
38
+ response: DataResponseMetadata;
39
+ } | {
40
+ kind: 'deferred';
41
+ critical: Record<string, unknown>;
42
+ deferred: Record<string, Promise<unknown>>;
43
+ response: DataResponseMetadata;
44
+ };
45
+ export interface DataHandlerInput<Context = unknown> {
46
+ request: Request;
47
+ routeId: string;
48
+ params: Readonly<Record<string, string>>;
49
+ context: Context;
50
+ }
51
+ export type DataHandler<Context = unknown> = (input: DataHandlerInput<Context>) => unknown | Promise<unknown>;
52
+ /** The native router supplies an authorized match, never a shared matcher. */
53
+ export interface SelectedDataRoute<Context = unknown> {
54
+ routeId: string;
55
+ params: Readonly<Record<string, string>>;
56
+ handler: DataHandler<Context>;
57
+ }
58
+ export interface DataWireEnvelope {
59
+ version: typeof DATA_PROTOCOL_VERSION;
60
+ identity: RendererIdentity;
61
+ routeId: string;
62
+ operation: DataOperation;
63
+ outcome: PublicDataOutcome;
64
+ deferredKeys?: string[];
65
+ }
66
+ /** Header values and request-owned context never enter a public payload. */
67
+ export type PublicDataOutcome = {
68
+ kind: 'success';
69
+ value: unknown;
70
+ status: number;
71
+ } | {
72
+ kind: 'redirect';
73
+ location: string;
74
+ status: number;
75
+ } | {
76
+ kind: 'not-found';
77
+ value: unknown;
78
+ thrown: boolean;
79
+ status: number;
80
+ } | {
81
+ kind: 'error';
82
+ error: PublicDataError;
83
+ data?: unknown;
84
+ thrown: boolean;
85
+ status: number;
86
+ };
87
+ /** A deferred body is successful only when its terminal framing completes. */
88
+ export type DecodedDataOutcome = PublicDataOutcome & {
89
+ completion?: Promise<void>;
90
+ };
91
+ export type DataStreamFrame = {
92
+ type: 'initial';
93
+ envelope: DataWireEnvelope;
94
+ } | {
95
+ type: 'resolve';
96
+ key: string;
97
+ value: unknown;
98
+ } | {
99
+ type: 'reject';
100
+ key: string;
101
+ error: PublicDataError;
102
+ } | {
103
+ type: 'complete';
104
+ };
@@ -0,0 +1,76 @@
1
+ import { type RendererIdentity } from './identity.js';
2
+ export interface DocumentAsset {
3
+ readonly kind: 'stylesheet' | 'modulepreload' | 'script';
4
+ readonly href: string;
5
+ readonly integrity?: string;
6
+ readonly crossOrigin?: 'anonymous' | 'use-credentials';
7
+ readonly scriptType?: 'module' | 'classic';
8
+ }
9
+ /** Preserve the native adapter's order. Equal asset claims collapse; conflicts fail. */
10
+ export declare function collectDocumentAssets(assets: readonly DocumentAsset[]): readonly DocumentAsset[];
11
+ /** Serialize asset metadata only. The native renderer decides its document position. */
12
+ export declare function serializeDocumentAsset(asset: DocumentAsset, nonce?: string, options?: {
13
+ readonly async?: boolean;
14
+ readonly defer?: boolean;
15
+ }): string;
16
+ /**
17
+ * Frame JSON text as an inert `<script type="application/json">` element.
18
+ * This is the one place inline document data is escaped for HTML.
19
+ */
20
+ export declare function serializeInlineData(input: {
21
+ readonly id: string;
22
+ /** JSON text, such as `serializePublicData` output or `JSON.stringify`. */
23
+ readonly payload: string;
24
+ readonly nonce?: string;
25
+ }): string;
26
+ /** Element id of the renderer bootstrap every native client reads first. */
27
+ export declare const RENDERER_BOOTSTRAP_ID = "__ULTRAMODERN_RENDERER__";
28
+ /** What the server tells the client about the document before it starts. */
29
+ export interface DocumentBootstrap {
30
+ readonly identity: Readonly<RendererIdentity>;
31
+ /** The renderer's hydration/render id for this response. */
32
+ readonly documentId: string;
33
+ readonly hydrating: boolean;
34
+ }
35
+ /** Public JSON a client module reads from the document before it starts. */
36
+ export interface DocumentInlineData {
37
+ readonly id: string;
38
+ /** JSON text; `serializeInlineData` escapes it for HTML. */
39
+ readonly payload: string;
40
+ }
41
+ export interface DocumentNonce {
42
+ readonly script?: string;
43
+ readonly style?: string;
44
+ }
45
+ export interface DocumentOptions {
46
+ readonly rootId?: string;
47
+ readonly lang?: string;
48
+ readonly nonce?: DocumentNonce;
49
+ readonly assets?: readonly DocumentAsset[];
50
+ /** Placed right after the renderer bootstrap, before entry scripts. */
51
+ readonly inlineData?: readonly DocumentInlineData[];
52
+ }
53
+ /** HTML fragments a native adapter places in its own document shell. */
54
+ export interface DocumentParts {
55
+ /** Escaped attribute values. */
56
+ readonly rootId: string;
57
+ readonly lang: string;
58
+ /** Stylesheets and module preloads. */
59
+ readonly headAssets: string;
60
+ /** The renderer bootstrap followed by the inline data elements. */
61
+ readonly bootstrap: string;
62
+ /** Entry scripts, scheduled so hydration starts before the stream ends. */
63
+ readonly entryScripts: string;
64
+ }
65
+ /**
66
+ * Prepare the renderer-neutral parts of a native HTML document: assets, the
67
+ * renderer bootstrap and inline data. `extra` adds renderer-specific bootstrap
68
+ * fields, which the client reads with `readDocumentBootstrap`.
69
+ */
70
+ export declare function prepareDocument(bootstrap: DocumentBootstrap & Readonly<Record<string, unknown>>, options?: DocumentOptions): DocumentParts;
71
+ /**
72
+ * Read the server's bootstrap before creating a native router or owner. The
73
+ * identity must equal the client's build identity. Renderer-specific fields
74
+ * must be named in `extraFields` and are returned for the adapter to check.
75
+ */
76
+ export declare function readDocumentBootstrap(document: Pick<Document, 'querySelectorAll'>, expectedIdentity: RendererIdentity, extraFields?: readonly string[]): DocumentBootstrap & Readonly<Record<string, unknown>>;
@@ -0,0 +1,53 @@
1
+ import { type DocumentBootstrap } from './document.js';
2
+ import type { NativeFederationBinding } from './federation.js';
3
+ import type { RendererIdentity } from './identity.js';
4
+ import { type NativeEntryI18n, type NativeI18nInstance, type NativeI18nView } from './localization.js';
5
+ import { type NativeApplicationModule, type NativeRoutedApplication, type NativeRouterOptions } from './router.js';
6
+ export type * from './localization.js';
7
+ export type { NativeApplicationModule, NativeRoutedApplication, NativeRouterOptions, } from './router.js';
8
+ /** What a generated client entry passes to its renderer. */
9
+ export interface NativeClientEntryOptions<Instance extends NativeI18nInstance = NativeI18nInstance, LocalisedUrls = unknown> {
10
+ readonly identity: RendererIdentity;
11
+ readonly federation?: NativeFederationBinding;
12
+ /** The generated application module, imported after startup begins. */
13
+ readonly load: () => Promise<NativeApplicationModule>;
14
+ readonly i18n?: NativeEntryI18n<Instance, LocalisedUrls>;
15
+ /** The entry module's bundler HMR object, `import.meta.webpackHot`. */
16
+ readonly hot?: unknown;
17
+ /** The mount element id; must match the server entry's `rootId`. */
18
+ readonly rootId?: string;
19
+ }
20
+ /** The application view a renderer mounts or hydrates. */
21
+ export type NativeClientView<Router, Instance, LocalisedUrls> = {
22
+ readonly i18n?: NativeI18nView<Instance, LocalisedUrls>;
23
+ } & ({
24
+ readonly kind: 'component';
25
+ readonly component: unknown;
26
+ } | {
27
+ readonly kind: 'router';
28
+ readonly router: Router;
29
+ });
30
+ export interface NativeClientStart<Bootstrap extends DocumentBootstrap, Router, Instance, LocalisedUrls> {
31
+ readonly root: HTMLElement;
32
+ readonly identity: Readonly<RendererIdentity>;
33
+ readonly bootstrap: Bootstrap | undefined;
34
+ /** Aborts when the entry is disposed during startup. */
35
+ readonly signal: AbortSignal;
36
+ /** Import the application and prepare its router for this document. */
37
+ load(): Promise<NativeClientView<Router, Instance, LocalisedUrls>>;
38
+ }
39
+ /** The renderer's own document, router and root lifecycle. */
40
+ export interface NativeClientAdapter<Bootstrap extends DocumentBootstrap, Router extends object, Instance extends NativeI18nInstance, LocalisedUrls> {
41
+ readBootstrap(document: Document, identity: Readonly<RendererIdentity>): Bootstrap;
42
+ createRouter(application: NativeRoutedApplication, options: NativeRouterOptions): Router;
43
+ /** Load a fresh router, or adopt the server's matches when hydrating. */
44
+ prepareRouter(router: Router, hydrating: boolean, signal: AbortSignal): Promise<void>;
45
+ /** Mount or hydrate the root; resolves its disposal. */
46
+ start(input: NativeClientStart<Bootstrap, Router, Instance, LocalisedUrls>): Promise<() => void>;
47
+ }
48
+ /**
49
+ * Start a generated browser entry: find the mount element, read the server
50
+ * bootstrap, own HMR disposal and startup cancellation, and surface startup
51
+ * failures. The renderer adapter owns its router and root.
52
+ */
53
+ export declare function startNativeClientEntry<Bootstrap extends DocumentBootstrap, Router extends object, Instance extends NativeI18nInstance, LocalisedUrls>(options: NativeClientEntryOptions<Instance, LocalisedUrls>, adapter: NativeClientAdapter<Bootstrap, Router, Instance, LocalisedUrls>): void;
@@ -0,0 +1,63 @@
1
+ import { type DataOutcome } from './data/index.js';
2
+ import type { DocumentAsset, DocumentInlineData } from './document.js';
3
+ import type { NativeFederationBinding } from './federation.js';
4
+ import { type RendererIdentity } from './identity.js';
5
+ import { type NativeEntryI18n, type NativeI18nInstance, type NativeI18nView } from './localization.js';
6
+ import { type NativeApplicationModule, type NativeRoutedApplication, type NativeRouteMatch, type NativeRouteMatcher, type NativeRouterOptions } from './router.js';
7
+ import type { NativeRequestContext, NativeServerManifest } from './server/index.js';
8
+ import type { RequestSession } from './session/index.js';
9
+ export type * from './localization.js';
10
+ export type { NativeApplicationModule, NativeRoutedApplication, NativeRouterOptions, } from './router.js';
11
+ /** What a generated server entry passes to its renderer. */
12
+ export interface NativeServerEntryOptions<Instance extends NativeI18nInstance = NativeI18nInstance, LocalisedUrls = unknown> {
13
+ readonly identity: RendererIdentity;
14
+ readonly federation?: NativeFederationBinding;
15
+ /** The generated application module, imported per request. */
16
+ readonly app: () => Promise<NativeApplicationModule>;
17
+ readonly i18n?: NativeEntryI18n<Instance, LocalisedUrls>;
18
+ /** The document mount element id; the client entry must use the same. */
19
+ readonly rootId?: string;
20
+ }
21
+ /** The renderer-neutral part of one response document. */
22
+ export interface NativeServerDocument {
23
+ readonly documentId: string;
24
+ readonly rootId: string;
25
+ readonly nonce?: string;
26
+ readonly assets?: readonly DocumentAsset[];
27
+ readonly lang?: string;
28
+ readonly inlineData?: readonly DocumentInlineData[];
29
+ }
30
+ export interface NativeServerRoutesInput<Router, Document, Instance, LocalisedUrls> {
31
+ /** The request bound to the session signal; data loaders observe it. */
32
+ readonly request: Request;
33
+ readonly context: NativeRequestContext;
34
+ readonly router: Router;
35
+ /** Blocking data outcomes, recorded while the router loads. */
36
+ readonly outcomes: readonly DataOutcome[];
37
+ readonly document: Document;
38
+ /** Request-private values the router must never serialize. */
39
+ readonly forbiddenValues: readonly object[];
40
+ readonly i18n?: NativeI18nView<Instance, LocalisedUrls>;
41
+ }
42
+ /** The renderer's own request scope, manifest, router and document. */
43
+ export interface NativeServerAdapter<Router extends NativeRouteMatcher<unknown, NativeRouteMatch>, Document extends NativeServerDocument, Instance extends NativeI18nInstance, LocalisedUrls> {
44
+ /** Validate the compiler manifest and complete the document. */
45
+ document(base: NativeServerDocument, nativeManifest: unknown, identity: Readonly<RendererIdentity>): Document;
46
+ /** Run one request inside the renderer's native request scope. */
47
+ run<Result>(session: RequestSession, callback: () => Promise<Result>): Promise<Result>;
48
+ /** Commit a terminal data or redirect response. */
49
+ respond(session: RequestSession, response: Response): Response;
50
+ createRouter(application: NativeRoutedApplication, options: NativeRouterOptions): Router;
51
+ renderCSR(context: NativeRequestContext, document: Document): Response | Promise<Response>;
52
+ renderComponent(context: NativeRequestContext, component: unknown, document: Document, i18n?: NativeI18nView<Instance, LocalisedUrls>): Promise<Response>;
53
+ /** Load the router, resolve its HTTP outcome and render the document. */
54
+ renderRoutes(input: NativeServerRoutesInput<Router, Document, Instance, LocalisedUrls>): Promise<Response>;
55
+ }
56
+ export type NativeServerEntry = Required<NativeServerManifest>;
57
+ /**
58
+ * Create the native transport handlers of a generated server entry: identity
59
+ * and session ownership, CSR and SSR documents, localized redirects, route
60
+ * matching and the data endpoint. The renderer adapter owns its request
61
+ * scope, router and document.
62
+ */
63
+ export declare function createNativeServerEntry<Router extends NativeRouteMatcher<unknown, NativeRouteMatch>, Document extends NativeServerDocument, Instance extends NativeI18nInstance, LocalisedUrls>(options: NativeServerEntryOptions<Instance, LocalisedUrls>, adapter: NativeServerAdapter<Router, Document, Instance, LocalisedUrls>): NativeServerEntry;
@@ -0,0 +1,56 @@
1
+ /** The application compiler's native Module Federation runtime. */
2
+ export interface FederationInstance {
3
+ /** The application's federation name, unique among this realm's instances. */
4
+ readonly name?: string;
5
+ loadRemote<T>(id: string): Promise<T | null>;
6
+ readonly remoteHandler?: {
7
+ readonly idToRemoteMap?: Record<string, {
8
+ name: string;
9
+ expose: string;
10
+ }>;
11
+ };
12
+ readonly moduleCache?: Map<string, {
13
+ readonly remoteInfo: unknown;
14
+ }>;
15
+ readonly snapshotHandler?: {
16
+ getGlobalRemoteInfo(info: unknown): {
17
+ remoteSnapshot?: RemoteSnapshot;
18
+ };
19
+ };
20
+ }
21
+ interface RemoteSnapshot {
22
+ readonly publicPath?: unknown;
23
+ readonly remoteEntry?: unknown;
24
+ readonly modules?: readonly {
25
+ readonly modulePath?: unknown;
26
+ readonly assets?: {
27
+ readonly js?: {
28
+ readonly sync?: readonly string[];
29
+ };
30
+ readonly css?: {
31
+ readonly sync?: readonly string[];
32
+ readonly async?: readonly string[];
33
+ };
34
+ };
35
+ }[];
36
+ }
37
+ /** Generated entries retain their own compiler's host, including on the server. */
38
+ export interface NativeFederationBinding {
39
+ readonly instance: () => FederationInstance;
40
+ /**
41
+ * Server bindings: the client module, relative to the client asset base,
42
+ * that loads a server-rendered remote through this host before hydration.
43
+ */
44
+ readonly hydrationModule?: string;
45
+ }
46
+ export interface FederatedAssets {
47
+ readonly js: readonly string[];
48
+ readonly css: readonly string[];
49
+ }
50
+ /** Capture the host before importing application modules or remote containers. */
51
+ export declare function getFederationHost(binding: NativeFederationBinding | undefined): FederationInstance | undefined;
52
+ /** Load through the selected application's runtime, never another app's host. */
53
+ export declare function loadFederatedModule<T>(instance: FederationInstance | undefined, id: string): Promise<T>;
54
+ /** Browser assets from the native snapshot that admitted and loaded this remote. */
55
+ export declare function remoteBrowserAssets(instance: FederationInstance, id: string): FederatedAssets | undefined;
56
+ export {};
@@ -0,0 +1,27 @@
1
+ export type Renderer = string;
2
+ /** Immutable identity for one application entry and its hydration bytes. */
3
+ export interface RendererIdentity {
4
+ renderer: Renderer;
5
+ appId: string;
6
+ entryName: string;
7
+ protocolVersion: 1;
8
+ buildId: string;
9
+ }
10
+ export declare function resolveRenderer(value?: unknown): Renderer;
11
+ export declare function identityCacheKey(identity: RendererIdentity): string;
12
+ export declare function assertRendererIdentity(actual: RendererIdentity, expected: RendererIdentity): void;
13
+ /**
14
+ * Read an identity from untrusted JSON (a document bootstrap or a build
15
+ * manifest). It must be a plain record with exactly the identity fields and
16
+ * equal the identity this application was built with.
17
+ */
18
+ export declare function readRendererIdentity(value: unknown, expected: RendererIdentity): Readonly<RendererIdentity>;
19
+ /** The emitted client compiler manifest for one native renderer entry. */
20
+ export declare function nativeModuleManifestFilename(renderer: Renderer, entryName: string): string;
21
+ /** Response header naming the built entry identity that rendered a document. */
22
+ export declare const RENDERER_IDENTITY_HEADER = "x-ultramodern-renderer-identity";
23
+ /**
24
+ * Serialize an entry identity as an ASCII-only header value (JSON with
25
+ * non-ASCII code units escaped), so every host emits the same bytes.
26
+ */
27
+ export declare function serializeRendererIdentityHeader(identity: RendererIdentity): string;
@@ -0,0 +1 @@
1
+ export { assertRendererIdentity, identityCacheKey, type Renderer, type RendererIdentity, resolveRenderer, } from './identity.js';
@@ -0,0 +1,58 @@
1
+ import type { DocumentInlineData } from './document.js';
2
+ import type { NativeLocationRewrite } from './router.js';
3
+ /** `{ [namespace]: { [key]: value } }` for one language. */
4
+ export type NativeI18nResources = Record<string, Record<string, unknown>>;
5
+ export type NativeRequestLanguage = {
6
+ readonly kind: 'language';
7
+ readonly language: string;
8
+ /** Request headers the language was detected from, for `Vary`. */
9
+ readonly vary?: readonly string[];
10
+ } | {
11
+ readonly kind: 'redirect';
12
+ readonly language: string;
13
+ readonly location: string;
14
+ };
15
+ /** A per-request or per-document translation instance, such as i18next's. */
16
+ export interface NativeI18nInstance {
17
+ readonly language: string;
18
+ }
19
+ /**
20
+ * Localized routing a native entry composes. `createNativeI18n()` from
21
+ * `@modern-js/i18n-runtime-extensions/native` implements it with i18next.
22
+ */
23
+ export interface NativeEntryI18n<Instance extends NativeI18nInstance = NativeI18nInstance, LocalisedUrls = unknown> {
24
+ readonly languages: readonly string[];
25
+ readonly localisedUrls?: LocalisedUrls;
26
+ /** The language of a request URL, or the redirect to its localized URL. */
27
+ resolveRequest(request: Request): NativeRequestLanguage;
28
+ redirect(location: string): Response;
29
+ /** A new, fully isolated instance for one request or one browser document. */
30
+ create(language: string, resources?: NativeI18nResources): Promise<Instance>;
31
+ /** The router rewrite: matching stays on canonical paths. */
32
+ rewrite(getLanguage: () => string): NativeLocationRewrite;
33
+ /** The document handoff of a language and, with an instance, its bundles. */
34
+ handoff(language: string, instance?: Instance): DocumentInlineData;
35
+ /** The server's language and bundles, read before the browser router starts. */
36
+ clientHandoff(): {
37
+ language: string;
38
+ resources?: NativeI18nResources;
39
+ };
40
+ /**
41
+ * History navigation to another language prefix switches the instance.
42
+ * Returns the cleanup that detaches it when the client entry is disposed.
43
+ */
44
+ syncWithRouter(router: object, instance: Instance): () => void;
45
+ /**
46
+ * Keep the document language and persisted language in step with the
47
+ * instance, for routed and component-only entries alike. Returns the
48
+ * cleanup that detaches it when the client entry is disposed.
49
+ */
50
+ persist?(instance: Instance): () => void;
51
+ }
52
+ /** What a renderer needs to provide localization to its application view. */
53
+ export interface NativeI18nView<Instance, LocalisedUrls> {
54
+ readonly instance: Instance;
55
+ readonly languages: readonly string[];
56
+ readonly localisedUrls?: LocalisedUrls;
57
+ }
58
+ export declare function nativeI18nView<Instance extends NativeI18nInstance, Urls>(i18n: NativeEntryI18n<Instance, Urls>, instance: Instance): NativeI18nView<Instance, Urls>;
@@ -0,0 +1,201 @@
1
+ import { untilAborted } from './abort.js';
2
+ import type { DataHandler, DataHandlerInput, DataOperation, DataOutcome, DecodedDataOutcome, FileSystemRouteIR, PublicDataOutcome, SelectedDataRoute } from './data/index.js';
3
+ import type { RendererIdentity } from './identity.js';
4
+ import type { RequestSession } from './session/index.js';
5
+ export interface FileSystemDataModule<Context = unknown> {
6
+ loader?: DataHandler<Context>;
7
+ action?: DataHandler<Context>;
8
+ }
9
+ export type RouteOutcome = DataOutcome | DecodedDataOutcome;
10
+ export interface FileSystemRouteOptions<Context = unknown, Router = unknown> {
11
+ /** The request owned by this router; carries RequestSession.signal. */
12
+ request?: Request;
13
+ /** Retires every route load, as a disposed browser entry does. */
14
+ signal?: AbortSignal;
15
+ /** The exact request owner validates native public snapshots (Solid). */
16
+ session?: RequestSession;
17
+ /** Private data-handler input; never part of native route context. */
18
+ context?: Context;
19
+ /** Resolve the native router once its route tree is installed (Octane). */
20
+ getRouter?: () => Router;
21
+ loadRoute?: (route: FileSystemRouteIR, input: DataHandlerInput<Context>) => Promise<RouteOutcome>;
22
+ /** The server resolves HTTP policy from blocking outcomes before rendering. */
23
+ onOutcome?: (routeId: string, outcome: RouteOutcome) => void;
24
+ }
25
+ /** A route boundary receives only the public error projection and its status. */
26
+ export declare class RouteDataError extends Error {
27
+ readonly status: number;
28
+ readonly data: unknown;
29
+ readonly routeId: string;
30
+ constructor(routeId: string, outcome: Extract<DataOutcome | PublicDataOutcome, {
31
+ kind: 'error';
32
+ }>);
33
+ }
34
+ /** The renderer binding's own redirect and not-found constructors. */
35
+ export interface NativeRouteSignals {
36
+ redirect(options: {
37
+ href: string;
38
+ statusCode: number;
39
+ headers?: HeadersInit;
40
+ }): unknown;
41
+ notFound(options: {
42
+ data: unknown;
43
+ }): unknown;
44
+ }
45
+ /**
46
+ * Turn a data outcome into loader data, or throw it into the native redirect,
47
+ * not-found or error boundary. `project` maps every public value first.
48
+ */
49
+ export declare function resolveRouteData(native: NativeRouteSignals, routeId: string, outcome: DataOutcome | PublicDataOutcome, project?: (value: unknown) => unknown): unknown;
50
+ /** Validate the filesystem shape: one application root and unique ids. */
51
+ export declare function splitFileSystemRoutes(routes: readonly FileSystemRouteIR[]): {
52
+ root: FileSystemRouteIR | undefined;
53
+ children: readonly FileSystemRouteIR[];
54
+ };
55
+ /** Native path (or pathless id) options for one filesystem route. */
56
+ export declare function nativeRoutePath(route: FileSystemRouteIR): {
57
+ path: string;
58
+ } | {
59
+ id: string;
60
+ };
61
+ export interface NativeLoaderMatch {
62
+ params: Record<string, string>;
63
+ location: {
64
+ publicHref: string;
65
+ };
66
+ abortController: AbortController;
67
+ }
68
+ /**
69
+ * Invoke a route's data handler for one native loader generation. The request
70
+ * carries the public URL (basepath included) and aborts with either owner.
71
+ */
72
+ export declare function loadFileSystemRoute<Context>(route: FileSystemRouteIR, loadRoute: NonNullable<FileSystemRouteOptions<Context>['loadRoute']>, options: FileSystemRouteOptions<Context>, { params, location, abortController }: NativeLoaderMatch): Promise<{
73
+ outcome: RouteOutcome;
74
+ request: Request;
75
+ signal: AbortSignal;
76
+ }>;
77
+ /** Renderer adapters race their authored router hooks with the same rule. */
78
+ export { untilAborted };
79
+ /** Location input accepted by a native router's parseLocation. */
80
+ export interface NativeHistoryLocation {
81
+ href: string;
82
+ pathname: string;
83
+ search: string;
84
+ hash: string;
85
+ state: {
86
+ __TSR_index: number;
87
+ };
88
+ }
89
+ export interface NativeRouteMatch {
90
+ routeId: string;
91
+ params: Readonly<Record<string, string>>;
92
+ }
93
+ export interface NativeRouteMatcher<Location, Match> {
94
+ parseLocation(location: NativeHistoryLocation): Location;
95
+ matchRoutes(location: Location): Match[];
96
+ routesById: Readonly<Record<string, {
97
+ options: {
98
+ staticData?: unknown;
99
+ };
100
+ } | undefined>>;
101
+ }
102
+ /**
103
+ * Match a public request URL through the router's own location parsing, so the
104
+ * basepath (a router rewrite) is removed exactly as navigation removes it.
105
+ */
106
+ export declare function matchApplicationRoutes<Location, Match>(router: NativeRouteMatcher<Location, Match>, url: URL): Match[];
107
+ /** The filesystem route ids a public request URL matches, outermost first. */
108
+ export declare function matchApplicationRouteIds<Location, Match extends {
109
+ routeId: string;
110
+ }>(router: NativeRouteMatcher<Location, Match>, url: URL): string[];
111
+ /** A requested data id must belong to the native router's match for this URL. */
112
+ export declare function selectApplicationDataRoute<Context, Location, Match extends NativeRouteMatch>(router: NativeRouteMatcher<Location, Match>, request: Request, requestedRouteId: string, operation: DataOperation, handlers: Readonly<Record<string, FileSystemDataModule<Context>>>): SelectedDataRoute<Context> | undefined;
113
+ /** One route's source module namespaces, as the generated application imports them. */
114
+ export interface NativeRouteSources {
115
+ readonly component?: {
116
+ readonly default?: unknown;
117
+ };
118
+ readonly pendingComponent?: {
119
+ readonly default?: unknown;
120
+ };
121
+ readonly errorComponent?: {
122
+ readonly default?: unknown;
123
+ };
124
+ readonly notFoundComponent?: {
125
+ readonly default?: unknown;
126
+ };
127
+ readonly head?: {
128
+ readonly head?: unknown;
129
+ readonly default?: unknown;
130
+ };
131
+ readonly search?: {
132
+ readonly validateSearch?: unknown;
133
+ readonly default?: unknown;
134
+ };
135
+ }
136
+ /** The generated module of a file-system routed entry: route sources and data. */
137
+ export interface NativeRoutedApplication {
138
+ /** The analyzed public prefix the router strips before matching. */
139
+ readonly basePath: string;
140
+ readonly routeIR: readonly FileSystemRouteIR[];
141
+ readonly routeModules: Readonly<Record<string, NativeRouteSources>>;
142
+ readonly dataModules: Readonly<Record<string, FileSystemDataModule>>;
143
+ /** Client graph only: routes whose loader runs on the server. */
144
+ readonly serverDataRoutes?: readonly string[];
145
+ }
146
+ /** The generated module of an entry that renders one component. */
147
+ export interface NativeComponentApplication {
148
+ readonly default: unknown;
149
+ }
150
+ export type NativeApplicationModule = NativeRoutedApplication | NativeComponentApplication;
151
+ export declare function isRoutedApplication(application: NativeApplicationModule): application is NativeRoutedApplication;
152
+ /** Structurally identical to router-core's `LocationRewrite`. */
153
+ export interface NativeLocationRewrite {
154
+ input?: (args: {
155
+ url: URL;
156
+ }) => undefined | string | URL;
157
+ output?: (args: {
158
+ url: URL;
159
+ }) => undefined | string | URL;
160
+ }
161
+ export interface NativeRouterOptions {
162
+ readonly identity: RendererIdentity;
163
+ readonly loadRoute: NonNullable<FileSystemRouteOptions['loadRoute']>;
164
+ /** The server request this router renders; a browser router omits it. */
165
+ readonly request?: Request;
166
+ /** Retires every route load of this router, e.g. on entry disposal. */
167
+ readonly signal?: AbortSignal;
168
+ /** Private data-handler input; never part of native route context. */
169
+ readonly context?: object;
170
+ readonly onOutcome?: (routeId: string, outcome: RouteOutcome) => void;
171
+ readonly session?: RequestSession;
172
+ /** The document CSP nonce the router stamps on its emitted scripts. */
173
+ readonly nonce?: string;
174
+ readonly rewrite?: NativeLocationRewrite;
175
+ }
176
+ /** Router options a renderer passes to its native router constructor. */
177
+ export interface NativeApplicationRouterOptions<Route> {
178
+ readonly routeTree: Route;
179
+ readonly basepath: string;
180
+ readonly context: {
181
+ readonly ultramodern: Readonly<{
182
+ rendererIdentity: Readonly<RendererIdentity>;
183
+ }>;
184
+ };
185
+ readonly rewrite?: NativeLocationRewrite;
186
+ readonly ssr?: {
187
+ readonly nonce: string;
188
+ };
189
+ /** A server router starts at the request location in memory history. */
190
+ readonly location?: {
191
+ readonly origin: string;
192
+ readonly href: string;
193
+ };
194
+ }
195
+ /** The renderer's own route tree and router constructors. */
196
+ export interface NativeRouterFactory<Route, Router> {
197
+ routeTree(routes: readonly FileSystemRouteIR[], modules: Readonly<Record<string, Record<string, unknown>>>, options: FileSystemRouteOptions<object, Router>): Route;
198
+ router(options: NativeApplicationRouterOptions<Route>): Router;
199
+ }
200
+ /** Create the native router of a generated routed application. */
201
+ export declare function createNativeRouter<Route, Router>(application: NativeRoutedApplication, options: NativeRouterOptions, factory: NativeRouterFactory<Route, Router>): Router;
@@ -0,0 +1,14 @@
1
+ import { type DocumentAsset } from '../document.js';
2
+ import { type Renderer, type RendererIdentity } from '../identity.js';
3
+ export declare const RENDERER_ASSET_MANIFEST_FILE = "renderer-assets.json";
4
+ export interface NativeClientAssetManifest {
5
+ readonly schema: 'ultramodern-renderer-assets';
6
+ readonly version: 1;
7
+ readonly renderer: Exclude<Renderer, 'react'>;
8
+ readonly entries: Readonly<Record<string, {
9
+ readonly rendererIdentity: RendererIdentity;
10
+ readonly assets: readonly DocumentAsset[];
11
+ }>>;
12
+ }
13
+ /** Read actual emitted initial assets, never infer URLs from source filenames. */
14
+ export declare function validateNativeClientAssetManifest(value: unknown, expectedIdentity: RendererIdentity): readonly DocumentAsset[];