@loozo/angular-launch 0.0.5 → 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 +1068 -187
- 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 +55 -0
- package/channel.js +232 -0
- package/client.d.ts +63 -33
- package/connect.d.ts +201 -0
- package/connect.js +148 -0
- package/generation/index.d.ts +2 -123
- package/generation/index.js +3 -669
- 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 +8 -1
- package/index.js +3 -0
- package/json.d.ts +9 -0
- package/json.js +24 -0
- package/launch-queries.d.ts +16 -0
- package/launch-queries.js +3 -0
- package/navigation.d.ts +36 -0
- package/navigation.js +47 -0
- package/node/index.d.ts +60 -0
- package/node/index.js +178 -0
- package/node/upgrade-listener-slot.d.ts +1 -0
- package/node/upgrade-listener-slot.js +4 -0
- package/outcomes.d.ts +71 -0
- package/outcomes.js +146 -0
- package/package.json +21 -11
- package/redirect-translation.d.ts +53 -0
- package/redirect-translation.js +141 -0
- package/{generated.d.ts → remote-client.d.ts} +1 -1
- package/remote-client.js +179 -0
- 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 +62 -31
- package/server/backend.js +149 -55
- package/server/channel-messages.d.ts +54 -0
- package/server/channel-messages.js +84 -0
- package/server/channel-socket.d.ts +67 -0
- package/server/channel-socket.js +322 -0
- package/server/definitions.d.ts +270 -294
- package/server/definitions.js +35 -115
- package/server/dispatch.d.ts +121 -66
- package/server/dispatch.js +267 -87
- package/server/event-stream.d.ts +63 -0
- package/server/event-stream.js +173 -0
- package/server/generated.d.ts +3 -1
- package/server/generated.js +3 -1
- package/server/index.d.ts +6 -3
- package/server/index.js +3 -2
- package/server/outcomes.d.ts +64 -2
- package/server/outcomes.js +85 -4
- package/server/read-cookies.d.ts +19 -0
- package/server/read-cookies.js +39 -0
- package/server/response-effects.d.ts +105 -0
- package/server/response-effects.js +78 -0
- package/server/stages.d.ts +62 -0
- package/server/stages.js +51 -0
- package/server/upgrade.d.ts +57 -0
- package/server/upgrade.js +116 -0
- package/source-text.d.ts +1 -0
- package/source-text.js +56 -0
- package/stream.d.ts +34 -0
- package/stream.js +161 -0
- package/tanstack-query/README.md +113 -21
- package/tanstack-query/create-queries.d.ts +2 -0
- package/tanstack-query/{generated.js → create-queries.js} +13 -11
- 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 +50 -33
- 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/generated.js +0 -90
- package/generation/context-file.d.ts +0 -2
- package/generation/context-file.js +0 -3
- package/tanstack-query/generated.d.ts +0 -5
package/connect.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { isPlatformServer } from "@angular/common";
|
|
2
|
+
import { afterNextRender, computed, DestroyRef, effect, inject, PLATFORM_ID, signal, untracked, } from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Follows a stream or channel as signals. Internal: generated callables expose it as
|
|
5
|
+
* `connect()`.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Must run in an injection context. On the server it never connects: status stays `"idle"`
|
|
9
|
+
* and `value` is `initial()`. In the browser it connects after the next render, and again
|
|
10
|
+
* whenever `input` changes; each connection reads every value as it arrives. A connection
|
|
11
|
+
* closed for a new input or by the injection context's destruction doesn't change `status`
|
|
12
|
+
* or `error`.
|
|
13
|
+
*
|
|
14
|
+
* @param open - Opens one call.
|
|
15
|
+
* @param options - The `connect()` options.
|
|
16
|
+
* @returns The connection; `send` delegates to the open channel.
|
|
17
|
+
*/
|
|
18
|
+
export function connect(open, { input = () => null, initial, reduce }) {
|
|
19
|
+
const server = isPlatformServer(inject(PLATFORM_ID));
|
|
20
|
+
const destroyRef = inject(DestroyRef);
|
|
21
|
+
const received = signal(undefined);
|
|
22
|
+
const status = signal("idle");
|
|
23
|
+
const error = signal(undefined);
|
|
24
|
+
const value = computed(() => {
|
|
25
|
+
const latest = received();
|
|
26
|
+
if (latest === undefined) {
|
|
27
|
+
return initial();
|
|
28
|
+
}
|
|
29
|
+
return latest.state;
|
|
30
|
+
});
|
|
31
|
+
let current;
|
|
32
|
+
function close() {
|
|
33
|
+
current?.controller.abort();
|
|
34
|
+
current = undefined;
|
|
35
|
+
}
|
|
36
|
+
function fail(caught) {
|
|
37
|
+
error.set(caught);
|
|
38
|
+
status.set("failed");
|
|
39
|
+
}
|
|
40
|
+
async function follow(call) {
|
|
41
|
+
const { controller, connection } = call;
|
|
42
|
+
let state;
|
|
43
|
+
let first = true;
|
|
44
|
+
try {
|
|
45
|
+
for await (const item of connection) {
|
|
46
|
+
if (controller.signal.aborted) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (!reduce) {
|
|
51
|
+
state = item;
|
|
52
|
+
}
|
|
53
|
+
else if (first) {
|
|
54
|
+
// A new call's first value folds into the initial state, not the previous call's.
|
|
55
|
+
state = untracked(() => reduce(initial(), item));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const previous = state;
|
|
59
|
+
state = untracked(() => reduce(previous, item));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (thrown) {
|
|
63
|
+
let failure;
|
|
64
|
+
if (thrown instanceof Error) {
|
|
65
|
+
failure = thrown;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
failure = new Error("Launch connection's reduce threw a non-Error value", {
|
|
69
|
+
cause: thrown,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Set before the loop closes the channel, so the sends it rejects carry this error.
|
|
73
|
+
call.failure = { error: failure };
|
|
74
|
+
fail(failure);
|
|
75
|
+
throw failure;
|
|
76
|
+
}
|
|
77
|
+
first = false;
|
|
78
|
+
received.set({ state });
|
|
79
|
+
status.set("open");
|
|
80
|
+
}
|
|
81
|
+
if (!controller.signal.aborted) {
|
|
82
|
+
status.set("ended");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (caught) {
|
|
86
|
+
if (controller.signal.aborted || call.failure !== undefined) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
fail(caught);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function start(next) {
|
|
93
|
+
close();
|
|
94
|
+
if (next === undefined) {
|
|
95
|
+
error.set(undefined);
|
|
96
|
+
status.set("idle");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
const connection = open(next, controller.signal, () => {
|
|
101
|
+
if (current?.controller === controller && status() === "connecting") {
|
|
102
|
+
status.set("open");
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const call = { controller, connection };
|
|
106
|
+
current = call;
|
|
107
|
+
error.set(undefined);
|
|
108
|
+
status.set("connecting");
|
|
109
|
+
void follow(call);
|
|
110
|
+
}
|
|
111
|
+
if (!server) {
|
|
112
|
+
const rendered = signal(false);
|
|
113
|
+
afterNextRender(() => rendered.set(true));
|
|
114
|
+
effect(() => {
|
|
115
|
+
if (!rendered()) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const next = input();
|
|
119
|
+
untracked(() => start(next));
|
|
120
|
+
});
|
|
121
|
+
destroyRef.onDestroy(close);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
value,
|
|
125
|
+
status: status.asReadonly(),
|
|
126
|
+
error: error.asReadonly(),
|
|
127
|
+
reconnect() {
|
|
128
|
+
const now = untracked(status);
|
|
129
|
+
if (now === "ended" || now === "failed") {
|
|
130
|
+
start(untracked(input));
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
send(message) {
|
|
134
|
+
const now = untracked(status);
|
|
135
|
+
const call = current;
|
|
136
|
+
if (!call || (now !== "connecting" && now !== "open") || !("send" in call.connection)) {
|
|
137
|
+
return Promise.reject(new TypeError("Launch connection isn't open"));
|
|
138
|
+
}
|
|
139
|
+
// A failing `reduce` closes the channel; its sends then reject with what it threw.
|
|
140
|
+
return call.connection.send(message).catch((rejection) => {
|
|
141
|
+
if (call.failure !== undefined) {
|
|
142
|
+
return Promise.reject(call.failure.error);
|
|
143
|
+
}
|
|
144
|
+
return Promise.reject(rejection);
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
package/generation/index.d.ts
CHANGED
|
@@ -1,123 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/** The application's tsconfig, relative to the workspace. It must enable strict checking. */
|
|
4
|
-
tsconfig: string;
|
|
5
|
-
/** Exactly one route directory, relative to the tsconfig's directory. */
|
|
6
|
-
scanDirectories: string[];
|
|
7
|
-
/** Where the application-wide generated files go, relative to the workspace. */
|
|
8
|
-
outDirectory: string;
|
|
9
|
-
/**
|
|
10
|
-
* Also writes `injectQueries()` and `type Queries` into each `rpc.generated.ts`: TanStack
|
|
11
|
-
* Query options and keys for the same groups as `injectRpc()`. Requires
|
|
12
|
-
* `@tanstack/angular-query` in the application and `provideLaunchQueries()` from
|
|
13
|
-
* `@loozo/angular-launch/tanstack-query` in its providers. Defaults to `false`.
|
|
14
|
-
*/
|
|
15
|
-
tanstackQuery?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Verifies the generated files without writing them, failing when any is changed,
|
|
18
|
-
* missing or stale. Defaults to `false`.
|
|
19
|
-
*/
|
|
20
|
-
check?: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* A generation session created by {@link createGenerationSession}, reusing compiler
|
|
24
|
-
* work between calls.
|
|
25
|
-
*/
|
|
26
|
-
export interface GenerationSession {
|
|
27
|
-
/**
|
|
28
|
-
* Generates or checks the application's files, like {@link generate} with the
|
|
29
|
-
* session's options.
|
|
30
|
-
*
|
|
31
|
-
* @remarks
|
|
32
|
-
* Calls must be sequential. A failed call doesn't break the session; the next call
|
|
33
|
-
* starts clean.
|
|
34
|
-
*
|
|
35
|
-
* @param options - `check`: verify without writing. Defaults to `false`.
|
|
36
|
-
* @param stopped - Called once just before writing; returning `true` skips writing and
|
|
37
|
-
* resolves. Defaults to never stopping.
|
|
38
|
-
* @returns A promise that resolves when generation finishes.
|
|
39
|
-
* @throws Rejects when the session is disposed, when another call hasn't settled yet,
|
|
40
|
-
* and for the same failures as {@link generate}.
|
|
41
|
-
*/
|
|
42
|
-
generate(options?: Pick<GenerationOptions, "check">, stopped?: () => boolean): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Disposes the session: stops an active call before it writes, waits for it to settle
|
|
45
|
-
* and makes later calls reject.
|
|
46
|
-
*
|
|
47
|
-
* @returns A promise that resolves once any active call has settled.
|
|
48
|
-
*/
|
|
49
|
-
dispose(): Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Generates the router's and Launch's files for an application, or checks them.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* Node-only. Generation reads your sources without running them. Besides the router's
|
|
56
|
-
* files, it writes an `rpc.generated.ts` beside each route that gets a
|
|
57
|
-
* `route.generated.ts`, and `context.generated.d.ts` and `server.generated.ts` in the
|
|
58
|
-
* output directory. Run it before the Angular build.
|
|
59
|
-
*
|
|
60
|
-
* Everything is validated, including a type check of the generated files with
|
|
61
|
-
* `skipLibCheck: false`, before anything is written, so a failed run changes nothing.
|
|
62
|
-
* Files are then written one at a time without rollback; a write error partway through
|
|
63
|
-
* can leave some files updated, which the next successful run repairs. Generation only
|
|
64
|
-
* replaces or removes files carrying its ownership marker, and removes stale ones.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```js
|
|
68
|
-
* import { generate } from "@loozo/angular-launch/generation";
|
|
69
|
-
*
|
|
70
|
-
* await generate(import.meta.dirname, {
|
|
71
|
-
* tsconfig: "tsconfig.app.json",
|
|
72
|
-
* scanDirectories: ["src/routes"],
|
|
73
|
-
* outDirectory: "generated",
|
|
74
|
-
* check: process.argv.includes("--check"),
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* @param workspace - The absolute path of the application directory, which contains
|
|
79
|
-
* its `package.json`. The tsconfig, scanned directory, sources and output directory
|
|
80
|
-
* must all be inside it.
|
|
81
|
-
* @param options - The generation options.
|
|
82
|
-
* @param stopped - Called once just before writing; returning `true` skips writing and
|
|
83
|
-
* resolves. Defaults to never stopping.
|
|
84
|
-
* @returns A promise that resolves when generation finishes.
|
|
85
|
-
* @throws Rejects when a path escapes the workspace, the tsconfig disables strict
|
|
86
|
-
* checking or enables `noCheck`, the application's `package.json` has no `name`, the
|
|
87
|
-
* sources or generated files fail validation, a file to replace lacks the ownership
|
|
88
|
-
* marker, or, with `check`, a generated file is out of date.
|
|
89
|
-
*/
|
|
90
|
-
export declare function generate(workspace: string, options: GenerationOptions, stopped?: () => boolean): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Creates a generation session that reuses compiler work between sequential calls.
|
|
93
|
-
*
|
|
94
|
-
* @remarks
|
|
95
|
-
* Node-only. For long-running tools that regenerate repeatedly, such as after file
|
|
96
|
-
* changes. A session doesn't watch files; you decide when to call `generate`. Edits
|
|
97
|
-
* inside the application are picked up by the next call. Create a new session after
|
|
98
|
-
* moving the application directory or changing dependencies. Don't run two sessions or
|
|
99
|
-
* generators against the same output at once.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```js
|
|
103
|
-
* const session = createGenerationSession(workspace, {
|
|
104
|
-
* tsconfig: "tsconfig.app.json",
|
|
105
|
-
* scanDirectories: ["src/routes"],
|
|
106
|
-
* outDirectory: "generated",
|
|
107
|
-
* });
|
|
108
|
-
*
|
|
109
|
-
* try {
|
|
110
|
-
* await session.generate();
|
|
111
|
-
* await session.generate({ check: true });
|
|
112
|
-
* } finally {
|
|
113
|
-
* await session.dispose();
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* @param workspace - The absolute path of the application directory, as for
|
|
118
|
-
* {@link generate}.
|
|
119
|
-
* @param options - The generation options, fixed for the session's lifetime; `check` is
|
|
120
|
-
* passed per call instead.
|
|
121
|
-
* @returns The session. Dispose it when done.
|
|
122
|
-
*/
|
|
123
|
-
export declare function createGenerationSession(workspace: string, { tsconfig, scanDirectories, outDirectory, tanstackQuery }: Omit<GenerationOptions, "check">): GenerationSession;
|
|
1
|
+
export { generate, createGenerationSession } from "./run.js";
|
|
2
|
+
export type { GenerationOptions, GenerationSession } from "./run.js";
|