@loozo/angular-launch 0.0.3 → 0.0.5
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 +290 -98
- package/builders/application.d.ts +4 -0
- package/builders/application.js +71 -0
- package/builders/options.d.ts +10 -0
- package/builders/options.js +64 -0
- package/builders/serve.d.ts +8 -0
- package/builders/serve.js +248 -0
- package/builders.json +15 -0
- package/client.d.ts +42 -21
- package/client.js +34 -16
- package/generation/context-file.d.ts +2 -0
- package/generation/context-file.js +3 -0
- package/generation/index.d.ts +8 -1
- package/generation/index.js +75 -38
- package/index.d.ts +1 -0
- package/input-issues.d.ts +56 -0
- package/input-issues.js +78 -0
- package/package.json +21 -3
- package/schemas/application.json +756 -0
- package/schemas/serve.json +153 -0
- package/server/backend.d.ts +3 -3
- package/server/backend.js +19 -8
- package/server/definitions.d.ts +347 -177
- package/server/definitions.js +82 -103
- package/server/dispatch.d.ts +45 -14
- package/server/dispatch.js +212 -73
- package/server/index.d.ts +4 -3
- package/server/index.js +2 -1
- package/server/outcomes.d.ts +26 -0
- package/server/outcomes.js +36 -0
- package/tanstack-query/README.md +164 -0
- package/tanstack-query/generated.d.ts +5 -0
- package/tanstack-query/generated.js +127 -0
- package/tanstack-query/hydration.d.ts +46 -0
- package/tanstack-query/hydration.js +70 -0
- package/tanstack-query/index.d.ts +2 -0
- package/tanstack-query/index.js +1 -0
- package/tanstack-query/queries.d.ts +124 -0
- package/tanstack-query/queries.js +1 -0
package/README.md
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
# @loozo/angular-launch
|
|
2
2
|
|
|
3
|
-
Typed server functions for Angular applications built with [`@loozo/angular-router`](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.
|
|
3
|
+
Typed server functions for Angular applications built with [`@loozo/angular-router`](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-router/README.md). You define queries and mutations in an `rpc.ts` file next to a route, and call them from that route's pages and resolvers through a generated, fully typed client.
|
|
4
4
|
|
|
5
5
|
Calls go through Angular's `HttpClient`. In the browser they're ordinary HTTP requests. During server rendering they run in-process with the current request's context, and hydration reuses their responses through Angular's transfer cache. Errors you declare on a procedure come back typed on the client.
|
|
6
6
|
|
|
7
7
|
Use it when you want typed reads and writes between an Angular SSR app and its own server, without maintaining a separate API layer.
|
|
8
8
|
|
|
9
|
-
**Status:** experimental. MIT license. It currently covers queries, mutations,
|
|
9
|
+
**Status:** experimental. MIT license. It currently covers queries, mutations, middleware and declared errors, with optional [TanStack Query](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md) options and keys, and Angular builders that generate before `ng build` and while `ng serve` runs. There are no subscriptions, optimistic updates, automatic invalidation or storage adapters.
|
|
10
10
|
|
|
11
11
|
## Requirements
|
|
12
12
|
|
|
13
13
|
- Angular 22 with SSR: `@angular/core` and `@angular/common` `^22.0.0` and `rxjs` `^7.8.2` (the peer dependencies), plus `@angular/router`, `@angular/ssr` and `@angular/platform-server` as in the example. Tested with Angular 22.2.2.
|
|
14
|
+
- `@angular/build` `~22.2.0`, for the builders. The range is narrow on purpose: the application builder's options schema is Angular's own at the version Launch was built against, so an option added in a later Angular minor is rejected until Launch is rebuilt against that minor.
|
|
14
15
|
- `@loozo/angular-router` at exactly the version Launch pins in its `peerDependencies`, as a dependency of your app. Launch generation writes the router's files too, through an internal router entry point, so the two must match; the exact peer dependency enforces that.
|
|
15
16
|
- TypeScript 6 with strict checking. Generation rejects a tsconfig where any of `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `strictBuiltinIteratorReturn`, `noImplicitThis` or `useUnknownInCatchVariables` is off, or where `noCheck` is on. `"strict": true` is enough unless a flag is explicitly turned off, including in an extended config. Generation never edits your tsconfig.
|
|
16
17
|
- A `package.json` with a `name` in the application directory. The name is part of the generated app identity.
|
|
18
|
+
- Optionally, `@tanstack/angular-query` `^5.0.0-rc.5` for the [TanStack Query integration](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md).
|
|
17
19
|
|
|
18
20
|
Install both packages:
|
|
19
21
|
|
|
20
22
|
```sh
|
|
21
|
-
pnpm add @loozo/angular-launch @loozo/angular-router@0.0.
|
|
23
|
+
pnpm add @loozo/angular-launch @loozo/angular-router@0.0.6
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
## How it fits together
|
|
@@ -50,11 +52,11 @@ The route tree is the router's. An `rpc.ts` belongs to the route declared in the
|
|
|
50
52
|
|
|
51
53
|
## Setup
|
|
52
54
|
|
|
53
|
-
The [todos example](https://github.com/theo-matzavinos/loozo/tree/angular-launch@0.0.
|
|
55
|
+
The [todos example](https://github.com/theo-matzavinos/loozo/tree/angular-launch@0.0.5/examples/angular-launch) is a complete app, and the snippets below are simplified from it. `db` and `sessions` stand for your own server-only modules: the example uses a test cookie instead of sessions, and its in-memory `db.todos.listForUser` also takes a test-only delay flag.
|
|
54
56
|
|
|
55
57
|
### 1. Define the context
|
|
56
58
|
|
|
57
|
-
One file anywhere in your app's TypeScript sources default-exports `defineContext`. It runs once per live server request and its return value is
|
|
59
|
+
One file anywhere in your app's TypeScript sources default-exports `defineContext`. It runs once per live server request and its return value is the `context` every middleware and handler starts from:
|
|
58
60
|
|
|
59
61
|
```ts
|
|
60
62
|
// src/context.ts
|
|
@@ -75,52 +77,55 @@ Generation registers the awaited return type, so `Context` from `@loozo/angular-
|
|
|
75
77
|
|
|
76
78
|
```ts
|
|
77
79
|
// src/routes/+authenticated/todos/rpc.ts
|
|
78
|
-
import { defineRpc
|
|
79
|
-
import {
|
|
80
|
+
import { defineRpc } from "@loozo/angular-launch/server";
|
|
81
|
+
import { signedIn } from "../../../auth.server";
|
|
80
82
|
import { idSchema, titleSchema } from "../../../todo-input.server";
|
|
81
83
|
|
|
82
84
|
export default defineRpc(
|
|
83
85
|
"todos",
|
|
84
|
-
{
|
|
86
|
+
({ query, mutation }) => ({
|
|
85
87
|
list: query({
|
|
86
|
-
handler: ({ context }) => context.db.todos.listForUser(
|
|
88
|
+
handler: ({ context }) => context.db.todos.listForUser(context.user.id),
|
|
87
89
|
}),
|
|
88
90
|
add: mutation({
|
|
89
91
|
input: titleSchema,
|
|
90
|
-
handler: ({ input, context }) =>
|
|
91
|
-
context.db.todos.addForUser(requireUser(context).id, input.title),
|
|
92
|
+
handler: ({ input, context }) => context.db.todos.addForUser(context.user.id, input.title),
|
|
92
93
|
}),
|
|
93
|
-
},
|
|
94
|
-
{
|
|
94
|
+
}),
|
|
95
|
+
{ use: [signedIn] },
|
|
95
96
|
);
|
|
96
97
|
```
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Generation is a Node function. The example calls it from a small script:
|
|
99
|
+
`signedIn` is a [middleware](#middleware) that refuses calls without a user and narrows `context.user` for the handlers.
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
// generate.mjs
|
|
104
|
-
import { generate } from "@loozo/angular-launch/generation";
|
|
105
|
-
|
|
106
|
-
await generate(import.meta.dirname, {
|
|
107
|
-
tsconfig: "tsconfig.app.json",
|
|
108
|
-
scanDirectories: ["src/routes"],
|
|
109
|
-
outDirectory: "generated",
|
|
110
|
-
check: process.argv.includes("--check"),
|
|
111
|
-
});
|
|
112
|
-
```
|
|
101
|
+
### 3. Generate
|
|
113
102
|
|
|
114
|
-
|
|
103
|
+
Generation runs inside two Angular builders that replace your project's `build` and `serve` builders. Both run Angular's official builders (`@angular/build:application` and `@angular/build:dev-server`) after generating, so everything else about your build stays the same. Use them instead of the router's builders, which don't accept Launch files. In `angular.json`:
|
|
115
104
|
|
|
116
105
|
```json
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
106
|
+
"build": {
|
|
107
|
+
"builder": "@loozo/angular-launch:application",
|
|
108
|
+
"options": {
|
|
109
|
+
"tsconfig": "tsconfig.app.json",
|
|
110
|
+
"scanDirectories": ["src/routes"],
|
|
111
|
+
"outDirectory": "generated",
|
|
112
|
+
"browser": "src/main.ts",
|
|
113
|
+
"server": "src/main.server.ts",
|
|
114
|
+
"ssr": { "entry": "src/server.ts" },
|
|
115
|
+
"outputMode": "server",
|
|
116
|
+
"tsConfig": "tsconfig.app.json"
|
|
117
|
+
},
|
|
118
|
+
"configurations": { "check": { "check": true } }
|
|
119
|
+
},
|
|
120
|
+
"serve": {
|
|
121
|
+
"builder": "@loozo/angular-launch:serve",
|
|
122
|
+
"options": { "buildTarget": "my-app:build" }
|
|
120
123
|
}
|
|
121
124
|
```
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
`ng build` and `ng serve` then generate first, and `ng serve` regenerates as you edit. `ng run my-app:build:check` verifies the generated files without writing them, for CI. `tsconfig` is the TypeScript config generation reads; `tsConfig` is Angular's own compilation config. They can be the same file.
|
|
127
|
+
|
|
128
|
+
Include the generated files, declarations included, in your app tsconfig: `"include": ["src/**/*.ts", "generated/**/*.ts"]`. See [Builders](#builders) for the builder options and [Generation](#generation) for what gets written.
|
|
124
129
|
|
|
125
130
|
### 4. Wire the browser and server apps
|
|
126
131
|
|
|
@@ -170,7 +175,7 @@ export default async function bootstrap(context: BootstrapContext) {
|
|
|
170
175
|
}
|
|
171
176
|
```
|
|
172
177
|
|
|
173
|
-
In the server entry, let `handleRequest` answer RPC requests (it returns `null` for anything else), and render pages with a request scope from `createContext`. This is the Express server that Angular's SSR setup generates, with Launch added:
|
|
178
|
+
In the server entry, let `handleRequest` answer RPC requests (it returns `null` for anything else), and render pages with a request scope from `createContext`. Give `handleRequest` and Angular the same `allowedHosts` list (see [Hosts](#hosts)), and give the web request a signal that aborts when the client goes away (see [Aborted requests](#aborted-requests)). This is the Express server that Angular's SSR setup generates, with Launch added:
|
|
174
179
|
|
|
175
180
|
```ts
|
|
176
181
|
// src/server.ts
|
|
@@ -186,15 +191,27 @@ import express from "express";
|
|
|
186
191
|
import { createContext, handleRequest } from "../generated/server.generated";
|
|
187
192
|
|
|
188
193
|
const browser = join(import.meta.dirname, "../browser");
|
|
189
|
-
|
|
194
|
+
// An explicit list stops Angular reading NG_ALLOWED_HOSTS, so read it here.
|
|
195
|
+
const allowedHosts = (process.env["NG_ALLOWED_HOSTS"] ?? "localhost").split(",");
|
|
196
|
+
const angular = new AngularNodeAppEngine({ allowedHosts });
|
|
190
197
|
const app = express();
|
|
191
198
|
|
|
192
199
|
app.use(express.static(browser, { maxAge: "1y", index: false, redirect: false }));
|
|
193
200
|
|
|
194
201
|
app.use(async (request, response, next) => {
|
|
195
202
|
try {
|
|
196
|
-
|
|
197
|
-
const
|
|
203
|
+
// Angular's helper only aborts while the body is still arriving; abort on a closed response.
|
|
204
|
+
const closed = new AbortController();
|
|
205
|
+
|
|
206
|
+
response.once("close", () => {
|
|
207
|
+
if (!response.writableFinished) {
|
|
208
|
+
closed.abort();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const native = createWebRequestFromNodeRequest(request);
|
|
213
|
+
const web = new Request(native, { signal: AbortSignal.any([native.signal, closed.signal]) });
|
|
214
|
+
const rpc = await handleRequest(web, { allowedHosts });
|
|
198
215
|
|
|
199
216
|
if (rpc) {
|
|
200
217
|
await writeResponseToNodeResponse(rpc, response);
|
|
@@ -238,36 +255,93 @@ Always pass `scope.request` together with `scope`, not your original request. Th
|
|
|
238
255
|
|
|
239
256
|
## Defining RPCs
|
|
240
257
|
|
|
241
|
-
`defineRpc(namespace,
|
|
258
|
+
`defineRpc(namespace, build, options?)` declares a group. `build` receives the `query` (a read) and `mutation` (a write) builders and returns the group's procedures:
|
|
242
259
|
|
|
243
260
|
```ts
|
|
244
|
-
|
|
245
|
-
|
|
261
|
+
defineRpc(
|
|
262
|
+
"todos",
|
|
263
|
+
({ query, mutation }) => ({
|
|
264
|
+
list: query({ input?, use?, errors?, handler }),
|
|
265
|
+
add: mutation({ input?, use?, errors?, handler }),
|
|
266
|
+
}),
|
|
267
|
+
{ use? },
|
|
268
|
+
);
|
|
246
269
|
```
|
|
247
270
|
|
|
248
|
-
The handler receives `{ context, input, errors }` and returns a value or a promise.
|
|
271
|
+
The handler receives `{ context, input, errors, request, signal }` and returns a value or a promise. `request` is the request the call runs in: the RPC request over HTTP, or the page request during server rendering. `signal` aborts when the caller goes away; see [Calling RPCs](#calling-rpcs).
|
|
249
272
|
|
|
250
273
|
- **Namespaces and procedure names** are literal ASCII identifiers. `__proto__` is not allowed; `constructor` and `toString` are fine. One `defineRpc` per route, and each namespace is unique across the app because it names the group's URL.
|
|
251
|
-
- **
|
|
252
|
-
- **
|
|
253
|
-
|
|
274
|
+
- **The callback** is read without running it: an arrow function that destructures `query` and/or `mutation` without renaming, returning a parenthesized object literal in which each procedure is a direct `query(...)` or `mutation(...)` call with inline options.
|
|
275
|
+
- **Inputs** are [Standard Schema](https://standardschema.dev) V1 schemas, from any library or written by hand. Validation can be async and can transform the value: callers pass the schema's input type, and procedure middleware and handlers receive its output. The `input` schema must have a concrete type without `undefined` or `null` branches, though its caller input type may be a union such as `Schema<string | number, …>`. Omit `input` for a procedure without input.
|
|
276
|
+
|
|
277
|
+
Availability isn't authorization: anyone who can reach your server can call any procedure, so protect every group and procedure that needs it with middleware. Route params aren't passed to procedures automatically; pass what you need as input and validate it.
|
|
278
|
+
|
|
279
|
+
### Middleware
|
|
280
|
+
|
|
281
|
+
Middleware runs around a call to refuse it, add typed values to its context, or wrap the rest of it:
|
|
254
282
|
|
|
255
283
|
```ts
|
|
256
284
|
// src/auth.server.ts
|
|
257
|
-
import
|
|
258
|
-
|
|
259
|
-
export const isSignedIn: Guard = ({ context }) => context.user !== null;
|
|
285
|
+
import { forbidden, middleware } from "@loozo/angular-launch/server";
|
|
260
286
|
|
|
261
|
-
export
|
|
287
|
+
export const signedIn = middleware(async ({ context, next }) => {
|
|
262
288
|
if (context.user === null) {
|
|
263
|
-
throw
|
|
289
|
+
throw forbidden();
|
|
264
290
|
}
|
|
265
291
|
|
|
266
|
-
return context.user;
|
|
267
|
-
}
|
|
292
|
+
return next({ user: context.user }); // later middleware and handlers see a non-null user
|
|
293
|
+
});
|
|
268
294
|
```
|
|
269
295
|
|
|
270
|
-
|
|
296
|
+
List middleware in the group's `use` to run it for every procedure in the group, or in a procedure's `use` to run it for that procedure. A call runs, in order:
|
|
297
|
+
|
|
298
|
+
1. the group's middleware, with no input;
|
|
299
|
+
2. input validation;
|
|
300
|
+
3. the procedure's middleware, with the validated input;
|
|
301
|
+
4. the handler.
|
|
302
|
+
|
|
303
|
+
So a caller that group middleware refuses gets `FORBIDDEN` even when its input is invalid, and can't probe your schemas.
|
|
304
|
+
|
|
305
|
+
- **`next()`** continues the call. `next(values)` also merges `values` into the context by spread, so the context must be a plain object: a class instance would lose its prototype. An addition is a single object type with required keys, since a missing optional value would leave the earlier one in place, and a union could hide such a key in one of its members. Write a value that may be missing as `next({ user: maybeUser })` with a type such as `User | null`, and alternatives as a union value, such as `next({ session: a | b })`. Every `next(...)` in a middleware adds the same keys, so `next({ user: null })` in one branch and `next()` in another is a type error. A value that differs per branch goes in one `next()` call with a union-typed value, such as `next({ user: preview ? null : context.user })` or a variable typed `User | null`. The context is read-only at the top level, so `context.user = null` is a type error: add and replace values through `next()`, where later middleware and handlers see their types. A middleware must call `next` exactly once and return its result; calling it twice or returning anything else fails the call with `INTERNAL`.
|
|
306
|
+
- **Wrapping:** `next()` rejects when anything after it throws, declared errors included, so a middleware can time, log or run the rest of the call in a transaction that rolls back:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
export const timing = middleware(async ({ next }) => {
|
|
310
|
+
const start = performance.now();
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
return await next();
|
|
314
|
+
} finally {
|
|
315
|
+
console.log(`RPC took ${(performance.now() - start).toFixed(1)} ms`);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- **Refusing:** `throw forbidden()` fails the call with `FORBIDDEN`; a handler can throw it too. Any other exception fails the call with `INTERNAL`. Declared errors belong to handlers.
|
|
321
|
+
- **Needs:** a middleware without an annotation needs your `Context` and accepts any input, so it fits anywhere. Annotate its argument with `MiddlewareArgs<Needs, Input>` to require values that earlier middleware adds, or an input shape:
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
export const ownTodo = middleware(
|
|
325
|
+
async ({ context, input, next }: MiddlewareArgs<{ user: User; db: Db }, { id: string }>) => {
|
|
326
|
+
const todo = await context.db.todos.findForUser(context.user.id, input.id);
|
|
327
|
+
|
|
328
|
+
if (todo === null) {
|
|
329
|
+
throw forbidden();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return next({ todo });
|
|
333
|
+
},
|
|
334
|
+
);
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Each `use` entry must accept the context and input accumulated before it, and the error lands on the entry that doesn't (`… is not assignable to type 'never'`). Group middleware gets no input, so a middleware that needs input only fits on a procedure.
|
|
338
|
+
|
|
339
|
+
- **Server rendering:** middleware runs for every call, also during server rendering, where `request` is the page request: usually a `GET` navigation with `Sec-Fetch-Site: none` or `cross-site`. Request-shaped checks, such as on the method or `Sec-Fetch-Site`, misfire there, which is why Launch's own [cross-origin check](#cross-origin-requests) isn't middleware and runs over HTTP only.
|
|
340
|
+
- There's no dedupe: middleware listed in both the group and a procedure runs twice. Middleware isn't inherited through the route tree.
|
|
341
|
+
- **Known limits:**
|
|
342
|
+
- Casting an addition to `object` or `{}`, or deliberately widening a middleware's result type, hides the keys it adds, so the context type no longer matches what runs.
|
|
343
|
+
- Only the top level of the context is read-only. Writing to a nested object, such as `context.session.user = null`, can still invalidate a narrowing nested inside it.
|
|
344
|
+
- Separate `next({ user: null })` and `next({ user: context.user })` calls don't infer `User | null` when `context.user` is a `User`; write the single-call form above.
|
|
271
345
|
|
|
272
346
|
### JSON values
|
|
273
347
|
|
|
@@ -284,7 +358,7 @@ complete: mutation({
|
|
|
284
358
|
NOT_FOUND: { status: 404, message: "Todo does not exist", data: idSchema },
|
|
285
359
|
},
|
|
286
360
|
handler: async ({ input, context, errors }) => {
|
|
287
|
-
const todo = await context.db.todos.completeForUser(
|
|
361
|
+
const todo = await context.db.todos.completeForUser(context.user.id, input.id);
|
|
288
362
|
|
|
289
363
|
if (todo === null) {
|
|
290
364
|
throw errors.NOT_FOUND({ id: input.id });
|
|
@@ -299,15 +373,29 @@ Each error needs an identifier code, an integer literal `status` from 400 to 599
|
|
|
299
373
|
|
|
300
374
|
Launch itself uses four codes, which you can't declare:
|
|
301
375
|
|
|
302
|
-
| Code | Status | When
|
|
303
|
-
| --------------- | ------ |
|
|
304
|
-
| `INVALID_INPUT` | 400 |
|
|
305
|
-
| `FORBIDDEN` | 403 |
|
|
306
|
-
| `RPC_NOT_FOUND` | 404 | No such procedure
|
|
307
|
-
| `INTERNAL` | 500 | Anything else: an unexpected exception, an invalid error payload, a non-JSON result
|
|
376
|
+
| Code | Status | When |
|
|
377
|
+
| --------------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
|
|
378
|
+
| `INVALID_INPUT` | 400 | The request is malformed, or its input failed schema validation |
|
|
379
|
+
| `FORBIDDEN` | 403 | `forbidden()` was thrown, the request wasn't proven same-origin, or a mutation was called during server rendering |
|
|
380
|
+
| `RPC_NOT_FOUND` | 404 | No such procedure |
|
|
381
|
+
| `INTERNAL` | 500 | Anything else: an unexpected exception, an invalid error payload, a non-JSON result |
|
|
308
382
|
|
|
309
383
|
`INTERNAL` never exposes details to the client; they go to the server log. Your own `NOT_FOUND` is fine, but `__proto__` can't be an error code.
|
|
310
384
|
|
|
385
|
+
`INVALID_INPUT` has `InvalidInputData`: `{ issues }`, with one `InputIssue` of `{ path, message }` per issue the input schema found, in the schema's order. `path` holds property names and array indexes into the input, such as `["lines", 1, "amount"]`. It's `[]` for the input as a whole, and for an issue whose schema path can't be sent as JSON, such as one with a symbol key. Only messages and paths reach the client, never the received input or other details of the schema library, so write your schema messages for users. A malformed request, such as a body that isn't JSON or an envelope with extra fields, has no issues. Server rendering and HTTP send the same issues. The other three codes have `null` data.
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
try {
|
|
389
|
+
await rpc.todos.add({ title });
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (rpc.todos.add.isError(error) && error.code === "INVALID_INPUT") {
|
|
392
|
+
for (const issue of error.data.issues) {
|
|
393
|
+
showError(issue.path, issue.message); // ["title"], "Title must contain 1–200 characters"
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
311
399
|
## Calling RPCs
|
|
312
400
|
|
|
313
401
|
Each route that has a page or descendants with pages gets an `rpc.generated.ts` with `injectRpc()`, even without its own group; redirect routes don't. Call it in an injection context:
|
|
@@ -341,10 +429,10 @@ await rpc.todos.list({ signal, transferCache: false });
|
|
|
341
429
|
await rpc.todos.add({ title }, { signal });
|
|
342
430
|
```
|
|
343
431
|
|
|
344
|
-
| Option | Effect
|
|
345
|
-
| --------------- |
|
|
346
|
-
| `signal` | Abort the HTTP request; the call rejects with an `AbortError`. The server
|
|
347
|
-
| `transferCache` | Queries default to `true`. Mutations only accept `false` and never use the transfer cache.
|
|
432
|
+
| Option | Effect |
|
|
433
|
+
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
434
|
+
| `signal` | Abort the HTTP request; the call rejects with an `AbortError`. The server's middleware and handler see their `signal` abort, but aborting is advisory: work that ignores it finishes, and a write may already have committed. |
|
|
435
|
+
| `transferCache` | Queries default to `true`. Mutations only accept `false` and never use the transfer cache. |
|
|
348
436
|
|
|
349
437
|
`isError(error)` is true only for errors returned by that exact procedure, and narrows them to its declared errors plus the four framework codes. Network failures and aborts are not `RpcError`s. For a type, use `ClientRpcError<typeof group.procedures.complete>` from `@loozo/angular-launch`. Each callable also has a literal `kind` of `"query"` or `"mutation"`.
|
|
350
438
|
|
|
@@ -359,7 +447,6 @@ import { injectRpc } from "./rpc.generated";
|
|
|
359
447
|
export default defineRoute("todos", {
|
|
360
448
|
parent,
|
|
361
449
|
resolve: {
|
|
362
|
-
todos: () => injectRpc().todos.list(),
|
|
363
450
|
session: () => injectRpc().session.current(),
|
|
364
451
|
},
|
|
365
452
|
});
|
|
@@ -367,9 +454,13 @@ export default defineRoute("todos", {
|
|
|
367
454
|
|
|
368
455
|
`Client<typeof group>` from `@loozo/angular-launch` gives you the client type for a group, for example to type a result: `Awaited<ReturnType<Client<typeof group>["list"]>>`. Import the group with `import type` so server code stays out of the browser bundle.
|
|
369
456
|
|
|
457
|
+
### With TanStack Query
|
|
458
|
+
|
|
459
|
+
With the `tanstackQuery` generation option, each `rpc.generated.ts` also exports `injectQueries()`: typed query and mutation options and keys for the same groups, for `@tanstack/angular-query`. See the [TanStack Query guide](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md) for setup, keys, invalidation and hydration.
|
|
460
|
+
|
|
370
461
|
## Server rendering and hydration
|
|
371
462
|
|
|
372
|
-
During server rendering, calls run directly on the server with the context created for that page request. Queries are stored in Angular's HTTP transfer cache, so hydration reuses the responses instead of calling the server again. After the app is stable, calls are ordinary HTTP requests, each with a fresh context. Opt a query out with `{ transferCache: false }`.
|
|
463
|
+
During server rendering, calls run directly on the server with the context created for that page request. Queries are stored in Angular's HTTP transfer cache, so hydration reuses the responses instead of calling the server again. After the app is stable, calls are ordinary HTTP requests, each with a fresh context. Opt a query out with `{ transferCache: false }`. Queries run through [TanStack Query](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md) opt out and are transferred by TanStack instead.
|
|
373
464
|
|
|
374
465
|
The reuse has limits, all of them Angular's transfer cache behaving as designed:
|
|
375
466
|
|
|
@@ -377,7 +468,9 @@ The reuse has limits, all of them Angular's transfer cache behaving as designed:
|
|
|
377
468
|
- The cache serves calls made before the app first becomes stable. RPCs called later, for example from a `@defer` block that hydrates on interaction or when it enters the viewport, go over HTTP.
|
|
378
469
|
- Launch relies on your app's transfer cache settings. `withNoHttpTransferCache()`, or a `withHttpTransferCacheOptions` `filter` that rejects `/_rpc/` requests, turns reuse off without any error, and every query runs again in the browser.
|
|
379
470
|
|
|
380
|
-
Mutations are refused during server rendering with `FORBIDDEN`, before
|
|
471
|
+
Mutations are refused during server rendering with `FORBIDDEN`, before any middleware, validation or the handler runs. Rendering should only read.
|
|
472
|
+
|
|
473
|
+
Middleware and handlers run during server rendering too, with the page request as `request`. Their `signal` aborts when the page request aborts, or when `HttpClient` unsubscribes from the call before it settled.
|
|
381
474
|
|
|
382
475
|
RPCs need a live request. Prerendering a page that calls an RPC fails the build (with `finishLaunchRendering` in place); static pages that don't call RPCs prerender normally. Blocking initial navigation (`withEnabledBlockingInitialNavigation`) combined with a root resolver that calls an RPC isn't supported.
|
|
383
476
|
|
|
@@ -399,24 +492,94 @@ Copy `dist/<app>` to the host and start the server with Node:
|
|
|
399
492
|
PORT=8080 NG_ALLOWED_HOSTS=example.com node dist/<app>/server/server.mjs
|
|
400
493
|
```
|
|
401
494
|
|
|
402
|
-
The server bundle includes your dependencies by default, so the host doesn't need `node_modules`.
|
|
403
|
-
|
|
404
|
-
| Variable | Effect |
|
|
405
|
-
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
406
|
-
| `NG_ALLOWED_HOSTS` | Comma-separated hostnames allowed to render pages, in addition to `security.allowedHosts` in `angular.json`. Pages for other hosts get a 400. |
|
|
407
|
-
| `NG_TRUST_PROXY_HEADERS` | Comma-separated `Forwarded` and `X-Forwarded-*` headers that Angular should trust. Set it only behind a proxy that overwrites those headers. Off by default. |
|
|
495
|
+
The server bundle includes your dependencies by default, so the host doesn't need `node_modules`. The server reads two environment variables:
|
|
408
496
|
|
|
409
|
-
|
|
497
|
+
| Variable | Effect |
|
|
498
|
+
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
499
|
+
| `NG_ALLOWED_HOSTS` | Comma-separated hostnames allowed for pages and RPCs. The server entry above reads it and passes the list to both; it defaults to `localhost` there. Other hosts get a 400. |
|
|
500
|
+
| `NG_TRUST_PROXY_HEADERS` | Read by `AngularNodeAppEngine`: comma-separated `Forwarded` and `X-Forwarded-*` headers that Angular should trust. Set it only behind a proxy that overwrites those headers. Off by default. |
|
|
410
501
|
|
|
411
502
|
Launch calls `/_rpc/<namespace>/<procedure>` from the root of the domain, even when the app has a different `<base href>`. If the app is served under a path prefix, route `/_rpc/` to the same server.
|
|
412
503
|
|
|
413
504
|
Browser tabs opened before a deploy keep calling the procedures they were built with. After you rename a namespace or procedure, or change an input schema, those calls fail with `RPC_NOT_FOUND` or `INVALID_INPUT` until the page reloads. The same applies while old and new servers run side by side during a rolling deploy.
|
|
414
505
|
|
|
415
|
-
Launch has been verified on Node
|
|
506
|
+
Launch has been verified on Node, and with a platform-neutral server build (below) on Deno and Cloudflare's workerd, run locally.
|
|
507
|
+
|
|
508
|
+
### Hosts
|
|
509
|
+
|
|
510
|
+
`handleRequest` checks the hostname of the request URL before anything else, matching `allowedHosts` the way Angular does: exactly, `*.example.com` for subdomains only, or `*` for any host. RPCs for other hosts get a plain-text 400 `Host not allowed`, as Angular answers pages, and the hostname is logged. An empty list refuses every RPC.
|
|
511
|
+
|
|
512
|
+
Passing `allowedHosts` to `AngularNodeAppEngine` replaces its own read of `NG_ALLOWED_HOSTS`, which is why the server entry reads the variable itself. `security.allowedHosts` in `angular.json` still applies to pages only: Angular builds it into an internal manifest that `handleRequest` can't read, so list RPC hosts in the server entry. Under `ng serve`, Vite's host check covers `/_rpc/` as well.
|
|
513
|
+
|
|
514
|
+
### Cross-origin requests
|
|
515
|
+
|
|
516
|
+
`handleRequest` answers only RPCs it can prove come from the app's own origin. The rest get `FORBIDDEN` (403), logged with the reason, before a context is created:
|
|
517
|
+
|
|
518
|
+
1. An `Origin` listed in `origins` passes.
|
|
519
|
+
2. Otherwise, if the request has `Sec-Fetch-Site`, it must be `same-origin`. `same-site` (a sibling subdomain), `cross-site` and `none` are refused.
|
|
520
|
+
3. Otherwise, if it has `Origin`, that must equal the request URL's origin.
|
|
521
|
+
4. A request with neither header is refused. There's no `Referer` fallback and no opt-out.
|
|
522
|
+
|
|
523
|
+
Launch's browser client always sends one of the two headers. curl, scripts, Node's `fetch` and server-to-server callers send neither, so they must send `Origin` with the app's origin. Browsers send `Sec-Fetch-Site` only to HTTPS and `localhost`, so a plain-HTTP deployment on any other hostname relies on `Origin` matching the request URL. Behind a proxy that rewrites `Host`, that URL isn't the public one, and those calls are refused until you list the public origin:
|
|
524
|
+
|
|
525
|
+
```ts
|
|
526
|
+
const rpc = await handleRequest(web, { allowedHosts, origins: ["https://app.example.com"] });
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
List a sibling site's origin the same way to let it call. Only HTTP requests are checked: calls made during server rendering carry the page request, whose `Sec-Fetch-Site` is `cross-site` or `none` on an ordinary navigation, and run without these checks.
|
|
530
|
+
|
|
531
|
+
### Other runtimes
|
|
532
|
+
|
|
533
|
+
`ng build` can also write a server bundle that doesn't depend on Node, for edge and serverless platforms: set `"platform": "neutral"` in the build target's `ssr` option, next to `entry`. Launch's server code uses only web `Request` and `Response`, so only your server entry changes:
|
|
534
|
+
|
|
535
|
+
```ts
|
|
536
|
+
// src/server.ts
|
|
537
|
+
import { AngularAppEngine, createRequestHandler } from "@angular/ssr";
|
|
538
|
+
import { createContext, handleRequest } from "../generated/server.generated";
|
|
539
|
+
|
|
540
|
+
const allowedHosts = ["app.example.com"];
|
|
541
|
+
const angular = new AngularAppEngine({ allowedHosts });
|
|
542
|
+
|
|
543
|
+
export const reqHandler = createRequestHandler(async (request: Request) => {
|
|
544
|
+
const rpc = await handleRequest(request, { allowedHosts });
|
|
545
|
+
|
|
546
|
+
if (rpc) {
|
|
547
|
+
return rpc;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const scope = await createContext(request);
|
|
551
|
+
const page = await angular.handle(scope.request, scope);
|
|
552
|
+
|
|
553
|
+
return page ?? new Response("Not found", { status: 404 });
|
|
554
|
+
});
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
- Import from `@angular/ssr`, not `@angular/ssr/node`. `AngularAppEngine` doesn't read `NG_ALLOWED_HOSTS` or `NG_TRUST_PROXY_HEADERS`: pass `allowedHosts`, and `trustProxyHeaders` if you're behind a proxy (it's off by default), to its constructor, and the same hosts to `handleRequest`. List them in the entry as above, or read them from your platform's configuration.
|
|
558
|
+
- The bundle neither serves the `browser` files nor starts a server. Point your platform's static hosting at `dist/<app>/browser` and its request handler at the exported `reqHandler`.
|
|
559
|
+
- Nothing polyfills Node modules for you, so your context, handlers and their dependencies must run on the platform. In-memory state lasts only as long as the platform keeps an instance alive.
|
|
560
|
+
|
|
561
|
+
### Aborted requests
|
|
562
|
+
|
|
563
|
+
Launch passes `request.signal` on to middleware and handlers as `signal`. Angular's `createWebRequestFromNodeRequest` gives a signal that only aborts while the request body is still arriving, so by the time an RPC handler runs, a client that disconnects no longer aborts it. That's why the server entry above links a signal that aborts when the Node response closes before it finished:
|
|
564
|
+
|
|
565
|
+
```ts
|
|
566
|
+
const closed = new AbortController();
|
|
567
|
+
|
|
568
|
+
response.once("close", () => {
|
|
569
|
+
if (!response.writableFinished) {
|
|
570
|
+
closed.abort();
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
const native = createWebRequestFromNodeRequest(request);
|
|
575
|
+
const web = new Request(native, { signal: AbortSignal.any([native.signal, closed.signal]) });
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Pass `web` to both `handleRequest` and `createContext`, so page renders get the same signal. Without this wiring everything works, but handlers never see an abort over HTTP.
|
|
416
579
|
|
|
417
580
|
### Other server frameworks
|
|
418
581
|
|
|
419
|
-
`handleRequest` and `createContext` take a web `Request`, so any framework that gives you one works. `AngularNodeAppEngine` also accepts a web `Request
|
|
582
|
+
`handleRequest` and `createContext` take a web `Request`, so any framework that gives you one works. `AngularNodeAppEngine` also accepts a web `Request`. With [Hono](https://hono.dev) on Node:
|
|
420
583
|
|
|
421
584
|
```ts
|
|
422
585
|
// src/server.ts
|
|
@@ -429,13 +592,15 @@ import { Hono } from "hono";
|
|
|
429
592
|
import { createContext, handleRequest } from "../generated/server.generated";
|
|
430
593
|
|
|
431
594
|
const browser = fileURLToPath(new URL("../browser", import.meta.url));
|
|
432
|
-
|
|
595
|
+
// An explicit list stops Angular reading NG_ALLOWED_HOSTS, so read it here.
|
|
596
|
+
const allowedHosts = (process.env["NG_ALLOWED_HOSTS"] ?? "localhost").split(",");
|
|
597
|
+
const angular = new AngularNodeAppEngine({ allowedHosts });
|
|
433
598
|
const app = new Hono();
|
|
434
599
|
|
|
435
600
|
app.use("*", serveStatic({ root: browser }));
|
|
436
601
|
|
|
437
602
|
app.all("*", async (c) => {
|
|
438
|
-
const rpc = await handleRequest(c.req.raw);
|
|
603
|
+
const rpc = await handleRequest(c.req.raw, { allowedHosts });
|
|
439
604
|
|
|
440
605
|
if (rpc) {
|
|
441
606
|
return rpc;
|
|
@@ -458,30 +623,33 @@ if (isMainModule(import.meta.url)) {
|
|
|
458
623
|
export const reqHandler = createRequestHandler(app.fetch);
|
|
459
624
|
```
|
|
460
625
|
|
|
461
|
-
Export the handler as `reqHandler`; Angular's dev server and build don't look for a default export. Under `ng serve`, `serveStatic` logs that the `browser` directory doesn't exist. That's expected: the dev server serves those files itself.
|
|
626
|
+
Export the handler as `reqHandler`; Angular's dev server and build don't look for a default export. Whether `@hono/node-server` aborts `c.req.raw.signal` when a client disconnects is unverified, so don't rely on handlers seeing an abort there. Under `ng serve`, `serveStatic` logs that the `browser` directory doesn't exist. That's expected: the dev server serves those files itself.
|
|
462
627
|
|
|
463
628
|
## Generation
|
|
464
629
|
|
|
630
|
+
The [builders](#builders) run generation for you. Underneath, it's a Node function you can also call from your own tools:
|
|
631
|
+
|
|
465
632
|
```ts
|
|
466
633
|
generate(workspace: string, options: GenerationOptions, stopped?: () => boolean): Promise<void>;
|
|
467
634
|
```
|
|
468
635
|
|
|
469
|
-
| Option | Type | Description
|
|
470
|
-
| ----------------- | ---------- |
|
|
471
|
-
| `tsconfig` | `string` | Your app tsconfig, relative to `workspace`
|
|
472
|
-
| `scanDirectories` | `string[]` | Exactly one route directory, relative to the tsconfig's directory
|
|
473
|
-
| `outDirectory` | `string` | Where the app-wide generated files go, relative to `workspace`
|
|
474
|
-
| `
|
|
636
|
+
| Option | Type | Description |
|
|
637
|
+
| ----------------- | ---------- | ------------------------------------------------------------------------------- |
|
|
638
|
+
| `tsconfig` | `string` | Your app tsconfig, relative to `workspace` |
|
|
639
|
+
| `scanDirectories` | `string[]` | Exactly one route directory, relative to the tsconfig's directory |
|
|
640
|
+
| `outDirectory` | `string` | Where the app-wide generated files go, relative to `workspace` |
|
|
641
|
+
| `tanstackQuery` | `boolean` | Also generate `injectQueries()`; see [TanStack Query](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md) |
|
|
642
|
+
| `check` | `boolean` | Verify generated files without writing them; fails if anything is out of date |
|
|
475
643
|
|
|
476
644
|
`workspace` is the absolute path of the application directory (the one with its `package.json`). The tsconfig, scan directory and output directory must all be inside it. `stopped` lets a caller cancel: if it returns `true` before writing starts, nothing is written.
|
|
477
645
|
|
|
478
646
|
Generation reads your source without running it. It writes the router's files plus:
|
|
479
647
|
|
|
480
|
-
| File | Contents
|
|
481
|
-
| --------------------------------------- |
|
|
482
|
-
| `rpc.generated.ts` beside each route | `injectRpc()` with the route's own and ancestor groups
|
|
483
|
-
| `<outDirectory>/context.generated.d.ts` | Registers your context type
|
|
484
|
-
| `<outDirectory>/server.generated.ts` | `createContext`, `handleRequest`, `provideServer`, the registry
|
|
648
|
+
| File | Contents |
|
|
649
|
+
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
650
|
+
| `rpc.generated.ts` beside each route | `injectRpc()` with the route's own and ancestor groups, plus `injectQueries()` with `tanstackQuery`; none for redirect routes |
|
|
651
|
+
| `<outDirectory>/context.generated.d.ts` | Registers your context type |
|
|
652
|
+
| `<outDirectory>/server.generated.ts` | `createContext`, `handleRequest`, `provideServer`, the registry |
|
|
485
653
|
|
|
486
654
|
Each file starts with an ownership marker comment. Generation only replaces or removes files with those exact names and markers, fails rather than overwrite an unmarked file or a symlink in their place, and removes stale ones. Unchanged files aren't rewritten. Everything is validated before anything is written, so a run that fails validation changes nothing. Files are then written one at a time, with no rollback: a write error partway through, such as an unwritable file, or an interrupted run can leave some files updated and others not. The next successful run repairs them.
|
|
487
655
|
|
|
@@ -491,10 +659,33 @@ Generated browser code contains only names, kinds and error metadata, never your
|
|
|
491
659
|
|
|
492
660
|
`server.generated.ts` binds Launch's internal `createRequestScope`, `handleRpc` and `provideLaunchServer` to your app. It imports them from `@loozo/angular-launch/_server`, an entry point for generated code only that isn't public API and can change in any release; use the generated functions instead. The app identity comes from the `package.json` name, the generation tsconfig's path within the app, and the context file's path and contents, so moving the whole app directory doesn't change it.
|
|
493
661
|
|
|
494
|
-
RPC URLs are `/_rpc/<namespace>/<procedure>`, so they change only when you rename a namespace or procedure. Moving an `rpc.ts` or the generation tsconfig doesn't change them. The example doesn't commit generated files:
|
|
662
|
+
RPC URLs are `/_rpc/<namespace>/<procedure>`, so they change only when you rename a namespace or procedure. Moving an `rpc.ts` or the generation tsconfig doesn't change them. The example doesn't commit generated files: every build regenerates them, and its `check` configuration (`ng run todos:build:check`) verifies them without writing.
|
|
495
663
|
|
|
496
664
|
`@loozo/angular-launch/generation` is Node-only.
|
|
497
665
|
|
|
666
|
+
### Builders
|
|
667
|
+
|
|
668
|
+
#### `@loozo/angular-launch:application`
|
|
669
|
+
|
|
670
|
+
All `@angular/build:application` options, plus the generation options above (`tsconfig`, `scanDirectories`, `outDirectory`, `tanstackQuery` and `check`, which default to `false`). It takes those out and passes every other option through unchanged.
|
|
671
|
+
|
|
672
|
+
The builder runs generation once, then the official application build. Invalid options stop the build before generation starts. Generation errors, including drift with `check: true`, are logged and fail the build before the Angular build runs. `watch: true` is rejected; use the serve builder for watching.
|
|
673
|
+
|
|
674
|
+
#### `@loozo/angular-launch:serve`
|
|
675
|
+
|
|
676
|
+
All `@angular/build:dev-server` options, set in `angular.json` or on the command line (`ng serve --port 4300`), plus:
|
|
677
|
+
|
|
678
|
+
| Option | Type | Default | Description |
|
|
679
|
+
| ------------- | ----------------- | -------- | ---------------------------------------------------------------------------------------- |
|
|
680
|
+
| `buildTarget` | `string` | required | A target that uses `@loozo/angular-launch:application`. Generation options come from it. |
|
|
681
|
+
| `poll` | `number \| false` | `1000` | The dev server's file-watch polling interval in milliseconds, or `false` for no default. |
|
|
682
|
+
|
|
683
|
+
Invalid options stop the serve builder before it generates anything, and so does an invalid build target. The build target must not resolve `check: true`, because serving always writes generated files. The initial generation must succeed before the dev server starts; if it fails, the error is logged and the builder reports a failed build.
|
|
684
|
+
|
|
685
|
+
The builder then watches the scan directory and the context file, wherever the last generation found it, and regenerates when files are added, changed or removed there. A pass starts once changes have been quiet for 150 ms, so saving several files at once or renaming a directory runs one pass. Passes run one at a time; changes during a pass cause one more. A failed pass is logged and the server keeps running; the next change retries. When it starts watching a context file outside the scan directory, it runs one more pass once that watch is live, so an edit made while the file was being found isn't lost. A plain rename of the context file is followed, but a move that passes through a missing or broken context, such as delete-then-create or a file that's broken at its new path, is picked up only on the next change in the scan directory or a restart. Other files, such as a module your context imports, don't trigger generation; Angular's build still checks them.
|
|
686
|
+
|
|
687
|
+
Polling is on by default because Angular 22.2.2's native file watcher misses edits to files inside a renamed directory, which leaves the dev server serving stale output. It costs some idle CPU. Set `"poll": false` in the serve target to go back to native file events; Angular's own configuration then applies, including a `poll` on the build target. A positive number overrides the build target's `poll`; `0` is rejected. On the command line, `--poll` accepts milliseconds only. `poll` configures Angular's dev-server watcher; Launch's own watcher uses native file events.
|
|
688
|
+
|
|
498
689
|
### Generation sessions
|
|
499
690
|
|
|
500
691
|
`generate` starts from scratch on every call. A long-running tool that regenerates repeatedly (for example, after file changes) can create a session instead, which reuses compiler work between calls:
|
|
@@ -522,26 +713,27 @@ The options are fixed when the session is created. Edits inside the app, includi
|
|
|
522
713
|
|
|
523
714
|
## Limitations
|
|
524
715
|
|
|
525
|
-
- No
|
|
526
|
-
- No subscriptions, optimistic updates, automatic invalidation, or query cache beyond hydration.
|
|
716
|
+
- No subscriptions, optimistic updates or automatic invalidation. Beyond hydration, the only query cache is TanStack Query's, through the optional [integration](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md#limitations), which has its own limitations.
|
|
527
717
|
- No storage adapters; persistence is your handler's job.
|
|
528
|
-
- No production authentication,
|
|
529
|
-
-
|
|
718
|
+
- No production authentication, CORS or caching policy. You provide those. Cross-origin RPCs are refused (see [Cross-origin requests](#cross-origin-requests)); there's no CSRF token scheme.
|
|
719
|
+
- Aborting is advisory: handlers get a `signal`, but work that ignores it finishes, a write may already have committed, and nothing is rolled back.
|
|
720
|
+
- Middleware is server-side only: there's no client middleware (use an Angular HTTP interceptor), and no dedupe of middleware listed twice.
|
|
530
721
|
- One RPC group per route, and one context per application.
|
|
531
722
|
|
|
532
723
|
## Further reading
|
|
533
724
|
|
|
534
|
-
- [
|
|
535
|
-
- [`
|
|
536
|
-
- [
|
|
725
|
+
- [TanStack Query](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-launch/tanstack-query/README.md): the optional query and mutation integration
|
|
726
|
+
- [`specs/angular-launch.md`](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/specs/angular-launch.md): design and full contract
|
|
727
|
+
- [`examples/angular-launch`](https://github.com/theo-matzavinos/loozo/tree/angular-launch@0.0.5/examples/angular-launch): the todos app. Its cookie identity and in-memory database are test fixtures, not security or deployment guidance.
|
|
728
|
+
- [`@loozo/angular-router`](https://github.com/theo-matzavinos/loozo/blob/angular-launch@0.0.5/packages/angular-router/README.md): routes, codecs and navigation
|
|
537
729
|
|
|
538
730
|
## Developing this package
|
|
539
731
|
|
|
540
732
|
```sh
|
|
541
|
-
pnpm run build # tsc
|
|
733
|
+
pnpm run build # builder schemas, then tsc
|
|
542
734
|
pnpm run typecheck
|
|
543
735
|
pnpm run test # node --test
|
|
544
736
|
node tests/packed.mjs /absolute/new-directory # packed consumer check; directory must not exist
|
|
545
737
|
```
|
|
546
738
|
|
|
547
|
-
The packed check keeps its consumer, pnpm store and temporary files inside the directory you pass.
|
|
739
|
+
The packed check keeps its consumer, pnpm store and temporary files inside the directory you pass. The build regenerates the builder schemas in `schemas/` from the installed `@angular/build`; `tests/schema.test.mjs` fails when a committed schema is stale.
|