@ubean/shared 0.7.3 → 0.7.5

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/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { Context, Env, Handler, MiddlewareHandler } from "hono";
2
2
  import { RequestIdVariables } from "hono/request-id";
3
3
  import { HandlerResponse, Input as Input$1 } from "hono/types";
4
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
5
- //#region src/types.d.ts
6
5
  /**
7
6
  * 基础路由元数据,由 @ubean/scan 使用。
8
7
  * 扩展的 RouteMeta 在此处定义,增加了 rateLimit 和 cache 字段。
@@ -362,8 +361,6 @@ export declare function fail<T extends Record<string, string>>(status: number, e
362
361
  * Type guard: is the value an `ActionFailure` (returned by `fail()`)?
363
362
  */
364
363
  export declare function isActionFailure(value: unknown): value is ActionFailure;
365
- //#endregion
366
- //#region src/error.d.ts
367
364
  export declare class UbeanError extends Error {
368
365
  statusCode: number;
369
366
  statusMessage: string;
@@ -378,8 +375,6 @@ export declare function createError(options: {
378
375
  }): UbeanError;
379
376
  export declare function isUbeanError(err: unknown): err is UbeanError;
380
377
  export declare function errorToResponse(c: unknown, err?: unknown): Response;
381
- //#endregion
382
- //#region src/env.d.ts
383
378
  export type EnvSchema = Record<string, EnvFieldDef>;
384
379
  /**
385
380
  * 环境变量的**归属维度**(借用 Astro `astro:env` 的模型,见 docs/contracts/env-v1.md)。
@@ -553,8 +548,6 @@ export declare function useRuntimeEnv<T = string>(key: string, defaultValue?: T)
553
548
  * 产物,只看 `process` 会在 worker/browser 里误判为真。
554
549
  */
555
550
  export declare function isNodeRuntime(): boolean;
556
- //#endregion
557
- //#region src/path.d.ts
558
551
  /**
559
552
  * 标准化路径:替换反斜杠、去除首尾多余斜杠、合并连续斜杠。
560
553
  */
@@ -579,8 +572,6 @@ export declare function getStem(filename: string): string;
579
572
  * 将文件路径转换为人类可读的标题。
580
573
  */
581
574
  export declare function pathToTitle(path: string): string;
582
- //#endregion
583
- //#region src/glob.d.ts
584
575
  /**
585
576
  * 通配符匹配,支持:
586
577
  * - `**` 多段递归 ('/blog/**' 匹配 '/blog/a/b/c' 与 '/blog')
@@ -594,14 +585,10 @@ export declare function matchGlob(route: string, pattern: string): boolean;
594
585
  * 检查 route 是否匹配任意一个 patterns。
595
586
  */
596
587
  export declare function matchAnyGlob(route: string, patterns: string[]): boolean;
597
- //#endregion
598
- //#region src/string.d.ts
599
588
  /**
600
589
  * 将字符串首字母大写。
601
590
  */
602
591
  export declare function capitalize(str: string): string;
603
- //#endregion
604
- //#region src/first-paint.d.ts
605
592
  /**
606
593
  * 首帧主题脚本的归属判据。
607
594
  *
@@ -633,5 +620,4 @@ export interface FirstPaintOwnerConfig {
633
620
  * - `ui.theme === false` 或 `ui.theme.initScript === false`(显式手动注入)
634
621
  */
635
622
  export declare function integrationOwnsFirstPaintScript(config: FirstPaintOwnerConfig): boolean;
636
- //#endregion
637
623
  export {};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { kebabCase } from "scule";
2
- //#region src/types.ts
2
+ // src/types.ts
3
3
  /**
4
4
  * Brand used to identify a server action at runtime (`Symbol`).
5
5
  */
@@ -52,8 +52,7 @@ function fail(status, errors) {
52
52
  function isActionFailure(value) {
53
53
  return typeof value === "object" && value !== null && value.__actionFailure === true;
54
54
  }
55
- //#endregion
56
- //#region src/error.ts
55
+ // src/error.ts
57
56
  var UbeanError = class extends Error {
58
57
  statusCode;
59
58
  statusMessage;
@@ -111,8 +110,7 @@ function errorToResponse(c, err) {
111
110
  headers: { "Content-Type": "application/json" }
112
111
  });
113
112
  }
114
- //#endregion
115
- //#region src/env.ts
113
+ // src/env.ts
116
114
  function assertEnvFieldCombo(options) {
117
115
  if (options.context === "client" && options.access === "secret") throw new Error("Invalid env field: context 'client' cannot be combined with access 'secret'. Secrets are never sent to the client; use `{ context: 'server', access: 'secret' }`.");
118
116
  }
@@ -500,16 +498,14 @@ function isNodeRuntime() {
500
498
  const proc = globalThis.process;
501
499
  return typeof proc?.versions?.node === "string" || typeof proc?.versions?.bun === "string";
502
500
  }
503
- //#endregion
504
- //#region src/string.ts
501
+ // src/string.ts
505
502
  /**
506
503
  * 将字符串首字母大写。
507
504
  */
508
505
  function capitalize(str) {
509
506
  return str.charAt(0).toUpperCase() + str.slice(1);
510
507
  }
511
- //#endregion
512
- //#region src/path.ts
508
+ // src/path.ts
513
509
  /**
514
510
  * 标准化路径:替换反斜杠、去除首尾多余斜杠、合并连续斜杠。
515
511
  */
@@ -552,8 +548,7 @@ function pathToTitle(path) {
552
548
  if (stem === "index") return kebabCase(getBasename(getDirname(path)) || "home").split("-").map(capitalize).join(" ");
553
549
  return kebabCase(stem).split("-").map(capitalize).join(" ");
554
550
  }
555
- //#endregion
556
- //#region src/glob.ts
551
+ // src/glob.ts
557
552
  /**
558
553
  * 通配符匹配,支持:
559
554
  * - `**` 多段递归 ('/blog/**' 匹配 '/blog/a/b/c' 与 '/blog')
@@ -583,8 +578,7 @@ function matchGlob(route, pattern) {
583
578
  function matchAnyGlob(route, patterns) {
584
579
  return patterns.some((p) => matchGlob(route, p));
585
580
  }
586
- //#endregion
587
- //#region src/first-paint.ts
581
+ // src/first-paint.ts
588
582
  /**
589
583
  * `ui` 是否接管首帧主题脚本。
590
584
  *
@@ -603,5 +597,4 @@ function integrationOwnsFirstPaintScript(config) {
603
597
  if (typeof options.theme === "object" && options.theme !== null && options.theme.initScript === false) return false;
604
598
  return true;
605
599
  }
606
- //#endregion
607
600
  export { ACTION_BRAND, ActionError, UbeanError, capitalize, createError, defineEnv, envField, errorToResponse, fail, getBasename, getDirname, getExtension, getStem, integrationOwnsFirstPaintScript, isActionFailure, isEnvFieldMeta, isNodeRuntime, isServerAction, isUbeanError, matchAnyGlob, matchGlob, normalizeEnvSchema, normalizePath, pathToTitle, resolveEnvSchema, setRuntimeEnv, useRuntimeEnv };
@@ -1,6 +1,5 @@
1
- import { n as RequestLoggerOptions } from "../types-CFy62PZV.js";
1
+ import { n as RequestLoggerOptions } from "../types-CSUrGnuZ.js";
2
2
  import { MiddlewareHandler } from "hono";
3
- //#region src/logger/hono.d.ts
4
3
  /**
5
4
  * Hono 请求日志中间件。
6
5
  *
@@ -20,5 +19,4 @@ import { MiddlewareHandler } from "hono";
20
19
  * }));
21
20
  * ```
22
21
  */
23
- export declare function createRequestLoggerMiddleware(options?: RequestLoggerOptions): MiddlewareHandler;
24
- //#endregion
22
+ export declare function createRequestLoggerMiddleware(options?: RequestLoggerOptions): MiddlewareHandler;
@@ -1,5 +1,5 @@
1
- import { n as getLogger } from "../logger-NMOHjTCB.js";
2
- //#region src/logger/hono.ts
1
+ import { n as getLogger } from "../logger-Ba3-ofGb.js";
2
+ // src/logger/hono.ts
3
3
  /**
4
4
  * 判断路径是否应被跳过。
5
5
  */
@@ -100,5 +100,4 @@ function createRequestLoggerMiddleware(options = {}) {
100
100
  }
101
101
  };
