@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
@@ -0,0 +1,14 @@
1
+ import { type Sources } from "@loozo/angular-router/_generation";
2
+ /**
3
+ * The text of `redirects.generated.ts`: every distinct canonical static word of every route,
4
+ * with the router's own message for it, so each localized build swaps a redirect's words into
5
+ * its language exactly as its destination copies translate them.
6
+ *
7
+ * @remarks
8
+ * A declaration's local static segments cover every effective one, since each effective static
9
+ * is some declaration's local static. Words are sorted by code unit, so the bytes don't depend
10
+ * on the machine's locale. The tags sit inside the table function: nothing evaluates them
11
+ * until a client in a localized application needs the table, and the module imports no
12
+ * destination, so lazy children stay lazy.
13
+ */
14
+ export declare function emitRedirects(sources: Sources): string;
@@ -0,0 +1,43 @@
1
+ import { launchMarkers, segmentMessage } from "@loozo/angular-router/_generation";
2
+ /**
3
+ * The text of `redirects.generated.ts`: every distinct canonical static word of every route,
4
+ * with the router's own message for it, so each localized build swaps a redirect's words into
5
+ * its language exactly as its destination copies translate them.
6
+ *
7
+ * @remarks
8
+ * A declaration's local static segments cover every effective one, since each effective static
9
+ * is some declaration's local static. Words are sorted by code unit, so the bytes don't depend
10
+ * on the machine's locale. The tags sit inside the table function: nothing evaluates them
11
+ * until a client in a localized application needs the table, and the module imports no
12
+ * destination, so lazy children stay lazy.
13
+ */
14
+ export function emitRedirects(sources) {
15
+ const words = new Set();
16
+ for (const declaration of sources.declarations) {
17
+ for (const segment of declaration.segments) {
18
+ if (segment.kind === "static") {
19
+ words.add(segment.text);
20
+ }
21
+ }
22
+ }
23
+ const sorted = [...words].sort((a, b) => {
24
+ if (a < b) {
25
+ return -1;
26
+ }
27
+ return Number(a > b);
28
+ });
29
+ return [
30
+ launchMarkers["redirects.generated.ts"],
31
+ `import { redirectTranslation } from '@loozo/angular-launch/_redirects';`,
32
+ "",
33
+ "// Every static route segment, canonical, with the router's own message for it.",
34
+ "export const provideRedirectTranslation = () =>",
35
+ " redirectTranslation(() => ({",
36
+ ` words: [${sorted.map((word) => JSON.stringify(word)).join(", ")}],`,
37
+ " translations: [",
38
+ ...sorted.map((word) => ` ${segmentMessage(word)},`),
39
+ " ],",
40
+ " }));",
41
+ "",
42
+ ].join("\n");
43
+ }
@@ -0,0 +1,168 @@
1
+ import { CompilerState, AnchorState } from "@loozo/angular-router/_generation";
2
+ import type { Localization, LocaleWords } from "@loozo/angular-router/_generation";
3
+ /** Options for {@link generate} and {@link createGenerationSession}. */
4
+ export interface GenerationOptions {
5
+ /** The application's tsconfig, relative to the workspace. It must enable strict checking. */
6
+ tsconfig: string;
7
+ /** Exactly one route directory, relative to the tsconfig's directory. */
8
+ scanDirectories: string[];
9
+ /** Where the application-wide generated files go, relative to the workspace. */
10
+ outDirectory: string;
11
+ /**
12
+ * Adds `route.queries` and `type Queries` to each route copy: TanStack Query options and
13
+ * keys for the same namespaces as `route.remote`. Requires `@tanstack/angular-query` in
14
+ * the application and `provideLaunchQueries()` from `@loozo/angular-launch/tanstack-query`
15
+ * in its providers. Defaults to `false`.
16
+ */
17
+ tanstackQuery?: boolean;
18
+ /**
19
+ * Translates static route segments per Angular localize build, as the router's
20
+ * `translateSegments` does, and writes `redirects.generated.ts`, whose
21
+ * `provideRedirectTranslation()` puts RPC redirects in the page's language. Needs
22
+ * `localization`. Defaults to `false`.
23
+ */
24
+ translateSegments?: boolean;
25
+ /**
26
+ * The build's i18n configuration and polyfills, which every locale's translated route tree
27
+ * is validated against. Read only when `translateSegments` is true; Launch's builders fill it
28
+ * from the project.
29
+ */
30
+ localization?: Localization;
31
+ /**
32
+ * Verifies the generated files without writing them, failing when any is changed,
33
+ * missing or stale. Defaults to `false`.
34
+ */
35
+ check?: boolean;
36
+ }
37
+ /**
38
+ * A generation session created by {@link createGenerationSession}, reusing compiler
39
+ * work between calls.
40
+ */
41
+ export interface GenerationSession {
42
+ /**
43
+ * Generates or checks the application's files, like {@link generate} with the
44
+ * session's options.
45
+ *
46
+ * @remarks
47
+ * Calls must be sequential. A failed call doesn't break the session; the next call
48
+ * starts clean.
49
+ *
50
+ * @param options - `check`: verify without writing. Defaults to `false`.
51
+ * @param stopped - Called once just before writing; returning `true` skips writing and
52
+ * resolves. Defaults to never stopping.
53
+ * @returns A promise that resolves when generation finishes.
54
+ * @throws Rejects when the session is disposed, when another call hasn't settled yet,
55
+ * and for the same failures as {@link generate}.
56
+ */
57
+ generate(options?: Pick<GenerationOptions, "check">, stopped?: () => boolean): Promise<void>;
58
+ /**
59
+ * Disposes the session: stops an active call before it writes, waits for it to settle
60
+ * and makes later calls reject.
61
+ *
62
+ * @returns A promise that resolves once any active call has settled.
63
+ */
64
+ dispose(): Promise<void>;
65
+ }
66
+ /**
67
+ * The builders' session: {@link GenerationSession}, with each call resolving to the locale words
68
+ * that `translateSegments` validated, for the locale table.
69
+ */
70
+ export interface BuilderSession {
71
+ generate(options?: Pick<GenerationOptions, "check">, stopped?: () => boolean): Promise<LocaleWords | undefined>;
72
+ dispose(): Promise<void>;
73
+ }
74
+ interface GenerationCompilerState {
75
+ discovery: CompilerState;
76
+ overlay: CompilerState;
77
+ routerAnchor: AnchorState;
78
+ }
79
+ /**
80
+ * Generation for the builders: {@link generate}, resolving to each non-source locale's text for
81
+ * every route word when `translateSegments` is on, and undefined otherwise.
82
+ */
83
+ export declare function runGeneration(workspace: string, options: GenerationOptions, stopped: () => boolean, compiler?: GenerationCompilerState): Promise<LocaleWords | undefined>;
84
+ /**
85
+ * Generates the router's and Launch's files for an application, or checks them.
86
+ *
87
+ * @remarks
88
+ * Node-only. Generation reads your sources without running them. It writes the router's
89
+ * files, with each route copy carrying its route's `.remote()` metadata and the `Remote`,
90
+ * `Context` and, with `tanstackQuery`, `Queries` types, and `server.generated.ts` in the
91
+ * output directory, which binds every route with a server step. With `translateSegments`,
92
+ * every locale's translated route tree is validated first, static segments become `$localize`
93
+ * messages, `server.generated.ts` first imports Launch's source-text `$localize` for the
94
+ * unlocalized host, and `redirects.generated.ts` holds the word table an application file must
95
+ * import `provideRedirectTranslation()` from. It deletes a marked
96
+ * `rpc.generated.ts` or `context.generated.d.ts` an earlier version wrote. Run it before
97
+ * the Angular build.
98
+ *
99
+ * Everything is validated, including a type check of the generated files with
100
+ * `skipLibCheck: false`, before anything is written, so a failed run changes nothing.
101
+ * Files are then written one at a time without rollback; a write error partway through
102
+ * can leave some files updated, which the next successful run repairs. Generation only
103
+ * replaces or removes files carrying its ownership marker, and removes stale ones.
104
+ *
105
+ * @example
106
+ * ```js
107
+ * import { generate } from "@loozo/angular-launch/generation";
108
+ *
109
+ * await generate(import.meta.dirname, {
110
+ * tsconfig: "tsconfig.app.json",
111
+ * scanDirectories: ["src/routes"],
112
+ * outDirectory: "generated",
113
+ * check: process.argv.includes("--check"),
114
+ * });
115
+ * ```
116
+ *
117
+ * @param workspace - The absolute path of the application directory, which contains
118
+ * its `package.json`. The tsconfig, scanned directory, sources and output directory
119
+ * must all be inside it.
120
+ * @param options - The generation options.
121
+ * @param stopped - Called once just before writing; returning `true` skips writing and
122
+ * resolves. Defaults to never stopping.
123
+ * @returns A promise that resolves when generation finishes.
124
+ * @throws Rejects when a path escapes the workspace, the tsconfig disables strict
125
+ * checking or enables `noCheck`, the application's `package.json` has no `name`, the
126
+ * sources or generated files fail validation, a file to replace lacks the ownership
127
+ * marker, or, with `check`, a generated file is out of date; with `translateSegments`, also
128
+ * when `localization` is missing, the build lacks the `@angular/localize/init` polyfill, a
129
+ * locale's catalog fails the router's checks, or no application file imports
130
+ * `provideRedirectTranslation`.
131
+ */
132
+ export declare function generate(workspace: string, options: GenerationOptions, stopped?: () => boolean): Promise<void>;
133
+ /**
134
+ * Creates a generation session that reuses compiler work between sequential calls.
135
+ *
136
+ * @remarks
137
+ * Node-only. For long-running tools that regenerate repeatedly, such as after file
138
+ * changes. A session doesn't watch files; you decide when to call `generate`. Edits
139
+ * inside the application are picked up by the next call. Create a new session after
140
+ * moving the application directory or changing dependencies. Don't run two sessions or
141
+ * generators against the same output at once.
142
+ *
143
+ * @example
144
+ * ```js
145
+ * const session = createGenerationSession(workspace, {
146
+ * tsconfig: "tsconfig.app.json",
147
+ * scanDirectories: ["src/routes"],
148
+ * outDirectory: "generated",
149
+ * });
150
+ *
151
+ * try {
152
+ * await session.generate();
153
+ * await session.generate({ check: true });
154
+ * } finally {
155
+ * await session.dispose();
156
+ * }
157
+ * ```
158
+ *
159
+ * @param workspace - The absolute path of the application directory, as for
160
+ * {@link generate}.
161
+ * @param options - The generation options, fixed for the session's lifetime; `check` is
162
+ * passed per call instead.
163
+ * @returns The session. Dispose it when done.
164
+ */
165
+ export declare function createGenerationSession(workspace: string, options: Omit<GenerationOptions, "check">): GenerationSession;
166
+ /** {@link createGenerationSession} for the builders, whose calls resolve to the locale words. */
167
+ export declare function createBuilderSession(workspace: string, { tsconfig, scanDirectories, outDirectory, tanstackQuery, translateSegments, localization, }: Omit<GenerationOptions, "check">): BuilderSession;
168
+ export {};