@route-forge/core 1.3.0 → 1.4.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/README.md +40 -0
- package/dist/codegen.d.cts +1 -1
- package/dist/codegen.d.ts +1 -1
- package/dist/index.cjs +73 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +73 -53
- package/dist/index.js.map +1 -1
- package/dist/route-forge.global.js +73 -53
- package/dist/route-forge.global.js.map +1 -1
- package/dist/route-forge.global.min.js +2 -2
- package/dist/{types-D4PMbR4-.d.cts → types-BFlrOTrN.d.cts} +20 -12
- package/dist/{types-D4PMbR4-.d.ts → types-BFlrOTrN.d.ts} +20 -12
- package/package.json +1 -1
|
@@ -146,6 +146,15 @@ interface ResponseData {
|
|
|
146
146
|
data: unknown;
|
|
147
147
|
config: RequestConfig;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* forge.api() 返回的可取消请求对象。
|
|
151
|
+
* 继承 Promise,附加 abort() 方法用于取消请求。
|
|
152
|
+
* 内部自动创建 AbortController,用户无需手动管理。
|
|
153
|
+
*/
|
|
154
|
+
interface ForgeRequest<T = unknown> extends Promise<T> {
|
|
155
|
+
/** 取消请求。调用后请求将被中止,Promise reject 为 RequestAbortedError */
|
|
156
|
+
abort(): void;
|
|
157
|
+
}
|
|
149
158
|
/**
|
|
150
159
|
* forge.api(level, name, params) 调用参数
|
|
151
160
|
*
|
|
@@ -182,14 +191,6 @@ interface ApiCallParams {
|
|
|
182
191
|
* 单次请求超时覆盖(毫秒);不传时使用 createRouteForge({ timeout }) 全局值
|
|
183
192
|
*/
|
|
184
193
|
timeout?: number;
|
|
185
|
-
/**
|
|
186
|
-
* 请求取消信号(AbortSignal);调用 AbortController.abort() 即可取消请求
|
|
187
|
-
* @example
|
|
188
|
-
* const controller = new AbortController();
|
|
189
|
-
* forge.api('admin', 'users.index', { signal: controller.signal });
|
|
190
|
-
* controller.abort(); // 取消请求
|
|
191
|
-
*/
|
|
192
|
-
signal?: AbortSignal;
|
|
193
194
|
}
|
|
194
195
|
/**
|
|
195
196
|
* 缓存存储介质
|
|
@@ -238,7 +239,7 @@ interface InterceptorHandler<TIn, TOut = TIn> {
|
|
|
238
239
|
*/
|
|
239
240
|
interface RouteForge {
|
|
240
241
|
/** 通过层级 + 路由名调用 API;level 用于确定加载哪个层级的路由元信息 */
|
|
241
|
-
api(level: string, name: string, params?: ApiCallParams):
|
|
242
|
+
api(level: string, name: string, params?: ApiCallParams): ForgeRequest;
|
|
242
243
|
/** 拉取一个或多个层级(自动并发去重) */
|
|
243
244
|
load(level: string | string[]): Promise<void>;
|
|
244
245
|
/** 仅生成 URL,不发请求;level 用于定位路由所在的层级缓存 */
|
|
@@ -323,6 +324,13 @@ interface RouteForgeOptions {
|
|
|
323
324
|
*/
|
|
324
325
|
response?: Array<((r: ResponseData) => unknown | Promise<unknown>) | [((r: ResponseData) => unknown | Promise<unknown>) | undefined, ((e: unknown) => unknown | Promise<unknown>) | undefined]>;
|
|
325
326
|
};
|
|
327
|
+
/**
|
|
328
|
+
* @deprecated 前端校验始终开启,此选项不再被消费。
|
|
329
|
+
* 前端在层级未声明时始终抛 `UnknownLevelError`、路由名不存在始终抛 `UnknownRouteError`、
|
|
330
|
+
* 必填路径参数缺失始终抛 `MissingRouteParamError` —— 校验行为与 strict 无关,静默忽略会掩盖拼写错误、难以排查。
|
|
331
|
+
* 后端 `strict_mode` 的宽松/严格语义(未命中层级路由是否归入 unassigned/fallback)由后端在生成 manifest 时决定。
|
|
332
|
+
* 字段保留仅为向后兼容,传入不会有任何效果。
|
|
333
|
+
*/
|
|
326
334
|
strict?: boolean;
|
|
327
335
|
timeout?: number;
|
|
328
336
|
baseURL?: string;
|
|
@@ -379,14 +387,14 @@ type ForgeApiResponse<L extends string, N extends string> = [
|
|
|
379
387
|
*/
|
|
380
388
|
interface BoundForge<LL = Promise<void>> {
|
|
381
389
|
/** 直接调用 = api 快捷方式,自动带绑定的 level */
|
|
382
|
-
(name: string, params?: ApiCallParams):
|
|
390
|
+
(name: string, params?: ApiCallParams): ForgeRequest;
|
|
383
391
|
/** 当前绑定的 level */
|
|
384
392
|
readonly level: string;
|
|
385
393
|
/** 绑定的路由名前缀(仅传入 prefix 时存在) */
|
|
386
394
|
readonly prefix?: string;
|
|
387
395
|
/** level 加载状态(core: Promise<void>,Vue: Ref<boolean>) */
|
|
388
396
|
levelLoaded: LL;
|
|
389
|
-
api(name: string, params?: ApiCallParams):
|
|
397
|
+
api(name: string, params?: ApiCallParams): ForgeRequest;
|
|
390
398
|
route(name: string, params?: Record<string, unknown>): string;
|
|
391
399
|
url(name: string, params?: Record<string, unknown>): string;
|
|
392
400
|
hasRoute(name: string): boolean;
|
|
@@ -443,4 +451,4 @@ interface UseForgeByPrefixReturn {
|
|
|
443
451
|
route: (suffix: string, params?: Record<string, unknown>) => string;
|
|
444
452
|
}
|
|
445
453
|
|
|
446
|
-
export { type AdapterOption as A, type BoundForge as B, type CacheStorage as C, type Fetcher as F, type InterceptorManager as I, type LevelRoutesResponse as L, type RouteMeta as R, type SummaryResponse as S, type UseForgeApiBoundCall as U, type InterceptorHandler as a, type RouteForgeOptions as b, type RouteForge as c, type ApiCallParams as d, type ForgeApiParams as e, type ForgeApiResponse as f, type
|
|
454
|
+
export { type AdapterOption as A, type BoundForge as B, type CacheStorage as C, type Fetcher as F, type InterceptorManager as I, type LevelRoutesResponse as L, type RouteMeta as R, type SummaryResponse as S, type UseForgeApiBoundCall as U, type InterceptorHandler as a, type RouteForgeOptions as b, type RouteForge as c, type ApiCallParams as d, type ForgeApiParams as e, type ForgeApiResponse as f, type ForgeRequest as g, type ForgeRouteMap as h, type ForgeRouteName as i, type LoadingChangeCallback as j, type LoadingChangeEvent as k, LoadingTracker as l, type RequestConfig as m, type ResponseData as n, type UseForgeApiBoundReturn as o, type UseForgeApiCall as p, type UseForgeApiReturn as q, type UseForgeByPrefixReturn as r };
|
|
@@ -146,6 +146,15 @@ interface ResponseData {
|
|
|
146
146
|
data: unknown;
|
|
147
147
|
config: RequestConfig;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* forge.api() 返回的可取消请求对象。
|
|
151
|
+
* 继承 Promise,附加 abort() 方法用于取消请求。
|
|
152
|
+
* 内部自动创建 AbortController,用户无需手动管理。
|
|
153
|
+
*/
|
|
154
|
+
interface ForgeRequest<T = unknown> extends Promise<T> {
|
|
155
|
+
/** 取消请求。调用后请求将被中止,Promise reject 为 RequestAbortedError */
|
|
156
|
+
abort(): void;
|
|
157
|
+
}
|
|
149
158
|
/**
|
|
150
159
|
* forge.api(level, name, params) 调用参数
|
|
151
160
|
*
|
|
@@ -182,14 +191,6 @@ interface ApiCallParams {
|
|
|
182
191
|
* 单次请求超时覆盖(毫秒);不传时使用 createRouteForge({ timeout }) 全局值
|
|
183
192
|
*/
|
|
184
193
|
timeout?: number;
|
|
185
|
-
/**
|
|
186
|
-
* 请求取消信号(AbortSignal);调用 AbortController.abort() 即可取消请求
|
|
187
|
-
* @example
|
|
188
|
-
* const controller = new AbortController();
|
|
189
|
-
* forge.api('admin', 'users.index', { signal: controller.signal });
|
|
190
|
-
* controller.abort(); // 取消请求
|
|
191
|
-
*/
|
|
192
|
-
signal?: AbortSignal;
|
|
193
194
|
}
|
|
194
195
|
/**
|
|
195
196
|
* 缓存存储介质
|
|
@@ -238,7 +239,7 @@ interface InterceptorHandler<TIn, TOut = TIn> {
|
|
|
238
239
|
*/
|
|
239
240
|
interface RouteForge {
|
|
240
241
|
/** 通过层级 + 路由名调用 API;level 用于确定加载哪个层级的路由元信息 */
|
|
241
|
-
api(level: string, name: string, params?: ApiCallParams):
|
|
242
|
+
api(level: string, name: string, params?: ApiCallParams): ForgeRequest;
|
|
242
243
|
/** 拉取一个或多个层级(自动并发去重) */
|
|
243
244
|
load(level: string | string[]): Promise<void>;
|
|
244
245
|
/** 仅生成 URL,不发请求;level 用于定位路由所在的层级缓存 */
|
|
@@ -323,6 +324,13 @@ interface RouteForgeOptions {
|
|
|
323
324
|
*/
|
|
324
325
|
response?: Array<((r: ResponseData) => unknown | Promise<unknown>) | [((r: ResponseData) => unknown | Promise<unknown>) | undefined, ((e: unknown) => unknown | Promise<unknown>) | undefined]>;
|
|
325
326
|
};
|
|
327
|
+
/**
|
|
328
|
+
* @deprecated 前端校验始终开启,此选项不再被消费。
|
|
329
|
+
* 前端在层级未声明时始终抛 `UnknownLevelError`、路由名不存在始终抛 `UnknownRouteError`、
|
|
330
|
+
* 必填路径参数缺失始终抛 `MissingRouteParamError` —— 校验行为与 strict 无关,静默忽略会掩盖拼写错误、难以排查。
|
|
331
|
+
* 后端 `strict_mode` 的宽松/严格语义(未命中层级路由是否归入 unassigned/fallback)由后端在生成 manifest 时决定。
|
|
332
|
+
* 字段保留仅为向后兼容,传入不会有任何效果。
|
|
333
|
+
*/
|
|
326
334
|
strict?: boolean;
|
|
327
335
|
timeout?: number;
|
|
328
336
|
baseURL?: string;
|
|
@@ -379,14 +387,14 @@ type ForgeApiResponse<L extends string, N extends string> = [
|
|
|
379
387
|
*/
|
|
380
388
|
interface BoundForge<LL = Promise<void>> {
|
|
381
389
|
/** 直接调用 = api 快捷方式,自动带绑定的 level */
|
|
382
|
-
(name: string, params?: ApiCallParams):
|
|
390
|
+
(name: string, params?: ApiCallParams): ForgeRequest;
|
|
383
391
|
/** 当前绑定的 level */
|
|
384
392
|
readonly level: string;
|
|
385
393
|
/** 绑定的路由名前缀(仅传入 prefix 时存在) */
|
|
386
394
|
readonly prefix?: string;
|
|
387
395
|
/** level 加载状态(core: Promise<void>,Vue: Ref<boolean>) */
|
|
388
396
|
levelLoaded: LL;
|
|
389
|
-
api(name: string, params?: ApiCallParams):
|
|
397
|
+
api(name: string, params?: ApiCallParams): ForgeRequest;
|
|
390
398
|
route(name: string, params?: Record<string, unknown>): string;
|
|
391
399
|
url(name: string, params?: Record<string, unknown>): string;
|
|
392
400
|
hasRoute(name: string): boolean;
|
|
@@ -443,4 +451,4 @@ interface UseForgeByPrefixReturn {
|
|
|
443
451
|
route: (suffix: string, params?: Record<string, unknown>) => string;
|
|
444
452
|
}
|
|
445
453
|
|
|
446
|
-
export { type AdapterOption as A, type BoundForge as B, type CacheStorage as C, type Fetcher as F, type InterceptorManager as I, type LevelRoutesResponse as L, type RouteMeta as R, type SummaryResponse as S, type UseForgeApiBoundCall as U, type InterceptorHandler as a, type RouteForgeOptions as b, type RouteForge as c, type ApiCallParams as d, type ForgeApiParams as e, type ForgeApiResponse as f, type
|
|
454
|
+
export { type AdapterOption as A, type BoundForge as B, type CacheStorage as C, type Fetcher as F, type InterceptorManager as I, type LevelRoutesResponse as L, type RouteMeta as R, type SummaryResponse as S, type UseForgeApiBoundCall as U, type InterceptorHandler as a, type RouteForgeOptions as b, type RouteForge as c, type ApiCallParams as d, type ForgeApiParams as e, type ForgeApiResponse as f, type ForgeRequest as g, type ForgeRouteMap as h, type ForgeRouteName as i, type LoadingChangeCallback as j, type LoadingChangeEvent as k, LoadingTracker as l, type RequestConfig as m, type ResponseData as n, type UseForgeApiBoundReturn as o, type UseForgeApiCall as p, type UseForgeApiReturn as q, type UseForgeByPrefixReturn as r };
|