@pauloevpr/solid-router 0.16.2-vt.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1097 -0
  3. package/dist/components.d.ts +31 -0
  4. package/dist/components.jsx +40 -0
  5. package/dist/data/action.d.ts +17 -0
  6. package/dist/data/action.js +166 -0
  7. package/dist/data/createAsync.d.ts +32 -0
  8. package/dist/data/createAsync.js +96 -0
  9. package/dist/data/events.d.ts +9 -0
  10. package/dist/data/events.js +123 -0
  11. package/dist/data/index.d.ts +4 -0
  12. package/dist/data/index.js +4 -0
  13. package/dist/data/query.d.ts +23 -0
  14. package/dist/data/query.js +232 -0
  15. package/dist/data/response.d.ts +4 -0
  16. package/dist/data/response.js +42 -0
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +2055 -0
  19. package/dist/index.jsx +7 -0
  20. package/dist/lifecycle.d.ts +5 -0
  21. package/dist/lifecycle.js +76 -0
  22. package/dist/routers/HashRouter.d.ts +9 -0
  23. package/dist/routers/HashRouter.js +41 -0
  24. package/dist/routers/MemoryRouter.d.ts +24 -0
  25. package/dist/routers/MemoryRouter.js +57 -0
  26. package/dist/routers/Router.d.ts +9 -0
  27. package/dist/routers/Router.js +45 -0
  28. package/dist/routers/StaticRouter.d.ts +6 -0
  29. package/dist/routers/StaticRouter.js +15 -0
  30. package/dist/routers/components.d.ts +29 -0
  31. package/dist/routers/components.jsx +122 -0
  32. package/dist/routers/createRouter.d.ts +10 -0
  33. package/dist/routers/createRouter.js +41 -0
  34. package/dist/routers/index.d.ts +11 -0
  35. package/dist/routers/index.js +6 -0
  36. package/dist/routing.d.ts +176 -0
  37. package/dist/routing.js +608 -0
  38. package/dist/types.d.ts +203 -0
  39. package/dist/types.js +1 -0
  40. package/dist/utils.d.ts +13 -0
  41. package/dist/utils.js +193 -0
  42. package/dist/viewTransitions.d.ts +20 -0
  43. package/dist/viewTransitions.js +118 -0
  44. package/package.json +71 -0
