@nudojs/service 4.0.0 → 5.0.0-beta.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.
@@ -1,5 +1,7 @@
1
- export { A as AnalysisConfig, a as AnalysisMode, C as CallRecord, D as DiagnosticsLevel, I as InterfaceConfig, L as LoadedEnv, N as NudoConfig, c as analysisConfig, f as findProjectConfig, i as interfaceConfig, l as loadEnvs, g as loadEnvsAsync, p as preloadPathEnvs } from '../config-Cqj8zeZH.js';
1
+ export { C as CallRecord } from '../call-record-CkyCFkT9.js';
2
2
  import { Abs } from '@nudojs/core';
3
+ export { L as LoadedEnv, l as loadEnvs, a as loadEnvsAsync, p as preloadPathEnvs } from '../env-loader-fj0TSCcA.js';
4
+ export { A as AnalysisConfig, a as AnalysisMode, C as CheckConfig, D as DiagnosticsLevel, I as InterfaceConfig, N as NudoConfig, b as analysisConfig, c as checkConfig, d as diskCacheRoot, f as findProjectConfig, i as interfaceConfig } from '../config-DDB588oA.js';
3
5
 
4
6
  /**
5
7
  * 内置类原型成员近似表(Abs 声明)。
@@ -3,20 +3,26 @@ import {
3
3
  analysisConfig,
4
4
  builtinProtoMember,
5
5
  builtinProtoMemberNames,
6
+ checkConfig,
6
7
  describeAbsMember,
8
+ diskCacheRoot,
7
9
  findProjectConfig,
8
10
  interfaceConfig,
11
+ resolveNpmNudo
12
+ } from "../chunk-YLALZXTZ.js";
13
+ import {
9
14
  loadEnvs,
10
15
  loadEnvsAsync,
11
- preloadPathEnvs,
12
- resolveNpmNudo
13
- } from "../chunk-ADFCZP72.js";
16
+ preloadPathEnvs
17
+ } from "../chunk-PVJIMQRI.js";
14
18
  export {
15
19
  BUILTIN_PROTOTYPE_METHOD_APPROXIMATIONS,
16
20
  analysisConfig,
17
21
  builtinProtoMember,
18
22
  builtinProtoMemberNames,
23
+ checkConfig,
19
24
  describeAbsMember,
25
+ diskCacheRoot,
20
26
  findProjectConfig,
21
27
  interfaceConfig,
22
28
  loadEnvs,
@@ -0,0 +1,254 @@
1
+ import { HarvestedEnv } from '@nudojs/harvester';
2
+ import { Abs, AbsModuleExports } from '@nudojs/core';
3
+
4
+ /**
5
+ * Host:从 npm 包 / @types 收集 .d.ts → harvestDts。
6
+ * 代数不碰 fs;这里只做「找到 dts 路径」这一层宿主职责。
7
+ */
8
+
9
+ /** 在 node_modules 中解析包根(含 @types/*) */
10
+ declare function resolvePackageRoot(pkg: string, fromDir?: string): string | undefined;
11
+ type PackageHarvest = {
12
+ pkg: string;
13
+ root: string;
14
+ dtsFiles: string[];
15
+ env: HarvestedEnv;
16
+ };
17
+ /**
18
+ * 从入口 .d.ts 沿 reference path / 相对 import 做 BFS 收集。
19
+ * 适合 @types 包(三斜线引用图);比整树 walk 更贴声明入口。
20
+ */
21
+ declare function collectDtsFromEntry(entry: string, maxFiles?: number): string[];
22
+ /** harvest 一个 npm 包(或 @types 包) */
23
+ declare function harvestPackage(pkg: string, fromDir?: string, maxFiles?: number): PackageHarvest | {
24
+ error: string;
25
+ };
26
+ /** harvest 结果 → 人类可读导出表 */
27
+ declare function formatHarvestSummary(h: PackageHarvest): string;
28
+ /** 取某个导出的展示串(formatShape) */
29
+ declare function lookupHarvested(h: PackageHarvest, moduleName: string, exportName: string): string | undefined;
30
+
31
+ /**
32
+ * harvest 自动化:源码裸 import → @types/package → env modules。
33
+ * 手动 `nudo harvest` 仍保留;这里是分析路径上的按需注入。
34
+ */
35
+
36
+ /** 裸说明符 → 包名(含 scope);相对/绝对/node: 与裸 Node 内建返回 undefined */
37
+ declare function barePackageName(spec: string): string | undefined;
38
+ declare function collectBarePackages(source: string): string[];
39
+ /** 测试/诊断:当前条目数(≤ HARVEST_CACHE_MAX) */
40
+ declare function getHarvestCacheSize(): number;
41
+ declare function harvestPackageCached(pkg: string, fromDir: string): PackageHarvest | null;
42
+ declare function clearHarvestCache(): void;
43
+ /**
44
+ * 自动 harvest 源码中全部裸包(有 @types 或包内 dts 时)。
45
+ * 返回可注入 setEnvModules 的 modules 表;无包可 harvest 时为空对象。
46
+ */
47
+ declare function autoHarvestModules(source: string, fromDir: string): Record<string, Record<string, Abs>>;
48
+
49
+ /**
50
+ * HarvestJson:L2 harvest 磁盘投影(design-persistent-cache)。
51
+ * 纯 JSON 签名投影——不存 Abs 本体;读回 materialize 为 mock Abs 导出表。
52
+ * fail-open:未知节点 / 损坏 JSON → undefined(miss,不 throw)。
53
+ */
54
+
55
+ /** 签名投影节点(可 JSON 化;足够 mock Abs 的 shape 面) */
56
+ type HarvestSig = {
57
+ k: "prim";
58
+ type: string;
59
+ } | {
60
+ k: "unknown";
61
+ } | {
62
+ k: "any";
63
+ } | {
64
+ k: "never";
65
+ } | {
66
+ k: "lit";
67
+ value: number | string | boolean | null;
68
+ } | {
69
+ k: "arr";
70
+ element: HarvestSig;
71
+ } | {
72
+ k: "tuple";
73
+ elements: HarvestSig[];
74
+ } | {
75
+ k: "obj";
76
+ slots: Record<string, {
77
+ v: HarvestSig;
78
+ opt?: boolean;
79
+ }>;
80
+ } | {
81
+ k: "fn";
82
+ params: string[];
83
+ paramTypes: HarvestSig[];
84
+ returns: HarvestSig;
85
+ } | {
86
+ k: "sum";
87
+ members: HarvestSig[];
88
+ } | {
89
+ k: "promise";
90
+ value: HarvestSig;
91
+ } | {
92
+ k: "generator";
93
+ value: HarvestSig;
94
+ } | {
95
+ k: "brand";
96
+ name: string;
97
+ shape: HarvestSig;
98
+ }
99
+ /** 泛型形参(T)——α 替换用 */
100
+ | {
101
+ k: "tvar";
102
+ name: string;
103
+ };
104
+ type HarvestJson = {
105
+ v: 1;
106
+ pkg: string;
107
+ pkgVersion?: string;
108
+ /** harvest 旋钮(maxFiles 等)进键 */
109
+ knobs: {
110
+ maxFiles: number;
111
+ abi: string;
112
+ };
113
+ /** 全部 dts 内容 sha256(不只入口) */
114
+ dtsHash: string;
115
+ modules: Record<string, Record<string, HarvestSig>>;
116
+ globals: Record<string, HarvestSig>;
117
+ stats: {
118
+ files: number;
119
+ symbols: number;
120
+ skipped: number;
121
+ };
122
+ };
123
+ /** Abs → 签名投影(丢 pred/conf;fn 只留参数名+类型面;保留泛型 α) */
124
+ declare function absToHarvestSig(a: Abs): HarvestSig;
125
+ /** 签名投影 → mock Abs(conf 合 mock) */
126
+ declare function harvestSigToAbs(sig: HarvestSig): Abs;
127
+ declare function serializeHarvestJson(pkg: string, env: HarvestedEnv, meta: {
128
+ dtsHash: string;
129
+ maxFiles: number;
130
+ pkgVersion?: string;
131
+ }): HarvestJson;
132
+ /** HarvestJson → mock Abs 导出表(materialize);损坏/版本不符 → null */
133
+ declare function materializeHarvestJson(j: unknown): HarvestedEnv | null;
134
+ /** L2 键:pkg + version + knobs + dtsClosureHash(相对化;content-addressable) */
135
+ declare function harvestCacheKey(pkg: string, meta: {
136
+ dtsHash: string;
137
+ maxFiles: number;
138
+ pkgVersion?: string;
139
+ }): string;
140
+
141
+ /**
142
+ * L2 harvest 磁盘层(design-persistent-cache):HarvestJson 跨会话复用。
143
+ * 布局:`~/.cache/nudo/deps/`(或 NUDO_DEPS_CACHE_DIR)。
144
+ * 键:harvestCacheKey(pkg, version, knobs, dtsClosureHash)。
145
+ * fail-open:读写失败 → 回落进程内 harvest(L0)。
146
+ */
147
+
148
+ /** 依赖包层缓存根(跨项目);off/0 关闭 */
149
+ declare function depsCacheRoot(): string | undefined;
150
+ /** dts 闭包内容哈希(覆盖每个实际读到的文件,不只入口) */
151
+ declare function dtsClosureHash(files: string[]): string;
152
+ declare function readHarvestDisk(root: string, key: string): HarvestJson | undefined;
153
+ declare function writeHarvestDisk(root: string, key: string, value: HarvestJson): void;
154
+ /**
155
+ * L2 + L0:**磁盘优先**(跳过 harvestDts 解析),miss 再 harvest 并写盘。
156
+ */
157
+ declare function harvestPackageWithDisk(pkg: string, fromDir: string, maxFiles?: number): PackageHarvest | null;
158
+ /** 从磁盘 materialize(不跑 harvestDts);键需调用方自算 */
159
+ declare function loadHarvestEnvFromDisk(pkg: string, meta: {
160
+ dtsHash: string;
161
+ maxFiles: number;
162
+ pkgVersion?: string;
163
+ }): HarvestedEnv | null;
164
+
165
+ /**
166
+ * Harvest Abs 导出 → AbsModuleExports(供 Abs 模块图注入)。
167
+ * harvest 产物已是 Abs;fn 槽 apply 直接返回声明返回类型(conf=mock)。
168
+ */
169
+
170
+ /** 单个 Abs 导出 → 可调用 mock(fn 槽按 relation α 替换,或返回声明返回类型) */
171
+ declare function harvestedValueToAbs(a: Abs): Abs;
172
+ /**
173
+ * 把 harvest 的 modules/globals 合成 AbsModuleExports。
174
+ * 键同时登记:原始模块路径、包名、basename(path / @types/path)。
175
+ */
176
+ declare function harvestToAbsModules(pkg: string, fromDir: string): Record<string, AbsModuleExports>;
177
+ declare function packageHarvestToAbsModules(pkg: string, h: PackageHarvest): Record<string, AbsModuleExports>;
178
+ /** 裸说明符 → Abs 导出表(走 harvest 缓存) */
179
+ declare function bareSpecToAbsModules(spec: string, fromFile: string): AbsModuleExports | undefined;
180
+
181
+ /**
182
+ * 预置 Node API env:从 @types/node 的 .d.ts harvest。
183
+ * 与 packages/env 的手写 env 并行;此路径自动、可刷新。
184
+ *
185
+ * Productization (P0-B B2/B7):
186
+ * - In-process cache keyed by package root + package.json mtime/size.
187
+ * - **Disk cache** (HarvestJson under `~/.cache/nudo/deps`) — cross-session reuse.
188
+ * - Terminal failures (`not-found`/`no-dts`/`failed`) also cache — no retry storm.
189
+ * `disabled` is never cached (env var can flip mid-process).
190
+ * - **Degrade chain**: harvest miss/fail → handwritten `@nudojs/env` node face
191
+ * (`loadEnvs(["node"])`), flagged `degraded`. Handwritten still wins on overlap
192
+ * via `mergeHarvestUnderEnv`.
193
+ * - `clearNodeHarvestCache()` for tests / watch invalidation.
194
+ * - `NUDO_HARVEST_NODE=off` disables harvest (explicit skip, not silent).
195
+ * - Defaults stay IDE-budgeted: maxFiles=12, maxMs=2500.
196
+ */
197
+
198
+ /** IDE-startup budgets for @types/node harvest. Do not raise casually. */
199
+ declare const HARVEST_NODE_DEFAULT_MAX_FILES = 12;
200
+ declare const HARVEST_NODE_DEFAULT_MAX_MS = 2500;
201
+ type HarvestNodeStats = {
202
+ files: number;
203
+ symbols: number;
204
+ skipped: number;
205
+ };
206
+ type NodeEnvResult = {
207
+ ok: true;
208
+ env: HarvestedEnv;
209
+ root: string;
210
+ files: number;
211
+ stats: HarvestNodeStats;
212
+ /** true when this result came from the in-process cache */
213
+ cached: boolean;
214
+ /** true when this result is handwritten `@nudojs/env` fallback (harvest miss/fail) */
215
+ degraded?: boolean;
216
+ } | {
217
+ ok: false;
218
+ error: string;
219
+ reason: "disabled" | "not-found" | "no-dts" | "failed";
220
+ /** true when this failure came from the in-process cache */
221
+ cached?: boolean;
222
+ };
223
+ /**
224
+ * Clear the in-process @types/node harvest cache.
225
+ * Drops **success and terminal-failure** entries (including `not-found`), so
226
+ * a mid-session `@types/node` install becomes visible without process restart.
227
+ * Tests, watch-mode dep-hash invalidation, and package-manager hooks should
228
+ * call this when `node_modules/@types/node` changes underneath the process.
229
+ */
230
+ declare function clearNodeHarvestCache(): void;
231
+ /** Number of cached harvest results (diagnostics / tests). */
232
+ declare function getNodeHarvestCacheSize(): number;
233
+ declare function isHarvestNodeDisabled(env?: NodeJS.ProcessEnv): boolean;
234
+ /**
235
+ * 手写 `@nudojs/env` node 面(B2 降级链):harvest 未命中/失败时仍给出
236
+ * 可分析的 Node API 声明;与 harvest 重叠处由 mergeHarvestUnderEnv 让手写 wins。
237
+ */
238
+ declare function handwrittenNodeEnv(): HarvestedEnv | null;
239
+ /**
240
+ * harvest @types/node(限制文件数 + 时间预算,避免拖垮启动)。
241
+ * Success **and** terminal failures (`not-found` / `no-dts` / `failed`) are
242
+ * cached in-process so IDE analysis does not re-walk / re-timeout every file.
243
+ * `disabled` is never cached — the env var can flip mid-process.
244
+ * Call `clearNodeHarvestCache()` after `@types/node` changes.
245
+ */
246
+ declare function harvestNodeTypes(fromDir?: string, maxFiles?: number, maxMs?: number): NodeEnvResult;
247
+ /** 把 harvest 结果压成「模块名 → 导出名列表」摘要,便于日志/测试 */
248
+ declare function summarizeNodeEnv(env: HarvestedEnv): {
249
+ modules: string[];
250
+ globals: string[];
251
+ symbolCount: number;
252
+ };
253
+
254
+ export { HARVEST_NODE_DEFAULT_MAX_FILES, HARVEST_NODE_DEFAULT_MAX_MS, type HarvestJson, type HarvestNodeStats, type HarvestSig, type NodeEnvResult, type PackageHarvest, absToHarvestSig, autoHarvestModules, barePackageName, bareSpecToAbsModules, clearHarvestCache, clearNodeHarvestCache, collectBarePackages, collectDtsFromEntry, depsCacheRoot, dtsClosureHash, formatHarvestSummary, getHarvestCacheSize, getNodeHarvestCacheSize, handwrittenNodeEnv, harvestCacheKey, harvestNodeTypes, harvestPackage, harvestPackageCached, harvestPackageWithDisk, harvestSigToAbs, harvestToAbsModules, harvestedValueToAbs, isHarvestNodeDisabled, loadHarvestEnvFromDisk, lookupHarvested, materializeHarvestJson, packageHarvestToAbsModules, readHarvestDisk, resolvePackageRoot, serializeHarvestJson, summarizeNodeEnv, writeHarvestDisk };
@@ -0,0 +1,75 @@
1
+ import {
2
+ HARVEST_NODE_DEFAULT_MAX_FILES,
3
+ HARVEST_NODE_DEFAULT_MAX_MS,
4
+ clearNodeHarvestCache,
5
+ getNodeHarvestCacheSize,
6
+ handwrittenNodeEnv,
7
+ harvestNodeTypes,
8
+ isHarvestNodeDisabled,
9
+ summarizeNodeEnv
10
+ } from "./chunk-K3ZPOTP2.js";
11
+ import {
12
+ absToHarvestSig,
13
+ autoHarvestModules,
14
+ barePackageName,
15
+ bareSpecToAbsModules,
16
+ clearHarvestCache,
17
+ collectBarePackages,
18
+ collectDtsFromEntry,
19
+ depsCacheRoot,
20
+ dtsClosureHash,
21
+ formatHarvestSummary,
22
+ getHarvestCacheSize,
23
+ harvestCacheKey,
24
+ harvestPackage,
25
+ harvestPackageCached,
26
+ harvestPackageWithDisk,
27
+ harvestSigToAbs,
28
+ harvestToAbsModules,
29
+ harvestedValueToAbs,
30
+ loadHarvestEnvFromDisk,
31
+ lookupHarvested,
32
+ materializeHarvestJson,
33
+ packageHarvestToAbsModules,
34
+ readHarvestDisk,
35
+ resolvePackageRoot,
36
+ serializeHarvestJson,
37
+ writeHarvestDisk
38
+ } from "./chunk-U7JYTRIB.js";
39
+ import "./chunk-PVJIMQRI.js";
40
+ export {
41
+ HARVEST_NODE_DEFAULT_MAX_FILES,
42
+ HARVEST_NODE_DEFAULT_MAX_MS,
43
+ absToHarvestSig,
44
+ autoHarvestModules,
45
+ barePackageName,
46
+ bareSpecToAbsModules,
47
+ clearHarvestCache,
48
+ clearNodeHarvestCache,
49
+ collectBarePackages,
50
+ collectDtsFromEntry,
51
+ depsCacheRoot,
52
+ dtsClosureHash,
53
+ formatHarvestSummary,
54
+ getHarvestCacheSize,
55
+ getNodeHarvestCacheSize,
56
+ handwrittenNodeEnv,
57
+ harvestCacheKey,
58
+ harvestNodeTypes,
59
+ harvestPackage,
60
+ harvestPackageCached,
61
+ harvestPackageWithDisk,
62
+ harvestSigToAbs,
63
+ harvestToAbsModules,
64
+ harvestedValueToAbs,
65
+ isHarvestNodeDisabled,
66
+ loadHarvestEnvFromDisk,
67
+ lookupHarvested,
68
+ materializeHarvestJson,
69
+ packageHarvestToAbsModules,
70
+ readHarvestDisk,
71
+ resolvePackageRoot,
72
+ serializeHarvestJson,
73
+ summarizeNodeEnv,
74
+ writeHarvestDisk
75
+ };