@nudojs/core 1.7.10 → 1.9.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.
@@ -116,6 +116,12 @@ type NudoConstraint = {
116
116
  readonly members?: NudoConstraint[];
117
117
  /** 一等函数约束(fn() 构建器产出) */
118
118
  readonly fn?: NudoFnConstraint;
119
+ /**
120
+ * 自引用模板 thunk(issue #120):侧车以真 JS 执行,thunk 闭包引用的
121
+ * const 在 derefConstraint 调用时已初始化——递归结构一句声明。
122
+ * 消费端按 LAZY_TEMPLATE_DEPTH 预算展开;derefConstraint 按 thunk 记忆化。
123
+ */
124
+ readonly lazy?: () => NudoConstraint | ConstraintBuilder;
119
125
  };
120
126
  /** fn(params, returns?, { throws? }) 的一等函数约束形态 */
121
127
  type NudoFnConstraint = {
@@ -178,11 +184,34 @@ declare function union(...cs: (NudoConstraint | ConstraintBuilder | number | str
178
184
  * 对不含 nullish 的契约(如 number().gt(0))报 constraint-violated。
179
185
  */
180
186
  declare function nullable(c: NudoConstraint | ConstraintBuilder | number | string | boolean): ConstraintBuilder;
187
+ /**
188
+ * lazy(() => constraint):自引用约束模板(issue #120)。
189
+ * 侧车以真 JS 执行——thunk 闭包里引用的 const 在 derefConstraint 调用时
190
+ * 已初始化,递归结构一句声明:
191
+ *
192
+ * export const astNode = shape({
193
+ * type: string(),
194
+ * object: lazy(() => astNode).optional(),
195
+ * });
196
+ *
197
+ * 消费端(instantiate / entry Abs / 显示)按 LAZY_TEMPLATE_DEPTH 预算展开,
198
+ * 预算耗尽的字段位渲染为「缺席槽」——与手写有限层模板同语义,
199
+ * 守卫递归(`if (node.object == null) …`)在边界处干净剪枝。
200
+ */
201
+ declare function lazy(thunk: () => NudoConstraint | ConstraintBuilder): ConstraintBuilder;
202
+ /**
203
+ * 解一层 lazy:调用 thunk 一次、校验产物是约束、toPlainConstraint 归一化,
204
+ * 并按 thunk 记忆化(重复 deref 同一闭包 → 同一对象)。
205
+ * 不递归展开——递归层数由消费端的 depth 预算控制。
206
+ */
207
+ declare function derefConstraint(c: NudoConstraint): NudoConstraint;
181
208
  /**
182
209
  * 契约域是否包含 nullish(null / undefined)。
183
210
  * union 任一成员含 nullish 即含;lit(null)/lit(undefined) 的 eq 谓词识别。
211
+ * lazy 包装先 deref;环经 seen(thunk 身份)终止——nullish 只出现在
212
+ * 有限位置,DFS-with-seen 判定可靠,无需层数预算。
184
213
  */
185
- declare function constraintAdmitsNullish(c: NudoConstraint): boolean;
214
+ declare function constraintAdmitsNullish(c: NudoConstraint, seen?: Set<object>): boolean;
186
215
  /**
187
216
  * fn(params, returns?, { throws? }):一等函数约束。
188
217
  * Phase 1 只展示不执法:参数位 instantiate 恒真(pTrue),
@@ -197,11 +226,11 @@ declare function fn(params: Record<string, NudoConstraint | ConstraintBuilder |
197
226
  * prim 不一致或任一含 fields/element/members/fn → throw。
198
227
  */
199
228
  declare function andC(...cs: (NudoConstraint | ConstraintBuilder)[]): ConstraintBuilder;
200
- /** partial(c):shape 全字段变可选;非 shape throw */
229
+ /** partial(c):shape 全字段变可选;非 shape throw(lazy 包装先解一层) */
201
230
  declare function partial(c: NudoConstraint | ConstraintBuilder): ConstraintBuilder;
202
- /** pick(c, keys):shape 子形状(不存在的 key 忽略);非 shape throw */
231
+ /** pick(c, keys):shape 子形状(不存在的 key 忽略);非 shape throw(lazy 包装先解一层) */
203
232
  declare function pick(c: NudoConstraint | ConstraintBuilder, keys: string[]): ConstraintBuilder;
204
- /** omit(c, keys):shape 去字段;非 shape throw */
233
+ /** omit(c, keys):shape 去字段;非 shape throw(lazy 包装先解一层) */
205
234
  declare function omit(c: NudoConstraint | ConstraintBuilder, keys: string[]): ConstraintBuilder;
206
235
  /**
207
236
  * 约束构建器表面名表(单一真源):case 实参文法、mock 类型表达式识别与
@@ -224,14 +253,14 @@ declare const CONSTRAINT_BUILDER_NAMES: readonly string[];
224
253
  * 这类拼接可以借前缀骗过本正则并执行任意 JS。
225
254
  */
226
255
  declare const CONSTRAINT_EXPR_RE: RegExp;
227
- /** 把模板绑定到参数名:self → paramName;shape 展开为字段访问 Pred */
228
- declare function instantiateConstraint(c: NudoConstraint, paramName: string): Pred;
256
+ /** 把模板绑定到参数名:self → paramName;shape 展开为字段访问 Pred(lazy 按 depth 预算展开) */
257
+ declare function instantiateConstraint(c: NudoConstraint, paramName: string, depth?: number): Pred;
229
258
  /**
230
259
  * 契约 → 函数入口 param Abs(infer/hover 用)。
231
260
  * 标量:prim + pred;shape:obj slots 递归;union:成员 joinAbs;
232
261
  * fn 形态:一等 fn shape(paramTypes/returnType),供 refine→error / 展示。
233
262
  */
234
- declare function constraintToEntryAbs(c: NudoConstraint, paramName: string): Abs;
263
+ declare function constraintToEntryAbs(c: NudoConstraint, paramName: string, depth?: number): Abs;
235
264
  /**
236
265
  * fn 约束 → 逐参约束表(interface 推导 / 入口签名消费)。
237
266
  * 非 fn() 形态 throw——调用方应先判 c.fn。
@@ -802,4 +831,4 @@ declare class ProjectionBudget {
802
831
  exit(): void;
803
832
  }
804
833
 
805
- export { array as $, type CheckJson as A, type CheckJsonMulti as B, type CheckIssue as C, type ConstraintBuilder as D, type EffectiveInterfaceOpts as E, type Diagnostic as F, type EffectiveInterface as G, type GitlabCodeQualityIssue as H, type InterfaceSource as I, type InterfaceDiag as J, type InterfaceTierInfo as K, type LeakBudget as L, MAX_PROMISE_MICROS as M, type NudoConstraint as N, type NamedImport as O, PROJECTION_MAX_DEPTH as P, type NudoField as Q, type NudoFnConstraint as R, NudoSidecarError as S, type NudoSig as T, type RefineDiag as U, type RefineEntry as V, type RefineResolveOpts as W, SELF as X, actionsForIssue as Y, andC as Z, any as _, type InterfaceTierOpts as a, takeRefineDiagsSince as a$, boolean as a0, checkArg as a1, checkCall as a2, constraintAdmitsNullish as a3, constraintToEntryAbs as a4, drainPromiseMicros as a5, effectiveInterface as a6, enterPromiseExecutorScope as a7, evalPromiseCtor as a8, evalPromiseMethod as a9, leavePromiseExecutorScope as aA, lenTerm as aB, litC as aC, localNamedExports as aD, notePromiseExecutorFork as aE, nullable as aF, number as aG, omit as aH, partial as aI, pick as aJ, queuePromiseMicro as aK, refineDiagCount as aL, refineToIndexedFull as aM, resetNudoModuleExecCache as aN, resetParseSourceCache as aO, resetSidecarLoadFailureCache as aP, serializeCheckJson as aQ, serializeCheckJsonMulti as aR, setInterfaceDiagCollector as aS, setRefineDiagCollector as aT, shape as aU, sidecarClosureFingerprint as aV, sidecarPathOf as aW, string as aX, takeInterfaceDiags as aY, takeInterfaceDiagsSince as aZ, takeRefineDiags as a_, evalPromiseStatic as aa, execNudoModule as ab, extractDeclaredThrows as ac, extractFnBudget as ad, extractNudoImports as ae, extractRefineReturnFromSource as af, extractRefinesFromSource as ag, fn as ah, fnConstraintToEntryReqs as ai, formatCheckReport as aj, formatConstraint as ak, formatDiagnostics as al, formatEffectiveInterfaceDisplay as am, formatGithubAnnotations as an, formatGitlabCodeQuality as ao, formatInterfaceTierLine as ap, generatedExportNames as aq, getParseSourceCacheSize as ar, getTerm as as, instantiateConstraint as at, interfaceDiagCount as au, interfaceSourceOf as av, interfaceTierOf as aw, isIntFlag as ax, isNodeModulesPath as ay, isNudoConstraint as az, type LoadDepsFingerprint as b, throwConstraintToKinds as b0, union as b1, ProjectionBudget as c, type ProjectionStopReason as d, defaultLeakBudget as e, exceedsBudget as f, exportedNameOfLocal as g, extractAllLoadSpecs as h, getPromiseMicrosLength as i, loadModuleDepsFingerprint as j, resolveDepPath as k, leakIfNeeded as l, maybeLeak as m, normPath as n, stablePathKey as o, parseSource as p, stablePathKeyGraph as q, resetLeakCounter as r, sidecarSpecsOf as s, termDepth as t, termNodes as u, type CheckReport as v, CONSTRAINT_BUILDERS as w, CONSTRAINT_BUILDER_NAMES as x, CONSTRAINT_EXPR_RE as y, type CheckAction as z };
834
+ export { array as $, type CheckJson as A, type CheckJsonMulti as B, type CheckIssue as C, type ConstraintBuilder as D, type EffectiveInterfaceOpts as E, type Diagnostic as F, type EffectiveInterface as G, type GitlabCodeQualityIssue as H, type InterfaceSource as I, type InterfaceDiag as J, type InterfaceTierInfo as K, type LeakBudget as L, MAX_PROMISE_MICROS as M, type NudoConstraint as N, type NamedImport as O, PROJECTION_MAX_DEPTH as P, type NudoField as Q, type NudoFnConstraint as R, NudoSidecarError as S, type NudoSig as T, type RefineDiag as U, type RefineEntry as V, type RefineResolveOpts as W, SELF as X, actionsForIssue as Y, andC as Z, any as _, type InterfaceTierOpts as a, takeInterfaceDiagsSince as a$, boolean as a0, checkArg as a1, checkCall as a2, constraintAdmitsNullish as a3, constraintToEntryAbs as a4, derefConstraint as a5, drainPromiseMicros as a6, effectiveInterface as a7, enterPromiseExecutorScope as a8, evalPromiseCtor as a9, isNudoConstraint as aA, lazy as aB, leavePromiseExecutorScope as aC, lenTerm as aD, litC as aE, localNamedExports as aF, notePromiseExecutorFork as aG, nullable as aH, number as aI, omit as aJ, partial as aK, pick as aL, queuePromiseMicro as aM, refineDiagCount as aN, refineToIndexedFull as aO, resetNudoModuleExecCache as aP, resetParseSourceCache as aQ, resetSidecarLoadFailureCache as aR, serializeCheckJson as aS, serializeCheckJsonMulti as aT, setInterfaceDiagCollector as aU, setRefineDiagCollector as aV, shape as aW, sidecarClosureFingerprint as aX, sidecarPathOf as aY, string as aZ, takeInterfaceDiags as a_, evalPromiseMethod as aa, evalPromiseStatic as ab, execNudoModule as ac, extractDeclaredThrows as ad, extractFnBudget as ae, extractNudoImports as af, extractRefineReturnFromSource as ag, extractRefinesFromSource as ah, fn as ai, fnConstraintToEntryReqs as aj, formatCheckReport as ak, formatConstraint as al, formatDiagnostics as am, formatEffectiveInterfaceDisplay as an, formatGithubAnnotations as ao, formatGitlabCodeQuality as ap, formatInterfaceTierLine as aq, generatedExportNames as ar, getParseSourceCacheSize as as, getTerm as at, instantiateConstraint as au, interfaceDiagCount as av, interfaceSourceOf as aw, interfaceTierOf as ax, isIntFlag as ay, isNodeModulesPath as az, type LoadDepsFingerprint as b, takeRefineDiags as b0, takeRefineDiagsSince as b1, throwConstraintToKinds as b2, union as b3, ProjectionBudget as c, type ProjectionStopReason as d, defaultLeakBudget as e, exceedsBudget as f, exportedNameOfLocal as g, extractAllLoadSpecs as h, getPromiseMicrosLength as i, loadModuleDepsFingerprint as j, resolveDepPath as k, leakIfNeeded as l, maybeLeak as m, normPath as n, stablePathKey as o, parseSource as p, stablePathKeyGraph as q, resetLeakCounter as r, sidecarSpecsOf as s, termDepth as t, termNodes as u, type CheckReport as v, CONSTRAINT_BUILDERS as w, CONSTRAINT_BUILDER_NAMES as x, CONSTRAINT_EXPR_RE as y, type CheckAction as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/core",
3
- "version": "1.7.10",
3
+ "version": "1.9.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },