@hamur/adapter-angular 0.0.0-stage → 0.0.2

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 (88) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +42 -2
  3. package/dist/chunks/browser-index-7h7x2xz2.js +131 -0
  4. package/dist/chunks/browser-index-nann848q.js +205 -0
  5. package/dist/chunks/browser-index-qn8q5fa2.js +580 -0
  6. package/dist/src/adapter.js +1075 -0
  7. package/dist/src/error-page.js +34 -0
  8. package/dist/src/index.js +1729 -0
  9. package/dist/src/keepalive.js +0 -0
  10. package/dist/src/runtime/client.js +21 -0
  11. package/dist/src/runtime/island.js +92 -0
  12. package/dist/src/runtime/server.js +175 -0
  13. package/dist/types/src/activation.d.ts +20 -0
  14. package/dist/types/src/adapter.d.ts +7 -0
  15. package/dist/types/src/app.d.ts +6 -0
  16. package/dist/types/src/async-data.d.ts +21 -0
  17. package/dist/types/src/client-parts.d.ts +35 -0
  18. package/dist/types/src/compile.d.ts +99 -0
  19. package/dist/types/src/context.d.ts +74 -0
  20. package/dist/types/src/data.d.ts +65 -0
  21. package/dist/types/src/definition.d.ts +13 -0
  22. package/dist/types/src/error-page.d.ts +8 -0
  23. package/dist/types/src/error.d.ts +4 -0
  24. package/dist/types/src/form.d.ts +68 -0
  25. package/dist/types/src/head.d.ts +12 -0
  26. package/dist/types/src/hmr.d.ts +14 -0
  27. package/dist/types/src/hydration.d.ts +16 -0
  28. package/dist/types/src/index.d.ts +24 -0
  29. package/dist/types/src/indicators.d.ts +76 -0
  30. package/dist/types/src/island.d.ts +42 -0
  31. package/dist/types/src/keepalive.d.ts +1 -0
  32. package/dist/types/src/link.d.ts +68 -0
  33. package/dist/types/src/markdown-page.d.ts +10 -0
  34. package/dist/types/src/markdown.d.ts +40 -0
  35. package/dist/types/src/mask.d.ts +12 -0
  36. package/dist/types/src/navigate.d.ts +17 -0
  37. package/dist/types/src/outlet.d.ts +76 -0
  38. package/dist/types/src/request.d.ts +31 -0
  39. package/dist/types/src/routing.d.ts +47 -0
  40. package/dist/types/src/runtime/client.d.ts +29 -0
  41. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  42. package/dist/types/src/runtime/hydration.d.ts +8 -0
  43. package/dist/types/src/runtime/island.d.ts +8 -0
  44. package/dist/types/src/runtime/server.d.ts +15 -0
  45. package/dist/types/src/server-island.d.ts +24 -0
  46. package/dist/types/src/state.d.ts +14 -0
  47. package/dist/types/src/svg.d.ts +15 -0
  48. package/dist/types/src/time.d.ts +40 -0
  49. package/dist/types/src/wrapper.d.ts +21 -0
  50. package/package.json +77 -4
  51. package/src/activation.ts +83 -0
  52. package/src/adapter.ts +107 -0
  53. package/src/app.ts +12 -0
  54. package/src/async-data.ts +105 -0
  55. package/src/client-parts.ts +107 -0
  56. package/src/compile.ts +963 -0
  57. package/src/context.ts +189 -0
  58. package/src/data.ts +389 -0
  59. package/src/definition.ts +144 -0
  60. package/src/error-page.ts +30 -0
  61. package/src/error.ts +15 -0
  62. package/src/form.ts +182 -0
  63. package/src/head.ts +63 -0
  64. package/src/hmr.ts +61 -0
  65. package/src/hydration.ts +120 -0
  66. package/src/index.ts +98 -0
  67. package/src/indicators.ts +220 -0
  68. package/src/island.ts +89 -0
  69. package/src/keepalive.ts +1 -0
  70. package/src/link.ts +214 -0
  71. package/src/markdown-page.ts +31 -0
  72. package/src/markdown.ts +140 -0
  73. package/src/mask.ts +36 -0
  74. package/src/navigate.ts +22 -0
  75. package/src/outlet.ts +316 -0
  76. package/src/request.ts +170 -0
  77. package/src/routing.ts +218 -0
  78. package/src/runtime/client.ts +140 -0
  79. package/src/runtime/contract.d.ts +4 -0
  80. package/src/runtime/hydration-dev.ts +18 -0
  81. package/src/runtime/hydration.ts +7 -0
  82. package/src/runtime/island.ts +109 -0
  83. package/src/runtime/server.ts +228 -0
  84. package/src/server-island.ts +67 -0
  85. package/src/state.ts +70 -0
  86. package/src/svg.ts +65 -0
  87. package/src/time.ts +115 -0
  88. package/src/wrapper.ts +187 -0