@@ -0,0 +1,31 @@
1
+ import type { JSX } from "solid-js";
2
+ import type { Location, Navigator } from "./types.js";
3
+ declare module "solid-js" {
4
+ namespace JSX {
5
+ interface AnchorHTMLAttributes<T> {
6
+ state?: string;
7
+ noScroll?: boolean;
8
+ replace?: boolean;
9
+ preload?: boolean;
10
+ link?: boolean;
11
+ }
12
+ }
13
+ }
14
+ export interface AnchorProps extends Omit<JSX.AnchorHTMLAttributes<HTMLAnchorElement>, "state"> {
15
+ href: string;
16
+ replace?: boolean | undefined;
17
+ noScroll?: boolean | undefined;
18
+ state?: unknown | undefined;
19
+ inactiveClass?: string | undefined;
20
+ activeClass?: string | undefined;
21
+ end?: boolean | undefined;
22
+ }
23
+ export declare function A(props: AnchorProps): JSX.Element;
24
+ export interface NavigateProps {
25
+ href: ((args: {
26
+ navigate: Navigator;
27
+ location: Location;
28
+ }) => string) | string;
29
+ state?: unknown;
30
+ }
31
+ export declare function Navigate(props: NavigateProps): null;
@@ -0,0 +1,40 @@
1
+ import { createMemo, mergeProps, splitProps } from "solid-js";
2
+ import { useHref, useLocation, useNavigate, useResolvedPath } from "./routing.js";
3
+ import { normalizePath } from "./utils.js";
4
+ export function A(props) {
5
+ props = mergeProps({ inactiveClass: "inactive", activeClass: "active" }, props);
6
+ const [, rest] = splitProps(props, [
7
+ "href",
8
+ "state",
9
+ "class",
10
+ "activeClass",
11
+ "inactiveClass",
12
+ "end"
13
+ ]);
14
+ const to = useResolvedPath(() => props.href);
15
+ const href = useHref(to);
16
+ const location = useLocation();
17
+ const isActive = createMemo(() => {
18
+ const to_ = to();
19
+ if (to_ === undefined)
20
+ return [false, false];
21
+ // trailing slashes are ignored so `/route` and `/route/` share active state
22
+ const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase().replace(/\/$/, "");
23
+ const loc = decodeURI(normalizePath(location.pathname).toLowerCase().replace(/\/$/, ""));
24
+ return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc];
25
+ });
26
+ return (<a {...rest} href={href() || props.href} state={JSON.stringify(props.state)} classList={{
27
+ ...(props.class && { [props.class]: true }),
28
+ [props.inactiveClass]: !isActive()[0],
29
+ [props.activeClass]: isActive()[0],
30
+ ...rest.classList
31
+ }} link aria-current={isActive()[1] ? "page" : undefined}/>);
32
+ }
33
+ export function Navigate(props) {
34
+ const navigate = useNavigate();
35
+ const location = useLocation();
36
+ const { href, state } = props;
37
+ const path = typeof href === "function" ? href({ navigate, location }) : href;
38
+ navigate(path, { replace: true, state });
39
+ return null;
40
+ }
@@ -0,0 +1,17 @@
1
+ import { JSX } from "solid-js";
2
+ import type { Submission, SubmissionStub, NarrowResponse } from "../types.js";
3
+ export type Action<T extends Array<any>, U, V = T> = (T extends [FormData | URLSearchParams] | [] ? JSX.SerializableAttributeValue : unknown) & ((...vars: T) => Promise<NarrowResponse<U>>) & {
4
+ url: string;
5
+ with<A extends any[], B extends any[]>(this: (this: any, ...args: [...A, ...B]) => Promise<NarrowResponse<U>>, ...args: A): Action<B, U, V>;
6
+ };
7
+ export declare const actions: Map<string, Action<any, any, any>>;
8
+ export declare function useSubmissions<T extends Array<any>, U, V>(fn: Action<T, U, V>, filter?: (input: V) => boolean): Submission<T, NarrowResponse<U>>[] & {
9
+ pending: boolean;
10
+ };
11
+ export declare function useSubmission<T extends Array<any>, U, V>(fn: Action<T, U, V>, filter?: (input: V) => boolean): Submission<T, NarrowResponse<U>> | SubmissionStub;
12
+ export declare function useAction<T extends Array<any>, U, V>(action: Action<T, U, V>): (...args: Parameters<Action<T, U, V>>) => Promise<NarrowResponse<U>>;
13
+ export declare function action<T extends Array<any>, U = void>(fn: (...args: T) => Promise<U>, name?: string): Action<T, U>;
14
+ export declare function action<T extends Array<any>, U = void>(fn: (...args: T) => Promise<U>, options?: {
15
+ name?: string;
16
+ onComplete?: (s: Submission<T, U>) => void;
17
+ }): Action<T, U>;
@@ -0,0 +1,166 @@
1
+ import { $TRACK, createMemo, createSignal, onCleanup, getOwner } from "solid-js";
2
+ import { isServer } from "solid-js/web";
3
+ import { useRouter } from "../routing.js";
4
+ import { mockBase, setFunctionName } from "../utils.js";
5
+ import { cacheKeyOp, hashKey, revalidate, query } from "./query.js";
6
+ export const actions = /* #__PURE__ */ new Map();
7
+ export function useSubmissions(fn, filter) {
8
+ const router = useRouter();
9
+ const subs = createMemo(() => router.submissions[0]().filter(s => s.url === fn.base && (!filter || filter(s.input))));
10
+ return new Proxy([], {
11
+ get(_, property) {
12
+ if (property === $TRACK)
13
+ return subs();
14
+ if (property === "pending")
15
+ return subs().some(sub => !sub.result);
16
+ return subs()[property];
17
+ },
18
+ has(_, property) {
19
+ return property in subs();
20
+ }
21
+ });
22
+ }
23
+ export function useSubmission(fn, filter) {
24
+ const submissions = useSubmissions(fn, filter);
25
+ return new Proxy({}, {
26
+ get(_, property) {
27
+ if (submissions.length === 0 && (property === "clear" || property === "retry"))
28
+ return () => { };
29
+ return submissions[submissions.length - 1]?.[property];
30
+ }
31
+ });
32
+ }
33
+ export function useAction(action) {
34
+ const r = useRouter();
35
+ return (...args) => action.apply({ r }, args);
36
+ }
37
+ export function action(fn, options = {}) {
38
+ function mutate(...variables) {
39
+ const router = this.r;
40
+ const form = this.f;
41
+ const p = (router.singleFlight && fn.withOptions
42
+ ? fn.withOptions({ headers: { "X-Single-Flight": "true" } })
43
+ : fn)(...variables);
44
+ const [result, setResult] = createSignal();
45
+ let submission;
46
+ function handler(error) {
47
+ return async (res) => {
48
+ const result = await handleResponse(res, error, router.navigatorFactory());
49
+ let retry = null;
50
+ o.onComplete?.({
51
+ ...submission,
52
+ result: result?.data,
53
+ error: result?.error,
54
+ pending: false,
55
+ retry() {
56
+ return (retry = submission.retry());
57
+ }
58
+ });
59
+ if (retry)
60
+ return retry;
61
+ if (!result)
62
+ return submission.clear();
63
+ setResult(result);
64
+ if (result.error && !form)
65
+ throw result.error;
66
+ return result.data;
67
+ };
68
+ }
69
+ router.submissions[1](s => [
70
+ ...s,
71
+ (submission = {
72
+ input: variables,
73
+ url,
74
+ get result() {
75
+ return result()?.data;
76
+ },
77
+ get error() {
78
+ return result()?.error;
79
+ },
80
+ get pending() {
81
+ return !result();
82
+ },
83
+ clear() {
84
+ router.submissions[1](v => v.filter(i => i !== submission));
85
+ },
86
+ retry() {
87
+ setResult(undefined);
88
+ const p = fn(...variables);
89
+ return p.then(handler(), handler(true));
90
+ }
91
+ })
92
+ ]);
93
+ return p.then(handler(), handler(true));
94
+ }
95
+ const o = typeof options === "string" ? { name: options } : options;
96
+ const name = o.name || (!isServer ? String(hashString(fn.toString())) : undefined);
97
+ const url = fn.url || (name && `https://action/${name}`) || "";
98
+ mutate.base = url;
99
+ if (name)
100
+ setFunctionName(mutate, name);
101
+ return toAction(mutate, url);
102
+ }
103
+ function toAction(fn, url) {
104
+ fn.toString = () => {
105
+ if (!url)
106
+ throw new Error("Client Actions need explicit names if server rendered");
107
+ return url;
108
+ };
109
+ fn.with = function (...args) {
110
+ const newFn = function (...passedArgs) {
111
+ return fn.call(this, ...args, ...passedArgs);
112
+ };
113
+ newFn.base = fn.base;
114
+ const uri = new URL(url, mockBase);
115
+ uri.searchParams.set("args", hashKey(args));
116
+ return toAction(newFn, (uri.origin === "https://action" ? uri.origin : "") + uri.pathname + uri.search);
117
+ };
118
+ fn.url = url;
119
+ if (!isServer) {
120
+ actions.set(url, fn);
121
+ // Only remove the registration if it still belongs to this instance —
122
+ // a re-created action (e.g. a new `.with()` binding after revalidation)
123
+ // may have registered itself under the same URL since.
124
+ getOwner() && onCleanup(() => actions.get(url) === fn && actions.delete(url));
125
+ }
126
+ return fn;
127
+ }
128
+ const hashString = (s) => s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0);
129
+ async function handleResponse(response, error, navigate) {
130
+ let data;
131
+ let custom;
132
+ let keys;
133
+ let flightKeys;
134
+ if (response instanceof Response) {
135
+ if (response.headers.has("X-Revalidate"))
136
+ keys = response.headers.get("X-Revalidate").split(",");
137
+ if (response.customBody) {
138
+ data = custom = await response.customBody();
139
+ if (response.headers.has("X-Single-Flight")) {
140
+ data = data._$value;
141
+ delete custom._$value;
142
+ flightKeys = Object.keys(custom);
143
+ }
144
+ }
145
+ if (response.headers.has("Location")) {
146
+ const locationUrl = response.headers.get("Location") || "/";
147
+ if (locationUrl.startsWith("http")) {
148
+ window.location.href = locationUrl;
149
+ }
150
+ else {
151
+ navigate(locationUrl);
152
+ }
153
+ }
154
+ }
155
+ else if (error)
156
+ return { error: response };
157
+ else
158
+ data = response;
159
+ // invalidate
160
+ cacheKeyOp(keys, entry => (entry[0] = 0));
161
+ // set cache
162
+ flightKeys && flightKeys.forEach(k => query.set(k, custom[k]));
163
+ // trigger revalidation
164
+ await revalidate(keys, false);
165
+ return data != null ? { data } : undefined;
166
+ }
@@ -0,0 +1,32 @@
1
+ import { type ReconcileOptions } from "solid-js/store";
2
+ /**
3
+ * As `createAsync` and `createAsyncStore` are wrappers for `createResource`,
4
+ * this type allows to support `latest` field for these primitives.
5
+ * It will be removed in the future.
6
+ */
7
+ export type AccessorWithLatest<T> = {
8
+ (): T;
9
+ latest: T;
10
+ };
11
+ export declare function createAsync<T>(fn: (prev: T) => Promise<T>, options: {
12
+ name?: string;
13
+ initialValue: T;
14
+ deferStream?: boolean;
15
+ }): AccessorWithLatest<T>;
16
+ export declare function createAsync<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
17
+ name?: string;
18
+ initialValue?: T;
19
+ deferStream?: boolean;
20
+ }): AccessorWithLatest<T | undefined>;
21
+ export declare function createAsyncStore<T>(fn: (prev: T) => Promise<T>, options: {
22
+ name?: string;
23
+ initialValue: T;
24
+ deferStream?: boolean;
25
+ reconcile?: ReconcileOptions;
26
+ }): AccessorWithLatest<T>;
27
+ export declare function createAsyncStore<T>(fn: (prev: T | undefined) => Promise<T>, options?: {
28
+ name?: string;
29
+ initialValue?: T;
30
+ deferStream?: boolean;
31
+ reconcile?: ReconcileOptions;
32
+ }): AccessorWithLatest<T | undefined>;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * This is mock of the eventual Solid 2.0 primitive. It is not fully featured.
3
+ */
4
+ import { createResource, sharedConfig, untrack, catchError } from "solid-js";
5
+ import { createStore, reconcile, unwrap } from "solid-js/store";
6
+ import { isServer } from "solid-js/web";
7
+ import { setFunctionName } from "../utils.js";
8
+ export function createAsync(fn, options) {
9
+ let resource;
10
+ let prev = () => !resource || resource.state === "unresolved" ? undefined : resource.latest;
11
+ [resource] = createResource(() => subFetch(fn, catchError(() => untrack(prev), () => undefined)), v => v, options);
12
+ const resultAccessor = (() => resource());
13
+ if (options?.name)
14
+ setFunctionName(resultAccessor, options.name);
15
+ Object.defineProperty(resultAccessor, "latest", {
16
+ get() {
17
+ return resource.latest;
18
+ }
19
+ });
20
+ return resultAccessor;
21
+ }
22
+ export function createAsyncStore(fn, options = {}) {
23
+ let resource;
24
+ let prev = () => !resource || resource.state === "unresolved"
25
+ ? undefined
26
+ : unwrap(resource.latest);
27
+ [resource] = createResource(() => subFetch(fn, catchError(() => untrack(prev), () => undefined)), v => v, {
28
+ ...options,
29
+ storage: (init) => createDeepSignal(init, options.reconcile)
30
+ });
31
+ const resultAccessor = (() => resource());
32
+ Object.defineProperty(resultAccessor, "latest", {
33
+ get() {
34
+ return resource.latest;
35
+ }
36
+ });
37
+ return resultAccessor;
38
+ }
39
+ function createDeepSignal(value, options) {
40
+ const [store, setStore] = createStore({
41
+ value: structuredClone(value)
42
+ });
43
+ return [
44
+ () => store.value,
45
+ (v) => {
46
+ typeof v === "function" && (v = v());
47
+ setStore("value", reconcile(structuredClone(v), options));
48
+ return store.value;
49
+ }
50
+ ];
51
+ }
52
+ // mock promise while hydrating to prevent fetching
53
+ class MockPromise {
54
+ static all() {
55
+ return new MockPromise();
56
+ }
57
+ static allSettled() {
58
+ return new MockPromise();
59
+ }
60
+ static any() {
61
+ return new MockPromise();
62
+ }
63
+ static race() {
64
+ return new MockPromise();
65
+ }
66
+ static reject() {
67
+ return new MockPromise();
68
+ }
69
+ static resolve() {
70
+ return new MockPromise();
71
+ }
72
+ catch() {
73
+ return new MockPromise();
74
+ }
75
+ then() {
76
+ return new MockPromise();
77
+ }
78
+ finally() {
79
+ return new MockPromise();
80
+ }
81
+ }
82
+ function subFetch(fn, prev) {
83
+ if (isServer || !sharedConfig.context)
84
+ return fn(prev);
85
+ const ogFetch = fetch;
86
+ const ogPromise = Promise;
87
+ try {
88
+ window.fetch = () => new MockPromise();
89
+ Promise = MockPromise;
90
+ return fn(prev);
91
+ }
92
+ finally {
93
+ window.fetch = ogFetch;
94
+ Promise = ogPromise;
95
+ }
96
+ }
@@ -0,0 +1,9 @@
1
+ import type { RouterContext } from "../types.js";
2
+ type NativeEventConfig = {
3
+ preload?: boolean;
4
+ explicitLinks?: boolean;
5
+ actionBase?: string;
6
+ transformUrl?: (url: string) => string;
7
+ };
8
+ export declare function setupNativeEvents({ preload, explicitLinks, actionBase, transformUrl }?: NativeEventConfig): (router: RouterContext) => void;
9
+ export {};
@@ -0,0 +1,123 @@
1
+ import { delegateEvents } from "solid-js/web";
2
+ import { onCleanup } from "solid-js";
3
+ import { actions } from "./action.js";
4
+ import { mockBase } from "../utils.js";
5
+ export function setupNativeEvents({ preload = true, explicitLinks = false, actionBase = "/_server", transformUrl } = {}) {
6
+ return (router) => {
7
+ const basePath = router.base.path();
8
+ const navigateFromRoute = router.navigatorFactory(router.base);
9
+ let preloadTimeout;
10
+ let lastElement;
11
+ function isSvg(el) {
12
+ return el.namespaceURI === "http://www.w3.org/2000/svg";
13
+ }
14
+ function handleAnchor(evt) {
15
+ if (evt.defaultPrevented ||
16
+ evt.button !== 0 ||
17
+ evt.metaKey ||
18
+ evt.altKey ||
19
+ evt.ctrlKey ||
20
+ evt.shiftKey)
21
+ return;
22
+ const a = evt
23
+ .composedPath()
24
+ .find(el => el instanceof Node && el.nodeName.toUpperCase() === "A");
25
+ if (!a || (explicitLinks && !a.hasAttribute("link")))
26
+ return;
27
+ const svg = isSvg(a);
28
+ const href = svg ? a.href.baseVal : a.href;
29
+ const target = svg ? a.target.baseVal : a.target;
30
+ if (target || (!href && !a.hasAttribute("state")))
31
+ return;
32
+ const rel = (a.getAttribute("rel") || "").split(/\s+/);
33
+ if (a.hasAttribute("download") || (rel && rel.includes("external")))
34
+ return;
35
+ const url = svg ? new URL(href, document.baseURI) : new URL(href);
36
+ if (url.origin !== window.location.origin ||
37
+ (basePath && url.pathname && !url.pathname.toLowerCase().startsWith(basePath.toLowerCase())))
38
+ return;
39
+ return [a, url];
40
+ }
41
+ function handleAnchorClick(evt) {
42
+ const res = handleAnchor(evt);
43
+ if (!res)
44
+ return;
45
+ const [a, url] = res;
46
+ const to = router.parsePath(url.pathname + url.search + url.hash);
47
+ const state = a.getAttribute("state");
48
+ evt.preventDefault();
49
+ navigateFromRoute(to, {
50
+ resolve: false,
51
+ replace: a.hasAttribute("replace"),
52
+ scroll: !a.hasAttribute("noscroll"),
53
+ state: state ? JSON.parse(state) : undefined
54
+ });
55
+ }
56
+ function handleAnchorPreload(evt) {
57
+ const res = handleAnchor(evt);
58
+ if (!res)
59
+ return;
60
+ const [a, url] = res;
61
+ transformUrl && (url.pathname = transformUrl(url.pathname));
62
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
63
+ }
64
+ function handleAnchorMove(evt) {
65
+ clearTimeout(preloadTimeout);
66
+ const res = handleAnchor(evt);
67
+ if (!res)
68
+ return (lastElement = null);
69
+ const [a, url] = res;
70
+ if (lastElement === a)
71
+ return;
72
+ transformUrl && (url.pathname = transformUrl(url.pathname));
73
+ preloadTimeout = setTimeout(() => {
74
+ router.preloadRoute(url, a.getAttribute("preload") !== "false");
75
+ lastElement = a;
76
+ }, 20);
77
+ }
78
+ function handleFormSubmit(evt) {
79
+ if (evt.defaultPrevented)
80
+ return;
81
+ let actionRef = evt.submitter && evt.submitter.hasAttribute("formaction")
82
+ ? evt.submitter.getAttribute("formaction")
83
+ : evt.target.getAttribute("action");
84
+ if (!actionRef)
85
+ return;
86
+ if (!actionRef.startsWith("https://action/")) {
87
+ // normalize server actions
88
+ const url = new URL(actionRef, mockBase);
89
+ actionRef = router.parsePath(url.pathname + url.search);
90
+ if (!actionRef.startsWith(actionBase))
91
+ return;
92
+ }
93
+ if (evt.target.method.toUpperCase() !== "POST")
94
+ throw new Error("Only POST forms are supported for Actions");
95
+ const handler = actions.get(actionRef);
96
+ if (handler) {
97
+ evt.preventDefault();
98
+ const data = new FormData(evt.target, evt.submitter);
99
+ handler.call({ r: router, f: evt.target }, evt.target.enctype === "multipart/form-data"
100
+ ? data
101
+ : new URLSearchParams(data));
102
+ }
103
+ }
104
+ // ensure delegated event run first
105
+ delegateEvents(["click", "submit"]);
106
+ document.addEventListener("click", handleAnchorClick);
107
+ if (preload) {
108
+ document.addEventListener("mousemove", handleAnchorMove, { passive: true });
109
+ document.addEventListener("focusin", handleAnchorPreload, { passive: true });
110
+ document.addEventListener("touchstart", handleAnchorPreload, { passive: true });
111
+ }
112
+ document.addEventListener("submit", handleFormSubmit);
113
+ onCleanup(() => {
114
+ document.removeEventListener("click", handleAnchorClick);
115
+ if (preload) {
116
+ document.removeEventListener("mousemove", handleAnchorMove);
117
+ document.removeEventListener("focusin", handleAnchorPreload);
118
+ document.removeEventListener("touchstart", handleAnchorPreload);
119
+ }
120
+ document.removeEventListener("submit", handleFormSubmit);
121
+ });
122
+ };
123
+ }
@@ -0,0 +1,4 @@
1
+ export { createAsync, createAsyncStore, type AccessorWithLatest } from "./createAsync.js";
2
+ export { action, useSubmission, useSubmissions, useAction, type Action } from "./action.js";
3
+ export { query, revalidate, cache, type CachedFunction } from "./query.js";
4
+ export { redirect, reload, json } from "./response.js";
@@ -0,0 +1,4 @@
1
+ export { createAsync, createAsyncStore } from "./createAsync.js";
2
+ export { action, useSubmission, useSubmissions, useAction } from "./action.js";
3
+ export { query, revalidate, cache } from "./query.js";
4
+ export { redirect, reload, json } from "./response.js";
@@ -0,0 +1,23 @@
1
+ import type { CacheEntry, NarrowResponse } from "../types.js";
2
+ /**
3
+ * Revalidates the given cache entry/entries.
4
+ */
5
+ export declare function revalidate(key?: string | string[] | void, force?: boolean): Promise<void>;
6
+ export declare function cacheKeyOp(key: string | string[] | void, fn: (cacheEntry: CacheEntry) => void): void;
7
+ export type CachedFunction<T extends (...args: any) => any> = T extends (...args: infer A) => infer R ? ([] extends {
8
+ [K in keyof A]-?: A[K];
9
+ } ? (...args: never[]) => R extends Promise<infer P> ? Promise<NarrowResponse<P>> : NarrowResponse<R> : (...args: A) => R extends Promise<infer P> ? Promise<NarrowResponse<P>> : NarrowResponse<R>) & {
10
+ keyFor: (...args: A) => string;
11
+ key: string;
12
+ } : never;
13
+ export declare function query<T extends (...args: any) => any>(fn: T, name: string): CachedFunction<T>;
14
+ export declare namespace query {
15
+ export var get: (key: string) => any;
16
+ export var set: <T>(key: string, value: T extends Promise<any> ? never : T) => void;
17
+ var _a: (key: string) => boolean;
18
+ export var clear: () => void;
19
+ export { _a as delete };
20
+ }
21
+ /** @deprecated use query instead */
22
+ export declare const cache: typeof query;
23
+ export declare function hashKey<T extends Array<any>>(args: T): string;