@sema-agent/settings-schema 35.1.0 → 35.2.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 +264 -0
- package/README.md +25 -6
- package/conformance/VERSION +1 -1
- package/dist/api/connector-assertions.d.ts +186 -0
- package/dist/api/connector-assertions.js +148 -0
- package/dist/api/credentials.d.ts +30 -50
- package/dist/api/credentials.js +14 -14
- package/dist/api/refusal-table.d.ts +16 -0
- package/dist/api/refusal-table.js +24 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/mutable-copy.d.ts +48 -0
- package/dist/mutable-copy.js +229 -0
- package/dist/settings-units.d.ts +8 -0
- package/dist/settings-units.js +6 -4
- package/dist/tighten-only-seat-limits.d.ts +16 -0
- package/dist/tighten-only-seat-limits.js +16 -0
- package/docs/API-SURFACE.md +17 -2
- package/docs/CONSUMER-INTEGRATION.md +169 -3
- package/llms-full.txt +24 -6
- package/llms.txt +5 -2
- package/package.json +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `api/connector-assertions` —— 连接器断言铸口(`POST /api/v1/connectors/assertions`)的 wire 型:管理台铸,本服务的对端座问。
|
|
3
|
+
* 一份 zod,发这些形的一方与收这些形的一方同 import。纯、零 I/O、浏览器安全。
|
|
4
|
+
*
|
|
5
|
+
* 一步答出:座带着「要发给哪台 MCP 服务器、发到哪个地址、替谁发」来问({@link ConnectorAssertionRequest}),管理台要么交回一枚断言与它的到期时刻
|
|
6
|
+
* ({@link ConnectorAssertionAnswer}),要么整次拒答({@link ConnectorAssertionRefusal})—— 没有句柄、没有第二步。
|
|
7
|
+
* 本模块只有**形、词表与一只比较函数**:调用方鉴权(`wat_`)、委托、活表复核、登记册查条目、判定序、断言的签发与缓存都是各方自己的事,不在这里。
|
|
8
|
+
* `assertion` 是应答里唯一的秘密位。
|
|
9
|
+
*
|
|
10
|
+
* ## 请求是严格对象,应答与拒体剥未知键
|
|
11
|
+
* · 请求({@link ConnectorAssertionRequest}):多一个键 ⇒ 不是这一形 ⇒ 答方回 `request_invalid`。凭据铸口上,调用方多给的键看起来像约束
|
|
12
|
+
* (作用域、连接器 id、有效期上限一类);剥掉 = 调用方以为表达了的约束被静默丢掉、断言照铸。所以请求的键集首发即定:以后要加键是主版本,两侧同窗提货。
|
|
13
|
+
* · 应答与拒体:多一个键剥掉(与包里的句柄应答、两只既有拒体同律)。发应答的是管理台、收应答的是本服务的座:管理台在应答里多带一个键,旧的收方照读、不整次失败;
|
|
14
|
+
* 拒体里别的臂带来的 `authorizeUrl` 被剥,收方拿到的值里只在 `authorization_required` 那一臂有地址。
|
|
15
|
+
*
|
|
16
|
+
* ## 拒答表
|
|
17
|
+
* {@link CONNECTOR_ASSERTION_REFUSALS} = 凭据平面共享拒答表的九词(原样原序,复用同一行对象)+ 铸口自有五词(管理台判定序的出场序),派生机关与沙箱 git 那一张是同一份
|
|
18
|
+
* (包内私有叶 `./refusal-table`)。自有五词只在铸口上有意义,所以不进共享表。一个词的 `permanence` 是固定的,拒体里再带一份只为收方不必查表 —— 两处不一致即畸形应答。
|
|
19
|
+
* 状态码是 HTTP 层的:拒体的校验只核 `permanence`,不核状态;词与状态码对不对得上是收方的事。
|
|
20
|
+
* `permanence` 的词集就是 `SANDBOX_GIT_PERMANENCE`(名字里带「沙箱 git」是既有的命名,词集是凭据平面共用的)。
|
|
21
|
+
*
|
|
22
|
+
* ## `terminal` 在铸口上怎么重问
|
|
23
|
+
* `terminal` = 这一次请求不按退避节奏重试;再问要等一件可能改变答案的事。四种情形:
|
|
24
|
+
* · 首次连接(引擎座问题的 `cause` 是连接):terminal ⇒ 这次座拒、不退避重铸;transient(只有 `vault_unavailable`)⇒ 可在座的等待窗内退避重铸;
|
|
25
|
+
* · 后续发送(`cause` 是请求):每次发送是一次新的问,不算定时重试;收方可以记住上一次的 terminal 词,免得每次发送都打中心;
|
|
26
|
+
* · 用户动作之后(重新登录续上委托、去 `authorizeUrl` 授权):立刻重问一次;首拨已失败的,随显式重拨或下一条腿;
|
|
27
|
+
* · 运维修复之后(`plane_misconfigured`、`vault_disabled` / `vault_frozen`、`connector_not_registered`、`connector_target_mismatch` 的出路是改条目或登记册并重启本服务):
|
|
28
|
+
* 重启后的首拨自然是新的一问;收方也可以为这些词设一个低频复查。
|
|
29
|
+
* 哪只词归哪一种情形、复查多久,是收方座的处置表;本模块不加列、不改值。
|
|
30
|
+
*
|
|
31
|
+
* ## 比较函数 {@link compareDialTargets}:只为「准不准铸」
|
|
32
|
+
* 律:两个地址算同一个发送目标,当且仅当两边都过 `NON_SECRET_URL`,且各自按 WHATWG URL 解析后的序列化串(`href`)逐字节相等。
|
|
33
|
+
* 任一边读不出 ⇒ `unreadable`,永不 `same`。先各自判,最后才比;没有「两边字节相同 / 同一只对象」的快径。步骤:
|
|
34
|
+
* 1. 输入不是原始字符串(`typeof` 不是 `string`)⇒ 读不出(不做 `String(raw)`;`new String(...)` 包装对象也是读不出);
|
|
35
|
+
* 2. 过不了 `NON_SECRET_URL` ⇒ 读不出(不另写 URL 形规则);
|
|
36
|
+
* 3. 规范串 = `new URL(raw).href`;
|
|
37
|
+
* 4. 两边各自走完 1–3;任一读不出 ⇒ `unreadable`;两串相等 ⇒ `same`;否则 `different`。
|
|
38
|
+
* 用途只有一个:管理台判定序里「请求的 `url` 与登记册那一行的端点相等」—— `same` 才铸,`different` ⇒ `connector_target_mismatch`,`unreadable` ⇒ 不铸。
|
|
39
|
+
* 在这个方向上多答 `different` 是多拒,失败关闭。**它不是登记册端点去重的判官**:去重方向上安全反过来(`%7E` 与 `~` 答 `different`,去重就放过了可能指向同一处理器的别名),
|
|
40
|
+
* 去重要哪种等价是另一件事。单只地址的规范串不出本模块。与 `DIAL_ADDRESS_URL_FORBIDDEN_PARTS`(`../url-shape`,「逐字发给拨号方的地址」那一座位禁哪些部件)名近义远:
|
|
41
|
+
* 那只是一个座位的部件表,这只是两个地址的比较。
|
|
42
|
+
* WHATWG 解析会做的改写:scheme 与主机名转小写;去默认端口;国际化域名转 punycode;IPv4 别写形规整、IPv6 压缩;解析 `.` / `..` 段(含百分号写的 `%2e`);
|
|
43
|
+
* 空路径补 `/`;路径里的非 ASCII 字符按 UTF-8 百分号编码;去首尾 C0 控制符与空格、去内嵌的制表与换行;空 userinfo 的 `@` 消失;特殊 scheme 缺 `//` 的写法补成层级式。
|
|
44
|
+
* 不做:不去路径尾斜杠(空路径补 `/` 除外)、不折路径大小写、不解码已有的百分号三元组(也不改它的十六进制大小写)、不排查询参数、不去空查询的 `?`、不去主机名末尾的点。
|
|
45
|
+
*
|
|
46
|
+
* ## 不给的保证
|
|
47
|
+
* 1. 同一序列化串 ≠ 同一实际对端:比较只看字符串;各自网络命名空间里的同一本机地址、分区 DNS、域名改指,都能让同一串落到不同进程。这是登记信任与部署网络的残余风险;
|
|
48
|
+
* 引擎发送链上自己的检查(不跟随重定向一类)不由本函数代替,也不靠本函数。
|
|
49
|
+
* 2. 跨运行时的 URL / 国际化域名归一差异没有证明只会偏向 `different`:比较跑在管理台的运行时,拨号跑在引擎的运行时,一边相等推不出另一边相等。
|
|
50
|
+
* 3. 判官按解析结果认,不按原串字面认:空 userinfo 的 `@`、特殊 scheme 缺 `//`、首尾空白、内嵌制表 / 换行都能过 `NON_SECRET_URL`,并与规范写法比成 `same`。
|
|
51
|
+
* 本模块不收紧 `NON_SECRET_URL`:它是多座位共用的判官,请求的 `url` 就是 MCP 条目的 `url`,请求侧另立更严的判法 = 同一串两答。
|
|
52
|
+
* 4. 挡不住会说谎的服务层,也看不到断言缓存命中的发送。
|
|
53
|
+
* 5. 只说「是不是同一个拨号目标」,不说「这个目标许不许拨」(https 律、本机 http 例外是登记册一方的规则)。
|
|
54
|
+
* 6. 不是去重判官(见上)。
|
|
55
|
+
*/
|
|
56
|
+
import { z } from "zod";
|
|
57
|
+
import { buildQuotedIssue } from "../quoted-issue.js";
|
|
58
|
+
import { deepFreeze } from "../deep-freeze.js";
|
|
59
|
+
import { McpServerSpec, NON_SECRET_URL } from "../types.js";
|
|
60
|
+
import { PrincipalIncarnation } from "./auth-bridge.js";
|
|
61
|
+
import { CREDENTIAL_PLANE_REFUSALS, CREDENTIAL_PLANE_REFUSAL_ERRORS, SANDBOX_GIT_PERMANENCE, } from "./credentials.js";
|
|
62
|
+
import { buildRefusalTable } from "./refusal-table.js";
|
|
63
|
+
import { NonEmptyString, PrincipalString, SafeCount } from "./wire-scalars.js";
|
|
64
|
+
// ── 请求与应答 ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* 铸断言的请求体(严格对象,恰四键,全必填;多一键 ⇒ 不是这一形,见模块头注):
|
|
67
|
+
* · `server` —— MCP 服务器名,与引擎座问题里的同名成员同义;形就是 `McpServerSpec` 的 `name` 那一只判官(同一对象,不另立名字规则);答方按原串逐字节查条目,不折大小写(正则的 `i` 旗只管字符集);
|
|
68
|
+
* · `url` —— 引擎实际要发往的地址(就是 MCP 条目的 `url` 原串);形 = `NON_SECRET_URL`;
|
|
69
|
+
* · `principal` / `principalInc` —— 替谁铸:主体名(就是凭据平面那一只主体名叶子 `PrincipalString`)与化身号,与凭据取值口的请求同义同形(同一对象)。
|
|
70
|
+
*/
|
|
71
|
+
export const ConnectorAssertionRequest = z.object({
|
|
72
|
+
server: McpServerSpec.shape.name,
|
|
73
|
+
url: NON_SECRET_URL,
|
|
74
|
+
principal: PrincipalString,
|
|
75
|
+
principalInc: PrincipalIncarnation,
|
|
76
|
+
}).strict();
|
|
77
|
+
/** 铸成的应答:断言(不透明串,应答里唯一的秘密位)与它的到期时刻(epoch 毫秒,中心的钟 —— 收方拿自己的钟比时自担钟差)。多一键剥掉。 */
|
|
78
|
+
export const ConnectorAssertionAnswer = z.object({ assertion: NonEmptyString, expiresAt: SafeCount });
|
|
79
|
+
// ── 整次拒答 ───────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
80
|
+
/** 永久性词表的 `terminal`(词只在 `./credentials` 里拼一次,这里取表的首项)。 */
|
|
81
|
+
const TERMINAL = SANDBOX_GIT_PERMANENCE[0];
|
|
82
|
+
/** 铸口自有五词(都是 403 · terminal),出场序 = 管理台判定序。 */
|
|
83
|
+
const CONNECTOR_ASSERTION_OWN_REFUSALS = deepFreeze({
|
|
84
|
+
runner_credential_unavailable: { statuses: [403], permanence: TERMINAL },
|
|
85
|
+
connector_not_entitled: { statuses: [403], permanence: TERMINAL },
|
|
86
|
+
connector_not_registered: { statuses: [403], permanence: TERMINAL },
|
|
87
|
+
connector_target_mismatch: { statuses: [403], permanence: TERMINAL },
|
|
88
|
+
authorization_required: { statuses: [403], permanence: TERMINAL },
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* 次序:共享九词按共享表的表序在前,自有五词按上面自有表的序在后 —— 次序一发出就是契约(重排 = 主版本)。
|
|
92
|
+
* 共享九词从共享表的词表读,不在这里再拼一遍(词的单一属主是 `./credentials`)。
|
|
93
|
+
*/
|
|
94
|
+
const CONNECTOR_ASSERTION_REFUSAL_ORDER = [
|
|
95
|
+
...CREDENTIAL_PLANE_REFUSAL_ERRORS,
|
|
96
|
+
...Object.keys(CONNECTOR_ASSERTION_OWN_REFUSALS),
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* 铸口整次拒答词 → 它的 HTTP 状态集(答方答这个词时用其一)与 `permanence`。共享九词的行就是共享表那一行(同一对象),自有五词见上。
|
|
100
|
+
* 收方怎么处置某个词(哪种情形、复查多久)是收方的处置表,不在这里(见模块头注「`terminal` 在铸口上怎么重问」)。
|
|
101
|
+
*/
|
|
102
|
+
export const CONNECTOR_ASSERTION_REFUSALS = buildRefusalTable("CONNECTOR_ASSERTION_REFUSAL_ORDER", CREDENTIAL_PLANE_REFUSALS, CONNECTOR_ASSERTION_OWN_REFUSALS, CONNECTOR_ASSERTION_REFUSAL_ORDER);
|
|
103
|
+
/** 铸口整次拒答词表(运行期;表的键,按表序)。 */
|
|
104
|
+
export const CONNECTOR_ASSERTION_REFUSAL_ERRORS = deepFreeze(Object.keys(CONNECTOR_ASSERTION_REFUSALS));
|
|
105
|
+
/** 只有这一臂带授权地址。 */
|
|
106
|
+
const AUTHORIZATION_REQUIRED = "authorization_required";
|
|
107
|
+
/** 除授权那一臂之外的十三词,按表序。 */
|
|
108
|
+
const PLAIN_REFUSAL_ERRORS = CONNECTOR_ASSERTION_REFUSAL_ERRORS.filter((word) => word !== AUTHORIZATION_REQUIRED);
|
|
109
|
+
/** 拒体的共有成员:永久性(必须等于表里这一词的,见下面的 `refine`)与诊断句。 */
|
|
110
|
+
const RefusalCommon = {
|
|
111
|
+
permanence: z.enum(SANDBOX_GIT_PERMANENCE),
|
|
112
|
+
message: z.string(),
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* 整次拒答的体,按 `error` 判别:
|
|
116
|
+
* · 十三词:`{ error, permanence, message }`;
|
|
117
|
+
* · `authorization_required`:另可带 `authorizeUrl`(非空串)—— 用户去哪里授权。它能不能交给用户不在这里判,由收方问 `connectorAuthorizeUrlFlaws`(`../connector-authorize-url`)。
|
|
118
|
+
* `permanence` 是错误词的函数,必须等于 {@link CONNECTOR_ASSERTION_REFUSALS} 里这一行的;`message` 是答方的诊断句(收方不据它判,可为空串)。
|
|
119
|
+
* 体里不带状态码。未知键剥掉(别的臂带来的 `authorizeUrl` 也剥)。
|
|
120
|
+
*/
|
|
121
|
+
export const ConnectorAssertionRefusal = z
|
|
122
|
+
.discriminatedUnion("error", [
|
|
123
|
+
z.object({ error: z.enum(PLAIN_REFUSAL_ERRORS), ...RefusalCommon }),
|
|
124
|
+
z.object({ error: z.literal(AUTHORIZATION_REQUIRED), ...RefusalCommon, authorizeUrl: NonEmptyString.optional() }),
|
|
125
|
+
])
|
|
126
|
+
.refine((body) => CONNECTOR_ASSERTION_REFUSALS[body.error].permanence === body.permanence, buildQuotedIssue `permanence must be the one the refusal table gives for this error`);
|
|
127
|
+
// ── 发送目标比较 ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
128
|
+
/** 比较的三态答案(闭集):同一个发送目标 / 不是 / 至少一边读不出。三态不能并成一个布尔:读不出永不等于「不同」。 */
|
|
129
|
+
export const DIAL_TARGET_COMPARISONS = deepFreeze(["same", "different", "unreadable"]);
|
|
130
|
+
const [SAME, DIFFERENT, UNREADABLE] = DIAL_TARGET_COMPARISONS;
|
|
131
|
+
/** 单只地址的规范串(模块内私有,不导出:比较律只要「两边各判、最后比串」,规范串交出去就等于给了去重一只现成的判官)。读不出 ⇒ `undefined`。 */
|
|
132
|
+
function dialTargetOf(raw) {
|
|
133
|
+
if (typeof raw !== "string")
|
|
134
|
+
return undefined;
|
|
135
|
+
if (!NON_SECRET_URL.safeParse(raw).success)
|
|
136
|
+
return undefined;
|
|
137
|
+
return new URL(raw).href;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 两个地址是不是同一个发送目标 —— 只为铸口判定「准不准铸」;不是登记册去重的判官。总、不抛。律、步骤与不给的保证见模块头注。
|
|
141
|
+
*/
|
|
142
|
+
export function compareDialTargets(a, b) {
|
|
143
|
+
const left = dialTargetOf(a);
|
|
144
|
+
const right = dialTargetOf(b);
|
|
145
|
+
if (left === undefined || right === undefined)
|
|
146
|
+
return UNREADABLE;
|
|
147
|
+
return left === right ? SAME : DIFFERENT;
|
|
148
|
+
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* 每一行的**条件**(什么事实使它命中)是 web-admin 的判定逻辑,写在 `docs/CONSUMER-INTEGRATION.md` 里,不进运行期表。
|
|
16
16
|
* · {@link CREDENTIAL_PLANE_REFUSALS} —— 凭据平面共享拒答表(九个词;同一平面的各只口从它派生,每个词的状态集与 `permanence` 只在这里写一次)。
|
|
17
17
|
* · {@link SANDBOX_GIT_REFUSALS} —— 整次拒答词(十一个)→ HTTP 状态集与 `permanence`,由凭据平面共享表 {@link CREDENTIAL_PLANE_REFUSALS}(九个)与本口自有的两个词按声明的次序派生(上一版的十个词原序、新词只在尾部);拒体里的 `permanence` 是错误词的函数,必须等于这一行的。
|
|
18
|
-
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(
|
|
18
|
+
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(这一次请求不按退避节奏重试,再问要等一件可能改变答案的事)/ `transient`(退避重试)两词,语义在本表定义。
|
|
19
19
|
*
|
|
20
20
|
* ## 解析一律剥未知键
|
|
21
21
|
* 与包内 api 契约的前向兼容同律(新键恒为加性)。同时这也是一条安全律:`secret` 只在 `active` 臂的形里 —— 别的臂即使收到也剥掉,
|
|
@@ -205,13 +205,18 @@ export declare const SandboxGitCredentialAnswer: z.ZodObject<{
|
|
|
205
205
|
kind: z.ZodLiteral<"sandbox_git">;
|
|
206
206
|
}, z.core.$strip>;
|
|
207
207
|
export type SandboxGitCredentialAnswer = z.infer<typeof SandboxGitCredentialAnswer>;
|
|
208
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* `permanence` 两词(凭据平面各只口共用这一张):
|
|
210
|
+
* · `terminal` = 这一次请求不按退避节奏重试;再问要等一件可能改变答案的事(用户的动作 —— 重新登录续上委托、去授权地址授权;运维的修复 —— 改配置并重启;
|
|
211
|
+
* 或收方自己的下一次连接 / 发送)。收方可以为这类词设一个低频的复查,那是收方的处置表,不在这里;
|
|
212
|
+
* · `transient` = 退避重试。
|
|
213
|
+
*/
|
|
209
214
|
export declare const SANDBOX_GIT_PERMANENCE: readonly ["terminal", "transient"];
|
|
210
215
|
export type SandboxGitPermanence = (typeof SANDBOX_GIT_PERMANENCE)[number];
|
|
211
216
|
/**
|
|
212
217
|
* 凭据平面共享拒答表(九个词):同一凭据平面的各只口都从它派生(`sandbox_git` 凭据取值口如此,同一平面的后续取值口同样如此),
|
|
213
218
|
* 每个词的 HTTP 状态集与 `permanence` 只在这里写一次。
|
|
214
|
-
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal
|
|
219
|
+
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal`,运维修正配置之前再问也不会成功(不按退避节奏重试;运维修复是那件可能改变答案的事)。
|
|
215
220
|
*/
|
|
216
221
|
export declare const CREDENTIAL_PLANE_REFUSALS: {
|
|
217
222
|
readonly caller_not_admitted: {
|
|
@@ -255,83 +260,58 @@ export declare const CREDENTIAL_PLANE_REFUSALS: {
|
|
|
255
260
|
export type CredentialPlaneRefusalError = keyof typeof CREDENTIAL_PLANE_REFUSALS;
|
|
256
261
|
/** 凭据平面共享拒答词表(运行期;表的键,按表序)。 */
|
|
257
262
|
export declare const CREDENTIAL_PLANE_REFUSAL_ERRORS: readonly [CredentialPlaneRefusalError, ...CredentialPlaneRefusalError[]];
|
|
258
|
-
declare const SANDBOX_GIT_OWN_REFUSALS: {
|
|
259
|
-
readonly scope_mismatch: {
|
|
260
|
-
readonly statuses: readonly [403];
|
|
261
|
-
readonly permanence: "terminal";
|
|
262
|
-
};
|
|
263
|
-
readonly handle_invalid: {
|
|
264
|
-
readonly statuses: readonly [401];
|
|
265
|
-
readonly permanence: "transient";
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
/** 上一版的十个词保持原序,新词只追加在尾部 —— 调整既有词的次序是破坏性变更。 */
|
|
269
|
-
declare const SANDBOX_GIT_REFUSAL_ORDER: readonly ["caller_not_admitted", "scope_mismatch", "incarnation_mismatch", "request_invalid", "principal_not_live", "delegation_required", "vault_disabled", "vault_frozen", "handle_invalid", "vault_unavailable", "plane_misconfigured"];
|
|
270
|
-
type SandboxGitRefusalWord = (typeof SANDBOX_GIT_REFUSAL_ORDER)[number];
|
|
271
|
-
type SandboxGitRefusalSource = CredentialPlaneRefusalError | keyof typeof SANDBOX_GIT_OWN_REFUSALS;
|
|
272
|
-
/** 编译期核对,只在类型层(不留运行期语句):`T` 必须是 `true`,否则这一行编译即红。 */
|
|
273
|
-
type MustBeTrue<T extends true> = T;
|
|
274
263
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
264
|
+
* 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
|
|
265
|
+
* 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
|
|
266
|
+
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(复用同一行对象,不抄行;次序表重复词即抛、与两张来源表不恰好互为全集即编译红 ——
|
|
267
|
+
* 派生机关在包内私有叶 `./refusal-table`,凭据平面各只口共用一份)。
|
|
277
268
|
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
Exclude<SandboxGitRefusalWord, SandboxGitRefusalSource>,
|
|
281
|
-
Extract<CredentialPlaneRefusalError, keyof typeof SANDBOX_GIT_OWN_REFUSALS>
|
|
282
|
-
] extends [never, never, never] ? true : false>;
|
|
283
|
-
declare const SANDBOX_GIT_REFUSAL_ROWS: {
|
|
284
|
-
scope_mismatch: {
|
|
285
|
-
readonly statuses: readonly [403];
|
|
286
|
-
readonly permanence: "terminal";
|
|
287
|
-
};
|
|
288
|
-
handle_invalid: {
|
|
289
|
-
readonly statuses: readonly [401];
|
|
290
|
-
readonly permanence: "transient";
|
|
291
|
-
};
|
|
292
|
-
caller_not_admitted: {
|
|
269
|
+
export declare const SANDBOX_GIT_REFUSALS: {
|
|
270
|
+
readonly caller_not_admitted: {
|
|
293
271
|
readonly statuses: readonly [401, 403];
|
|
294
272
|
readonly permanence: "terminal";
|
|
295
273
|
};
|
|
296
|
-
incarnation_mismatch: {
|
|
274
|
+
readonly incarnation_mismatch: {
|
|
297
275
|
readonly statuses: readonly [403];
|
|
298
276
|
readonly permanence: "terminal";
|
|
299
277
|
};
|
|
300
|
-
request_invalid: {
|
|
278
|
+
readonly request_invalid: {
|
|
301
279
|
readonly statuses: readonly [400];
|
|
302
280
|
readonly permanence: "terminal";
|
|
303
281
|
};
|
|
304
|
-
principal_not_live: {
|
|
282
|
+
readonly principal_not_live: {
|
|
305
283
|
readonly statuses: readonly [403];
|
|
306
284
|
readonly permanence: "terminal";
|
|
307
285
|
};
|
|
308
|
-
delegation_required: {
|
|
286
|
+
readonly delegation_required: {
|
|
309
287
|
readonly statuses: readonly [403];
|
|
310
288
|
readonly permanence: "terminal";
|
|
311
289
|
};
|
|
312
|
-
vault_disabled: {
|
|
290
|
+
readonly vault_disabled: {
|
|
313
291
|
readonly statuses: readonly [503];
|
|
314
292
|
readonly permanence: "terminal";
|
|
315
293
|
};
|
|
316
|
-
vault_frozen: {
|
|
294
|
+
readonly vault_frozen: {
|
|
317
295
|
readonly statuses: readonly [503];
|
|
318
296
|
readonly permanence: "terminal";
|
|
319
297
|
};
|
|
320
|
-
vault_unavailable: {
|
|
298
|
+
readonly vault_unavailable: {
|
|
321
299
|
readonly statuses: readonly [503];
|
|
322
300
|
readonly permanence: "transient";
|
|
323
301
|
};
|
|
324
|
-
plane_misconfigured: {
|
|
302
|
+
readonly plane_misconfigured: {
|
|
325
303
|
readonly statuses: readonly [503];
|
|
326
304
|
readonly permanence: "terminal";
|
|
327
305
|
};
|
|
306
|
+
readonly scope_mismatch: {
|
|
307
|
+
readonly statuses: readonly [403];
|
|
308
|
+
readonly permanence: "terminal";
|
|
309
|
+
};
|
|
310
|
+
readonly handle_invalid: {
|
|
311
|
+
readonly statuses: readonly [401];
|
|
312
|
+
readonly permanence: "transient";
|
|
313
|
+
};
|
|
328
314
|
};
|
|
329
|
-
/**
|
|
330
|
-
* 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
|
|
331
|
-
* 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
|
|
332
|
-
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(复用同一行对象,不抄行)。
|
|
333
|
-
*/
|
|
334
|
-
export declare const SANDBOX_GIT_REFUSALS: { readonly [W in SandboxGitRefusalOrderIsExact extends true ? SandboxGitRefusalWord : never]: (typeof SANDBOX_GIT_REFUSAL_ROWS)[W]; };
|
|
335
315
|
/** 整次拒答词(闭集,十一个)—— 类型由 {@link SANDBOX_GIT_REFUSALS} 派生,次序来自声明的次序。 */
|
|
336
316
|
export type SandboxGitRefusalError = keyof typeof SANDBOX_GIT_REFUSALS;
|
|
337
317
|
/** 整次拒答词表(运行期;表的键,按声明的次序)。 */
|
package/dist/api/credentials.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* 每一行的**条件**(什么事实使它命中)是 web-admin 的判定逻辑,写在 `docs/CONSUMER-INTEGRATION.md` 里,不进运行期表。
|
|
16
16
|
* · {@link CREDENTIAL_PLANE_REFUSALS} —— 凭据平面共享拒答表(九个词;同一平面的各只口从它派生,每个词的状态集与 `permanence` 只在这里写一次)。
|
|
17
17
|
* · {@link SANDBOX_GIT_REFUSALS} —— 整次拒答词(十一个)→ HTTP 状态集与 `permanence`,由凭据平面共享表 {@link CREDENTIAL_PLANE_REFUSALS}(九个)与本口自有的两个词按声明的次序派生(上一版的十个词原序、新词只在尾部);拒体里的 `permanence` 是错误词的函数,必须等于这一行的。
|
|
18
|
-
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(
|
|
18
|
+
* · {@link SANDBOX_GIT_PERMANENCE} —— `terminal`(这一次请求不按退避节奏重试,再问要等一件可能改变答案的事)/ `transient`(退避重试)两词,语义在本表定义。
|
|
19
19
|
*
|
|
20
20
|
* ## 解析一律剥未知键
|
|
21
21
|
* 与包内 api 契约的前向兼容同律(新键恒为加性)。同时这也是一条安全律:`secret` 只在 `active` 臂的形里 —— 别的臂即使收到也剥掉,
|
|
@@ -27,6 +27,7 @@ import { SANDBOX_GIT_MAX_ORIGINS, SandboxGitOrigin, SandboxGitOriginList } from
|
|
|
27
27
|
import { PrincipalIncarnation } from "./auth-bridge.js";
|
|
28
28
|
import { NonEmptyString, PrincipalString, SafeCount } from "./wire-scalars.js";
|
|
29
29
|
import { deepFreeze } from "../deep-freeze.js";
|
|
30
|
+
import { buildRefusalTable } from "./refusal-table.js";
|
|
30
31
|
// ── 逐 origin 判定序表 ─────────────────────────────────────────────────────────────────────────────────────────────
|
|
31
32
|
/**
|
|
32
33
|
* 逐 origin 判定序表(11 行,序即判定序)。每行 `{ state, reason? }`:命中这一行的 origin 的应答是这个状态与这个原因。
|
|
@@ -119,12 +120,17 @@ export const SandboxGitCredentialAnswer = z.object({
|
|
|
119
120
|
origins: z.array(SandboxGitOriginAnswer).min(1).max(SANDBOX_GIT_MAX_ORIGINS),
|
|
120
121
|
});
|
|
121
122
|
// ── 整次拒答 ───────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
122
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* `permanence` 两词(凭据平面各只口共用这一张):
|
|
125
|
+
* · `terminal` = 这一次请求不按退避节奏重试;再问要等一件可能改变答案的事(用户的动作 —— 重新登录续上委托、去授权地址授权;运维的修复 —— 改配置并重启;
|
|
126
|
+
* 或收方自己的下一次连接 / 发送)。收方可以为这类词设一个低频的复查,那是收方的处置表,不在这里;
|
|
127
|
+
* · `transient` = 退避重试。
|
|
128
|
+
*/
|
|
123
129
|
export const SANDBOX_GIT_PERMANENCE = deepFreeze(["terminal", "transient"]);
|
|
124
130
|
/**
|
|
125
131
|
* 凭据平面共享拒答表(九个词):同一凭据平面的各只口都从它派生(`sandbox_git` 凭据取值口如此,同一平面的后续取值口同样如此),
|
|
126
132
|
* 每个词的 HTTP 状态集与 `permanence` 只在这里写一次。
|
|
127
|
-
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal
|
|
133
|
+
* `plane_misconfigured` = 凭据平面在答方配置错 —— `terminal`,运维修正配置之前再问也不会成功(不按退避节奏重试;运维修复是那件可能改变答案的事)。
|
|
128
134
|
*/
|
|
129
135
|
export const CREDENTIAL_PLANE_REFUSALS = deepFreeze({
|
|
130
136
|
caller_not_admitted: { statuses: [401, 403], permanence: "terminal" },
|
|
@@ -143,24 +149,18 @@ const SANDBOX_GIT_OWN_REFUSALS = deepFreeze({
|
|
|
143
149
|
scope_mismatch: { statuses: [403], permanence: "terminal" },
|
|
144
150
|
handle_invalid: { statuses: [401], permanence: "transient" },
|
|
145
151
|
});
|
|
146
|
-
/** 同一个词写了两遍 ⇒ 模块加载即抛(次序表是公开事实,重复的词会让派生表静默少一行)。原样交回入参(元组类型不丢)。 */
|
|
147
|
-
function wordsListedOnce(words) {
|
|
148
|
-
if (new Set(words).size !== words.length)
|
|
149
|
-
throw new Error("SANDBOX_GIT_REFUSAL_ORDER lists a word twice");
|
|
150
|
-
return words;
|
|
151
|
-
}
|
|
152
152
|
/** 上一版的十个词保持原序,新词只追加在尾部 —— 调整既有词的次序是破坏性变更。 */
|
|
153
|
-
const SANDBOX_GIT_REFUSAL_ORDER =
|
|
153
|
+
const SANDBOX_GIT_REFUSAL_ORDER = [
|
|
154
154
|
"caller_not_admitted", "scope_mismatch", "incarnation_mismatch", "request_invalid", "principal_not_live",
|
|
155
155
|
"delegation_required", "vault_disabled", "vault_frozen", "handle_invalid", "vault_unavailable", "plane_misconfigured",
|
|
156
|
-
]
|
|
157
|
-
const SANDBOX_GIT_REFUSAL_ROWS = { ...CREDENTIAL_PLANE_REFUSALS, ...SANDBOX_GIT_OWN_REFUSALS };
|
|
156
|
+
];
|
|
158
157
|
/**
|
|
159
158
|
* 整次拒答词 → 它的 HTTP 状态集(中心答这个词时用其一)与 `permanence`。**一个错误词的 permanence 是固定的**,拒体里再带一份只为让收方不必查表 ——
|
|
160
159
|
* 两处不一致就是畸形应答({@link SandboxGitCredentialRefusal} 拒)。收方怎么处置某个词(例如哪些 terminal 可由用户动作恢复)是收方的状态机,不在这里。
|
|
161
|
-
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(
|
|
160
|
+
* 表由 {@link CREDENTIAL_PLANE_REFUSALS} 与本口自有两词按声明的次序派生(复用同一行对象,不抄行;次序表重复词即抛、与两张来源表不恰好互为全集即编译红 ——
|
|
161
|
+
* 派生机关在包内私有叶 `./refusal-table`,凭据平面各只口共用一份)。
|
|
162
162
|
*/
|
|
163
|
-
export const SANDBOX_GIT_REFUSALS =
|
|
163
|
+
export const SANDBOX_GIT_REFUSALS = buildRefusalTable("SANDBOX_GIT_REFUSAL_ORDER", CREDENTIAL_PLANE_REFUSALS, SANDBOX_GIT_OWN_REFUSALS, SANDBOX_GIT_REFUSAL_ORDER);
|
|
164
164
|
/** 整次拒答词表(运行期;表的键,按声明的次序)。 */
|
|
165
165
|
export const SANDBOX_GIT_REFUSAL_ERRORS = deepFreeze(Object.keys(SANDBOX_GIT_REFUSALS));
|
|
166
166
|
/** 整次拒答的体:`{ error, permanence, message }`。`message` 是中心的诊断句(收方不据它判,可为空串)。 */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type RefusalSource = Readonly<Record<string, object>>;
|
|
2
|
+
/** 次序表与两张来源表「恰好」互为全集、两张来源表不重名 ⇒ `unknown`(不收窄实参);否则 `never`(实参不可赋 ⇒ 编译红)。 */
|
|
3
|
+
type OrderIsExact<Shared, Own, Word> = [
|
|
4
|
+
Exclude<keyof Shared | keyof Own, Word>,
|
|
5
|
+
Exclude<Word, keyof Shared | keyof Own>,
|
|
6
|
+
Extract<keyof Shared, keyof Own>
|
|
7
|
+
] extends [never, never, never] ? unknown : never;
|
|
8
|
+
/** 派生表的型:次序表里的每个词 → 来源里那一行的型。 */
|
|
9
|
+
type RefusalTableOf<Shared, Own, Word extends PropertyKey> = {
|
|
10
|
+
readonly [W in Word]: W extends keyof Own ? Own[W] : W extends keyof Shared ? Shared[W] : never;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 由共享表与自有表按次序表派生一只口的拒答表(见模块头注 ①–④)。`orderName` 只用于抛句(`<orderName> lists a word twice`)。
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildRefusalTable<Shared extends RefusalSource, Own extends RefusalSource, const Order extends readonly ((keyof Shared & string) | (keyof Own & string))[]>(orderName: string, shared: Shared, own: Own, order: Order & OrderIsExact<Shared, Own, Order[number]>): RefusalTableOf<Shared, Own, Order[number]>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `api/refusal-table` —— 包内私有模块(不在主桶、不在任何子路径):凭据平面各只口的拒答表从共享表派生的那一套机关,一处定义、各口调用。
|
|
3
|
+
*
|
|
4
|
+
* 一只口的拒答表 = 凭据平面共享拒答表(`CREDENTIAL_PLANE_REFUSALS`,`./credentials`)的全部词 + 这只口自有的词,按这只口声明的次序排。
|
|
5
|
+
* {@link buildRefusalTable} 做四件事:
|
|
6
|
+
* ① 次序表里同一个词写了两遍 ⇒ 调用即抛(次序表是公开事实,重复的词会让派生表静默少一行);抛句带次序表的名字;
|
|
7
|
+
* ② 编译期三项核:来源(共享表 + 自有表)里每个词都在次序表里 · 次序表里每个词都在来源里 · 共享表与自有表没有同名的词 ——
|
|
8
|
+
* 不成立 ⇒ 次序表那个实参的型是 `never`,调用处编译红(不留运行期语句);
|
|
9
|
+
* ③ 合行复用来源里的同一只行对象(不抄行),按次序逐项构造;
|
|
10
|
+
* ④ 整只表深冻结。
|
|
11
|
+
* 返回型逐词取来源里那一行的型(状态码元组、permanence 单词都是字面量,不放宽)。
|
|
12
|
+
*
|
|
13
|
+
* 不导出给消费方:消费方要的是派生出来的表(`SANDBOX_GIT_REFUSALS` / `CONNECTOR_ASSERTION_REFUSALS`),不是这只机关。纯、浏览器安全。
|
|
14
|
+
*/
|
|
15
|
+
import { deepFreeze } from "../deep-freeze.js";
|
|
16
|
+
/**
|
|
17
|
+
* 由共享表与自有表按次序表派生一只口的拒答表(见模块头注 ①–④)。`orderName` 只用于抛句(`<orderName> lists a word twice`)。
|
|
18
|
+
*/
|
|
19
|
+
export function buildRefusalTable(orderName, shared, own, order) {
|
|
20
|
+
if (new Set(order).size !== order.length)
|
|
21
|
+
throw new Error(`${orderName} lists a word twice`);
|
|
22
|
+
const rows = { ...shared, ...own };
|
|
23
|
+
return deepFreeze(Object.fromEntries(order.map((word) => [word, rows[word]])));
|
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./api/pull-token.js";
|
|
|
40
40
|
export * from "./api/feedback.js";
|
|
41
41
|
export * from "./api/credentials.js";
|
|
42
42
|
export * from "./api/lifecycle-events.js";
|
|
43
|
+
export * from "./api/connector-assertions.js";
|
|
43
44
|
export * from "./sandbox-git.js";
|
|
44
45
|
export * from "./web-admin-env.js";
|
|
45
46
|
export * from "./web-admin-credential.js";
|
|
@@ -58,3 +59,5 @@ export * from "./mcp-entry-credential.js";
|
|
|
58
59
|
export * from "./connector-authorize-url.js";
|
|
59
60
|
export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js";
|
|
60
61
|
export * from "./center-refs.js";
|
|
62
|
+
export * from "./tighten-only-seat-limits.js";
|
|
63
|
+
export { mutableCopyOf, type MutableCopy } from "./mutable-copy.js";
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./api/pull-token.js"; // scope-bound token FORM + minting rule (o
|
|
|
40
40
|
export * from "./api/feedback.js"; // /bug report wire contract: FeedbackSubmitRequest (POST body) + FeedbackWire / FeedbackListResponse + the two caps, pure/browser-safe
|
|
41
41
|
export * from "./api/credentials.js"; // 14.7.0: the credential port's `sandbox_git` wire (barrel only, no subpath): SandboxGitCredentialRequest / CredentialHandleAnswer / CredentialResolveRequest / SandboxGitCredentialAnswer (per-origin SandboxGitOriginAnswer) / SandboxGitCredentialRefusal + the three word tables (SANDBOX_GIT_ORIGIN_VERDICTS → _STATES / _REASONS, SANDBOX_GIT_REFUSALS → _ERRORS, SANDBOX_GIT_PERMANENCE), pure/browser-safe
|
|
42
42
|
export * from "./api/lifecycle-events.js"; // 29.0.0: the user-lifecycle-event wire (barrel only, no subpath): PRINCIPAL_LIFECYCLE_EVENT_KINDS (five words) + PrincipalLifecycleEvent (unknown keys stripped, discriminated by `kind`; the two `membership.*` arms carry `scope`) + PrincipalLifecycleEventPage { events, head, next } + LIFECYCLE_PAGE_REFUSALS (four words → status; 410 bodies carry `head`) / LifecyclePageRefusal + the reconcile pair PrincipalReconcileRequest (1–PRINCIPAL_RECONCILE_MAX_ITEMS) / PrincipalReconcileAnswer (PrincipalStanding, discriminated by `standing`), pure/browser-safe
|
|
43
|
+
export * from "./api/connector-assertions.js"; // the connector assertion mint's wire (barrel only, no subpath): ConnectorAssertionRequest (STRICT object, four keys) / ConnectorAssertionAnswer { assertion, expiresAt } / ConnectorAssertionRefusal (discriminated by `error`; only authorization_required carries authorizeUrl) + CONNECTOR_ASSERTION_REFUSALS → _ERRORS (the credential plane's nine shared words + the mint's own five) + compareDialTargets (same / different / unreadable, DIAL_TARGET_COMPARISONS — the mint's "same dial target?" test, not a registry dedup judge), pure/browser-safe
|
|
43
44
|
export * from "./sandbox-git.js"; // 14.7.0: the sandbox git plane's origin form (isSandboxGitOrigin — a string equal to its own WHATWG origin) + the `sandboxGit` effective-config block (SandboxGitConfig: origins ≤ 16, each { origin, connectUrl }), pure/browser-safe
|
|
44
45
|
export * from "./web-admin-env.js"; // WEB_ADMIN_ENV — every env name an engine reads to reach web-admin (one table; a leaf module), pure/browser-safe
|
|
45
46
|
export * from "./web-admin-credential.js"; // S-698 web-admin credential FILE contract: WebAdminCredentialEnvelope (user-session envelope, strict) + parseWebAdminCredentialFile (bare / envelope / unreadable — the one discrimination law) + judgeWebAdminCredentialDeclaration(env, credential) (pick-exactly-one over the credential's WEB_ADMIN_ENV pair; WEB_ADMIN_CREDENTIALS = access | assertion), pure/browser-safe
|
|
@@ -58,6 +59,8 @@ export * from "./mcp-entry-credential.js"; // 29.0.0: the MCP http entry's crede
|
|
|
58
59
|
export * from "./connector-authorize-url.js"; // 29.0.0: the hosted connector authorization address (connectorAuthorizeUrlOf / connectorAuthorizeUrlFlaws / CONNECTOR_AUTHORIZE_QUERY / CONNECTOR_AUTHORIZE_URL_FLAWS — one route form, the assembler and its judge in one module), pure/browser-safe
|
|
59
60
|
export { REMOTE_MCP_SERVER_NAME_PREFIX } from "./mcp-server-name.js"; // the MCP server-name prefix reserved for the remote MCP servers a device executor offers (mount name = prefix + the executor's server name); the predicate and its sentence stay package-private — the request plane's MCP name judges (isUsableMcpServerName / describeBadMcpServerName) read them; the config plane's McpServerSpec.name accepts the prefix (refusing it would be a validation tightening — a major), pure/browser-safe
|
|
60
61
|
export * from "./center-refs.js"; // resolveCenterRefs(refs, lookup) — THE center-roster reference resolver: one verdict word per member (missing_name / not_a_string / read_threw, CENTER_REF_FAULTS), one whole verdict (resolved / unresolved / refs_unreadable, CENTER_REFS_VERDICTS); the refs record is read by the public readPlainStringRecord, the lookup is the caller's, it reads no process.env; pure/browser-safe
|
|
62
|
+
export * from "./tighten-only-seat-limits.js"; // acceptance bounds the server applies to the request-face tighten-only seats (MAX_READ_DENY_STARS_PER_SEGMENT / MAX_READ_DENY_STARS_TOTAL / MAX_TIGHTEN_ONLY_SEAT_ENTRIES / MAX_READ_DENY_ENTRIES), pure/browser-safe
|
|
63
|
+
export { mutableCopyOf } from "./mutable-copy.js"; // THE mutable deep copy of a (deep-frozen) export — plain data (arrays / plain objects / Map / Set / Date / RegExp / primitives) rebuilt level by level, nothing frozen, the source untouched, aliases and cycles kept; functions / zod schemas / other objects / accessors (never called) / symbol keys ⇒ TypeError naming the path; MutableCopy<T> = T with readonly removed at every level; pure/browser-safe
|
|
61
64
|
// NOTE: the Node-fs-backed helpers (FileConfigStore + the file editor) are NOT in this barrel — they pull
|
|
62
65
|
// `node:fs`/`node:path` and would break a browser/client bundle that only wants the contract (e.g.
|
|
63
66
|
// web-admin's client components import the zod types through here). Import them from the Node-only
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 包根导出的表,容器层(数组 / 表 / Set / Map)都是**深冻结**的(包内冻结助手 `./deep-freeze`;表里的 RegExp 不冻):共享的闭集不许被某个读者原地改写。消费方要一份**能改的**副本时,这里是唯一的一只口 ——
|
|
3
|
+
* 浅拷贝(`[...X]` / `{ ...X }`)只解冻最外一层;`structuredClone` 对带 symbol 值的表(`EXTENSION_NAMESPACES` 的 `at` 里的 `ANY_INDEX`)与带函数 / zod schema 的表
|
|
4
|
+
* (`DOMAIN_SCHEMAS`)抛 `DataCloneError`,不说是哪一格。
|
|
5
|
+
*
|
|
6
|
+
* {@link mutableCopyOf} 的规则(纯数据 ⇒ 逐层新建的副本;别的 ⇒ 响亮拒,不交回半份):
|
|
7
|
+
* · **容器**逐层新建、任何一层都不冻:数组(同长;洞仍是洞)· 朴素对象(座位 `./plain-json-object` 的 `plain`;副本是寻常对象 `{}`,同 `structuredClone`)·
|
|
8
|
+
* `Map`(键与值都拷)· `Set` · `Date`(按时间值新建)· `RegExp`(`new RegExp(source, flags)`,`lastIndex` 归零)。这四种按**内部槽**认(见下),原型被换掉
|
|
9
|
+
* (含换成 `null`、座位因此读成朴素)的也照这四种拷。
|
|
10
|
+
* 数组拷它的各个下标(可枚举与否都拷,同内核的数组读法 —— 不可枚举的**数据**下标进副本;下标是访问器的,可枚举与否都拒);其余容器拷自有的**可枚举串键**数据属性,照原序;不可枚举的自有属性(数据或访问器)不进副本、
|
|
11
|
+
* 访问器也不被调(同 `Object.keys` / 展开 / `structuredClone`;冻结助手装在 Set / Map 上的只读修改方法就是这一类,所以副本是普通的、能 `add` / `set` 的集合)。
|
|
12
|
+
* 原型不是数据:副本的原型是本 realm 的内建原型(`Object.prototype` / `Array.prototype` / …),与源共享原型这件事不算共享可变状态。
|
|
13
|
+
* 数组的 `length` 与 RegExp 的 `lastIndex` 是语言规定的不可配置属性,副本里照样可写、不可配置。
|
|
14
|
+
* · **原始值**(含 symbol、bigint、`undefined`)原样交回。
|
|
15
|
+
* · **别名**:同一只源对象在图里出现几次,副本里就是同一只新对象出现几次;**环**照拷(副本里同样成环),不死循环;实现是迭代的,深度只受内存限制。
|
|
16
|
+
* · **拒**(`TypeError`,句子是「`mutableCopyOf: <路径> <它是什么>; only plain data is copied …`」,路径从根 `value` 起:`.key` / `["键"]` / `[下标]` /
|
|
17
|
+
* `.get(<Map 键>)` / `.keys()[i]` / `.values()[i]`;外来的键名经 `./caller-text-echo` 有界回显):
|
|
18
|
+
* 函数 · zod schema · 其余对象(类实例 —— 继承上面四种或 `Array` 的除外,见「已知的边」—— 与别的 realm 认不出的对象)·
|
|
19
|
+
* 可枚举的访问器属性(getter / setter —— **getter 从不被调**;数组的访问器下标可枚举与否都拒)·
|
|
20
|
+
* 自有 symbol 键(副本拷不了它,不静默丢)· 数组上挂的非下标键 · 检视就抛的对象(已撤销的 Proxy 等,全包那一句「检视不了」)。
|
|
21
|
+
* 对「带 schema / 函数的导出」(如 `DOMAIN_SCHEMAS`)整只拒 —— 那不是数据表。
|
|
22
|
+
* · 原值一个字节不动:只读描述符、不写源对象;也从不 `[[Get]]` 源对象的成员(读法走内核 `./own-key-read`:一次列成员、每个成员一份描述符,值只从描述符取)。
|
|
23
|
+
*
|
|
24
|
+
* 认 `Map` / `Set` / `Date` / `RegExp` 用的是本 realm 内建的**品牌检查**,以源对象为接收者调:`Map` / `Set` 是模块加载时取的 `has`、`Date` 是加载时取的 `getTime`、
|
|
25
|
+
* `RegExp` 是 `RegExp.prototype` 上的 `source` 与各旗的读取器(读取器取不成加载时的一份,调用时从内建原型上读)。不读源对象自己的成员、不调它的任何代码,
|
|
26
|
+
* 另一 realm 造的这四种也认得出。新建副本用的构造器、填 Map / Set 用的 `forEach` / `set` / `add` 同样是加载时取的。Map / Set 先经内建 `forEach` 拍一份条目快照
|
|
27
|
+
* (拍的时候不检视任何成员),再逐条检视、拷贝 —— 快照拍下之后,检视成员时跑到的 Proxy 陷阱改了源集合,副本也只含快照里的条目,遍历有终点。
|
|
28
|
+
* 快照在**填这只集合时**才拍:排在它自有的可枚举属性之后(那些属性的值先被检视),也排在工作队列里先于它的容器之后;在那之前跑到的 Proxy 陷阱对源集合的修改会进副本。
|
|
29
|
+
* **信任边界**:本 realm 的内建(全局构造器、内建原型上的读取器)在模块加载之后被人替换,不在这只口的防护范围内(包里只有安全轴的朴素数组判据做这一层)。
|
|
30
|
+
* **已知的边**:继承这四种的类的实例按基类拷(子类身份与它原型上的方法不进副本);`Array.isArray` 答真的值 —— 继承 `Array` 的类的实例、包着数组的 Proxy —— 座位读成数组,
|
|
31
|
+
* 拷成普通数组、不拒(子类身份与原型方法同样不进副本);Proxy 的陷阱在检视时照样被调(语言里认不出一只 Proxy),它说了什么副本就是什么。
|
|
32
|
+
*
|
|
33
|
+
* 返回型 {@link MutableCopy}:逐层去掉 `readonly`(`ReadonlyMap` ⇒ `Map`、`ReadonlySet` ⇒ `Set`、只读数组 / 元组 ⇒ 可写数组 / 元组);函数与 schema 位的型原样(运行期那里抛)。
|
|
34
|
+
* 型按**声明的键**映射:声明里有、运行期却是不可枚举的键,型里仍在、副本里没有(型说不出可枚举性)。
|
|
35
|
+
* 纯函数、pure/browser-safe。
|
|
36
|
+
*/
|
|
37
|
+
import type { z } from "zod";
|
|
38
|
+
/** `T` 的可改形:逐层去掉 `readonly`。`any` / `unknown`、原始值、函数、zod schema(运行期这两种抛)、`RegExp`、`Date` 原样;`ReadonlyMap` / `ReadonlySet` ⇒ `Map` / `Set`;数组、元组与对象逐键映射(可选性保留)。 */
|
|
39
|
+
export type MutableCopy<T> = unknown extends T ? T : MutableCopyOfKnown<T>;
|
|
40
|
+
type MutableCopyOfKnown<T> = T extends string | number | boolean | bigint | symbol | null | undefined ? T : T extends ((...args: never[]) => unknown) | z.core.$ZodType ? T : T extends RegExp ? RegExp : T extends Date ? Date : T extends ReadonlyMap<infer K, infer V> ? Map<MutableCopy<K>, MutableCopy<V>> : T extends ReadonlySet<infer M> ? Set<MutableCopy<M>> : {
|
|
41
|
+
-readonly [P in keyof T]: MutableCopy<T[P]>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* 取一份可改的深副本:纯数据逐层新建(任何一层都不冻,原值不动),别名保别名、环照拷;不是纯数据的地方抛 `TypeError` 点出路径(规则全文见本模块头注)。
|
|
45
|
+
* 用途:包根导出的闭集都是深冻结的,要在它的基础上改出一份自己的(排序、加一行、改一格)时调它,例:`const rules = mutableCopyOf(EXTENSION_NAMESPACES); rules.models?.push(…)`。
|
|
46
|
+
*/
|
|
47
|
+
export declare function mutableCopyOf<T>(value: T): MutableCopy<T>;
|
|
48
|
+
export {};
|