@nudojs/core 2.0.0 → 2.1.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.
- package/dist/{chunk-VVSVQKWF.js → chunk-6REHMIAE.js} +22 -3
- package/dist/exec.js +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.js +58 -20
- package/package.json +1 -1
|
@@ -2811,6 +2811,15 @@ function ok() {
|
|
|
2811
2811
|
function fail(reason) {
|
|
2812
2812
|
return { ok: false, reason };
|
|
2813
2813
|
}
|
|
2814
|
+
function requiredFnArity(params) {
|
|
2815
|
+
if (!params) return 0;
|
|
2816
|
+
let n = 0;
|
|
2817
|
+
for (const p of params) {
|
|
2818
|
+
if (!p || p.startsWith("...") || p.endsWith("?")) continue;
|
|
2819
|
+
n++;
|
|
2820
|
+
}
|
|
2821
|
+
return n;
|
|
2822
|
+
}
|
|
2814
2823
|
function leqAbs(src, tgt, opts = {}) {
|
|
2815
2824
|
const phi2 = opts.phi ?? pTrue;
|
|
2816
2825
|
return leqWithPred(src, tgt, phi2, opts.env ?? null, 0);
|
|
@@ -2963,8 +2972,12 @@ function leqShape(src, tgt, phi2, env, depth) {
|
|
|
2963
2972
|
}
|
|
2964
2973
|
if (t.k === "fn") {
|
|
2965
2974
|
if (s.k !== "fn") return fail(`shape ${s.k} \u22AD fn`);
|
|
2966
|
-
|
|
2967
|
-
|
|
2975
|
+
const sReq = requiredFnArity(s.params);
|
|
2976
|
+
const tReq = requiredFnArity(t.params);
|
|
2977
|
+
if (sReq > tReq) {
|
|
2978
|
+
return fail(
|
|
2979
|
+
`fn arity required ${sReq} \u22AD target required ${tReq} (params ${s.params.length} / ${t.params.length})`
|
|
2980
|
+
);
|
|
2968
2981
|
}
|
|
2969
2982
|
if (t.returnType !== void 0) {
|
|
2970
2983
|
const sr = s.returnType;
|
|
@@ -3879,7 +3892,12 @@ function isRelFn(a) {
|
|
|
3879
3892
|
if (!s || s.k !== "fn") return false;
|
|
3880
3893
|
if (s.returnType === void 0) return false;
|
|
3881
3894
|
if (s.paramTypes === void 0) return s.params.length === 0;
|
|
3882
|
-
|
|
3895
|
+
if (s.paramTypes.length === s.params.length) return true;
|
|
3896
|
+
let required = 0;
|
|
3897
|
+
for (const p of s.params) {
|
|
3898
|
+
if (p && !p.startsWith("...") && !p.endsWith("?")) required++;
|
|
3899
|
+
}
|
|
3900
|
+
return s.paramTypes.length === required;
|
|
3883
3901
|
}
|
|
3884
3902
|
function litOfTerm(t) {
|
|
3885
3903
|
return t.op === "lit" ? t.value : void 0;
|
|
@@ -10413,6 +10431,7 @@ export {
|
|
|
10413
10431
|
awaitAbs,
|
|
10414
10432
|
coerceAsyncReturn,
|
|
10415
10433
|
classFromMethods,
|
|
10434
|
+
requiredFnArity,
|
|
10416
10435
|
leqAbs,
|
|
10417
10436
|
tagAbsOrigin,
|
|
10418
10437
|
getAbsOrigin,
|
package/dist/exec.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -490,6 +490,8 @@ type LeqResult = {
|
|
|
490
490
|
* src 可赋给 tgt。
|
|
491
491
|
* phi:路径前提(可选);env:用于 brand 继承链。
|
|
492
492
|
*/
|
|
493
|
+
/** Required arity from fn param labels — skips rest (`...`) and optional (`?`). */
|
|
494
|
+
declare function requiredFnArity(params: readonly string[] | undefined): number;
|
|
493
495
|
declare function leqAbs(src: Abs, tgt: Abs, opts?: {
|
|
494
496
|
phi?: Phi;
|
|
495
497
|
env?: AstEnv;
|
|
@@ -797,23 +799,25 @@ declare function string(): ConstraintBuilder;
|
|
|
797
799
|
declare function boolean(): ConstraintBuilder;
|
|
798
800
|
/** any() —— 无约束;formatConstraint / draft import 与显示同源 */
|
|
799
801
|
declare function any(): ConstraintBuilder;
|
|
800
|
-
/** array(item) —— 数组,元素满足 item */
|
|
801
|
-
declare function array(item: NudoConstraint | ConstraintBuilder): ConstraintBuilder;
|
|
802
|
+
/** array(item) —— 数组,元素满足 item;item 亦可为具体字面量(指令文法) */
|
|
803
|
+
declare function array(item: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined): ConstraintBuilder;
|
|
802
804
|
/**
|
|
803
805
|
* object 形状约束(契约规范形状,无需 interface):
|
|
804
806
|
*
|
|
805
807
|
* shape({ id: number().gt(0), name: string() })
|
|
808
|
+
*
|
|
809
|
+
* 字段值亦可为具体字面量(指令文法)。
|
|
806
810
|
*/
|
|
807
|
-
declare function shape(fields: Record<string, NudoConstraint | ConstraintBuilder>): ConstraintBuilder;
|
|
811
|
+
declare function shape(fields: Record<string, NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined>): ConstraintBuilder;
|
|
808
812
|
/** union(...cs):成员析取;instantiate 为 or(...),entry Abs 为成员 joinAbs。空参 throw */
|
|
809
|
-
declare function union(...cs: (NudoConstraint | ConstraintBuilder)[]): ConstraintBuilder;
|
|
813
|
+
declare function union(...cs: (NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined)[]): ConstraintBuilder;
|
|
810
814
|
/**
|
|
811
815
|
* fn(params, returns?, { throws? }):一等函数约束。
|
|
812
816
|
* Phase 1 只展示不执法:参数位 instantiate 恒真(pTrue),
|
|
813
817
|
* 逐参约束经 fnConstraintToEntryReqs 消费。
|
|
814
818
|
*/
|
|
815
|
-
declare function fn(params: Record<string, NudoConstraint | ConstraintBuilder>, returns?: NudoConstraint | ConstraintBuilder, opts?: {
|
|
816
|
-
throws?: NudoConstraint | ConstraintBuilder;
|
|
819
|
+
declare function fn(params: Record<string, NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined>, returns?: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined, opts?: {
|
|
820
|
+
throws?: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined;
|
|
817
821
|
}): ConstraintBuilder;
|
|
818
822
|
/** partial(c):shape 全字段变可选;非 shape throw */
|
|
819
823
|
declare function partial(c: NudoConstraint | ConstraintBuilder): ConstraintBuilder;
|
|
@@ -1793,4 +1797,4 @@ type InjectedDomainEvidenceOpts = {
|
|
|
1793
1797
|
*/
|
|
1794
1798
|
declare function checkInjectedDomainEvidence(fnName: string, source: string, records: InjectedDomainRecord[], opts: InjectedDomainEvidenceOpts): CheckIssue[];
|
|
1795
1799
|
|
|
1796
|
-
export { Abs, type AbsAssignRecord, type AbsCallRecord, type AbsFnImpl, type AbsInlay, AbsModuleExports, type AbsSigImpl, type ArgDerivation, AstEnv, type CheckIssue, type CheckJson, type CheckOptions, type CheckReport, type ClassDef, type CollectAbsInlaysOpts, Confidence, type ConstraintBuilder, type DerivationNode, type Diagnostic, type EffectiveInterface, type EffectiveInterfaceOpts, type Environment, type EvalOptions, type EvalResult, type FnAbs, type FnFp, type FormalParam, type FormatOptions, HofSite, type InjectedDomainRecord, type InterfaceDiag, type InterfaceSource, type InterfaceTierInfo, type InterfaceTierOpts, type LeakBudget, type LeqResult, type LoadDepsFingerprint, MAX_CALL_DEPTH, MAX_TOTAL_CALLS, type MethodDef, type MockHelper, type NamedImport, type NudoConstraint, type NudoField, type NudoFnConstraint, NudoSidecarError, type NudoSig, type ObjShape, Phi, type PolyFn, Pred, PrimName, type RefineDiag, type RefineEntry, type RefineResolveOpts, RelSource, SELF, Shape, type Slot, type TemplateMeta, type TemplatePartDesc, type TemplatePartView, type TemplatePredicateDecision, Term, type TypeParam, abortDerivationSession, absFunction, absShapeKey, absTemplateViews, absToConstraint, add, allFixedTextOfViews, analyzeFn, analyzeFnFull, any, applyAbsFn, array, attachFnImpl, awaitAbs, beginCollectionFork, beginDerivationSession, boolean, buildArgsFromAssume, callAbsMethod, callFunction, callFunctionFull, canSkipLiteralCallScan, checkArg, checkCall, checkInjectedDomainEvidence, checkSource, classFromMethods, clearCollectionTables, cmp, coerceAsyncReturn, collectAbsFreeVars, collectAbsInlays, collectAbsNodeTypes, collectionElementJoin, collectionExactLen, concatString, constraintToEntryAbs, contractParamNameSet, createEnvironment, createTemplateAbs, currentPhi, decideEndsWith, decideIncludes, decideStartsWith, defaultLeakBudget, defineClass, definitelyNotNullishShape, denoteGuard, derivationChain, describePhi, div, effectiveInterface, emptyEnv, endCollectionFork, endDerivationSession, errorBrandAbs, evalArrayStatic, evalBuiltinInstanceMethod, evalBuiltinNew, evalDateCtor, evalDateMethod, evalDateStatic, evalGlobalFn, evalJsonMethod, evalMathMethod, evalMethodBody, evalNamespaceCall, evalNode, evalNumberStatic, evalObjectMethod, evalProgramAbs, evalPromiseCtor, evalPromiseStatic, evalRegExpCtor, evalRegExpMethod, evalSource, evictCheckSourceMemoForPaths, evictGeneralizeMemoForPaths, exceedsBudget, execNudoModule, extractAllLoadSpecs, extractFn, extractNudoImports, extractRefineReturnFromSource, extractRefinesFromSource, falseConstraint, findAbsAtPosition, fixedLengthOfViews, fn, fnConstraintToEntryReqs, fnFingerprints, fnOf, formalParamDisplayNames, formalParamsFromNodes, formatAbs, formatAbsMultiline, formatCheckReport, formatConstraint, formatDiagnostics, formatEffectiveInterfaceDisplay, formatInterfaceTierLine, formatShape, formatShapeSlot, formatTemplateNameViews, generalizeAll, generalizeFromAst, generalizeSourceKeyPart, generatedExportNames, getAbsProperty, getClass, getClassChain, getDerivation, getFnImpl, getFnNameAndBodies, getGeneralizeMemoSize, getParseSourceCacheSize, getSlot, getTerm, hasDerivationSession, hashSource, instanceOf, instantiateClass, instantiateConstraint, interfaceDiagCount, interfaceSourceOf, interfaceTierOf, isErrorCtorName, isIntFlag, isMapAbs, isNodeModulesPath, isNudoConstraint, isNullishLitAbs, isObj, isSetAbs, isTemplateLike, joinAbs, joinFunctions, joinObjects, joinThenProject, joinValues, knownPrefixOfViews, knownSuffixOfViews, leakIfNeeded, lenTerm, leqAbs, listFunctionNames, literalMeetsConstraint, loadModuleDepsFingerprint, localNamedExports, locateContractParam, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, looseEqAbs, makeMapAbs, makeSetAbs, makeSum, mapClearEntries, mapDeleteEntry, mapEntriesAbs, mapGetEntry, mapHasEntry, mapSetEntry, mapSizeAbs, mapValuesAbs, matchRelIdentLit, maybeLeak, mergeAdjacentFixedViews, mergeCollectionArms, mock, mod, mul, negAbs, normPath, notAbs, noteCollectionWrite, noteDerivationAdd, noteDerivationJoin, number, objOf, omit, parseSource, partial, pick, popCollectionArm, popPhi, projectBrand, projectDerivationDsl, pushCollectionArm, pushPhi, refineAbsForRelTrue, refineDiagCount, refineToIndexedFull, relationFingerprint, relationFn, resetAbsCallBudget, resetCheckSourceMemo, resetFnFpCache, resetGeneralizeMemo, resetHashSourceCache, resetLeakCounter, resetNudoModuleExecCache, resetParseSourceCache, resetPhi, resolveDepPath, serializeCheckJson, setAbsAssignCollector, setAbsCallCollector, setAbsNodeCollector, setAbsTruncationCollector, setAddEntry, setClearEntries, setDeleteEntry, setDerivation, setDerivationCollector, setElementsAbs, setHasEntry, setInterfaceDiagCollector, setRefineDiagCollector, setSizeAbs, shape, shapeOnlyFn, sidecarClosureFingerprint, sidecarPathOf, sidecarSpecsOf, spread, spy, stableAnalyzeKeySource, strictEqAbs, string, stripTypes, stub, sub, superNameOf, tagDerivationRoot, takeInterfaceDiags, takeInterfaceDiagsSince, takeRefineDiags, takeRefineDiagsSince, templateMatchesValue, templatePartsOf, termDepth, termKey, termNodes, trueConstraint, typeofAbs, union, viewTemplateParts, withPhiConstraint, withVar, wrapPromise };
|
|
1800
|
+
export { Abs, type AbsAssignRecord, type AbsCallRecord, type AbsFnImpl, type AbsInlay, AbsModuleExports, type AbsSigImpl, type ArgDerivation, AstEnv, type CheckIssue, type CheckJson, type CheckOptions, type CheckReport, type ClassDef, type CollectAbsInlaysOpts, Confidence, type ConstraintBuilder, type DerivationNode, type Diagnostic, type EffectiveInterface, type EffectiveInterfaceOpts, type Environment, type EvalOptions, type EvalResult, type FnAbs, type FnFp, type FormalParam, type FormatOptions, HofSite, type InjectedDomainRecord, type InterfaceDiag, type InterfaceSource, type InterfaceTierInfo, type InterfaceTierOpts, type LeakBudget, type LeqResult, type LoadDepsFingerprint, MAX_CALL_DEPTH, MAX_TOTAL_CALLS, type MethodDef, type MockHelper, type NamedImport, type NudoConstraint, type NudoField, type NudoFnConstraint, NudoSidecarError, type NudoSig, type ObjShape, Phi, type PolyFn, Pred, PrimName, type RefineDiag, type RefineEntry, type RefineResolveOpts, RelSource, SELF, Shape, type Slot, type TemplateMeta, type TemplatePartDesc, type TemplatePartView, type TemplatePredicateDecision, Term, type TypeParam, abortDerivationSession, absFunction, absShapeKey, absTemplateViews, absToConstraint, add, allFixedTextOfViews, analyzeFn, analyzeFnFull, any, applyAbsFn, array, attachFnImpl, awaitAbs, beginCollectionFork, beginDerivationSession, boolean, buildArgsFromAssume, callAbsMethod, callFunction, callFunctionFull, canSkipLiteralCallScan, checkArg, checkCall, checkInjectedDomainEvidence, checkSource, classFromMethods, clearCollectionTables, cmp, coerceAsyncReturn, collectAbsFreeVars, collectAbsInlays, collectAbsNodeTypes, collectionElementJoin, collectionExactLen, concatString, constraintToEntryAbs, contractParamNameSet, createEnvironment, createTemplateAbs, currentPhi, decideEndsWith, decideIncludes, decideStartsWith, defaultLeakBudget, defineClass, definitelyNotNullishShape, denoteGuard, derivationChain, describePhi, div, effectiveInterface, emptyEnv, endCollectionFork, endDerivationSession, errorBrandAbs, evalArrayStatic, evalBuiltinInstanceMethod, evalBuiltinNew, evalDateCtor, evalDateMethod, evalDateStatic, evalGlobalFn, evalJsonMethod, evalMathMethod, evalMethodBody, evalNamespaceCall, evalNode, evalNumberStatic, evalObjectMethod, evalProgramAbs, evalPromiseCtor, evalPromiseStatic, evalRegExpCtor, evalRegExpMethod, evalSource, evictCheckSourceMemoForPaths, evictGeneralizeMemoForPaths, exceedsBudget, execNudoModule, extractAllLoadSpecs, extractFn, extractNudoImports, extractRefineReturnFromSource, extractRefinesFromSource, falseConstraint, findAbsAtPosition, fixedLengthOfViews, fn, fnConstraintToEntryReqs, fnFingerprints, fnOf, formalParamDisplayNames, formalParamsFromNodes, formatAbs, formatAbsMultiline, formatCheckReport, formatConstraint, formatDiagnostics, formatEffectiveInterfaceDisplay, formatInterfaceTierLine, formatShape, formatShapeSlot, formatTemplateNameViews, generalizeAll, generalizeFromAst, generalizeSourceKeyPart, generatedExportNames, getAbsProperty, getClass, getClassChain, getDerivation, getFnImpl, getFnNameAndBodies, getGeneralizeMemoSize, getParseSourceCacheSize, getSlot, getTerm, hasDerivationSession, hashSource, instanceOf, instantiateClass, instantiateConstraint, interfaceDiagCount, interfaceSourceOf, interfaceTierOf, isErrorCtorName, isIntFlag, isMapAbs, isNodeModulesPath, isNudoConstraint, isNullishLitAbs, isObj, isSetAbs, isTemplateLike, joinAbs, joinFunctions, joinObjects, joinThenProject, joinValues, knownPrefixOfViews, knownSuffixOfViews, leakIfNeeded, lenTerm, leqAbs, listFunctionNames, literalMeetsConstraint, loadModuleDepsFingerprint, localNamedExports, locateContractParam, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, looseEqAbs, makeMapAbs, makeSetAbs, makeSum, mapClearEntries, mapDeleteEntry, mapEntriesAbs, mapGetEntry, mapHasEntry, mapSetEntry, mapSizeAbs, mapValuesAbs, matchRelIdentLit, maybeLeak, mergeAdjacentFixedViews, mergeCollectionArms, mock, mod, mul, negAbs, normPath, notAbs, noteCollectionWrite, noteDerivationAdd, noteDerivationJoin, number, objOf, omit, parseSource, partial, pick, popCollectionArm, popPhi, projectBrand, projectDerivationDsl, pushCollectionArm, pushPhi, refineAbsForRelTrue, refineDiagCount, refineToIndexedFull, relationFingerprint, relationFn, requiredFnArity, resetAbsCallBudget, resetCheckSourceMemo, resetFnFpCache, resetGeneralizeMemo, resetHashSourceCache, resetLeakCounter, resetNudoModuleExecCache, resetParseSourceCache, resetPhi, resolveDepPath, serializeCheckJson, setAbsAssignCollector, setAbsCallCollector, setAbsNodeCollector, setAbsTruncationCollector, setAddEntry, setClearEntries, setDeleteEntry, setDerivation, setDerivationCollector, setElementsAbs, setHasEntry, setInterfaceDiagCollector, setRefineDiagCollector, setSizeAbs, shape, shapeOnlyFn, sidecarClosureFingerprint, sidecarPathOf, sidecarSpecsOf, spread, spy, stableAnalyzeKeySource, strictEqAbs, string, stripTypes, stub, sub, superNameOf, tagDerivationRoot, takeInterfaceDiags, takeInterfaceDiagsSince, takeRefineDiags, takeRefineDiagsSince, templateMatchesValue, templatePartsOf, termDepth, termKey, termNodes, trueConstraint, typeofAbs, union, viewTemplateParts, withPhiConstraint, withVar, wrapPromise };
|
package/dist/index.js
CHANGED
|
@@ -272,6 +272,7 @@ import {
|
|
|
272
272
|
registerBClass,
|
|
273
273
|
relationFingerprint,
|
|
274
274
|
relationFn,
|
|
275
|
+
requiredFnArity,
|
|
275
276
|
resetAbsCallBudget,
|
|
276
277
|
resetLeakCounter,
|
|
277
278
|
resetParseSourceCache,
|
|
@@ -337,7 +338,7 @@ import {
|
|
|
337
338
|
withExecPhi,
|
|
338
339
|
withVar,
|
|
339
340
|
wrapPromise
|
|
340
|
-
} from "./chunk-
|
|
341
|
+
} from "./chunk-6REHMIAE.js";
|
|
341
342
|
|
|
342
343
|
// src/environment.ts
|
|
343
344
|
function createEnvironment(parent, bindings = /* @__PURE__ */ new Map()) {
|
|
@@ -511,13 +512,39 @@ function formatShape(a) {
|
|
|
511
512
|
case "tuple":
|
|
512
513
|
return `[${s.elements.map(formatShape).join(", ")}]`;
|
|
513
514
|
case "fn": {
|
|
514
|
-
if (s.paramTypes && s.paramTypes.length > 0) {
|
|
515
|
-
const ps = s.paramTypes.map((p) => formatShapeSlot(p));
|
|
516
|
-
const ret2 = s.returnType !== void 0 ? formatShapeSlot(s.returnType) : "?";
|
|
517
|
-
return `(${ps.join(", ")}) => ${ret2}`;
|
|
518
|
-
}
|
|
519
515
|
const ret = s.returnType !== void 0 ? formatShapeSlot(s.returnType) : "?";
|
|
520
|
-
|
|
516
|
+
const labels = s.params ?? [];
|
|
517
|
+
const paramTypes = s.paramTypes;
|
|
518
|
+
const hasMarkers = labels.some(
|
|
519
|
+
(p) => p.startsWith("...") || p.endsWith("?")
|
|
520
|
+
);
|
|
521
|
+
const renderLabeled = () => {
|
|
522
|
+
const ps = [];
|
|
523
|
+
const n = paramTypes ? Math.max(paramTypes.length, labels.length) : labels.length;
|
|
524
|
+
for (let i = 0; i < n; i++) {
|
|
525
|
+
const label = labels[i];
|
|
526
|
+
const type = paramTypes?.[i];
|
|
527
|
+
const typeText = type !== void 0 ? formatShapeSlot(type) : void 0;
|
|
528
|
+
if (label?.startsWith("...")) {
|
|
529
|
+
ps.push(typeText ? `...${label.slice(3)}: ${typeText}` : label);
|
|
530
|
+
} else if (label?.endsWith("?")) {
|
|
531
|
+
ps.push(typeText ? `${label.slice(0, -1)}?: ${typeText}` : label);
|
|
532
|
+
} else if (typeText !== void 0) {
|
|
533
|
+
ps.push(typeText);
|
|
534
|
+
} else if (label) {
|
|
535
|
+
ps.push(label);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return ps;
|
|
539
|
+
};
|
|
540
|
+
if (hasMarkers) {
|
|
541
|
+
return `(${renderLabeled().join(", ")}) => ${ret}`;
|
|
542
|
+
}
|
|
543
|
+
if (paramTypes && paramTypes.length > 0) {
|
|
544
|
+
const ps = paramTypes.map((p) => formatShapeSlot(p));
|
|
545
|
+
return `(${ps.join(", ")}) => ${ret}`;
|
|
546
|
+
}
|
|
547
|
+
return `(${labels.join(", ")}) => ${ret}`;
|
|
521
548
|
}
|
|
522
549
|
case "brand":
|
|
523
550
|
return `${s.name}`;
|
|
@@ -639,20 +666,17 @@ function any() {
|
|
|
639
666
|
return makeBuilder(void 0, []);
|
|
640
667
|
}
|
|
641
668
|
function array(item) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
669
|
+
return makeBuilder(void 0, [], {
|
|
670
|
+
element: asNestedConstraint(item, "array(item)")
|
|
671
|
+
});
|
|
645
672
|
}
|
|
646
673
|
function shape(fields) {
|
|
647
674
|
const mapped = {};
|
|
648
675
|
for (const [k, v2] of Object.entries(fields)) {
|
|
649
|
-
|
|
650
|
-
throw new Error(
|
|
651
|
-
`nudo: shape \u5B57\u6BB5 '${k}' \u671F\u671B\u7EA6\u675F\u503C\uFF08number()/string()/\u2026\u6216\u5176\u7EC4\u5408\u5B50\uFF09\uFF0C\u6536\u5230\u975E\u7EA6\u675F`
|
|
652
|
-
);
|
|
676
|
+
const constraint = asNestedConstraint(v2, `shape \u5B57\u6BB5 '${k}'`);
|
|
653
677
|
mapped[k] = {
|
|
654
|
-
constraint
|
|
655
|
-
...
|
|
678
|
+
constraint,
|
|
679
|
+
...constraint.isOptional ? { optional: true } : {}
|
|
656
680
|
};
|
|
657
681
|
}
|
|
658
682
|
return makeBuilder(void 0, [], { fields: mapped });
|
|
@@ -677,19 +701,32 @@ function lit2(v2) {
|
|
|
677
701
|
const prim = typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : typeof v2 === "boolean" ? "boolean" : void 0;
|
|
678
702
|
return makeBuilder(prim, [eq(selfTerm(), lit(v2))]);
|
|
679
703
|
}
|
|
704
|
+
function asNestedConstraint(x, ctx) {
|
|
705
|
+
if (isConstraint(x)) return toPlainConstraint(x);
|
|
706
|
+
if (x === null || x === void 0 || typeof x === "number" || typeof x === "string" || typeof x === "boolean") {
|
|
707
|
+
return toPlainConstraint(lit2(x));
|
|
708
|
+
}
|
|
709
|
+
throw new Error(
|
|
710
|
+
`nudo: ${ctx} \u671F\u671B\u7EA6\u675F\u503C\uFF08number()/string()/\u2026\uFF09\u6216\u5177\u4F53\u5B57\u9762\u91CF\uFF0C\u6536\u5230\u975E\u7EA6\u675F`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
680
713
|
function union(...cs) {
|
|
681
714
|
if (cs.length === 0)
|
|
682
715
|
throw new Error("nudo union(): \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6210\u5458\u7EA6\u675F");
|
|
683
|
-
return makeBuilder(void 0, [], {
|
|
716
|
+
return makeBuilder(void 0, [], {
|
|
717
|
+
members: cs.map((c) => asNestedConstraint(c, "union \u6210\u5458"))
|
|
718
|
+
});
|
|
684
719
|
}
|
|
685
720
|
function fn(params, returns, opts) {
|
|
686
721
|
const normalized = {};
|
|
687
|
-
for (const [k, v2] of Object.entries(params))
|
|
722
|
+
for (const [k, v2] of Object.entries(params)) {
|
|
723
|
+
normalized[k] = asNestedConstraint(v2, `fn \u53C2\u6570 '${k}'`);
|
|
724
|
+
}
|
|
688
725
|
return makeBuilder(void 0, [], {
|
|
689
726
|
fn: {
|
|
690
727
|
params: normalized,
|
|
691
|
-
...returns !== void 0 ? { returns:
|
|
692
|
-
...opts?.throws !== void 0 ? { throws:
|
|
728
|
+
...returns !== void 0 ? { returns: asNestedConstraint(returns, "fn \u8FD4\u56DE\u503C") } : {},
|
|
729
|
+
...opts?.throws !== void 0 ? { throws: asNestedConstraint(opts.throws, "fn throws") } : {}
|
|
693
730
|
}
|
|
694
731
|
});
|
|
695
732
|
}
|
|
@@ -6695,6 +6732,7 @@ export {
|
|
|
6695
6732
|
registerBClass,
|
|
6696
6733
|
relationFingerprint,
|
|
6697
6734
|
relationFn,
|
|
6735
|
+
requiredFnArity,
|
|
6698
6736
|
resetAbsCallBudget,
|
|
6699
6737
|
resetCheckSourceMemo,
|
|
6700
6738
|
resetFnFpCache,
|