102
102
  }
103
- //#endregion
104
103
  export { createRequestLoggerMiddleware };
@@ -1,6 +1,5 @@
1
- import { i as UbeanLoggerOptions, n as RequestLoggerOptions, r as UbeanLogger, t as LogLevelName } from "../types-CFy62PZV.js";
1
+ import { i as UbeanLoggerOptions, n as RequestLoggerOptions, r as UbeanLogger, t as LogLevelName } from "../types-CSUrGnuZ.js";
2
2
  import { TLogLevel } from "tslog";
3
- //#region src/logger/logger.d.ts
4
3
  /**
5
4
  * 创建一个 ubean 命名的 tslog logger(默认 name 为 `ubean`)。
6
5
  *
@@ -63,5 +62,4 @@ export declare function setDebugLogging(enabled: boolean): void;
63
62
  * ```
64
63
  */
65
64
  export declare function setMinLevel(level: LogLevelName | TLogLevel | undefined): void;
66
- //#endregion
67
65
  export type { LogLevelName, RequestLoggerOptions, UbeanLogger, UbeanLoggerOptions };
@@ -1 +1 @@
1
- export { t as createUbeanLogger, n as getLogger, r as logger, i as setDebugLogging, a as setMinLevel } from "../logger-NMOHjTCB.js";
1
+ export { t as createUbeanLogger, n as getLogger, r as logger, i as setDebugLogging, a as setMinLevel } from "../logger-Ba3-ofGb.js";
@@ -1,5 +1,5 @@
1
1
  import { Logger } from "tslog";
