@kimesh/router-runtime 0.2.40 → 0.2.41
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/{executor-CRRUmoFz.d.mts → index-B0Xt0G76.d.mts} +45 -2
- package/dist/index.d.mts +2 -5
- package/dist/index.mjs +2 -4
- package/dist/middleware/index.d.mts +2 -3
- package/dist/middleware/index.mjs +2 -3
- package/dist/middleware/plugin.d.mts +1 -46
- package/dist/middleware/plugin.mjs +1 -116
- package/dist/plugin-ppRzW7AM.mjs +204 -0
- package/package.json +4 -4
- package/dist/context-Dm4fd4Um.mjs +0 -89
- /package/dist/{executor-DghrGTKE.mjs → middleware-DvCiATAB.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
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, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRaw, Router } from "vue-router";
|
|
4
|
+
import { LocationQueryValue, NavigationFailure, NavigationGuard, NavigationHookAfter, RouteLocationNormalized, RouteLocationNormalized as RouteLocationNormalized$1, RouteLocationNormalizedLoaded, RouteLocationNormalizedLoaded as RouteLocationNormalizedLoaded$1, RouteRecordRaw, RouteRecordRaw as RouteRecordRaw$1, Router, Router as Router$1, onBeforeRouteLeave, onBeforeRouteUpdate, useLink, useRoute as useRoute$1, useRouter as useRouter$1 } from "vue-router";
|
|
5
5
|
import { QueryClient, QueryClientConfig } from "@tanstack/vue-query";
|
|
6
6
|
import { Hookable } from "hookable";
|
|
7
7
|
|
|
@@ -1748,6 +1748,49 @@ 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
|
|
1751
1794
|
//#region src/middleware/context.d.ts
|
|
1752
1795
|
/**
|
|
1753
1796
|
* Create middleware execution context
|
|
@@ -1778,4 +1821,4 @@ declare function createMiddlewareExecutor(appContext: KimeshAppContext): {
|
|
|
1778
1821
|
executeChain(middlewares: RouteMiddleware[], context: MiddlewareContext): Promise<void | false | NavigationRedirect>;
|
|
1779
1822
|
};
|
|
1780
1823
|
//#endregion
|
|
1781
|
-
export {
|
|
1824
|
+
export { NavigationMiddlewareOptions as $, BeforeLoadContext as $t, MiddlewareRegistryEntry as A, RoutePath as An, mergeAllRouteHeads as At, isLayoutRouteMeta as B, KimeshRuntimePluginMeta as Bn, defineKimeshRuntimePlugin as Bt, navigateTo as C, RouteHeadFn as Cn, KmLinkProps as Ct, MiddlewareDefinition as D, RouteNames as Dn, applyTitleTemplate as Dt, MiddlewareContext as E, RouteNamedMap as En, applyHeadConfigNative as Et, LayoutLoaderData as F, TypedRedirectStatic as Fn, routerPlugin as Ft, useRouteQueryBoolean as G, RuntimeConfigPublic as Gn, defineContext as Gt, RouteQueryValueRaw as H, NavigationAfterHookContext as Hn, getPluginMeta as Ht, LayoutRouteMeta as I, KimeshAppContext as In, applyPlugin as It, useLoaderData as J, defineRoute as Jt, useRouteQueryNumber as K, useKimeshContext as Kt, LoaderDataKey as L, KimeshRuntimeHooks as Ln, applyPlugins as Lt, NavigationRedirect as M, SearchSchema as Mn, QueryPluginOptions as Mt, RouteMiddleware as N, TypedNavigationRedirect as Nn, getCorePlugins as Nt, MiddlewareOption as O, RouteParams as On, collectRouteHeads as Ot, TypedRouteMiddleware as P, TypedRedirectDynamic as Pn, queryPlugin as Pt, NavigationErrorContext as Q, AugmentedContext as Qt, UseMatchLoaderDataOptions as R, KimeshRuntimePlugin as Rn, applyPluginsWithParallel as Rt, defineKimeshMiddleware as S, RouteHeadContext as Sn, KmLink as St, KnownMiddleware as T, RouteLocationRaw as Tn, HeadPluginOptions as Tt, UseRouteQueryOptions as U, NavigationErrorHookContext as Un, getPluginName as Ut, RouteQueryTransform as V, KimeshRuntimePluginResult as Vn, getPluginHooks as Vt, useRouteQuery as W, NavigationHookContext as Wn, isKimeshRuntimePlugin as Wt, useRouteLoaderData as X, KIMESH_APP_CONTEXT_KEY as Xt, useMatchLoaderData as Y, CreateKimeshAppOptionsExtended as Yt, NavigationContext as Z, createKimeshApp as Zt, createMiddlewarePlugin as _, ParamValueZeroOrOne as _n, useSearch as _t, RouteRecordRaw$1 as a, FullContext as an, getKmStateKeys as at, TypedNavigateToOptions as b, RouteDefinition as bn, installLoaderGuard as bt, onBeforeRouteUpdate as c, InlineRouteMiddleware as cn, tryUseKimeshApp as ct, useRouter$1 as d, KimeshContext as dn, useRuntimeConfig as dt, BeforeLoadContextFull as en, useAfterNavigation as et, createMiddlewareExecutor as f, LoaderContext as fn, NavigateOptions as ft, MiddlewarePluginOptions as g, ParamValueZeroOrMore as gn, UseSearchReturn as gt, createMiddlewareContext as h, ParamValueOneOrMore as hn, useReactiveParams as ht, RouteLocationNormalizedLoaded$1 as i, FileRouteOptions as in, clearKmState as it, MiddlewareResult as j, RouteRecordInfo as jn, mergeHeadConfigs as jt, MiddlewareRegistry as k, RouteParamsRaw as kn, createHeadPlugin as kt, useLink as l, KIMESH_CONTEXT_KEY as ln, useKimeshApp as lt, executeMiddlewareChain as m, ParamValue as mn, useParams as mt, NavigationHookAfter as n, CreateKimeshAppOptions as nn, useNavigationMiddleware as nt, Router$1 as o, HasParams as on, hasKmState as ot, executeMiddleware as p, LoaderFn as pn, useNavigate as pt, useLayoutData as q, createFileRoute as qt, RouteLocationNormalized$1 as r, ExtractRouteParams as rn, STATE_KEY_PREFIX as rt, onBeforeRouteLeave as s, InlineMiddlewareContext as sn, useState as st, NavigationGuard as t, BeforeLoadFn as tn, useNavigationGuard as tt, useRoute$1 as u, KimeshApp as un, RuntimeConfig as ut, middlewarePlugin as v, PendingConfig as vn, LoaderGuardOptions as vt, KimeshMiddlewareNames as w, RouteInfoByName as wn, KmOutlet as wt, abortNavigation as x, RouteHeadConfig as xn, KmDeferred as xt, NavigateToOptions as y, RouteContext as yn, createLoaderGuard as yt, createLoaderDataKey as z, KimeshRuntimePluginDefinition as zn, KIMESH_PLUGIN_INDICATOR as zt };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
|
|
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 };
|
|
1
|
+
import { $ as NavigationMiddlewareOptions, $t as BeforeLoadContext, An as RoutePath, At as mergeAllRouteHeads, B as isLayoutRouteMeta, Bn as KimeshRuntimePluginMeta, Bt as defineKimeshRuntimePlugin, C as navigateTo, Cn as RouteHeadFn, Ct as KmLinkProps, D as MiddlewareDefinition, Dn as RouteNames, Dt as applyTitleTemplate, E as MiddlewareContext, En as RouteNamedMap, Et as applyHeadConfigNative, F as LayoutLoaderData, Fn as TypedRedirectStatic, Ft as routerPlugin, G as useRouteQueryBoolean, Gn as RuntimeConfigPublic, Gt as defineContext, H as RouteQueryValueRaw, Hn as NavigationAfterHookContext, Ht as getPluginMeta, I as LayoutRouteMeta, In as KimeshAppContext, It as applyPlugin, J as useLoaderData, Jt as defineRoute, K as useRouteQueryNumber, Kt as useKimeshContext, L as LoaderDataKey, Ln as KimeshRuntimeHooks, Lt as applyPlugins, M as NavigationRedirect, Mn as SearchSchema, Mt as QueryPluginOptions, N as RouteMiddleware, Nn as TypedNavigationRedirect, Nt as getCorePlugins, O as MiddlewareOption, On as RouteParams, Ot as collectRouteHeads, P as TypedRouteMiddleware, Pn as TypedRedirectDynamic, Pt as queryPlugin, Q as NavigationErrorContext, Qt as AugmentedContext, R as UseMatchLoaderDataOptions, Rn as KimeshRuntimePlugin, Rt as applyPluginsWithParallel, S as defineKimeshMiddleware, Sn as RouteHeadContext, St as KmLink, T as KnownMiddleware, Tn as RouteLocationRaw, Tt as HeadPluginOptions, U as UseRouteQueryOptions, Un as NavigationErrorHookContext, Ut as getPluginName, V as RouteQueryTransform, Vn as KimeshRuntimePluginResult, Vt as getPluginHooks, W as useRouteQuery, Wn as NavigationHookContext, Wt as isKimeshRuntimePlugin, X as useRouteLoaderData, Xt as KIMESH_APP_CONTEXT_KEY, Y as useMatchLoaderData, Yt as CreateKimeshAppOptionsExtended, Z as NavigationContext, Zt as createKimeshApp, _ as createMiddlewarePlugin, _n as ParamValueZeroOrOne, _t as useSearch, a as RouteRecordRaw, an as FullContext, at as getKmStateKeys, bn as RouteDefinition, bt as installLoaderGuard, c as onBeforeRouteUpdate, cn as InlineRouteMiddleware, ct as tryUseKimeshApp, d as useRouter, dn as KimeshContext, dt as useRuntimeConfig, en as BeforeLoadContextFull, et as useAfterNavigation, f as createMiddlewareExecutor, fn as LoaderContext, ft as NavigateOptions, g as MiddlewarePluginOptions, gn as ParamValueZeroOrMore, gt as UseSearchReturn, h as createMiddlewareContext, hn as ParamValueOneOrMore, ht as useReactiveParams, i as RouteLocationNormalizedLoaded, in as FileRouteOptions, it as clearKmState, j as MiddlewareResult, jn as RouteRecordInfo, jt as mergeHeadConfigs, kn as RouteParamsRaw, kt as createHeadPlugin, l as useLink, ln as KIMESH_CONTEXT_KEY, lt as useKimeshApp, mn as ParamValue, mt as useParams, n as NavigationHookAfter, nn as CreateKimeshAppOptions, nt as useNavigationMiddleware, o as Router, on as HasParams, ot as hasKmState, pn as LoaderFn, pt as useNavigate, q as useLayoutData, qt as createFileRoute, r as RouteLocationNormalized, rn as ExtractRouteParams, rt as STATE_KEY_PREFIX, s as onBeforeRouteLeave, sn as InlineMiddlewareContext, st as useState, t as NavigationGuard, tn as BeforeLoadFn, tt as useNavigationGuard, u as useRoute, un as KimeshApp, ut as RuntimeConfig, v as middlewarePlugin, vn as PendingConfig, vt as LoaderGuardOptions, w as KimeshMiddlewareNames, wn as RouteInfoByName, wt as KmOutlet, x as abortNavigation, xn as RouteHeadConfig, xt as KmDeferred, y as NavigateToOptions, yn as RouteContext, yt as createLoaderGuard, z as createLoaderDataKey, zn as KimeshRuntimePluginDefinition, zt as KIMESH_PLUGIN_INDICATOR } from "./index-B0Xt0G76.mjs";
|
|
2
|
+
export { AugmentedContext, BeforeLoadContext, BeforeLoadContextFull, BeforeLoadFn, CreateKimeshAppOptions, CreateKimeshAppOptionsExtended, ExtractRouteParams, FileRouteOptions, FullContext, HasParams, HeadPluginOptions, InlineMiddlewareContext, InlineRouteMiddleware, KIMESH_APP_CONTEXT_KEY, KIMESH_CONTEXT_KEY, KIMESH_PLUGIN_INDICATOR, KimeshApp, KimeshAppContext, KimeshContext, KimeshMiddlewareNames, KimeshRuntimeHooks, KimeshRuntimePlugin, KimeshRuntimePluginDefinition, KimeshRuntimePluginMeta, KimeshRuntimePluginResult, KmDeferred, KmLink, KmLinkProps, KmOutlet, KnownMiddleware, LayoutLoaderData, LayoutRouteMeta, LoaderContext, LoaderDataKey, LoaderFn, LoaderGuardOptions, MiddlewareContext, MiddlewareDefinition, MiddlewareOption, MiddlewarePluginOptions, MiddlewareResult, NavigateOptions, NavigateToOptions, NavigationAfterHookContext, NavigationContext, NavigationErrorContext, NavigationErrorHookContext, NavigationGuard, NavigationHookAfter, NavigationHookContext, NavigationMiddlewareOptions, NavigationRedirect, ParamValue, ParamValueOneOrMore, ParamValueZeroOrMore, ParamValueZeroOrOne, PendingConfig, QueryPluginOptions, RouteContext, RouteDefinition, RouteHeadConfig, RouteHeadContext, RouteHeadFn, RouteInfoByName, RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteLocationRaw, RouteMiddleware, RouteNamedMap, RouteNames, RouteParams, RouteParamsRaw, RoutePath, RouteQueryTransform, RouteQueryValueRaw, RouteRecordInfo, RouteRecordRaw, Router, RuntimeConfig, RuntimeConfigPublic, STATE_KEY_PREFIX, SearchSchema, TypedNavigationRedirect, TypedRedirectDynamic, TypedRedirectStatic, TypedRouteMiddleware, UseMatchLoaderDataOptions, UseRouteQueryOptions, 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,7 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as defineKimeshMiddleware, i as abortNavigation, o as navigateTo, t as createMiddlewareExecutor } from "./
|
|
3
|
-
import middlewarePlugin, { createMiddlewarePlugin } from "./middleware/plugin.mjs";
|
|
4
|
-
import "./middleware/index.mjs";
|
|
1
|
+
import { a as defineKimeshRuntimePlugin, c as getPluginName, i as KIMESH_PLUGIN_INDICATOR, l as isKimeshRuntimePlugin, n as middlewarePlugin, o as getPluginHooks, r as createMiddlewareContext, s as getPluginMeta, t as createMiddlewarePlugin } from "./plugin-ppRzW7AM.mjs";
|
|
2
|
+
import { a as defineKimeshMiddleware, i as abortNavigation, o as navigateTo, t as createMiddlewareExecutor } from "./middleware-DvCiATAB.mjs";
|
|
5
3
|
import { KeepAlive, Suspense, Transition, computed, createApp, customRef, defineComponent, getCurrentInstance, h, inject, isRef, nextTick, onErrorCaptured, onScopeDispose, reactive, ref, toRef, toValue, watch } from "vue";
|
|
6
4
|
import { RouterLink, RouterView, createRouter, createWebHashHistory, createWebHistory, onBeforeRouteLeave, onBeforeRouteUpdate, routeLocationKey, routerKey, useLink, useRoute, useRoute as useRoute$1, useRouter, useRouter as useRouter$1 } from "vue-router";
|
|
7
5
|
import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
+
import { A as MiddlewareRegistryEntry, C as navigateTo, D as MiddlewareDefinition, E as MiddlewareContext, M as NavigationRedirect, N as RouteMiddleware, O as MiddlewareOption, P as TypedRouteMiddleware, S as defineKimeshMiddleware, T as KnownMiddleware, _ as createMiddlewarePlugin, b as TypedNavigateToOptions, f as createMiddlewareExecutor, g as MiddlewarePluginOptions, h as createMiddlewareContext, j as MiddlewareResult, k as MiddlewareRegistry, m as executeMiddlewareChain, p as executeMiddleware, v as middlewarePlugin, w as KimeshMiddlewareNames, x as abortNavigation, y as NavigateToOptions } from "../index-B0Xt0G76.mjs";
|
|
2
|
+
export { KimeshMiddlewareNames, KnownMiddleware, MiddlewareContext, MiddlewareDefinition, MiddlewareOption, MiddlewarePluginOptions, MiddlewareRegistry, MiddlewareRegistryEntry, MiddlewareResult, NavigateToOptions, NavigationRedirect, RouteMiddleware, TypedNavigateToOptions, TypedRouteMiddleware, abortNavigation, createMiddlewareContext, createMiddlewareExecutor, createMiddlewarePlugin, defineKimeshMiddleware, executeMiddleware, executeMiddlewareChain, middlewarePlugin, navigateTo };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as defineKimeshMiddleware, i as abortNavigation, n as executeMiddleware, o as navigateTo, r as executeMiddlewareChain, t as createMiddlewareExecutor } from "../
|
|
3
|
-
import middlewarePlugin, { createMiddlewarePlugin } from "./plugin.mjs";
|
|
1
|
+
import { n as middlewarePlugin, r as createMiddlewareContext, t as createMiddlewarePlugin } from "../plugin-ppRzW7AM.mjs";
|
|
2
|
+
import { a as defineKimeshMiddleware, i as abortNavigation, n as executeMiddleware, o as navigateTo, r as executeMiddlewareChain, t as createMiddlewareExecutor } from "../middleware-DvCiATAB.mjs";
|
|
4
3
|
|
|
5
4
|
export { abortNavigation, createMiddlewareContext, createMiddlewareExecutor, createMiddlewarePlugin, defineKimeshMiddleware, executeMiddleware, executeMiddlewareChain, middlewarePlugin, navigateTo };
|
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
1
|
+
import { _ as createMiddlewarePlugin, g as MiddlewarePluginOptions, v as middlewarePlugin } from "../index-B0Xt0G76.mjs";
|
|
47
2
|
export { MiddlewarePluginOptions, createMiddlewarePlugin, middlewarePlugin as default, middlewarePlugin };
|
|
@@ -1,118 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as middlewarePlugin, t as createMiddlewarePlugin } from "../plugin-ppRzW7AM.mjs";
|
|
2
2
|
|
|
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
3
|
export { createMiddlewarePlugin, middlewarePlugin as default, middlewarePlugin };
|
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
export { defineKimeshRuntimePlugin as a, getPluginName as c, KIMESH_PLUGIN_INDICATOR as i, isKimeshRuntimePlugin as l, middlewarePlugin as n, getPluginHooks as o, createMiddlewareContext as r, getPluginMeta as s, createMiddlewarePlugin as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kimesh/router-runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.41",
|
|
4
4
|
"description": "Runtime router for Kimesh framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"vue-router": "^4.6.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@tanstack/vue-query": "^5.92.
|
|
45
|
+
"@tanstack/vue-query": "^5.92.9",
|
|
46
46
|
"@types/node": "^25.0.8",
|
|
47
|
-
"tsdown": "^0.20.
|
|
47
|
+
"tsdown": "^0.20.3",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^4.0.17",
|
|
50
50
|
"vue": "^3.5.29",
|
|
51
|
-
"vue-tsc": "^3.2.
|
|
51
|
+
"vue-tsc": "^3.2.5"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@tanstack/vue-query": "^5.0.0",
|
|
@@ -1,89 +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
|
-
export { getPluginMeta as a, getPluginHooks as i, KIMESH_PLUGIN_INDICATOR as n, getPluginName as o, defineKimeshRuntimePlugin as r, isKimeshRuntimePlugin as s, createMiddlewareContext as t };
|
|
File without changes
|