@analogjs/router 2.6.4 → 2.7.0-beta.2

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.
@@ -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';
@@ -8,7 +8,6 @@ import * as rxjs from 'rxjs';
8
8
  import { Observable } from 'rxjs';
9
9
  import * as _angular_common_http from '@angular/common/http';
10
10
  import { HttpRequest, HttpHandlerFn } from '@angular/common/http';
11
- import { SafeHtml } from '@angular/platform-browser';
12
11
 
13
12
  type RouteOmitted = 'component' | 'loadComponent' | 'loadChildren' | 'path' | 'pathMatch';
14
13
  type RestrictedRoute = Omit<Route, RouteOmitted>;
@@ -234,35 +233,149 @@ declare function withDebugRoutes(): {
234
233
  }[];
235
234
  };
236
235
 
237
- type ServerProps = Record<string, any>;
238
- type ServerOutputs = Record<string, any>;
236
+ /** Minimal Standard Schema shape (valibot/zod/arktype conform). */
237
+ interface StandardSchemaV1<In = unknown> {
238
+ readonly '~standard': {
239
+ readonly version: 1;
240
+ readonly vendor: string;
241
+ validate: (value: unknown) => {
242
+ value: In;
243
+ issues?: undefined;
244
+ } | {
245
+ issues: ReadonlyArray<{
246
+ message: string;
247
+ }>;
248
+ } | Promise<{
249
+ value: In;
250
+ issues?: undefined;
251
+ } | {
252
+ issues: ReadonlyArray<{
253
+ message: string;
254
+ }>;
255
+ }>;
256
+ };
257
+ }
258
+ type ServerFnMethod = 'GET' | 'POST';
259
+ interface ServerFnConfig<In> {
260
+ /**
261
+ * Opaque route id `/_analog/fn/<id>`. **Build-injected, not author-supplied:**
262
+ * the Analog transform derives `hash(fileId + exportName)` and stamps it into
263
+ * both the server registration and the client proxy, so authors never choose a
264
+ * route. Absent at runtime means the transform did not run — `serverFn` throws.
265
+ */
266
+ id?: string;
267
+ /** Defaults to 'POST' when `input` is present, otherwise 'GET'. */
268
+ method?: ServerFnMethod;
269
+ input?: StandardSchemaV1<In>;
270
+ }
239
271
  /**
240
- * @description
241
- * Component that defines the bridge between the client and server-only
242
- * components. The component passes the component ID and props to the server
243
- * and retrieves the rendered HTML and outputs from the server-only component.
272
+ * Interceptor-accumulated context, delivered to the handler as its second
273
+ * argument. Apps extend this by declaration merging.
274
+ */
275
+ interface ServerFnContext {
276
+ }
277
+ /** A server function reference: callable type on both sides; real impl only on the server. */
278
+ type ServerFn<In, Out> = ((input: In) => Promise<Out>) & {
279
+ readonly __serverFn: true;
280
+ readonly id: string;
281
+ readonly url: string;
282
+ readonly method: ServerFnMethod;
283
+ };
284
+ type ServerFnHandler<In, Out> = (input: In, context: ServerFnContext) => Promise<Out> | Out;
285
+ interface ServerFnDef {
286
+ id: string;
287
+ method: ServerFnMethod;
288
+ config: ServerFnConfig<unknown>;
289
+ handler: ServerFnHandler<unknown, unknown>;
290
+ }
291
+
292
+ /**
293
+ * Client transport for server functions. In the browser it goes through Angular
294
+ * `HttpClient`, so client `HttpInterceptorFn`s apply. During SSR the dispatcher
295
+ * token is provided, and the call short-circuits the HTTP round-trip: the
296
+ * handler runs in-process in the current request injector. Lives in the client
297
+ * entry (client-safe).
298
+ */
299
+ declare class ServerFnClient {
300
+ private readonly http;
301
+ private readonly transferState;
302
+ private readonly injector;
303
+ private readonly dispatcher;
304
+ /** True while rendering on the server (the in-process dispatcher is provided). */
305
+ get isServer(): boolean;
306
+ call<In, Out>(fn: ServerFn<In, Out>, input: In): Promise<Out>;
307
+ /** Key a read's value for TransferState hydration (fn id + input). */
308
+ stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown): _angular_core.StateKey<Out>;
309
+ readSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown): Out | undefined;
310
+ writeSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown, value: Out): void;
311
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ServerFnClient, never>;
312
+ static ɵprov: _angular_core.ɵɵInjectableDeclaration<ServerFnClient>;
313
+ }
314
+ /** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
315
+ declare function provideServerFnClient(): readonly [];
316
+ /**
317
+ * Reactive read of a server function as an Angular `resource()`.
244
318
  *
245
- * Status: experimental
319
+ * `args` is optional: omit it for an input-less read (the resource loads once);
320
+ * provide it for an input-bearing read (returning `undefined` from `args` leaves
321
+ * the resource idle until inputs are ready, the standard resource pattern). For
322
+ * imperative calls (mutations, event handlers) use `injectServerFnMutation`.
246
323
  */
