@hamur/adapter-html 0.0.2 → 0.0.4

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.
@@ -22,7 +22,7 @@ function hotTransform(source, id) {
22
22
  `import { hot as __hamurHot, rerender as __hamurRerender } from ${JSON.stringify(HMR_RUNTIME)};`,
23
23
  `const __hamurDefault = __hamurHot(${JSON.stringify(id)}, ${named ?? "__hamurImpl"});`,
24
24
  `export default __hamurDefault;`,
25
- `if (import.meta.hot) import.meta.hot.accept(() => __hamurRerender());`
25
+ `if (import.meta.hot) import.meta.hot.accept(() => void setTimeout(__hamurRerender));`
26
26
  ].join(`
27
27
  `);
28
28
  }
@@ -8,9 +8,9 @@ import type { StateKey } from "hamur/app";
8
8
  import type { HamurEvent } from "hamur/server";
9
9
  import type { LinkDefaults, LinkSlot, Navigation, UseLinkOptions } from "hamur/adapter";
10
10
  import type { AnnouncerActions, AnnouncerPoliteness, AnnouncerState, RouteAnnouncerActions, RouteAnnouncerProps, RouteAnnouncerState, LoadingIndicatorActions, LoadingIndicatorProps as LoadingIndicatorCoreProps, LoadingIndicatorOptions, LoadingIndicatorState, TimeInput } from "hamur/adapter";
11
- import type { ActionOptions, ActionRunner, PrefetchOn, Handler, AfterNavigateHook, BeforeNavigateHook, NavigateHook, NavigationBlocker, NavigationGuard, Blocker, ShouldBlock, UseBlockerOptions, SnapshotOptions } from "hamur/adapter";
11
+ import type { ActionOptions, ActionRunner, ActionValue, FailureOf, PrefetchOn, Handler, AfterNavigateHook, BeforeNavigateHook, NavigateHook, NavigationBlocker, NavigationGuard, Blocker, ShouldBlock, UseBlockerOptions, SnapshotOptions } from "hamur/adapter";
12
12
  import type { HandlerForm, HamurLinkProps } from "hamur/app";
13
- import type { ActionFailure, AppContext, PickFrom, RouteLocation, ClientRuntimeConfig, SiteConfig, ErrorPageProps, FetchData, AsyncDataOptions, AsyncDataStatus, HeadInput, HeadSafeInput, SeoMetaInput, UseCookieOptions, HamurError } from "hamur/app";
13
+ import type { AppContext, PickFrom, RouteLocation, ClientRuntimeConfig, SiteConfig, ErrorPageProps, FetchData, AsyncDataOptions, AsyncDataStatus, HeadInput, HeadSafeInput, SeoMetaInput, UseCookieOptions, HamurError } from "hamur/app";
14
14
  import type { RouteLoaderData, UseDataArgs, AsyncDataHandler, ErrorBoundaryFallbackProps, FetchRequest, GetCachedData, CheckedTarget, NavigationState, RouteValue, RouterApi } from "hamur/adapter";
15
15
  import type { HtmlChildren, HtmlProps } from "./context.ts";
16
16
  export { addRouteMiddleware, clearError, disableScrollHandling, forbidden, navigateTo, notFound, permanentRedirect, refreshCookie, setPageLayout, showError, unauthorized, };
@@ -243,10 +243,10 @@ export declare function useAction<I, O>(fn: Handler<I, O>, options?: ActionOptio
243
243
  instance?: string | number;
244
244
  }): {
245
245
  run: ActionRunner<I, O>["run"];
246
- readonly state: O | undefined;
246
+ readonly state: ActionValue<O> | undefined;
247
247
  readonly pending: boolean;
248
248
  readonly error: HamurError | undefined;
249
- readonly failure: ActionFailure | undefined;
249
+ readonly failure: FailureOf<O> | undefined;
250
250
  reset(): void;
251
251
  subscribe(listener: () => void): () => void;
252
252
  };
@@ -274,7 +274,7 @@ export declare function useCookie<T = string>(name: string, options?: Omit<UseCo
274
274
  export interface UseAsyncDataOptions<T = unknown, R = T, K extends keyof T & string = never, D = T> extends Omit<AsyncDataOptions<T, R, D>, "pick"> {
275
275
  /** Accepted for the same options in every adapter and ignored: nothing watches. */
276
276
  watch?: false;
277
- getCachedData?: GetCachedData<T>;
277
+ getCachedData?: GetCachedData<NoInfer<T>>;
278
278
  /** Top-level keys of an object result to keep. */
279
279
  pick?: readonly K[];
280
280
  }
@@ -300,10 +300,10 @@ export declare function useAsyncData<I, R, T = R, K extends keyof T & string = n
300
300
  default: () => D;
301
301
  }): UseAsyncDataResult<PickFrom<T, K>, D>;
