@quvel-kit/core 1.3.18 → 1.3.19

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.
@@ -15,7 +15,7 @@ import type { AuthMeta } from '../types/auth-meta';
15
15
  * meta: {
16
16
  * auth: createAuthMeta({
17
17
  * guestOnly: true,
18
- * redirectTo: '/dashboard'
18
+ * redirectTo: '/dadshboard'
19
19
  * })
20
20
  * }
21
21
  * ```
@@ -14,7 +14,7 @@
14
14
  * meta: {
15
15
  * auth: createAuthMeta({
16
16
  * guestOnly: true,
17
- * redirectTo: '/dashboard'
17
+ * redirectTo: '/dadshboard'
18
18
  * })
19
19
  * }
20
20
  * ```
@@ -10,6 +10,7 @@ import { type Ref } from 'vue';
10
10
  *
11
11
  * @param key - Unique key for this data (used for serialization)
12
12
  * @param fetcher - Async function that fetches the data
13
+ * @param factory - Optional factory function to reconstruct class instances from plain objects on client hydration
13
14
  * @returns Reactive data ref and error state
14
15
  *
15
16
  * @example
@@ -18,9 +19,16 @@ import { type Ref } from 'vue';
18
19
  * `household-${route.params.id}`,
19
20
  * () => householdService.get(route.params.id)
20
21
  * );
22
+ *
23
+ * // With factory for class instances:
24
+ * const { data: bill, error } = useSSRData(
25
+ * `bill-${route.params.id}`,
26
+ * () => billService.get(route.params.id),
27
+ * (plainObj) => new Bill(plainObj)
28
+ * );
21
29
  * ```
22
30
  */
23
- export declare function useSSRData<T>(key: string, fetcher: () => Promise<T>): {
31
+ export declare function useSSRData<T>(key: string, fetcher: () => Promise<T>, factory?: (data: any) => T): {
24
32
  data: Ref<T | null>;
25
33
  error: Ref<Error | null>;
26
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useSSRData.d.ts","sourceRoot":"","sources":["../../src/composables/useSSRData.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAMjE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB;IACD,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC1B,CAkDA"}
1
+ {"version":3,"file":"useSSRData.d.ts","sourceRoot":"","sources":["../../src/composables/useSSRData.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAMjE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GACzB;IACD,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC1B,CAkDA"}
@@ -13,6 +13,7 @@ const SSR_ERROR_PREFIX = '__SSR_ERROR_';
13
13
  *
14
14
  * @param key - Unique key for this data (used for serialization)
15
15
  * @param fetcher - Async function that fetches the data
16
+ * @param factory - Optional factory function to reconstruct class instances from plain objects on client hydration
16
17
  * @returns Reactive data ref and error state
17
18
  *
18
19
  * @example
@@ -21,9 +22,16 @@ const SSR_ERROR_PREFIX = '__SSR_ERROR_';
21
22
  * `household-${route.params.id}`,
22
23
  * () => householdService.get(route.params.id)
23
24
  * );
25
+ *
26
+ * // With factory for class instances:
27
+ * const { data: bill, error } = useSSRData(
28
+ * `bill-${route.params.id}`,
29
+ * () => billService.get(route.params.id),
30
+ * (plainObj) => new Bill(plainObj)
31
+ * );
24
32
  * ```
25
33
  */
26
- export function useSSRData(key, fetcher) {
34
+ export function useSSRData(key, fetcher, factory) {
27
35
  const isSSR = typeof window === 'undefined';
28
36
  const container = useQuvel();
29
37
  const dataKey = `${SSR_DATA_PREFIX}${key}`;
@@ -40,7 +48,7 @@ export function useSSRData(key, fetcher) {
40
48
  delete win[errorKey];
41
49
  }
42
50
  else if (ssrData !== undefined) {
43
- initialData = ssrData;
51
+ initialData = factory ? factory(ssrData) : ssrData;
44
52
  delete win[dataKey];
45
53
  }
46
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quvel-kit/core",
3
- "version": "1.3.18",
3
+ "version": "1.3.19",
4
4
  "description": "Core utilities for Quvel UI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",