File without changes
@@ -0,0 +1,21 @@
1
+ import {
2
+ ClientErrors2,
3
+ documentNonce2,
4
+ hydrate2,
5
+ mount2,
6
+ update2
7
+ } from "../../chunks/browser-index-7h7x2xz2.js";
8
+ import {
9
+ clientComponentOnClient,
10
+ serverComponentOnClient
11
+ } from "../../chunks/browser-index-nann848q.js";
12
+ import"../../chunks/browser-index-qn8q5fa2.js";
13
+ export {
14
+ ClientErrors2 as ClientErrors,
15
+ clientComponentOnClient as clientComponent,
16
+ documentNonce2 as documentNonce,
17
+ hydrate2 as hydrate,
18
+ mount2 as mount,
19
+ serverComponentOnClient as serverComponent,
20
+ update2 as update
21
+ };
@@ -0,0 +1,92 @@
1
+ import {
2
+ islandHref,
3
+ createState,
4
+ hamurProviders,
5
+ setupOf
6
+ } from "../../chunks/browser-index-qn8q5fa2.js";
7
+ import {
8
+ HamurApp
9
+ } from "../../chunks/browser-index-nann848q.js";
10
+ import {
11
+ ClientErrors2,
12
+ documentNonce2
13
+ } from "../../chunks/browser-index-7h7x2xz2.js";
14
+
15
+ // packages/adapter-angular/src/runtime/island.ts
16
+ import { APP_ID, CSP_NONCE, ErrorHandler } from "@angular/core";
17
+ import {
18
+ createApplication,
19
+ provideClientHydration,
20
+ withEventReplay,
21
+ withNoHttpTransferCache
22
+ } from "@angular/platform-browser";
23
+ import { reportClientError, setAdapterInstance } from "hamur/adapter";
24
+ var HOST = "hamur-app";
25
+ var ISLAND_ENTRY = "island";
26
+ var islands = new WeakMap;
27
+ var sourceOf = (component, props, ctx) => ({
28
+ app: ctx.app,
29
+ route: ctx.route,
30
+ payload: {},
31
+ tree: { components: [{ id: ISLAND_ENTRY, component, props }] },
32
+ baseURL: ctx.baseURL,
33
+ href: islandHref(ctx.baseURL)
34
+ });
35
+ async function start(el, component, props, ctx, hydrating) {
36
+ islands.get(el)?.appRef?.destroy();
37
+ const running = { state: createState(sourceOf(component, props, ctx)), component, ctx };
38
+ islands.set(el, running);
39
+ const { setup, bootstrapped } = setupOf(ctx.app);
40
+ await setAdapterInstance(ctx.app, setup);
41
+ const providers = [
42
+ { provide: APP_ID, useValue: ctx.idPrefix },
43
+ { provide: CSP_NONCE, useValue: documentNonce2() },
44
+ { provide: ErrorHandler, useValue: new ClientErrors2(ctx.app) },
45
+ ...hamurProviders(ctx.app, running.state, (error) => reportClientError(ctx.app, error, { render: true }))
46
+ ];
47
+ const appRef = await createApplication({
48
+ providers: [
49
+ ...hydrating ? [provideClientHydration(withEventReplay(), withNoHttpTransferCache())] : [],
50
+ ...providers,
51
+ ...setup.providers
52
+ ]
53
+ });
54
+ if (islands.get(el) !== running)
55
+ return void appRef.destroy();
56
+ running.appRef = appRef;
57
+ bootstrapped(appRef.injector);
58
+ let host = el.querySelector(`:scope > ${HOST}`);
59
+ if (!hydrating || !host) {
60
+ host?.remove();
61
+ host = el.appendChild(document.createElement(HOST));
62
+ }
63
+ appRef.bootstrap(HamurApp, host);
64
+ await appRef.whenStable();
65
+ }
66
+ function hydrateIsland(el, component, props, ctx) {
67
+ return start(el, component, props, ctx, true);
68
+ }
69
+ function mountIsland(el, component, props, ctx) {
70
+ el.replaceChildren();
71
+ return start(el, component, props, ctx, false);
72
+ }
73
+ function unmountIsland(el) {
74
+ islands.get(el)?.appRef?.destroy();
75
+ islands.delete(el);
76
+ }
77
+ async function updateIsland(el, props) {
78
+ const running = islands.get(el);
79
+ if (!running)
80
+ return;
81
+ running.state.write(sourceOf(running.component, props, running.ctx));
82
+ if (!running.appRef)
83
+ return;
84
+ running.appRef.tick();
85
+ await running.appRef.whenStable();
86
+ }
87
+ export {
88
+ hydrateIsland,
89
+ mountIsland,
90
+ unmountIsland,
91
+ updateIsland
92
+ };
@@ -0,0 +1,175 @@
1
+ import {
2
+ islandHref,
3
+ createState,
4
+ hamurProviders,
5
+ setupOf
6
+ } from "../../chunks/browser-index-qn8q5fa2.js";
7
+ import {
8
+ HamurApp,
9
+ maskInPlace,
10
+ boundaryKey,
11
+ shownError,
12
+ clientComponentOnServer,
13
+ serverComponentOnServer
14
+ } from "../../chunks/browser-index-nann848q.js";
15
+
16
+ // packages/adapter-angular/src/runtime/server.ts
17
+ import { APP_ID, CSP_NONCE, ErrorHandler, REQUEST } from "@angular/core";
18
+ import {
19
+ bootstrapApplication,
20
+ provideClientHydration,
21
+ withEventReplay,
22
+ withNoHttpTransferCache
23
+ } from "@angular/platform-browser";
24
+ import { provideServerRendering, renderApplication } from "@angular/platform-server";
25
+ import CONTRACT from "@angular/core/event-dispatch-contract.min.js";
26
+ import { cspHash, publicError, setAdapterInstance } from "hamur/adapter";
27
+ import { isRedirect } from "hamur/app";
28
+ var APP = "hamur";
29
+ var CONTRACT_ID = "ng-event-dispatch-contract";
30
+ var MARKER = "<!--nghm-->";
31
+ var SCRIPT = /<script\b([^>]*)>([\s\S]*?)<\/script>/g;
32
+ var STYLE = /<style\b[^>]*>[\s\S]*?<\/style>/g;
33
+ var nonceAttribute = (nonce) => nonce ? ` nonce="${nonce.replace(/&/g, "&amp;").replace(/"/g, "&quot;")}"` : "";
34
+ var shell = (nonce) => `<!doctype html><html><head></head><body><script id="${CONTRACT_ID}"${nonceAttribute(nonce)}>${CONTRACT}</script><hamur-app></hamur-app></body></html>`;
35
+ function redirectOf(error) {
36
+ if (isRedirect(error))
37
+ return error;
38
+ const cause = error instanceof Error ? error.cause : undefined;
39
+ return isRedirect(cause) ? cause : undefined;
40
+ }
41
+ var isFatal = (error) => typeof error === "object" && error !== null && error.fatal === true;
42
+
43
+ class RenderErrors extends ErrorHandler {
44
+ app;
45
+ failed;
46
+ reported = new WeakSet;
47
+ caught = 0;
48
+ constructor(app) {
49
+ super();
50
+ this.app = app;
51
+ }
52
+ fail = (error) => {
53
+ this.failed ??= { error };
54
+ };
55
+ handleError(error) {
56
+ this.fail(error);
57
+ }
58
+ onViewError(error) {
59
+ const thrown = redirectOf(error) ?? (isFatal(error) || isFatal(error.cause) ? error : undefined);
60
+ if (thrown)
61
+ return this.fail(thrown === error ? error : thrown);
62
+ if (this.reported.has(error))
63
+ return;
64
+ this.reported.add(error);
65
+ const masked = publicError(this.app, error);
66
+ if (masked !== error) {
67
+ try {
68
+ maskInPlace(error, masked);
69
+ } catch {
70
+ return this.fail(masked);
71
+ }
72
+ }
73
+ this.app.state.set(boundaryKey(this.caught++), shownError(error));
74
+ this.app.hooks?.callHook("app:error", masked, { source: "render" }).catch(() => {});
75
+ }
76
+ }
77
+ function partsOf(document, appId, nonce) {
78
+ const head = (/<head>([\s\S]*?)<\/head>/.exec(document)?.[1] ?? "").match(STYLE) ?? [];
79
+ let body = /<body[^>]*>([\s\S]*)<\/body>/.exec(document)?.[1] ?? "";
80
+ const marker = body.includes(MARKER);
81
+ body = body.replace(MARKER, "");
82
+ if (nonce)
83
+ body = body.replace(`<script id="${appId}-state"`, `<script id="${appId}-state"${nonceAttribute(nonce)}`);
84
+ const scripts = [...body.matchAll(SCRIPT)].filter(([, attributes]) => !/\btype="application\/json"/.test(attributes)).map(([, , text]) => text);
85
+ return { head: head.join(""), body, marker, scripts };
86
+ }
87
+ function withoutHydration(document) {
88
+ return document.replace(/<!--ngh[\s\S]*?-->/g, "").replace(/ ngh="[^"]*"/g, "").replace(new RegExp(`<script id="(?:${CONTRACT_ID}|${APP}-state)"[^>]*>[\\s\\S]*?</script>`, "g"), "").replace(/<script\b[^>]*>window\.__jsaction_bootstrap\([\s\S]*?<\/script>/g, "");
89
+ }
90
+ async function renderTree(app, options, appId, nonce, scriptFree = false) {
91
+ const { setup, bootstrapped } = setupOf(app);
92
+ await setAdapterInstance(app, setup);
93
+ const errors = new RenderErrors(app);
94
+ const state = createState({ app, ...options });
95
+ const providers = [
96
+ { provide: APP_ID, useValue: appId },
97
+ { provide: CSP_NONCE, useValue: nonce ?? null },
98
+ { provide: REQUEST, useValue: app.event?.request ?? null },
99
+ { provide: ErrorHandler, useValue: errors },
100
+ ...hamurProviders(app, state, errors.fail)
101
+ ];
102
+ let document = "";
103
+ try {
104
+ document = await renderApplication(async (context) => {
105
+ const appRef = await bootstrapApplication(HamurApp, {
106
+ providers: [
107
+ provideServerRendering(),
108
+ provideClientHydration(withEventReplay(), withNoHttpTransferCache()),
109
+ ...providers,
110
+ ...setup.providers
111
+ ]
112
+ }, context);
113
+ bootstrapped(appRef.injector);
114
+ return appRef;
115
+ }, { document: shell(nonce), url: options.url.href, allowedHosts: [options.url.hostname] });
116
+ } catch (error) {
117
+ errors.fail(error);
118
+ }
119
+ if (errors.failed)
120
+ throw redirectOf(errors.failed.error) ?? errors.failed.error;
121
+ return partsOf(scriptFree ? withoutHydration(document) : document, appId, nonce);
122
+ }
123
+ async function render(ctx) {
124
+ const parts = await renderTree(ctx.app, ctx, APP, ctx.nonce, ctx.route.meta.scripts === false);
125
+ if (ctx.scriptHashes)
126
+ for (const script of parts.scripts)
127
+ ctx.scriptHashes.push(await cspHash(script));
128
+ return {
129
+ body: parts.body,
130
+ ...parts.head ? { head: parts.head } : {},
131
+ ...parts.marker ? { teleports: { body: MARKER } } : {}
132
+ };
133
+ }
134
+ var ISLAND_ENTRY = "island";
135
+ var REPLAY_SCRIPT = /<script\b[^>]*>window\.__jsaction_bootstrap\(document\.currentScript\.parentElement,[\s\S]*?<\/script>/;
136
+ var CONTRACT_SCRIPT = new RegExp(`<script id="${CONTRACT_ID}"[^>]*>([\\s\\S]*?)</script>`);
137
+ var contractInHead = new WeakSet;
138
+ async function renderComponent(component, props, ctx) {
139
+ const parts = await renderTree(ctx.app, {
140
+ url: ctx.url,
141
+ route: ctx.route,
142
+ payload: {},
143
+ tree: { components: [{ id: ISLAND_ENTRY, component, props }] },
144
+ baseURL: ctx.baseURL,
145
+ href: islandHref(ctx.baseURL)
146
+ }, ctx.idPrefix, ctx.nonce);
147
+ let head = parts.head;
148
+ let html = parts.body.replace(/window\.__jsaction_bootstrap\(document\.body,/, "window.__jsaction_bootstrap(document.currentScript.parentElement,");
149
+ const replay = REPLAY_SCRIPT.exec(html);
150
+ if (replay)
151
+ html = html.replace(replay[0], "") + replay[0];
152
+ const contract = CONTRACT_SCRIPT.exec(html);
153
+ if (contract) {
154
+ html = html.replace(contract[0], "");
155
+ if (!contractInHead.has(ctx.app)) {
156
+ contractInHead.add(ctx.app);
157
+ head = contract[0] + head;
158
+ if (ctx.scriptHashes)
159
+ ctx.scriptHashes.push(await cspHash(contract[1]));
160
+ }
161
+ }
162
+ if (ctx.scriptHashes) {
163
+ for (const [, attributes, text] of html.matchAll(SCRIPT))
164
+ if (!/\btype="application\/json"/.test(attributes))
165
+ ctx.scriptHashes.push(await cspHash(text));
166
+ }
167
+ return head ? { html, head } : { html };
168
+ }
169
+ export {
170
+ clientComponentOnServer as clientComponent,
171
+ render,
172
+ renderComponent,
173
+ serverComponentOnServer as serverComponent,
174
+ withoutHydration
175
+ };
@@ -0,0 +1,20 @@
1
+ import { InjectionToken } from "@angular/core";
2
+ /** The shown state of one keep-alive wrapper and the `onPageActivated`/`onPageDeactivated` functions under it. */
3
+ export interface Activation {
4
+ hidden: boolean;
5
+ readonly parent: Activation | undefined;
6
+ readonly children: Set<Activation>;
7
+ readonly on: Set<() => void>;
8
+ readonly off: Set<() => void>;
9
+ }
10
+ /** The nearest keep-alive wrapper above a component; absent when its page is not kept. */
11
+ export declare const HAMUR_ACTIVATION: InjectionToken<Activation>;
12
+ export declare function activation(parent: Activation | undefined, hidden: boolean): Activation;
13
+ export declare function detach(own: Activation): void;
14
+ /** Whether a page under `own` is on screen: no wrapper above it is hidden. */
15
+ export declare function shown(own: Activation | undefined): boolean;
16
+ export declare function setHidden(own: Activation, hidden: boolean): void;
17
+ /** Runs `fn` after the component's first render and each time its kept page is shown again. */
18
+ export declare function onPageActivated(fn: () => void): void;
19
+ /** Runs `fn` each time its kept page is hidden and when the component is destroyed on screen. */
20
+ export declare function onPageDeactivated(fn: () => void): void;
@@ -0,0 +1,7 @@
1
+ import type { BunPlugin } from "bun";
2
+ /** The core's peer check only asks that each peer resolves, so a wrong install would fail late inside the compiler. */
3
+ export declare function assertAngular(rootDir: string): void;
4
+ /** A build drops Angular's dev-mode and JIT branches; `hamur dev` sets none, Bun.serve's dev bundler ignores them. */
5
+ export declare function angularDefines(target: "client" | "server"): BunPlugin;
6
+ declare const _default: import("hamur/adapter").Adapter;
7
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import * as i0 from "@angular/core";
2
+ /** The one Angular root, inside the core's root element; it renders the tree's first entry. */
3
+ export declare class HamurApp {
4
+ static ɵfac: i0.ɵɵFactoryDeclaration<HamurApp, never>;
5
+ static ɵcmp: i0.ɵɵComponentDeclaration<HamurApp, "hamur-app", never, {}, {}, never, never, true, never>;
6
+ }
@@ -0,0 +1,21 @@
1
+ import type { $Fetch, AppContext, AsyncDataOptions, FetchOptions } from "hamur/app";
2
+ import type { AsyncDataHandler, FetchRequest, GetCachedData, GetCachedDataCause, HandlerReference } from "hamur/adapter";
3
+ export declare const valueOf: <T>(value: T | (() => T)) => T;
4
+ export declare function requestOf({ query, body, ...rest }: FetchRequest): FetchOptions;
5
+ /** A getter `injectFetch` key; each key's handler fetches the url and request that key was made from. */
6
+ export declare function fetchSlots<R>(url: string | (() => string), options: FetchRequest, fetcher?: $Fetch, fixedKey?: string): {
7
+ keyOf: () => string;
8
+ handlerFor: (key: string) => AsyncDataHandler<R>;
9
+ };
10
+ /** The key of `useAsyncData(fn, input)` for the input as it reads now; each key's handler calls `fn` with the input that key was made from. */
11
+ export declare function handlerSlots<R>(app: AppContext, fn: HandlerReference, input: unknown): {
12
+ keyOf: () => string;
13
+ handlerFor: (key: string) => AsyncDataHandler<R>;
14
+ };
15
+ /** The restored payload entry's data while the app hydrates, else `undefined`. */
16
+ export declare function defaultGetCachedData<T>(key: string, app: AppContext): T | undefined;
17
+ /** `refresh()`, `execute()` and a `watch` change: ask `getCachedData` with their cause, run `handler` when it has nothing. */
18
+ export declare function refreshCached<T, R>(app: AppContext, key: string, handler: AsyncDataHandler<R>, options: AsyncDataOptions<T, R>, getCachedData: GetCachedData<T>, cause: GetCachedDataCause): Promise<void>;
19
+ export declare function keepCached<T>(app: AppContext, key: string, getCachedData: GetCachedData<T>): void;
20
+ /** The run's signal, combined with a `signal` the caller gave to `injectFetch`. */
21
+ export declare const signalOf: (own: AbortSignal | undefined, run: AbortSignal) => AbortSignal;
@@ -0,0 +1,35 @@
1
+ import { InjectionToken, type Resource, type Signal } from "@angular/core";
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * `<div *hamurDevOnly>…</div>` renders its template only in a dev build. A production client keeps the template's code:
5
+ * a component named in it is a static import of the compiled one.
6
+ */
7
+ export declare class DevOnly {
8
+ constructor();
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<DevOnly, never>;
10
+ static ɵdir: i0.ɵɵDirectiveDeclaration<DevOnly, "[hamurDevOnly]", never, {}, {}, never, never, true, never>;
11
+ }
12
+ /**
13
+ * The value of a promise a loader returned, as Angular's `Resource<T>`: read with `@if (value.hasValue()) … @else if
14
+ * (value.error()) … @else …`. On the server the render waits for it; `value()` throws the error of a rejected promise,
15
+ * as Angular's own resources do.
16
+ */
17
+ export declare function injectDeferred<T>(promise: PromiseLike<T> | T): Resource<Awaited<T>>;
18
+ /** `false` on the server and until the first render of a hydrated page is done; `true` at once after a client navigation. */
19
+ export declare function injectHydrated(): Signal<boolean>;
20
+ /** The counter `injectId` reads; a server-only component's render has one of its own, with a prefix, so it leaves the page's numbering alone. */
21
+ export declare const HAMUR_IDS: InjectionToken<{
22
+ next: number;
23
+ prefix: string;
24
+ }>;
25
+ /**
26
+ * An id that is the same in the server's HTML and in hydration, `<APP_ID>-<n>`: Angular 22 has no id function of
27
+ * its own, and the components of both renders are created in the same order.
28
+ */
29
+ export declare function injectId(): string;
30
+ /** The id for `data-hamur-p` on the element `fn` is called with, as an inline script before hydration; `undefined` in the browser. */
31
+ export declare function onPrehydrate(fn: (el: Element) => void): string | undefined;
32
+ /** The `[style]` that names an element for a view transition. */
33
+ export declare function transitionName(name: string): {
34
+ "view-transition-name": string;
35
+ };
@@ -0,0 +1,99 @@
1
+ import type { AdapterBuildContext, AdapterTransform } from "hamur/adapter";
2
+ export interface AngularEmit {
3
+ code: string;
4
+ map?: string;
5
+ /** The declarations, emitted by `compilePartial` only. */
6
+ types?: string;
7
+ }
8
+ /**
9
+ * The app's program, shared by the client and server builds of one `hamur build`: the client and server steps
10
+ * find the same roots unchanged and take the same emit; a later build in the process whose roots changed compiles again.
11
+ */
12
+ export declare function angularProgram(ctx: AdapterBuildContext): Promise<Map<string, AngularEmit>>;
13
+ /** The one program of a `hamur dev` process for `rootDir` and `buildDir`, shared by every step that process makes. */
14
+ export declare function angularDevProgram(ctx: AdapterBuildContext): AngularDevProgram;
15
+ /** The dev program of `rootDir` and `buildDir` once a load built it; the adapter's hooks read it. */
16
+ export declare const devProgramOf: (rootDir: string, buildDir: string) => AngularDevProgram | undefined;
17
+ /** Drops the dev program and base URL of `rootDir` and `buildDir`: a closed `hamur dev` must not keep its whole `NgtscProgram`. */
18
+ export declare function releaseDevProgram(rootDir: string, buildDir: string): void;
19
+ /** `app.baseURL`, which the `modules:done` hook records for the `ɵɵgetReplaceMetadataURL` rewrite. */
20
+ export declare function setDevBaseURL(rootDir: string, buildDir: string, baseURL: string): void;
21
+ /**
22
+ * Angular's HMR initializer (`_enableHmr`) listens on `import.meta.hot` and resolves the update module
23
+ * against `import.meta.url`. In the client its listener goes to `onDevEvent`, one microtask later since an app root runs before
24
+ * the dev client entry makes the channel, and its base becomes `app.baseURL`; on the server its first load is dropped.
25
+ */
26
+ export declare function rewriteHmrInitializer(code: string, target: "client" | "server", baseURL: string): string;
27
+ export interface AngularHotUpdate {
28
+ /** Angular's id of the component, the URI-encoded `<file>@<ClassName>` its initializer compares. */
29
+ id: string;
30
+ /** The update module `emitHmrUpdateModule` gave. */
31
+ code: string;
32
+ }
33
+ /**
34
+ * Built on the first load, then built again with the last good `NgtscProgram` as `oldProgram` when a load finds a
35
+ * root whose text, or a resource whose stamp, changed. Unchanged source files keep their `ts.SourceFile`, so Angular reuses
36
+ * their analysis and emits only the files the change reaches.
37
+ */
38
+ export declare class AngularDevProgram {
39
+ /** The real paths the last build emitted. */
40
+ emitted: string[];
41
+ private readonly ctx;
42
+ private readonly root;
43
+ private readonly app;
44
+ private readonly server;
45
+ private readonly own;
46
+ private readonly files;
47
+ /** Real path of each source file of the program to the text it compiled. */
48
+ private readonly texts;
49
+ /** Each resource the program read (templates, style files, a style file's imports) to its stamp when read. */
50
+ private readonly resources;
51
+ /** A style file's import to the style files that import it: Angular tracks the style file, not its imports. */
52
+ private readonly importers;
53
+ private readonly sourceFiles;
54
+ /** Real path of each component file to the real paths of the resources it reads (`getResourceDependencies`). */
55
+ private readonly resourcesOf;
56
+ /** Component files a hot update left with errors. */
57
+ private readonly broken;
58
+ private options;
59
+ private program;
60
+ private problems;
61
+ private failure;
62
+ private built;
63
+ private queue;
64
+ constructor(ctx: AdapterBuildContext);
65
+ /** As in a build: a load file's `#server` pulls `server/` into the program, whose emit must not replace the server files in the client. */
66
+ private emits;
67
+ /** The emit of `path` (a real path) after any build its load calls for; throws the program's errors for that file. */
68
+ load(path: string): Promise<AngularEmit | undefined>;
69
+ private stale;
70
+ /** The stamps of the resources the components of `path` read, so `hamur dev`'s cache misses after an edit of one. */
71
+ version(path: string): string;
72
+ /** Real paths of the component files that read `file`, a resource or a file a style resource imports; none for any other file. */
73
+ dependentsOf(file: string): string[];
74
+ /**
75
+ * Builds the program again for an edit of `file` and gives the update module of each component that
76
+ * reads it. A component left with errors is in `reload` instead, so Bun loads it again and shows the error, and once more
77
+ * after the fix; a file that is no resource gives neither.
78
+ */
79
+ hotUpdate(file: string): Promise<{
80
+ updates: AngularHotUpdate[];
81
+ reload: string[];
82
+ }>;
83
+ /** Whether the component file `component` reads `file`: one of its resources, or a file one of its style resources imports. */
84
+ private reads;
85
+ /** Real paths of the files the style resources among `files` imported (their preprocessor `dependencies`). */
86
+ private styleImportsOf;
87
+ private modifiedResources;
88
+ private build;
89
+ /** The texts the program compiled, so a load of an unchanged file does not build again, even when the build fails. */
90
+ private record;
91
+ }
92
+ /** The emitted code of a file of the program, of a module the adapter generated, or the wrapper of a client-only or server-only component; any other `.ts` goes on through the chain. */
93
+ export declare function compileStep(ctx: AdapterBuildContext): AdapterTransform;
94
+ /** In `hamur dev` the client runtime imports `./hydration-dev.ts` first, which feeds the hydration mismatch report; a build adds nothing. */
95
+ export declare function hydrationStep(): AdapterTransform;
96
+ /** Angular's linker on a partial-compiled package file (`ɵɵngDeclare*`), kept per path and size for the life of the process. */
97
+ export declare function linkStep(ctx: AdapterBuildContext): AdapterTransform;
98
+ /** The package's own components in `compilationMode: "partial"`, as `scripts/release.ts` publishes them: real source path to JavaScript and declarations. */
99
+ export declare function compilePartial(packageDir: string, from?: string): Promise<Map<string, AngularEmit>>;
@@ -0,0 +1,74 @@
1
+ import { InjectionToken } from "@angular/core";
2
+ import type { EnvironmentInjector, EnvironmentProviders, Provider, Signal, WritableSignal } from "@angular/core";
3
+ import type { ClientContext, NavigationState, RenderContext, RenderTree, RouteValue, RouterApi } from "hamur/adapter";
4
+ import type { AppContext, ErrorPageProps, RouteLocation } from "hamur/app";
5
+ /** `app.adapter`, handed to `app:adapter` before the application is created; a plugin pushes Angular providers. */
6
+ export interface AngularSetup {
7
+ providers: Array<Provider | EnvironmentProviders>;
8
+ /** The application's injector, set once it is bootstrapped. */
9
+ readonly injector: EnvironmentInjector | undefined;
10
+ }
11
+ type Source = Pick<RenderContext | ClientContext, "route" | "tree" | "payload" | "app"> & Partial<Pick<RenderContext, "baseURL" | "href" | "url">> & {
12
+ navigator?: unknown;
13
+ };
14
+ type Payload = RenderContext["payload"];
15
+ /** Dev-only diagnostics read it; a test sets it, as the build defines `import.meta.dev`. */
16
+ export declare const mode: {
17
+ dev: boolean;
18
+ };
19
+ export declare const HAMUR_APP: InjectionToken<AppContext>;
20
+ export declare const HAMUR_TREE: InjectionToken<Signal<RenderTree>>;
21
+ /** The tree of the page; `HAMUR_TREE` is the chain of a slot below an `Outlet name`. */
22
+ export declare const HAMUR_ROOT_TREE: InjectionToken<Signal<RenderTree>>;
23
+ export declare const HAMUR_ROUTER: InjectionToken<RouterApi>;
24
+ export declare const HAMUR_NAVIGATION: InjectionToken<Signal<NavigationState>>;
25
+ export declare const HAMUR_BASE_URL: InjectionToken<string>;
26
+ export declare const HAMUR_HREF: InjectionToken<(to: string | RouteLocation) => string>;
27
+ /** The value an `Outlet` above hands to the entries it renders. */
28
+ export declare const HAMUR_OUTLET_CONTEXT: InjectionToken<Signal<unknown>>;
29
+ export declare const HAMUR_ROUTE: InjectionToken<Signal<RouteValue>>;
30
+ export declare const HAMUR_PAYLOAD: InjectionToken<Signal<Payload>>;
31
+ /** What a level does with a throw of the entry it creates: recorded for `render` on the server, the error page in the browser. */
32
+ export declare const HAMUR_FAIL: InjectionToken<(error: unknown) => void>;
33
+ /** The page's render or client context as `routeBoundary` reads it, built from the latest tree the state was given. */
34
+ export declare const HAMUR_CONTEXT: InjectionToken<() => RenderContext | ClientContext>;
35
+ /** The error a route boundary or not-found component shows: set on the injector of an entry the core marks `caught`. */
36
+ export declare const HAMUR_CAUGHT: InjectionToken<ErrorPageProps>;
37
+ /** The index in `tree.components` of the entry whose injector this is; the `Outlet` below it renders the next one. */
38
+ export declare const HAMUR_LEVEL: InjectionToken<number>;
39
+ /**
40
+ * Registers a cleanup run when the level's entry is dropped. A view that throws while `@boundary` creates it is never destroyed, so its
41
+ * `DestroyRef` never fires; what it registered goes with the level (K32).
42
+ */
43
+ export declare const HAMUR_LEVEL_DISPOSE: InjectionToken<(dispose: () => void) => void>;
44
+ /** Whether the component renders on the server; a bare injector with no platform has no `document` there, as on the server. */
45
+ export declare function onServer(): boolean;
46
+ export declare function required<T>(token: InjectionToken<T>, name: string): T;
47
+ /** The id of the tree entry whose component calls the inject function, read when asked: the entry's data and its guards are its own. */
48
+ export declare function entryOf(name: string): () => string | undefined;
49
+ export declare const dataOf: (payload: Signal<{
50
+ data?: unknown;
51
+ }>) => Record<string, unknown>;
52
+ export declare function routeValue({ route, app, payload, tree }: Source): RouteValue;
53
+ /** A `Link` in an island takes a path, as no route table ships there. */
54
+ export declare function islandHref(baseURL: string): RenderContext["href"];
55
+ export declare function detachedHref(to: string | RouteLocation): string;
56
+ export interface HamurState {
57
+ tree: WritableSignal<RenderTree>;
58
+ route: WritableSignal<RouteValue>;
59
+ payload: WritableSignal<Payload>;
60
+ navigation: Signal<NavigationState>;
61
+ router: RouterApi;
62
+ baseURL: string;
63
+ href: RenderContext["href"];
64
+ context(): RenderContext | ClientContext;
65
+ write(source: Source): void;
66
+ }
67
+ export declare function createState(source: Source): HamurState;
68
+ export declare function hamurProviders(app: AppContext, state: HamurState, fail: (error: unknown) => void): Provider[];
69
+ /** One `AngularSetup` per app context: a request on the server, a page load in the browser. */
70
+ export declare function setupOf(app: AppContext): {
71
+ setup: AngularSetup;
72
+ bootstrapped(injector: EnvironmentInjector): void;
73
+ };
74
+ export {};
@@ -0,0 +1,65 @@
1
+ import { type Resource, type Signal } from "@angular/core";
2
+ import type { AsyncDataHandler, FetchRequest, GetCachedData, Handler, RouteLoaderData, UseDataArgs } from "hamur/adapter";
3
+ import { clearState as clearStateOf } from "hamur/app";
4
+ import type { AsyncDataOptions, FetchCheckedInput, FetchData, FetchInputField, PickFrom } from "hamur/app";
5
+ /**
6
+ * Angular's `Resource<T>` over an entry of the core's store, with `refresh()` and `clear()`. The core's `idle`,
7
+ * `pending`, `success` and `error` are `idle`, `loading` (`reloading` while there is a value), `resolved` and `error`; `value`
8
+ * throws the error of a failed entry, as Angular's own resources do.
9
+ */
10
+ export interface AsyncDataResource<T, D = undefined> extends Resource<T | D> {
11
+ /** Runs the handler again (through `getCachedData`) and resolves when the run ends. */
12
+ refresh(): Promise<void>;
13
+ /** Resets the entry of the current key to `idle` (`clearAsyncData`). */
14
+ clear(): void;
15
+ }
16
+ export interface InjectAsyncDataOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends Omit<AsyncDataOptions<T, R, D>, "pick"> {
17
+ /** Signals (or any getters) whose change runs the handler again. `false` is accepted and does nothing: nothing watches implicitly. */
18
+ watch?: ReadonlyArray<() => unknown> | false;
19
+ getCachedData?: GetCachedData<T>;
20
+ /** Top-level keys of an object result to keep. */
21
+ pick?: readonly K[];
22
+ }
23
+ export interface InjectFetchOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends FetchRequest, InjectAsyncDataOptions<T, R, K, D> {
24
+ /** The store key, instead of the one derived from the url and the request. */
25
+ key?: string;
26
+ }
27
+ export declare function injectAsyncData<I, R, T = R, K extends keyof T & string = never, D = T>(fn: Handler<I, R>, input: NoInfer<I> | (() => NoInfer<I>) | undefined, options: InjectAsyncDataOptions<T, R, K, D> & {
28
+ default: () => D;
29
+ }): AsyncDataResource<PickFrom<T, K>, D>;
30
+ export declare function injectAsyncData<I, R, T = R, K extends keyof T & string = never>(fn: Handler<I, R>, input?: NoInfer<I> | (() => NoInfer<I>), options?: InjectAsyncDataOptions<T, R, K, undefined>): AsyncDataResource<PickFrom<T, K>>;
31
+ export declare function injectAsyncData<T = unknown, R = T, K extends keyof T & string = never, D = T>(key: string | (() => string), handler: AsyncDataHandler<R>, options: InjectAsyncDataOptions<T, R, K, D> & {
32
+ default: () => D;
33
+ }): AsyncDataResource<PickFrom<T, K>, D>;
34
+ export declare function injectAsyncData<T = unknown, R = T, K extends keyof T & string = never>(key: string | (() => string), handler: AsyncDataHandler<R>, options?: InjectAsyncDataOptions<T, R, K, undefined>): AsyncDataResource<PickFrom<T, K>>;
35
+ /** What a literal `injectFetch` call is checked against; any other call stays loose. */
36
+ type FetchInput<X> = X extends {
37
+ key: infer K extends string;
38
+ input: infer I;
39
+ } ? FetchInputField<I, K, I | (() => I)> : unknown;
40
+ type Unkeyed<O, X> = X extends {
41
+ key: infer K extends string;
42
+ } ? Omit<O, K> : O;
43
+ type FetchCall<U extends string, M extends string, B extends string | undefined> = {
44
+ method?: M | string;
45
+ baseURL?: B | string;
46
+ } & FetchInput<FetchCheckedInput<U, M, B>>;
47
+ export declare function injectFetch<U extends string, M extends string = "GET", K extends keyof FetchData<U, M> & string = never, D = undefined, B extends string | undefined = undefined>(url: U | (() => U), options?: Unkeyed<InjectFetchOptions<FetchData<U, M>, FetchData<U, M>, K, D>, FetchCheckedInput<U, M, B>> & FetchCall<U, M, B>): AsyncDataResource<PickFrom<FetchData<U, M>, K>, D>;
48
+ export declare function injectFetch<T = unknown, R = T, K extends keyof T & string = never, D = T, U extends string = string, M extends string = "GET", B extends string | undefined = undefined>(url: U | (() => U), options: Unkeyed<InjectFetchOptions<T, R, K, D>, FetchCheckedInput<U, M, B>> & {
49
+ default: () => D;
50
+ } & FetchCall<U, M, B>): AsyncDataResource<PickFrom<T, K>, D>;
51
+ export declare function injectFetch<T = unknown, R = T, K extends keyof T & string = never, U extends string = string, M extends string = "GET", B extends string | undefined = undefined>(url: U | (() => U), options?: Unkeyed<InjectFetchOptions<T, R, K, undefined>, FetchCheckedInput<U, M, B>> & FetchCall<U, M, B>): AsyncDataResource<PickFrom<T, K>>;
52
+ export declare const injectLazyFetch: typeof injectFetch;
53
+ export declare const injectLazyAsyncData: typeof injectAsyncData;
54
+ /** The entry another component made under `key`, or under the key of `fn` and `input`, read as a resource; it creates none. */
55
+ export declare function injectNuxtData<T = unknown>(key: string): AsyncDataResource<T>;
56
+ export declare function injectNuxtData<I, O>(fn: Handler<I, O>, input?: I | (() => I)): AsyncDataResource<O>;
57
+ /** The loader data of the page or layout the component belongs to, `null` for a route with no loader. */
58
+ export declare function injectData<T = unknown>(..._route: UseDataArgs<T>): Signal<RouteLoaderData<T>>;
59
+ export declare function clearState(keys?: Parameters<typeof clearStateOf>[1], options?: {
60
+ reset?: boolean;
61
+ }): void;
62
+ export declare function callOnce(key: string, fn: () => unknown | Promise<unknown>, options?: {
63
+ mode?: "render" | "navigation";
64
+ }): Promise<void>;
65
+ export {};
@@ -0,0 +1,13 @@
1
+ /** What a client-only or server-only component's wrapper copies from the real component: its selectors (as the compiler wrote them) and the public names of its inputs. */
2
+ export interface ComponentDefinition {
3
+ /** The text of the `selectors` array, valid JSON. */
4
+ selectors: string;
5
+ inputs: string[];
6
+ }
7
+ /**
8
+ * The selectors and the public input names of the first component the compiler defined in `code`, the JavaScript the
9
+ * Angular program emitted for a file. `undefined` when `code` defines no component.
10
+ */
11
+ export declare function readDefinition(code: string): ComponentDefinition | undefined;
12
+ /** The `selector` of a component from its compiled `selectors`: an element name, attributes and classes, one selector for each list. */
13
+ export declare function selectorOf(selectors: string): string;
@@ -0,0 +1,8 @@
1
+ import type { ErrorPageProps } from "hamur/app";
2
+ import * as i0 from "@angular/core";
3
+ export default class DefaultErrorPage {
4
+ readonly error: import("@angular/core").InputSignal<ErrorPageProps>;
5
+ readonly clearError: import("@angular/core").InputSignal<(() => void) | undefined>;
6
+ static ɵfac: i0.ɵɵFactoryDeclaration<DefaultErrorPage, never>;
7
+ static ɵcmp: i0.ɵɵComponentDeclaration<DefaultErrorPage, "ng-component", never, { "error": { "alias": "error"; "required": true; "isSignal": true; }; "clearError": { "alias": "clearError"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
8
+ }