@nuxt/bridge-edge 3.0.0-27478656.5b2ed85 → 3.0.0-27478938.fdd6a91

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.
@@ -3,7 +3,7 @@ import hash from 'hash-sum';
3
3
  import { resolve } from 'pathe';
4
4
  import { genImport, genObjectFromRawEntries } from 'knitwork';
5
5
 
6
- const version = "3.0.0-27478656.5b2ed85";
6
+ const version = "3.0.0-27478938.fdd6a91";
7
7
 
8
8
  const middlewareTemplate = {
9
9
  filename: "middleware.js",
@@ -12,11 +12,15 @@ export interface AsyncDataOptions<DataT, Transform extends _Transform<DataT, any
12
12
  transform?: Transform;
13
13
  pick?: PickKeys;
14
14
  watch?: MultiWatchSources;
15
+ initialCache?: boolean;
16
+ }
17
+ export interface RefreshOptions {
18
+ _initial?: boolean;
15
19
  }
16
20
  export interface _AsyncData<DataT> {
17
21
  data: Ref<DataT>;
18
22
  pending: Ref<boolean>;
19
- refresh: (force?: boolean) => Promise<void>;
23
+ refresh: (opts?: RefreshOptions) => Promise<void>;
20
24
  error?: any;
21
25
  }
22
26
  export declare type AsyncData<Data> = _AsyncData<Data> & Promise<_AsyncData<Data>>;
@@ -13,6 +13,7 @@ export function useAsyncData(key, handler, options = {}) {
13
13
  console.warn("[useAsyncData] `defer` has been renamed to `lazy`. Support for `defer` will be removed in RC.");
14
14
  }
15
15
  options.lazy = options.lazy ?? options.defer ?? false;
16
+ options.initialCache = options.initialCache ?? true;
16
17
  const nuxt = useNuxtApp();
17
18
  const instance = getCurrentInstance();