247
- declare class ServerOnly {
248
- component: _angular_core.InputSignal<string>;
249
- props: _angular_core.InputSignal<ServerProps | undefined>;
250
- outputs: _angular_core.OutputEmitterRef<ServerOutputs>;
251
- private http;
252
- private sanitizer;
253
- protected content: _angular_core.WritableSignal<SafeHtml>;
254
- private route;
255
- private baseURL;
256
- private transferState;
257
- constructor();
258
- updateContent(content: {
259
- html: string;
260
- outputs: ServerOutputs;
261
- }): void;
262
- getComponentUrl(componentId: string): string;
263
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<ServerOnly, never>;
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>;
324
+ declare function injectServerFn<Out>(fn: ServerFn<void, Out>): ResourceRef<Out | undefined>;
325
+ declare function injectServerFn<In, Out>(fn: ServerFn<In, Out>, args: () => In | undefined): ResourceRef<Out | undefined>;
326
+ /**
327
+ * Imperative binding of a server function: returns a callable that dispatches
328
+ * the call through `HttpClient` (so client interceptors apply) and resolves the
329
+ * result. Use for mutations and event-driven calls; use `injectServerFn` for
330
+ * reactive reads.
331
+ */
332
+ declare function injectServerFnMutation<In, Out>(fn: ServerFn<In, Out>): (input: In) => Promise<Out>;
333
+
334
+ interface ServerFnRefConfig {
335
+ id?: string;
336
+ method?: ServerFnMethod;
337
+ /**
338
+ * Only its presence matters here: when `method` is omitted, a config with an
339
+ * `input` schema defaults to `POST`, otherwise `GET`. The schema itself is
340
+ * never used to build the ref — validation happens server-side.
341
+ */
342
+ input?: unknown;
265
343
  }
344
+ /**
345
+ * Builds a server-function reference: the client-safe `{ __serverFn, id, url,
346
+ * method }` metadata that `injectServerFn`/`ServerFnClient` dispatch through.
347
+ *
348
+ * Shared by both sides so they produce identical refs: the server `serverFn`
349
+ * wraps this with registration + the handler, and the client build's scrub
350
+ * transform emits a call to this factory in place of the server module so the
351
+ * browser bundle carries only the ref, never the handler or its server imports.
352
+ *
353
+ * The returned value is callable-typed but throws if invoked directly — it is
354
+ * always dispatched via `injectServerFn`/`ServerFnClient`, never called.
355
+ */
356
+ declare function createServerFnRef<In, Out>(config: ServerFnRefConfig): ServerFn<In, Out>;
357
+
358
+ /**
359
+ * In-process transport for a server function call.
360
+ *
361
+ * Provided on the server by `provideServerContext`, so during SSR a server
362
+ * function runs in the same process — and the same request injector — as the
363
+ * render instead of making an HTTP request back into the app. Absent in the
364
+ * browser, where `ServerFnClient` falls back to `HttpClient`.
365
+ *
366
+ * `injector` is the **app environment injector** — `ServerFnClient` is
367
+ * `providedIn: 'root'`, and SSR bootstraps a fresh application per request, so
368
+ * its injector is both per-request and the right scope for a handler to resolve
369
+ * from. It is passed rather than captured from the token because
370
+ * `provideServerContext` is applied as *platform* providers, which sit above
371
+ * the app's `providedIn: 'root'` services.
372
+ *
373
+ * Deliberately not a component's node injector: a handler resolves app-level
374
+ * services, and making that depend on which component happened to call it would
375
+ * be surprising and unportable.
376
+ */
377
+ type ServerFnDispatcher = <In, Out>(fn: ServerFn<In, Out>, input: In, injector: Injector) => Promise<Out>;
378
+ declare const SERVER_FN_DISPATCHER: InjectionToken<ServerFnDispatcher>;
266
379
 
267
- export { FormAction, ServerOnly, createRoutes, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, provideFileRouter, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
268
- export type { Files, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta };
380
+ export { FormAction, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
381
+ export type { Files, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta, ServerFn, ServerFnConfig, ServerFnContext, ServerFnDef, ServerFnDispatcher, ServerFnHandler, ServerFnMethod, ServerFnRefConfig, StandardSchemaV1 };