@loozo/angular-launch 0.0.6 → 0.1.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 +715 -255
- package/builders/application.js +32 -3
- package/builders/channel-forwarding.d.ts +15 -0
- package/builders/channel-forwarding.js +61 -0
- package/builders/options.d.ts +6 -2
- package/builders/options.js +16 -5
- package/builders/serve.js +198 -140
- package/channel.d.ts +3 -1
- package/channel.js +3 -2
- package/client.d.ts +14 -24
- package/generation/index.d.ts +2 -123
- package/generation/index.js +3 -685
- package/generation/redirects.d.ts +14 -0
- package/generation/redirects.js +43 -0
- package/generation/run.d.ts +168 -0
- package/generation/run.js +659 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/launch-queries.d.ts +16 -0
- package/launch-queries.js +3 -0
- package/navigation.d.ts +3 -3
- package/navigation.js +1 -1
- package/node/index.d.ts +3 -0
- package/node/index.js +6 -3
- package/node/upgrade-listener-slot.d.ts +1 -0
- package/node/upgrade-listener-slot.js +4 -0
- package/outcomes.d.ts +23 -7
- package/outcomes.js +58 -12
- package/package.json +15 -11
- package/redirect-translation.d.ts +53 -0
- package/redirect-translation.js +141 -0
- package/{generated.js → remote-client.js} +27 -21
- package/route-types.d.ts +130 -0
- package/route-types.js +1 -0
- package/route.d.ts +45 -0
- package/route.js +113 -0
- package/schemas/application.json +19 -3
- package/schemas/serve.json +3 -3
- package/server/application.d.ts +107 -0
- package/server/application.js +108 -0
- package/server/backend.d.ts +25 -13
- package/server/backend.js +39 -24
- package/server/channel-messages.d.ts +1 -1
- package/server/channel-messages.js +1 -1
- package/server/channel-socket.d.ts +1 -1
- package/server/definitions.d.ts +146 -298
- package/server/definitions.js +29 -117
- package/server/dispatch.d.ts +67 -63
- package/server/dispatch.js +121 -61
- package/server/event-stream.d.ts +2 -2
- package/server/event-stream.js +1 -1
- package/server/generated.d.ts +2 -1
- package/server/generated.js +2 -1
- package/server/index.d.ts +3 -2
- package/server/index.js +2 -1
- package/server/outcomes.d.ts +26 -13
- package/server/outcomes.js +43 -16
- package/server/read-cookies.d.ts +19 -0
- package/server/read-cookies.js +39 -0
- package/server/response-effects.d.ts +2 -2
- package/server/stages.d.ts +62 -0
- package/server/stages.js +51 -0
- package/server/upgrade.d.ts +11 -12
- package/server/upgrade.js +13 -14
- package/source-text.d.ts +1 -0
- package/source-text.js +56 -0
- package/stream.d.ts +6 -3
- package/stream.js +8 -6
- package/tanstack-query/README.md +15 -15
- package/tanstack-query/create-queries.d.ts +2 -0
- package/tanstack-query/{generated.js → create-queries.js} +8 -9
- package/tanstack-query/hydration-window.d.ts +11 -0
- package/tanstack-query/hydration-window.js +9 -0
- package/tanstack-query/hydration.d.ts +4 -14
- package/tanstack-query/hydration.js +9 -12
- package/tanstack-query/index.d.ts +1 -1
- package/tanstack-query/queries.d.ts +42 -27
- package/testing/call-procedure.d.ts +154 -0
- package/testing/call-procedure.js +97 -0
- package/testing/index.d.ts +2 -0
- package/testing/index.js +1 -0
- package/generation/context-file.d.ts +0 -2
- package/generation/context-file.js +0 -3
- package/tanstack-query/generated.d.ts +0 -5
- /package/{generated.d.ts → remote-client.d.ts} +0 -0
package/route-types.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { ContributionOf, ExtensionSpec, InputContribution, StepSignature } from "@loozo/angular-router/_core";
|
|
2
|
+
import type { Client } from "./client.js";
|
|
3
|
+
import type { MiddlewareDefinition, ProcedureBuilder, ProcedureDefinition, StageArgs } from "./server/definitions.js";
|
|
4
|
+
/** Type-only witness of Launch's route extension; absent at runtime. */
|
|
5
|
+
export declare const launch: unique symbol;
|
|
6
|
+
type Flat<Value> = {
|
|
7
|
+
[Key in keyof Value]: Value[Key];
|
|
8
|
+
} & {};
|
|
9
|
+
declare const noStage: unique symbol;
|
|
10
|
+
type NoStage = typeof noStage;
|
|
11
|
+
type StageValue<Own> = Own extends {
|
|
12
|
+
readonly context: (...args: never[]) => infer Value;
|
|
13
|
+
} ? Awaited<Value> : NoStage;
|
|
14
|
+
type Last<Chain, Context> = Chain extends readonly [infer Head, ...infer Rest] ? Last<Rest, StageValue<Head> extends NoStage ? Context : StageValue<Head>> : Context;
|
|
15
|
+
/**
|
|
16
|
+
* The context a route chain's `.context()` stages build: what its last stage returns, as
|
|
17
|
+
* it is. Each stage returns the route's whole context, so a stage that merges spreads the
|
|
18
|
+
* context it receives itself. `{}` without a stage.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam Chain - A route's contribution chain.
|
|
21
|
+
*/
|
|
22
|
+
export type ChainContext<Chain> = Last<Chain, {}>;
|
|
23
|
+
type NamespacesOf<Own> = Own extends {
|
|
24
|
+
readonly remote: (...args: never[]) => infer Namespaces;
|
|
25
|
+
} ? Namespaces : {};
|
|
26
|
+
type Collect<Chain, Namespaces> = Chain extends readonly [infer Head, ...infer Rest] ? Collect<Rest, Namespaces & NamespacesOf<Head>> : Namespaces;
|
|
27
|
+
/**
|
|
28
|
+
* The `.remote()` namespaces a route chain declares, its own and its ancestors', keyed by
|
|
29
|
+
* namespace.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam Chain - A route's contribution chain.
|
|
32
|
+
*/
|
|
33
|
+
export type ChainNamespaces<Chain> = Flat<Collect<Chain, {}>>;
|
|
34
|
+
type RemoteFor<Chain> = {
|
|
35
|
+
readonly [Namespace in keyof ChainNamespaces<Chain>]: Client<ChainNamespaces<Chain>[Namespace]>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A route's client: one {@link Client} per namespace the route can see, its own and its
|
|
39
|
+
* ancestors'. A route copy exports it as `Remote`, and it's the type of `route.remote` and
|
|
40
|
+
* of `remote` in the route's kept callbacks.
|
|
41
|
+
*
|
|
42
|
+
* @typeParam Route - A route made by Launch's `defineRoute`, or its copy.
|
|
43
|
+
*/
|
|
44
|
+
export type RemoteOf<Route> = RemoteFor<ContributionOf<Route>>;
|
|
45
|
+
/**
|
|
46
|
+
* The context a route's procedures receive: what its own and its ancestors' `.context()`
|
|
47
|
+
* stages build. A route copy exports it as `Context`.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam Route - A route made by Launch's `defineRoute`, or its copy.
|
|
50
|
+
*/
|
|
51
|
+
export type ContextOf<Route> = ChainContext<ContributionOf<Route>>;
|
|
52
|
+
type OwnEntry<Name extends string, Args> = Args extends readonly [infer Value] ? {
|
|
53
|
+
readonly [Key in Name]: Value;
|
|
54
|
+
} : {};
|
|
55
|
+
type UseEntry<Args> = {
|
|
56
|
+
readonly use: Args;
|
|
57
|
+
};
|
|
58
|
+
type InputMembers<Chain> = {
|
|
59
|
+
/** The route's client, its own and its ancestors' namespaces. */
|
|
60
|
+
readonly remote: RemoteFor<Chain>;
|
|
61
|
+
};
|
|
62
|
+
/** The signature of a route's `.context(stage)` step. */
|
|
63
|
+
export interface ContextStep extends StepSignature {
|
|
64
|
+
/** One stage, which receives the context of the stages above it. */
|
|
65
|
+
readonly parameters: [
|
|
66
|
+
stage: (args: StageArgs<ChainContext<this["chain"]>>) => object | PromiseLike<object>
|
|
67
|
+
];
|
|
68
|
+
/** The route's own record keeps the stage under `context`. */
|
|
69
|
+
readonly own: OwnEntry<"context", this["args"]>;
|
|
70
|
+
}
|
|
71
|
+
/** The signature of a route's `.use(...middleware)` step. */
|
|
72
|
+
export interface UseStep extends StepSignature {
|
|
73
|
+
/**
|
|
74
|
+
* Middleware that each accept the route's context: `middleware()` definitions, or bare
|
|
75
|
+
* functions, which receive it typed.
|
|
76
|
+
*/
|
|
77
|
+
readonly parameters: readonly (MiddlewareDefinition<NoInfer<ChainContext<this["chain"]>>> | MiddlewareDefinition<NoInfer<ChainContext<this["chain"]>>>["run"])[];
|
|
78
|
+
/** The route's own record keeps the middleware under `use`. */
|
|
79
|
+
readonly own: UseEntry<this["args"]>;
|
|
80
|
+
}
|
|
81
|
+
/** The signature of a route's `.remote(build)` step. */
|
|
82
|
+
export interface RemoteStep extends StepSignature {
|
|
83
|
+
/** A callback returning the route's namespaces, built with the route's context. */
|
|
84
|
+
readonly parameters: [
|
|
85
|
+
build: (procedures: ProcedureBuilder<ChainContext<this["chain"]>>) => Readonly<Record<string, Readonly<Record<string, ProcedureDefinition>>>>
|
|
86
|
+
];
|
|
87
|
+
/** The route's own record keeps the callback under `remote`. */
|
|
88
|
+
readonly own: OwnEntry<"remote", this["args"]>;
|
|
89
|
+
}
|
|
90
|
+
/** What Launch adds to a route's kept router callbacks: `remote`. */
|
|
91
|
+
export interface LaunchInput extends InputContribution {
|
|
92
|
+
/** The members kept callbacks receive besides the router's own. */
|
|
93
|
+
readonly input: InputMembers<this["chain"]>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* One entry of Launch's step manifest.
|
|
97
|
+
*
|
|
98
|
+
* @typeParam Name - The step's method name.
|
|
99
|
+
* @typeParam Type - The step's typing.
|
|
100
|
+
* @typeParam Max - The most arguments it takes: one, or any number (`null`).
|
|
101
|
+
*/
|
|
102
|
+
export interface LaunchStep<Name extends string, Type extends StepSignature, Max extends 1 | null> {
|
|
103
|
+
/** The step's method name on the route chain. */
|
|
104
|
+
readonly name: Name;
|
|
105
|
+
/** The step's typing. */
|
|
106
|
+
readonly type: Type;
|
|
107
|
+
/** Always `true`: route copies strip the step, and only the server runs it. */
|
|
108
|
+
readonly serverOnly: true;
|
|
109
|
+
/** How many arguments the step takes. */
|
|
110
|
+
readonly arity: {
|
|
111
|
+
/** At least one. */
|
|
112
|
+
readonly min: 1;
|
|
113
|
+
/** One, or any number. */
|
|
114
|
+
readonly max: Max;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Launch's route extension: `.context()`, `.use()` and `.remote()`, all server-only. */
|
|
118
|
+
export interface LaunchSpec extends ExtensionSpec {
|
|
119
|
+
/** The steps, in the order a route may use them, each at most once. */
|
|
120
|
+
readonly steps: readonly [
|
|
121
|
+
LaunchStep<"context", ContextStep, 1>,
|
|
122
|
+
LaunchStep<"use", UseStep, null>,
|
|
123
|
+
LaunchStep<"remote", RemoteStep, 1>
|
|
124
|
+
];
|
|
125
|
+
/** What Launch adds to kept router callbacks. */
|
|
126
|
+
readonly input: LaunchInput;
|
|
127
|
+
/** The brand that ties a route's type to Launch's extension. */
|
|
128
|
+
readonly witness: typeof launch;
|
|
129
|
+
}
|
|
130
|
+
export {};
|
package/route-types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/route.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type RouteFactory } from "@loozo/angular-router/_core";
|
|
2
|
+
import type { LaunchSpec } from "./route-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Declares a route, like the router's `defineRoute`, with Launch's server steps offered
|
|
5
|
+
* first: `.context(stage)`, then `.use(...middleware)`, then `.remote(build)`, each at most
|
|
6
|
+
* once and in that order, before any router step.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Import it from `@loozo/angular-launch` in every `route.ts` of a Launch app. Its steps are
|
|
10
|
+
* server-only: generation strips them from the route's browser copy, and the server reads
|
|
11
|
+
* them from `server.generated.ts`.
|
|
12
|
+
*
|
|
13
|
+
* - `.context(stage)` derives the route's context from its ancestors'. The stage receives
|
|
14
|
+
* `StageArgs` from `@loozo/angular-launch/server` and returns the route's whole context:
|
|
15
|
+
* spread the context above, `{ ...context, user }`, to keep its keys. It runs at most once
|
|
16
|
+
* per request scope, only when a call needs it.
|
|
17
|
+
* - `.use(...middleware)` runs around this route's own procedures, after the stages and
|
|
18
|
+
* before input validation. Each entry is a shared `middleware()` or a bare async function,
|
|
19
|
+
* which receives the route's context typed. A child route's procedures don't run it.
|
|
20
|
+
* - `.remote(({ query, mutation, stream, channel }) => ({ namespace: { … } }))` declares
|
|
21
|
+
* procedures in namespaces, each unique across the app and called at
|
|
22
|
+
* `/_rpc/<namespace>/<procedure>`. The route and its descendants see them as
|
|
23
|
+
* `injectRoute().remote.<namespace>` and as `remote` in their kept `resolve`, guards and
|
|
24
|
+
* `title`.
|
|
25
|
+
*
|
|
26
|
+
* Generation reads every step statically: write the chain as a direct default export, and
|
|
27
|
+
* each `.remote()` callback as an arrow function destructuring the builders it uses,
|
|
28
|
+
* returning a parenthesized object literal of namespaces whose procedures are direct
|
|
29
|
+
* builder calls with inline options.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { defineRoute } from "@loozo/angular-launch";
|
|
34
|
+
* import parent from "../route";
|
|
35
|
+
*
|
|
36
|
+
* export default defineRoute("todos", { parent })
|
|
37
|
+
* .remote(({ query }) => ({
|
|
38
|
+
* todos: {
|
|
39
|
+
* list: query({ handler: ({ context }) => context.db.todos.listForUser(context.user.id) }),
|
|
40
|
+
* },
|
|
41
|
+
* }))
|
|
42
|
+
* .resolve({ todos: ({ remote }) => remote.todos.list() });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const defineRoute: RouteFactory<LaunchSpec>;
|
package/route.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { runInInjectionContext } from "@angular/core";
|
|
2
|
+
import { createRouteFactory, } from "@loozo/angular-router/_core";
|
|
3
|
+
import { launchQueries } from "./launch-queries.js";
|
|
4
|
+
import { injectClient } from "./remote-client.js";
|
|
5
|
+
// A route copy's own record holds generation's data, `{ remote: { [namespace]: { methods } } }`,
|
|
6
|
+
// never the authored builder, which only the server's authored routes hold.
|
|
7
|
+
function namespacesOf(chain) {
|
|
8
|
+
const namespaces = Object.create(null);
|
|
9
|
+
for (const record of chain) {
|
|
10
|
+
const data = record.remote;
|
|
11
|
+
if (data === undefined) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
for (const [namespace, entry] of Object.entries(data)) {
|
|
15
|
+
namespaces[namespace] = entry;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return namespaces;
|
|
19
|
+
}
|
|
20
|
+
// The queries and mutations, which have TanStack factories; streams and channels don't.
|
|
21
|
+
function queryMethodsOf(namespaces) {
|
|
22
|
+
const result = Object.create(null);
|
|
23
|
+
for (const [namespace, { methods }] of Object.entries(namespaces)) {
|
|
24
|
+
const entries = Object.create(null);
|
|
25
|
+
for (const { name, kind, input } of methods) {
|
|
26
|
+
if (kind === "query" || kind === "mutation") {
|
|
27
|
+
entries[name] = { kind, input };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
result[namespace] = entries;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
function input(chain) {
|
|
35
|
+
return { remote: injectClient(namespacesOf(chain)) };
|
|
36
|
+
}
|
|
37
|
+
// Lazy getters: a page may read `route.remote` first from an event or after an `await`, so
|
|
38
|
+
// each member is built on first read inside the handle creator's injection context.
|
|
39
|
+
function handle(chain, injector) {
|
|
40
|
+
let remote;
|
|
41
|
+
let queries;
|
|
42
|
+
function client() {
|
|
43
|
+
remote ??= runInInjectionContext(injector, () => injectClient(namespacesOf(chain)));
|
|
44
|
+
return remote;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
get remote() {
|
|
48
|
+
return client();
|
|
49
|
+
},
|
|
50
|
+
get queries() {
|
|
51
|
+
if (queries === undefined) {
|
|
52
|
+
const create = injector.get(launchQueries, null);
|
|
53
|
+
if (create === null) {
|
|
54
|
+
throw new Error("route.queries requires provideLaunchQueries() from @loozo/angular-launch/tanstack-query in the application providers");
|
|
55
|
+
}
|
|
56
|
+
const rpc = client();
|
|
57
|
+
queries = runInInjectionContext(injector, () => create(rpc, queryMethodsOf(namespacesOf(chain))));
|
|
58
|
+
}
|
|
59
|
+
return queries;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Declares a route, like the router's `defineRoute`, with Launch's server steps offered
|
|
65
|
+
* first: `.context(stage)`, then `.use(...middleware)`, then `.remote(build)`, each at most
|
|
66
|
+
* once and in that order, before any router step.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Import it from `@loozo/angular-launch` in every `route.ts` of a Launch app. Its steps are
|
|
70
|
+
* server-only: generation strips them from the route's browser copy, and the server reads
|
|
71
|
+
* them from `server.generated.ts`.
|
|
72
|
+
*
|
|
73
|
+
* - `.context(stage)` derives the route's context from its ancestors'. The stage receives
|
|
74
|
+
* `StageArgs` from `@loozo/angular-launch/server` and returns the route's whole context:
|
|
75
|
+
* spread the context above, `{ ...context, user }`, to keep its keys. It runs at most once
|
|
76
|
+
* per request scope, only when a call needs it.
|
|
77
|
+
* - `.use(...middleware)` runs around this route's own procedures, after the stages and
|
|
78
|
+
* before input validation. Each entry is a shared `middleware()` or a bare async function,
|
|
79
|
+
* which receives the route's context typed. A child route's procedures don't run it.
|
|
80
|
+
* - `.remote(({ query, mutation, stream, channel }) => ({ namespace: { … } }))` declares
|
|
81
|
+
* procedures in namespaces, each unique across the app and called at
|
|
82
|
+
* `/_rpc/<namespace>/<procedure>`. The route and its descendants see them as
|
|
83
|
+
* `injectRoute().remote.<namespace>` and as `remote` in their kept `resolve`, guards and
|
|
84
|
+
* `title`.
|
|
85
|
+
*
|
|
86
|
+
* Generation reads every step statically: write the chain as a direct default export, and
|
|
87
|
+
* each `.remote()` callback as an arrow function destructuring the builders it uses,
|
|
88
|
+
* returning a parenthesized object literal of namespaces whose procedures are direct
|
|
89
|
+
* builder calls with inline options.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { defineRoute } from "@loozo/angular-launch";
|
|
94
|
+
* import parent from "../route";
|
|
95
|
+
*
|
|
96
|
+
* export default defineRoute("todos", { parent })
|
|
97
|
+
* .remote(({ query }) => ({
|
|
98
|
+
* todos: {
|
|
99
|
+
* list: query({ handler: ({ context }) => context.db.todos.listForUser(context.user.id) }),
|
|
100
|
+
* },
|
|
101
|
+
* }))
|
|
102
|
+
* .resolve({ todos: ({ remote }) => remote.todos.list() });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export const defineRoute = createRouteFactory({
|
|
106
|
+
steps: [
|
|
107
|
+
{ name: "context", serverOnly: true, arity: { min: 1, max: 1 } },
|
|
108
|
+
{ name: "use", serverOnly: true, arity: { min: 1, max: null } },
|
|
109
|
+
{ name: "remote", serverOnly: true, arity: { min: 1, max: 1 } },
|
|
110
|
+
],
|
|
111
|
+
input,
|
|
112
|
+
handle,
|
|
113
|
+
});
|
package/schemas/application.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$comment": "Generated by scripts/builder-schemas.mjs from the @angular/build 22.
|
|
3
|
+
"$comment": "Generated by scripts/builder-schemas.mjs from the @angular/build 22.3.0 application schema plus the Launch options. Do not edit. The @angular/build schema portions are distributed under this license:\n\nThe MIT License\n\nCopyright (c) 2010-2026 Google LLC. https://angular.dev/license\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
|
4
4
|
"title": "Application schema for Build Facade.",
|
|
5
5
|
"description": "Application builder target options",
|
|
6
6
|
"type": "object",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"type": "boolean",
|
|
27
27
|
"default": false
|
|
28
28
|
},
|
|
29
|
+
"translateSegments": {
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"default": false
|
|
32
|
+
},
|
|
29
33
|
"check": {
|
|
30
34
|
"type": "boolean",
|
|
31
35
|
"default": false
|
|
@@ -563,7 +567,7 @@
|
|
|
563
567
|
},
|
|
564
568
|
"statsJson": {
|
|
565
569
|
"type": "boolean",
|
|
566
|
-
"description": "Generates a 'stats.json' file which can be analyzed with https://esbuild.github.io/analyze/.",
|
|
570
|
+
"description": "Generates a 'browser-stats.json' file which can be analyzed with https://esbuild.github.io/analyze/. When server-side rendering is enabled, a 'server-stats.json' file is also generated.",
|
|
567
571
|
"default": false
|
|
568
572
|
},
|
|
569
573
|
"budgets": {
|
|
@@ -597,7 +601,7 @@
|
|
|
597
601
|
"oneOf": [
|
|
598
602
|
{
|
|
599
603
|
"type": "boolean",
|
|
600
|
-
"description": "Enable
|
|
604
|
+
"description": "Enable prerendering of pages of your application during build time."
|
|
601
605
|
},
|
|
602
606
|
{
|
|
603
607
|
"type": "object",
|
|
@@ -613,6 +617,18 @@
|
|
|
613
617
|
}
|
|
614
618
|
},
|
|
615
619
|
"additionalProperties": false
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
"type": "object",
|
|
623
|
+
"properties": {
|
|
624
|
+
"format": {
|
|
625
|
+
"type": "string",
|
|
626
|
+
"description": "Defines the file layout of prerendered pages. 'directory': '/foo' is written to 'foo/index.html'. 'file': '/foo' is written to 'foo.html', which some hosting services serve for '/foo' without a redirect to '/foo/'. The root route of the application and of each locale is always written to 'index.html'. Only considered when the build does not produce a server.",
|
|
627
|
+
"enum": ["directory", "file"]
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
"additionalProperties": false,
|
|
631
|
+
"required": ["format"]
|
|
616
632
|
}
|
|
617
633
|
]
|
|
618
634
|
},
|
package/schemas/serve.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
-
"$comment": "Generated by scripts/builder-schemas.mjs from the @angular/build 22.
|
|
3
|
+
"$comment": "Generated by scripts/builder-schemas.mjs from the @angular/build 22.3.0 dev-server schema plus the Launch options. Do not edit. The @angular/build schema portions are distributed under this license:\n\nThe MIT License\n\nCopyright (c) 2010-2026 Google LLC. https://angular.dev/license\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
|
|
4
4
|
"title": "Dev Server Target",
|
|
5
5
|
"description": "Dev Server target options for Build Facade.",
|
|
6
6
|
"type": "object",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"port": {
|
|
14
14
|
"type": "number",
|
|
15
|
-
"description": "Port to listen on.",
|
|
15
|
+
"description": "Port to listen on. The `PORT` environment variable, when set, takes precedence over this option.",
|
|
16
16
|
"default": 4200
|
|
17
17
|
},
|
|
18
18
|
"host": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
},
|
|
93
93
|
"hmr": {
|
|
94
94
|
"type": "boolean",
|
|
95
|
-
"description": "Enable hot module replacement. Defaults to the value of 'liveReload'. Currently,
|
|
95
|
+
"description": "Enable hot module replacement. Defaults to the value of 'liveReload'. Currently, global stylesheets, component stylesheets, and component templates are supported."
|
|
96
96
|
},
|
|
97
97
|
"watch": {
|
|
98
98
|
"type": "boolean",
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type AnyRoute, type ContributionRecord } from "@loozo/angular-router/_core";
|
|
2
|
+
import { type ErrorDefinitions, type ProcedureKind, type Schema } from "./definitions.js";
|
|
3
|
+
import { declaredFailures, type DeclaredFailure } from "./errors.js";
|
|
4
|
+
import type { Stage } from "./stages.js";
|
|
5
|
+
/**
|
|
6
|
+
* A registered procedure, as the server dispatches it.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Internal; not exported from a public entry point.
|
|
10
|
+
*/
|
|
11
|
+
export interface RuntimeProcedure {
|
|
12
|
+
readonly kind: ProcedureKind;
|
|
13
|
+
readonly input: Schema | undefined;
|
|
14
|
+
readonly message: Schema | undefined;
|
|
15
|
+
readonly errors: ErrorDefinitions;
|
|
16
|
+
readonly use: readonly ChainMiddleware[];
|
|
17
|
+
readonly [declaredFailures]?: WeakMap<object, DeclaredFailure>;
|
|
18
|
+
readonly handler: (args: object) => unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The runtime view of a middleware, a `middleware()` definition or a bare function; the
|
|
22
|
+
* dispatcher checks what it returns.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Internal; not exported from a public entry point.
|
|
26
|
+
*/
|
|
27
|
+
export type ChainMiddleware = {
|
|
28
|
+
readonly run: (args: never) => Promise<unknown>;
|
|
29
|
+
} | ((args: never) => Promise<unknown>);
|
|
30
|
+
/**
|
|
31
|
+
* One namespace of a route's `.remote()`, bound to the route that declared it.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Internal; not exported from a public entry point.
|
|
35
|
+
*/
|
|
36
|
+
export interface BoundNamespace {
|
|
37
|
+
/** The namespace's procedures, keyed by name. */
|
|
38
|
+
readonly procedures: Readonly<Record<string, RuntimeProcedure>>;
|
|
39
|
+
/** The declaring route's `.use()` middleware. */
|
|
40
|
+
readonly use: readonly ChainMiddleware[];
|
|
41
|
+
/** The stages from the root to the declaring route, root first. */
|
|
42
|
+
readonly stages: readonly Stage[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The application requests are bound to: its identity and its namespaces.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Internal; not exported from a public entry point. Generation writes it as `application`
|
|
49
|
+
* in `server.generated.ts`.
|
|
50
|
+
*/
|
|
51
|
+
export interface ApplicationBinding {
|
|
52
|
+
/** The generated application identity. */
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** Every route's `.remote()` namespaces, keyed by namespace. */
|
|
55
|
+
readonly namespaces: Readonly<Record<string, BoundNamespace>>;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the application was generated with `translateSegments`: its redirect frames then
|
|
58
|
+
* list their static word positions.
|
|
59
|
+
*/
|
|
60
|
+
readonly translateSegments?: true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A route's Launch contribution chain: the own records of its ancestors that used a Launch
|
|
64
|
+
* step, then its own, root first.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Internal; not exported from a public entry point.
|
|
68
|
+
*
|
|
69
|
+
* @param route - Any route.
|
|
70
|
+
* @returns The chain, or `undefined` for a route Launch's `defineRoute` didn't make and
|
|
71
|
+
* that has no Launch ancestor.
|
|
72
|
+
*/
|
|
73
|
+
export declare function launchChain(route: AnyRoute): readonly ContributionRecord[] | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Binds each namespace of a route's `.remote()` to the route's `.use()` middleware and to
|
|
76
|
+
* `stages`.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* Internal; not exported from a public entry point.
|
|
80
|
+
*
|
|
81
|
+
* @param own - The declaring route's own record, which has a `.remote()` callback.
|
|
82
|
+
* @param stages - The stages a call to one of the namespaces runs, root first.
|
|
83
|
+
* @returns The route's namespaces, keyed by namespace.
|
|
84
|
+
*/
|
|
85
|
+
export declare function bindNamespaces(own: ContributionRecord, stages: readonly Stage[]): Record<string, BoundNamespace>;
|
|
86
|
+
/**
|
|
87
|
+
* Binds an application's authored routes into the {@link ApplicationBinding} the server
|
|
88
|
+
* dispatches with.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* Internal: exported only from `@loozo/angular-launch/_server` for the generated
|
|
92
|
+
* `server.generated.ts`. Each namespace's owner is fixed here, from the route that declared
|
|
93
|
+
* it: a call runs that route's stages and `.use()` middleware, whichever page called it.
|
|
94
|
+
* Every route with a stage that a listed route's chain holds must be listed too, so the
|
|
95
|
+
* stage carries its route's file. Generation lists every route with a server-only step and
|
|
96
|
+
* enforces namespace uniqueness.
|
|
97
|
+
*
|
|
98
|
+
* @param id - The generated application identity.
|
|
99
|
+
* @param routes - Each authored route with a server-only step, with its workspace-relative file.
|
|
100
|
+
* @param options - `translateSegments`: generation wrote the app with translated segments.
|
|
101
|
+
* @returns The application binding.
|
|
102
|
+
* @throws TypeError for a route Launch's `defineRoute` didn't make, or a stage whose route
|
|
103
|
+
* isn't listed.
|
|
104
|
+
*/
|
|
105
|
+
export declare function bindApplication(id: string, routes: readonly (readonly [route: AnyRoute, file: string])[], options?: {
|
|
106
|
+
readonly translateSegments?: true;
|
|
107
|
+
}): ApplicationBinding;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { routeContributions, } from "@loozo/angular-router/_core";
|
|
2
|
+
import { defineRoute } from "../route.js";
|
|
3
|
+
import { builder } from "./definitions.js";
|
|
4
|
+
import { declaredFailures } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* A route's Launch contribution chain: the own records of its ancestors that used a Launch
|
|
7
|
+
* step, then its own, root first.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Internal; not exported from a public entry point.
|
|
11
|
+
*
|
|
12
|
+
* @param route - Any route.
|
|
13
|
+
* @returns The chain, or `undefined` for a route Launch's `defineRoute` didn't make and
|
|
14
|
+
* that has no Launch ancestor.
|
|
15
|
+
*/
|
|
16
|
+
export function launchChain(route) {
|
|
17
|
+
// `routeContributions` takes any extension's factory; a spec's step tuple isn't
|
|
18
|
+
// assignable to the general one, so name Launch's factory by the general type.
|
|
19
|
+
const factory = defineRoute;
|
|
20
|
+
return routeContributions(factory, route);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Binds each namespace of a route's `.remote()` to the route's `.use()` middleware and to
|
|
24
|
+
* `stages`.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Internal; not exported from a public entry point.
|
|
28
|
+
*
|
|
29
|
+
* @param own - The declaring route's own record, which has a `.remote()` callback.
|
|
30
|
+
* @param stages - The stages a call to one of the namespaces runs, root first.
|
|
31
|
+
* @returns The route's namespaces, keyed by namespace.
|
|
32
|
+
*/
|
|
33
|
+
export function bindNamespaces(own, stages) {
|
|
34
|
+
const build = own.remote;
|
|
35
|
+
const use = (own.use ?? []);
|
|
36
|
+
const namespaces = Object.create(null);
|
|
37
|
+
for (const [namespace, procedures] of Object.entries(build(builder))) {
|
|
38
|
+
namespaces[namespace] = {
|
|
39
|
+
procedures: procedures,
|
|
40
|
+
use,
|
|
41
|
+
stages,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return namespaces;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Binds an application's authored routes into the {@link ApplicationBinding} the server
|
|
48
|
+
* dispatches with.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Internal: exported only from `@loozo/angular-launch/_server` for the generated
|
|
52
|
+
* `server.generated.ts`. Each namespace's owner is fixed here, from the route that declared
|
|
53
|
+
* it: a call runs that route's stages and `.use()` middleware, whichever page called it.
|
|
54
|
+
* Every route with a stage that a listed route's chain holds must be listed too, so the
|
|
55
|
+
* stage carries its route's file. Generation lists every route with a server-only step and
|
|
56
|
+
* enforces namespace uniqueness.
|
|
57
|
+
*
|
|
58
|
+
* @param id - The generated application identity.
|
|
59
|
+
* @param routes - Each authored route with a server-only step, with its workspace-relative file.
|
|
60
|
+
* @param options - `translateSegments`: generation wrote the app with translated segments.
|
|
61
|
+
* @returns The application binding.
|
|
62
|
+
* @throws TypeError for a route Launch's `defineRoute` didn't make, or a stage whose route
|
|
63
|
+
* isn't listed.
|
|
64
|
+
*/
|
|
65
|
+
export function bindApplication(id, routes, options = {}) {
|
|
66
|
+
const chains = [];
|
|
67
|
+
// Keyed by each route's own record, which its descendants' chains share.
|
|
68
|
+
const labels = new Map();
|
|
69
|
+
const stages = new Map();
|
|
70
|
+
const namespaces = Object.create(null);
|
|
71
|
+
for (const [route, file] of routes) {
|
|
72
|
+
const chain = launchChain(route);
|
|
73
|
+
if (!chain || chain.length === 0) {
|
|
74
|
+
throw new TypeError(`Launch route has no server steps: ${file}`);
|
|
75
|
+
}
|
|
76
|
+
chains.push(chain);
|
|
77
|
+
labels.set(chain[chain.length - 1], file);
|
|
78
|
+
}
|
|
79
|
+
function stageOf(record) {
|
|
80
|
+
let stage = stages.get(record);
|
|
81
|
+
if (!stage) {
|
|
82
|
+
const route = labels.get(record);
|
|
83
|
+
if (route === undefined) {
|
|
84
|
+
throw new TypeError("Launch stage belongs to a route the application doesn't list");
|
|
85
|
+
}
|
|
86
|
+
stage = { run: record.context, route };
|
|
87
|
+
stages.set(record, stage);
|
|
88
|
+
}
|
|
89
|
+
return stage;
|
|
90
|
+
}
|
|
91
|
+
for (const chain of chains) {
|
|
92
|
+
const own = chain[chain.length - 1];
|
|
93
|
+
if (typeof own.remote !== "function") {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const owned = [];
|
|
97
|
+
for (const record of chain) {
|
|
98
|
+
if (typeof record.context === "function") {
|
|
99
|
+
owned.push(stageOf(record));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Object.assign(namespaces, bindNamespaces(own, owned));
|
|
103
|
+
}
|
|
104
|
+
if (options.translateSegments) {
|
|
105
|
+
return { id, namespaces, translateSegments: true };
|
|
106
|
+
}
|
|
107
|
+
return { id, namespaces };
|
|
108
|
+
}
|