2
- //#region src/logger/logger.ts
2
+ // src/logger/logger.ts
3
3
  const DEFAULT_NAME = "ubean";
4
4
  /**
5
5
  * 默认精简模板:空模板 → 仅输出消息(无日期 / 等级 / 路径),适合 CLI 日常使用。
@@ -157,5 +157,4 @@ function setMinLevel(level) {
157
157
  const name = level.toUpperCase();
158
158
  for (const instance of instances) instance.setMinLevel(name);
159
159
  }
160
- //#endregion
161
160
  export { setMinLevel as a, setDebugLogging as i, getLogger as n, logger as r, createUbeanLogger as t };
package/dist/node.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/port.d.ts
2
1
  export interface FindPortOptions {
3
2
  host?: string;
4
3
  strictPort?: boolean;
@@ -30,15 +29,11 @@ export declare function waitForPort(port: number, options?: WaitForPortOptions):
30
29
  */
31
30
  export declare function isPortReachable(port: number, host: string): Promise<boolean>;
32
31
  export declare function sleep(ms: number): Promise<void>;
33
- //#endregion
34
- //#region src/vite-config.d.ts
35
32
  /**
36
33
  * 检测项目根目录下是否存在 vite 配置文件。
37
34
  * 返回找到的第一个文件的完整路径,如果都不存在则返回 null。
38
35
  */
39
36
  export declare function findUserViteConfig(cwd: string): string | null;
40
- //#endregion
41
- //#region src/network.d.ts
42
37
  /** 仅回环可达的 host(监听这些地址时局域网无法访问,不展示 Network 行)。 */
43
38
  export declare function isLoopbackHost(host: string): boolean;
44
39
  /** 通配绑定(监听所有网卡)。 */
@@ -47,5 +42,4 @@ export declare function isWildcardHost(host: string): boolean;
47
42
  * 本机局域网 IPv4 地址(`os.networkInterfaces()` 去掉 internal,按网卡名排序保证稳定输出)。
48
43
  * 仅返回 IPv4 —— IPv6 全局地址通常携带临时/隐私扩展后缀,逐条展示噪音大于价值。
49
44
  */
50
- export declare function getLanAddresses(): string[];
51
- //#endregion
45
+ export declare function getLanAddresses(): string[];
package/dist/node.js CHANGED
@@ -2,7 +2,7 @@ import { createConnection, createServer } from "node:net";
2
2
  import { existsSync } from "node:fs";
3
3
  import { join } from "pathe";
4
4
  import { networkInterfaces } from "node:os";
5
- //#region src/port.ts
5
+ // src/port.ts
6
6
  /**
7
7
  * Tries to listen on `port` at `host`. If the port is already in use and
8
8
  * `strictPort` is false, recursively tries `port + 1` until an available
@@ -70,8 +70,7 @@ function isPortReachable(port, host) {
70
70
  function sleep(ms) {
71
71
  return new Promise((resolve) => setTimeout(resolve, ms));
72
72
  }
73
- //#endregion
74
- //#region src/vite-config.ts
73
+ // src/vite-config.ts
75
74
  const VITE_CONFIG_FILES = [
76
75
  "vite.config.ts",
77
76
  "vite.config.mts",
@@ -89,8 +88,7 @@ function findUserViteConfig(cwd) {
89
88
  }
90
89
  return null;
91
90
  }
92
- //#endregion
93
- //#region src/network.ts
91
+ // src/network.ts
94
92
  /** 仅回环可达的 host(监听这些地址时局域网无法访问,不展示 Network 行)。 */
95
93
  function isLoopbackHost(host) {
96
94
  return host === "localhost" || host === "127.0.0.1" || host === "::1";
@@ -112,5 +110,4 @@ function getLanAddresses() {
112
110
  }
113
111
  return addresses;
114
112
  }
115
- //#endregion
116
113
  export { findAvailablePort, findUserViteConfig, getLanAddresses, isLoopbackHost, isPortReachable, isWildcardHost, sleep, waitForPort };
@@ -1,5 +1,4 @@
1
1
  import { ILogObj, ISettingsParam, Logger } from "tslog";
2
- //#region src/logger/types.d.ts
3
2
  /**
4
3
  * 日志等级名称(与 tslog v5 默认等级表一致)。
5
4
  * 仅用于类型标注;`minLevel` 实际接受 number / tslog LogLevel 枚举 / 大小写不敏感的名称。
@@ -36,5 +35,4 @@ interface RequestLoggerOptions {
36
35
  */
37
36
  logQuery?: boolean;
38
37
  }
39
- //#endregion
40
38
  export { UbeanLoggerOptions as i, RequestLoggerOptions as n, UbeanLogger as r, LogLevelName as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/shared",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Shared protocol types, errors, env and universal utilities for ubean",
5
5
  "files": [
6
6
  "dist"
@@ -37,7 +37,7 @@
37
37
  "devDependencies": {
38
38
  "@types/node": "^26.6.5",
39
39
  "typescript": "npm:typescript-native-bridge@latest",
40
- "vite-plus": "1.3.0"
40
+ "vite-plus": "1.4.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "vp pack",