@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.
Files changed (85) hide show
  1. package/README.md +715 -255
  2. package/builders/application.js +32 -3
  3. package/builders/channel-forwarding.d.ts +15 -0
  4. package/builders/channel-forwarding.js +61 -0
  5. package/builders/options.d.ts +6 -2
  6. package/builders/options.js +16 -5
  7. package/builders/serve.js +198 -140
  8. package/channel.d.ts +3 -1
  9. package/channel.js +3 -2
  10. package/client.d.ts +14 -24
  11. package/generation/index.d.ts +2 -123
  12. package/generation/index.js +3 -685
  13. package/generation/redirects.d.ts +14 -0
  14. package/generation/redirects.js +43 -0
  15. package/generation/run.d.ts +168 -0
  16. package/generation/run.js +659 -0
  17. package/index.d.ts +2 -0
  18. package/index.js +1 -0
  19. package/launch-queries.d.ts +16 -0
  20. package/launch-queries.js +3 -0
  21. package/navigation.d.ts +3 -3
  22. package/navigation.js +1 -1
  23. package/node/index.d.ts +3 -0
  24. package/node/index.js +6 -3
  25. package/node/upgrade-listener-slot.d.ts +1 -0
  26. package/node/upgrade-listener-slot.js +4 -0
  27. package/outcomes.d.ts +23 -7
  28. package/outcomes.js +58 -12
  29. package/package.json +15 -11
  30. package/redirect-translation.d.ts +53 -0
  31. package/redirect-translation.js +141 -0
  32. package/{generated.js → remote-client.js} +27 -21
  33. package/route-types.d.ts +130 -0
  34. package/route-types.js +1 -0
  35. package/route.d.ts +45 -0
  36. package/route.js +113 -0
  37. package/schemas/application.json +19 -3
  38. package/schemas/serve.json +3 -3
  39. package/server/application.d.ts +107 -0
  40. package/server/application.js +108 -0
  41. package/server/backend.d.ts +25 -13
  42. package/server/backend.js +39 -24
  43. package/server/channel-messages.d.ts +1 -1
  44. package/server/channel-messages.js +1 -1
  45. package/server/channel-socket.d.ts +1 -1
  46. package/server/definitions.d.ts +146 -298
  47. package/server/definitions.js +29 -117
  48. package/server/dispatch.d.ts +67 -63
  49. package/server/dispatch.js +121 -61
  50. package/server/event-stream.d.ts +2 -2
  51. package/server/event-stream.js +1 -1
  52. package/server/generated.d.ts +2 -1
  53. package/server/generated.js +2 -1
  54. package/server/index.d.ts +3 -2
  55. package/server/index.js +2 -1
  56. package/server/outcomes.d.ts +26 -13
  57. package/server/outcomes.js +43 -16
  58. package/server/read-cookies.d.ts +19 -0
  59. package/server/read-cookies.js +39 -0
  60. package/server/response-effects.d.ts +2 -2
  61. package/server/stages.d.ts +62 -0
  62. package/server/stages.js +51 -0
  63. package/server/upgrade.d.ts +11 -12
  64. package/server/upgrade.js +13 -14
  65. package/source-text.d.ts +1 -0
  66. package/source-text.js +56 -0
  67. package/stream.d.ts +6 -3
  68. package/stream.js +8 -6
  69. package/tanstack-query/README.md +15 -15
  70. package/tanstack-query/create-queries.d.ts +2 -0
  71. package/tanstack-query/{generated.js → create-queries.js} +8 -9
  72. package/tanstack-query/hydration-window.d.ts +11 -0
  73. package/tanstack-query/hydration-window.js +9 -0
  74. package/tanstack-query/hydration.d.ts +4 -14
  75. package/tanstack-query/hydration.js +9 -12
  76. package/tanstack-query/index.d.ts +1 -1
  77. package/tanstack-query/queries.d.ts +42 -27
  78. package/testing/call-procedure.d.ts +154 -0
  79. package/testing/call-procedure.js +97 -0
  80. package/testing/index.d.ts +2 -0
  81. package/testing/index.js +1 -0
  82. package/generation/context-file.d.ts +0 -2
  83. package/generation/context-file.js +0 -3
  84. package/tanstack-query/generated.d.ts +0 -5
  85. /package/{generated.d.ts → remote-client.d.ts} +0 -0
package/channel.js CHANGED
@@ -19,8 +19,9 @@ const messageWindow = 32;
19
19
  * @param options - The call options.
20
20
  * @param opened - Called once the socket opens.
21
21
  * @param refused - Fails the channel at once with this error, without a connection.
22
+ * @param translate - Puts a redirect's listed words in this build's language.
22
23
  */
