@ubean/routes 0.2.2 → 0.3.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.
- package/dist/form-action-CZA0dSMO.js +511 -0
- package/dist/index.d.ts +382 -3
- package/dist/index.js +448 -94
- package/dist/invoke-CzODqUg-.d.ts +12 -0
- package/dist/runtime.d.ts +149 -0
- package/dist/runtime.js +278 -0
- package/package.json +15 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { n as unwrapActionResult, r as unwrapServerFnResult, t as invokeServerFn } from "./invoke-CzODqUg-.js";
|
|
1
2
|
import { ScannedApiRoute, ScannedLayout, ScannedMiddleware, ScannedPageRoute } from "@ubean/scan";
|
|
2
|
-
import { ComposedHandler, GenericSchema, Input, IsrRule, IsrRule as IsrRule$1, RouteMeta, RouteMeta as RouteMeta$1, RouteRule, RouteRule as RouteRule$1, Span, SpanAttributes, SpanContext, SpanEndOptions, SpanEvent, SpanOptions, SpanStatus, UbeanBindings, UbeanContext, UbeanEnv, UbeanEnv as UbeanEnv$1, UbeanHandler, UbeanMiddleware, UbeanMiddleware as UbeanMiddleware$1, UbeanVariables } from "@ubean/shared";
|
|
3
|
+
import { ACTION_BRAND, ActionContext, ActionContext as ActionContext$1, ActionError, ActionFailure, ActionHandler, ActionHandler as ActionHandler$1, ActionId, ActionId as ActionId$1, ActionResult, ActionResult as ActionResult$1, ActionSchema, ActionSchema as ActionSchema$1, ComposedHandler, GenericSchema, Input, IsrRule, IsrRule as IsrRule$1, RouteMeta, RouteMeta as RouteMeta$1, RouteRule, RouteRule as RouteRule$1, ServerAction, ServerAction as ServerAction$1, Span, SpanAttributes, SpanContext, SpanEndOptions, SpanEvent, SpanOptions, SpanStatus, UbeanBindings, UbeanContext, UbeanEnv, UbeanEnv as UbeanEnv$1, UbeanHandler, UbeanMiddleware, UbeanMiddleware as UbeanMiddleware$1, UbeanVariables, fail, isActionFailure, isServerAction } from "@ubean/shared";
|
|
3
4
|
import { Context, Hono, MiddlewareHandler, Next } from "hono";
|
|
4
5
|
import { H, HandlerResponse, Input as Input$1 } from "hono/types";
|
|
5
6
|
import { FetchAdapter } from "@soybeanjs/fetch";
|
|
@@ -189,9 +190,12 @@ interface RegisterOptions {
|
|
|
189
190
|
pageAssetTags?: unknown;
|
|
190
191
|
pageLoaders?: Record<string, () => Promise<any>>;
|
|
191
192
|
i18nConfig?: {
|
|
193
|
+
enabled?: boolean;
|
|
192
194
|
strategy?: 'prefix' | 'prefix_except_default' | 'prefix_and_default' | 'no_prefix';
|
|
193
195
|
defaultLocale?: string;
|
|
194
196
|
locales?: string[];
|
|
197
|
+
cookieName?: string;
|
|
198
|
+
baseUrl?: string;
|
|
195
199
|
};
|
|
196
200
|
/**
|
|
197
201
|
* 不进行 SSR 的路由模式列表(glob)。
|
|
@@ -249,6 +253,17 @@ declare function createRouteLoader(importMetaGlob: Record<string, () => Promise<
|
|
|
249
253
|
[k: string]: () => Promise<any>;
|
|
250
254
|
};
|
|
251
255
|
//#endregion
|
|
256
|
+
//#region src/path-transform.d.ts
|
|
257
|
+
/**
|
|
258
|
+
* Apply a rewrite/proxy target to a request path (Nuxt-style wildcards).
|
|
259
|
+
*
|
|
260
|
+
* - `/old` + `/new` → `/new`
|
|
261
|
+
* - rule `/blog/**`, request `/blog/a/b`, target `/news/**` → `/news/a/b`
|
|
262
|
+
* - target containing `$1` receives the captured suffix without a leading slash
|
|
263
|
+
* - absolute `https://…` targets keep the origin and transform the pathname
|
|
264
|
+
*/
|
|
265
|
+
declare function applyPathTransform(requestPath: string, rulePath: string, target: string): string;
|
|
266
|
+
//#endregion
|
|
252
267
|
//#region src/route-rules.d.ts
|
|
253
268
|
interface CompiledRouteRule {
|
|
254
269
|
pattern: RegExp;
|
|
@@ -256,6 +271,13 @@ interface CompiledRouteRule {
|
|
|
256
271
|
/** 原始路径模式(用于路径特异性计算) */
|
|
257
272
|
path: string;
|
|
258
273
|
}
|
|
274
|
+
interface RouteRulesMiddlewareOptions {
|
|
275
|
+
/**
|
|
276
|
+
* Internal dispatch used to rematch Hono routes after a rewrite.
|
|
277
|
+
* Typically `req => app.fetch(req)` from `createUbeanApp`.
|
|
278
|
+
*/
|
|
279
|
+
dispatch?: (request: Request) => Promise<Response>;
|
|
280
|
+
}
|
|
259
281
|
declare function compileRouteRules(rules: Record<string, RouteRule$1>): CompiledRouteRule[];
|
|
260
282
|
/**
|
|
261
283
|
* 规范化 `isr` 字段为 `IsrRule` 对象形式。
|
|
@@ -263,7 +285,364 @@ declare function compileRouteRules(rules: Record<string, RouteRule$1>): Compiled
|
|
|
263
285
|
*/
|
|
264
286
|
declare function normalizeIsrRule(isr: RouteRule$1['isr']): IsrRule$1 | undefined;
|
|
265
287
|
declare function matchRouteRules(path: string, compiledRules: CompiledRouteRule[]): RouteRule$1;
|
|
266
|
-
declare function createRouteRulesMiddleware(rules: Record<string, RouteRule$1
|
|
288
|
+
declare function createRouteRulesMiddleware(rules: Record<string, RouteRule$1>, options?: RouteRulesMiddlewareOptions): (c: Context, next: Next) => Promise<Response | undefined>;
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/select-ssr.d.ts
|
|
291
|
+
type SelectSsrValue = boolean | 'streaming' | 'data-only';
|
|
292
|
+
type SelectSsrMode = 'ssr' | 'streaming' | 'data-only' | 'csr';
|
|
293
|
+
interface ResolveSelectSsrInput {
|
|
294
|
+
pageSsr?: SelectSsrValue;
|
|
295
|
+
routeRuleSsr?: SelectSsrValue;
|
|
296
|
+
ppr?: boolean;
|
|
297
|
+
excludedByGlob: boolean;
|
|
298
|
+
streaming: boolean;
|
|
299
|
+
}
|
|
300
|
+
interface ResolvedSelectSsr {
|
|
301
|
+
mode: SelectSsrMode;
|
|
302
|
+
runLoader: boolean;
|
|
303
|
+
useRenderer: boolean;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* TanStack-style select SSR: page meta wins over routeRules, which win over
|
|
307
|
+
* the global exclude list. Glob exclude stays backward-compatible (CSR shell
|
|
308
|
+
* still runs loader). Explicit `ssr: false` skips the loader.
|
|
309
|
+
*/
|
|
310
|
+
declare function resolveSelectSsr(input: ResolveSelectSsrInput): ResolvedSelectSsr;
|
|
311
|
+
declare function ssrModeHeader(mode: SelectSsrMode): string;
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/actions/define.d.ts
|
|
314
|
+
interface DefineActionOptions {
|
|
315
|
+
/**
|
|
316
|
+
* Override the auto-generated action ID.
|
|
317
|
+
*
|
|
318
|
+
* The Vite plugin injects this for `'use server'` modules so the client
|
|
319
|
+
* and server agree on the ID. Inline `defineAction` calls use the
|
|
320
|
+
* auto-generated ID derived from `import.meta.url` + the call site.
|
|
321
|
+
*/
|
|
322
|
+
id?: string;
|
|
323
|
+
/**
|
|
324
|
+
* Override the action's source file path (used for ID generation and
|
|
325
|
+
* debugging). Injected by the Vite plugin.
|
|
326
|
+
*/
|
|
327
|
+
filePath?: string;
|
|
328
|
+
/**
|
|
329
|
+
* Override the action's export name (used for ID generation). Defaults
|
|
330
|
+
* to the function's `name` property or `'anonymous'`.
|
|
331
|
+
*/
|
|
332
|
+
name?: string;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Define a server action with input schema validation.
|
|
336
|
+
*
|
|
337
|
+
* The handler receives the parsed/validated `data` (typed by the schema's
|
|
338
|
+
* output). On validation failure, the action returns an `ActionResult`
|
|
339
|
+
* with `errors` set to the schema's issue messages.
|
|
340
|
+
*/
|
|
341
|
+
declare function defineAction<TOutput>(schema: ActionSchema$1<TOutput>, handler: ActionHandler$1<TOutput, unknown>, options?: DefineActionOptions): ServerAction$1<TOutput, unknown>;
|
|
342
|
+
/**
|
|
343
|
+
* Define a server action without a schema.
|
|
344
|
+
*
|
|
345
|
+
* The handler receives the raw input (FormData or parsed JSON object).
|
|
346
|
+
*/
|
|
347
|
+
declare function defineAction<TInput = unknown, TOutput = unknown>(handler: ActionHandler$1<TInput, TOutput>, options?: DefineActionOptions): ServerAction$1<TInput, TOutput>;
|
|
348
|
+
/**
|
|
349
|
+
* Type-safe server function. Same ID, registry, and `POST /__actions` RPC as
|
|
350
|
+
* `defineAction` — use this alias when the function is a loader/query as well
|
|
351
|
+
* as a mutation. Do not invent a second RPC.
|
|
352
|
+
*/
|
|
353
|
+
declare const defineServerFn: typeof defineAction;
|
|
354
|
+
/**
|
|
355
|
+
* Parse a Request body into a plain object suitable for action handlers.
|
|
356
|
+
*
|
|
357
|
+
* - `application/json` → parsed JSON object
|
|
358
|
+
* - `multipart/form-data` or `application/x-www-form-urlencoded` → Object
|
|
359
|
+
* from FormData entries (string values, files skipped)
|
|
360
|
+
* - Otherwise → empty object (handler can read `ctx.request` directly)
|
|
361
|
+
*/
|
|
362
|
+
declare function parseActionInput(request: Request): Promise<Record<string, unknown>>;
|
|
363
|
+
declare function validateActionInput<T>(schema: ActionSchema$1<T>, input: unknown): {
|
|
364
|
+
success: true;
|
|
365
|
+
data: T;
|
|
366
|
+
} | {
|
|
367
|
+
success: false;
|
|
368
|
+
errors: Record<string, string>;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Normalize a handler return value into an `ActionResult`.
|
|
372
|
+
*
|
|
373
|
+
* - `ActionFailure` → `{ errors, status: failure.status }`
|
|
374
|
+
* - `ActionError` (thrown) → `{ error: { message, code }, status }`
|
|
375
|
+
* - Other thrown error → `{ error: { message }, status: 500 }`
|
|
376
|
+
* - Plain value → `{ data: value, status: 200 }`
|
|
377
|
+
*/
|
|
378
|
+
declare function normalizeActionResult(result: unknown, error: unknown, failureStatus?: number): {
|
|
379
|
+
data?: unknown;
|
|
380
|
+
error?: {
|
|
381
|
+
message: string;
|
|
382
|
+
code?: string;
|
|
383
|
+
};
|
|
384
|
+
errors?: Record<string, string> | null;
|
|
385
|
+
status: number;
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* Build an `ActionContext` from a Hono context.
|
|
389
|
+
*
|
|
390
|
+
* - `request`: the underlying `c.req.raw` Request
|
|
391
|
+
* - `context`: the Hono context (for `c.set`, `c.get`, etc.)
|
|
392
|
+
* - `params`: route params from `c.req.param()`
|
|
393
|
+
*/
|
|
394
|
+
declare function buildActionContext(c: Context<UbeanEnv$1>): ActionContext$1;
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/actions/request-context.d.ts
|
|
397
|
+
interface ActionContextStorage {
|
|
398
|
+
getStore(): ActionContext$1 | undefined;
|
|
399
|
+
run<T>(ctx: ActionContext$1, fn: () => T): T;
|
|
400
|
+
}
|
|
401
|
+
declare function bindActionContextStorage(storage: ActionContextStorage): void;
|
|
402
|
+
declare function getActionContext(): ActionContext$1 | undefined;
|
|
403
|
+
declare function runWithActionContext<T>(ctx: ActionContext$1, fn: () => T): T;
|
|
404
|
+
declare function createDetachedActionContext(request?: Request): ActionContext$1;
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/actions/openapi.d.ts
|
|
407
|
+
/**
|
|
408
|
+
* Optional OpenAPI fragment for the shared `POST /__actions` RPC.
|
|
409
|
+
*
|
|
410
|
+
* Per-action operations stay on the same endpoint (id in the body) so this
|
|
411
|
+
* does not create a second RPC surface.
|
|
412
|
+
*/
|
|
413
|
+
declare function describeActionsOpenApi(): {
|
|
414
|
+
paths: Record<string, {
|
|
415
|
+
post: {
|
|
416
|
+
summary: string;
|
|
417
|
+
description: string;
|
|
418
|
+
operationId: string;
|
|
419
|
+
};
|
|
420
|
+
}>;
|
|
421
|
+
};
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/actions/id.d.ts
|
|
424
|
+
/**
|
|
425
|
+
* Stable Action ID generation (P9-02).
|
|
426
|
+
*
|
|
427
|
+
* Action IDs are derived from the action's source location (file path +
|
|
428
|
+
* export name) so the client and server agree on the same ID without
|
|
429
|
+
* runtime coordination. The Vite plugin injects the ID at build time,
|
|
430
|
+
* but a runtime fallback is provided for actions defined outside the
|
|
431
|
+
* `'use server'` pipeline (e.g. inline `defineAction` in page modules).
|
|
432
|
+
*
|
|
433
|
+
* Format: `act_<base32(sha1(relPath:exportName)).slice(0, 12)>`
|
|
434
|
+
* - `act_` prefix avoids collisions with other URL components
|
|
435
|
+
* - 12 chars of base32 gives ~60 bits of entropy (collision-resistant
|
|
436
|
+
* for any reasonable project size)
|
|
437
|
+
* - base32 (RFC 4648, lowercase) is URL-safe and case-insensitive
|
|
438
|
+
*/
|
|
439
|
+
/**
|
|
440
|
+
* Compute a stable action ID from a file path and export name.
|
|
441
|
+
*
|
|
442
|
+
* @param filePath Project-relative file path (e.g. `src/actions/auth.ts`)
|
|
443
|
+
* @param exportName The export name (e.g. `login`, `default`)
|
|
444
|
+
* @returns A stable action ID string
|
|
445
|
+
*/
|
|
446
|
+
declare function createActionId(filePath: string, exportName: string): string;
|
|
447
|
+
/**
|
|
448
|
+
* Validate that a string is a well-formed action ID.
|
|
449
|
+
*
|
|
450
|
+
* Used by the dispatcher to reject malformed requests early.
|
|
451
|
+
*/
|
|
452
|
+
declare function isValidActionId(id: string): boolean;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/actions/registry.d.ts
|
|
455
|
+
/**
|
|
456
|
+
* Register a server action in the global registry.
|
|
457
|
+
*
|
|
458
|
+
* Called by `defineAction` (implicitly) and by the Vite plugin's virtual
|
|
459
|
+
* module (explicitly) for `'use server'` modules.
|
|
460
|
+
*
|
|
461
|
+
* If an action with the same ID is already registered, the call is a
|
|
462
|
+
* no-op (HMR-safe: re-registering the same action on hot reload doesn't
|
|
463
|
+
* throw).
|
|
464
|
+
*/
|
|
465
|
+
declare function registerAction(action: ServerAction$1): void;
|
|
466
|
+
/**
|
|
467
|
+
* Look up a registered server action by ID.
|
|
468
|
+
*/
|
|
469
|
+
declare function getAction(id: ActionId$1): ServerAction$1 | undefined;
|
|
470
|
+
/**
|
|
471
|
+
* Check whether an action with the given ID is registered.
|
|
472
|
+
*/
|
|
473
|
+
declare function hasAction(id: ActionId$1): boolean;
|
|
474
|
+
/**
|
|
475
|
+
* List all registered actions (for debugging / DevTools).
|
|
476
|
+
*/
|
|
477
|
+
declare function listActions(): ServerAction$1[];
|
|
478
|
+
/**
|
|
479
|
+
* Clear the registry (for tests).
|
|
480
|
+
*
|
|
481
|
+
* Not intended for application code — actions are registered once at
|
|
482
|
+
* module load and remain for the lifetime of the process.
|
|
483
|
+
*/
|
|
484
|
+
declare function clearActions(): void;
|
|
485
|
+
/**
|
|
486
|
+
* Register a map of actions at once (bulk registration helper for the
|
|
487
|
+
* Vite plugin's virtual module).
|
|
488
|
+
*/
|
|
489
|
+
declare function registerActions(actions: ServerAction$1[]): void;
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/actions/dispatch.d.ts
|
|
492
|
+
/**
|
|
493
|
+
* Dispatch a registered server action by ID.
|
|
494
|
+
*
|
|
495
|
+
* Used by the `/__actions` POST endpoint (RPC-style invocation from the
|
|
496
|
+
* client). The action ID is looked up in the global registry; the request
|
|
497
|
+
* body is parsed as JSON or FormData depending on `Content-Type`.
|
|
498
|
+
*
|
|
499
|
+
* When `preParsedInput` is provided (RPC path — the middleware has already
|
|
500
|
+
* read the body to extract the `{ id, args }` envelope), body parsing is
|
|
501
|
+
* skipped and `preParsedInput` is used as the handler input directly.
|
|
502
|
+
*
|
|
503
|
+
* Returns an `ActionResult` (serializable). When the action ID is unknown
|
|
504
|
+
* or invalid, returns a 404 error result without throwing.
|
|
505
|
+
*/
|
|
506
|
+
declare function dispatchAction(actionId: string, c: Context<UbeanEnv$1>, preParsedInput?: unknown): Promise<ActionResult$1>;
|
|
507
|
+
/**
|
|
508
|
+
* Run an arbitrary `ServerAction` against the given Hono context.
|
|
509
|
+
*
|
|
510
|
+
* Used internally by `dispatchAction` and by `handlePageRequest` for
|
|
511
|
+
* page-level form actions (which are not in the global registry but
|
|
512
|
+
* are exported from the page module's `actions` map).
|
|
513
|
+
*
|
|
514
|
+
* When `preParsedInput` is provided, body parsing is skipped (the caller
|
|
515
|
+
* has already read the request body — e.g. the RPC middleware extracting
|
|
516
|
+
* the `{ id, args }` envelope).
|
|
517
|
+
*/
|
|
518
|
+
declare function runAction<TInput, TOutput>(action: ServerAction$1<TInput, TOutput>, c: Context<UbeanEnv$1>, preParsedInput?: unknown): Promise<ActionResult$1<TOutput>>;
|
|
519
|
+
/**
|
|
520
|
+
* Run a page-level form action by name (SvelteKit-style `?/name` convention).
|
|
521
|
+
*
|
|
522
|
+
* Page modules may export an `actions` map:
|
|
523
|
+
*
|
|
524
|
+
* ```ts
|
|
525
|
+
* export const actions = {
|
|
526
|
+
* default: defineAction(async (input, ctx) => { ... }),
|
|
527
|
+
* login: defineAction(async (input, ctx) => { ... }),
|
|
528
|
+
* register: defineAction(async (input, ctx) => { ... })
|
|
529
|
+
* };
|
|
530
|
+
* ```
|
|
531
|
+
*
|
|
532
|
+
* - `POST /page` (no `?/`) → `actions.default`
|
|
533
|
+
* - `POST /page?/login` → `actions.login`
|
|
534
|
+
* - `POST /page?/register` → `actions.register`
|
|
535
|
+
*
|
|
536
|
+
* Returns `null` when:
|
|
537
|
+
* - No `actions` export exists (caller should fall back to `mod.action`).
|
|
538
|
+
* - The named action doesn't exist (caller should return 404).
|
|
539
|
+
*
|
|
540
|
+
* The caller (`handlePageRequest`) is responsible for converting the
|
|
541
|
+
* `ActionResult` into an HTTP response (HTML for browser navigation,
|
|
542
|
+
* JSON for SPA `submit()` calls).
|
|
543
|
+
*/
|
|
544
|
+
declare function runPageAction(actions: Record<string, ServerAction$1>, actionName: string, c: Context<UbeanEnv$1>): Promise<ActionResult$1 | null>;
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region src/actions/constants.d.ts
|
|
547
|
+
/**
|
|
548
|
+
* Shared constants for Server Actions RPC.
|
|
549
|
+
*
|
|
550
|
+
* Kept in a leaf module so the browser runtime can import them without
|
|
551
|
+
* pulling the Hono middleware barrel.
|
|
552
|
+
*/
|
|
553
|
+
declare const ACTIONS_ENDPOINT = "/__actions";
|
|
554
|
+
declare const ACTION_RESPONSE_HEADER = "x-ubean-action";
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/actions/middleware.d.ts
|
|
557
|
+
/**
|
|
558
|
+
* Create the actions middleware — a Hono handler that mounts the
|
|
559
|
+
* `/__actions` POST endpoint.
|
|
560
|
+
*
|
|
561
|
+
* Usage:
|
|
562
|
+
*
|
|
563
|
+
* ```ts
|
|
564
|
+
* import { createUbeanApp } from 'ubean/runtime/app';
|
|
565
|
+
* import { createActionsMiddleware } from '@ubean/routes';
|
|
566
|
+
*
|
|
567
|
+
* const app = createUbeanApp();
|
|
568
|
+
* app.on('POST', '/__actions', createActionsMiddleware());
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* The middleware is auto-registered by ubean's dev server / production
|
|
572
|
+
* server setup — users don't need to mount it manually.
|
|
573
|
+
*/
|
|
574
|
+
declare function createActionsMiddleware(): MiddlewareHandler<UbeanEnv$1>;
|
|
575
|
+
/**
|
|
576
|
+
* Check whether a request targets the actions endpoint.
|
|
577
|
+
*
|
|
578
|
+
* Used by route registrars to skip registering regular API routes for
|
|
579
|
+
* the `/__actions` path.
|
|
580
|
+
*/
|
|
581
|
+
declare function isActionsRequest(c: {
|
|
582
|
+
req: {
|
|
583
|
+
path: string;
|
|
584
|
+
method: string;
|
|
585
|
+
};
|
|
586
|
+
}): boolean;
|
|
587
|
+
/**
|
|
588
|
+
* Check whether a response came from the actions middleware.
|
|
589
|
+
*
|
|
590
|
+
* Used by the client `callAction()` to validate the response shape.
|
|
591
|
+
*/
|
|
592
|
+
declare function isActionResponse(response: Response): boolean;
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/actions/form-action.d.ts
|
|
595
|
+
/**
|
|
596
|
+
* SvelteKit-style form action URL parsing (P9-02).
|
|
597
|
+
*
|
|
598
|
+
* Form actions are invoked via `POST /page?/<actionName>`:
|
|
599
|
+
*
|
|
600
|
+
* - `POST /login` → `actions.default`
|
|
601
|
+
* - `POST /login?/login` → `actions.login`
|
|
602
|
+
* - `POST /login?/register` → `actions.register`
|
|
603
|
+
*
|
|
604
|
+
* The `?/<name>` syntax is URL-safe and works without JavaScript (the
|
|
605
|
+
* browser submits the form to the full URL). On the server, the page
|
|
606
|
+
* route handler parses the action name from the URL's search query.
|
|
607
|
+
*
|
|
608
|
+
* For progressive enhancement, the client can intercept the form submit
|
|
609
|
+
* and call the action via `useFormAction()` for SPA-style navigation.
|
|
610
|
+
*/
|
|
611
|
+
/**
|
|
612
|
+
* Extract the form action name from a URL's search query.
|
|
613
|
+
*
|
|
614
|
+
* SvelteKit's convention: the query string contains a single key `/<name>`
|
|
615
|
+
* with no value. URLSearchParams treats this as a key with empty value.
|
|
616
|
+
*
|
|
617
|
+
* - `?/login` → `login`
|
|
618
|
+
* - `?/register` → `register`
|
|
619
|
+
* - `?` (no action) → `default`
|
|
620
|
+
* - (no query) → `default`
|
|
621
|
+
*
|
|
622
|
+
* @returns The action name, or `'default'` when no specific action is
|
|
623
|
+
* specified.
|
|
624
|
+
*/
|
|
625
|
+
declare function parseFormActionName(url: string | URL): string;
|
|
626
|
+
/**
|
|
627
|
+
* Build a form action URL for the current page.
|
|
628
|
+
*
|
|
629
|
+
* Used by `useFormAction()` to generate the `action` attribute for
|
|
630
|
+
* `<form>` elements. The URL is relative so it works on any page.
|
|
631
|
+
*
|
|
632
|
+
* - `useFormAction()` → `?/default`
|
|
633
|
+
* - `useFormAction('login')` → `?/login`
|
|
634
|
+
* - `useFormAction('register')` → `?/register`
|
|
635
|
+
*
|
|
636
|
+
* The returned string is intended for `<form :action="formAction">` —
|
|
637
|
+
* the browser submits to the current page URL with the action name
|
|
638
|
+
* appended as a query parameter.
|
|
639
|
+
*/
|
|
640
|
+
declare function buildFormActionUrl(actionName?: string): string;
|
|
641
|
+
/**
|
|
642
|
+
* Check whether a URL's query string contains a form action specifier
|
|
643
|
+
* (`?/<name>` pattern).
|
|
644
|
+
*/
|
|
645
|
+
declare function hasFormAction(url: string | URL): boolean;
|
|
267
646
|
//#endregion
|
|
268
647
|
//#region src/internal-fetch.d.ts
|
|
269
648
|
interface InternalFetchOptions {
|
|
@@ -331,4 +710,4 @@ declare function registerOpenAPIRoutes(app: Hono<UbeanEnv$1>, options?: OpenAPIG
|
|
|
331
710
|
openAPIPath?: string;
|
|
332
711
|
}): void;
|
|
333
712
|
//#endregion
|
|
334
|
-
export { type CompiledLayout, type CompiledMiddleware, type CompiledPage, type CompiledRoute, type CompiledRouteRule, type ComposedHandler, type GenericSchema, type Input, type InternalFetchOptions, type IsrCacheEntry, type IsrCacheEntryInternal, type IsrCacheStore, type IsrRule, type IsrServeOptions, type OpenAPIGenerationOptions, type RegisterOptions, type RouteMeta, type RouteRegistrar, type RouteRule, type Span, type SpanAttributes, type SpanContext, type SpanEndOptions, type SpanEvent, type SpanOptions, type SpanStatus, type UbeanBindings, type UbeanContext, type UbeanEnv, type UbeanHandler, type UbeanMiddleware, UbeanRouter, type UbeanVariables, buildIsrCacheKey, clearInternalFetcher, compileRouteRules, createInternalAdapter, createRouteLoader, createRouteRulesMiddleware, createServerRouter, defineHandler, defineHandlerMeta, defineMiddleware, extractRouteMeta, getInternalFetcher, getIsrCache, getIsrRuleFromContext, getStaleIsrCache, invalidateIsrCache, invalidateIsrCachePattern, isBotUserAgent, isHandlerChain, isIsrEntryStale, matchRouteRules, normalizeIsrRule, registerApiRoutes, registerOpenAPIRoutes, registerPageRoutes, registerRoutes, serveIsr, setInternalFetcher, setIsrCache, sortPagesForRegistration, useRouter };
|
|
713
|
+
export { ACTIONS_ENDPOINT, ACTION_BRAND, ACTION_RESPONSE_HEADER, type ActionContext, type ActionContextStorage, ActionError, type ActionFailure, type ActionHandler, type ActionId, type ActionResult, type ActionSchema, type CompiledLayout, type CompiledMiddleware, type CompiledPage, type CompiledRoute, type CompiledRouteRule, type ComposedHandler, type DefineActionOptions, type GenericSchema, type Input, type InternalFetchOptions, type IsrCacheEntry, type IsrCacheEntryInternal, type IsrCacheStore, type IsrRule, type IsrServeOptions, type OpenAPIGenerationOptions, type RegisterOptions, type ResolveSelectSsrInput, type ResolvedSelectSsr, type RouteMeta, type RouteRegistrar, type RouteRule, type RouteRulesMiddlewareOptions, type SelectSsrMode, type SelectSsrValue, type ServerAction, type Span, type SpanAttributes, type SpanContext, type SpanEndOptions, type SpanEvent, type SpanOptions, type SpanStatus, type UbeanBindings, type UbeanContext, type UbeanEnv, type UbeanHandler, type UbeanMiddleware, UbeanRouter, type UbeanVariables, applyPathTransform, bindActionContextStorage, buildActionContext, buildFormActionUrl, buildIsrCacheKey, clearActions, clearInternalFetcher, compileRouteRules, createActionId, createActionsMiddleware, createDetachedActionContext, createInternalAdapter, createRouteLoader, createRouteRulesMiddleware, createServerRouter, defineAction, defineHandler, defineHandlerMeta, defineMiddleware, defineServerFn, describeActionsOpenApi, dispatchAction, extractRouteMeta, fail, getAction, getActionContext, getInternalFetcher, getIsrCache, getIsrRuleFromContext, getStaleIsrCache, hasAction, hasFormAction, invalidateIsrCache, invalidateIsrCachePattern, invokeServerFn, isActionFailure, isActionResponse, isActionsRequest, isBotUserAgent, isHandlerChain, isIsrEntryStale, isServerAction, isValidActionId, listActions, matchRouteRules, normalizeActionResult, normalizeIsrRule, parseActionInput, parseFormActionName, registerAction, registerActions, registerApiRoutes, registerOpenAPIRoutes, registerPageRoutes, registerRoutes, resolveSelectSsr, runAction, runPageAction, runWithActionContext, serveIsr, setInternalFetcher, setIsrCache, sortPagesForRegistration, ssrModeHeader, unwrapActionResult, unwrapServerFnResult, useRouter, validateActionInput };
|