@depup/nuxt 4.2.2-depup.0

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 (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/app.d.ts +1 -0
  4. package/bin/nuxt.mjs +2 -0
  5. package/config.cjs +7 -0
  6. package/config.d.ts +8 -0
  7. package/config.js +5 -0
  8. package/dist/app/compat/capi.d.ts +4 -0
  9. package/dist/app/compat/capi.js +19 -0
  10. package/dist/app/compat/idle-callback.d.ts +2 -0
  11. package/dist/app/compat/idle-callback.js +15 -0
  12. package/dist/app/compat/interval.d.ts +1 -0
  13. package/dist/app/compat/interval.js +11 -0
  14. package/dist/app/compat/vue-demi.d.ts +4 -0
  15. package/dist/app/compat/vue-demi.js +4 -0
  16. package/dist/app/components/client-fallback.client.d.ts +50 -0
  17. package/dist/app/components/client-fallback.client.js +50 -0
  18. package/dist/app/components/client-fallback.server.d.ts +57 -0
  19. package/dist/app/components/client-fallback.server.js +80 -0
  20. package/dist/app/components/client-only.d.ts +26 -0
  21. package/dist/app/components/client-only.js +130 -0
  22. package/dist/app/components/dev-only.d.ts +11 -0
  23. package/dist/app/components/dev-only.js +14 -0
  24. package/dist/app/components/error-404.d.vue.ts +51 -0
  25. package/dist/app/components/error-404.vue +48 -0
  26. package/dist/app/components/error-404.vue.d.ts +51 -0
  27. package/dist/app/components/error-500.d.vue.ts +51 -0
  28. package/dist/app/components/error-500.vue +46 -0
  29. package/dist/app/components/error-500.vue.d.ts +51 -0
  30. package/dist/app/components/index.d.ts +3 -0
  31. package/dist/app/components/index.js +1 -0
  32. package/dist/app/components/injections.d.ts +7 -0
  33. package/dist/app/components/injections.js +2 -0
  34. package/dist/app/components/island-renderer.d.ts +20 -0
  35. package/dist/app/components/island-renderer.js +28 -0
  36. package/dist/app/components/nuxt-error-boundary.d.vue.ts +24 -0
  37. package/dist/app/components/nuxt-error-boundary.vue +46 -0
  38. package/dist/app/components/nuxt-error-boundary.vue.d.ts +24 -0
  39. package/dist/app/components/nuxt-error-page.d.vue.ts +7 -0
  40. package/dist/app/components/nuxt-error-page.vue +27 -0
  41. package/dist/app/components/nuxt-error-page.vue.d.ts +7 -0
  42. package/dist/app/components/nuxt-island.d.ts +70 -0
  43. package/dist/app/components/nuxt-island.js +331 -0
  44. package/dist/app/components/nuxt-layout.d.ts +14 -0
  45. package/dist/app/components/nuxt-layout.js +171 -0
  46. package/dist/app/components/nuxt-link.d.ts +101 -0
  47. package/dist/app/components/nuxt-link.js +409 -0
  48. package/dist/app/components/nuxt-loading-indicator.d.ts +78 -0
  49. package/dist/app/components/nuxt-loading-indicator.js +75 -0
  50. package/dist/app/components/nuxt-root.d.vue.ts +3 -0
  51. package/dist/app/components/nuxt-root.vue +60 -0
  52. package/dist/app/components/nuxt-root.vue.d.ts +3 -0
  53. package/dist/app/components/nuxt-route-announcer.d.ts +26 -0
  54. package/dist/app/components/nuxt-route-announcer.js +48 -0
  55. package/dist/app/components/nuxt-stubs.d.ts +6 -0
  56. package/dist/app/components/nuxt-stubs.js +14 -0
  57. package/dist/app/components/nuxt-teleport-island-component.d.ts +22 -0
  58. package/dist/app/components/nuxt-teleport-island-component.js +38 -0
  59. package/dist/app/components/nuxt-teleport-island-slot.d.ts +32 -0
  60. package/dist/app/components/nuxt-teleport-island-slot.js +53 -0
  61. package/dist/app/components/nuxt-time.d.vue.ts +37 -0
  62. package/dist/app/components/nuxt-time.vue +148 -0
  63. package/dist/app/components/nuxt-time.vue.d.ts +37 -0
  64. package/dist/app/components/route-provider.d.ts +48 -0
  65. package/dist/app/components/route-provider.js +49 -0
  66. package/dist/app/components/server-placeholder.d.ts +2 -0
  67. package/dist/app/components/server-placeholder.js +7 -0
  68. package/dist/app/components/test-component-wrapper.d.ts +4 -0
  69. package/dist/app/components/test-component-wrapper.js +27 -0
  70. package/dist/app/components/utils.d.ts +48 -0
  71. package/dist/app/components/utils.js +126 -0
  72. package/dist/app/components/welcome.d.vue.ts +24 -0
  73. package/dist/app/components/welcome.vue +34 -0
  74. package/dist/app/components/welcome.vue.d.ts +24 -0
  75. package/dist/app/composables/asyncContext.d.ts +2 -0
  76. package/dist/app/composables/asyncContext.js +7 -0
  77. package/dist/app/composables/asyncData.d.ts +146 -0
  78. package/dist/app/composables/asyncData.js +491 -0
  79. package/dist/app/composables/chunk.d.ts +25 -0
  80. package/dist/app/composables/chunk.js +30 -0
  81. package/dist/app/composables/component.d.ts +4 -0
  82. package/dist/app/composables/component.js +82 -0
  83. package/dist/app/composables/cookie.d.ts +22 -0
  84. package/dist/app/composables/cookie.js +205 -0
  85. package/dist/app/composables/error.d.ts +25 -0
  86. package/dist/app/composables/error.js +39 -0
  87. package/dist/app/composables/fetch.d.ts +37 -0
  88. package/dist/app/composables/fetch.js +123 -0
  89. package/dist/app/composables/head.d.ts +1 -0
  90. package/dist/app/composables/head.js +1 -0
  91. package/dist/app/composables/hydrate.d.ts +9 -0
  92. package/dist/app/composables/hydrate.js +14 -0
  93. package/dist/app/composables/id.d.ts +3 -0
  94. package/dist/app/composables/id.js +2 -0
  95. package/dist/app/composables/index.d.ts +29 -0
  96. package/dist/app/composables/index.js +21 -0
  97. package/dist/app/composables/lazy-hydration.d.ts +40 -0
  98. package/dist/app/composables/lazy-hydration.js +2 -0
  99. package/dist/app/composables/loading-indicator.d.ts +39 -0
  100. package/dist/app/composables/loading-indicator.js +142 -0
  101. package/dist/app/composables/manifest.d.ts +20 -0
  102. package/dist/app/composables/manifest.js +59 -0
  103. package/dist/app/composables/once.d.ts +14 -0
  104. package/dist/app/composables/once.js +49 -0
  105. package/dist/app/composables/payload.d.ts +27 -0
  106. package/dist/app/composables/payload.js +137 -0
  107. package/dist/app/composables/preload.d.ts +20 -0
  108. package/dist/app/composables/preload.js +55 -0
  109. package/dist/app/composables/preview.d.ts +38 -0
  110. package/dist/app/composables/preview.js +61 -0
  111. package/dist/app/composables/ready.d.ts +2 -0
  112. package/dist/app/composables/ready.js +15 -0
  113. package/dist/app/composables/route-announcer.d.ts +19 -0
  114. package/dist/app/composables/route-announcer.js +55 -0
  115. package/dist/app/composables/router.d.ts +96 -0
  116. package/dist/app/composables/router.js +197 -0
  117. package/dist/app/composables/runtime-hook.d.ts +9 -0
  118. package/dist/app/composables/runtime-hook.js +7 -0
  119. package/dist/app/composables/script-stubs.d.ts +32 -0
  120. package/dist/app/composables/script-stubs.js +104 -0
  121. package/dist/app/composables/ssr.d.ts +33 -0
  122. package/dist/app/composables/ssr.js +113 -0
  123. package/dist/app/composables/state.d.ts +11 -0
  124. package/dist/app/composables/state.js +40 -0
  125. package/dist/app/composables/url.d.ts +3 -0
  126. package/dist/app/composables/url.js +8 -0
  127. package/dist/app/config.d.ts +14 -0
  128. package/dist/app/config.js +72 -0
  129. package/dist/app/entry-spa.d.ts +2 -0
  130. package/dist/app/entry-spa.js +2 -0
  131. package/dist/app/entry.async.d.ts +3 -0
  132. package/dist/app/entry.async.js +5 -0
  133. package/dist/app/entry.d.ts +7 -0
  134. package/dist/app/entry.js +78 -0
  135. package/dist/app/index.d.ts +12 -0
  136. package/dist/app/index.js +8 -0
  137. package/dist/app/middleware/manifest-route-rule.d.ts +2 -0
  138. package/dist/app/middleware/manifest-route-rule.js +17 -0
  139. package/dist/app/nuxt.d.ts +271 -0
  140. package/dist/app/nuxt.js +279 -0
  141. package/dist/app/plugins/browser-devtools-timing.client.d.ts +2 -0
  142. package/dist/app/plugins/browser-devtools-timing.client.js +23 -0
  143. package/dist/app/plugins/check-if-layout-used.d.ts +2 -0
  144. package/dist/app/plugins/check-if-layout-used.js +28 -0
  145. package/dist/app/plugins/check-outdated-build.client.d.ts +2 -0
  146. package/dist/app/plugins/check-outdated-build.client.js +39 -0
  147. package/dist/app/plugins/chunk-reload-immediate.client.d.ts +2 -0
  148. package/dist/app/plugins/chunk-reload-immediate.client.js +20 -0
  149. package/dist/app/plugins/chunk-reload.client.d.ts +2 -0
  150. package/dist/app/plugins/chunk-reload.client.js +30 -0
  151. package/dist/app/plugins/cross-origin-prefetch.client.d.ts +2 -0
  152. package/dist/app/plugins/cross-origin-prefetch.client.js +37 -0
  153. package/dist/app/plugins/debug-hooks.d.ts +2 -0
  154. package/dist/app/plugins/debug-hooks.js +9 -0
  155. package/dist/app/plugins/dev-server-logs.d.ts +2 -0
  156. package/dist/app/plugins/dev-server-logs.js +60 -0
  157. package/dist/app/plugins/navigation-repaint.client.d.ts +2 -0
  158. package/dist/app/plugins/navigation-repaint.client.js +16 -0
  159. package/dist/app/plugins/payload.client.d.ts +2 -0
  160. package/dist/app/plugins/payload.client.js +50 -0
  161. package/dist/app/plugins/preload.server.d.ts +2 -0
  162. package/dist/app/plugins/preload.server.js +13 -0
  163. package/dist/app/plugins/restore-state.client.d.ts +2 -0
  164. package/dist/app/plugins/restore-state.client.js +18 -0
  165. package/dist/app/plugins/revive-payload.client.d.ts +2 -0
  166. package/dist/app/plugins/revive-payload.client.js +44 -0
  167. package/dist/app/plugins/revive-payload.server.d.ts +2 -0
  168. package/dist/app/plugins/revive-payload.server.js +26 -0
  169. package/dist/app/plugins/router.d.ts +59 -0
  170. package/dist/app/plugins/router.js +222 -0
  171. package/dist/app/plugins/utils.d.ts +1 -0
  172. package/dist/app/plugins/utils.js +4 -0
  173. package/dist/app/plugins/view-transitions.client.d.ts +2 -0
  174. package/dist/app/plugins/view-transitions.client.js +55 -0
  175. package/dist/app/plugins/warn.dev.server.d.ts +2 -0
  176. package/dist/app/plugins/warn.dev.server.js +6 -0
  177. package/dist/app/types/augments.d.ts +49 -0
  178. package/dist/app/types/augments.js +0 -0
  179. package/dist/app/types.d.ts +39 -0
  180. package/dist/app/types.js +0 -0
  181. package/dist/app/utils.d.ts +13 -0
  182. package/dist/app/utils.js +34 -0
  183. package/dist/components/runtime/client-component.d.ts +2 -0
  184. package/dist/components/runtime/client-component.js +59 -0
  185. package/dist/components/runtime/lazy-hydrated-component.d.ts +124 -0
  186. package/dist/components/runtime/lazy-hydrated-component.js +101 -0
  187. package/dist/components/runtime/server-component.d.ts +20 -0
  188. package/dist/components/runtime/server-component.js +69 -0
  189. package/dist/head/runtime/components.d.ts +1058 -0
  190. package/dist/head/runtime/components.js +297 -0
  191. package/dist/head/runtime/composables.d.ts +25 -0
  192. package/dist/head/runtime/composables.js +47 -0
  193. package/dist/head/runtime/plugins/unhead.d.ts +2 -0
  194. package/dist/head/runtime/plugins/unhead.js +31 -0
  195. package/dist/head/runtime/types.d.ts +7 -0
  196. package/dist/head/runtime/types.js +0 -0
  197. package/dist/index.d.mts +9 -0
  198. package/dist/index.d.ts +9 -0
  199. package/dist/index.mjs +6974 -0
  200. package/dist/pages/runtime/app.d.vue.ts +3 -0
  201. package/dist/pages/runtime/app.vue +6 -0
  202. package/dist/pages/runtime/app.vue.d.ts +3 -0
  203. package/dist/pages/runtime/component-stub.d.ts +2 -0
  204. package/dist/pages/runtime/component-stub.js +1 -0
  205. package/dist/pages/runtime/composables.d.ts +58 -0
  206. package/dist/pages/runtime/composables.js +24 -0
  207. package/dist/pages/runtime/index.d.ts +3 -0
  208. package/dist/pages/runtime/index.js +1 -0
  209. package/dist/pages/runtime/page-placeholder.d.ts +4 -0
  210. package/dist/pages/runtime/page-placeholder.js +11 -0
  211. package/dist/pages/runtime/page.d.ts +30 -0
  212. package/dist/pages/runtime/page.js +212 -0
  213. package/dist/pages/runtime/plugins/check-if-page-unused.d.ts +2 -0
  214. package/dist/pages/runtime/plugins/check-if-page-unused.js +29 -0
  215. package/dist/pages/runtime/plugins/prefetch.client.d.ts +2 -0
  216. package/dist/pages/runtime/plugins/prefetch.client.js +41 -0
  217. package/dist/pages/runtime/plugins/prerender.server.d.ts +2 -0
  218. package/dist/pages/runtime/plugins/prerender.server.js +47 -0
  219. package/dist/pages/runtime/plugins/router.d.ts +6 -0
  220. package/dist/pages/runtime/plugins/router.js +236 -0
  221. package/dist/pages/runtime/router.options.d.ts +3 -0
  222. package/dist/pages/runtime/router.options.js +60 -0
  223. package/dist/pages/runtime/utils.d.ts +11 -0
  224. package/dist/pages/runtime/utils.js +18 -0
  225. package/dist/pages/runtime/validate.d.ts +2 -0
  226. package/dist/pages/runtime/validate.js +23 -0
  227. package/kit.d.ts +1 -0
  228. package/kit.js +1 -0
  229. package/package.json +156 -0
  230. package/schema.d.ts +1 -0
  231. package/schema.js +1 -0
  232. package/types.d.mts +14 -0
  233. package/types.d.ts +14 -0
@@ -0,0 +1,491 @@
1
+ import { computed, getCurrentInstance, getCurrentScope, inject, isShallow, nextTick, onBeforeMount, onScopeDispose, onServerPrefetch, onUnmounted, queuePostFlushCb, ref, shallowRef, toRef, toValue, unref, watch } from "vue";
2
+ import { debounce } from "perfect-debounce";
3
+ import { hash } from "ohash";
4
+ import { useNuxtApp } from "../nuxt.js";
5
+ import { getUserCaller, toArray } from "../utils.js";
6
+ import { clientOnlySymbol } from "../components/client-only.js";
7
+ import { createError } from "./error.js";
8
+ import { onNuxtReady } from "./ready.js";
9
+ import { asyncDataDefaults, granularCachedData, pendingWhenIdle, purgeCachedData } from "#build/nuxt.config.mjs";
10
+ export function useAsyncData(...args) {
11
+ const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
12
+ if (_isAutoKeyNeeded(args[0], args[1])) {
13
+ args.unshift(autoKey);
14
+ }
15
+ let [_key, _handler, options = {}] = args;
16
+ let keyChanging = false;
17
+ const key = computed(() => toValue(_key));
18
+ if (typeof key.value !== "string") {
19
+ throw new TypeError("[nuxt] [useAsyncData] key must be a string.");
20
+ }
21
+ if (typeof _handler !== "function") {
22
+ throw new TypeError("[nuxt] [useAsyncData] handler must be a function.");
23
+ }
24
+ const nuxtApp = useNuxtApp();
25
+ options.server ??= true;
26
+ options.default ??= getDefault;
27
+ options.getCachedData ??= getDefaultCachedData;
28
+ options.lazy ??= false;
29
+ options.immediate ??= true;
30
+ options.deep ??= asyncDataDefaults.deep;
31
+ options.dedupe ??= "cancel";
32
+ const functionName = options._functionName || "useAsyncData";
33
+ const currentData = nuxtApp._asyncData[key.value];
34
+ if (import.meta.dev && currentData) {
35
+ const warnings = [];
36
+ const values = createHash(_handler, options);
37
+ if (values.handler !== currentData._hash?.handler) {
38
+ warnings.push(`different handler`);
39
+ }
40
+ for (const opt of ["transform", "pick", "getCachedData"]) {
41
+ if (values[opt] !== currentData._hash[opt]) {
42
+ warnings.push(`different \`${opt}\` option`);
43
+ }
44
+ }
45
+ if (currentData._default.toString() !== options.default.toString()) {
46
+ warnings.push(`different \`default\` value`);
47
+ }
48
+ if (options.deep && isShallow(currentData.data)) {
49
+ warnings.push(`mismatching \`deep\` option`);
50
+ }
51
+ if (warnings.length) {
52
+ const caller = getUserCaller();
53
+ const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
54
+ console.warn(`[nuxt] [${functionName}] Incompatible options detected for "${key.value}"${explanation}:
55
+ ${warnings.map((w) => `- ${w}`).join("\n")}
56
+ You can use a different key or move the call to a composable to ensure the options are shared across calls.`);
57
+ }
58
+ }
59
+ function createInitialFetch() {
60
+ const initialFetchOptions = { cause: "initial", dedupe: options.dedupe };
61
+ if (!nuxtApp._asyncData[key.value]?._init) {
62
+ initialFetchOptions.cachedData = options.getCachedData(key.value, nuxtApp, { cause: "initial" });
63
+ nuxtApp._asyncData[key.value] = createAsyncData(nuxtApp, key.value, _handler, options, initialFetchOptions.cachedData);
64
+ }
65
+ return () => nuxtApp._asyncData[key.value].execute(initialFetchOptions);
66
+ }
67
+ const initialFetch = createInitialFetch();
68
+ const asyncData = nuxtApp._asyncData[key.value];
69
+ asyncData._deps++;
70
+ const fetchOnServer = options.server !== false && nuxtApp.payload.serverRendered;
71
+ if (import.meta.server && fetchOnServer && options.immediate) {
72
+ const promise = initialFetch();
73
+ if (getCurrentInstance()) {
74
+ onServerPrefetch(() => promise);
75
+ } else {
76
+ nuxtApp.hook("app:created", async () => {
77
+ await promise;
78
+ });
79
+ }
80
+ }
81
+ if (import.meta.client) {
82
+ let unregister = function(key2) {
83
+ const data = nuxtApp._asyncData[key2];
84
+ if (data?._deps) {
85
+ data._deps--;
86
+ if (data._deps === 0) {
87
+ data?._off();
88
+ }
89
+ }
90
+ };
91
+ const instance = getCurrentInstance();
92
+ if (instance && fetchOnServer && options.immediate && !instance.sp) {
93
+ instance.sp = [];
94
+ }
95
+ if (import.meta.dev && !nuxtApp.isHydrating && !nuxtApp._processingMiddleware && (!instance || instance?.isMounted)) {
96
+ console.warn(`[nuxt] [${functionName}] Component is already mounted, please use $fetch instead. See https://nuxt.com/docs/4.x/getting-started/data-fetching`);
97
+ }
98
+ if (instance && !instance._nuxtOnBeforeMountCbs) {
99
+ instance._nuxtOnBeforeMountCbs = [];
100
+ const cbs = instance._nuxtOnBeforeMountCbs;
101
+ onBeforeMount(() => {
102
+ cbs.forEach((cb) => {
103
+ cb();
104
+ });
105
+ cbs.splice(0, cbs.length);
106
+ });
107
+ onUnmounted(() => cbs.splice(0, cbs.length));
108
+ }
109
+ const isWithinClientOnly = instance && (instance._nuxtClientOnly || inject(clientOnlySymbol, false));
110
+ if (fetchOnServer && nuxtApp.isHydrating && (asyncData.error.value || asyncData.data.value !== void 0)) {
111
+ if (pendingWhenIdle) {
112
+ asyncData.pending.value = false;
113
+ }
114
+ asyncData.status.value = asyncData.error.value ? "error" : "success";
115
+ } else if (instance && (!isWithinClientOnly && nuxtApp.payload.serverRendered && nuxtApp.isHydrating || options.lazy) && options.immediate) {
116
+ instance._nuxtOnBeforeMountCbs.push(initialFetch);
117
+ } else if (options.immediate && asyncData.status.value !== "success") {
118
+ initialFetch();
119
+ }
120
+ const hasScope = getCurrentScope();
121
+ const unsubKeyWatcher = watch(key, (newKey, oldKey) => {
122
+ if ((newKey || oldKey) && newKey !== oldKey) {
123
+ keyChanging = true;
124
+ const hadData = nuxtApp._asyncData[oldKey]?.data.value !== void 0;
125
+ const wasRunning = nuxtApp._asyncDataPromises[oldKey] !== void 0;
126
+ const initialFetchOptions = { cause: "initial", dedupe: options.dedupe };
127
+ if (!nuxtApp._asyncData[newKey]?._init) {
128
+ let initialValue;
129
+ if (oldKey && hadData) {
130
+ initialValue = nuxtApp._asyncData[oldKey].data.value;
131
+ } else {
132
+ initialValue = options.getCachedData(newKey, nuxtApp, { cause: "initial" });
133
+ initialFetchOptions.cachedData = initialValue;
134
+ }
135
+ nuxtApp._asyncData[newKey] = createAsyncData(nuxtApp, newKey, _handler, options, initialValue);
136
+ }
137
+ nuxtApp._asyncData[newKey]._deps++;
138
+ if (oldKey) {
139
+ unregister(oldKey);
140
+ }
141
+ if (options.immediate || hadData || wasRunning) {
142
+ nuxtApp._asyncData[newKey].execute(initialFetchOptions);
143
+ }
144
+ queuePostFlushCb(() => {
145
+ keyChanging = false;
146
+ });
147
+ }
148
+ }, { flush: "sync" });
149
+ const unsubParamsWatcher = options.watch ? watch(options.watch, () => {
150
+ if (keyChanging) {
151
+ return;
152
+ }
153
+ nuxtApp._asyncData[key.value]?._execute({ cause: "watch", dedupe: options.dedupe });
154
+ }) : () => {
155
+ };
156
+ if (hasScope) {
157
+ onScopeDispose(() => {
158
+ unsubKeyWatcher();
159
+ unsubParamsWatcher();
160
+ unregister(key.value);
161
+ });
162
+ }
163
+ }
164
+ const asyncReturn = {
165
+ data: writableComputedRef(() => nuxtApp._asyncData[key.value]?.data),
166
+ pending: writableComputedRef(() => nuxtApp._asyncData[key.value]?.pending),
167
+ status: writableComputedRef(() => nuxtApp._asyncData[key.value]?.status),
168
+ error: writableComputedRef(() => nuxtApp._asyncData[key.value]?.error),
169
+ refresh: (...args2) => {
170
+ if (!nuxtApp._asyncData[key.value]?._init) {
171
+ const initialFetch2 = createInitialFetch();
172
+ return initialFetch2();
173
+ }
174
+ return nuxtApp._asyncData[key.value].execute(...args2);
175
+ },
176
+ execute: (...args2) => asyncReturn.refresh(...args2),
177
+ clear: () => {
178
+ const entry = nuxtApp._asyncData[key.value];
179
+ if (entry?._abortController) {
180
+ try {
181
+ entry._abortController.abort(new DOMException("AsyncData aborted by user.", "AbortError"));
182
+ } finally {
183
+ entry._abortController = void 0;
184
+ }
185
+ }
186
+ clearNuxtDataByKey(nuxtApp, key.value);
187
+ }
188
+ };
189
+ const asyncDataPromise = Promise.resolve(nuxtApp._asyncDataPromises[key.value]).then(() => asyncReturn);
190
+ Object.assign(asyncDataPromise, asyncReturn);
191
+ return asyncDataPromise;
192
+ }
193
+ function writableComputedRef(getter) {
194
+ return computed({
195
+ get() {
196
+ return getter()?.value;
197
+ },
198
+ set(value) {
199
+ const ref2 = getter();
200
+ if (ref2) {
201
+ ref2.value = value;
202
+ }
203
+ }
204
+ });
205
+ }
206
+ export function useLazyAsyncData(...args) {
207
+ const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
208
+ if (_isAutoKeyNeeded(args[0], args[1])) {
209
+ args.unshift(autoKey);
210
+ }
211
+ const [key, handler, options = {}] = args;
212
+ if (import.meta.dev) {
213
+ options._functionName ||= "useLazyAsyncData";
214
+ }
215
+ return useAsyncData(key, handler, { ...options, lazy: true }, null);
216
+ }
217
+ function _isAutoKeyNeeded(keyOrFetcher, fetcher) {
218
+ if (typeof keyOrFetcher === "string") {
219
+ return false;
220
+ }
221
+ if (typeof keyOrFetcher === "object" && keyOrFetcher !== null) {
222
+ return false;
223
+ }
224
+ if (typeof keyOrFetcher === "function" && typeof fetcher === "function") {
225
+ return false;
226
+ }
227
+ return true;
228
+ }
229
+ export function useNuxtData(key) {
230
+ const nuxtApp = useNuxtApp();
231
+ if (!(key in nuxtApp.payload.data)) {
232
+ nuxtApp.payload.data[key] = void 0;
233
+ }
234
+ if (nuxtApp._asyncData[key]) {
235
+ const data = nuxtApp._asyncData[key];
236
+ data._deps++;
237
+ if (getCurrentScope()) {
238
+ onScopeDispose(() => {
239
+ data._deps--;
240
+ if (data._deps === 0) {
241
+ data?._off();
242
+ }
243
+ });
244
+ }
245
+ }
246
+ return {
247
+ data: computed({
248
+ get() {
249
+ return nuxtApp._asyncData[key]?.data.value ?? nuxtApp.payload.data[key];
250
+ },
251
+ set(value) {
252
+ if (nuxtApp._asyncData[key]) {
253
+ nuxtApp._asyncData[key].data.value = value;
254
+ } else {
255
+ nuxtApp.payload.data[key] = value;
256
+ }
257
+ }
258
+ })
259
+ };
260
+ }
261
+ export async function refreshNuxtData(keys) {
262
+ if (import.meta.server) {
263
+ return Promise.resolve();
264
+ }
265
+ await new Promise((resolve) => onNuxtReady(resolve));
266
+ const _keys = keys ? toArray(keys) : void 0;
267
+ await useNuxtApp().hooks.callHookParallel("app:data:refresh", _keys);
268
+ }
269
+ export function clearNuxtData(keys) {
270
+ const nuxtApp = useNuxtApp();
271
+ const _allKeys = Object.keys(nuxtApp.payload.data);
272
+ const _keys = !keys ? _allKeys : typeof keys === "function" ? _allKeys.filter(keys) : toArray(keys);
273
+ for (const key of _keys) {
274
+ clearNuxtDataByKey(nuxtApp, key);
275
+ }
276
+ }
277
+ function clearNuxtDataByKey(nuxtApp, key) {
278
+ if (key in nuxtApp.payload.data) {
279
+ nuxtApp.payload.data[key] = void 0;
280
+ }
281
+ if (key in nuxtApp.payload._errors) {
282
+ nuxtApp.payload._errors[key] = void 0;
283
+ }
284
+ if (nuxtApp._asyncData[key]) {
285
+ nuxtApp._asyncData[key].data.value = unref(nuxtApp._asyncData[key]._default());
286
+ nuxtApp._asyncData[key].error.value = void 0;
287
+ if (pendingWhenIdle) {
288
+ nuxtApp._asyncData[key].pending.value = false;
289
+ }
290
+ nuxtApp._asyncData[key].status.value = "idle";
291
+ }
292
+ if (key in nuxtApp._asyncDataPromises) {
293
+ nuxtApp._asyncDataPromises[key] = void 0;
294
+ }
295
+ }
296
+ function pick(obj, keys) {
297
+ const newObj = {};
298
+ for (const key of keys) {
299
+ newObj[key] = obj[key];
300
+ }
301
+ return newObj;
302
+ }
303
+ function createAsyncData(nuxtApp, key, _handler, options, initialCachedData) {
304
+ nuxtApp.payload._errors[key] ??= void 0;
305
+ const hasCustomGetCachedData = options.getCachedData !== getDefaultCachedData;
306
+ const handler = import.meta.client || !import.meta.prerender || !nuxtApp.ssrContext?._sharedPrerenderCache ? _handler : (nuxtApp2, options2) => {
307
+ const value = nuxtApp2.ssrContext._sharedPrerenderCache.get(key);
308
+ if (value) {
309
+ return value;
310
+ }
311
+ const promise = Promise.resolve().then(() => nuxtApp2.runWithContext(() => _handler(nuxtApp2, options2)));
312
+ nuxtApp2.ssrContext._sharedPrerenderCache.set(key, promise);
313
+ return promise;
314
+ };
315
+ const _ref = options.deep ? ref : shallowRef;
316
+ const hasCachedData = initialCachedData !== void 0;
317
+ const unsubRefreshAsyncData = nuxtApp.hook("app:data:refresh", async (keys) => {
318
+ if (!keys || keys.includes(key)) {
319
+ await asyncData.execute({ cause: "refresh:hook" });
320
+ }
321
+ });
322
+ const asyncData = {
323
+ data: _ref(hasCachedData ? initialCachedData : options.default()),
324
+ pending: pendingWhenIdle ? shallowRef(!hasCachedData) : computed(() => asyncData.status.value === "pending"),
325
+ error: toRef(nuxtApp.payload._errors, key),
326
+ status: shallowRef("idle"),
327
+ execute: (...args) => {
328
+ const [_opts, newValue = void 0] = args;
329
+ const opts = _opts && newValue === void 0 && typeof _opts === "object" ? _opts : {};
330
+ if (import.meta.dev && newValue !== void 0 && (!_opts || typeof _opts !== "object")) {
331
+ console.warn(`[nuxt] [${options._functionName}] Do not pass \`execute\` directly to \`watch\`. Instead, use an inline function, such as \`watch(q, () => execute())\`.`);
332
+ }
333
+ if (nuxtApp._asyncDataPromises[key]) {
334
+ if ((opts.dedupe ?? options.dedupe) === "defer") {
335
+ return nuxtApp._asyncDataPromises[key];
336
+ }
337
+ }
338
+ if (granularCachedData || opts.cause === "initial" || nuxtApp.isHydrating) {
339
+ const cachedData = "cachedData" in opts ? opts.cachedData : options.getCachedData(key, nuxtApp, { cause: opts.cause ?? "refresh:manual" });
340
+ if (cachedData !== void 0) {
341
+ nuxtApp.payload.data[key] = asyncData.data.value = cachedData;
342
+ asyncData.error.value = void 0;
343
+ asyncData.status.value = "success";
344
+ return Promise.resolve(cachedData);
345
+ }
346
+ }
347
+ if (pendingWhenIdle) {
348
+ asyncData.pending.value = true;
349
+ }
350
+ if (asyncData._abortController) {
351
+ asyncData._abortController.abort(new DOMException("AsyncData request cancelled by deduplication", "AbortError"));
352
+ }
353
+ asyncData._abortController = new AbortController();
354
+ asyncData.status.value = "pending";
355
+ const cleanupController = new AbortController();
356
+ const promise = new Promise(
357
+ (resolve, reject) => {
358
+ try {
359
+ const timeout = opts.timeout ?? options.timeout;
360
+ const mergedSignal = mergeAbortSignals([asyncData._abortController?.signal, opts?.signal], cleanupController.signal, timeout);
361
+ if (mergedSignal.aborted) {
362
+ const reason = mergedSignal.reason;
363
+ reject(reason instanceof Error ? reason : new DOMException(String(reason ?? "Aborted"), "AbortError"));
364
+ return;
365
+ }
366
+ mergedSignal.addEventListener("abort", () => {
367
+ const reason = mergedSignal.reason;
368
+ reject(reason instanceof Error ? reason : new DOMException(String(reason ?? "Aborted"), "AbortError"));
369
+ }, { once: true, signal: cleanupController.signal });
370
+ return Promise.resolve(handler(nuxtApp, { signal: mergedSignal })).then(resolve, reject);
371
+ } catch (err) {
372
+ reject(err);
373
+ }
374
+ }
375
+ ).then(async (_result) => {
376
+ let result = _result;
377
+ if (options.transform) {
378
+ result = await options.transform(_result);
379
+ }
380
+ if (options.pick) {
381
+ result = pick(result, options.pick);
382
+ }
383
+ if (import.meta.dev && import.meta.server && typeof result === "undefined") {
384
+ const caller = getUserCaller();
385
+ const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
386
+ console.warn(`[nuxt] \`${options._functionName || "useAsyncData"}${explanation}\` must return a value (it should not be \`undefined\`) or the request may be duplicated on the client side.`);
387
+ }
388
+ nuxtApp.payload.data[key] = result;
389
+ asyncData.data.value = result;
390
+ asyncData.error.value = void 0;
391
+ asyncData.status.value = "success";
392
+ }).catch((error) => {
393
+ if (nuxtApp._asyncDataPromises[key] && nuxtApp._asyncDataPromises[key] !== promise) {
394
+ return nuxtApp._asyncDataPromises[key];
395
+ }
396
+ if (asyncData._abortController?.signal.aborted) {
397
+ return nuxtApp._asyncDataPromises[key];
398
+ }
399
+ if (typeof DOMException !== "undefined" && error instanceof DOMException && error.name === "AbortError") {
400
+ asyncData.status.value = "idle";
401
+ return nuxtApp._asyncDataPromises[key];
402
+ }
403
+ asyncData.error.value = createError(error);
404
+ asyncData.data.value = unref(options.default());
405
+ asyncData.status.value = "error";
406
+ }).finally(() => {
407
+ if (pendingWhenIdle) {
408
+ asyncData.pending.value = false;
409
+ }
410
+ cleanupController.abort();
411
+ delete nuxtApp._asyncDataPromises[key];
412
+ });
413
+ nuxtApp._asyncDataPromises[key] = promise;
414
+ return nuxtApp._asyncDataPromises[key];
415
+ },
416
+ _execute: debounce((...args) => asyncData.execute(...args), 0, { leading: true }),
417
+ _default: options.default,
418
+ _deps: 0,
419
+ _init: true,
420
+ _hash: import.meta.dev ? createHash(_handler, options) : void 0,
421
+ _off: () => {
422
+ unsubRefreshAsyncData();
423
+ if (nuxtApp._asyncData[key]?._init) {
424
+ nuxtApp._asyncData[key]._init = false;
425
+ }
426
+ if (purgeCachedData && !hasCustomGetCachedData) {
427
+ nextTick(() => {
428
+ if (!nuxtApp._asyncData[key]?._init) {
429
+ clearNuxtDataByKey(nuxtApp, key);
430
+ asyncData.execute = () => Promise.resolve();
431
+ }
432
+ });
433
+ }
434
+ }
435
+ };
436
+ return asyncData;
437
+ }
438
+ const getDefault = () => void 0;
439
+ const getDefaultCachedData = (key, nuxtApp, ctx) => {
440
+ if (nuxtApp.isHydrating) {
441
+ return nuxtApp.payload.data[key];
442
+ }
443
+ if (ctx.cause !== "refresh:manual" && ctx.cause !== "refresh:hook") {
444
+ return nuxtApp.static.data[key];
445
+ }
446
+ };
447
+ function createHash(_handler, options) {
448
+ return {
449
+ handler: hash(_handler),
450
+ transform: options.transform ? hash(options.transform) : void 0,
451
+ pick: options.pick ? hash(options.pick) : void 0,
452
+ getCachedData: options.getCachedData ? hash(options.getCachedData) : void 0
453
+ };
454
+ }
455
+ function mergeAbortSignals(signals, cleanupSignal, timeout) {
456
+ const list = signals.filter((s) => !!s);
457
+ if (typeof timeout === "number" && timeout >= 0) {
458
+ const timeoutSignal = AbortSignal.timeout?.(timeout);
459
+ if (timeoutSignal) {
460
+ list.push(timeoutSignal);
461
+ }
462
+ }
463
+ if (AbortSignal.any) {
464
+ return AbortSignal.any(list);
465
+ }
466
+ const controller = new AbortController();
467
+ for (const sig of list) {
468
+ if (sig.aborted) {
469
+ const reason = sig.reason ?? new DOMException("Aborted", "AbortError");
470
+ try {
471
+ controller.abort(reason);
472
+ } catch {
473
+ controller.abort();
474
+ }
475
+ return controller.signal;
476
+ }
477
+ }
478
+ const onAbort = () => {
479
+ const abortedSignal = list.find((s) => s.aborted);
480
+ const reason = abortedSignal?.reason ?? new DOMException("Aborted", "AbortError");
481
+ try {
482
+ controller.abort(reason);
483
+ } catch {
484
+ controller.abort();
485
+ }
486
+ };
487
+ for (const sig of list) {
488
+ sig.addEventListener?.("abort", onAbort, { once: true, signal: cleanupSignal });
489
+ }
490
+ return controller.signal;
491
+ }
@@ -0,0 +1,25 @@
1
+ export interface ReloadNuxtAppOptions {
2
+ /**
3
+ * Number of milliseconds in which to ignore future reload requests
4
+ * @default {10000}
5
+ */
6
+ ttl?: number;
7
+ /**
8
+ * Force a reload even if one has occurred within the previously specified TTL.
9
+ * @default {false}
10
+ */
11
+ force?: boolean;
12
+ /**
13
+ * Whether to dump the current Nuxt state to sessionStorage (as `nuxt:reload:state`).
14
+ * @default {false}
15
+ */
16
+ persistState?: boolean;
17
+ /**
18
+ * The path to reload. If this is different from the current window location it will
19
+ * trigger a navigation and add an entry in the browser history.
20
+ * @default {window.location.pathname}
21
+ */
22
+ path?: string;
23
+ }
24
+ /** @since 3.3.0 */
25
+ export declare function reloadNuxtApp(options?: ReloadNuxtAppOptions): void;
@@ -0,0 +1,30 @@
1
+ import destr from "destr";
2
+ import { useNuxtApp } from "../nuxt.js";
3
+ export function reloadNuxtApp(options = {}) {
4
+ if (import.meta.server) {
5
+ return;
6
+ }
7
+ const path = options.path || window.location.pathname;
8
+ let handledPath = {};
9
+ try {
10
+ handledPath = destr(sessionStorage.getItem("nuxt:reload") || "{}");
11
+ } catch {
12
+ }
13
+ if (options.force || handledPath?.path !== path || handledPath?.expires < Date.now()) {
14
+ try {
15
+ sessionStorage.setItem("nuxt:reload", JSON.stringify({ path, expires: Date.now() + (options.ttl ?? 1e4) }));
16
+ } catch {
17
+ }
18
+ if (options.persistState) {
19
+ try {
20
+ sessionStorage.setItem("nuxt:reload:state", JSON.stringify({ state: useNuxtApp().payload.state }));
21
+ } catch {
22
+ }
23
+ }
24
+ if (window.location.pathname !== path) {
25
+ window.location.href = path;
26
+ } else {
27
+ window.location.reload();
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,4 @@
1
+ import type { defineComponent } from 'vue';
2
+ export declare const NuxtComponentIndicator = "__nuxt_component";
3
+ /** @since 3.0.0 */
4
+ export declare const defineNuxtComponent: typeof defineComponent;
@@ -0,0 +1,82 @@
1
+ import { computed, getCurrentInstance } from "vue";
2
+ import { hash } from "ohash";
3
+ import { getNuxtAppCtx, useNuxtApp } from "../nuxt.js";
4
+ import { useHead } from "./head.js";
5
+ import { useAsyncData } from "./asyncData.js";
6
+ import { useRoute } from "./router.js";
7
+ import { createError } from "./error.js";
8
+ export const NuxtComponentIndicator = "__nuxt_component";
9
+ // @__NO_SIDE_EFFECTS__
10
+ function getFetchKey() {
11
+ const vm = getCurrentInstance();
12
+ const route = useRoute();
13
+ const { _fetchKeyBase } = vm.proxy.$options;
14
+ return hash([
15
+ _fetchKeyBase,
16
+ route.path,
17
+ route.query,
18
+ route.matched.findIndex((r) => Object.values(r.components || {}).includes(vm.type))
19
+ ]);
20
+ }
21
+ async function runLegacyAsyncData(res, fn) {
22
+ const nuxtApp = useNuxtApp();
23
+ const { fetchKey } = getCurrentInstance().proxy.$options;
24
+ const key = (typeof fetchKey === "function" ? fetchKey(() => "") : fetchKey) || /* @__PURE__ */ getFetchKey();
25
+ const { data, error } = await useAsyncData(`options:asyncdata:${key}`, () => import.meta.server ? nuxtApp.runWithContext(() => fn(nuxtApp)) : fn(nuxtApp));
26
+ if (error.value) {
27
+ throw createError(error.value);
28
+ }
29
+ if (data.value && typeof data.value === "object") {
30
+ const _res = await res;
31
+ for (const key2 in data.value) {
32
+ _res[key2] = computed({
33
+ get: () => data.value?.[key2],
34
+ set(v) {
35
+ data.value ||= {};
36
+ data.value[key2] = v;
37
+ }
38
+ });
39
+ }
40
+ } else if (import.meta.dev) {
41
+ console.warn("[nuxt] asyncData should return an object", data);
42
+ }
43
+ }
44
+ export const defineNuxtComponent = /* @__NO_SIDE_EFFECTS__ */ function defineNuxtComponent2(...args) {
45
+ const [options, key] = args;
46
+ const { setup } = options;
47
+ if (!setup && !options.asyncData && !options.head) {
48
+ return {
49
+ [NuxtComponentIndicator]: true,
50
+ ...options
51
+ };
52
+ }
53
+ return {
54
+ [NuxtComponentIndicator]: true,
55
+ _fetchKeyBase: key,
56
+ ...options,
57
+ setup(props, ctx) {
58
+ const nuxtApp = useNuxtApp();
59
+ let res = {};
60
+ if (setup) {
61
+ const fn = () => Promise.resolve(setup(props, ctx)).then((r) => r || {});
62
+ const nuxtAppCtx = getNuxtAppCtx(nuxtApp._id);
63
+ if (import.meta.server) {
64
+ res = nuxtAppCtx.callAsync(nuxtApp, fn);
65
+ } else {
66
+ nuxtAppCtx.set(nuxtApp);
67
+ res = fn();
68
+ }
69
+ }
70
+ const promises = [];
71
+ if (options.asyncData) {
72
+ promises.push(runLegacyAsyncData(res, options.asyncData));
73
+ }
74
+ if (options.head) {
75
+ useHead(typeof options.head === "function" ? () => options.head(nuxtApp) : options.head);
76
+ }
77
+ return Promise.resolve(res).then(() => Promise.all(promises)).then(() => res).finally(() => {
78
+ promises.length = 0;
79
+ });
80
+ }
81
+ };
82
+ };
@@ -0,0 +1,22 @@
1
+ import type { Ref } from 'vue';
2
+ import type { CookieParseOptions, CookieSerializeOptions } from 'cookie-es';
3
+ type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, 'decode' | 'encode'>;
4
+ export interface CookieOptions<T = any> extends _CookieOptions {
5
+ decode?(value: string): T;
6
+ encode?(value: T): string;
7
+ default?: () => T | Ref<T>;
8
+ watch?: boolean | 'shallow';
9
+ readonly?: boolean;
10
+ }
11
+ export interface CookieRef<T> extends Ref<T> {
12
+ }
13
+ /** @since 3.0.0 */
14
+ export declare function useCookie<T = string | null | undefined>(name: string, _opts?: CookieOptions<T> & {
15
+ readonly?: false;
16
+ }): CookieRef<T>;
17
+ export declare function useCookie<T = string | null | undefined>(name: string, _opts: CookieOptions<T> & {
18
+ readonly: true;
19
+ }): Readonly<CookieRef<T>>;
20
+ /** @since 3.10.0 */
21
+ export declare function refreshCookie(name: string): void;
22
+ export {};