@sema-agent/settings-schema 31.1.0 → 33.0.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/CHANGELOG.md +917 -0
- package/README.md +103 -19
- package/conformance/VERSION +1 -1
- package/conformance/cases/c97-roles-own-proto-key-entry-dropped/expected.json +105 -0
- package/conformance/cases/c97-roles-own-proto-key-entry-dropped/input.json +26 -0
- package/conformance/cases/c97-roles-own-proto-key-entry-dropped/meta.json +6 -0
- package/dist/api/auth.d.ts +1 -1
- package/dist/api/feedback.d.ts +3 -3
- package/dist/api/feedback.js +3 -2
- package/dist/center-refs.d.ts +1 -1
- package/dist/center-refs.js +1 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.js +8 -3
- package/dist/config-dir-migration.d.ts +17 -1
- package/dist/config-dir-migration.js +89 -31
- package/dist/config-fns.d.ts +31 -4
- package/dist/config-fns.js +180 -24
- package/dist/config-root-documents.js +1 -1
- package/dist/conformance/contract-adapter.js +18 -1
- package/dist/conformance/warnings.d.ts +1 -1
- package/dist/conformance/warnings.js +8 -2
- package/dist/declared-capture.d.ts +1 -1
- package/dist/declared-capture.js +5 -1
- package/dist/device-lane-knobs.d.ts +57 -0
- package/dist/device-lane-knobs.js +127 -0
- package/dist/execution-lanes.d.ts +3 -1
- package/dist/execution-lanes.js +3 -1
- package/dist/fleet.d.ts +5 -5
- package/dist/fleet.js +4 -3
- package/dist/hooks-config.d.ts +47 -23
- package/dist/hooks-config.js +93 -134
- package/dist/hooks.d.ts +26 -22
- package/dist/hooks.js +17 -8
- package/dist/host-path.d.ts +9 -5
- package/dist/host-path.js +9 -20
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/ip-address.d.ts +19 -0
- package/dist/ip-address.js +28 -0
- package/dist/loopback.d.ts +3 -11
- package/dist/loopback.js +11 -12
- package/dist/mcp-request-entry.js +4 -6
- package/dist/migration-receipt.d.ts +1 -1
- package/dist/migration-receipt.js +1 -1
- package/dist/one-time-migrations.d.ts +1 -1
- package/dist/one-time-migrations.js +257 -62
- package/dist/plain-json-object.d.ts +5 -8
- package/dist/plain-json-object.js +5 -8
- package/dist/read-sentences.d.ts +66 -0
- package/dist/read-sentences.js +85 -0
- package/dist/record-seat.d.ts +35 -0
- package/dist/record-seat.js +97 -0
- package/dist/reserved-member-name.d.ts +8 -3
- package/dist/reserved-member-name.js +10 -3
- package/dist/retired-envs.js +10 -0
- package/dist/retired-form.d.ts +2 -0
- package/dist/retired-form.js +4 -0
- package/dist/safety-merge-spec.d.ts +11 -3
- package/dist/safety-merge-spec.js +3 -2
- package/dist/types.d.ts +405 -113
- package/dist/types.js +135 -76
- package/docs/API-SURFACE.md +25 -6
- package/docs/CC-DIVERGENCE.md +11 -2
- package/docs/CONFORMANCE.md +4 -4
- package/docs/CONSUMER-INTEGRATION.md +185 -6
- package/llms-full.txt +35 -20
- package/llms.txt +15 -8
- package/package.json +7 -6
package/dist/config-fns.js
CHANGED
|
@@ -20,10 +20,12 @@ import { MODEL_ENTRY_REFUSAL_CODES, ModelRefusalsWire } from "./fleet.js";
|
|
|
20
20
|
import { UNINSPECTABLE, dataDescriptor, emptyDocument, guardedSafeParse, inspect, isAccessorDescriptor, isolatedObject, ownEntriesOf, ownRow, ownValueOf } from "./own-key-read.js";
|
|
21
21
|
import { stableStringify } from "./hash.js";
|
|
22
22
|
import { ownEnabledFlag } from "./catalog-manages.js";
|
|
23
|
+
import { causeText, defaultedDomainSentence, droppedEntrySentence, identityText, issueSentence } from "./read-sentences.js"; // package-private: the one wording of the read-leg diagnostic sentences
|
|
23
24
|
import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object.js";
|
|
24
25
|
import { carriesUserinfo, secretScanForms } from "./secret-scan.js"; // package-private normalization (both scanners read it) + the userinfo judgement (not in the barrel)
|
|
25
26
|
import { sha256Hex } from "./sha256.js";
|
|
26
27
|
import { unwrapSchema } from "./zod-unwrap.js"; // package-private: the ONE reading of zod's wrapper layers (salvage + the one-time migrations share it)
|
|
28
|
+
import { RECORD_MEMBER_NAME } from "./record-seat.js"; // package-private: a Record key named by a reserved member name is refused — the same issue as the record seat's own guard
|
|
27
29
|
import { DOMAIN_SCHEMAS, InfraCostRates, LimitsConfig, PRIVATE_KEY_PEM_HEADER, RETIRED_DOMAINS, SkillsManifestSchema, WIRE_CARRIED_DOMAINS, containsSecretToken, isDomainName, isRetiredDomainName, renderQuotedSentence, retiredDomainSentence } from "./types.js";
|
|
28
30
|
import { deepFreeze } from "./deep-freeze.js";
|
|
29
31
|
/** Redact secret-shaped tokens from a validation MESSAGE — a zod error echoes the offending value (e.g.
|
|
@@ -331,6 +333,28 @@ export class RetiredDomainError extends Error {
|
|
|
331
333
|
this.name = "RetiredDomainError";
|
|
332
334
|
}
|
|
333
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* 一次**跨域读**(`buildEffective` / `readEffectiveWire` / `FileConfigStore` 的 `read()` 与 `getEffective()`)里,一个门控域({@link DOMAIN_READ_FALLBACK} 判 `"throw"`)
|
|
338
|
+
* 整域读不进 —— 读者要知道**是哪个域**、**判官为什么拒**:`domain` 是那个域;`cause` 是判官的原拒,原样(整份严判没过 = 脱敏后的 ZodError;校验途中读不出 =
|
|
339
|
+
* 一句中性 TypeError;逐条丢弃域里条目体内有被剥的键且救不活 = `unrecognized_keys` 的 ZodError)。`message` 点名域并接原拒的句子 —— 原拒已脱敏,这里不读任何
|
|
340
|
+
* 脱敏之前的东西;原拒的句子读不出 ⇒ 只留点名域的前半句。
|
|
341
|
+
* 铸点只有一处(视图面读的整域档位,{@link readViewOr})。单域读口(`parseDomain` / `parseDomainLoud` / `parseDomainSalvaged`)照抛原拒 —— 调用方自己点了域;
|
|
342
|
+
* 目录域整域读不进不抛:回落默认 + 一条 `domain-defaulted`,告警的 `error` 与这里的 `cause` 是同一只原拒的 `issues`(另一只对象:同类、同 `issues`,`message` 换成一句话),告警自带 `domain`。retired 域的墓碑拒是另一件事({@link RetiredDomainError})。
|
|
343
|
+
*/
|
|
344
|
+
export class DomainReadRefusedError extends Error {
|
|
345
|
+
domain;
|
|
346
|
+
constructor(domain, cause) {
|
|
347
|
+
super(domainReadRefusedSentence(domain, cause), { cause });
|
|
348
|
+
this.domain = domain;
|
|
349
|
+
this.name = "DomainReadRefusedError";
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/** {@link DomainReadRefusedError} 的句子:点名域 + 原拒的句子(原拒是本包铸的、已脱敏的错;读它的 `message` 在安全检视里 —— 读不出就只留前半句,不转述别的)。 */
|
|
353
|
+
function domainReadRefusedSentence(domain, cause) {
|
|
354
|
+
const head = `config domain "${domain}" could not be read`;
|
|
355
|
+
const said = inspect(() => (cause instanceof Error ? cause.message : undefined));
|
|
356
|
+
return said.ok && typeof said.value === "string" ? `${head}: ${said.value}` : head;
|
|
357
|
+
}
|
|
334
358
|
/** 一份retired 域文档**带不带事实**:缺席与 `{}` 不带(没有可丢的东西,读者不理会);其余一切(含 `null` / 非对象 / 有键的对象)都带 ⇒ 拒。 */
|
|
335
359
|
function carriesFacts(raw) {
|
|
336
360
|
if (raw === undefined)
|
|
@@ -456,8 +480,7 @@ export function isDisclosableIdentity(v) {
|
|
|
456
480
|
}
|
|
457
481
|
/** S-768 —— 「一个目录条目名能不能当 {@link ModelRefusalsWire} `entries` 的键」的**唯一**判据;引擎铸键前只调这一只,
|
|
458
482
|
* 不过 ⇒ 按无名处置(不进键、不计数)。两条律的合取,不手抄任何一条:
|
|
459
|
-
* ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(
|
|
460
|
-
* 载不住),不写名单;
|
|
483
|
+
* ① 这只 schema **自己载得住**这个键 —— 就地拿 schema 判(空串不过键规则;保留成员名让记录座位拒掉整只信号,载不住),不写名单;
|
|
461
484
|
* ② {@link isDisclosableIdentity}(不是白名单闭形里的标识符,或是秘密形 ⇒ 不出门)。
|
|
462
485
|
* 非字符串 ⇒ false。住在本文件而不是 `./fleet`:`fleet.ts` 被 `types.ts` 引,它再引本文件会成环。 */
|
|
463
486
|
export function isReportableRefusalName(name) {
|
|
@@ -479,7 +502,8 @@ export function withheldNameToken(name) {
|
|
|
479
502
|
}
|
|
480
503
|
/** 一条被丢条目原文的身份({@link DroppedEntryIdentity} 的**唯一**读法)。只看纯 JSON 对象的**自有数据
|
|
481
504
|
* 属性**;任何反射/陷阱抛错 ⇒ 当作读不出(身份是诊断面的附件,绝不许把抢救拖下水)。`enabled` 读的是「显式停用」的那一只
|
|
482
|
-
* ({@link ownEnabledFlag},`./catalog-manages`):目录管不管模型面的原文判官与这里同一份读法。
|
|
505
|
+
* ({@link ownEnabledFlag},`./catalog-manages`):目录管不管模型面的原文判官与这里同一份读法。
|
|
506
|
+
* 包内私有:公开的读口是按坐标读的 {@link readEntryIdentityAt}。 */
|
|
483
507
|
function readEntryIdentity(entry) {
|
|
484
508
|
try {
|
|
485
509
|
if (!isPlainJsonObject(entry))
|
|
@@ -502,6 +526,28 @@ function readEntryIdentity(entry) {
|
|
|
502
526
|
return undefined;
|
|
503
527
|
}
|
|
504
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* 一个坐标落进的那一条**条目**的身份(只带可披露的名与 id,见 {@link DroppedEntryIdentity}):坐标形如 `[<集合字段>, <下标>, …]` 且文档里那一处是数组里的一个条目 ⇒ 读它的身份;
|
|
531
|
+
* 否则(域级的键、整份文档、Record 里的值)⇒ `undefined`。条目身份的读法只有 {@link readEntryIdentity} 一只:`entry-dropped` 的身份由抢救记账时对那一条原文调它;
|
|
532
|
+
* 按坐标找到那一条再调它的,是这一只 —— `domain-defaulted`(抢救账里没有那一条时)与命令行报告的 `refused[]` 说「是哪一条」读它。坐标只给下标,
|
|
533
|
+
* 消费方自己渲染诊断、要点名一条条目时调它(`doc` 是坐标所指的那份文档的原文,`path` 是 {@link ConfigPath}),不另写一份读名字的代码。读文档只走内核的自有成员读;
|
|
534
|
+
* 读不出(含 `path` 不是数组、读它就抛)⇒ `undefined`,从不抛。
|
|
535
|
+
*/
|
|
536
|
+
export function readEntryIdentityAt(doc, path) {
|
|
537
|
+
const read = inspect(() => {
|
|
538
|
+
if (!isJsonArray(path))
|
|
539
|
+
return undefined;
|
|
540
|
+
const [field, index] = path;
|
|
541
|
+
if (typeof field !== "string" || typeof index !== "number" || !isPlainJsonObject(doc))
|
|
542
|
+
return undefined;
|
|
543
|
+
const collection = ownValueOf(doc, field);
|
|
544
|
+
if (!collection.ok || !isJsonArray(collection.value))
|
|
545
|
+
return undefined;
|
|
546
|
+
const entry = ownValueOf(collection.value, String(index));
|
|
547
|
+
return entry.ok ? readEntryIdentity(entry.value) : undefined;
|
|
548
|
+
});
|
|
549
|
+
return read.ok ? read.value : undefined;
|
|
550
|
+
}
|
|
505
551
|
/** 一条记账行 → 它的 `entry-dropped` 告警。域面({@link buildEffective})与 wire 面(skills manifest)共用
|
|
506
552
|
* 这**一只** —— 告警形只在这里拼,新字段不会在一条腿上漏铸。 */
|
|
507
553
|
function entryDroppedWarning(domain, d) {
|
|
@@ -509,11 +555,47 @@ function entryDroppedWarning(domain, d) {
|
|
|
509
555
|
domain,
|
|
510
556
|
kind: "entry-dropped",
|
|
511
557
|
path: d.path,
|
|
512
|
-
error: d
|
|
558
|
+
error: droppedEntryError(domain, d),
|
|
513
559
|
...(d.reasonCode === undefined ? {} : { reasonCode: d.reasonCode }),
|
|
514
560
|
...(d.identity === undefined ? {} : { identity: d.identity }),
|
|
515
561
|
};
|
|
516
562
|
}
|
|
563
|
+
/** 一条 issue 清单的**每条一句话**(坐标出门形的串 + 句子):`ZodError` 逐条 issue 读(联合取各选项的句子),别的错只有它的 `message`。读不出 ⇒ 空清单(诊断是旁路,不许把读拖下水)。 */
|
|
564
|
+
function pathedSentencesOf(error) {
|
|
565
|
+
const read = inspect(() => {
|
|
566
|
+
if (error instanceof z.ZodError)
|
|
567
|
+
return error.issues.map((i) => ({ path: formatConfigPath(i.path), sentence: issueSentence(i) }));
|
|
568
|
+
if (error instanceof Error)
|
|
569
|
+
return [{ path: "", sentence: issueSentence({ message: error.message }) }];
|
|
570
|
+
return [];
|
|
571
|
+
});
|
|
572
|
+
return read.ok ? read.value : [];
|
|
573
|
+
}
|
|
574
|
+
/** 给一只原拒换上**一句话**的 `message`(单行):`ZodError` ⇒ 同一份 `issues` 的新 `ZodError`(原对象不动 —— 它还在别处用:域读拒的 `cause`、公开的 {@link salvageEntries} 结果),
|
|
575
|
+
* `TypeError` ⇒ 一只新的 `TypeError`;别的错不认识 ⇒ 原样交回。铸不出 ⇒ 原样交回(旁路)。
|
|
576
|
+
* 新铸的 `ZodError` 是 zod 解析失败时交出的那一种(`ZodRealError`:`Error` 的实例、带 `stack`)—— 与原拒同读:按 `instanceof Error` 分流的读者读到的仍是一只错;
|
|
577
|
+
* `ZodError` 这只构造器本身铸的不是 `Error`。
|
|
578
|
+
* 句子出门前过本包唯一的脱敏器({@link redactSecrets}):句子里回显的串(键名、坐标、别人的句子)在铸句时已折成一行、剥掉一行回显的剥除集 ——
|
|
579
|
+
* 剥掉一个隔开的字符可以把两段拼成一个密钥形(`g<U+202E>hp_…` ⇒ `ghp_…`),所以脱敏判在剥之后、对最终的那一串再做一次。 */
|
|
580
|
+
function withSentence(error, sentence) {
|
|
581
|
+
const minted = inspect(() => {
|
|
582
|
+
const outgoing = redactSecrets(sentence);
|
|
583
|
+
if (error instanceof z.ZodError) {
|
|
584
|
+
const sentenced = new z.ZodRealError(error.issues);
|
|
585
|
+
sentenced.message = outgoing;
|
|
586
|
+
if (typeof Error.captureStackTrace === "function")
|
|
587
|
+
Error.captureStackTrace(sentenced, withSentence); // zod 铸错时不采栈(解析口事后补上);这里同样补上,栈头是这一句
|
|
588
|
+
return sentenced;
|
|
589
|
+
}
|
|
590
|
+
return error instanceof TypeError ? new TypeError(outgoing) : error;
|
|
591
|
+
});
|
|
592
|
+
return minted.ok ? minted.value : error;
|
|
593
|
+
}
|
|
594
|
+
/** `entry-dropped` 告警的 `error`:原拒的 `issues` 不动,`message` 是一句话 —— 哪一条、是谁、为什么、其余照常、手改回来({@link droppedEntrySentence})。 */
|
|
595
|
+
function droppedEntryError(domain, d) {
|
|
596
|
+
const sentence = inspect(() => droppedEntrySentence({ domain, entry: `entry ${formatConfigPath(d.path)}`, identity: identityText(d.identity), cause: causeText(pathedSentencesOf(d.error)) }));
|
|
597
|
+
return sentence.ok ? withSentence(d.error, sentence.value) : d.error;
|
|
598
|
+
}
|
|
517
599
|
/** 一条被丢条目的记账行 —— `salvageEntries` 两种集合形(数组 / Record)共用的**唯一**铸点。词随判决来({@link EntryVerdict}),
|
|
518
600
|
* 不在这里另行推断:判的那一刻才知道是哪种丢法。 */
|
|
519
601
|
function droppedEntry(path, verdict, entry) {
|
|
@@ -538,10 +620,15 @@ function judgeAgainst(schema, value, rejectedAs) {
|
|
|
538
620
|
return { ok: false, verdict: unreadableEntryVerdict() };
|
|
539
621
|
return judged.value.success ? { ok: true, value: judged.value.data } : { ok: false, verdict: { error: judged.value.error, reasonCode: rejectedAs } };
|
|
540
622
|
}
|
|
541
|
-
/** Record 的一个键的判决(键先判:键坏的条目不再算值,也不下钻)
|
|
623
|
+
/** Record 的一个键的判决(键先判:键坏的条目不再算值,也不下钻)。先问成员名律({@link RECORD_MEMBER_NAME}:名叫保留成员名 ⇒ 坏键 —— 与记录座位的守卫同一条 issue,
|
|
624
|
+
* 座位整份拒的那一格在这里就是这一格丢;键 schema 宽的集合不会把它放过去、再让整份重判拒掉),再问记录自己的键 schema。 */
|
|
542
625
|
function judgeKey(keySchema, key) {
|
|
543
|
-
const
|
|
544
|
-
|
|
626
|
+
for (const schema of [RECORD_MEMBER_NAME, keySchema]) {
|
|
627
|
+
const judged = judgeAgainst(schema, key, "entry-key-invalid");
|
|
628
|
+
if (!judged.ok)
|
|
629
|
+
return judged.verdict;
|
|
630
|
+
}
|
|
631
|
+
return undefined;
|
|
545
632
|
}
|
|
546
633
|
/** 一条条目(数组元素 / Record 值)的判决 —— **条目好 ⇔ 它过自己的 schema,且体内没有键被剥**(22.0.0;一条判据,不分域、不分键)。
|
|
547
634
|
* 被剥的键 = 原文有、schema 读数里没有的键({@link strippedKeysUnder}:对象逐键、数组同长逐下标,不读 zod 内省),{@link EXTENSION_NAMESPACES}
|
|
@@ -616,15 +703,25 @@ function judgeEntry(element, entry, domain, from) {
|
|
|
616
703
|
export function salvageEntries(schema, raw, domain) {
|
|
617
704
|
if (!isDomainName(domain))
|
|
618
705
|
throw new TypeError(`salvageEntries: "${outgoingSegment(String(domain))}" is not a config domain (the third argument names whose extension namespaces apply)`);
|
|
706
|
+
const { raw: salvaged, dropped, keptIndex } = salvageLedger(schema, raw, domain);
|
|
707
|
+
return { raw: salvaged, dropped, keptIndex };
|
|
708
|
+
}
|
|
709
|
+
/** 整域读不进时第一次判留下的抢救账,按它抛出去的那只原拒挂着(包内私有的旁路:公开读口抛的仍是原拒、对象与形都不变)。读腿告警 `domain-defaulted` 说「触发的是哪一条」读它,
|
|
710
|
+
* 不把文档再抢救一遍(有状态的 getter 下两遍读到的可以不是同一份)。范围照实:触发的条目在这本账里(条目本身坏)⇒ 身份与原因词都取账上的,不再读文档;
|
|
711
|
+
* 账里没有它(重名、悬空引用这类域级跨行规则把整域拒了)⇒ 身份按坐标回原文读那一条({@link readEntryIdentityAt}),集合字段多读一次。WeakMap:原拒没人留着,账随它一起走。 */
|
|
712
|
+
const LEDGER_OF_REFUSAL = new WeakMap();
|
|
713
|
+
/** 抢救的**完整账**(包内私有):{@link salvageEntries} 的结果,外加 `lost` = 「一个集合里条目全坏、所以一条没丢」的那些条目的记账行(零幸存者律:不凭空造出空集合)。
|
|
714
|
+
* 整域因此读不进时,它们就是病因 —— 读腿告警 `domain-defaulted` 点名其中的身份与原因词读的是这一份;公开的 {@link salvageEntries} 不带它(结果形不变)。 */
|
|
715
|
+
function salvageLedger(schema, raw, domain) {
|
|
619
716
|
const layer = salvageLayer(schema, raw, domain, []);
|
|
620
|
-
return { raw: layer.raw, dropped: layer.dropped, keptIndex: keptIndexOf(layer.shifts) };
|
|
717
|
+
return { raw: layer.raw, dropped: layer.dropped, keptIndex: keptIndexOf(layer.shifts), lost: layer.lost };
|
|
621
718
|
}
|
|
622
719
|
/** 一层抢救,抢不动就当没抢救(反射 / 访问器抛错:绝不外泄其文案)。最外层与每一条条目体内走的是**同一只** —— 一条条目体内抢不动,
|
|
623
720
|
* 只是这一条不下钻、照原样去判,不连坐它所在的那一层。`origin` = 本层文档在域文档里的**原文**坐标(未脱敏、原下标;最外层 `[]`)——
|
|
624
721
|
* 扩展命名空间按运维写下的段判,出门坐标(脱敏)另由 `outgoingPath` 铸。 */
|
|
625
722
|
function salvageLayer(schema, raw, domain, origin) {
|
|
626
723
|
const layer = inspect(() => salvageLayerUnsafe(schema, raw, domain, origin));
|
|
627
|
-
return layer.ok ? layer.value : { raw, dropped: [], shifts: [] };
|
|
724
|
+
return layer.ok ? layer.value : { raw, dropped: [], shifts: [], lost: [] };
|
|
628
725
|
}
|
|
629
726
|
/** 「哪些字段是一组条目」的**唯一**派生(逐条抢救 {@link salvageLayerUnsafe} 与视图面判官 {@link entryHeldStrippedKeys} 同读这一只):
|
|
630
727
|
* 根(拆掉包装层后)是对象 ⇒ 它的每个元素是条目({@link isEntrySchema})的数组 / Record 字段。元素不是条目的集合(值名单、凭据引用)是一个值,
|
|
@@ -667,10 +764,11 @@ function collectionSlots(value, isArray) {
|
|
|
667
764
|
return isPlainJsonObject(value) ? Object.entries(value) : undefined;
|
|
668
765
|
}
|
|
669
766
|
function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
670
|
-
const untouched = { raw, dropped: [], shifts: [] };
|
|
767
|
+
const untouched = { raw, dropped: [], shifts: [], lost: [] };
|
|
671
768
|
if (!isPlainJsonObject(raw))
|
|
672
769
|
return untouched;
|
|
673
770
|
const dropped = [];
|
|
771
|
+
const lost = [];
|
|
674
772
|
const shifts = [];
|
|
675
773
|
const patch = {};
|
|
676
774
|
for (const { field, isArray, element, keySchema } of entryCollectionsOf(schema)) {
|
|
@@ -708,6 +806,8 @@ function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
|
708
806
|
innerShifts.push({ at: [...at, ...s.at], kept: s.kept });
|
|
709
807
|
}
|
|
710
808
|
// 零幸存者 ⇒ 没有要抢救的东西(见头注:绝不凭空造出一个空集合);什么都没上账 ⇒ 这个字段原样不动。
|
|
809
|
+
if (survivors.length === 0)
|
|
810
|
+
lost.push(...found); // 全坏的集合:一条不丢(不改 raw),但这些条目就是整域读不进的病因,记在 `lost` 里
|
|
711
811
|
if (survivors.length === 0 || found.length === 0)
|
|
712
812
|
continue;
|
|
713
813
|
dropped.push(...found);
|
|
@@ -719,8 +819,8 @@ function salvageLayerUnsafe(schema, raw, domain, origin) {
|
|
|
719
819
|
shifts.push(...innerShifts);
|
|
720
820
|
}
|
|
721
821
|
if (dropped.length === 0)
|
|
722
|
-
return untouched;
|
|
723
|
-
return { raw: { ...raw, ...patch }, dropped, shifts };
|
|
822
|
+
return lost.length === 0 ? untouched : { raw, dropped: [], shifts: [], lost };
|
|
823
|
+
return { raw: { ...raw, ...patch }, dropped, shifts, lost };
|
|
724
824
|
}
|
|
725
825
|
/** 段坐标记的位移账 → {@link EntryKeptIndex}(键 = 全路径的出门串)。同一个键出现两次只可能是两只被打码成同一串的 Record 键
|
|
726
826
|
* (坐标本身已分不清是谁)⇒ 那个键不登记。什么都没压缩 ⇒ 冻结的共享空表。 */
|
|
@@ -820,6 +920,7 @@ export function projectWarning(w) {
|
|
|
820
920
|
* 说的就是这件事。{@link salvageEntries} 铸 `entry-dropped` 时用的是它**入参**那份文档的坐标;若那份文档本身被外层
|
|
821
921
|
* 压缩过,外层照样要回写它一次。今天读路径上只有一个压缩点(11.0.0 起 hosts 的读侧夹紧臂已retired),所以这一臂当下
|
|
822
922
|
* 只对 `keptIndex` 为空的表恒等;把「不动」写成一条臂的性质,就是把「哪一层」这件事错记在了「哪个 kind」上。
|
|
923
|
+
* `domain-defaulted` 的可缺坐标 `path`(33.0.0)同理:在场就回写,缺席就原样。
|
|
823
924
|
*
|
|
824
925
|
* **恒等纪律**:没有任何一条路径真的变了(含 `keptIndex` 为空)⇒ 返回**同一个对象引用**,连 `keys`
|
|
825
926
|
* 数组也不复制(好数据穿过读路径 byte 不变)。
|
|
@@ -839,8 +940,14 @@ export function rebaseWarningPaths(w, keptIndex) {
|
|
|
839
940
|
const path = rebasePath(w.path, keptIndex);
|
|
840
941
|
return path === w.path ? w : { ...w, path };
|
|
841
942
|
}
|
|
842
|
-
//
|
|
843
|
-
case "domain-defaulted":
|
|
943
|
+
// 33.0.0 起 `domain-defaulted` 可带一只坐标(`path`,触发的那一处):与 `entry-dropped` 同一条律 —— 铸它那一层用的是它入参那份文档的坐标,外层压缩过就回写一次。
|
|
944
|
+
case "domain-defaulted": {
|
|
945
|
+
if (w.path === undefined)
|
|
946
|
+
return w;
|
|
947
|
+
const path = rebasePath(w.path, keptIndex);
|
|
948
|
+
return path === w.path ? w : { ...w, path };
|
|
949
|
+
}
|
|
950
|
+
// 这一臂不带任何坐标:点名的是文件名。
|
|
844
951
|
case "unread-config-file":
|
|
845
952
|
return w;
|
|
846
953
|
default: {
|
|
@@ -1231,21 +1338,63 @@ const SKILLS_MANIFEST_SEAT = { domain: "skills", schema: SkillsManifestSchema };
|
|
|
1231
1338
|
function readView(seat, raw, onWarning) {
|
|
1232
1339
|
return readDomainDocument(seat.domain, raw, onWarning, (doc) => parseForView(seat, doc), (unreadable) => parseSalvaged(seat, raw, unreadable, onWarning));
|
|
1233
1340
|
}
|
|
1341
|
+
/** `a` 是不是 `prefix` 的延伸(逐段相等;空前缀不算 —— 没有坐标就没有条目)。 */
|
|
1342
|
+
const startsWithPath = (path, prefix) => prefix.length > 0 && prefix.length <= path.length && prefix.every((seg, i) => path[i] === seg);
|
|
1234
1343
|
/**
|
|
1235
|
-
*
|
|
1344
|
+
* 读腿整域读不进、按缺省读时的告警(`domain-defaulted`;唯一铸点,{@link readViewOr} 调它):`error` = 原拒换上一句话的 `message`(整域按缺省读 · 为什么 · 触发的条目是谁 · 在这份文档里手改);
|
|
1345
|
+
* 三个可缺的键说出**触发的是谁** —— `path` = 原拒第一条 issue 的坐标;`identity` = 坐标落进的那一条条目的身份(条目本身没坏、只是域级的跨行规则 —— 重名、悬空引用 —— 把整域拒了,也有);
|
|
1346
|
+
* `reasonCode` = 那一条条目为什么坏(只有条目本身坏才有;域级的毛病没有)。
|
|
1347
|
+
* 条目为什么坏读第一次判留下的抢救账({@link salvageLedger},随原拒带来:丢掉的条目,与零幸存者的集合里那些一条没丢的条目)—— 不把文档再抢救一遍;
|
|
1348
|
+
* 身份先取账上那一行的(条目本身坏 ⇒ 不再读文档),账里没有那一条(域级跨行规则)才按坐标回原文读那一条({@link readEntryIdentityAt},与命令行 `refused[]` 同一只;集合字段多读一次)。
|
|
1349
|
+
* 诊断是旁路 —— 任何一步读不出 ⇒ 少几个键、`error` 原样,从不把读拖下水。
|
|
1350
|
+
*/
|
|
1351
|
+
function domainDefaultedWarning(seat, raw, refusal) {
|
|
1352
|
+
const issues = pathedSentencesOf(refusal);
|
|
1353
|
+
const first = inspect(() => (refusal instanceof z.ZodError ? refusal.issues[0]?.path : undefined));
|
|
1354
|
+
const path = first.ok && first.value !== undefined && first.value.length > 0 ? first.value : undefined;
|
|
1355
|
+
const held = inspect(() => (refusal instanceof Error ? LEDGER_OF_REFUSAL.get(refusal) : undefined));
|
|
1356
|
+
const ledger = held.ok ? held.value : undefined;
|
|
1357
|
+
const culprit = path === undefined || ledger === undefined ? undefined : [...ledger.lost, ...ledger.dropped].find((c) => startsWithPath(path, c.path));
|
|
1358
|
+
const identity = culprit?.identity ?? (path === undefined ? undefined : readEntryIdentityAt(raw, path));
|
|
1359
|
+
const entryPath = culprit?.path ?? (path !== undefined && typeof path[1] === "number" ? path.slice(0, 2) : undefined);
|
|
1360
|
+
const entry = entryPath === undefined || (culprit === undefined && identity === undefined) ? undefined : `entry ${formatConfigPath(entryPath)}`;
|
|
1361
|
+
const who = identityText(identity);
|
|
1362
|
+
const sentence = inspect(() => defaultedDomainSentence({ domain: seat.domain, cause: causeText(issues), culprit: entry === undefined ? undefined : who === undefined ? entry : `${entry}: ${who}` }));
|
|
1363
|
+
return {
|
|
1364
|
+
domain: seat.domain,
|
|
1365
|
+
kind: "domain-defaulted",
|
|
1366
|
+
error: sentence.ok ? withSentence(refusal, sentence.value) : refusal,
|
|
1367
|
+
...(path === undefined ? {} : { path }),
|
|
1368
|
+
...(identity === undefined ? {} : { identity }),
|
|
1369
|
+
...(culprit?.reasonCode === undefined ? {} : { reasonCode: culprit.reasonCode }),
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* 视图面读一份文档,**读不进时按 {@link DOMAIN_READ_FALLBACK} 答**:`"throw"` ⇒ 抛 {@link DomainReadRefusedError}(`domain` = 这个域,`cause` = 判官的原拒);
|
|
1374
|
+
* `"default"` ⇒ schema 默认 + 一条 `domain-defaulted`(`error` = 原拒的同类、同 `issues`,`message` 换成一句话,见 {@link domainDefaultedWarning})。这里是那只错的唯一铸点。
|
|
1236
1375
|
* `buildEffective` 的每个域与 `readEffectiveWire` 的 skills 清单都经这一只 —— 两张表各问一次,同一个域在每条读腿上同一个答案(24.0.0 前清单是单列一臂,
|
|
1237
1376
|
* 恒逐条抢救、恒默认化,不读这两张表)。好文档的路径一字不动。
|
|
1377
|
+
*
|
|
1378
|
+
* 「读不进」只问判官:读这一份文档时发的告警先收在本地,判完、在 `try` 之外按原序交给 `onWarning` —— 消费方回调自己抛的错原样穿出,不包成域读拒、
|
|
1379
|
+
* 不把一份读得进的文档默认化(此前回调的错也被这里接住:门控域原样再抛,目录域被读成整域读不进)。没读进的文档不交半路的告警(一个域一个结论)。
|
|
1238
1380
|
*/
|
|
1239
1381
|
function readViewOr(seat, raw, onWarning) {
|
|
1382
|
+
const held = [];
|
|
1383
|
+
let read;
|
|
1240
1384
|
try {
|
|
1241
|
-
|
|
1385
|
+
read = readView(seat, raw, onWarning === undefined ? undefined : (w) => void held.push(w));
|
|
1242
1386
|
}
|
|
1243
|
-
catch (
|
|
1387
|
+
catch (refusal) {
|
|
1244
1388
|
if (DOMAIN_READ_FALLBACK[seat.domain] === "throw")
|
|
1245
|
-
throw
|
|
1246
|
-
onWarning
|
|
1389
|
+
throw new DomainReadRefusedError(seat.domain, refusal);
|
|
1390
|
+
if (onWarning !== undefined)
|
|
1391
|
+
onWarning(domainDefaultedWarning(seat, raw, refusal));
|
|
1247
1392
|
return strictParse(seat.schema, seat.domain, emptyDocument()); // schema default — always valid
|
|
1248
1393
|
}
|
|
1394
|
+
if (onWarning !== undefined)
|
|
1395
|
+
for (const w of held)
|
|
1396
|
+
onWarning(w);
|
|
1397
|
+
return read;
|
|
1249
1398
|
}
|
|
1250
1399
|
/**
|
|
1251
1400
|
* 视图面的**整份判官**(22.0.0):整份严判(缺席 —— 只有 `undefined` —— 按空文档判,与 {@link parseDomain} 同一条),外加 —— 在逐条丢弃域
|
|
@@ -1300,16 +1449,23 @@ function parseSalvaged(seat, raw, unreadable, onWarning) {
|
|
|
1300
1449
|
* 抛 `unreadable`(第一次严判的原错)—— 一个文档一个结论,没救活就不留「丢了某条」的半路叙述。`domain` = 哪个域的扩展命名空间生效(见 {@link salvageEntries})。
|
|
1301
1450
|
*/
|
|
1302
1451
|
function salvageThenParse(schema, domain, raw, parse, unreadable) {
|
|
1303
|
-
const salvage =
|
|
1452
|
+
const salvage = salvageLedger(schema, raw, domain);
|
|
1304
1453
|
if (salvage.dropped.length === 0)
|
|
1305
|
-
|
|
1454
|
+
return refuseWithLedger(unreadable, salvage);
|
|
1306
1455
|
try {
|
|
1307
1456
|
return { parsed: parse(salvage.raw), salvage };
|
|
1308
1457
|
}
|
|
1309
1458
|
catch {
|
|
1310
|
-
|
|
1459
|
+
return refuseWithLedger(unreadable, salvage);
|
|
1311
1460
|
}
|
|
1312
1461
|
}
|
|
1462
|
+
/** 抛 `unreadable`(第一次严判的原错),抛之前把抢救账挂在它身上(原拒不是 `Error` ⇒ 只抛、不挂:本包铸的原拒都是 `Error`)。 */
|
|
1463
|
+
function refuseWithLedger(unreadable, ledger) {
|
|
1464
|
+
const isError = inspect(() => unreadable instanceof Error);
|
|
1465
|
+
if (isError.ok && isError.value && unreadable instanceof Error)
|
|
1466
|
+
LEDGER_OF_REFUSAL.set(unreadable, ledger);
|
|
1467
|
+
throw unreadable;
|
|
1468
|
+
}
|
|
1313
1469
|
/** 未知键两条告警(剥掉的 / 承运的)—— `raw` 是这次真被 parse 的那份文档,`emit` 决定坐标出门前要不要回写。 */
|
|
1314
1470
|
function announceUnknownKeys(domain, raw, parsed, emit) {
|
|
1315
1471
|
const dropped = droppedKeys(domain, raw, parsed);
|
|
@@ -1473,7 +1629,7 @@ export function buildEffective(version, getRaw, updatedAt, onWarning) {
|
|
|
1473
1629
|
refuseRetiredDomain(retired, getRaw(retired));
|
|
1474
1630
|
// 每个域同一只读法(12.3.0 起;24.0.0 起 wire 上的 skills 清单也是这一只):{@link readViewOr} —— 视图面读(整域 parse → 按 DOMAIN_ENTRY_SALVAGE
|
|
1475
1631
|
// 逐条抢救 → 未知键告警)读不进 ⇒ 只剩**整域读不进**这一个问题,答案只看 DOMAIN_READ_FALLBACK(决策表与逐域理由见那张表):
|
|
1476
|
-
// `"throw"` ⇒
|
|
1632
|
+
// `"throw"` ⇒ 抛 DomainReadRefusedError(点名域,原拒在 `cause`);`"default"` ⇒ schema 默认 + `domain-defaulted`。哪个域走哪一档不写在下面的行上,行只说「读这个域」。
|
|
1477
1633
|
// 好配置的路径一字不动(同一次严判,同一份字节)。
|
|
1478
1634
|
const parseOr = (domain, raw) => readViewOr(domainSeat(domain), raw, onWarning);
|
|
1479
1635
|
return {
|
|
@@ -1508,7 +1664,7 @@ export function buildEffective(version, getRaw, updatedAt, onWarning) {
|
|
|
1508
1664
|
* type-asserting it(0.12.0,[2281] 裁B:「两个契约共用一个拼写不是一个被检查的契约」——拼写副本要在
|
|
1509
1665
|
* 消费端被真校验)。ONE judgment, two legs: every known domain goes through the SAME `parseDomain` +
|
|
1510
1666
|
* {@link DOMAIN_READ_FALLBACK} policy as {@link buildEffective}(catalog 域坏形 → schema default + warning;
|
|
1511
|
-
* gate 域坏形 → throw,caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
|
|
1667
|
+
* gate 域坏形 → throw {@link DomainReadRefusedError}(点名域,原拒在 `cause`),caller 的整包 catch 决定回落),including the retired-domain tombstone — DELEGATED to
|
|
1512
1668
|
* buildEffective, not re-implemented(单判据双腿消费,§M4)。A retired domain on the wire (an older web-admin still
|
|
1513
1669
|
* ships `runtime`) is judged by the same tombstone: carrying facts ⇒ {@link RetiredDomainError}; `{}` (what an older
|
|
1514
1670
|
* web-admin materialises for an unset domain) carries nothing and is dropped from the result — it never rides through as
|
|
@@ -47,7 +47,7 @@ const digestOf = (bytes) => toHex(sha256Digest(bytes)).slice(0, 16);
|
|
|
47
47
|
const textOf = (bytes) => new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
48
48
|
/**
|
|
49
49
|
* 一个 JSON 值若是「恰好这一个自有键」的纯对象 ⇒ 那个键的值;否则(多一个键 —— 含 `JSON.parse` 铸出的自有 `__proto__` 键 —— 少一个键、不是纯对象)⇒ `undefined`。
|
|
50
|
-
* 两份文档的形都是 strict 的,判在这里一处;不交给 zod 的 strict:它对自有 `__proto__` 键的处置随版本变(4.4.x 跳过它、4.6.x
|
|
50
|
+
* 两份文档的形都是 strict 的,判在这里一处;不交给 zod 的 strict:它对自有 `__proto__` 键的处置随版本变(4.4.x 跳过它、4.6.x 拒它;32.0.0 起声明的区间已不含 4.4.x,判仍在这里一处,不依赖 zod 的处置)。
|
|
51
51
|
* 文档是 `JSON.parse` 的产物,自有键都是可枚举数据属性,`Object.keys` 就是它的全部键。
|
|
52
52
|
*/
|
|
53
53
|
function soleOwnValue(v, key) {
|
|
@@ -54,11 +54,28 @@ const isZodLike = (e) => {
|
|
|
54
54
|
/** 内容哈希那一层拒绝的自述 —— `stableStringify` 的深度闸是**本包自己**抛的、也只有它会抛这一句;
|
|
55
55
|
* 适配器给自家流水线分层,认得自家那句话是合理的(消费方的适配器认它自己那几层的错)。 */
|
|
56
56
|
const HASH_STAGE_MARK = "stableStringify:";
|
|
57
|
+
/** 分层看的是**判官的原拒**:跨域读口的域读拒(`DomainReadRefusedError`,32.0.0 起)把原拒放在 `cause` —— 鸭子判它的 `name`(不用 `instanceof`:historical 模式下旧版 dist
|
|
58
|
+
* 是另一份类;旧版直接抛原拒,读到的就是它自己)。两次成员读都经检视内核;读不出 ⇒ 按抛出物本身分层。 */
|
|
59
|
+
const judgedRefusalOf = (e) => {
|
|
60
|
+
const name = inspect(() => e.name);
|
|
61
|
+
if (!name.ok || name.value !== "DomainReadRefusedError")
|
|
62
|
+
return e;
|
|
63
|
+
const cause = inspect(() => e.cause);
|
|
64
|
+
return cause.ok ? cause.value : e;
|
|
65
|
+
};
|
|
57
66
|
const reject = (e, fallback) => {
|
|
58
67
|
const diagnostics = e instanceof Error ? e.message : String(e);
|
|
59
|
-
const
|
|
68
|
+
const judged = judgedRefusalOf(e);
|
|
69
|
+
// 抛出物本身就是原拒 ⇒ 用上面那一句(不再问第二次原型);原拒在 `cause` ⇒ 读它的句子经检视内核,读不出就当没有句子(落这条腿的缺省层)
|
|
70
|
+
const judgedText = judged === e ? diagnostics : textOf(judged);
|
|
71
|
+
const stage = isZodLike(judged) ? "validate" : judgedText.startsWith(HASH_STAGE_MARK) ? "hash" : fallback;
|
|
60
72
|
return { outcome: "rejected", stage, diagnostics };
|
|
61
73
|
};
|
|
74
|
+
/** 原拒的句子(只用来认 {@link HASH_STAGE_MARK});读不出 ⇒ 空串。 */
|
|
75
|
+
const textOf = (v) => {
|
|
76
|
+
const read = inspect(() => (v instanceof Error ? v.message : String(v)));
|
|
77
|
+
return read.ok && typeof read.value === "string" ? read.value : "";
|
|
78
|
+
};
|
|
62
79
|
/**
|
|
63
80
|
* 入口的**运行期拒**(fail-closed):四条腿的入口一条都不许落在**这份正在跑的**契约包自己的构建产物里,
|
|
64
81
|
* 缺席也不行。判别式与拒绝句来自 `./entry-origin.js`,这里只负责「拒」这个动作 —— 以及**按形分派**:
|
|
@@ -38,7 +38,7 @@ export declare function diffWarningMultiset(expected: readonly WarningProjection
|
|
|
38
38
|
extra: unknown[];
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
* 告警面(
|
|
41
|
+
* 告警面(除 `error` 外的每一只键 + `error` 文案 —— 不只是投影:不进投影的诊断键同样出门)里有没有语料自带的秘密。
|
|
42
42
|
*
|
|
43
43
|
* 口径(诚实登记,docs/CONFORMANCE.md 同步写明):扫的是**告警**,不是 effective。effective 里逐字承运
|
|
44
44
|
* 运维自己写下的那份文档是契约(配置就是他写的那份),而告警是**本包自己铸的新文本** —— 一条把秘密
|
|
@@ -111,7 +111,7 @@ function errorText(w) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* 告警面(
|
|
114
|
+
* 告警面(除 `error` 外的每一只键 + `error` 文案 —— 不只是投影:不进投影的诊断键同样出门)里有没有语料自带的秘密。
|
|
115
115
|
*
|
|
116
116
|
* 口径(诚实登记,docs/CONFORMANCE.md 同步写明):扫的是**告警**,不是 effective。effective 里逐字承运
|
|
117
117
|
* 运维自己写下的那份文档是契约(配置就是他写的那份),而告警是**本包自己铸的新文本** —— 一条把秘密
|
|
@@ -120,6 +120,12 @@ function errorText(w) {
|
|
|
120
120
|
export function findSecretLeaks(warnings, secrets) {
|
|
121
121
|
if (secrets.length === 0)
|
|
122
122
|
return [];
|
|
123
|
-
|
|
123
|
+
// 投影照旧先算一次:它是闭集穷举(不认识的 kind ⇒ 抛,不静默扫成空);扫的是投影之外还带出门的每一只键
|
|
124
|
+
const hay = warnings.map((w) => `${stableKey(projectWarning(w))}${JOINER}${stableKey(fieldsBesideError(w))}${JOINER}${errorText(w)}`).join(JOINER);
|
|
124
125
|
return secrets.filter((s) => s.length > 0 && hay.includes(s));
|
|
125
126
|
}
|
|
127
|
+
/** 一条告警除 `error` 外的**每一只**键(扫描用,不是投影):投影只留比对用的键(`domain-defaulted` 的 `path` / `identity` / `reasonCode` 是诊断、不进投影),
|
|
128
|
+
* 扫描却要看告警带出门的一切 —— 每个 kind 同一个读法,新加的键不会因为不在投影里就躲过扫描。 */
|
|
129
|
+
function fieldsBesideError(w) {
|
|
130
|
+
return Object.fromEntries(Object.entries(w).filter(([k]) => k !== "error")); // fromEntries(不是逐键赋值):键名不走原型 setter
|
|
131
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* **门 = 闭集白名单**(`admit`,每只 schema 第一次进来时走一遍整棵 schema 树,通过的记下;递归 schema 按「节点 × 位置」只判一次):只放行**与 zod 同答**(判决与数据,对 JSON 输入)的节点种类
|
|
18
18
|
* —— 每一种都按 zod 4.4 / 4.6 的读法推过、有对 zod 逐例比判决与数据的钉;反例搜索不是穷举,找到不同答的形就从放行单拿掉 ——
|
|
19
19
|
* 叶子(不跑用户函数、没有子 schema)· 不跑看得见输入的函数的包装层(`optional` / `nullable` / `default` / `prefault`)· 后处理 `.transform(f)`(`f` 看到的是里面那只 schema 的输出,两边同一份)·
|
|
20
|
-
* 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record` · 数组 ·
|
|
20
|
+
* 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record`(包里的每一只都是记录座位 —— 输入侧是座位守卫本身的管道,按守卫函数的身份认:守卫只按自有名读成员,在深拷副本上与在原值上同答)· 数组 ·
|
|
21
21
|
* 投影走到的位置上的 `unknown` / `any`。对象 / 数组 / record 上挂的检查(refine / superRefine / 长度 …)看到的是 zod 自己铸的新输出,两边同一份。
|
|
22
22
|
* 其余一律**响亮拒**(抛 `parseDeclared: unsupported schema shape — …`;这是包自己的 schema 选错了读法,不是调用方的值读不出):`.catch`(兜底函数看到整个原值 —— zod ≥ 4.6 交 `ctx.input`)·
|
|
23
23
|
* 输入侧变换(`z.preprocess`、字段位上单独的 `z.transform`、两侧都是 schema 的管道)· `z.custom`(谓词看到的是副本)· 深拷节点之下的 `unknown` / `any`(副本会进输出;passthrough 对象同因)·
|
package/dist/declared-capture.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* **门 = 闭集白名单**(`admit`,每只 schema 第一次进来时走一遍整棵 schema 树,通过的记下;递归 schema 按「节点 × 位置」只判一次):只放行**与 zod 同答**(判决与数据,对 JSON 输入)的节点种类
|
|
18
18
|
* —— 每一种都按 zod 4.4 / 4.6 的读法推过、有对 zod 逐例比判决与数据的钉;反例搜索不是穷举,找到不同答的形就从放行单拿掉 ——
|
|
19
19
|
* 叶子(不跑用户函数、没有子 schema)· 不跑看得见输入的函数的包装层(`optional` / `nullable` / `default` / `prefault`)· 后处理 `.transform(f)`(`f` 看到的是里面那只 schema 的输出,两边同一份)·
|
|
20
|
-
* 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record` · 数组 ·
|
|
20
|
+
* 对象(声明键不是符号、也不叫寻常对象从 `Object.prototype` 继承来的名字 —— zod 在原值上读到继承的成员,投影读成缺席)· 判别联合(不带 `unionFallback`)· 普通 / 互斥联合 · `record`(包里的每一只都是记录座位 —— 输入侧是座位守卫本身的管道,按守卫函数的身份认:守卫只按自有名读成员,在深拷副本上与在原值上同答)· 数组 ·
|
|
21
21
|
* 投影走到的位置上的 `unknown` / `any`。对象 / 数组 / record 上挂的检查(refine / superRefine / 长度 …)看到的是 zod 自己铸的新输出,两边同一份。
|
|
22
22
|
* 其余一律**响亮拒**(抛 `parseDeclared: unsupported schema shape — …`;这是包自己的 schema 选错了读法,不是调用方的值读不出):`.catch`(兜底函数看到整个原值 —— zod ≥ 4.6 交 `ctx.input`)·
|
|
23
23
|
* 输入侧变换(`z.preprocess`、字段位上单独的 `z.transform`、两侧都是 schema 的管道)· `z.custom`(谓词看到的是副本)· 深拷节点之下的 `unknown` / `any`(副本会进输出;passthrough 对象同因)·
|
|
@@ -28,6 +28,7 @@ import { z } from "zod";
|
|
|
28
28
|
import { NOT_PLAIN_DATA, NO_PRIOR_READS, UNINSPECTABLE, captureJson, dataDescriptor, inspect, isolatedObject, readDeclaredKey } from "./own-key-read.js";
|
|
29
29
|
import { jsonShapeOf } from "./plain-json-object.js";
|
|
30
30
|
import { unwrapOnce } from "./zod-unwrap.js";
|
|
31
|
+
import { isRecordSeat } from "./record-seat.js";
|
|
31
32
|
const failed = (sentence) => ({ ok: false, sentence });
|
|
32
33
|
/** 判语的句子(只在这里拼一次)。 */
|
|
33
34
|
const unsupportedShape = (what) => `parseDeclared: unsupported schema shape — ${what}`;
|
|
@@ -157,6 +158,9 @@ function admitAt(schema, at, seen) {
|
|
|
157
158
|
case "catch":
|
|
158
159
|
return "`.catch` (its fallback sees the caller's whole value — zod ≥ 4.6 hands it `ctx.input`; a projection changes what it sees)";
|
|
159
160
|
case "pipe":
|
|
161
|
+
// 记录座位(`./record-seat`,按守卫函数的身份认):输入侧的守卫只按自有名读成员,而记录在这里恒是整份深拷 —— 副本保留自有 `__proto__`、拒隐藏 / 访问器成员,守卫在副本上与在原值上同答
|
|
162
|
+
if (isRecordSeat(inner))
|
|
163
|
+
return admitAt(inner.out, at, seen);
|
|
160
164
|
return `a pipe the projection does not pass through — an input-side \`z.preprocess(f, …)\` or \`a.pipe(b)\` (the function / the second schema would see a projection or a copy, not what zod sees), or wrappers nested deeper than ${WRAPPER_BOUND} layers`;
|
|
161
165
|
case "transform":
|
|
162
166
|
return "a bare `z.transform(f)` (an input-side function: it would see the projection, not the caller's value)";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** 这只坐标的拒因(闭集;词序 = 判序):`not-a-cap` = 不是正十进制整数、也不是 `off`;`unsafe-integer` = 是一串数字,但超出安全整数(读成的已不是写下的那个数)。 */
|
|
2
|
+
export declare const DEVICE_MAX_PREAUTH_PER_REMOTE_FLAWS: readonly ["not-a-cap", "unsafe-integer"];
|
|
3
|
+
export type DeviceMaxPreAuthPerRemoteFlaw = (typeof DEVICE_MAX_PREAUTH_PER_REMOTE_FLAWS)[number];
|
|
4
|
+
/** 读数:`cap` = 那个数 / `"off"` / `undefined`(未设,引擎用它的缺省);或一个拒因。 */
|
|
5
|
+
export type DeviceMaxPreAuthPerRemoteReading = {
|
|
6
|
+
readonly ok: true;
|
|
7
|
+
readonly cap: number | "off" | undefined;
|
|
8
|
+
} | {
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly flaw: DeviceMaxPreAuthPerRemoteFlaw;
|
|
11
|
+
};
|
|
12
|
+
/** 规则句(不含值):写闸的拒句、表单的提示读这一句。 */
|
|
13
|
+
export declare const DEVICE_MAX_PREAUTH_PER_REMOTE_RULE: string;
|
|
14
|
+
/** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
|
|
15
|
+
export declare function readDeviceMaxPreAuthPerRemote(value: string | undefined): DeviceMaxPreAuthPerRemoteReading;
|
|
16
|
+
/**
|
|
17
|
+
* 名单一项的拒因(闭集;词序 = 判序):`empty` = 项是空的(多余 / 连续的逗号,或整个值只有空白)—— 多半是拼接事故,收下会让人以为某条还在;
|
|
18
|
+
* `zone-id` = 带 `%…`;`not-cidr` = 不是「地址[/十进制前缀]」(主机名、前缀越界、两道斜杠、前缀里有别的字符、IPv4 段带前导零 …);
|
|
19
|
+
* `all-sources` = 这一项装下某一族的**每个**来源 —— 信任它们的转发头,等于每个客户端自报帽键:前缀 0(两族都是),或装下整段 IPv4 映射地址 `::ffff:0:0/96`
|
|
20
|
+
* 的 IPv6 网络(引擎拿读数建的地址集合拿 IPv4 来源比 IPv6 规则时按映射形比,这样一项就信了每个 IPv4 来源);
|
|
21
|
+
* `host-bits` = 前缀之后还有为 1 的位 —— 是想信整块还是信一台?两条出路都交出。
|
|
22
|
+
*/
|
|
23
|
+
export declare const TRUSTED_PROXY_CIDR_FLAWS: readonly ["empty", "zone-id", "not-cidr", "all-sources", "host-bits"];
|
|
24
|
+
export type TrustedProxyCidrFlaw = (typeof TRUSTED_PROXY_CIDR_FLAWS)[number];
|
|
25
|
+
/** 名单里合格的一项:`text` = 规范文本(`地址/前缀`,IPv6 压缩小写);`address` = 规范形的网络地址;`prefix` = 十进制前缀;`family` = 族。 */
|
|
26
|
+
export interface TrustedProxyCidr {
|
|
27
|
+
readonly text: string;
|
|
28
|
+
readonly address: string;
|
|
29
|
+
readonly prefix: number;
|
|
30
|
+
readonly family: "ipv4" | "ipv6";
|
|
31
|
+
}
|
|
32
|
+
/** 名单里坏的一项:第几项(从 1 起)/ 共几项 / 那一项剥掉两侧空格与制表符之后的文本 / 拒因;`host-bits` 另带两条出路(整块的网络写法、那一台的主机写法)。 */
|
|
33
|
+
export type TrustedProxyCidrItemFlaw = {
|
|
34
|
+
readonly item: number;
|
|
35
|
+
readonly of: number;
|
|
36
|
+
readonly text: string;
|
|
37
|
+
readonly flaw: Exclude<TrustedProxyCidrFlaw, "host-bits">;
|
|
38
|
+
} | {
|
|
39
|
+
readonly item: number;
|
|
40
|
+
readonly of: number;
|
|
41
|
+
readonly text: string;
|
|
42
|
+
readonly flaw: "host-bits";
|
|
43
|
+
readonly block: string;
|
|
44
|
+
readonly host: string;
|
|
45
|
+
};
|
|
46
|
+
/** 读数:合格 ⇒ 规范后的项(`undefined` = 未设,不读任何代理头);有坏项 ⇒ 每个坏项按项序一条。 */
|
|
47
|
+
export type TrustedProxyCidrsReading = {
|
|
48
|
+
readonly ok: true;
|
|
49
|
+
readonly cidrs: readonly TrustedProxyCidr[] | undefined;
|
|
50
|
+
} | {
|
|
51
|
+
readonly ok: false;
|
|
52
|
+
readonly items: readonly TrustedProxyCidrItemFlaw[];
|
|
53
|
+
};
|
|
54
|
+
/** 规则句(不含值)。 */
|
|
55
|
+
export declare const DEVICE_TRUSTED_PROXY_CIDRS_RULE: string;
|
|
56
|
+
/** 读一个值(env 原文或写闸的坐标值;`undefined` = 没写)。 */
|
|
57
|
+
export declare function readDeviceTrustedProxyCidrs(value: string | undefined): TrustedProxyCidrsReading;
|