18
19
  if (instance && !instance._nuxtOnBeforeMountCbs) {
@@ -32,10 +33,13 @@ export function useAsyncData(key, handler, options = {}) {
32
33
  pending: ref(true),
33
34
  error: ref(nuxt.payload._errors[key] ?? null)
34
35
  };
35
- asyncData.refresh = (force) => {
36
- if (nuxt._asyncDataPromises[key] && !force) {
36
+ asyncData.refresh = (opts = {}) => {
37
+ if (nuxt._asyncDataPromises[key]) {
37
38
  return nuxt._asyncDataPromises[key];
38
39
  }
40
+ if (opts._initial && options.initialCache && nuxt.payload.data[key] !== void 0) {
41
+ return nuxt.payload.data[key];
42
+ }
39
43
  asyncData.pending.value = true;
40
44
  nuxt._asyncDataPromises[key] = Promise.resolve(handler(nuxt)).then((result) => {
41
45
  if (options.transform) {
@@ -59,18 +63,19 @@ export function useAsyncData(key, handler, options = {}) {
59
63
  });
60
64
  return nuxt._asyncDataPromises[key];
61
65
  };
66
+ const initialFetch = () => asyncData.refresh({ _initial: true });
62
67
  const fetchOnServer = options.server !== false && nuxt.payload.serverRendered;
63
68
  if (process.server && fetchOnServer) {
64
- const promise = asyncData.refresh();
69
+ const promise = initialFetch();
65
70
  onServerPrefetch(() => promise);
66
71
  }
67
72
  if (process.client) {
68
73
  if (fetchOnServer && nuxt.isHydrating) {
69
74
  asyncData.pending.value = false;
70
75
  } else if (instance && (nuxt.isHydrating || options.lazy)) {
71
- instance._nuxtOnBeforeMountCbs.push(asyncData.refresh);
76
+ instance._nuxtOnBeforeMountCbs.push(initialFetch);
72
77
  } else {
73
- asyncData.refresh();
78
+ initialFetch();
74
79
  }
75
80
  if (options.watch) {
76
81
  watch(options.watch, () => asyncData.refresh());
@@ -3,8 +3,8 @@ import type { TypedInternalResponse } from '@nuxt/nitro';
3
3
  import { Ref } from 'vue';
4
4
  import type { AsyncDataOptions, _Transform, KeyOfRes } from './asyncData';
5
5
  export declare type FetchResult<ReqT extends FetchRequest> = TypedInternalResponse<ReqT, unknown>;
6
- export declare type UseFetchOptions<DataT, Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>> = AsyncDataOptions<DataT, Transform, PickKeys> & FetchOptions & {
6
+ export interface UseFetchOptions<DataT, Transform extends _Transform<DataT, any> = _Transform<DataT, DataT>, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>> extends AsyncDataOptions<DataT, Transform, PickKeys>, FetchOptions {
7
7
  key?: string;
8
- };
9
- export declare function useFetch<ResT = void, ReqT extends FetchRequest = FetchRequest, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, Transform, PickKeys>): import("./asyncData").AsyncData<import("./asyncData").PickFrom<ReturnType<Transform>, PickKeys>>;
10
- export declare function useLazyFetch<ResT = void, ReqT extends string = string, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, Transform, PickKeys>, 'lazy'>): import("./asyncData").AsyncData<import("./asyncData").PickFrom<ReturnType<Transform>, PickKeys>>;
8
+ }
9
+ export declare function useFetch<ResT = void, ReqT extends FetchRequest = FetchRequest, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: UseFetchOptions<_ResT, Transform, PickKeys>): import("./asyncData").AsyncData<any>;
10
+ export declare function useLazyFetch<ResT = void, ReqT extends string = string, _ResT = ResT extends void ? FetchResult<ReqT> : ResT, Transform extends (res: _ResT) => any = (res: _ResT) => _ResT, PickKeys extends KeyOfRes<Transform> = KeyOfRes<Transform>>(request: Ref<ReqT> | ReqT | (() => ReqT), opts?: Omit<UseFetchOptions<_ResT, Transform, PickKeys>, 'lazy'>): import("./asyncData").AsyncData<any>;
@@ -10,15 +10,20 @@ export function useFetch(request, opts = {}) {
10
10
  }
11
11
  return isRef(r) ? r.value : r;
12
12
  });
13
- const asyncData = useAsyncData(key, () => {
14
- return $fetch(_request.value, opts);
15
- }, {
13
+ const _fetchOptions = {
14
+ ...opts,
15
+ cache: typeof opts.cache === "boolean" ? void 0 : opts.cache
16
+ };
17
+ const _asyncDataOptions = {
16
18
  ...opts,
17
19
  watch: [
18
20
  _request,
19
21
  ...opts.watch || []
20
22
  ]
21
- });
23
+ };
24
+ const asyncData = useAsyncData(key, () => {
25
+ return $fetch(_request.value, _fetchOptions);
26
+ }, _asyncDataOptions);
22
27
  return asyncData;
23
28
  }
24
29
  export function useLazyFetch(request, opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/bridge-edge",
3
- "version": "3.0.0-27478656.5b2ed85",
3
+ "version": "3.0.0-27478938.fdd6a91",
4
4
  "repository": "nuxt/framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,10 +21,10 @@
21
21
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
22
22
  "@babel/plugin-proposal-optional-chaining": "^7.16.7",
23
23
  "@babel/plugin-transform-typescript": "^7.16.8",
24
- "@nuxt/kit": "npm:@nuxt/kit-edge@3.0.0-27478656.5b2ed85",
25
- "@nuxt/nitro": "npm:@nuxt/nitro-edge@3.0.0-27478656.5b2ed85",
24
+ "@nuxt/kit": "npm:@nuxt/kit-edge@3.0.0-27478938.fdd6a91",
25
+ "@nuxt/nitro": "npm:@nuxt/nitro-edge@3.0.0-27478938.fdd6a91",
26
26
  "@nuxt/postcss8": "^1.1.3",
27
- "@nuxt/schema": "npm:@nuxt/schema-edge@3.0.0-27478656.5b2ed85",
27
+ "@nuxt/schema": "npm:@nuxt/schema-edge@3.0.0-27478938.fdd6a91",
28
28
  "@vitejs/plugin-legacy": "^1.8.0",
29
29
  "@vue/composition-api": "^1.4.9",
30
30
  "@vueuse/head": "^0.7.5",
@@ -45,7 +45,7 @@
45
45
  "mlly": "^0.5.1",
46
46
  "murmurhash-es": "^0.1.1",
47
47
  "node-fetch": "^3.2.3",
48
- "nuxi": "npm:nuxi-edge@3.0.0-27478656.5b2ed85",
48
+ "nuxi": "npm:nuxi-edge@3.0.0-27478938.fdd6a91",
49
49
  "ohash": "^0.1.0",
50
50
  "pathe": "^0.2.0",
51
51
  "perfect-debounce": "^0.1.3",