@solidjs/router 0.17.0-next.5 → 1.0.0-next.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +526 -716
  2. package/dist/claims.d.ts +21 -0
  3. package/dist/claims.js +108 -0
  4. package/dist/data/action.d.ts +28 -1
  5. package/dist/data/action.js +184 -43
  6. package/dist/data/events.d.ts +8 -0
  7. package/dist/data/events.js +23 -22
  8. package/dist/data/flash.d.ts +21 -0
  9. package/dist/data/flash.js +78 -0
  10. package/dist/data/flashCookie.d.ts +7 -0
  11. package/dist/data/flashCookie.js +20 -0
  12. package/dist/data/query.js +11 -4
  13. package/dist/data/serverForms.d.ts +1 -0
  14. package/dist/data/serverForms.js +5 -0
  15. package/dist/index.d.ts +5 -3
  16. package/dist/index.js +1381 -686
  17. package/dist/index.jsx +2 -2
  18. package/dist/lifecycle.d.ts +29 -4
  19. package/dist/lifecycle.js +40 -37
  20. package/dist/paths.d.ts +117 -0
  21. package/dist/paths.js +41 -0
  22. package/dist/routers/components.d.ts +10 -21
  23. package/dist/routers/components.jsx +29 -44
  24. package/dist/routers/factory.d.ts +45 -0
  25. package/dist/routers/factory.jsx +143 -0
  26. package/dist/routers/history.d.ts +24 -0
  27. package/dist/routers/history.js +180 -0
  28. package/dist/routers/index.d.ts +4 -11
  29. package/dist/routers/index.js +2 -6
  30. package/dist/routing.d.ts +80 -44
  31. package/dist/routing.js +303 -107
  32. package/dist/server.d.ts +75 -0
  33. package/dist/server.js +264 -0
  34. package/dist/types.d.ts +75 -6
  35. package/dist/utils.d.ts +2 -0
  36. package/dist/utils.js +2 -0
  37. package/package.json +10 -8
  38. package/dist/components.d.ts +0 -31
  39. package/dist/components.jsx +0 -46
  40. package/dist/routers/HashRouter.d.ts +0 -9
  41. package/dist/routers/HashRouter.js +0 -41
  42. package/dist/routers/MemoryRouter.d.ts +0 -24
  43. package/dist/routers/MemoryRouter.js +0 -57
  44. package/dist/routers/Router.d.ts +0 -9
  45. package/dist/routers/Router.js +0 -45
  46. package/dist/routers/StaticRouter.d.ts +0 -6
  47. package/dist/routers/StaticRouter.js +0 -15
  48. package/dist/routers/createRouter.d.ts +0 -10
  49. package/dist/routers/createRouter.js +0 -40
@@ -0,0 +1,20 @@
1
+ // The flash cookie's name and one-shot clearing — split from the codec in
2
+ // flash.ts so the router core can consume the cookie eagerly (the clear must
3
+ // be appended before streaming flushes the response headers, and an unread
4
+ // outcome must not haunt a later request) without carrying the encode/decode
5
+ // machinery into client bundles that never load the action layer.
6
+ export const FLASH_COOKIE = "flash";
7
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
8
+ /** Whether a Cookie header carries a flash cookie (readable or not). */
9
+ export function hasFlashCookie(cookieHeader) {
10
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
11
+ }
12
+ /** The raw encoded flash payload out of a Cookie header, if present. */
13
+ export function matchFlashCookie(cookieHeader) {
14
+ const match = cookieHeader && cookieHeader.match(FLASH_MATCHER);
15
+ return match ? match[1] : undefined;
16
+ }
17
+ /** The Set-Cookie value clearing the flash cookie after it has been read. */
18
+ export function clearFlashCookie() {
19
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
20
+ }
@@ -1,6 +1,6 @@
1
1
  import { createSignal, getObserver, getOwner, onCleanup, sharedConfig } from "solid-js";
2
2
  import { getRequestEvent, isResponseEnvelope, isServer } from "@solidjs/web";
3
- import { decodeResponse } from "@solidjs/web/server-functions";
3
+ import { GET, decodeResponse, getServerFunctionMetadata, isServerFunction } from "@solidjs/web/server-functions";
4
4
  import { useNavigate, getIntent, getInPreloadFn } from "../routing.js";
5
5
  const LocationHeader = "Location";
6
6
  const PRELOAD_TIMEOUT = 5000;
@@ -43,9 +43,16 @@ export function cacheKeyOp(key, fn) {
43
43
  }
44
44
  }
45
45
  export function query(fn, name) {
46
- // prioritize GET for server functions
47
- if (fn.GET)
48
- fn = fn.GET;
46
+ // query implies GET: the router primitive is the declaration site, so a
47
+ // server function handed to query() is wrapped with core `GET(fn)` here,
48
+ // at query-creation (module scope) — the server half records the method
49
+ // declaration for dispatch, the client half swaps in the GET transport.
50
+ // An explicit `GET(fn)` already carries the declaration on the metadata
51
+ // channel (`getServerFunctionMetadata(fn)?.method === "GET"`) and passes
52
+ // through; non-server functions are untouched.
53
+ if (isServerFunction(fn) && !getServerFunctionMetadata(fn)?.method) {
54
+ fn = GET(fn);
55
+ }
49
56
  const cachedFn = ((...args) => {
50
57
  const cache = getCache();
51
58
  const intent = getIntent();
@@ -0,0 +1 @@
1
+ export { submitServerForm } from "./action.js";
@@ -0,0 +1,5 @@
1
+ // The delegation fallback's lazy entry (see data/events.ts). Nothing imports
2
+ // this module statically — it exists so the dynamic import has a target that
3
+ // bundlers can keep as a split point: router-only apps never load the action
4
+ // machinery unless a server-action form actually submits.
5
+ export { submitServerForm } from "./action.js";
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./routers/index.js";
2
- export * from "./components.jsx";
3
2
  export * from "./lifecycle.js";
4
- export { useHref, useIsRouting, useLocation, useMatch, useCurrentMatches, useNavigate, useParams, useResolvedPath, useSearchParams, useBeforeLeave, usePreloadRoute, RouterContextObj as RouterContext } from "./routing.js";
3
+ export { useHref, useIsRouting, useLinkState, useLocation, useMatch, useNavigate, usePreloadRoute, useParams, useResolvedPath, useRouteMatches, useSearchParams, RouterContextObj as RouterContext } from "./routing.js";
4
+ export type { LinkState } from "./routing.js";
5
5
  export { mergeSearchString as _mergeSearchString } from "./utils.js";
6
+ export { int } from "./paths.js";
7
+ export type { RoutePaths, PathParamsOf, PathEnd, TypedMatchFilter } from "./paths.js";
6
8
  export * from "./data/index.js";
7
- export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs } from "./types.js";
9
+ export type { Location, LocationChange, SearchParams, MatchFilter, MatchFilters, NavigateOptions, Navigator, OutputMatch, Params, PathMatch, RouteSectionProps, RoutePreloadFunc, RoutePreloadFuncArgs, RouteDefinition, RouteDescription, RouteMatch, RouterIntegration, RouterUtils, SetParams, Submission, BeforeLeaveEventArgs, TypedPath, TypedSearchPath, StandardSchemaV1 } from "./types.js";