@vizejs/musea-nuxt 0.463.0 → 0.467.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.
- package/dist/auto-imports.d.mts +3 -0
- package/dist/auto-imports.mjs +3 -0
- package/dist/error-k5KbRk2C.mjs +507 -0
- package/dist/index.d.mts +2 -295
- package/dist/index.mjs +10 -519
- package/dist/runtime-DQQ-6lr_.d.mts +297 -0
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { computed, defineComponent, h, reactive, ref, toValue } from "vue";
|
|
1
|
+
import { A as useRequestURL, B as preloadComponents, C as updateAppConfig, D as useNuxtApp, E as useId, F as abortNavigation, G as getRouteState, H as setPageLayout, I as defineNuxtRouteMiddleware, J as resolveNavigationTarget, K as getRuntimeConfigState, L as definePageMeta, M as useState, N as useRoute, O as useRequestEvent, P as useRouter, R as navigateTo, S as reloadNuxtApp, T as useCookie, U as configureNuxtMuseaMocks, V as preloadRouteComponents, W as getAppConfigState, _ as callOnce, a as useHead, b as defineNuxtPlugin, c as useServerSeoMeta, d as useAsyncData, f as useFetch, g as useRequestFetch, h as useNuxtData, i as useError, j as useRuntimeConfig, k as useRequestHeaders, l as clearNuxtData, m as useLazyFetch, n as createError, o as useHeadSafe, p as useLazyAsyncData, q as resetNuxtMuseaMocks, r as showError, s as useSeoMeta, t as clearError, u as refreshNuxtData, v as clearNuxtState, w as useAppConfig, x as onNuxtReady, y as defineNuxtComponent, z as prefetchComponents } from "./error-k5KbRk2C.mjs";
|
|
2
|
+
import { defineComponent, h } from "vue";
|
|
4
3
|
//#region src/plugin.ts
|
|
5
4
|
const VIRTUAL_IMPORTS_ID = "\0musea-nuxt:imports";
|
|
6
5
|
const VIRTUAL_NUXT_COMPONENTS_ID = "\0musea-nuxt:components";
|
|
@@ -16,7 +15,6 @@ const NUXT_COMPONENT_IDS = new Set([
|
|
|
16
15
|
"nuxt/dist/app/components"
|
|
17
16
|
]);
|
|
18
17
|
function createNuxtMuseaPlugin(options = {}) {
|
|
19
|
-
const srcDir = path.dirname(fileURLToPath(import.meta.url));
|
|
20
18
|
return {
|
|
21
19
|
name: "vite-plugin-musea-nuxt",
|
|
22
20
|
enforce: "pre",
|
|
@@ -26,27 +24,25 @@ function createNuxtMuseaPlugin(options = {}) {
|
|
|
26
24
|
return null;
|
|
27
25
|
},
|
|
28
26
|
load(id) {
|
|
29
|
-
if (id === VIRTUAL_IMPORTS_ID) return generateImportsModule(
|
|
30
|
-
if (id === VIRTUAL_NUXT_COMPONENTS_ID) return generateComponentsModule(
|
|
27
|
+
if (id === VIRTUAL_IMPORTS_ID) return generateImportsModule(options);
|
|
28
|
+
if (id === VIRTUAL_NUXT_COMPONENTS_ID) return generateComponentsModule();
|
|
31
29
|
return null;
|
|
32
30
|
}
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
|
-
function generateImportsModule(
|
|
36
|
-
const autoImportsPath = path.join(srcDir, "auto-imports.js").replace(/\\/g, "/");
|
|
37
|
-
const configJson = JSON.stringify(options);
|
|
33
|
+
function generateImportsModule(options) {
|
|
38
34
|
return `
|
|
39
35
|
// Auto-generated by @vizejs/musea-nuxt
|
|
40
|
-
export * from
|
|
36
|
+
export * from "@vizejs/musea-nuxt/auto-imports";
|
|
41
37
|
|
|
42
38
|
// Configure mocks with provided options
|
|
43
|
-
import { configureNuxtMuseaMocks } from
|
|
39
|
+
import { configureNuxtMuseaMocks } from "@vizejs/musea-nuxt";
|
|
44
40
|
|
|
45
|
-
const _config = ${
|
|
41
|
+
const _config = ${JSON.stringify(options)};
|
|
46
42
|
configureNuxtMuseaMocks(_config);
|
|
47
43
|
`;
|
|
48
44
|
}
|
|
49
|
-
function generateComponentsModule(
|
|
45
|
+
function generateComponentsModule() {
|
|
50
46
|
return `
|
|
51
47
|
// Auto-generated by @vizejs/musea-nuxt
|
|
52
48
|
export {
|
|
@@ -64,259 +60,10 @@ export {
|
|
|
64
60
|
NuxtPicture,
|
|
65
61
|
RouterLink,
|
|
66
62
|
RouterView,
|
|
67
|
-
} from
|
|
63
|
+
} from "@vizejs/musea-nuxt";
|
|
68
64
|
`;
|
|
69
65
|
}
|
|
70
66
|
//#endregion
|
|
71
|
-
//#region src/context.ts
|
|
72
|
-
const DEFAULT_REQUEST_URL = "http://localhost:3000/";
|
|
73
|
-
const routeState = reactive(createRoute({}));
|
|
74
|
-
const runtimeConfigState = reactive({ public: {} });
|
|
75
|
-
const appConfigState = reactive({});
|
|
76
|
-
const requestState = reactive({
|
|
77
|
-
url: DEFAULT_REQUEST_URL,
|
|
78
|
-
headers: {}
|
|
79
|
-
});
|
|
80
|
-
const stateRefs = /* @__PURE__ */ new Map();
|
|
81
|
-
const cookieRefs = /* @__PURE__ */ new Map();
|
|
82
|
-
const callOnceKeys = /* @__PURE__ */ new Set();
|
|
83
|
-
const fetchMocksState = {};
|
|
84
|
-
const errorRef = ref(null);
|
|
85
|
-
let idCounter = 0;
|
|
86
|
-
function configureNuxtMuseaMocks(options = {}) {
|
|
87
|
-
setRouteConfig(options.route ?? {});
|
|
88
|
-
setRuntimeConfig(options.runtimeConfig ?? {});
|
|
89
|
-
setAppConfig(options.appConfig ?? {});
|
|
90
|
-
setFetchMocks(options.fetchMocks ?? {});
|
|
91
|
-
setStateMocks(options.stateMocks ?? {});
|
|
92
|
-
setCookieMocks(options.cookieMocks ?? {});
|
|
93
|
-
setRequestConfig(options.request ?? {});
|
|
94
|
-
}
|
|
95
|
-
function resetNuxtMuseaMocks() {
|
|
96
|
-
setRouteConfig({});
|
|
97
|
-
setRuntimeConfig({});
|
|
98
|
-
setAppConfig({});
|
|
99
|
-
setFetchMocks({});
|
|
100
|
-
setRequestConfig({});
|
|
101
|
-
stateRefs.clear();
|
|
102
|
-
cookieRefs.clear();
|
|
103
|
-
callOnceKeys.clear();
|
|
104
|
-
errorRef.value = null;
|
|
105
|
-
idCounter = 0;
|
|
106
|
-
}
|
|
107
|
-
function getRouteState() {
|
|
108
|
-
return routeState;
|
|
109
|
-
}
|
|
110
|
-
function setRouteConfig(config) {
|
|
111
|
-
Object.assign(routeState, createRoute(config));
|
|
112
|
-
}
|
|
113
|
-
function resolveNavigationTarget(target) {
|
|
114
|
-
if (typeof target === "string") return createRoute({ path: target });
|
|
115
|
-
return createRoute({
|
|
116
|
-
path: target.path,
|
|
117
|
-
name: target.name ?? null,
|
|
118
|
-
params: target.params,
|
|
119
|
-
query: target.query,
|
|
120
|
-
hash: target.hash,
|
|
121
|
-
meta: typeof target.meta === "object" && target.meta != null ? target.meta : void 0
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function getRuntimeConfigState() {
|
|
125
|
-
return runtimeConfigState;
|
|
126
|
-
}
|
|
127
|
-
function setRuntimeConfig(config) {
|
|
128
|
-
replaceRecord(runtimeConfigState, {
|
|
129
|
-
public: {},
|
|
130
|
-
...config
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function getAppConfigState() {
|
|
134
|
-
return appConfigState;
|
|
135
|
-
}
|
|
136
|
-
function setAppConfig(config) {
|
|
137
|
-
replaceRecord(appConfigState, config);
|
|
138
|
-
}
|
|
139
|
-
function updateAppConfigState(config) {
|
|
140
|
-
Object.assign(appConfigState, config);
|
|
141
|
-
}
|
|
142
|
-
function getFetchMocks() {
|
|
143
|
-
return fetchMocksState;
|
|
144
|
-
}
|
|
145
|
-
function setFetchMocks(mocks) {
|
|
146
|
-
replaceRecord(fetchMocksState, mocks);
|
|
147
|
-
}
|
|
148
|
-
function getStateRef(key, init) {
|
|
149
|
-
const existing = stateRefs.get(key);
|
|
150
|
-
if (existing) return existing;
|
|
151
|
-
const state = ref(init ? init() : void 0);
|
|
152
|
-
stateRefs.set(key, state);
|
|
153
|
-
return state;
|
|
154
|
-
}
|
|
155
|
-
function setStateMocks(mocks) {
|
|
156
|
-
stateRefs.clear();
|
|
157
|
-
for (const [key, value] of Object.entries(mocks)) stateRefs.set(key, ref(value));
|
|
158
|
-
}
|
|
159
|
-
function clearStateRefs(keys) {
|
|
160
|
-
if (keys == null) {
|
|
161
|
-
stateRefs.clear();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
for (const key of Array.isArray(keys) ? keys : [keys]) stateRefs.delete(key);
|
|
165
|
-
}
|
|
166
|
-
function getCookieRef(name, init) {
|
|
167
|
-
const existing = cookieRefs.get(name);
|
|
168
|
-
if (existing) return existing;
|
|
169
|
-
const cookie = ref(init ? init() : void 0);
|
|
170
|
-
cookieRefs.set(name, cookie);
|
|
171
|
-
return cookie;
|
|
172
|
-
}
|
|
173
|
-
function setCookieMocks(mocks) {
|
|
174
|
-
cookieRefs.clear();
|
|
175
|
-
for (const [key, value] of Object.entries(mocks)) cookieRefs.set(key, ref(value));
|
|
176
|
-
}
|
|
177
|
-
function getRequestState() {
|
|
178
|
-
return requestState;
|
|
179
|
-
}
|
|
180
|
-
function setRequestConfig(request) {
|
|
181
|
-
requestState.url = request.url ?? DEFAULT_REQUEST_URL;
|
|
182
|
-
requestState.headers = { ...request.headers };
|
|
183
|
-
}
|
|
184
|
-
function getErrorRef() {
|
|
185
|
-
return errorRef;
|
|
186
|
-
}
|
|
187
|
-
function setError(error) {
|
|
188
|
-
errorRef.value = error;
|
|
189
|
-
}
|
|
190
|
-
function nextNuxtId() {
|
|
191
|
-
idCounter += 1;
|
|
192
|
-
return `musea-nuxt-${idCounter}`;
|
|
193
|
-
}
|
|
194
|
-
async function runCallOnce(key, fn) {
|
|
195
|
-
if (callOnceKeys.has(key)) return;
|
|
196
|
-
callOnceKeys.add(key);
|
|
197
|
-
return await fn();
|
|
198
|
-
}
|
|
199
|
-
function createRoute(config) {
|
|
200
|
-
const path = config.path ?? "/";
|
|
201
|
-
const query = { ...config.query };
|
|
202
|
-
const hash = normalizeHash(config.hash ?? "");
|
|
203
|
-
return {
|
|
204
|
-
path,
|
|
205
|
-
name: config.name ?? inferRouteName(path),
|
|
206
|
-
params: { ...config.params },
|
|
207
|
-
query,
|
|
208
|
-
hash,
|
|
209
|
-
fullPath: config.fullPath ?? buildFullPath(path, query, hash),
|
|
210
|
-
meta: { ...config.meta },
|
|
211
|
-
matched: [...config.matched ?? []],
|
|
212
|
-
redirectedFrom: config.redirectedFrom
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function inferRouteName(path) {
|
|
216
|
-
const normalized = path.replace(/^\/+|\/+$/g, "");
|
|
217
|
-
return normalized.length === 0 ? "index" : normalized.replace(/[^A-Za-z0-9_]+/g, "-");
|
|
218
|
-
}
|
|
219
|
-
function buildFullPath(path, query, hash) {
|
|
220
|
-
const searchParams = new URLSearchParams();
|
|
221
|
-
for (const [key, value] of Object.entries(query)) {
|
|
222
|
-
if (value == null) continue;
|
|
223
|
-
if (Array.isArray(value)) {
|
|
224
|
-
for (const item of value) searchParams.append(key, item);
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
searchParams.set(key, value);
|
|
228
|
-
}
|
|
229
|
-
const search = searchParams.toString();
|
|
230
|
-
return `${path}${search ? `?${search}` : ""}${hash}`;
|
|
231
|
-
}
|
|
232
|
-
function normalizeHash(hash) {
|
|
233
|
-
if (!hash) return "";
|
|
234
|
-
return hash.startsWith("#") ? hash : `#${hash}`;
|
|
235
|
-
}
|
|
236
|
-
function replaceRecord(target, value) {
|
|
237
|
-
for (const key of Object.keys(target)) delete target[key];
|
|
238
|
-
Object.assign(target, value);
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/mocks/navigation.ts
|
|
242
|
-
/**
|
|
243
|
-
* Mock Nuxt navigation utilities.
|
|
244
|
-
*/
|
|
245
|
-
/**
|
|
246
|
-
* Mock navigateTo - updates the shared route state in gallery context.
|
|
247
|
-
*/
|
|
248
|
-
function navigateTo(to, _opts) {
|
|
249
|
-
setRouteConfig(resolveNavigationTarget(to));
|
|
250
|
-
return Promise.resolve();
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Mock abortNavigation - no-op in gallery context.
|
|
254
|
-
*/
|
|
255
|
-
function abortNavigation(_err) {}
|
|
256
|
-
/**
|
|
257
|
-
* Mock defineNuxtRouteMiddleware - returns the middleware function as-is.
|
|
258
|
-
*/
|
|
259
|
-
function defineNuxtRouteMiddleware(middleware) {
|
|
260
|
-
return middleware;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Mock definePageMeta - page metadata is handled by Nuxt at build time.
|
|
264
|
-
*/
|
|
265
|
-
function definePageMeta(_meta) {}
|
|
266
|
-
/**
|
|
267
|
-
* Mock setPageLayout - no layout switching in isolated previews.
|
|
268
|
-
*/
|
|
269
|
-
function setPageLayout(_layout) {}
|
|
270
|
-
function prefetchComponents(_to) {
|
|
271
|
-
return Promise.resolve();
|
|
272
|
-
}
|
|
273
|
-
function preloadComponents(_to) {
|
|
274
|
-
return Promise.resolve();
|
|
275
|
-
}
|
|
276
|
-
function preloadRouteComponents(_to) {
|
|
277
|
-
return Promise.resolve();
|
|
278
|
-
}
|
|
279
|
-
//#endregion
|
|
280
|
-
//#region src/mocks/composables.ts
|
|
281
|
-
/**
|
|
282
|
-
* Mock Nuxt routing composables.
|
|
283
|
-
*/
|
|
284
|
-
/**
|
|
285
|
-
* Mock useRoute - returns a reactive route object.
|
|
286
|
-
*/
|
|
287
|
-
function useRoute() {
|
|
288
|
-
return getRouteState();
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Mock useRouter - returns a router-like object with no-op navigation.
|
|
292
|
-
*/
|
|
293
|
-
function useRouter() {
|
|
294
|
-
const navigate = async (to) => {
|
|
295
|
-
setRouteConfig(resolveNavigationTarget(to));
|
|
296
|
-
};
|
|
297
|
-
return {
|
|
298
|
-
push: navigate,
|
|
299
|
-
replace: navigate,
|
|
300
|
-
back: () => {},
|
|
301
|
-
forward: () => {},
|
|
302
|
-
go: (_delta) => {},
|
|
303
|
-
resolve: (to) => ({
|
|
304
|
-
href: resolveNavigationTarget(to).fullPath,
|
|
305
|
-
route: resolveNavigationTarget(to)
|
|
306
|
-
}),
|
|
307
|
-
currentRoute: computed(() => useRoute()),
|
|
308
|
-
addRoute: () => () => {},
|
|
309
|
-
removeRoute: () => {},
|
|
310
|
-
hasRoute: () => false,
|
|
311
|
-
getRoutes: () => [],
|
|
312
|
-
beforeEach: () => () => {},
|
|
313
|
-
afterEach: () => () => {},
|
|
314
|
-
onError: () => () => {},
|
|
315
|
-
isReady: () => Promise.resolve(),
|
|
316
|
-
options: {}
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
//#endregion
|
|
320
67
|
//#region src/mocks/components.ts
|
|
321
68
|
/**
|
|
322
69
|
* Mock Nuxt built-in components.
|
|
@@ -588,104 +335,6 @@ function isExternalHref(href) {
|
|
|
588
335
|
return /^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(href);
|
|
589
336
|
}
|
|
590
337
|
//#endregion
|
|
591
|
-
//#region src/mocks/runtime.ts
|
|
592
|
-
/**
|
|
593
|
-
* Mock Nuxt runtime composables.
|
|
594
|
-
*/
|
|
595
|
-
/**
|
|
596
|
-
* Mock useNuxtApp - returns a minimal Nuxt app-like object.
|
|
597
|
-
*/
|
|
598
|
-
function useNuxtApp() {
|
|
599
|
-
return {
|
|
600
|
-
$config: useRuntimeConfig(),
|
|
601
|
-
$router: useRouter(),
|
|
602
|
-
$route: useRoute(),
|
|
603
|
-
provide: (_name, _value) => {},
|
|
604
|
-
hook: (_name, _fn) => {},
|
|
605
|
-
callHook: async (_name, ..._args) => {},
|
|
606
|
-
vueApp: null,
|
|
607
|
-
payload: reactive({
|
|
608
|
-
data: {},
|
|
609
|
-
state: {}
|
|
610
|
-
}),
|
|
611
|
-
isHydrating: false,
|
|
612
|
-
runWithContext: (fn) => fn()
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Mock useRuntimeConfig - returns the configured runtime config.
|
|
617
|
-
*/
|
|
618
|
-
function useRuntimeConfig() {
|
|
619
|
-
return getRuntimeConfigState();
|
|
620
|
-
}
|
|
621
|
-
function useAppConfig() {
|
|
622
|
-
return getAppConfigState();
|
|
623
|
-
}
|
|
624
|
-
function updateAppConfig(config) {
|
|
625
|
-
updateAppConfigState(config);
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Mock useState - returns a ref initialized from mock config or init function.
|
|
629
|
-
*/
|
|
630
|
-
function useState(key, init) {
|
|
631
|
-
return getStateRef(key, init);
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Mock useRequestHeaders - returns empty headers in gallery context.
|
|
635
|
-
*/
|
|
636
|
-
function useRequestHeaders(_include) {
|
|
637
|
-
return { ...getRequestState().headers };
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Mock useRequestEvent - returns undefined in gallery context.
|
|
641
|
-
*/
|
|
642
|
-
function useRequestEvent() {}
|
|
643
|
-
/**
|
|
644
|
-
* Mock useRequestURL - returns current window location.
|
|
645
|
-
*/
|
|
646
|
-
function useRequestURL() {
|
|
647
|
-
if (typeof window !== "undefined") return new URL(window.location.href);
|
|
648
|
-
return new URL(getRequestState().url);
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Mock useCookie - returns a ref-like cookie mock.
|
|
652
|
-
*/
|
|
653
|
-
function useCookie(name, opts) {
|
|
654
|
-
return getCookieRef(name, opts?.default);
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Mock clearNuxtState - no-op.
|
|
658
|
-
*/
|
|
659
|
-
function clearNuxtState(keys) {
|
|
660
|
-
clearStateRefs(keys);
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Mock defineNuxtPlugin - returns the plugin function as-is.
|
|
664
|
-
*/
|
|
665
|
-
function defineNuxtPlugin(plugin) {
|
|
666
|
-
return plugin;
|
|
667
|
-
}
|
|
668
|
-
function defineNuxtComponent(component) {
|
|
669
|
-
return component;
|
|
670
|
-
}
|
|
671
|
-
function onNuxtReady(callback) {
|
|
672
|
-
if (typeof queueMicrotask === "function") {
|
|
673
|
-
queueMicrotask(callback);
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
Promise.resolve().then(callback);
|
|
677
|
-
}
|
|
678
|
-
function callOnce(keyOrFn, fn) {
|
|
679
|
-
if (typeof keyOrFn === "function") return runCallOnce("__default__", keyOrFn);
|
|
680
|
-
return runCallOnce(keyOrFn, fn ?? (() => void 0));
|
|
681
|
-
}
|
|
682
|
-
function useId() {
|
|
683
|
-
return nextNuxtId();
|
|
684
|
-
}
|
|
685
|
-
function reloadNuxtApp(_options) {
|
|
686
|
-
return Promise.resolve();
|
|
687
|
-
}
|
|
688
|
-
//#endregion
|
|
689
338
|
//#region src/app.ts
|
|
690
339
|
const builtInComponents = {
|
|
691
340
|
NuxtLink,
|
|
@@ -727,164 +376,6 @@ function createNuxtMuseaPreviewSetup(options = {}) {
|
|
|
727
376
|
};
|
|
728
377
|
}
|
|
729
378
|
//#endregion
|
|
730
|
-
//#region src/mocks/data.ts
|
|
731
|
-
/**
|
|
732
|
-
* Mock Nuxt data-fetching composables.
|
|
733
|
-
*/
|
|
734
|
-
function findMockData(key) {
|
|
735
|
-
const fetchMocks = getFetchMocks();
|
|
736
|
-
if (key in fetchMocks) return fetchMocks[key];
|
|
737
|
-
for (const [pattern, data] of Object.entries(fetchMocks)) if (key.includes(pattern)) return data;
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Mock useFetch - returns reactive data based on mock config.
|
|
741
|
-
*/
|
|
742
|
-
function useFetch(url, opts) {
|
|
743
|
-
return createAsyncDataResult(stringifyDataKey(toValue(url)), void 0, opts);
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Mock useAsyncData - similar to useFetch but with key-based lookup.
|
|
747
|
-
*/
|
|
748
|
-
function useAsyncData(key, handler, opts) {
|
|
749
|
-
return createAsyncDataResult(key, handler, opts);
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Mock useLazyFetch - lazy variant of useFetch.
|
|
753
|
-
*/
|
|
754
|
-
function useLazyFetch(url, opts) {
|
|
755
|
-
return useFetch(url, {
|
|
756
|
-
...opts,
|
|
757
|
-
lazy: true
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Mock useLazyAsyncData - lazy variant of useAsyncData.
|
|
762
|
-
*/
|
|
763
|
-
function useLazyAsyncData(key, handler, opts) {
|
|
764
|
-
return useAsyncData(key, handler, {
|
|
765
|
-
...opts,
|
|
766
|
-
lazy: true
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
function refreshNuxtData(_keys) {
|
|
770
|
-
return Promise.resolve();
|
|
771
|
-
}
|
|
772
|
-
function clearNuxtData(_keys) {}
|
|
773
|
-
function useNuxtData(key) {
|
|
774
|
-
return { data: ref(findMockData(key) ?? null) };
|
|
775
|
-
}
|
|
776
|
-
function useRequestFetch() {
|
|
777
|
-
return async (url) => {
|
|
778
|
-
return findMockData(stringifyDataKey(url));
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
function createAsyncDataResult(key, handler, opts = {}) {
|
|
782
|
-
const initial = resolveInitialData(key, opts);
|
|
783
|
-
const data = ref(initial);
|
|
784
|
-
const pending = ref(false);
|
|
785
|
-
const error = ref(null);
|
|
786
|
-
const status = ref(initial == null ? "idle" : "success");
|
|
787
|
-
const execute = async () => {
|
|
788
|
-
pending.value = true;
|
|
789
|
-
status.value = "pending";
|
|
790
|
-
error.value = null;
|
|
791
|
-
try {
|
|
792
|
-
const mockData = findMockData(key);
|
|
793
|
-
data.value = applyDataOptions(mockData !== void 0 ? mockData : handler ? await handler() : data.value, opts);
|
|
794
|
-
status.value = "success";
|
|
795
|
-
} catch (caught) {
|
|
796
|
-
error.value = caught instanceof Error ? caught : new Error(String(caught));
|
|
797
|
-
status.value = "error";
|
|
798
|
-
} finally {
|
|
799
|
-
pending.value = false;
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
if (opts.immediate !== false && opts.lazy !== true && initial == null && handler) execute();
|
|
803
|
-
return {
|
|
804
|
-
data,
|
|
805
|
-
pending,
|
|
806
|
-
error,
|
|
807
|
-
refresh: execute,
|
|
808
|
-
execute,
|
|
809
|
-
clear: () => {
|
|
810
|
-
data.value = null;
|
|
811
|
-
error.value = null;
|
|
812
|
-
pending.value = false;
|
|
813
|
-
status.value = "idle";
|
|
814
|
-
},
|
|
815
|
-
status
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
function resolveInitialData(key, opts) {
|
|
819
|
-
const mockData = findMockData(key);
|
|
820
|
-
if (mockData !== void 0) return applyDataOptions(mockData, opts);
|
|
821
|
-
return opts.default ? opts.default() : null;
|
|
822
|
-
}
|
|
823
|
-
function applyDataOptions(value, opts) {
|
|
824
|
-
const transformed = opts.transform ? opts.transform(value) : value;
|
|
825
|
-
if (!opts.pick || typeof transformed !== "object" || transformed == null) return transformed;
|
|
826
|
-
const picked = {};
|
|
827
|
-
for (const key of opts.pick) picked[key] = transformed[key];
|
|
828
|
-
return picked;
|
|
829
|
-
}
|
|
830
|
-
function stringifyDataKey(value) {
|
|
831
|
-
return typeof value === "string" ? value : value.toString();
|
|
832
|
-
}
|
|
833
|
-
//#endregion
|
|
834
|
-
//#region src/mocks/head.ts
|
|
835
|
-
function createHeadEntry() {
|
|
836
|
-
return {
|
|
837
|
-
dispose: () => {},
|
|
838
|
-
patch: (_input) => {},
|
|
839
|
-
pause: () => {},
|
|
840
|
-
resume: () => {}
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Mock useHead - no-op.
|
|
845
|
-
*/
|
|
846
|
-
function useHead(_input) {
|
|
847
|
-
return createHeadEntry();
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Mock useSeoMeta - no-op.
|
|
851
|
-
*/
|
|
852
|
-
function useSeoMeta(_input) {
|
|
853
|
-
return createHeadEntry();
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* Mock useHeadSafe - no-op.
|
|
857
|
-
*/
|
|
858
|
-
function useHeadSafe(_input) {
|
|
859
|
-
return createHeadEntry();
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Mock useServerSeoMeta - no-op.
|
|
863
|
-
*/
|
|
864
|
-
function useServerSeoMeta(_input) {
|
|
865
|
-
return createHeadEntry();
|
|
866
|
-
}
|
|
867
|
-
//#endregion
|
|
868
|
-
//#region src/mocks/error.ts
|
|
869
|
-
function createError(input) {
|
|
870
|
-
const message = typeof input === "string" ? input : input.message ?? input.statusMessage ?? "Error";
|
|
871
|
-
const error = new Error(message);
|
|
872
|
-
if (typeof input === "object") Object.assign(error, input);
|
|
873
|
-
return error;
|
|
874
|
-
}
|
|
875
|
-
function showError(input) {
|
|
876
|
-
const error = createError(input);
|
|
877
|
-
setError(error);
|
|
878
|
-
return error;
|
|
879
|
-
}
|
|
880
|
-
function clearError(_options) {
|
|
881
|
-
setError(null);
|
|
882
|
-
return Promise.resolve();
|
|
883
|
-
}
|
|
884
|
-
function useError() {
|
|
885
|
-
return getErrorRef();
|
|
886
|
-
}
|
|
887
|
-
//#endregion
|
|
888
379
|
//#region src/index.ts
|
|
889
380
|
/**
|
|
890
381
|
* Create Nuxt mock Vite plugin for Musea.
|