23
- export function openChannel(path, declared, own, { signal }, opened = () => undefined, refused) {
24
+ export function openChannel(path, declared, own, { signal }, opened = () => undefined, refused, translate) {
24
25
  const values = [];
25
26
  const sends = [];
26
27
  let socket;
@@ -125,7 +126,7 @@ export function openChannel(path, declared, own, { signal }, opened = () => unde
125
126
  const { status, ...body } = frame;
126
127
  let error;
127
128
  if (typeof status === "number") {
128
- error = failureRejection(body, status, declared, own);
129
+ error = failureRejection(body, status, declared, own, translate);
129
130
  }
130
131
  finish(error ?? new TypeError("Launch channel sent an unrecognized error"));
131
132
  return;
package/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ErrorDefinitions, Group, InputOf, OutputOf, Procedure, ProcedureKind, Schema } from "./server/definitions.js";
1
+ import type { ErrorDefinitions, InputOf, OutputOf, Procedure, ProcedureKind, Schema } from "./server/definitions.js";
2
2
  import type { Channel } from "./channel.js";
3
3
  import type { ChannelConnector, ConnectInput, OptionalConnectInput, StreamConnector } from "./connect.js";
4
4
  import { type InvalidInputData } from "./input-issues.js";
@@ -64,7 +64,7 @@ export interface ChannelCallOptions {
64
64
  *
65
65
  * @remarks
66
66
  * Internal; not exported from a public entry point. Generation writes these entries
67
- * into each `rpc.generated.ts` so the client can recognize the procedure's declared
67
+ * into each route copy's data so the client can recognize the procedure's declared
68
68
  * error responses without the server's schemas.
69
69
  */
70
70
  export interface ErrorMetadata {
@@ -214,16 +214,8 @@ type DeclaredError<Errors extends ErrorDefinitions> = {
214
214
  * @remarks
215
215
  * A union discriminated by `code`: one member per framework failure, with
216
216
  * {@link InvalidInputData} for `INVALID_INPUT` and `null` data for the others, and one
217
- * per declared error with its data schema's output type. Import the group
218
- * with `import type` so server code stays out of the browser bundle.
219
- *
220
- * @example
221
- * ```ts
222
- * import type { ClientRpcError } from "@loozo/angular-launch";
223
- * import type todos from "./rpc";
224
- *
225
- * type CompleteError = ClientRpcError<typeof todos.procedures.complete>;
226
- * ```
217
+ * per declared error with its data schema's output type. Narrow a caught error with the
218
+ * callable's `isError` to get it.
227
219
  *
228
220
  * @typeParam Value - A procedure created by `query` or `mutation`.
229
221
  */
@@ -245,7 +237,7 @@ type Connectable<Input, Output, Kind extends ProcedureKind, Message> = Kind exte
245
237
  * The generated client callable for a procedure.
246
238
  *
247
239
  * @remarks
248
- * The type of `Client<typeof group>["name"]`. A procedure with an input schema is called as
240
+ * The type of `route.remote.<namespace>.<name>`. A procedure with an input schema is called as
249
241
  * `(input, options?)`, where `input` is the schema's input type; one without input is
250
242
  * called as `(options?)`. A query or mutation call returns a promise of the handler's
251
243
  * awaited result, a stream call an async iterable of its values, and a channel call an open
@@ -269,25 +261,23 @@ export type ClientProcedure<Value> = Value extends Procedure<infer Input, infer
269
261
  isError(error: unknown): error is FrameworkError | DeclaredError<Errors>;
270
262
  } : never;
271
263
  /**
272
- * The generated client for an RPC group: one callable per procedure.
264
+ * The client for one `.remote()` namespace: one callable per procedure.
273
265
  *
274
266
  * @remarks
275
- * Generated `injectRpc()` functions return an object of these, keyed by namespace.
276
- * Call `injectRpc()` in an Angular injection context where `HttpClient` is provided;
277
- * the clients it returns can be called later, outside an injection context. Import the
278
- * group with `import type` so server code stays out of the browser bundle.
267
+ * A route handle's `remote` holds one of these per namespace the route can see, its own and
268
+ * its ancestors'. Read `injectRoute().remote` and call the procedures later, outside an
269
+ * injection context if you like. A route copy exports the whole shape as `Remote`.
279
270
  *
280
271
  * @example
281
272
  * ```ts
282
- * import type { Client } from "@loozo/angular-launch";
283
- * import type todos from "./rpc";
273
+ * import type { Remote } from "./route.generated";
284
274
  *
285
- * type Todos = Awaited<ReturnType<Client<typeof todos>["list"]>>;
275
+ * type Todos = Awaited<ReturnType<Remote["todos"]["list"]>>;
286
276
  * ```
287
277
  *
288
- * @typeParam Value - A group created by `defineRpc`.
278
+ * @typeParam Procedures - A namespace's procedures, keyed by name, as `.remote()` returns them.
289
279
  */
290
- export type Client<Value> = Value extends Group<string, infer Procedures> ? {
280
+ export type Client<Procedures> = {
291
281
  readonly [Key in keyof Procedures]: ClientProcedure<Procedures[Key]>;
292
- } : never;
282
+ };
293
283
  export {};
@@ -1,123 +1,2 @@
1
- /** Options for {@link generate} and {@link createGenerationSession}. */
2
- export interface GenerationOptions {
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";