@ubean/shared 0.4.5 → 0.4.6

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
@@ -7,19 +7,19 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
7
7
  * 基础路由元数据,由 @ubean/scan 使用。
8
8
  * 扩展的 RouteMeta 在此处定义,增加了 rateLimit 和 cache 字段。
9
9
  */
10
- interface BaseRouteMeta {
10
+ export interface BaseRouteMeta {
11
11
  requiresAuth?: boolean;
12
12
  [key: string]: unknown;
13
13
  }
14
- interface RateLimitMeta {
14
+ export interface RateLimitMeta {
15
15
  maxRequests: number;
16
16
  windowSeconds: number;
17
17
  }
18
- interface CacheMeta {
18
+ export interface CacheMeta {
19
19
  ttl: number;
20
20
  swr?: boolean;
21
21
  }
22
- interface RouteMeta extends BaseRouteMeta {
22
+ export interface RouteMeta extends BaseRouteMeta {
23
23
  rateLimit?: RateLimitMeta;
24
24
  cache?: CacheMeta;
25
25
  }
@@ -30,7 +30,7 @@ interface RouteMeta extends BaseRouteMeta {
30
30
  * - 对象形式可显式指定 `swr` 启用 stale-while-revalidate 语义
31
31
  * (返回过期内容 + 后台异步重新生成)
32
32
  */
33
- interface IsrRule {
33
+ export interface IsrRule {
34
34
  /** 缓存有效期(秒)。过期后下次请求触发重新生成 */
35
35
  ttl: number;
36
36
  /** 是否启用 stale-while-revalidate:过期时先返回旧内容,后台异步刷新 */
@@ -59,7 +59,7 @@ interface IsrRule {
59
59
  * `prerender: true` 的路由会被 `collectPrerenderRoutes` 加入队列(受
60
60
  * `PrerenderConfig.exclude` 过滤)。`ppr: true` 隐含 `prerender: true`。
61
61
  */
62
- interface RouteRule {
62
+ export interface RouteRule {
63
63
  cache?: {
64
64
  ttl?: number;
65
65
  swr?: boolean;
@@ -99,31 +99,31 @@ interface RouteRule {
99
99
  */
100
100
  ppr?: boolean;
101
101
  }
102
- type SpanStatus = 'ok' | 'error' | 'cancelled';
103
- interface SpanAttributes {
102
+ export type SpanStatus = 'ok' | 'error' | 'cancelled';
103
+ export interface SpanAttributes {
104
104
  [key: string]: string | number | boolean | undefined | null;
105
105
  }
106
- interface SpanContext {
106
+ export interface SpanContext {
107
107
  traceId: string;
108
108
  spanId: string;
109
109
  parentSpanId?: string;
110
110
  }
111
- interface SpanEndOptions {
111
+ export interface SpanEndOptions {
112
112
  status?: SpanStatus;
113
113
  error?: Error;
114
114
  attributes?: SpanAttributes;
115
115
  }
116
- interface SpanEvent {
116
+ export interface SpanEvent {
117
117
  name: string;
118
118
  timestamp: number;
119
119
  attributes?: SpanAttributes;
120
120
  }
121
- interface SpanOptions {
121
+ export interface SpanOptions {
122
122
  name: string;
123
123
  attributes?: SpanAttributes;
124
124
  parent?: Span | SpanContext;
125
125
  }
126
- interface Span {
126
+ export interface Span {
127
127
  readonly name: string;
128
128
  readonly context: SpanContext;
129
129
  readonly startTime: number;
@@ -140,7 +140,7 @@ interface Span {
140
140
  isRecording(): boolean;
141
141
  duration(): number | undefined;
142
142
  }
143
- interface PageHead {
143
+ export interface PageHead {
144
144
  title?: string;
145
145
  meta?: Array<Record<string, string>>;
146
146
  link?: Array<Record<string, string>>;
@@ -148,7 +148,7 @@ interface PageHead {
148
148
  htmlAttrs?: Record<string, string>;
149
149
  bodyAttrs?: Record<string, string>;
150
150
  }
151
- interface UbeanVariables extends RequestIdVariables {
151
+ export interface UbeanVariables extends RequestIdVariables {
152
152
  route: {
153
153
  meta: RouteMeta;
154
154
  path: string;
@@ -164,14 +164,14 @@ interface UbeanVariables extends RequestIdVariables {
164
164
  */
165
165
  routeRule?: RouteRule;
166
166
  }
167
- interface UbeanBindings {}
168
- interface UbeanEnv extends Env {
167
+ export interface UbeanBindings {}
168
+ export interface UbeanEnv extends Env {
169
169
  Variables: UbeanVariables;
170
170
  Bindings: UbeanBindings;
171
171
  }
172
- type UbeanContext = Context<UbeanEnv>;
173
- type Input = Input$1;
174
- interface GenericSchema<O = unknown> {
172
+ export type UbeanContext = Context<UbeanEnv>;
173
+ export type Input = Input$1;
174
+ export interface GenericSchema<O = unknown> {
175
175
  safeParse?(value: unknown): {
176
176
  success: boolean;
177
177
  data?: O;
@@ -184,9 +184,9 @@ interface GenericSchema<O = unknown> {
184
184
  parse?(value: unknown): O;
185
185
  _output?: O;
186
186
  }
187
- type UbeanMiddleware<I extends Input = {}> = MiddlewareHandler<UbeanEnv, any, I>;
188
- type UbeanHandler<I extends Input = {}, R extends HandlerResponse<any> = HandlerResponse<any>> = Handler<UbeanEnv, any, I, R>;
189
- type ComposedHandler = MiddlewareHandler<UbeanEnv>;
187
+ export type UbeanMiddleware<I extends Input = {}> = MiddlewareHandler<UbeanEnv, any, I>;
188
+ export type UbeanHandler<I extends Input = {}, R extends HandlerResponse<any> = HandlerResponse<any>> = Handler<UbeanEnv, any, I, R>;
189
+ export type ComposedHandler = MiddlewareHandler<UbeanEnv>;
190
190
  /**
191
191
  * Action ID — a stable string identifier for a server action.
192
192
  *
@@ -194,7 +194,7 @@ type ComposedHandler = MiddlewareHandler<UbeanEnv>;
194
194
  * the client and server sides agree on the same ID without runtime
195
195
  * coordination. Format: `<base32(sha1(relPath:exportName))>`.
196
196
  */
197
- type ActionId = string;
197
+ export type ActionId = string;
198
198
  /**
199
199
  * Context passed to every server action handler.
200
200
  *
@@ -202,7 +202,7 @@ type ActionId = string;
202
202
  * - `context`: the Hono context (for `c.set`, `c.get`, `c.req`, etc.)
203
203
  * - `params`: route params extracted from the URL (for page-level actions)
204
204
  */
205
- interface ActionContext {
205
+ export interface ActionContext {
206
206
  request: Request;
207
207
  context: Context<UbeanEnv>;
208
208
  params: Record<string, string>;
@@ -221,7 +221,7 @@ interface ActionContext {
221
221
  * Either `data` (success), `error`/`errors` (failure), or `response`
222
222
  * (passthrough) is set; never more than one.
223
223
  */
224
- interface ActionResult<T = unknown> {
224
+ export interface ActionResult<T = unknown> {
225
225
  data?: T;
226
226
  error?: {
227
227
  message: string;
@@ -242,7 +242,7 @@ interface ActionResult<T = unknown> {
242
242
  * The handler may return any serializable value, throw an `ActionError`,
243
243
  * or call `fail()` to return field-level validation errors.
244
244
  */
245
- type ActionHandler<TInput = unknown, TOutput = unknown> = (input: TInput, ctx: ActionContext) => Promise<TOutput | ActionFailure> | TOutput | ActionFailure;
245
+ export type ActionHandler<TInput = unknown, TOutput = unknown> = (input: TInput, ctx: ActionContext) => Promise<TOutput | ActionFailure> | TOutput | ActionFailure;
246
246
  /**
247
247
  * Field-level validation failure (SvelteKit-style).
248
248
  *
@@ -250,7 +250,7 @@ type ActionHandler<TInput = unknown, TOutput = unknown> = (input: TInput, ctx: A
250
250
  * back to the form without throwing. The page can read `result.errors` to
251
251
  * display per-field messages.
252
252
  */
253
- interface ActionFailure<T = Record<string, string>> {
253
+ export interface ActionFailure<T = Record<string, string>> {
254
254
  __actionFailure: true;
255
255
  status: number;
256
256
  errors: T;
@@ -261,7 +261,7 @@ interface ActionFailure<T = Record<string, string>> {
261
261
  * Any Standard Schema (`safeParse`/`parse`) or a function
262
262
  * `(value: unknown) => { success: true; data } | { success: false; error }`.
263
263
  */
264
- interface ActionSchema<TOutput = unknown> {
264
+ export interface ActionSchema<TOutput = unknown> {
265
265
  safeParse?(value: unknown): {
266
266
  success: boolean;
267
267
  data?: TOutput;
@@ -293,7 +293,7 @@ interface ActionSchema<TOutput = unknown> {
293
293
  * The function is callable server-side (direct invocation with typed input)
294
294
  * and is replaced by an RPC stub on the client (POST to `/__actions`).
295
295
  */
296
- interface ServerAction<TInput = unknown, TOutput = unknown> {
296
+ export interface ServerAction<TInput = unknown, TOutput = unknown> {
297
297
  /** Stable action ID (file path + export name hash). */
298
298
  id: ActionId;
299
299
  /** The handler that runs server-side. */
@@ -308,18 +308,18 @@ interface ServerAction<TInput = unknown, TOutput = unknown> {
308
308
  /**
309
309
  * Brand used to identify a server action at runtime (`Symbol`).
310
310
  */
311
- declare const ACTION_BRAND: unique symbol;
311
+ export declare const ACTION_BRAND: unique symbol;
312
312
  /**
313
313
  * Type guard: is the value a registered `ServerAction`?
314
314
  */
315
- declare function isServerAction(value: unknown): value is ServerAction;
315
+ export declare function isServerAction(value: unknown): value is ServerAction;
316
316
  /**
317
317
  * Error thrown by action handlers to signal a user-facing error.
318
318
  *
319
319
  * The `code` field can be used for programmatic error handling on the client
320
320
  * (e.g. `err.code === 'INVALID_CREDENTIALS'`).
321
321
  */
322
- declare class ActionError extends Error {
322
+ export declare class ActionError extends Error {
323
323
  code?: string;
324
324
  status: number;
325
325
  constructor(message: string, opts?: {
@@ -340,42 +340,42 @@ declare class ActionError extends Error {
340
340
  * });
341
341
  * ```
342
342
  */
343
- declare function fail<T extends Record<string, string>>(status: number, errors: T): ActionFailure<T>;
343
+ export declare function fail<T extends Record<string, string>>(status: number, errors: T): ActionFailure<T>;
344
344
  /**
345
345
  * Type guard: is the value an `ActionFailure` (returned by `fail()`)?
346
346
  */
347
- declare function isActionFailure(value: unknown): value is ActionFailure;
347
+ export declare function isActionFailure(value: unknown): value is ActionFailure;
348
348
  //#endregion
349
349
  //#region src/error.d.ts
350
- declare class UbeanError extends Error {
350
+ export declare class UbeanError extends Error {
351
351
  statusCode: number;
352
352
  statusMessage: string;
353
353
  data?: unknown;
354
354
  constructor(statusCode: number, statusMessage?: string, data?: unknown);
355
355
  }
356
- declare function createError(options: {
356
+ export declare function createError(options: {
357
357
  statusCode: number;
358
358
  statusMessage?: string;
359
359
  data?: unknown;
360
360
  message?: string;
361
361
  }): UbeanError;
362
- declare function isUbeanError(err: unknown): err is UbeanError;
363
- declare function errorToResponse(c: unknown, err?: unknown): Response;
362
+ export declare function isUbeanError(err: unknown): err is UbeanError;
363
+ export declare function errorToResponse(c: unknown, err?: unknown): Response;
364
364
  //#endregion
365
365
  //#region src/env.d.ts
366
- type EnvSchema = Record<string, StandardSchemaV1 | GenericSchema | {
366
+ export type EnvSchema = Record<string, StandardSchemaV1 | GenericSchema | {
367
367
  type: StringConstructor | NumberConstructor | BooleanConstructor;
368
368
  default?: unknown;
369
369
  required?: boolean;
370
370
  }>;
371
- type InferEnvOutput<S extends EnvSchema> = { [K in keyof S]: S[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S[K]> : S[K] extends GenericSchema<infer O> ? O : S[K] extends {
371
+ export type InferEnvOutput<S extends EnvSchema> = { [K in keyof S]: S[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S[K]> : S[K] extends GenericSchema<infer O> ? O : S[K] extends {
372
372
  type: StringConstructor;
373
373
  } ? string : S[K] extends {
374
374
  type: NumberConstructor;
375
375
  } ? number : S[K] extends {
376
376
  type: BooleanConstructor;
377
377
  } ? boolean : string; };
378
- interface EnvConfig<S extends EnvSchema = EnvSchema> {
378
+ export interface EnvConfig<S extends EnvSchema = EnvSchema> {
379
379
  /** Server-only env variables (not exposed to client) */
380
380
  server?: S;
381
381
  /** Public env variables (exposed to client via import.meta.env) */
@@ -383,7 +383,7 @@ interface EnvConfig<S extends EnvSchema = EnvSchema> {
383
383
  /** Validation mode - 'warn' logs errors, 'throw' throws on validation failure */
384
384
  mode?: 'warn' | 'throw';
385
385
  }
386
- interface DefineEnvResult<S extends EnvSchema> {
386
+ export interface DefineEnvResult<S extends EnvSchema> {
387
387
  readonly env: InferEnvOutput<S>;
388
388
  validate(source?: Record<string, string | undefined>): {
389
389
  success: boolean;
@@ -391,40 +391,40 @@ interface DefineEnvResult<S extends EnvSchema> {
391
391
  data: InferEnvOutput<S>;
392
392
  };
393
393
  }
394
- interface EnvValidationError {
394
+ export interface EnvValidationError {
395
395
  key: string;
396
396
  message: string;
397
397
  value: unknown;
398
398
  }
399
- declare function defineEnv<S extends EnvSchema>(config: EnvConfig<S>): DefineEnvResult<S>;
400
- declare function setRuntimeEnv(env: Record<string, unknown>): void;
401
- declare function useRuntimeEnv<T = string>(key: string, defaultValue?: T): T;
399
+ export declare function defineEnv<S extends EnvSchema>(config: EnvConfig<S>): DefineEnvResult<S>;
400
+ export declare function setRuntimeEnv(env: Record<string, unknown>): void;
401
+ export declare function useRuntimeEnv<T = string>(key: string, defaultValue?: T): T;
402
402
  //#endregion
403
403
  //#region src/path.d.ts
404
404
  /**
405
405
  * 标准化路径:替换反斜杠、去除首尾多余斜杠、合并连续斜杠。
406
406
  */
407
- declare function normalizePath(path: string): string;
407
+ export declare function normalizePath(path: string): string;
408
408
  /**
409
409
  * 获取路径的目录部分(不含文件名)。
410
410
  */
411
- declare function getDirname(path: string): string;
411
+ export declare function getDirname(path: string): string;
412
412
  /**
413
413
  * 获取路径的文件名部分(含扩展名)。
414
414
  */
415
- declare function getBasename(path: string): string;
415
+ export declare function getBasename(path: string): string;
416
416
  /**
417
417
  * 获取文件名的扩展名(小写,不含点)。
418
418
  */
419
- declare function getExtension(filename: string): string;
419
+ export declare function getExtension(filename: string): string;
420
420
  /**
421
421
  * 获取文件名(不含扩展名)。
422
422
  */
423
- declare function getStem(filename: string): string;
423
+ export declare function getStem(filename: string): string;
424
424
  /**
425
425
  * 将文件路径转换为人类可读的标题。
426
426
  */
427
- declare function pathToTitle(path: string): string;
427
+ export declare function pathToTitle(path: string): string;
428
428
  //#endregion
429
429
  //#region src/glob.d.ts
430
430
  /**
@@ -435,16 +435,15 @@ declare function pathToTitle(path: string): string;
435
435
  *
436
436
  * 提取自 `@ubean/prerender`,供 SSR exclude / prerender / 其他需要 glob 匹配的模块共享。
437
437
  */
438
- declare function matchGlob(route: string, pattern: string): boolean;
438
+ export declare function matchGlob(route: string, pattern: string): boolean;
439
439
  /**
440
440
  * 检查 route 是否匹配任意一个 patterns。
441
441
  */
442
- declare function matchAnyGlob(route: string, patterns: string[]): boolean;
442
+ export declare function matchAnyGlob(route: string, patterns: string[]): boolean;
443
443
  //#endregion
444
444
  //#region src/string.d.ts
445
445
  /**
446
446
  * 将字符串首字母大写。
447
447
  */
448
- declare function capitalize(str: string): string;
449
- //#endregion
450
- export { ACTION_BRAND, ActionContext, ActionError, ActionFailure, ActionHandler, ActionId, ActionResult, ActionSchema, BaseRouteMeta, CacheMeta, ComposedHandler, DefineEnvResult, EnvConfig, EnvSchema, EnvValidationError, GenericSchema, InferEnvOutput, Input, IsrRule, PageHead, RateLimitMeta, RouteMeta, RouteRule, ServerAction, Span, SpanAttributes, SpanContext, SpanEndOptions, SpanEvent, SpanOptions, SpanStatus, UbeanBindings, UbeanContext, UbeanEnv, UbeanError, UbeanHandler, UbeanMiddleware, UbeanVariables, capitalize, createError, defineEnv, errorToResponse, fail, getBasename, getDirname, getExtension, getStem, isActionFailure, isServerAction, isUbeanError, matchAnyGlob, matchGlob, normalizePath, pathToTitle, setRuntimeEnv, useRuntimeEnv };
448
+ export declare function capitalize(str: string): string;
449
+ //#endregion
@@ -20,6 +20,5 @@ import { MiddlewareHandler } from "hono";
20
20
  * }));
21
21
  * ```
22
22
  */
23
- declare function createRequestLoggerMiddleware(options?: RequestLoggerOptions): MiddlewareHandler;
24
- //#endregion
25
- export { createRequestLoggerMiddleware };
23
+ export declare function createRequestLoggerMiddleware(options?: RequestLoggerOptions): MiddlewareHandler;
24
+ //#endregion
@@ -15,9 +15,9 @@ import { i as UbeanLoggerOptions, n as RequestLoggerOptions, r as UbeanLogger, t
15
15
  * log.info({ port: 3000 }, 'server started');
16
16
  * ```
17
17
  */
18
- declare function createUbeanLogger(options?: UbeanLoggerOptions): UbeanLogger;
18
+ export declare function createUbeanLogger(options?: UbeanLoggerOptions): UbeanLogger;
19
19
  /** ubean 全局默认 logger(供应用侧 `import { logger } from 'ubean'` 使用) */
20
- declare const logger: UbeanLogger;
20
+ export declare const logger: UbeanLogger;
21
21
  /**
22
22
  * 获取命名(scope)logger。
23
23
  *
@@ -31,7 +31,7 @@ declare const logger: UbeanLogger;
31
31
  * cli.info('building...');
32
32
  * ```
33
33
  */
34
- declare function getLogger(scope?: string, options?: UbeanLoggerOptions): UbeanLogger;
34
+ export declare function getLogger(scope?: string, options?: UbeanLoggerOptions): UbeanLogger;
35
35
  /**
36
36
  * 切换 debug 日志模式,对所有已创建的 logger 实例(含子 logger)即时生效:
37
37
  * - `true`:输出详细日志(日期 + 等级 + 调用位置 + logger 名)
@@ -44,6 +44,6 @@ declare function getLogger(scope?: string, options?: UbeanLoggerOptions): UbeanL
44
44
  * setDebugLogging(process.argv.includes('--debug'));
45
45
  * ```
46
46
  */
47
- declare function setDebugLogging(enabled: boolean): void;
47
+ export declare function setDebugLogging(enabled: boolean): void;
48
48
  //#endregion
49
- export { type LogLevelName, type RequestLoggerOptions, type UbeanLogger, type UbeanLoggerOptions, createUbeanLogger, getLogger, logger, setDebugLogging };
49
+ export type { LogLevelName, RequestLoggerOptions, UbeanLogger, UbeanLoggerOptions };
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/port.d.ts
2
- interface FindPortOptions {
2
+ export interface FindPortOptions {
3
3
  host?: string;
4
4
  strictPort?: boolean;
5
5
  }
@@ -12,8 +12,8 @@ interface FindPortOptions {
12
12
  * when not in strict mode). Rejects with the original error when the port is
13
13
  * in use and `strictPort` is true, or for any non-EADDRINUSE error.
14
14
  */
15
- declare function findAvailablePort(port: number, options?: FindPortOptions): Promise<number>;
16
- interface WaitForPortOptions {
15
+ export declare function findAvailablePort(port: number, options?: FindPortOptions): Promise<number>;
16
+ export interface WaitForPortOptions {
17
17
  host?: string;
18
18
  retries?: number;
19
19
  delay?: number;
@@ -24,18 +24,17 @@ interface WaitForPortOptions {
24
24
  *
25
25
  * Rejects when the port does not become available within `retries` attempts.
26
26
  */
27
- declare function waitForPort(port: number, options?: WaitForPortOptions): Promise<void>;
27
+ export declare function waitForPort(port: number, options?: WaitForPortOptions): Promise<void>;
28
28
  /**
29
29
  * Returns true when something is actively listening on `port` at `host`.
30
30
  */
31
- declare function isPortReachable(port: number, host: string): Promise<boolean>;
32
- declare function sleep(ms: number): Promise<void>;
31
+ export declare function isPortReachable(port: number, host: string): Promise<boolean>;
32
+ export declare function sleep(ms: number): Promise<void>;
33
33
  //#endregion
34
34
  //#region src/vite-config.d.ts
35
35
  /**
36
36
  * 检测项目根目录下是否存在 vite 配置文件。
37
37
  * 返回找到的第一个文件的完整路径,如果都不存在则返回 null。
38
38
  */
39
- declare function findUserViteConfig(cwd: string): string | null;
40
- //#endregion
41
- export { FindPortOptions, WaitForPortOptions, findAvailablePort, findUserViteConfig, isPortReachable, sleep, waitForPort };
39
+ export declare function findUserViteConfig(cwd: string): string | null;
40
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/shared",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Shared protocol types, errors, env and universal utilities for ubean",
5
5
  "files": [
6
6
  "dist"
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^26.5.0",
40
- "typescript": "7.0.2",
41
- "vite-plus": "0.3.0"
40
+ "typescript": "npm:typescript-native-bridge@latest",
41
+ "vite-plus": "0.3.1"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "vp pack",