@analogjs/router 2.6.4 → 2.7.0-beta.1
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/fesm2022/analogjs-router-server.mjs +460 -11
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +130 -2
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/package.json +2 -2
- package/types/analogjs-router-server.d.ts +216 -2
- package/types/analogjs-router.d.ts +147 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _angular_core from '@angular/core';
|
|
2
|
-
import { Type, EnvironmentProviders, Injector } from '@angular/core';
|
|
2
|
+
import { Type, EnvironmentProviders, Injector, ResourceRef, InjectionToken } from '@angular/core';
|
|
3
3
|
import * as _angular_router from '@angular/router';
|
|
4
4
|
import { Route, ActivatedRoute, Router, CanActivateFn, DeprecatedGuard, CanActivateChildFn, CanDeactivateFn, CanMatchFn, ResolveFn, RouterFeatures, Routes, ActivatedRouteSnapshot } from '@angular/router';
|
|
5
5
|
import { H3EventContext, H3Event } from 'h3';
|
|
@@ -264,5 +264,149 @@ declare class ServerOnly {
|
|
|
264
264
|
static ɵcmp: _angular_core.ɵɵComponentDeclaration<ServerOnly, "server-only,ServerOnly,Server", never, { "component": { "alias": "component"; "required": true; "isSignal": true; }; "props": { "alias": "props"; "required": false; "isSignal": true; }; }, { "outputs": "outputs"; }, never, never, true, never>;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
/** Minimal Standard Schema shape (valibot/zod/arktype conform). */
|
|
268
|
+
interface StandardSchemaV1<In = unknown> {
|
|
269
|
+
readonly '~standard': {
|
|
270
|
+
readonly version: 1;
|
|
271
|
+
readonly vendor: string;
|
|
272
|
+
validate: (value: unknown) => {
|
|
273
|
+
value: In;
|
|
274
|
+
issues?: undefined;
|
|
275
|
+
} | {
|
|
276
|
+
issues: ReadonlyArray<{
|
|
277
|
+
message: string;
|
|
278
|
+
}>;
|
|
279
|
+
} | Promise<{
|
|
280
|
+
value: In;
|
|
281
|
+
issues?: undefined;
|
|
282
|
+
} | {
|
|
283
|
+
issues: ReadonlyArray<{
|
|
284
|
+
message: string;
|
|
285
|
+
}>;
|
|
286
|
+
}>;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
type ServerFnMethod = 'GET' | 'POST';
|
|
290
|
+
interface ServerFnConfig<In> {
|
|
291
|
+
/**
|
|
292
|
+
* Opaque route id `/_analog/fn/<id>`. **Build-injected, not author-supplied:**
|
|
293
|
+
* the Analog transform derives `hash(fileId + exportName)` and stamps it into
|
|
294
|
+
* both the server registration and the client proxy, so authors never choose a
|
|
295
|
+
* route. Absent at runtime means the transform did not run — `serverFn` throws.
|
|
296
|
+
*/
|
|
297
|
+
id?: string;
|
|
298
|
+
/** Defaults to 'POST' when `input` is present, otherwise 'GET'. */
|
|
299
|
+
method?: ServerFnMethod;
|
|
300
|
+
input?: StandardSchemaV1<In>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Interceptor-accumulated context, delivered to the handler as its second
|
|
304
|
+
* argument. Apps extend this by declaration merging.
|
|
305
|
+
*/
|
|
306
|
+
interface ServerFnContext {
|
|
307
|
+
}
|
|
308
|
+
/** A server function reference: callable type on both sides; real impl only on the server. */
|
|
309
|
+
type ServerFn<In, Out> = ((input: In) => Promise<Out>) & {
|
|
310
|
+
readonly __serverFn: true;
|
|
311
|
+
readonly id: string;
|
|
312
|
+
readonly url: string;
|
|
313
|
+
readonly method: ServerFnMethod;
|
|
314
|
+
};
|
|
315
|
+
type ServerFnHandler<In, Out> = (input: In, context: ServerFnContext) => Promise<Out> | Out;
|
|
316
|
+
interface ServerFnDef {
|
|
317
|
+
id: string;
|
|
318
|
+
method: ServerFnMethod;
|
|
319
|
+
config: ServerFnConfig<unknown>;
|
|
320
|
+
handler: ServerFnHandler<unknown, unknown>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Client transport for server functions. In the browser it goes through Angular
|
|
325
|
+
* `HttpClient`, so client `HttpInterceptorFn`s apply. During SSR the dispatcher
|
|
326
|
+
* token is provided, and the call short-circuits the HTTP round-trip: the
|
|
327
|
+
* handler runs in-process in the current request injector. Lives in the client
|
|
328
|
+
* entry (client-safe).
|
|
329
|
+
*/
|
|
330
|
+
declare class ServerFnClient {
|
|
331
|
+
private readonly http;
|
|
332
|
+
private readonly transferState;
|
|
333
|
+
private readonly injector;
|
|
334
|
+
private readonly dispatcher;
|
|
335
|
+
/** True while rendering on the server (the in-process dispatcher is provided). */
|
|
336
|
+
get isServer(): boolean;
|
|
337
|
+
call<In, Out>(fn: ServerFn<In, Out>, input: In): Promise<Out>;
|
|
338
|
+
/** Key a read's value for TransferState hydration (fn id + input). */
|
|
339
|
+
stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown): _angular_core.StateKey<Out>;
|
|
340
|
+
readSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown): Out | undefined;
|
|
341
|
+
writeSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown, value: Out): void;
|
|
342
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ServerFnClient, never>;
|
|
343
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<ServerFnClient>;
|
|
344
|
+
}
|
|
345
|
+
/** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
|
|
346
|
+
declare function provideServerFnClient(): readonly [];
|
|
347
|
+
/**
|
|
348
|
+
* Reactive read of a server function as an Angular `resource()`.
|
|
349
|
+
*
|
|
350
|
+
* `args` is optional: omit it for an input-less read (the resource loads once);
|
|
351
|
+
* provide it for an input-bearing read (returning `undefined` from `args` leaves
|
|
352
|
+
* the resource idle until inputs are ready, the standard resource pattern). For
|
|
353
|
+
* imperative calls (mutations, event handlers) use `injectServerFnMutation`.
|
|
354
|
+
*/
|
|
355
|
+
declare function injectServerFn<Out>(fn: ServerFn<void, Out>): ResourceRef<Out | undefined>;
|
|
356
|
+
declare function injectServerFn<In, Out>(fn: ServerFn<In, Out>, args: () => In | undefined): ResourceRef<Out | undefined>;
|
|
357
|
+
/**
|
|
358
|
+
* Imperative binding of a server function: returns a callable that dispatches
|
|
359
|
+
* the call through `HttpClient` (so client interceptors apply) and resolves the
|
|
360
|
+
* result. Use for mutations and event-driven calls; use `injectServerFn` for
|
|
361
|
+
* reactive reads.
|
|
362
|
+
*/
|
|
363
|
+
declare function injectServerFnMutation<In, Out>(fn: ServerFn<In, Out>): (input: In) => Promise<Out>;
|
|
364
|
+
|
|
365
|
+
interface ServerFnRefConfig {
|
|
366
|
+
id?: string;
|
|
367
|
+
method?: ServerFnMethod;
|
|
368
|
+
/**
|
|
369
|
+
* Only its presence matters here: when `method` is omitted, a config with an
|
|
370
|
+
* `input` schema defaults to `POST`, otherwise `GET`. The schema itself is
|
|
371
|
+
* never used to build the ref — validation happens server-side.
|
|
372
|
+
*/
|
|
373
|
+
input?: unknown;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Builds a server-function reference: the client-safe `{ __serverFn, id, url,
|
|
377
|
+
* method }` metadata that `injectServerFn`/`ServerFnClient` dispatch through.
|
|
378
|
+
*
|
|
379
|
+
* Shared by both sides so they produce identical refs: the server `serverFn`
|
|
380
|
+
* wraps this with registration + the handler, and the client build's scrub
|
|
381
|
+
* transform emits a call to this factory in place of the server module so the
|
|
382
|
+
* browser bundle carries only the ref, never the handler or its server imports.
|
|
383
|
+
*
|
|
384
|
+
* The returned value is callable-typed but throws if invoked directly — it is
|
|
385
|
+
* always dispatched via `injectServerFn`/`ServerFnClient`, never called.
|
|
386
|
+
*/
|
|
387
|
+
declare function createServerFnRef<In, Out>(config: ServerFnRefConfig): ServerFn<In, Out>;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* In-process transport for a server function call.
|
|
391
|
+
*
|
|
392
|
+
* Provided on the server by `provideServerContext`, so during SSR a server
|
|
393
|
+
* function runs in the same process — and the same request injector — as the
|
|
394
|
+
* render instead of making an HTTP request back into the app. Absent in the
|
|
395
|
+
* browser, where `ServerFnClient` falls back to `HttpClient`.
|
|
396
|
+
*
|
|
397
|
+
* `injector` is the **app environment injector** — `ServerFnClient` is
|
|
398
|
+
* `providedIn: 'root'`, and SSR bootstraps a fresh application per request, so
|
|
399
|
+
* its injector is both per-request and the right scope for a handler to resolve
|
|
400
|
+
* from. It is passed rather than captured from the token because
|
|
401
|
+
* `provideServerContext` is applied as *platform* providers, which sit above
|
|
402
|
+
* the app's `providedIn: 'root'` services.
|
|
403
|
+
*
|
|
404
|
+
* Deliberately not a component's node injector: a handler resolves app-level
|
|
405
|
+
* services, and making that depend on which component happened to call it would
|
|
406
|
+
* be surprising and unportable.
|
|
407
|
+
*/
|
|
408
|
+
type ServerFnDispatcher = <In, Out>(fn: ServerFn<In, Out>, input: In, injector: Injector) => Promise<Out>;
|
|
409
|
+
declare const SERVER_FN_DISPATCHER: InjectionToken<ServerFnDispatcher>;
|
|
410
|
+
|
|
411
|
+
export { FormAction, SERVER_FN_DISPATCHER, ServerFnClient, ServerOnly, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
|
|
412
|
+
export type { Files, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta, ServerFn, ServerFnConfig, ServerFnContext, ServerFnDef, ServerFnDispatcher, ServerFnHandler, ServerFnMethod, ServerFnRefConfig, StandardSchemaV1 };
|