302
302
  export declare function useAsyncData<I, R, T = R, K extends keyof T & string = never>(fn: Handler<I, R>, input?: NoInfer<I> | (() => NoInfer<I>), options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
303
- export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never, D = T>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options: UseAsyncDataOptions<T, R, K, D> & {
303
+ export declare function useAsyncData<R, T = R, K extends keyof T & string = never, D = T>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options: UseAsyncDataOptions<T, R, K, D> & {
304
304
  default: () => D;
305
305
  }): UseAsyncDataResult<PickFrom<T, K>, D>;
306
- export declare function useAsyncData<T = unknown, R = T, K extends keyof T & string = never>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
306
+ export declare function useAsyncData<R, T = R, K extends keyof T & string = never>(keyOrGetter: string | (() => string), handler: AsyncDataHandler<R>, options?: UseAsyncDataOptions<T, R, K, undefined>): UseAsyncDataResult<PickFrom<T, K>>;
307
307
  /** What a literal `useFetch` call is checked against; any other call stays loose. */
308
308
  type FetchInput<X> = X extends {
309
309
  key: infer K extends string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/adapter-html",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -59,6 +59,6 @@
59
59
  ],
60
60
  "dependencies": {},
61
61
  "peerDependencies": {
62
- "hamur": "^0.0.2"
62
+ "hamur": ">=0.0.4 <0.1.0"
63
63
  }
64
64
  }
package/src/index.ts CHANGED
@@ -108,6 +108,8 @@ import type {
108
108
  import type {
109
109
  ActionOptions,
110
110
  ActionRunner,
111
+ ActionValue,
112
+ FailureOf,
111
113
  PrefetchOn,
112
114
  Handler,
113
115
  AfterNavigateHook,
@@ -122,7 +124,6 @@ import type {
122
124
  } from "hamur/adapter"
123
125
  import type { HandlerForm, HamurLinkProps } from "hamur/app"
124
126
  import type {
125
- ActionFailure,
126
127
  AppContext,
127
128
  PickFrom,
128
129
  RouteLocation,
@@ -1189,10 +1190,10 @@ export function useAction<I, O>(
1189
1190
  options: ActionOptions<O> & { instance?: string | number } = {},
1190
1191
  ): {
1191
1192
  run: ActionRunner<I, O>["run"]
1192
- readonly state: O | undefined
1193
+ readonly state: ActionValue<O> | undefined
1193
1194
  readonly pending: boolean
1194
1195
  readonly error: HamurError | undefined
1195
- readonly failure: ActionFailure | undefined
1196
+ readonly failure: FailureOf<O> | undefined
1196
1197
  reset(): void
1197
1198
  subscribe(listener: () => void): () => void
1198
1199
  } {
@@ -1318,7 +1319,7 @@ export interface UseAsyncDataOptions<T = unknown, R = T, K extends keyof T & str
1318
1319
  > {
1319
1320
  /** Accepted for the same options in every adapter and ignored: nothing watches. */
1320
1321
  watch?: false
1321
- getCachedData?: GetCachedData<T>
1322
+ getCachedData?: GetCachedData<NoInfer<T>>
1322
1323
  /** Top-level keys of an object result to keep. */
1323
1324
  pick?: readonly K[]
1324
1325
  }
@@ -1388,12 +1389,12 @@ export function useAsyncData<I, R, T = R, K extends keyof T & string = never>(
1388
1389
  input?: NoInfer<I> | (() => NoInfer<I>),
1389
1390
  options?: UseAsyncDataOptions<T, R, K, undefined>,
1390
1391
  ): UseAsyncDataResult<PickFrom<T, K>>
1391
- export function useAsyncData<T = unknown, R = T, K extends keyof T & string = never, D = T>(
1392
+ export function useAsyncData<R, T = R, K extends keyof T & string = never, D = T>(
1392
1393
  keyOrGetter: string | (() => string),
1393
1394
  handler: AsyncDataHandler<R>,
1394
1395
  options: UseAsyncDataOptions<T, R, K, D> & { default: () => D },
1395
1396
  ): UseAsyncDataResult<PickFrom<T, K>, D>
1396
- export function useAsyncData<T = unknown, R = T, K extends keyof T & string = never>(
1397
+ export function useAsyncData<R, T = R, K extends keyof T & string = never>(
1397
1398
  keyOrGetter: string | (() => string),
1398
1399
  handler: AsyncDataHandler<R>,
1399
1400
  options?: UseAsyncDataOptions<T, R, K, undefined>,
@@ -1554,7 +1555,7 @@ function fetchWith<T, R, K extends keyof T & string, D>(
1554
1555
  const url = valueOf(urlOrGetter)
1555
1556
  const request = requestOf(rest)
1556
1557
  const fetcher = client ?? useApp().fetch ?? $fetch
1557
- return useAsyncData<T, R, K, D>(
1558
+ return useAsyncData<R, T, K, D>(
1558
1559
  key ?? fetchKey(url, request),
1559
1560
  ({ signal }) => fetcher<R>(url, { ...request, signal: signalOf(request.signal, signal) }),
1560
1561
  { server, lazy, default: init as () => D, transform, immediate, dedupe, pick, getCachedData },
package/src/plugin.ts CHANGED
@@ -25,7 +25,8 @@ export function hotTransform(source: string, id: string): string {
25
25
  `import { hot as __hamurHot, rerender as __hamurRerender } from ${JSON.stringify(HMR_RUNTIME)};`,
26
26
  `const __hamurDefault = __hamurHot(${JSON.stringify(id)}, ${named ?? "__hamurImpl"});`,
27
27
  `export default __hamurDefault;`,
28
- `if (import.meta.hot) import.meta.hot.accept(() => __hamurRerender());`,
28
+ // Bun calls this before it runs the other modules of the same update, which the page may import.
29
+ `if (import.meta.hot) import.meta.hot.accept(() => void setTimeout(__hamurRerender));`,
29
30
  ].join("\n")
30
31
  }
31
32