@kimesh/router-runtime 0.2.39 → 0.2.40
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/context-Dm4fd4Um.mjs +89 -0
- package/dist/{index-B2f-KCQg.d.mts → executor-CRRUmoFz.d.mts} +13 -56
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +4 -2
- package/dist/middleware/index.d.mts +3 -2
- package/dist/middleware/index.mjs +3 -2
- package/dist/middleware/plugin.d.mts +46 -1
- package/dist/middleware/plugin.mjs +117 -2
- package/package.json +2 -2
- package/dist/plugin-jUmO3cn2.mjs +0 -205
- /package/dist/{middleware-DvCiATAB.mjs → executor-DghrGTKE.mjs} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/runtime-plugin.ts
|
|
2
|
+
const KIMESH_PLUGIN_INDICATOR = "__kimesh_plugin";
|
|
3
|
+
/**
|
|
4
|
+
* Define a Kimesh runtime plugin
|
|
5
|
+
*
|
|
6
|
+
* @example Function-style plugin
|
|
7
|
+
* ```ts
|
|
8
|
+
* export default defineKimeshRuntimePlugin((app) => {
|
|
9
|
+
* const analytics = new AnalyticsService()
|
|
10
|
+
* app.router.afterEach((to) => analytics.trackPageView(to.path))
|
|
11
|
+
* return { provide: { analytics } }
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Object-style plugin with hooks
|
|
16
|
+
* ```ts
|
|
17
|
+
* export default defineKimeshRuntimePlugin({
|
|
18
|
+
* name: 'my-plugin',
|
|
19
|
+
* enforce: 'pre',
|
|
20
|
+
* hooks: {
|
|
21
|
+
* 'app:mounted': () => console.log('App mounted!')
|
|
22
|
+
* },
|
|
23
|
+
* setup(app) {
|
|
24
|
+
* return { provide: { myService: new MyService() } }
|
|
25
|
+
* }
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function defineKimeshRuntimePlugin(plugin) {
|
|
30
|
+
if (typeof plugin === "function") {
|
|
31
|
+
plugin[KIMESH_PLUGIN_INDICATOR] = true;
|
|
32
|
+
return plugin;
|
|
33
|
+
}
|
|
34
|
+
const { name, enforce, order, dependsOn, parallel, hooks, setup } = plugin;
|
|
35
|
+
const pluginFn = setup ?? (() => {});
|
|
36
|
+
pluginFn[KIMESH_PLUGIN_INDICATOR] = true;
|
|
37
|
+
pluginFn._name = name;
|
|
38
|
+
pluginFn.meta = {
|
|
39
|
+
name,
|
|
40
|
+
enforce,
|
|
41
|
+
order,
|
|
42
|
+
dependsOn,
|
|
43
|
+
parallel
|
|
44
|
+
};
|
|
45
|
+
pluginFn.hooks = hooks;
|
|
46
|
+
return pluginFn;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a value is a Kimesh runtime plugin
|
|
50
|
+
*/
|
|
51
|
+
function isKimeshRuntimePlugin(value) {
|
|
52
|
+
return typeof value === "function" && value[KIMESH_PLUGIN_INDICATOR] === true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get plugin metadata
|
|
56
|
+
*/
|
|
57
|
+
function getPluginMeta(plugin) {
|
|
58
|
+
return plugin.meta ?? {};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get plugin name
|
|
62
|
+
*/
|
|
63
|
+
function getPluginName(plugin) {
|
|
64
|
+
return plugin._name ?? plugin.meta?.name ?? "anonymous";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get plugin hooks
|
|
68
|
+
*/
|
|
69
|
+
function getPluginHooks(plugin) {
|
|
70
|
+
return plugin.hooks;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/middleware/context.ts
|
|
75
|
+
/**
|
|
76
|
+
* Create middleware execution context
|
|
77
|
+
*/
|
|
78
|
+
function createMiddlewareContext(to, from, appContext) {
|
|
79
|
+
return {
|
|
80
|
+
to,
|
|
81
|
+
from,
|
|
82
|
+
router: appContext.router,
|
|
83
|
+
app: appContext,
|
|
84
|
+
data: {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { getPluginMeta as a, getPluginHooks as i, KIMESH_PLUGIN_INDICATOR as n, getPluginName as o, defineKimeshRuntimePlugin as r, isKimeshRuntimePlugin as s, createMiddlewareContext as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue from "vue";
|
|
2
2
|
import { App, Component, ComputedRef, InjectionKey, KeepAliveProps, MaybeRefOrGetter, PropType, Ref, TransitionProps, VNode } from "vue";
|
|
3
3
|
import * as vue_router0 from "vue-router";
|
|
4
|
-
import { LocationQueryValue, NavigationFailure,
|
|
4
|
+
import { LocationQueryValue, NavigationFailure, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRaw, Router } from "vue-router";
|
|
5
5
|
import { QueryClient, QueryClientConfig } from "@tanstack/vue-query";
|
|
6
6
|
import { Hookable } from "hookable";
|
|
7
7
|
|
|
@@ -830,7 +830,7 @@ declare function createHeadPlugin(options?: HeadPluginOptions): {
|
|
|
830
830
|
* 3. transition: { name: 'fade', mode: 'out-in' }
|
|
831
831
|
* - ⚠️ NOT recommended for async pages - may cause blank screen
|
|
832
832
|
*/
|
|
833
|
-
declare const KmOutlet:
|
|
833
|
+
declare const KmOutlet: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
834
834
|
name: {
|
|
835
835
|
type: StringConstructor;
|
|
836
836
|
default: string;
|
|
@@ -866,7 +866,7 @@ declare const KmOutlet: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
866
866
|
type: any;
|
|
867
867
|
default: null;
|
|
868
868
|
};
|
|
869
|
-
}>, () => VNode, {}, {}, {},
|
|
869
|
+
}>, () => VNode, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
870
870
|
name: {
|
|
871
871
|
type: StringConstructor;
|
|
872
872
|
default: string;
|
|
@@ -908,7 +908,7 @@ declare const KmOutlet: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
908
908
|
viewTransition: boolean;
|
|
909
909
|
keepalive: any;
|
|
910
910
|
pageKey: any;
|
|
911
|
-
}, {}, {}, {}, string,
|
|
911
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
912
912
|
//#endregion
|
|
913
913
|
//#region src/components/KmLink.d.ts
|
|
914
914
|
/**
|
|
@@ -946,7 +946,7 @@ type KmLinkProps<T extends string = RouteNames> = T extends RouteNames ? HasPara
|
|
|
946
946
|
* </KmLink>
|
|
947
947
|
* ```
|
|
948
948
|
*/
|
|
949
|
-
declare const KmLink:
|
|
949
|
+
declare const KmLink: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
950
950
|
to: {
|
|
951
951
|
type: PropType<RouteLocationRaw>;
|
|
952
952
|
required: true;
|
|
@@ -975,9 +975,9 @@ declare const KmLink: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
975
975
|
type: StringConstructor;
|
|
976
976
|
default: string;
|
|
977
977
|
};
|
|
978
|
-
}>, () =>
|
|
978
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
979
979
|
[key: string]: any;
|
|
980
|
-
}>, {}, {}, {},
|
|
980
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
981
981
|
to: {
|
|
982
982
|
type: PropType<RouteLocationRaw>;
|
|
983
983
|
required: true;
|
|
@@ -1013,7 +1013,7 @@ declare const KmLink: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
1013
1013
|
exactActiveClass: string;
|
|
1014
1014
|
prefetch: boolean;
|
|
1015
1015
|
tag: string;
|
|
1016
|
-
}, {}, {}, {}, string,
|
|
1016
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
1017
1017
|
//#endregion
|
|
1018
1018
|
//#region src/components/KmDeferred.d.ts
|
|
1019
1019
|
/**
|
|
@@ -1035,7 +1035,7 @@ declare const KmLink: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
1035
1035
|
* </KmDeferred>
|
|
1036
1036
|
* ```
|
|
1037
1037
|
*/
|
|
1038
|
-
declare const KmDeferred:
|
|
1038
|
+
declare const KmDeferred: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
1039
1039
|
/**
|
|
1040
1040
|
* Delay in ms before showing fallback (default: 0)
|
|
1041
1041
|
* Helps avoid flashing loading states for fast loads
|
|
@@ -1044,7 +1044,7 @@ declare const KmDeferred: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
1044
1044
|
type: PropType<number>;
|
|
1045
1045
|
default: number;
|
|
1046
1046
|
};
|
|
1047
|
-
}>, () => VNode, {}, {}, {},
|
|
1047
|
+
}>, () => VNode, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
1048
1048
|
/**
|
|
1049
1049
|
* Delay in ms before showing fallback (default: 0)
|
|
1050
1050
|
* Helps avoid flashing loading states for fast loads
|
|
@@ -1055,7 +1055,7 @@ declare const KmDeferred: vue13.DefineComponent<vue13.ExtractPropTypes<{
|
|
|
1055
1055
|
};
|
|
1056
1056
|
}>> & Readonly<{}>, {
|
|
1057
1057
|
timeout: number;
|
|
1058
|
-
}, {}, {}, {}, string,
|
|
1058
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
1059
1059
|
//#endregion
|
|
1060
1060
|
//#region src/guards/loader-guard.d.ts
|
|
1061
1061
|
interface LoaderGuardOptions {
|
|
@@ -1748,49 +1748,6 @@ declare function navigateTo(to: NavigationRedirect, options?: NavigateToOptions)
|
|
|
1748
1748
|
*/
|
|
1749
1749
|
declare function abortNavigation(reason?: string | Error): false;
|
|
1750
1750
|
//#endregion
|
|
1751
|
-
//#region src/middleware/plugin.d.ts
|
|
1752
|
-
/**
|
|
1753
|
-
* Options for middleware plugin
|
|
1754
|
-
*/
|
|
1755
|
-
interface MiddlewarePluginOptions {
|
|
1756
|
-
/** Global middleware array */
|
|
1757
|
-
globalMiddleware?: RouteMiddleware[];
|
|
1758
|
-
/** Named middleware registry (lazy loaders) */
|
|
1759
|
-
namedMiddleware?: Record<string, () => Promise<RouteMiddleware>>;
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* Create middleware plugin with provided registry
|
|
1763
|
-
*
|
|
1764
|
-
* @example
|
|
1765
|
-
* ```ts
|
|
1766
|
-
* import { globalMiddleware, namedMiddleware } from '#kimesh/middleware'
|
|
1767
|
-
*
|
|
1768
|
-
* const plugin = createMiddlewarePlugin({
|
|
1769
|
-
* globalMiddleware,
|
|
1770
|
-
* namedMiddleware,
|
|
1771
|
-
* })
|
|
1772
|
-
* ```
|
|
1773
|
-
*/
|
|
1774
|
-
declare function createMiddlewarePlugin(options?: MiddlewarePluginOptions): KimeshRuntimePlugin<{
|
|
1775
|
-
middleware: {
|
|
1776
|
-
globalCount: number;
|
|
1777
|
-
namedCount: number;
|
|
1778
|
-
};
|
|
1779
|
-
}>;
|
|
1780
|
-
/**
|
|
1781
|
-
* Middleware runtime plugin (legacy - no-op stub)
|
|
1782
|
-
*
|
|
1783
|
-
* @deprecated Use createMiddlewarePlugin() with explicit registry instead.
|
|
1784
|
-
* This export is kept for backward compatibility but does nothing.
|
|
1785
|
-
* The kit generates middleware-plugin.mjs that uses createMiddlewarePlugin.
|
|
1786
|
-
*/
|
|
1787
|
-
declare const middlewarePlugin: KimeshRuntimePlugin<{
|
|
1788
|
-
middleware: {
|
|
1789
|
-
globalCount: number;
|
|
1790
|
-
namedCount: number;
|
|
1791
|
-
};
|
|
1792
|
-
}>;
|
|
1793
|
-
//#endregion
|
|
1794
1751
|
//#region src/middleware/context.d.ts
|
|
1795
1752
|
/**
|
|
1796
1753
|
* Create middleware execution context
|
|
@@ -1821,4 +1778,4 @@ declare function createMiddlewareExecutor(appContext: KimeshAppContext): {
|
|
|
1821
1778
|
executeChain(middlewares: RouteMiddleware[], context: MiddlewareContext): Promise<void | false | NavigationRedirect>;
|
|
1822
1779
|
};
|
|
1823
1780
|
//#endregion
|
|
1824
|
-
export {
|
|
1781
|
+
export { useNavigate as $, LoaderFn as $t, useRouteQuery as A, NavigationHookContext as An, isKimeshRuntimePlugin as At, useAfterNavigation as B, BeforeLoadContextFull as Bt, LoaderDataKey as C, KimeshRuntimeHooks as Cn, applyPlugins as Ct, RouteQueryTransform as D, KimeshRuntimePluginResult as Dn, getPluginHooks as Dt, isLayoutRouteMeta as E, KimeshRuntimePluginMeta as En, defineKimeshRuntimePlugin as Et, useMatchLoaderData as F, CreateKimeshAppOptionsExtended as Ft, getKmStateKeys as G, FullContext as Gt, useNavigationMiddleware as H, CreateKimeshAppOptions as Ht, useRouteLoaderData as I, KIMESH_APP_CONTEXT_KEY as It, tryUseKimeshApp as J, InlineRouteMiddleware as Jt, hasKmState as K, HasParams as Kt, NavigationContext as L, createKimeshApp as Lt, useRouteQueryNumber as M, useKimeshContext as Mt, useLayoutData as N, createFileRoute as Nt, RouteQueryValueRaw as O, NavigationAfterHookContext as On, getPluginMeta as Ot, useLoaderData as P, defineRoute as Pt, NavigateOptions as Q, LoaderContext as Qt, NavigationErrorContext as R, AugmentedContext as Rt, LayoutRouteMeta as S, KimeshAppContext as Sn, applyPlugin as St, createLoaderDataKey as T, KimeshRuntimePluginDefinition as Tn, KIMESH_PLUGIN_INDICATOR as Tt, STATE_KEY_PREFIX as U, ExtractRouteParams as Ut, useNavigationGuard as V, BeforeLoadFn as Vt, clearKmState as W, FileRouteOptions as Wt, RuntimeConfig as X, KimeshApp as Xt, useKimeshApp as Y, KIMESH_CONTEXT_KEY as Yt, useRuntimeConfig as Z, KimeshContext as Zt, MiddlewareResult as _, RouteRecordInfo as _n, mergeHeadConfigs as _t, NavigateToOptions as a, RouteContext as an, createLoaderGuard as at, TypedRouteMiddleware as b, TypedRedirectDynamic as bn, queryPlugin as bt, defineKimeshMiddleware as c, RouteHeadContext as cn, KmLink as ct, KnownMiddleware as d, RouteLocationRaw as dn, HeadPluginOptions as dt, ParamValue as en, useParams as et, MiddlewareContext as f, RouteNamedMap as fn, applyHeadConfigNative as ft, MiddlewareRegistryEntry as g, RoutePath as gn, mergeAllRouteHeads as gt, MiddlewareRegistry as h, RouteParamsRaw as hn, createHeadPlugin as ht, createMiddlewareContext as i, PendingConfig as in, LoaderGuardOptions as it, useRouteQueryBoolean as j, RuntimeConfigPublic as jn, defineContext as jt, UseRouteQueryOptions as k, NavigationErrorHookContext as kn, getPluginName as kt, navigateTo as l, RouteHeadFn as ln, KmLinkProps as lt, MiddlewareOption as m, RouteParams as mn, collectRouteHeads as mt, executeMiddleware as n, ParamValueZeroOrMore as nn, UseSearchReturn as nt, TypedNavigateToOptions as o, RouteDefinition as on, installLoaderGuard as ot, MiddlewareDefinition as p, RouteNames as pn, applyTitleTemplate as pt, useState as q, InlineMiddlewareContext as qt, executeMiddlewareChain as r, ParamValueZeroOrOne as rn, useSearch as rt, abortNavigation as s, RouteHeadConfig as sn, KmDeferred as st, createMiddlewareExecutor as t, ParamValueOneOrMore as tn, useReactiveParams as tt, KimeshMiddlewareNames as u, RouteInfoByName as un, KmOutlet as ut, NavigationRedirect as v, SearchSchema as vn, QueryPluginOptions as vt, UseMatchLoaderDataOptions as w, KimeshRuntimePlugin as wn, applyPluginsWithParallel as wt, LayoutLoaderData as x, TypedRedirectStatic as xn, routerPlugin as xt, RouteMiddleware as y, TypedNavigationRedirect as yn, getCorePlugins as yt, NavigationMiddlewareOptions as z, BeforeLoadContext as zt };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
|
|
1
|
+
import { $ as useNavigate, $t as LoaderFn, A as useRouteQuery, An as NavigationHookContext, At as isKimeshRuntimePlugin, B as useAfterNavigation, Bt as BeforeLoadContextFull, C as LoaderDataKey, Cn as KimeshRuntimeHooks, Ct as applyPlugins, D as RouteQueryTransform, Dn as KimeshRuntimePluginResult, Dt as getPluginHooks, E as isLayoutRouteMeta, En as KimeshRuntimePluginMeta, Et as defineKimeshRuntimePlugin, F as useMatchLoaderData, Ft as CreateKimeshAppOptionsExtended, G as getKmStateKeys, Gt as FullContext, H as useNavigationMiddleware, Ht as CreateKimeshAppOptions, I as useRouteLoaderData, It as KIMESH_APP_CONTEXT_KEY, J as tryUseKimeshApp, Jt as InlineRouteMiddleware, K as hasKmState, Kt as HasParams, L as NavigationContext, Lt as createKimeshApp, M as useRouteQueryNumber, Mt as useKimeshContext, N as useLayoutData, Nt as createFileRoute, O as RouteQueryValueRaw, On as NavigationAfterHookContext, Ot as getPluginMeta, P as useLoaderData, Pt as defineRoute, Q as NavigateOptions, Qt as LoaderContext, R as NavigationErrorContext, Rt as AugmentedContext, S as LayoutRouteMeta, Sn as KimeshAppContext, St as applyPlugin, T as createLoaderDataKey, Tn as KimeshRuntimePluginDefinition, Tt as KIMESH_PLUGIN_INDICATOR, U as STATE_KEY_PREFIX, Ut as ExtractRouteParams, V as useNavigationGuard, Vt as BeforeLoadFn, W as clearKmState, Wt as FileRouteOptions, X as RuntimeConfig, Xt as KimeshApp, Y as useKimeshApp, Yt as KIMESH_CONTEXT_KEY, Z as useRuntimeConfig, Zt as KimeshContext, _ as MiddlewareResult, _n as RouteRecordInfo, _t as mergeHeadConfigs, a as NavigateToOptions, an as RouteContext, at as createLoaderGuard, b as TypedRouteMiddleware, bn as TypedRedirectDynamic, bt as queryPlugin, c as defineKimeshMiddleware, cn as RouteHeadContext, ct as KmLink, d as KnownMiddleware, dn as RouteLocationRaw, dt as HeadPluginOptions, en as ParamValue, et as useParams, f as MiddlewareContext, fn as RouteNamedMap, ft as applyHeadConfigNative, gn as RoutePath, gt as mergeAllRouteHeads, hn as RouteParamsRaw, ht as createHeadPlugin, i as createMiddlewareContext, in as PendingConfig, it as LoaderGuardOptions, j as useRouteQueryBoolean, jn as RuntimeConfigPublic, jt as defineContext, k as UseRouteQueryOptions, kn as NavigationErrorHookContext, kt as getPluginName, l as navigateTo, ln as RouteHeadFn, lt as KmLinkProps, m as MiddlewareOption, mn as RouteParams, mt as collectRouteHeads, nn as ParamValueZeroOrMore, nt as UseSearchReturn, on as RouteDefinition, ot as installLoaderGuard, p as MiddlewareDefinition, pn as RouteNames, pt as applyTitleTemplate, q as useState, qt as InlineMiddlewareContext, rn as ParamValueZeroOrOne, rt as useSearch, s as abortNavigation, sn as RouteHeadConfig, st as KmDeferred, t as createMiddlewareExecutor, tn as ParamValueOneOrMore, tt as useReactiveParams, u as KimeshMiddlewareNames, un as RouteInfoByName, ut as KmOutlet, v as NavigationRedirect, vn as SearchSchema, vt as QueryPluginOptions, w as UseMatchLoaderDataOptions, wn as KimeshRuntimePlugin, wt as applyPluginsWithParallel, x as LayoutLoaderData, xn as TypedRedirectStatic, xt as routerPlugin, y as RouteMiddleware, yn as TypedNavigationRedirect, yt as getCorePlugins, z as NavigationMiddlewareOptions, zt as BeforeLoadContext } from "./executor-CRRUmoFz.mjs";
|
|
2
|
+
import middlewarePlugin, { MiddlewarePluginOptions, createMiddlewarePlugin } from "./middleware/plugin.mjs";
|
|
3
|
+
import "./middleware/index.mjs";
|
|
4
|
+
import { NavigationGuard, NavigationHookAfter, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRaw, Router, onBeforeRouteLeave, onBeforeRouteUpdate, useLink, useRoute, useRouter } from "vue-router";
|
|
5
|
+
export { type AugmentedContext, type BeforeLoadContext, type BeforeLoadContextFull, type BeforeLoadFn, type CreateKimeshAppOptions, type CreateKimeshAppOptionsExtended, type ExtractRouteParams, type FileRouteOptions, type FullContext, type HasParams, type HeadPluginOptions, type InlineMiddlewareContext, type InlineRouteMiddleware, KIMESH_APP_CONTEXT_KEY, KIMESH_CONTEXT_KEY, KIMESH_PLUGIN_INDICATOR, type KimeshApp, type KimeshAppContext, type KimeshContext, type KimeshMiddlewareNames, type KimeshRuntimeHooks, type KimeshRuntimePlugin, type KimeshRuntimePluginDefinition, type KimeshRuntimePluginMeta, type KimeshRuntimePluginResult, KmDeferred, KmLink, type KmLinkProps, KmOutlet, type KnownMiddleware, type LayoutLoaderData, type LayoutRouteMeta, type LoaderContext, type LoaderDataKey, type LoaderFn, type LoaderGuardOptions, type MiddlewareContext, type MiddlewareDefinition, type MiddlewareOption, type MiddlewarePluginOptions, type MiddlewareResult, type NavigateOptions, type NavigateToOptions, type NavigationAfterHookContext, type NavigationContext, type NavigationErrorContext, type NavigationErrorHookContext, type NavigationGuard, type NavigationHookAfter, type NavigationHookContext, type NavigationMiddlewareOptions, type NavigationRedirect, type ParamValue, type ParamValueOneOrMore, type ParamValueZeroOrMore, type ParamValueZeroOrOne, type PendingConfig, type QueryPluginOptions, type RouteContext, type RouteDefinition, type RouteHeadConfig, type RouteHeadContext, type RouteHeadFn, type RouteInfoByName, type RouteLocationNormalized, type RouteLocationNormalizedLoaded, type RouteLocationRaw, type RouteMiddleware, type RouteNamedMap, type RouteNames, type RouteParams, type RouteParamsRaw, type RoutePath, type RouteQueryTransform, type RouteQueryValueRaw, type RouteRecordInfo, type RouteRecordRaw, type Router, type RuntimeConfig, type RuntimeConfigPublic, STATE_KEY_PREFIX, type SearchSchema, type TypedNavigationRedirect, type TypedRedirectDynamic, type TypedRedirectStatic, type TypedRouteMiddleware, type UseMatchLoaderDataOptions, type UseRouteQueryOptions, type UseSearchReturn, abortNavigation, applyHeadConfigNative, applyPlugin, applyPlugins, applyPluginsWithParallel, applyTitleTemplate, clearKmState, collectRouteHeads, createFileRoute, createHeadPlugin, createKimeshApp, createLoaderDataKey, createLoaderGuard, createMiddlewareContext, createMiddlewareExecutor, createMiddlewarePlugin, defineContext, defineKimeshMiddleware, defineKimeshRuntimePlugin, defineRoute, getCorePlugins, getKmStateKeys, getPluginHooks, getPluginMeta, getPluginName, hasKmState, installLoaderGuard, isKimeshRuntimePlugin, isLayoutRouteMeta, mergeAllRouteHeads, mergeHeadConfigs, middlewarePlugin, navigateTo, onBeforeRouteLeave, onBeforeRouteUpdate, queryPlugin, routerPlugin, tryUseKimeshApp, useAfterNavigation, useKimeshApp, useKimeshContext, useLayoutData, useLink, useLoaderData, useMatchLoaderData, useNavigate, useNavigationGuard, useNavigationMiddleware, useParams, useReactiveParams, useRoute, useRouteLoaderData, useRouteQuery, useRouteQueryBoolean, useRouteQueryNumber, useRouter, useRuntimeConfig, useSearch, useState };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as defineKimeshMiddleware, i as abortNavigation, o as navigateTo, t as createMiddlewareExecutor } from "./
|
|
1
|
+
import { a as getPluginMeta, i as getPluginHooks, n as KIMESH_PLUGIN_INDICATOR, o as getPluginName, r as defineKimeshRuntimePlugin, s as isKimeshRuntimePlugin, t as createMiddlewareContext } from "./context-Dm4fd4Um.mjs";
|
|
2
|
+
import { a as defineKimeshMiddleware, i as abortNavigation, o as navigateTo, t as createMiddlewareExecutor } from "./executor-DghrGTKE.mjs";
|
|
3
|
+
import middlewarePlugin, { createMiddlewarePlugin } from "./middleware/plugin.mjs";
|
|
4
|
+
import "./middleware/index.mjs";
|
|
3
5
|
import { KeepAlive, Suspense, Transition, computed, createApp, customRef, defineComponent, getCurrentInstance, h, inject, isRef, nextTick, onErrorCaptured, onScopeDispose, reactive, ref, toRef, toValue, watch } from "vue";
|
|
4
6
|
import { RouterLink, RouterView, createRouter, createWebHashHistory, createWebHistory, onBeforeRouteLeave, onBeforeRouteUpdate, routeLocationKey, routerKey, useLink, useRoute, useRoute as useRoute$1, useRouter, useRouter as useRouter$1 } from "vue-router";
|
|
5
7
|
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { _ as MiddlewareResult, a as NavigateToOptions, b as TypedRouteMiddleware, c as defineKimeshMiddleware, d as KnownMiddleware, f as MiddlewareContext, g as MiddlewareRegistryEntry, h as MiddlewareRegistry, i as createMiddlewareContext, l as navigateTo, m as MiddlewareOption, n as executeMiddleware, o as TypedNavigateToOptions, p as MiddlewareDefinition, r as executeMiddlewareChain, s as abortNavigation, t as createMiddlewareExecutor, u as KimeshMiddlewareNames, v as NavigationRedirect, y as RouteMiddleware } from "../executor-CRRUmoFz.mjs";
|
|
2
|
+
import middlewarePlugin, { MiddlewarePluginOptions, createMiddlewarePlugin } from "./plugin.mjs";
|
|
3
|
+
export { type KimeshMiddlewareNames, type KnownMiddleware, type MiddlewareContext, type MiddlewareDefinition, type MiddlewareOption, type MiddlewarePluginOptions, type MiddlewareRegistry, type MiddlewareRegistryEntry, type MiddlewareResult, type NavigateToOptions, type NavigationRedirect, type RouteMiddleware, type TypedNavigateToOptions, type TypedRouteMiddleware, abortNavigation, createMiddlewareContext, createMiddlewareExecutor, createMiddlewarePlugin, defineKimeshMiddleware, executeMiddleware, executeMiddlewareChain, middlewarePlugin, navigateTo };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as defineKimeshMiddleware, i as abortNavigation, n as executeMiddleware, o as navigateTo, r as executeMiddlewareChain, t as createMiddlewareExecutor } from "../
|
|
1
|
+
import { t as createMiddlewareContext } from "../context-Dm4fd4Um.mjs";
|
|
2
|
+
import { a as defineKimeshMiddleware, i as abortNavigation, n as executeMiddleware, o as navigateTo, r as executeMiddlewareChain, t as createMiddlewareExecutor } from "../executor-DghrGTKE.mjs";
|
|
3
|
+
import middlewarePlugin, { createMiddlewarePlugin } from "./plugin.mjs";
|
|
3
4
|
|
|
4
5
|
export { abortNavigation, createMiddlewareContext, createMiddlewareExecutor, createMiddlewarePlugin, defineKimeshMiddleware, executeMiddleware, executeMiddlewareChain, middlewarePlugin, navigateTo };
|
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wn as KimeshRuntimePlugin, y as RouteMiddleware } from "../executor-CRRUmoFz.mjs";
|
|
2
|
+
import "../index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/plugin.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for middleware plugin
|
|
7
|
+
*/
|
|
8
|
+
interface MiddlewarePluginOptions {
|
|
9
|
+
/** Global middleware array */
|
|
10
|
+
globalMiddleware?: RouteMiddleware[];
|
|
11
|
+
/** Named middleware registry (lazy loaders) */
|
|
12
|
+
namedMiddleware?: Record<string, () => Promise<RouteMiddleware>>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create middleware plugin with provided registry
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { globalMiddleware, namedMiddleware } from '#kimesh/middleware'
|
|
20
|
+
*
|
|
21
|
+
* const plugin = createMiddlewarePlugin({
|
|
22
|
+
* globalMiddleware,
|
|
23
|
+
* namedMiddleware,
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createMiddlewarePlugin(options?: MiddlewarePluginOptions): KimeshRuntimePlugin<{
|
|
28
|
+
middleware: {
|
|
29
|
+
globalCount: number;
|
|
30
|
+
namedCount: number;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Middleware runtime plugin (legacy - no-op stub)
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Use createMiddlewarePlugin() with explicit registry instead.
|
|
37
|
+
* This export is kept for backward compatibility but does nothing.
|
|
38
|
+
* The kit generates middleware-plugin.mjs that uses createMiddlewarePlugin.
|
|
39
|
+
*/
|
|
40
|
+
declare const middlewarePlugin: KimeshRuntimePlugin<{
|
|
41
|
+
middleware: {
|
|
42
|
+
globalCount: number;
|
|
43
|
+
namedCount: number;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
//#endregion
|
|
2
47
|
export { MiddlewarePluginOptions, createMiddlewarePlugin, middlewarePlugin as default, middlewarePlugin };
|
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as defineKimeshRuntimePlugin, t as createMiddlewareContext } from "../context-Dm4fd4Um.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/middleware/plugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* @kimesh/router-runtime - Middleware Plugin
|
|
6
|
+
*
|
|
7
|
+
* Runtime plugin that integrates middleware execution with Vue Router.
|
|
8
|
+
* Executes middleware in router.beforeEach guard.
|
|
9
|
+
*
|
|
10
|
+
* This plugin receives middleware registry from options instead of importing
|
|
11
|
+
* virtual modules, avoiding Vite pre-bundling issues.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Create middleware plugin with provided registry
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { globalMiddleware, namedMiddleware } from '#kimesh/middleware'
|
|
19
|
+
*
|
|
20
|
+
* const plugin = createMiddlewarePlugin({
|
|
21
|
+
* globalMiddleware,
|
|
22
|
+
* namedMiddleware,
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function createMiddlewarePlugin(options = {}) {
|
|
27
|
+
const globalMiddleware = options.globalMiddleware || [];
|
|
28
|
+
const namedMiddleware = options.namedMiddleware || {};
|
|
29
|
+
const hasRegisteredMiddleware = globalMiddleware.length > 0 || Object.keys(namedMiddleware).length > 0;
|
|
30
|
+
return defineKimeshRuntimePlugin({
|
|
31
|
+
name: "kimesh:middleware",
|
|
32
|
+
enforce: "pre",
|
|
33
|
+
setup(appContext) {
|
|
34
|
+
if (__KIMESH_DEV__ && hasRegisteredMiddleware) console.info(`[Kimesh] Middleware loaded: ${globalMiddleware.length} global, ${Object.keys(namedMiddleware).length} named`);
|
|
35
|
+
appContext.router.beforeEach(async (to, from) => {
|
|
36
|
+
const context = createMiddlewareContext(to, from, appContext);
|
|
37
|
+
for (const middleware of globalMiddleware) {
|
|
38
|
+
if (__KIMESH_DEV__) console.debug("[Kimesh] Executing global middleware");
|
|
39
|
+
const result = await appContext.runWithContext(() => middleware(to, from, context));
|
|
40
|
+
if (result !== void 0) return convertResult(result);
|
|
41
|
+
}
|
|
42
|
+
const routeMiddleware = await extractRouteMiddleware(to, namedMiddleware);
|
|
43
|
+
if (routeMiddleware.length === 0) return true;
|
|
44
|
+
if (__KIMESH_DEV__) console.debug(`[Kimesh] Executing ${routeMiddleware.length} route middleware`);
|
|
45
|
+
for (const middleware of routeMiddleware) {
|
|
46
|
+
const result = await appContext.runWithContext(() => middleware(to, from, context));
|
|
47
|
+
if (result !== void 0) return convertResult(result);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
return { provide: { middleware: {
|
|
52
|
+
globalCount: globalMiddleware.length,
|
|
53
|
+
namedCount: Object.keys(namedMiddleware).length
|
|
54
|
+
} } };
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Middleware runtime plugin (legacy - no-op stub)
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use createMiddlewarePlugin() with explicit registry instead.
|
|
62
|
+
* This export is kept for backward compatibility but does nothing.
|
|
63
|
+
* The kit generates middleware-plugin.mjs that uses createMiddlewarePlugin.
|
|
64
|
+
*/
|
|
65
|
+
const middlewarePlugin = createMiddlewarePlugin({});
|
|
66
|
+
/**
|
|
67
|
+
* Convert middleware result to Vue Router format
|
|
68
|
+
*/
|
|
69
|
+
function convertResult(result) {
|
|
70
|
+
if (result === false) return false;
|
|
71
|
+
if (result && typeof result === "object") return {
|
|
72
|
+
path: result.path,
|
|
73
|
+
name: result.name,
|
|
74
|
+
params: result.params,
|
|
75
|
+
query: result.query,
|
|
76
|
+
replace: result.replace
|
|
77
|
+
};
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Extract route middleware from route definition
|
|
82
|
+
*/
|
|
83
|
+
async function extractRouteMiddleware(route, namedMiddleware) {
|
|
84
|
+
const middlewareOption = route.meta?.middleware || route.meta?.__kimesh?.middleware;
|
|
85
|
+
if (!middlewareOption) return [];
|
|
86
|
+
return normalizeMiddleware(middlewareOption, namedMiddleware);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Load named middleware by name
|
|
90
|
+
*/
|
|
91
|
+
async function loadNamedMiddleware(name, namedMiddleware) {
|
|
92
|
+
const loader = namedMiddleware[name];
|
|
93
|
+
if (!loader) {
|
|
94
|
+
if (__KIMESH_DEV__) console.warn(`[Kimesh] Unknown middleware: ${name}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
return loader();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Normalize middleware to array of functions
|
|
101
|
+
*/
|
|
102
|
+
async function normalizeMiddleware(middleware, namedMiddleware) {
|
|
103
|
+
if (typeof middleware === "string") {
|
|
104
|
+
const mw = await loadNamedMiddleware(middleware, namedMiddleware);
|
|
105
|
+
return mw ? [mw] : [];
|
|
106
|
+
}
|
|
107
|
+
if (typeof middleware === "function") return [middleware];
|
|
108
|
+
if (!Array.isArray(middleware)) return [];
|
|
109
|
+
const result = [];
|
|
110
|
+
for (const item of middleware) if (typeof item === "string") {
|
|
111
|
+
const mw = await loadNamedMiddleware(item, namedMiddleware);
|
|
112
|
+
if (mw) result.push(mw);
|
|
113
|
+
} else if (typeof item === "function") result.push(item);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { createMiddlewarePlugin, middlewarePlugin as default, middlewarePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kimesh/router-runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.40",
|
|
4
4
|
"description": "Runtime router for Kimesh framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"tsdown": "^0.20.0-beta.3",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^4.0.17",
|
|
50
|
-
"vue": "^3.5.
|
|
50
|
+
"vue": "^3.5.29",
|
|
51
51
|
"vue-tsc": "^3.2.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
package/dist/plugin-jUmO3cn2.mjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
//#region src/runtime-plugin.ts
|
|
2
|
-
const KIMESH_PLUGIN_INDICATOR = "__kimesh_plugin";
|
|
3
|
-
/**
|
|
4
|
-
* Define a Kimesh runtime plugin
|
|
5
|
-
*
|
|
6
|
-
* @example Function-style plugin
|
|
7
|
-
* ```ts
|
|
8
|
-
* export default defineKimeshRuntimePlugin((app) => {
|
|
9
|
-
* const analytics = new AnalyticsService()
|
|
10
|
-
* app.router.afterEach((to) => analytics.trackPageView(to.path))
|
|
11
|
-
* return { provide: { analytics } }
|
|
12
|
-
* })
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @example Object-style plugin with hooks
|
|
16
|
-
* ```ts
|
|
17
|
-
* export default defineKimeshRuntimePlugin({
|
|
18
|
-
* name: 'my-plugin',
|
|
19
|
-
* enforce: 'pre',
|
|
20
|
-
* hooks: {
|
|
21
|
-
* 'app:mounted': () => console.log('App mounted!')
|
|
22
|
-
* },
|
|
23
|
-
* setup(app) {
|
|
24
|
-
* return { provide: { myService: new MyService() } }
|
|
25
|
-
* }
|
|
26
|
-
* })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
function defineKimeshRuntimePlugin(plugin) {
|
|
30
|
-
if (typeof plugin === "function") {
|
|
31
|
-
plugin[KIMESH_PLUGIN_INDICATOR] = true;
|
|
32
|
-
return plugin;
|
|
33
|
-
}
|
|
34
|
-
const { name, enforce, order, dependsOn, parallel, hooks, setup } = plugin;
|
|
35
|
-
const pluginFn = setup ?? (() => {});
|
|
36
|
-
pluginFn[KIMESH_PLUGIN_INDICATOR] = true;
|
|
37
|
-
pluginFn._name = name;
|
|
38
|
-
pluginFn.meta = {
|
|
39
|
-
name,
|
|
40
|
-
enforce,
|
|
41
|
-
order,
|
|
42
|
-
dependsOn,
|
|
43
|
-
parallel
|
|
44
|
-
};
|
|
45
|
-
pluginFn.hooks = hooks;
|
|
46
|
-
return pluginFn;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if a value is a Kimesh runtime plugin
|
|
50
|
-
*/
|
|
51
|
-
function isKimeshRuntimePlugin(value) {
|
|
52
|
-
return typeof value === "function" && value[KIMESH_PLUGIN_INDICATOR] === true;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get plugin metadata
|
|
56
|
-
*/
|
|
57
|
-
function getPluginMeta(plugin) {
|
|
58
|
-
return plugin.meta ?? {};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get plugin name
|
|
62
|
-
*/
|
|
63
|
-
function getPluginName(plugin) {
|
|
64
|
-
return plugin._name ?? plugin.meta?.name ?? "anonymous";
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Get plugin hooks
|
|
68
|
-
*/
|
|
69
|
-
function getPluginHooks(plugin) {
|
|
70
|
-
return plugin.hooks;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/middleware/context.ts
|
|
75
|
-
/**
|
|
76
|
-
* Create middleware execution context
|
|
77
|
-
*/
|
|
78
|
-
function createMiddlewareContext(to, from, appContext) {
|
|
79
|
-
return {
|
|
80
|
-
to,
|
|
81
|
-
from,
|
|
82
|
-
router: appContext.router,
|
|
83
|
-
app: appContext,
|
|
84
|
-
data: {}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/middleware/plugin.ts
|
|
90
|
-
/**
|
|
91
|
-
* @kimesh/router-runtime - Middleware Plugin
|
|
92
|
-
*
|
|
93
|
-
* Runtime plugin that integrates middleware execution with Vue Router.
|
|
94
|
-
* Executes middleware in router.beforeEach guard.
|
|
95
|
-
*
|
|
96
|
-
* This plugin receives middleware registry from options instead of importing
|
|
97
|
-
* virtual modules, avoiding Vite pre-bundling issues.
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* Create middleware plugin with provided registry
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* import { globalMiddleware, namedMiddleware } from '#kimesh/middleware'
|
|
105
|
-
*
|
|
106
|
-
* const plugin = createMiddlewarePlugin({
|
|
107
|
-
* globalMiddleware,
|
|
108
|
-
* namedMiddleware,
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
function createMiddlewarePlugin(options = {}) {
|
|
113
|
-
const globalMiddleware = options.globalMiddleware || [];
|
|
114
|
-
const namedMiddleware = options.namedMiddleware || {};
|
|
115
|
-
const hasRegisteredMiddleware = globalMiddleware.length > 0 || Object.keys(namedMiddleware).length > 0;
|
|
116
|
-
return defineKimeshRuntimePlugin({
|
|
117
|
-
name: "kimesh:middleware",
|
|
118
|
-
enforce: "pre",
|
|
119
|
-
setup(appContext) {
|
|
120
|
-
if (__KIMESH_DEV__ && hasRegisteredMiddleware) console.info(`[Kimesh] Middleware loaded: ${globalMiddleware.length} global, ${Object.keys(namedMiddleware).length} named`);
|
|
121
|
-
appContext.router.beforeEach(async (to, from) => {
|
|
122
|
-
const context = createMiddlewareContext(to, from, appContext);
|
|
123
|
-
for (const middleware of globalMiddleware) {
|
|
124
|
-
if (__KIMESH_DEV__) console.debug("[Kimesh] Executing global middleware");
|
|
125
|
-
const result = await appContext.runWithContext(() => middleware(to, from, context));
|
|
126
|
-
if (result !== void 0) return convertResult(result);
|
|
127
|
-
}
|
|
128
|
-
const routeMiddleware = await extractRouteMiddleware(to, namedMiddleware);
|
|
129
|
-
if (routeMiddleware.length === 0) return true;
|
|
130
|
-
if (__KIMESH_DEV__) console.debug(`[Kimesh] Executing ${routeMiddleware.length} route middleware`);
|
|
131
|
-
for (const middleware of routeMiddleware) {
|
|
132
|
-
const result = await appContext.runWithContext(() => middleware(to, from, context));
|
|
133
|
-
if (result !== void 0) return convertResult(result);
|
|
134
|
-
}
|
|
135
|
-
return true;
|
|
136
|
-
});
|
|
137
|
-
return { provide: { middleware: {
|
|
138
|
-
globalCount: globalMiddleware.length,
|
|
139
|
-
namedCount: Object.keys(namedMiddleware).length
|
|
140
|
-
} } };
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Middleware runtime plugin (legacy - no-op stub)
|
|
146
|
-
*
|
|
147
|
-
* @deprecated Use createMiddlewarePlugin() with explicit registry instead.
|
|
148
|
-
* This export is kept for backward compatibility but does nothing.
|
|
149
|
-
* The kit generates middleware-plugin.mjs that uses createMiddlewarePlugin.
|
|
150
|
-
*/
|
|
151
|
-
const middlewarePlugin = createMiddlewarePlugin({});
|
|
152
|
-
/**
|
|
153
|
-
* Convert middleware result to Vue Router format
|
|
154
|
-
*/
|
|
155
|
-
function convertResult(result) {
|
|
156
|
-
if (result === false) return false;
|
|
157
|
-
if (result && typeof result === "object") return {
|
|
158
|
-
path: result.path,
|
|
159
|
-
name: result.name,
|
|
160
|
-
params: result.params,
|
|
161
|
-
query: result.query,
|
|
162
|
-
replace: result.replace
|
|
163
|
-
};
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Extract route middleware from route definition
|
|
168
|
-
*/
|
|
169
|
-
async function extractRouteMiddleware(route, namedMiddleware) {
|
|
170
|
-
const middlewareOption = route.meta?.middleware || route.meta?.__kimesh?.middleware;
|
|
171
|
-
if (!middlewareOption) return [];
|
|
172
|
-
return normalizeMiddleware(middlewareOption, namedMiddleware);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Load named middleware by name
|
|
176
|
-
*/
|
|
177
|
-
async function loadNamedMiddleware(name, namedMiddleware) {
|
|
178
|
-
const loader = namedMiddleware[name];
|
|
179
|
-
if (!loader) {
|
|
180
|
-
if (__KIMESH_DEV__) console.warn(`[Kimesh] Unknown middleware: ${name}`);
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
return loader();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Normalize middleware to array of functions
|
|
187
|
-
*/
|
|
188
|
-
async function normalizeMiddleware(middleware, namedMiddleware) {
|
|
189
|
-
if (typeof middleware === "string") {
|
|
190
|
-
const mw = await loadNamedMiddleware(middleware, namedMiddleware);
|
|
191
|
-
return mw ? [mw] : [];
|
|
192
|
-
}
|
|
193
|
-
if (typeof middleware === "function") return [middleware];
|
|
194
|
-
if (!Array.isArray(middleware)) return [];
|
|
195
|
-
const result = [];
|
|
196
|
-
for (const item of middleware) if (typeof item === "string") {
|
|
197
|
-
const mw = await loadNamedMiddleware(item, namedMiddleware);
|
|
198
|
-
if (mw) result.push(mw);
|
|
199
|
-
} else if (typeof item === "function") result.push(item);
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
var plugin_default = middlewarePlugin;
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
export { KIMESH_PLUGIN_INDICATOR as a, getPluginMeta as c, createMiddlewareContext as i, getPluginName as l, middlewarePlugin as n, defineKimeshRuntimePlugin as o, plugin_default as r, getPluginHooks as s, createMiddlewarePlugin as t, isKimeshRuntimePlugin as u };
|
|
File without changes
|