isr-engine 3.1.3 → 3.1.4
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/{abVariantContext-Ud3aZ1yk.js → abVariantContext-BtLsLN1J.js} +2 -12
- package/dist/{abVariantContext-Ud3aZ1yk.js.map → abVariantContext-BtLsLN1J.js.map} +1 -1
- package/dist/cli/cli.js +1 -1
- package/dist/{createCacheInspectorMiddleware-GgzKVkq2.js → createCacheInspectorMiddleware-Cb_MZhLZ.js} +2 -2
- package/dist/{createCacheInspectorMiddleware-GgzKVkq2.js.map → createCacheInspectorMiddleware-Cb_MZhLZ.js.map} +1 -1
- package/dist/{createISRApp-DPD3Er4F.js → createISRApp-rD8EUB--.js} +2255 -1721
- package/dist/createISRApp-rD8EUB--.js.map +1 -0
- package/dist/defaults/runtime/defineSiteHooks.js +2 -2
- package/dist/{defineSiteHooks-bHtGQftZ.js → defineSiteHooks-BWaDDJ4B.js} +2 -2
- package/dist/{defineSiteHooks-bHtGQftZ.js.map → defineSiteHooks-BWaDDJ4B.js.map} +1 -1
- package/dist/{i18n-CnXYAgQE.js → i18n-BFCx28rB.js} +2 -8
- package/dist/{i18n-CnXYAgQE.js.map → i18n-BFCx28rB.js.map} +1 -1
- package/dist/isr-engine.js +11 -10
- package/dist/isr-engine.js.map +1 -1
- package/dist/plugin/googleFontAssets.d.ts.map +1 -1
- package/dist/plugin/isrCacheMiddleware.d.ts.map +1 -1
- package/dist/rsc/index.js +2 -2
- package/dist/{rsc-BJzB9s8U.js → rsc-Da-Nc0OM.js} +2 -2
- package/dist/{rsc-BJzB9s8U.js.map → rsc-Da-Nc0OM.js.map} +1 -1
- package/dist/security/staticCspManifest.d.ts.map +1 -1
- package/dist/server/productionRuntime.d.ts.map +1 -1
- package/dist/server/requestLimits.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/Logger-bg-doGwZ.js +0 -174
- package/dist/Logger-bg-doGwZ.js.map +0 -1
- package/dist/createISRApp-DPD3Er4F.js.map +0 -1
- package/dist/createImagePlugin-QNvY9vPB.js +0 -462
- package/dist/createImagePlugin-QNvY9vPB.js.map +0 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"googleFontAssets.d.ts","sourceRoot":"","sources":["../../src/plugin/googleFontAssets.ts"],"names":[],"mappings":"AAcA,UAAU,QAAQ;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAWD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWzD;
|
|
1
|
+
{"version":3,"file":"googleFontAssets.d.ts","sourceRoot":"","sources":["../../src/plugin/googleFontAssets.ts"],"names":[],"mappings":"AAcA,UAAU,QAAQ;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB;AAWD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWzD;AA8TD;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA+G/D;AAED,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,gBAAgB,CAAC,CA+D3B;AAeD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GACrC,MAAM,CAYR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isrCacheMiddleware.d.ts","sourceRoot":"","sources":["../../src/plugin/isrCacheMiddleware.ts"],"names":[],"mappings":"AA0CA,OAAO,EAA0B,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"isrCacheMiddleware.d.ts","sourceRoot":"","sources":["../../src/plugin/isrCacheMiddleware.ts"],"names":[],"mappings":"AA0CA,OAAO,EAA0B,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAQlG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,SAAS,EAA6B,MAAM,UAAU,CAAC;AAsBrE,mCAAmC;AACnC,KAAK,WAAW,GAAG,cAAc,CAAC;AAElC,iEAAiE;AACjE,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;AA2BlF,WAAW;AACX,MAAM,WAAW,yBAAyB;IACxC,sFAAsF;IACtF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kGAAkG;IAClG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,uBAAuB,CAAC,EAAE,CAAC,QA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3 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { a as LEGACY_SERVER_ACTION_ENDPOINT, c as isLegacyServerActionEndpoint, d as createServerAction, f as serverActionsRegistry, i as getI18nLocale, l as shouldSkipServerActionEndpointRetry, n as runWithI18n, o as SERVER_ACTION_ENDPOINT, r as getI18n, s as getServerActionEndpointCandidates, t as getCurrentI18n, u as ServerActionUtils } from "../rsc-
|
|
1
|
+
import { C as getTraceId, S as getRequestId, a as isUncacheable, b as getExperiments, c as RevalidationError, d as revalidateTag, i as debugTagStore, l as registerInvalidator, n as cacheTag, o as markUncacheable, r as collectTags, s as runWithTagStore, t as getVariant, u as revalidatePath, w as getUserId, x as getRequestContext, y as getAnonId } from "../abVariantContext-BtLsLN1J.js";
|
|
2
|
+
import { a as LEGACY_SERVER_ACTION_ENDPOINT, c as isLegacyServerActionEndpoint, d as createServerAction, f as serverActionsRegistry, i as getI18nLocale, l as shouldSkipServerActionEndpointRetry, n as runWithI18n, o as SERVER_ACTION_ENDPOINT, r as getI18n, s as getServerActionEndpointCandidates, t as getCurrentI18n, u as ServerActionUtils } from "../rsc-Da-Nc0OM.js";
|
|
3
3
|
export { LEGACY_SERVER_ACTION_ENDPOINT, RevalidationError, SERVER_ACTION_ENDPOINT, ServerActionUtils, cacheTag, collectTags, createServerAction, debugTagStore, getAnonId, getCurrentI18n, getExperiments, getI18n, getI18nLocale, getRequestContext, getRequestId, getServerActionEndpointCandidates, getTraceId, getUserId, getVariant, isLegacyServerActionEndpoint, isUncacheable, markUncacheable, registerInvalidator, revalidatePath, revalidateTag, runWithI18n, runWithTagStore, serverActionsRegistry, shouldSkipServerActionEndpointRetry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as runtimeLogger, x as getRequestContext } from "./abVariantContext-BtLsLN1J.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
//#region src/rsc/ServerActions.ts
|
|
4
4
|
/**
|
|
@@ -163,4 +163,4 @@ function isIntlPayload(value) {
|
|
|
163
163
|
//#endregion
|
|
164
164
|
export { LEGACY_SERVER_ACTION_ENDPOINT as a, isLegacyServerActionEndpoint as c, createServerAction as d, serverActionsRegistry as f, getI18nLocale as i, shouldSkipServerActionEndpointRetry as l, runWithI18n as n, SERVER_ACTION_ENDPOINT as o, getI18n as r, getServerActionEndpointCandidates as s, getCurrentI18n as t, ServerActionUtils as u };
|
|
165
165
|
|
|
166
|
-
//# sourceMappingURL=rsc-
|
|
166
|
+
//# sourceMappingURL=rsc-Da-Nc0OM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc-
|
|
1
|
+
{"version":3,"file":"rsc-Da-Nc0OM.js","names":[],"sources":["../src/rsc/ServerActions.ts","../src/rsc/constants.ts","../src/runtime/i18n-store.ts","../src/defaults/runtime/i18n-server.ts"],"sourcesContent":["/**\n * Server Actions —— engine 级元数据注册\n *\n * 架构分工(方案 A 后):\n * - 协议传输:`@vitejs/plugin-rsc` 负责 encodeReply/decodeReply、loadServerAction、\n * Server Action 的 POST 路由、multipart 解码、响应 Flight 流等全部协议层工作\n * - 本模块职责:仅做元数据层面的注册表,供 engine 的调试 / 指标 / 管理面板使用\n *\n * 编写注意:\n * - 不重复实现执行/传输/序列化逻辑 —— 全部交给 plugin\n * - `createServerAction` 仅为便利 API:在 registry 中登记元数据,返回原函数\n * (不再伪造 `$$typeof`/`$$id` —— 这些由 plugin 的 transforms 在编译时注入到\n * `'use server'` 声明的模块导出上)\n */\n\nimport { runtimeLogger as logger } from '../logger/runtimeLogger';\n\nexport interface ServerActionMetadata {\n /** Action ID(应与 plugin 生成的 reference id 保持一致;自行注册时由调用方提供) */\n id: string;\n name: string;\n module?: string;\n line?: number;\n file?: string;\n}\n\nexport type ServerActionHandler = (...args: unknown[]) => Promise<unknown> | unknown;\n\nclass ServerActionsRegistry {\n private readonly metadata = new Map<string, ServerActionMetadata>();\n private initialized = false;\n\n async initialize(): Promise<void> {\n if (this.initialized) return;\n this.initialized = true;\n logger.info('✅ Server Actions Registry 已初始化');\n }\n\n async cleanup(): Promise<void> {\n this.metadata.clear();\n this.initialized = false;\n logger.info('✅ Server Actions Registry 已清理');\n }\n\n register(id: string, metadata: Omit<ServerActionMetadata, 'id'>): string {\n this.metadata.set(id, { id, ...metadata });\n return id;\n }\n\n getAllActions(): ServerActionMetadata[] {\n return Array.from(this.metadata.values());\n }\n\n hasAction(actionId: string): boolean {\n return this.metadata.has(actionId);\n }\n\n getMetadata(actionId: string): ServerActionMetadata | undefined {\n return this.metadata.get(actionId);\n }\n}\n\nexport const serverActionsRegistry = new ServerActionsRegistry();\n\n/**\n * 声明式注册:用于在服务端日志/管理面板中登记一个 action 的元数据\n *\n * 运行时执行请使用 `'use server'` 指令;本函数**不**改变执行语义,仅记录元数据\n */\nexport function createServerAction<T extends ServerActionHandler>(\n handler: T,\n metadata: Omit<ServerActionMetadata, 'id'> & { id: string }\n): T {\n serverActionsRegistry.register(metadata.id, metadata);\n return handler;\n}\n\nexport const ServerActionUtils = {\n isServer(): boolean {\n return typeof window === 'undefined';\n },\n isClient(): boolean {\n return typeof window !== 'undefined';\n },\n getExecutionContext() {\n if (this.isServer()) {\n return {\n environment: 'server' as const,\n nodeVersion: process.version,\n platform: process.platform,\n cwd: process.cwd(),\n };\n }\n return {\n environment: 'client' as const,\n userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,\n url: typeof window !== 'undefined' ? window.location.href : undefined,\n timestamp: new Date().toISOString(),\n };\n },\n};\n","/**\n * RSC / Flight 协议相关常量\n */\n\nexport const SERVER_ACTION_ENDPOINT = '/_rsc/action';\nexport const LEGACY_SERVER_ACTION_ENDPOINT = '/api/server-actions';\nexport const SERVER_ACTION_ENDPOINTS = [SERVER_ACTION_ENDPOINT, LEGACY_SERVER_ACTION_ENDPOINT];\n\nexport function getServerActionEndpointCandidates(primaryEndpoint?: string): string[] {\n const candidates = new Set<string>();\n const endpoint = primaryEndpoint || SERVER_ACTION_ENDPOINT;\n\n candidates.add(endpoint);\n candidates.add(SERVER_ACTION_ENDPOINT);\n candidates.add(LEGACY_SERVER_ACTION_ENDPOINT);\n\n return Array.from(candidates);\n}\n\nexport function isLegacyServerActionEndpoint(endpoint: string): boolean {\n return endpoint === LEGACY_SERVER_ACTION_ENDPOINT;\n}\n\nexport function shouldSkipServerActionEndpointRetry(endpoint: string): boolean {\n return isLegacyServerActionEndpoint(endpoint);\n}\n","import type { IntlPayload } from '../defaults/runtime/seo-runtime';\n\nexport type I18nParams = Record<string, string | number | boolean | null | undefined>;\n\nexport type Translate = (key: string, params?: I18nParams, fallback?: string) => string;\n\ntype ServerReader = () => IntlPayload | null | undefined;\n\ninterface I18nRuntimeState {\n clientIntl: IntlPayload | null;\n serverReader: ServerReader | null;\n keyPathCache: Map<string, string[]>;\n}\n\nconst I18N_RUNTIME_STATE_KEY = '__ISR_ENGINE_I18N_RUNTIME_STATE__';\n\nconst runtimeState = getRuntimeState();\n\nexport function setClientI18n(intl: IntlPayload | null | undefined): void {\n runtimeState.clientIntl = intl ?? null;\n}\n\nexport function registerServerI18nReader(reader: ServerReader): void {\n runtimeState.serverReader = reader;\n}\n\nexport function getCurrentI18n(): IntlPayload | null {\n return runtimeState.serverReader?.() ?? runtimeState.clientIntl;\n}\n\nexport function getI18nLocale(fallback = ''): string {\n return getCurrentI18n()?.locale ?? fallback;\n}\n\nexport const getI18n: Translate = (key, params, fallback = key) => {\n const value = readPath(getCurrentI18n()?.messages, key);\n const message = typeof value === 'string' && value.trim() ? value : fallback;\n return interpolate(message, params);\n};\n\nfunction readPath(source: unknown, key: string): unknown {\n let path = runtimeState.keyPathCache.get(key);\n if (!path) {\n path = key.split('.');\n runtimeState.keyPathCache.set(key, path);\n }\n\n let cur = source;\n for (const part of path) {\n if (!cur || typeof cur !== 'object' || !(part in cur)) return undefined;\n cur = (cur as Record<string, unknown>)[part];\n }\n return cur;\n}\n\nfunction getRuntimeState(): I18nRuntimeState {\n const globalState = globalThis as typeof globalThis & {\n [I18N_RUNTIME_STATE_KEY]?: I18nRuntimeState;\n };\n\n globalState[I18N_RUNTIME_STATE_KEY] ??= {\n clientIntl: null,\n serverReader: null,\n keyPathCache: new Map<string, string[]>(),\n };\n\n return globalState[I18N_RUNTIME_STATE_KEY];\n}\n\nfunction interpolate(message: string, params?: I18nParams): string {\n if (!params) return message;\n return message.replace(/\\{(\\w+)\\}/g, (match, name) => {\n const value = params[name];\n return value === undefined || value === null ? match : String(value);\n });\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { IntlPayload } from './seo-runtime';\nimport { getI18n, getI18nLocale, registerServerI18nReader } from '../../runtime/i18n-store';\nimport { getRequestContext } from '../../context/RequestContext';\n\nconst store = new AsyncLocalStorage<IntlPayload | null>();\n\nexport function runWithI18n<T>(intl: IntlPayload | null | undefined, fn: () => T): T {\n return store.run(intl ?? null, fn);\n}\n\nexport function getCurrentI18n(): IntlPayload | null {\n const scoped = store.getStore();\n if (scoped) return scoped;\n const requestIntl = getRequestContext()?.intl;\n return isIntlPayload(requestIntl) ? requestIntl : null;\n}\n\nregisterServerI18nReader(getCurrentI18n);\n\nexport { getI18n, getI18nLocale };\nexport type { I18nParams, Translate } from '../../runtime/i18n-store';\n\nfunction isIntlPayload(value: unknown): value is IntlPayload {\n return !!value && typeof value === 'object' && typeof (value as IntlPayload).locale === 'string';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,IAAM,wBAAN,MAA4B;CAC1B,2BAA4B,IAAI,IAAkC;CAClE,cAAsB;CAEtB,MAAM,aAA4B;EAChC,IAAI,KAAK,aAAa;EACtB,KAAK,cAAc;EACnB,cAAO,KAAK,gCAAgC;CAC9C;CAEA,MAAM,UAAyB;EAC7B,KAAK,SAAS,MAAM;EACpB,KAAK,cAAc;EACnB,cAAO,KAAK,+BAA+B;CAC7C;CAEA,SAAS,IAAY,UAAoD;EACvE,KAAK,SAAS,IAAI,IAAI;GAAE;GAAI,GAAG;EAAS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F;AAsHD,wFAAwF;AACxF,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC9C,OAAO,CAAC,iBAAiB,CAAC,CAW5B;AA2ED,8FAA8F;AAC9F,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,IAAI,CAAA;CAAO,GAC3C,OAAO,CAAC,cAAc,CAAC,CA8BzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"productionRuntime.d.ts","sourceRoot":"","sources":["../../src/server/productionRuntime.ts"],"names":[],"mappings":"AAKA,OAAO,OAAO,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"productionRuntime.d.ts","sourceRoot":"","sources":["../../src/server/productionRuntime.ts"],"names":[],"mappings":"AAKA,OAAO,OAAO,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAuChD,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAWtC;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,MAAM,EAAE,CAS9F;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAoDrF;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED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odeLogField, m as setOriginLogger, v as snapshotLogArgument, w as getTraceId } from "./abVariantContext-Ud3aZ1yk.js";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import pino from "pino";
|
|
6
|
-
//#region src/logger/Logger.ts
|
|
7
|
-
var LogLevel = /* @__PURE__ */ function(LogLevel) {
|
|
8
|
-
LogLevel["VERBOSE"] = "verbose";
|
|
9
|
-
LogLevel["DEBUG"] = "debug";
|
|
10
|
-
LogLevel["INFO"] = "info";
|
|
11
|
-
LogLevel["WARN"] = "warn";
|
|
12
|
-
LogLevel["ERROR"] = "error";
|
|
13
|
-
LogLevel["SUCCESS"] = "success";
|
|
14
|
-
return LogLevel;
|
|
15
|
-
}({});
|
|
16
|
-
var Logger = class Logger {
|
|
17
|
-
static instance;
|
|
18
|
-
verboseMode = false;
|
|
19
|
-
logFile = null;
|
|
20
|
-
fileLogger = null;
|
|
21
|
-
fileDestination = null;
|
|
22
|
-
spinner = null;
|
|
23
|
-
static getInstance(options = {}) {
|
|
24
|
-
if (!Logger.instance) {
|
|
25
|
-
Logger.instance = new Logger();
|
|
26
|
-
setOriginLogger(Logger.instance);
|
|
27
|
-
}
|
|
28
|
-
if (options.verbose !== void 0) Logger.instance.verboseMode = options.verbose;
|
|
29
|
-
if (options.logFile !== void 0) Logger.instance.configureFile(options.logFile);
|
|
30
|
-
return Logger.instance;
|
|
31
|
-
}
|
|
32
|
-
/** File destinations are operator configuration; request data is only a record field. */
|
|
33
|
-
configureFile(logFile) {
|
|
34
|
-
if (typeof logFile !== "string" || /[\u0000-\u001f\u007f]/.test(logFile)) throw new TypeError("logFile must be a path without control characters");
|
|
35
|
-
const resolved = logFile ? path.resolve(logFile) : null;
|
|
36
|
-
if (resolved === this.logFile) return;
|
|
37
|
-
this.closeFileDestination();
|
|
38
|
-
if (!resolved) return;
|
|
39
|
-
try {
|
|
40
|
-
const destination = pino.destination({
|
|
41
|
-
dest: resolved,
|
|
42
|
-
mkdir: true,
|
|
43
|
-
sync: true
|
|
44
|
-
});
|
|
45
|
-
destination.on("error", (error) => {
|
|
46
|
-
if (this.fileDestination === destination) this.closeFileDestination();
|
|
47
|
-
this.reportFileError(error);
|
|
48
|
-
});
|
|
49
|
-
destination.once("close", () => {
|
|
50
|
-
if (this.fileDestination !== destination) return;
|
|
51
|
-
this.fileLogger = null;
|
|
52
|
-
this.fileDestination = null;
|
|
53
|
-
this.logFile = null;
|
|
54
|
-
});
|
|
55
|
-
this.fileDestination = destination;
|
|
56
|
-
this.fileLogger = pino({
|
|
57
|
-
base: null,
|
|
58
|
-
timestamp: false,
|
|
59
|
-
level: "trace",
|
|
60
|
-
hooks: { streamWrite: escapeSupplementalLogControls }
|
|
61
|
-
}, destination);
|
|
62
|
-
this.logFile = resolved;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
this.closeFileDestination();
|
|
65
|
-
this.reportFileError(error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
closeFileDestination() {
|
|
69
|
-
const destination = this.fileDestination;
|
|
70
|
-
this.fileLogger = null;
|
|
71
|
-
this.fileDestination = null;
|
|
72
|
-
this.logFile = null;
|
|
73
|
-
if (!destination) return;
|
|
74
|
-
try {
|
|
75
|
-
destination.flushSync();
|
|
76
|
-
destination.end();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
destination.destroy();
|
|
79
|
-
this.reportFileError(error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
reportFileError(error) {
|
|
83
|
-
try {
|
|
84
|
-
process.stderr.write(`Failed to write to log file: ${encodeLogField(snapshotLogArgument(error))}\n`);
|
|
85
|
-
} catch {}
|
|
86
|
-
}
|
|
87
|
-
getLevelColor(level) {
|
|
88
|
-
switch (level) {
|
|
89
|
-
case "error": return chalk.red.bold;
|
|
90
|
-
case "warn": return chalk.yellow.bold;
|
|
91
|
-
case "success": return chalk.green.bold;
|
|
92
|
-
case "info": return chalk.blue.bold;
|
|
93
|
-
case "debug": return chalk.magenta;
|
|
94
|
-
case "verbose": return chalk.gray;
|
|
95
|
-
default: return chalk.white;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
log(level, ...args) {
|
|
99
|
-
if (!Object.values(LogLevel).includes(level)) throw new TypeError("Unknown log level");
|
|
100
|
-
if (level === "verbose" && !this.verboseMode) return;
|
|
101
|
-
if (level === "debug" && !this.verboseMode) return;
|
|
102
|
-
if (this.spinner?.isSpinning) this.spinner.stop();
|
|
103
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
104
|
-
const traceId = snapshotLogArgument(getTraceId());
|
|
105
|
-
const requestId = snapshotLogArgument(getRequestId());
|
|
106
|
-
const values = args.map(snapshotLogArgument);
|
|
107
|
-
const errors = [];
|
|
108
|
-
const message = values.map((value, index) => {
|
|
109
|
-
if (args[index] instanceof Error) {
|
|
110
|
-
errors.push({
|
|
111
|
-
argument: index,
|
|
112
|
-
error: value
|
|
113
|
-
});
|
|
114
|
-
if (value && typeof value === "object" && !Array.isArray(value)) return value.stack || value.message || JSON.stringify(value, null, 2);
|
|
115
|
-
}
|
|
116
|
-
return typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
117
|
-
}).join(" ");
|
|
118
|
-
const levelTag = this.getLevelColor(level)(`[${level.toUpperCase()}]`);
|
|
119
|
-
const traceTag = chalk.cyan(`traceId=${encodeLogField(traceId)}`);
|
|
120
|
-
const requestTag = requestId === "unknown" ? "" : chalk.blue(`requestId=${encodeLogField(requestId)}`);
|
|
121
|
-
console.log(`${chalk.gray(timestamp)} ${levelTag} ${traceTag} ${requestTag} message=${encodeLogField(message)}`);
|
|
122
|
-
if (this.fileLogger) {
|
|
123
|
-
const transportLevel = level === "verbose" ? "trace" : level === "success" ? "info" : level;
|
|
124
|
-
try {
|
|
125
|
-
this.fileLogger[transportLevel]({
|
|
126
|
-
timestamp,
|
|
127
|
-
severity: level,
|
|
128
|
-
traceId,
|
|
129
|
-
requestId,
|
|
130
|
-
args: values,
|
|
131
|
-
errors
|
|
132
|
-
});
|
|
133
|
-
} catch (error) {
|
|
134
|
-
this.closeFileDestination();
|
|
135
|
-
this.reportFileError(error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (this.spinner && !this.spinner.isSpinning) this.spinner.start();
|
|
139
|
-
}
|
|
140
|
-
error(...args) {
|
|
141
|
-
this.log("error", ...args);
|
|
142
|
-
}
|
|
143
|
-
warn(...args) {
|
|
144
|
-
this.log("warn", ...args);
|
|
145
|
-
}
|
|
146
|
-
info(...args) {
|
|
147
|
-
this.log("info", ...args);
|
|
148
|
-
}
|
|
149
|
-
success(...args) {
|
|
150
|
-
this.log("success", ...args);
|
|
151
|
-
}
|
|
152
|
-
debug(...args) {
|
|
153
|
-
this.log("debug", ...args);
|
|
154
|
-
}
|
|
155
|
-
verbose(...args) {
|
|
156
|
-
this.log("verbose", ...args);
|
|
157
|
-
}
|
|
158
|
-
spin(message) {
|
|
159
|
-
if (this.spinner) this.spinner.succeed();
|
|
160
|
-
this.spinner = ora(encodeSpinnerMessage(message)).start();
|
|
161
|
-
return this.spinner;
|
|
162
|
-
}
|
|
163
|
-
stopSpinner(message, success = true) {
|
|
164
|
-
if (this.spinner) {
|
|
165
|
-
if (success) this.spinner.succeed(message === void 0 ? void 0 : encodeSpinnerMessage(message));
|
|
166
|
-
else this.spinner.fail(message === void 0 ? void 0 : encodeSpinnerMessage(message));
|
|
167
|
-
this.spinner = null;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
//#endregion
|
|
172
|
-
export { Logger as t };
|
|
173
|
-
|
|
174
|
-
//# sourceMappingURL=Logger-bg-doGwZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger-bg-doGwZ.js","names":[],"sources":["../src/logger/Logger.ts"],"sourcesContent":["import chalk from 'chalk';\nimport ora, { Ora } from 'ora';\nimport path from 'path';\nimport pino, { type Logger as PinoLogger } from 'pino';\nimport { getTraceId, getRequestId } from '../context/RequestContext';\nimport {\n encodeLogField,\n encodeSpinnerMessage,\n escapeSupplementalLogControls,\n snapshotLogArgument,\n type LogValue,\n} from './logRecord';\nimport { setOriginLogger } from './runtimeLogger';\n\nexport enum LogLevel {\n VERBOSE = 'verbose',\n DEBUG = 'debug',\n INFO = 'info',\n WARN = 'warn',\n ERROR = 'error',\n SUCCESS = 'success',\n}\n\nexport interface LoggerOptions {\n verbose?: boolean;\n logFile?: string;\n}\n\nexport class Logger {\n private static instance: Logger;\n private verboseMode: boolean = false;\n private logFile: string | null = null;\n private fileLogger: PinoLogger | null = null;\n private fileDestination: ReturnType<typeof pino.destination> | null = null;\n private spinner: Ora | null = null;\n\n public static getInstance(options: LoggerOptions = {}): Logger {\n if (!Logger.instance) {\n Logger.instance = new Logger();\n setOriginLogger(Logger.instance);\n }\n\n if (options.verbose !== undefined) {\n Logger.instance.verboseMode = options.verbose;\n }\n\n if (options.logFile !== undefined) {\n Logger.instance.configureFile(options.logFile);\n }\n\n return Logger.instance;\n }\n\n /** File destinations are operator configuration; request data is only a record field. */\n private configureFile(logFile: string): void {\n // eslint-disable-next-line no-control-regex\n if (typeof logFile !== 'string' || /[\\u0000-\\u001f\\u007f]/.test(logFile)) {\n throw new TypeError('logFile must be a path without control characters');\n }\n const resolved = logFile ? path.resolve(logFile) : null;\n if (resolved === this.logFile) return;\n this.closeFileDestination();\n if (!resolved) return;\n\n try {\n const destination = pino.destination({ dest: resolved, mkdir: true, sync: true });\n destination.on('error', error => {\n if (this.fileDestination === destination) this.closeFileDestination();\n this.reportFileError(error);\n });\n destination.once('close', () => {\n if (this.fileDestination !== destination) return;\n this.fileLogger = null;\n this.fileDestination = null;\n this.logFile = null;\n });\n this.fileDestination = destination;\n this.fileLogger = pino(\n {\n base: null,\n timestamp: false,\n level: 'trace',\n hooks: { streamWrite: escapeSupplementalLogControls },\n },\n destination\n );\n this.logFile = resolved;\n } catch (error) {\n this.closeFileDestination();\n this.reportFileError(error);\n }\n }\n\n private closeFileDestination(): void {\n const destination = this.fileDestination;\n this.fileLogger = null;\n this.fileDestination = null;\n this.logFile = null;\n if (!destination) return;\n try {\n destination.flushSync();\n destination.end();\n } catch (error) {\n destination.destroy();\n this.reportFileError(error);\n }\n }\n\n private reportFileError(error: unknown): void {\n try {\n process.stderr.write(\n `Failed to write to log file: ${encodeLogField(snapshotLogArgument(error))}\\n`\n );\n } catch {\n // Logging failure must never recurse or prevent serving a request.\n }\n }\n\n private getLevelColor(level: LogLevel) {\n switch (level) {\n case LogLevel.ERROR:\n return chalk.red.bold;\n case LogLevel.WARN:\n return chalk.yellow.bold;\n case LogLevel.SUCCESS:\n return chalk.green.bold;\n case LogLevel.INFO:\n return chalk.blue.bold;\n case LogLevel.DEBUG:\n return chalk.magenta;\n case LogLevel.VERBOSE:\n return chalk.gray;\n default:\n return chalk.white;\n }\n }\n\n public log(level: LogLevel, ...args: unknown[]) {\n if (!Object.values(LogLevel).includes(level)) {\n throw new TypeError('Unknown log level');\n }\n\n if (level === LogLevel.VERBOSE && !this.verboseMode) return;\n if (level === LogLevel.DEBUG && !this.verboseMode) return;\n\n if (this.spinner?.isSpinning) this.spinner.stop();\n\n const timestamp = new Date().toISOString();\n const traceId = snapshotLogArgument(getTraceId());\n const requestId = snapshotLogArgument(getRequestId());\n const values = args.map(snapshotLogArgument);\n const errors: Array<{ argument: number; error: LogValue }> = [];\n const message = values\n .map((value, index) => {\n if (args[index] instanceof Error) {\n errors.push({ argument: index, error: value });\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n return value.stack || value.message || JSON.stringify(value, null, 2);\n }\n }\n return typeof value === 'string' ? value : JSON.stringify(value, null, 2);\n })\n .join(' ');\n\n // Encode each field before adding only the logger's own ANSI color sequences.\n const levelTag = this.getLevelColor(level)(`[${level.toUpperCase()}]`);\n const traceTag = chalk.cyan(`traceId=${encodeLogField(traceId)}`);\n const requestTag =\n requestId === 'unknown' ? '' : chalk.blue(`requestId=${encodeLogField(requestId)}`);\n console.log(\n `${chalk.gray(timestamp)} ${levelTag} ${traceTag} ${requestTag} message=${encodeLogField(message)}`\n );\n\n if (this.fileLogger) {\n const transportLevel =\n level === LogLevel.VERBOSE ? 'trace' : level === LogLevel.SUCCESS ? 'info' : level;\n try {\n this.fileLogger[transportLevel]({\n timestamp,\n severity: level,\n traceId,\n requestId,\n args: values,\n errors,\n });\n } catch (error) {\n this.closeFileDestination();\n this.reportFileError(error);\n }\n }\n\n if (this.spinner && !this.spinner.isSpinning) {\n this.spinner.start();\n }\n }\n\n public error(...args: unknown[]) {\n this.log(LogLevel.ERROR, ...args);\n }\n\n public warn(...args: unknown[]) {\n this.log(LogLevel.WARN, ...args);\n }\n\n public info(...args: unknown[]) {\n this.log(LogLevel.INFO, ...args);\n }\n\n public success(...args: unknown[]) {\n this.log(LogLevel.SUCCESS, ...args);\n }\n\n public debug(...args: unknown[]) {\n this.log(LogLevel.DEBUG, ...args);\n }\n\n public verbose(...args: unknown[]) {\n this.log(LogLevel.VERBOSE, ...args);\n }\n\n public spin(message: string): Ora {\n if (this.spinner) {\n this.spinner.succeed();\n }\n this.spinner = ora(encodeSpinnerMessage(message)).start();\n return this.spinner;\n }\n\n public stopSpinner(message?: string, success: boolean = true) {\n if (this.spinner) {\n if (success) {\n this.spinner.succeed(message === undefined ? undefined : encodeSpinnerMessage(message));\n } else {\n this.spinner.fail(message === undefined ? undefined : encodeSpinnerMessage(message));\n }\n this.spinner = null;\n }\n }\n}\n"],"mappings":";;;;;;AAcA,IAAY,WAAL,yBAAA,UAAA;CACL,SAAA,aAAA;CACA,SAAA,WAAA;CACA,SAAA,UAAA;CACA,SAAA,UAAA;CACA,SAAA,WAAA;CACA,SAAA,aAAA;;AACF,EAAA,CAAA,CAAA;AAOA,IAAa,SAAb,MAAa,OAAO;CAClB,OAAe;CACf,cAA+B;CAC/B,UAAiC;CACjC,aAAwC;CACxC,kBAAsE;CACtE,UAA8B;CAE9B,OAAc,YAAY,UAAyB,CAAC,GA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