carrick 0.3.153 → 0.3.155
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/bin/carrick.mjs +26 -4
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +37 -3
- package/dist/contract.js +8 -0
- package/dist/contract.js.map +1 -1
- package/dist/facts/diff.d.ts +27 -0
- package/dist/facts/diff.js +134 -0
- package/dist/facts/diff.js.map +1 -0
- package/dist/facts/enabled.d.ts +2 -0
- package/dist/facts/enabled.js +9 -0
- package/dist/facts/enabled.js.map +1 -0
- package/dist/facts/fetch.d.ts +48 -0
- package/dist/facts/fetch.js +235 -0
- package/dist/facts/fetch.js.map +1 -0
- package/dist/facts/files.d.ts +21 -0
- package/dist/facts/files.js +58 -0
- package/dist/facts/files.js.map +1 -0
- package/dist/facts/lines.d.ts +70 -0
- package/dist/facts/lines.js +335 -0
- package/dist/facts/lines.js.map +1 -0
- package/dist/facts/match.d.ts +91 -0
- package/dist/facts/match.js +1122 -0
- package/dist/facts/match.js.map +1 -0
- package/dist/facts/peers.d.ts +48 -0
- package/dist/facts/peers.js +143 -0
- package/dist/facts/peers.js.map +1 -0
- package/dist/facts/refresh-run.d.ts +2 -0
- package/dist/facts/refresh-run.js +18 -0
- package/dist/facts/refresh-run.js.map +1 -0
- package/dist/facts/rules/packages.d.ts +16 -0
- package/dist/facts/rules/packages.js +157 -0
- package/dist/facts/rules/packages.js.map +1 -0
- package/dist/facts/rules/same-name.d.ts +28 -0
- package/dist/facts/rules/same-name.js +131 -0
- package/dist/facts/rules/same-name.js.map +1 -0
- package/dist/facts/store.d.ts +119 -0
- package/dist/facts/store.js +341 -0
- package/dist/facts/store.js.map +1 -0
- package/dist/git-remote.d.ts +6 -0
- package/dist/git-remote.js +37 -0
- package/dist/git-remote.js.map +1 -0
- package/dist/hook/apply-patch.d.ts +23 -0
- package/dist/hook/apply-patch.js +92 -0
- package/dist/hook/apply-patch.js.map +1 -1
- package/dist/hook/bash-targets.d.ts +8 -0
- package/dist/hook/bash-targets.js +23 -11
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/edit-flow.d.ts +29 -2
- package/dist/hook/edit-flow.js +80 -29
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/late.d.ts +29 -0
- package/dist/hook/late.js +121 -26
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-bash.js +45 -22
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.d.ts +16 -1
- package/dist/hook/post-edit.js +177 -13
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +8 -12
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.d.ts +2 -0
- package/dist/hook/post-search.js +25 -0
- package/dist/hook/post-search.js.map +1 -0
- package/dist/hook/probe.d.ts +18 -3
- package/dist/hook/probe.js +30 -6
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/rechecks.d.ts +66 -11
- package/dist/hook/rechecks.js +115 -29
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/refresh.d.ts +9 -0
- package/dist/hook/refresh.js +10 -0
- package/dist/hook/refresh.js.map +1 -1
- package/dist/hook/reuse.d.ts +16 -2
- package/dist/hook/reuse.js +49 -6
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-key.d.ts +12 -0
- package/dist/hook/session-key.js +30 -0
- package/dist/hook/session-key.js.map +1 -0
- package/dist/hook/session-start.js +14 -7
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stop-wait.d.ts +2 -9
- package/dist/hook/stop-wait.js +96 -113
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/stop.js +13 -8
- package/dist/hook/stop.js.map +1 -1
- package/dist/hook/subagent-stop.d.ts +2 -0
- package/dist/hook/subagent-stop.js +45 -0
- package/dist/hook/subagent-stop.js.map +1 -0
- package/dist/hook/timings.d.ts +72 -0
- package/dist/hook/timings.js +175 -0
- package/dist/hook/timings.js.map +1 -0
- package/dist/hook/user-prompt.js +17 -13
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hook/worktree.d.ts +11 -0
- package/dist/hook/worktree.js +27 -1
- package/dist/hook/worktree.js.map +1 -1
- package/dist/init/repo-copies.d.ts +6 -0
- package/dist/init/repo-copies.js +7 -3
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/repos.d.ts +2 -2
- package/dist/init/repos.js +1 -34
- package/dist/init/repos.js.map +1 -1
- package/dist/init/settings.js +25 -13
- package/dist/init/settings.js.map +1 -1
- package/dist/render.d.ts +8 -33
- package/dist/render.js +42 -120
- package/dist/render.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/hooks.json +44 -3
- package/scripts/install-scanned-deps.sh +25 -2
- package/sidecar/dist/src/capture/anchors.d.ts +12 -1
- package/sidecar/dist/src/capture/anchors.js +28 -47
- package/sidecar/dist/src/capture/api.d.ts +41 -1
- package/sidecar/dist/src/capture/augmentations.d.ts +2 -0
- package/sidecar/dist/src/capture/augmentations.js +1 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +12 -1
- package/sidecar/dist/src/capture/check-classify.js +43 -0
- package/sidecar/dist/src/capture/check-deep.d.ts +44 -1
- package/sidecar/dist/src/capture/check-deep.js +161 -2
- package/sidecar/dist/src/capture/check.js +23 -2
- package/sidecar/dist/src/capture/checkout.d.ts +9 -3
- package/sidecar/dist/src/capture/checkout.js +12 -5
- package/sidecar/dist/src/capture/deep-walk.d.ts +25 -0
- package/sidecar/dist/src/capture/deep-walk.js +41 -0
- package/sidecar/dist/src/capture/deno-project.d.ts +22 -0
- package/sidecar/dist/src/capture/deno-project.js +48 -1
- package/sidecar/dist/src/capture/index.d.ts +3 -1
- package/sidecar/dist/src/capture/index.js +14 -4
- package/sidecar/dist/src/capture/machinery.d.ts +8 -53
- package/sidecar/dist/src/capture/machinery.js +10 -157
- package/sidecar/dist/src/capture/node-builder.d.ts +6 -0
- package/sidecar/dist/src/capture/self-check.d.ts +7 -0
- package/sidecar/dist/src/capture/self-check.js +44 -1
- package/sidecar/dist/src/capture/site-node.d.ts +166 -0
- package/sidecar/dist/src/capture/site-node.js +570 -0
- package/sidecar/dist/src/capture/tool-env.d.ts +12 -0
- package/sidecar/dist/src/capture/tool-env.js +26 -0
- package/sidecar/dist/src/default-library.d.ts +39 -0
- package/sidecar/dist/src/default-library.js +132 -0
- package/sidecar/dist/src/definition-resolver.js +2 -0
- package/sidecar/dist/src/index.js +1 -1
- package/sidecar/dist/src/library-claims.d.ts +2 -0
- package/sidecar/dist/src/library-claims.js +387 -37
- package/sidecar/dist/src/node-index.d.ts +2 -0
- package/sidecar/dist/src/node-index.js +5 -1
- package/sidecar/dist/src/position-rows.d.ts +78 -7
- package/sidecar/dist/src/position-rows.js +343 -18
- package/sidecar/dist/src/project-loader.d.ts +3 -3
- package/sidecar/dist/src/project-loader.js +18 -9
- package/sidecar/dist/src/retype.d.ts +13 -0
- package/sidecar/dist/src/retype.js +126 -0
- package/sidecar/dist/src/type-inferrer.d.ts +47 -145
- package/sidecar/dist/src/type-inferrer.js +102 -529
- package/sidecar/dist/src/types.d.ts +64 -2
- package/sidecar/dist/src/validators.d.ts +806 -142
- package/sidecar/dist/src/validators.js +12 -1
|
@@ -76,8 +76,28 @@ const ROLE_PROTOCOLS = {
|
|
|
76
76
|
socket: new Set(['socket']),
|
|
77
77
|
broker: new Set(['message']),
|
|
78
78
|
in_process_bus: new Set(['message']),
|
|
79
|
+
// A direct function call is no claim protocol: the scanner reads it as `invoke`.
|
|
80
|
+
invoke_client: new Set(),
|
|
79
81
|
none: new Set(),
|
|
80
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* A maker's `protocol` (amendment 11): only `graphql` is a make protocol, on
|
|
85
|
+
* `server_framework` only (any other role is `protocol_role`), and it takes
|
|
86
|
+
* `runs`, with `prefix` optional, and no `name`, `base`, `handler` or
|
|
87
|
+
* `key_labels`. Undefined when the check has no make protocol or it is well
|
|
88
|
+
* formed; the make is then judged as any other.
|
|
89
|
+
*/
|
|
90
|
+
function makeProtocolRefusal(check) {
|
|
91
|
+
const claim = check.claim;
|
|
92
|
+
if (claim.kind !== 'make' || claim.protocol === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (claim.protocol !== 'graphql')
|
|
95
|
+
return 'claim_invalid';
|
|
96
|
+
if (check.role !== 'server_framework')
|
|
97
|
+
return 'protocol_role';
|
|
98
|
+
const stray = claim.name !== undefined || claim.base !== undefined || claim.handler !== undefined || claim.key_labels !== undefined;
|
|
99
|
+
return claim.runs === undefined || stray ? 'claim_invalid' : undefined;
|
|
100
|
+
}
|
|
81
101
|
/** The type names a `document` name slot accepts; a string is accepted too. */
|
|
82
102
|
const DOCUMENT_TYPES = new Set([
|
|
83
103
|
'DocumentNode',
|
|
@@ -157,6 +177,12 @@ const HTTP_V2_RULES = { http: false, message: true, ops: new Set(['request']), m
|
|
|
157
177
|
* the method from the member's own name (`get` registers GET) or from a slot.
|
|
158
178
|
*/
|
|
159
179
|
const SERVER_RULES = { http: false, message: true, ops: new Set(['receive']), methods: ROUTE_METHODS };
|
|
180
|
+
/**
|
|
181
|
+
* A client that calls a deployed function by its name (carrick#3439): the
|
|
182
|
+
* message checks for its one op, `request`. It never receives: the function's
|
|
183
|
+
* handler is declared in `carrick.json`, not read from a library.
|
|
184
|
+
*/
|
|
185
|
+
const INVOKE_RULES = { http: false, message: true, ops: new Set(['request']) };
|
|
160
186
|
/**
|
|
161
187
|
* A server's rules as `labelledMembers` reads them (carrick#2674): a `send`
|
|
162
188
|
* op is the reply a handler sends back through its reply parameter, on the
|
|
@@ -178,6 +204,7 @@ const ROLE_TABLE = {
|
|
|
178
204
|
socket: MESSAGE_RULES,
|
|
179
205
|
graphql_client: undefined,
|
|
180
206
|
server_framework: SERVER_RULES,
|
|
207
|
+
invoke_client: INVOKE_RULES,
|
|
181
208
|
none: undefined,
|
|
182
209
|
};
|
|
183
210
|
/**
|
|
@@ -672,13 +699,16 @@ export class LibraryClaimsVerifier {
|
|
|
672
699
|
};
|
|
673
700
|
const judgeCheck = (index) => {
|
|
674
701
|
const check = checks[index];
|
|
702
|
+
const makeProtocol = makeProtocolRefusal(check);
|
|
703
|
+
if (makeProtocol !== undefined)
|
|
704
|
+
return { outcome: unchecked(makeProtocol) };
|
|
675
705
|
const rules = rulesFor(check);
|
|
676
706
|
if (!rules)
|
|
677
707
|
return { outcome: unchecked('role_unsupported') };
|
|
678
708
|
// An export given two roles is classified two ways; neither is a fact.
|
|
679
709
|
if ((roles.get(exportKey(check))?.size ?? 0) > 1)
|
|
680
710
|
return { outcome: unchecked('role_conflict') };
|
|
681
|
-
if (placementInvalid(check.claim))
|
|
711
|
+
if (placementInvalid(check.claim) || handleMisplaced(check.claim) || orFileMisplaced(check.claim))
|
|
682
712
|
return { outcome: unchecked('claim_invalid') };
|
|
683
713
|
if (check.claim.kind === 'op' && check.claim.protocol !== undefined) {
|
|
684
714
|
if (!PROTOCOLS.has(check.claim.protocol))
|
|
@@ -885,7 +915,13 @@ export class LibraryClaimsVerifier {
|
|
|
885
915
|
defaultImport: file.statements[at + 1],
|
|
886
916
|
};
|
|
887
917
|
};
|
|
888
|
-
const read = this.readProbe(fromDir, imports, (_checker, reader, file) =>
|
|
918
|
+
const read = this.readProbe(fromDir, imports, (_checker, reader, file) => {
|
|
919
|
+
const made = packages.map((pkg, i) => reader.exportMakers(pkg, probeOf(file, i), only[pkg]));
|
|
920
|
+
// One decision for the whole call: the checker's cost is the sum over its specifiers.
|
|
921
|
+
const estimate = made.reduce((sum, each) => sum + each.foreignMakerMembers, 0);
|
|
922
|
+
const gated = estimate > (options.foreignMakerBudget ?? FOREIGN_MAKER_BUDGET);
|
|
923
|
+
return made.map(each => reader.makersOf(each, gated));
|
|
924
|
+
});
|
|
889
925
|
const importLines = [];
|
|
890
926
|
const buildLines = [];
|
|
891
927
|
const builtIndex = new Map();
|
|
@@ -934,7 +970,8 @@ export class LibraryClaimsVerifier {
|
|
|
934
970
|
typeExports.push({ ...built, name });
|
|
935
971
|
}
|
|
936
972
|
}
|
|
937
|
-
|
|
973
|
+
const gate = { gated: read[i].gated, leftOut: read[i].makersLeftOut };
|
|
974
|
+
return reader.listPackage(pkg, probeOf(file, i), maxEntries, only[pkg], options, typeExports, gate, (name, receiver) => {
|
|
938
975
|
const index = builtIndex.get(builtKey({ package: pkg, export: name }, receiver));
|
|
939
976
|
return index === undefined ? undefined : resolvedBuild(checker, file.statements[firstBuild + index]);
|
|
940
977
|
});
|
|
@@ -1253,6 +1290,45 @@ function placementInvalid(claim) {
|
|
|
1253
1290
|
const of = parseReceiver(claim.of);
|
|
1254
1291
|
return of === undefined || (of.maker === undefined && of.scope === undefined && of.type === undefined);
|
|
1255
1292
|
}
|
|
1293
|
+
/** The slots a claim's name sits at: one slot, or each of its parts. */
|
|
1294
|
+
function nameSlots(claim) {
|
|
1295
|
+
const name = claim.name;
|
|
1296
|
+
if (typeof name !== 'object' || name === null)
|
|
1297
|
+
return [];
|
|
1298
|
+
if ('parts' in name)
|
|
1299
|
+
return [...name.parts];
|
|
1300
|
+
return 'arg' in name ? [name] : [];
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* `handle: true` sits only on a scope's `mounts` (K1a); on any other slot
|
|
1304
|
+
* the claim is `claim_invalid`. `handle: false` is no flag.
|
|
1305
|
+
*/
|
|
1306
|
+
function handleMisplaced(claim) {
|
|
1307
|
+
const slots = nameSlots(claim);
|
|
1308
|
+
if (claim.kind === 'make')
|
|
1309
|
+
slots.push(claim.base, claim.prefix, claim.handler, claim.runs);
|
|
1310
|
+
if (claim.kind === 'scope')
|
|
1311
|
+
slots.push(claim.runs, claim.merges);
|
|
1312
|
+
if (claim.kind === 'op') {
|
|
1313
|
+
slots.push(claim.payload, claim.handler, claim.ack, claim.options, claim.method_key, claim.base);
|
|
1314
|
+
}
|
|
1315
|
+
return slots.some(slot => slot?.handle === true);
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* `or_file: true` sits only on a make's or an op's `handler` (QW-1); on any
|
|
1319
|
+
* other slot, a name or a name's parts included, the claim is
|
|
1320
|
+
* `claim_invalid`. `or_file: false` is no flag.
|
|
1321
|
+
*/
|
|
1322
|
+
function orFileMisplaced(claim) {
|
|
1323
|
+
const slots = nameSlots(claim);
|
|
1324
|
+
if (claim.kind === 'make')
|
|
1325
|
+
slots.push(claim.base, claim.prefix, claim.runs);
|
|
1326
|
+
if (claim.kind === 'scope')
|
|
1327
|
+
slots.push(claim.runs, claim.merges, claim.mounts);
|
|
1328
|
+
if (claim.kind === 'op')
|
|
1329
|
+
slots.push(claim.payload, claim.ack, claim.options, claim.method_key, claim.base);
|
|
1330
|
+
return slots.some(slot => slot?.or_file === true);
|
|
1331
|
+
}
|
|
1256
1332
|
/**
|
|
1257
1333
|
* Where a handler's request holds its path, method and body (#2474 R0,
|
|
1258
1334
|
* carrick#2674) is read on a receive op with a handler, and names `path`,
|
|
@@ -1434,17 +1510,25 @@ function readLocalRanges(fromDir) {
|
|
|
1434
1510
|
dir = parent;
|
|
1435
1511
|
}
|
|
1436
1512
|
}
|
|
1513
|
+
/** One slot's place in a `ClaimLayout`: its argument, and its key when it has one. */
|
|
1514
|
+
function slotKey(arg, key) {
|
|
1515
|
+
return key === undefined ? String(arg) : `${arg}.${key}`;
|
|
1516
|
+
}
|
|
1437
1517
|
/**
|
|
1438
1518
|
* Reads the declarations the probe imported, with the program's own checker.
|
|
1439
1519
|
* Every predicate is the contract's (carrick#1564, section 3), stated on the
|
|
1440
1520
|
* checker's public API, with the definitions the review amended.
|
|
1441
1521
|
*/
|
|
1522
|
+
/** How many deferred conditionals one object read follows into one another. */
|
|
1523
|
+
const MAX_CONDITIONAL_DEPTH = 8;
|
|
1442
1524
|
class DeclarationReader {
|
|
1443
1525
|
program;
|
|
1444
1526
|
probe;
|
|
1445
1527
|
host;
|
|
1446
1528
|
graph;
|
|
1447
1529
|
checker;
|
|
1530
|
+
/** Nesting of `isObjectConditional` reads in progress. */
|
|
1531
|
+
conditionalDepth = 0;
|
|
1448
1532
|
/** Names declaring files as position rows do: from the scan root, else the service root. */
|
|
1449
1533
|
pathNames;
|
|
1450
1534
|
/** The service root, as a realpath. */
|
|
@@ -2196,8 +2280,11 @@ class DeclarationReader {
|
|
|
2196
2280
|
const holding = [];
|
|
2197
2281
|
let best;
|
|
2198
2282
|
for (const signature of callee.signatures) {
|
|
2199
|
-
let result = this.messageSignatureOutcome(signature, layout.value, labels);
|
|
2200
|
-
if (
|
|
2283
|
+
let result = this.messageSignatureOutcome(signature, layout.value, labels, claim.protocol === 'graphql' ? declared => this.graphqlRunsFailure(declared) : undefined);
|
|
2284
|
+
if (claim.protocol !== 'graphql' &&
|
|
2285
|
+
result.outcome.verdict !== 'verified' &&
|
|
2286
|
+
result.outcome.reason.startsWith('runs_') &&
|
|
2287
|
+
collections !== undefined) {
|
|
2201
2288
|
const collected = collections();
|
|
2202
2289
|
if (collected !== undefined) {
|
|
2203
2290
|
result = this.messageSignatureOutcome(signature, layout.value, labels, declared => this.runsCollectionOutcome(signature, declared, collected));
|
|
@@ -2243,17 +2330,36 @@ class DeclarationReader {
|
|
|
2243
2330
|
* `arg`, read through a rest (`parameterAt`), takes what a verified
|
|
2244
2331
|
* `collects` scope of the request returns (`collectionSlotOutcome`), and
|
|
2245
2332
|
* the return is read as a plain scope's is.
|
|
2333
|
+
*
|
|
2334
|
+
* Path-less mounts and pass-throughs (K1a): a scope that binds (`mounts`,
|
|
2335
|
+
* or `runs` with `yields`) may carry none of the four, and then binds no
|
|
2336
|
+
* name. `mounts: { ..., handle: true }` is judged by `handlerFailure`
|
|
2337
|
+
* (the slot takes a middleware) instead of `mountsOutcome`. `passes: true`
|
|
2338
|
+
* stands alone: the member's value is its receiver, its call takes no
|
|
2339
|
+
* string the claim leaves unread (`nameSiblings`), and its return opens no
|
|
2340
|
+
* `>scope:` receiver.
|
|
2246
2341
|
*/
|
|
2247
2342
|
judgeScope(receiver, claim, built, collections) {
|
|
2248
|
-
|
|
2343
|
+
// A pass-through is a call's value, never a decorator (K1a).
|
|
2344
|
+
if (claim.form === 'decorate') {
|
|
2345
|
+
if (claim.passes === true)
|
|
2346
|
+
return { outcome: unchecked('claim_invalid') };
|
|
2249
2347
|
return { outcome: this.decorateScopeOutcome(receiver, claim) };
|
|
2348
|
+
}
|
|
2250
2349
|
if ((claim.runs === undefined) !== (claim.yields === undefined))
|
|
2251
2350
|
return { outcome: unchecked('claim_invalid') };
|
|
2252
2351
|
if (claim.mounts !== undefined && claim.runs !== undefined)
|
|
2253
2352
|
return { outcome: unchecked('claim_invalid') };
|
|
2254
|
-
const
|
|
2255
|
-
|
|
2353
|
+
const passes = claim.passes === true;
|
|
2354
|
+
const binds = claim.runs !== undefined || claim.mounts !== undefined;
|
|
2355
|
+
// A pass-through stands alone (K1a).
|
|
2356
|
+
if (passes && (binds || claim.yields !== undefined))
|
|
2357
|
+
return { outcome: unchecked('claim_invalid') };
|
|
2358
|
+
const carried = [claim.name, claim.collects, claim.merges, passes || undefined].filter(part => part !== undefined).length;
|
|
2359
|
+
// Exactly one carries the scope; a scope that binds may carry none (K1a).
|
|
2360
|
+
if (carried > 1 || (carried === 0 && !binds))
|
|
2256
2361
|
return { outcome: unchecked('claim_invalid') };
|
|
2362
|
+
const namelessMount = carried === 0 && claim.mounts !== undefined;
|
|
2257
2363
|
if ((claim.collects !== undefined || claim.merges !== undefined) &&
|
|
2258
2364
|
(claim.runs !== undefined || claim.mounts !== undefined)) {
|
|
2259
2365
|
return { outcome: unchecked('claim_invalid') };
|
|
@@ -2264,7 +2370,6 @@ class DeclarationReader {
|
|
|
2264
2370
|
return { outcome: unchecked('claim_invalid') };
|
|
2265
2371
|
}
|
|
2266
2372
|
const collected = merges === undefined ? undefined : collections?.();
|
|
2267
|
-
const binds = claim.runs !== undefined || claim.mounts !== undefined;
|
|
2268
2373
|
const layout = this.layout({ name: claim.name, runs: claim.runs, mounts: claim.mounts });
|
|
2269
2374
|
if ('failure' in layout)
|
|
2270
2375
|
return { outcome: layout.failure };
|
|
@@ -2277,14 +2382,24 @@ class DeclarationReader {
|
|
|
2277
2382
|
const holding = [];
|
|
2278
2383
|
let best;
|
|
2279
2384
|
for (const signature of callee.signatures) {
|
|
2280
|
-
|
|
2385
|
+
// A pass-through's call, and a name-less mount's, takes no string the
|
|
2386
|
+
// claim leaves unread (D2, `nameSiblings`): one taking a path would
|
|
2387
|
+
// serve under it. For the mount that is `claim_invalid` (K1a ruling).
|
|
2388
|
+
let result = this.messageSignatureOutcome(signature, layout.value, labels, undefined, passes || namelessMount ? [] : undefined);
|
|
2389
|
+
if (namelessMount && result.outcome.verdict === 'failed' && result.outcome.reason === 'name_ambiguous') {
|
|
2390
|
+
// Above every other overload's failure: the claim is the wrong spelling.
|
|
2391
|
+
result = { rank: 7, outcome: unchecked('claim_invalid') };
|
|
2392
|
+
}
|
|
2281
2393
|
if (result.rank === Infinity && claim.yields !== undefined) {
|
|
2282
2394
|
const given = this.yieldsOutcome(signature, claim.runs, claim.yields, receiver);
|
|
2283
2395
|
if (given)
|
|
2284
2396
|
result = { rank: 5, outcome: given };
|
|
2285
2397
|
}
|
|
2286
2398
|
if (result.rank === Infinity && claim.mounts !== undefined) {
|
|
2287
|
-
|
|
2399
|
+
// `handle` (K1a): the slot takes a middleware, judged as a handler is.
|
|
2400
|
+
const mounted = claim.mounts.handle === true
|
|
2401
|
+
? this.handlerFailure(this.mountedSlot(signature, claim.mounts))
|
|
2402
|
+
: this.mountsOutcome(signature, claim.mounts, receiver);
|
|
2288
2403
|
if (mounted)
|
|
2289
2404
|
result = { rank: 5, outcome: mounted };
|
|
2290
2405
|
}
|
|
@@ -2311,7 +2426,8 @@ class DeclarationReader {
|
|
|
2311
2426
|
// The member's own declarations, as a verified op carries them (#2636).
|
|
2312
2427
|
const declarations = this.declarationsOf({ signatures: holding, named: callee.named });
|
|
2313
2428
|
const outcome = declarations.length > 0 ? { verdict: 'verified', declarations } : VERIFIED;
|
|
2314
|
-
|
|
2429
|
+
// A binding scope and a pass-through open no `>scope:` receiver.
|
|
2430
|
+
return binds || passes ? { outcome } : { outcome, holding };
|
|
2315
2431
|
}
|
|
2316
2432
|
return { outcome: best.outcome };
|
|
2317
2433
|
}
|
|
@@ -2326,11 +2442,7 @@ class DeclarationReader {
|
|
|
2326
2442
|
* Undefined when it holds.
|
|
2327
2443
|
*/
|
|
2328
2444
|
mountsOutcome(signature, mounts, receiver) {
|
|
2329
|
-
|
|
2330
|
-
if (declared !== undefined && mounts.key !== undefined) {
|
|
2331
|
-
const property = this.declaredProperty(declared, mounts.key);
|
|
2332
|
-
declared = property ? this.checker.getTypeOfSymbol(property) : undefined;
|
|
2333
|
-
}
|
|
2445
|
+
const declared = this.mountedSlot(signature, mounts);
|
|
2334
2446
|
if (declared === undefined)
|
|
2335
2447
|
return failed('param_missing');
|
|
2336
2448
|
const slot = this.throughConstraint(declared);
|
|
@@ -2347,6 +2459,14 @@ class DeclarationReader {
|
|
|
2347
2459
|
return erased ? undefined : failed('mounts_not_instance');
|
|
2348
2460
|
return this.checker.isTypeAssignableTo(receiver.type, slot) ? undefined : failed('mounts_not_instance');
|
|
2349
2461
|
}
|
|
2462
|
+
/** The parameter a scope's `mounts` names: through a rest, then at `key`. */
|
|
2463
|
+
mountedSlot(signature, mounts) {
|
|
2464
|
+
const declared = this.keyParameterAt(signature, mounts.arg);
|
|
2465
|
+
if (declared === undefined || mounts.key === undefined)
|
|
2466
|
+
return declared;
|
|
2467
|
+
const property = this.declaredProperty(declared, mounts.key);
|
|
2468
|
+
return property ? this.checker.getTypeOfSymbol(property) : undefined;
|
|
2469
|
+
}
|
|
2350
2470
|
/**
|
|
2351
2471
|
* `collects: { arg, key?, join }` on a scope (#2474 R6a): the parameter
|
|
2352
2472
|
* there is an object type that is not a function, whose keys name the
|
|
@@ -2839,7 +2959,7 @@ class DeclarationReader {
|
|
|
2839
2959
|
if (declared === undefined)
|
|
2840
2960
|
return { rank: 1, outcome: failed('param_missing') };
|
|
2841
2961
|
if (slot.key === undefined) {
|
|
2842
|
-
const read = this.throughConditional(declared);
|
|
2962
|
+
const read = this.throughDefault(this.throughConditional(declared));
|
|
2843
2963
|
return this.acceptsString(read) ? undefined : { rank: 1, outcome: this.slotFailure(read, 'name_not_string') };
|
|
2844
2964
|
}
|
|
2845
2965
|
const view = this.viewFor(declared, new Map([[slot.key, 'name']]), given => this.runsFailure(given));
|
|
@@ -3245,6 +3365,30 @@ class DeclarationReader {
|
|
|
3245
3365
|
}
|
|
3246
3366
|
return best?.outcome ?? failed('param_missing');
|
|
3247
3367
|
}
|
|
3368
|
+
/**
|
|
3369
|
+
* A `runs` slot on a `protocol: "graphql"` make (ruling G9): what the maker
|
|
3370
|
+
* is given to run is a schema, which is an object, or a factory, which is a
|
|
3371
|
+
* function. `any`, `unknown` and an unconstrained type parameter say
|
|
3372
|
+
* nothing (`runs_untyped`); anything that is not an object type, a
|
|
3373
|
+
* primitive for one, fails `runs_not_schema`. Names no library type.
|
|
3374
|
+
*/
|
|
3375
|
+
graphqlRunsFailure(declared) {
|
|
3376
|
+
if (declared === undefined)
|
|
3377
|
+
return failed('param_missing');
|
|
3378
|
+
const slot = this.throughConditional(this.throughConstraint(declared));
|
|
3379
|
+
if (slot === VARIADIC)
|
|
3380
|
+
return unchecked('runs_untyped');
|
|
3381
|
+
const parts = this.parts(slot);
|
|
3382
|
+
if (parts.length === 0)
|
|
3383
|
+
return failed('runs_not_schema');
|
|
3384
|
+
for (const part of parts) {
|
|
3385
|
+
if (this.isOpenTop(part) || this.isUnconstrained(part))
|
|
3386
|
+
return unchecked('runs_untyped');
|
|
3387
|
+
if (!this.isObjectLike(part))
|
|
3388
|
+
return failed('runs_not_schema');
|
|
3389
|
+
}
|
|
3390
|
+
return undefined;
|
|
3391
|
+
}
|
|
3248
3392
|
/** A `runs` slot: a function with a declared signature, as a handler is, under its own reasons. */
|
|
3249
3393
|
runsFailure(declared) {
|
|
3250
3394
|
const failure = this.handlerFailure(declared);
|
|
@@ -3418,9 +3562,12 @@ class DeclarationReader {
|
|
|
3418
3562
|
layout(parts) {
|
|
3419
3563
|
const positional = new Map();
|
|
3420
3564
|
const keyed = new Map();
|
|
3565
|
+
const orFile = new Set();
|
|
3421
3566
|
for (const [part, slot] of Object.entries(parts)) {
|
|
3422
3567
|
if (slot === undefined)
|
|
3423
3568
|
continue;
|
|
3569
|
+
if (part === 'handler' && slot.or_file === true)
|
|
3570
|
+
orFile.add(slotKey(slot.arg, slot.key));
|
|
3424
3571
|
if (slot.key === undefined) {
|
|
3425
3572
|
if (positional.has(slot.arg) || keyed.has(slot.arg))
|
|
3426
3573
|
return { failure: failed('slots_overlap') };
|
|
@@ -3435,7 +3582,7 @@ class DeclarationReader {
|
|
|
3435
3582
|
keys.set(slot.key, part);
|
|
3436
3583
|
keyed.set(slot.arg, keys);
|
|
3437
3584
|
}
|
|
3438
|
-
return { value: { positional, keyed } };
|
|
3585
|
+
return { value: orFile.size > 0 ? { positional, keyed, orFile } : { positional, keyed } };
|
|
3439
3586
|
}
|
|
3440
3587
|
/**
|
|
3441
3588
|
* One overload against a message claim's layout; rank `Infinity` holds.
|
|
@@ -3479,7 +3626,7 @@ class DeclarationReader {
|
|
|
3479
3626
|
const declared = this.keyParameterAt(signature, arg);
|
|
3480
3627
|
if (declared === undefined)
|
|
3481
3628
|
return { rank: 1, outcome: failed('param_missing') };
|
|
3482
|
-
const slot = this.throughConditional(declared);
|
|
3629
|
+
const slot = this.throughDefault(this.throughConditional(declared));
|
|
3483
3630
|
if (!this.acceptsString(slot)) {
|
|
3484
3631
|
return { rank: 1, outcome: this.slotFailure(slot, part === 'name' ? 'name_not_string' : 'slot_not_string') };
|
|
3485
3632
|
}
|
|
@@ -3501,7 +3648,11 @@ class DeclarationReader {
|
|
|
3501
3648
|
if (part !== 'handler' && part !== 'ack' && part !== 'runs')
|
|
3502
3649
|
continue;
|
|
3503
3650
|
const declared = this.keyParameterAt(signature, arg);
|
|
3504
|
-
const failure = part === 'runs'
|
|
3651
|
+
const failure = part === 'runs'
|
|
3652
|
+
? runsFailure(declared)
|
|
3653
|
+
: part === 'handler' && layout.orFile?.has(slotKey(arg))
|
|
3654
|
+
? this.functionOrFileFailure(declared)
|
|
3655
|
+
: this.handlerFailure(declared);
|
|
3505
3656
|
if (failure)
|
|
3506
3657
|
return { rank: 3, outcome: failure };
|
|
3507
3658
|
}
|
|
@@ -3510,7 +3661,7 @@ class DeclarationReader {
|
|
|
3510
3661
|
const slot = this.keyParameterAt(signature, arg);
|
|
3511
3662
|
if (slot === undefined)
|
|
3512
3663
|
return { rank: 1, outcome: failed('param_missing') };
|
|
3513
|
-
const view = this.viewFor(slot, keys, runsFailure);
|
|
3664
|
+
const view = this.viewFor(slot, keys, runsFailure, key => layout.orFile?.has(slotKey(arg, key)) === true);
|
|
3514
3665
|
if ('rank' in view)
|
|
3515
3666
|
return view;
|
|
3516
3667
|
views.set(arg, view.view);
|
|
@@ -3525,7 +3676,7 @@ class DeclarationReader {
|
|
|
3525
3676
|
* union member that is an object type and not a function type, declaring
|
|
3526
3677
|
* every claimed key with the type its part needs.
|
|
3527
3678
|
*/
|
|
3528
|
-
viewFor(slot, keys, runsFailure) {
|
|
3679
|
+
viewFor(slot, keys, runsFailure, orFile = () => false) {
|
|
3529
3680
|
if (slot === VARIADIC || !this.isObjectType(slot)) {
|
|
3530
3681
|
return { rank: 1, outcome: this.slotFailure(slot, 'param_missing') };
|
|
3531
3682
|
}
|
|
@@ -3570,7 +3721,7 @@ class DeclarationReader {
|
|
|
3570
3721
|
}
|
|
3571
3722
|
}
|
|
3572
3723
|
if (part === 'handler' || part === 'ack') {
|
|
3573
|
-
const bad = this.handlerFailure(type);
|
|
3724
|
+
const bad = part === 'handler' && orFile(key) ? this.functionOrFileFailure(type) : this.handlerFailure(type);
|
|
3574
3725
|
if (bad) {
|
|
3575
3726
|
failure = { rank: 3, outcome: bad };
|
|
3576
3727
|
break;
|
|
@@ -3836,6 +3987,55 @@ class DeclarationReader {
|
|
|
3836
3987
|
}
|
|
3837
3988
|
return undefined;
|
|
3838
3989
|
}
|
|
3990
|
+
/**
|
|
3991
|
+
* A `handler` slot flagged `or_file` (QW-1): the function that runs, or the
|
|
3992
|
+
* path of a file that exports it. The slot is read as `handlerFailure`
|
|
3993
|
+
* reads it; its file parts (`isFilePart`) are dropped and every other part
|
|
3994
|
+
* besides null and undefined is judged by the handler rule. At least one
|
|
3995
|
+
* part must remain: a slot of only paths runs no handler of its own.
|
|
3996
|
+
*/
|
|
3997
|
+
functionOrFileFailure(declared) {
|
|
3998
|
+
if (declared === undefined)
|
|
3999
|
+
return failed('param_missing');
|
|
4000
|
+
const slot = this.throughConditional(this.throughConstraint(declared));
|
|
4001
|
+
if (slot === VARIADIC)
|
|
4002
|
+
return unchecked('handler_untyped');
|
|
4003
|
+
const rest = this.parts(slot).filter(part => !this.isFilePart(part));
|
|
4004
|
+
if (rest.length === 0)
|
|
4005
|
+
return failed('handler_not_function');
|
|
4006
|
+
for (const part of rest) {
|
|
4007
|
+
const failure = this.handlerFailure(part);
|
|
4008
|
+
if (failure)
|
|
4009
|
+
return failure;
|
|
4010
|
+
}
|
|
4011
|
+
return undefined;
|
|
4012
|
+
}
|
|
4013
|
+
/**
|
|
4014
|
+
* The lister's mark for an `or_file` slot: not a handler as it stands, but
|
|
4015
|
+
* one once its file parts are dropped. An `opts | fn` union is not: an
|
|
4016
|
+
* options object is no file part.
|
|
4017
|
+
*/
|
|
4018
|
+
isFunctionOrFile(slot) {
|
|
4019
|
+
return this.handlerFailure(slot) !== undefined && this.functionOrFileFailure(slot) === undefined;
|
|
4020
|
+
}
|
|
4021
|
+
/**
|
|
4022
|
+
* A part that names a file rather than being the function: string-like, or
|
|
4023
|
+
* the platform `URL` (declared in a default library file or in the
|
|
4024
|
+
* runtime's own `url` types), never a package's own class of that name.
|
|
4025
|
+
*/
|
|
4026
|
+
isFilePart(part) {
|
|
4027
|
+
if (isStringLike(part))
|
|
4028
|
+
return true;
|
|
4029
|
+
const symbol = part.getSymbol();
|
|
4030
|
+
if (symbol === undefined || symbol.getName() !== 'URL')
|
|
4031
|
+
return false;
|
|
4032
|
+
return (symbol.getDeclarations() ?? []).some(declaration => {
|
|
4033
|
+
const file = declaration.getSourceFile();
|
|
4034
|
+
if (this.program.isSourceFileDefaultLibrary(file))
|
|
4035
|
+
return true;
|
|
4036
|
+
return this.packageOf(file) === '@types/node' && path.basename(file.fileName) === 'url.d.ts';
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
3839
4039
|
/**
|
|
3840
4040
|
* A name typed by a conditional (`IdOf<T> = T extends Def<infer Id> ? Id
|
|
3841
4041
|
* : never`) is read through what its branches allow. When a branch says
|
|
@@ -4138,7 +4338,7 @@ class DeclarationReader {
|
|
|
4138
4338
|
* `built` answers the probe's no-argument build of a receiver an export
|
|
4139
4339
|
* makes, resolved, when the probe holds one.
|
|
4140
4340
|
*/
|
|
4141
|
-
listPackage(pkg, probe, maxEntries, only, options, typeExports, built) {
|
|
4341
|
+
listPackage(pkg, probe, maxEntries, only, options, typeExports, gate, built) {
|
|
4142
4342
|
this.setPackage(pkg);
|
|
4143
4343
|
// Runtime modules on: a `node:` specifier is listed from the runtime's
|
|
4144
4344
|
// types package, as the message roles read it.
|
|
@@ -4223,7 +4423,9 @@ class DeclarationReader {
|
|
|
4223
4423
|
}
|
|
4224
4424
|
};
|
|
4225
4425
|
receiverOf('export', type);
|
|
4226
|
-
|
|
4426
|
+
const all = this.makers(pkg, target, type);
|
|
4427
|
+
const listed = gate.gated && this.typedByAnotherPackage(target, type) ? all.filter(maker => !maker.member) : all;
|
|
4428
|
+
for (const maker of listed) {
|
|
4227
4429
|
const made = this.madeBy(maker.signatures, built(name, maker.receiver), target === defaultTarget);
|
|
4228
4430
|
if (!made)
|
|
4229
4431
|
continue;
|
|
@@ -4258,6 +4460,8 @@ class DeclarationReader {
|
|
|
4258
4460
|
}
|
|
4259
4461
|
if (propertiesLeftOut > 0)
|
|
4260
4462
|
surface.properties_left_out = propertiesLeftOut;
|
|
4463
|
+
if (gate.leftOut > 0)
|
|
4464
|
+
surface.makers_left_out = gate.leftOut;
|
|
4261
4465
|
return surface;
|
|
4262
4466
|
}
|
|
4263
4467
|
/**
|
|
@@ -4628,29 +4832,68 @@ class DeclarationReader {
|
|
|
4628
4832
|
return this.namedProperties(type).some(member => this.librarySignatures(this.checker.getTypeOfSymbol(member), 'call').length > 0);
|
|
4629
4833
|
}
|
|
4630
4834
|
/**
|
|
4631
|
-
*
|
|
4632
|
-
* the
|
|
4835
|
+
* Every listed export of a specifier with the receivers it can make, and
|
|
4836
|
+
* what the foreign ones (`typedByAnotherPackage`) are estimated to cost: their
|
|
4837
|
+
* member makers times their member count (carrick#3745).
|
|
4633
4838
|
*/
|
|
4634
|
-
|
|
4839
|
+
exportMakers(pkg, probe, only) {
|
|
4635
4840
|
this.setPackage(pkg);
|
|
4636
4841
|
const moduleRead = 'namespace' in probe ? this.readModule(pkg, probe.namespace, true) : undefined;
|
|
4637
4842
|
if (moduleRead?.reason)
|
|
4638
|
-
return {
|
|
4843
|
+
return { pkg, exports: [], types: [], classes: [], foreignMakerMembers: 0 };
|
|
4639
4844
|
const readable = 'namespace' in probe && !moduleRead?.globalFile;
|
|
4640
4845
|
const types = readable ? this.typeExportCandidates(probe.namespace, false) : [];
|
|
4641
4846
|
const classes = readable ? this.typeExportCandidates(probe.namespace, true) : [];
|
|
4642
|
-
|
|
4847
|
+
let foreignMakerMembers = 0;
|
|
4848
|
+
const exports = (this.listedExports(probe, only, moduleRead?.globalFile) ?? [])
|
|
4643
4849
|
.filter(({ type }) => !this.isOpenTop(type))
|
|
4644
4850
|
.map(({ name, target, type }) => {
|
|
4645
4851
|
const makers = this.makers(pkg, target, type);
|
|
4852
|
+
const foreign = this.typedByAnotherPackage(target, type);
|
|
4853
|
+
if (foreign)
|
|
4854
|
+
foreignMakerMembers += makers.filter(maker => maker.member).length * this.namedProperties(type).length;
|
|
4855
|
+
return { name, target, foreign, makers };
|
|
4856
|
+
});
|
|
4857
|
+
return { pkg, exports, types, classes, foreignMakerMembers };
|
|
4858
|
+
}
|
|
4859
|
+
/**
|
|
4860
|
+
* The receivers each export of a specifier can make, by receiver id, for
|
|
4861
|
+
* the probe statements that build them (see `LibraryClaimsVerifier.listSurface`).
|
|
4862
|
+
* `gated`: a foreign export makes no member receivers, and its scope
|
|
4863
|
+
* candidates are not asked for (carrick#3745).
|
|
4864
|
+
*/
|
|
4865
|
+
makersOf(read, gated) {
|
|
4866
|
+
this.setPackage(read.pkg);
|
|
4867
|
+
let makersLeftOut = 0;
|
|
4868
|
+
const makers = read.exports
|
|
4869
|
+
.map(({ name, target, foreign, makers: all }) => {
|
|
4870
|
+
const kept = gated && foreign ? all.filter(maker => !maker.member) : all;
|
|
4871
|
+
makersLeftOut += all.length - kept.length;
|
|
4646
4872
|
return {
|
|
4647
4873
|
export: name,
|
|
4648
|
-
receivers:
|
|
4649
|
-
scopes: this.scopeCandidates(pkg, target,
|
|
4874
|
+
receivers: kept.map(maker => maker.receiver),
|
|
4875
|
+
scopes: this.scopeCandidates(read.pkg, target, kept),
|
|
4650
4876
|
};
|
|
4651
4877
|
})
|
|
4652
4878
|
.filter(({ receivers }) => receivers.length > 0);
|
|
4653
|
-
return { makers, types, classes };
|
|
4879
|
+
return { makers, types: read.types, classes: read.classes, gated, makersLeftOut };
|
|
4880
|
+
}
|
|
4881
|
+
/**
|
|
4882
|
+
* A variable whose type's own declaration only other installed packages
|
|
4883
|
+
* write. Re-exports are judged where they are declared; a value outside
|
|
4884
|
+
* every installed package, or typed by the default library, never is.
|
|
4885
|
+
*/
|
|
4886
|
+
typedByAnotherPackage(target, type) {
|
|
4887
|
+
if ((target.flags & ts.SymbolFlags.Variable) === 0)
|
|
4888
|
+
return false;
|
|
4889
|
+
const owners = (target.declarations ?? []).map(declaration => this.packageOf(declaration.getSourceFile()));
|
|
4890
|
+
if (owners.length === 0 || owners.some(owner => owner === undefined))
|
|
4891
|
+
return false;
|
|
4892
|
+
const valueOwners = new Set(owners);
|
|
4893
|
+
return this.isDeclaredOnlyIn(type.getSymbol() ?? type.aliasSymbol, file => {
|
|
4894
|
+
const owner = this.packageOf(file);
|
|
4895
|
+
return owner !== undefined && !valueOwners.has(owner);
|
|
4896
|
+
});
|
|
4654
4897
|
}
|
|
4655
4898
|
/**
|
|
4656
4899
|
* The type-only exports of a specifier a handler's parameter may be
|
|
@@ -5225,6 +5468,8 @@ class DeclarationReader {
|
|
|
5225
5468
|
accepts_string: slot !== undefined && this.acceptsString(this.throughConditional(slot)),
|
|
5226
5469
|
function: this.handlerFailure(slot) === undefined,
|
|
5227
5470
|
};
|
|
5471
|
+
if (this.isFunctionOrFile(slot))
|
|
5472
|
+
param.function_or_file = true;
|
|
5228
5473
|
if (slot !== undefined && slot !== VARIADIC && this.isObjectType(slot) && this.handlerFailure(slot) !== undefined) {
|
|
5229
5474
|
const keys = this.listKeys(slot, take);
|
|
5230
5475
|
if (keys.length > 0)
|
|
@@ -5290,12 +5535,36 @@ class DeclarationReader {
|
|
|
5290
5535
|
if (known !== undefined)
|
|
5291
5536
|
return known;
|
|
5292
5537
|
surfaceReadCounts.typePrints += 1;
|
|
5293
|
-
const
|
|
5294
|
-
const text = node === undefined ? this.checker.typeToString(type) : printTypeNode(this.orderUnions(node));
|
|
5295
|
-
const listed = truncate(this.scrubbed(text));
|
|
5538
|
+
const listed = this.printedWithinBudget(type);
|
|
5296
5539
|
this.printedTexts.set(type, listed);
|
|
5297
5540
|
return listed;
|
|
5298
5541
|
}
|
|
5542
|
+
/**
|
|
5543
|
+
* The print of `type`, or `NOT_PRINTED` when building it reaches more than
|
|
5544
|
+
* `PRINT_SYMBOL_BUDGET` symbol references. The compiler reports each one to
|
|
5545
|
+
* the tracker, so counting there stops the print wherever it is.
|
|
5546
|
+
*/
|
|
5547
|
+
printedWithinBudget(type) {
|
|
5548
|
+
const stop = {};
|
|
5549
|
+
let references = 0;
|
|
5550
|
+
const tracker = {
|
|
5551
|
+
trackSymbol: () => {
|
|
5552
|
+
if (++references > PRINT_SYMBOL_BUDGET)
|
|
5553
|
+
throw stop;
|
|
5554
|
+
return false;
|
|
5555
|
+
},
|
|
5556
|
+
};
|
|
5557
|
+
try {
|
|
5558
|
+
const node = this.checker.typeToTypeNode(type, undefined, PRINT_FLAGS, undefined, tracker);
|
|
5559
|
+
const text = node === undefined ? this.checker.typeToString(type) : printTypeNode(this.orderUnions(node));
|
|
5560
|
+
return truncate(this.scrubbed(text));
|
|
5561
|
+
}
|
|
5562
|
+
catch (err) {
|
|
5563
|
+
if (err === stop)
|
|
5564
|
+
return NOT_PRINTED;
|
|
5565
|
+
throw err;
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5299
5568
|
/** `text` with the service root written as `<root>`. */
|
|
5300
5569
|
scrubbed(text) {
|
|
5301
5570
|
for (const root of this.printedRoots)
|
|
@@ -5630,6 +5899,24 @@ class DeclarationReader {
|
|
|
5630
5899
|
return (this.checker.isTypeAssignableTo(this.checker.getStringType(), slot) &&
|
|
5631
5900
|
this.parts(slot).some(part => isStringLike(part)));
|
|
5632
5901
|
}
|
|
5902
|
+
/**
|
|
5903
|
+
* A type parameter that `throughConstraint` left as it is (no constraint,
|
|
5904
|
+
* or `any` or `unknown`) and whose default takes a string reads as that
|
|
5905
|
+
* default.
|
|
5906
|
+
* Only a name, base or prefix slot reads it (T2b): the default is what a
|
|
5907
|
+
* call that infers nothing names, never a promise about a body or payload.
|
|
5908
|
+
*/
|
|
5909
|
+
throughDefault(slot) {
|
|
5910
|
+
const bare = this.throughConstraint(slot);
|
|
5911
|
+
if (bare === VARIADIC)
|
|
5912
|
+
return slot;
|
|
5913
|
+
const parts = this.parts(bare);
|
|
5914
|
+
if (parts.length !== 1 || !(parts[0].flags & ts.TypeFlags.TypeParameter))
|
|
5915
|
+
return slot;
|
|
5916
|
+
const fallback = this.checker.getDefaultFromTypeParameter(parts[0]);
|
|
5917
|
+
// A default that takes no string leaves the slot as it was: it says nothing.
|
|
5918
|
+
return fallback !== undefined && this.acceptsString(fallback) ? fallback : slot;
|
|
5919
|
+
}
|
|
5633
5920
|
/** Accepts string, or names an HTTP method as a literal in either case. */
|
|
5634
5921
|
acceptsMethod(declared) {
|
|
5635
5922
|
const slot = this.throughConstraint(declared);
|
|
@@ -5668,8 +5955,51 @@ class DeclarationReader {
|
|
|
5668
5955
|
const constraint = this.checker.getBaseConstraintOfType(type);
|
|
5669
5956
|
return constraint !== undefined && constraint !== type && this.isObjectLike(constraint);
|
|
5670
5957
|
}
|
|
5958
|
+
if (type.flags & ts.TypeFlags.Conditional)
|
|
5959
|
+
return this.isObjectConditional(type);
|
|
5671
5960
|
return false;
|
|
5672
5961
|
}
|
|
5962
|
+
/**
|
|
5963
|
+
* A conditional on a type parameter stays deferred inside a generic
|
|
5964
|
+
* signature (an options intersection whose context key is optional only
|
|
5965
|
+
* when the context is empty). It is an object when every part of its
|
|
5966
|
+
* branches' constraint is one: the constraint reads both branches as
|
|
5967
|
+
* instantiated, so `any` or `unknown` in either leaves no object. One that
|
|
5968
|
+
* infers (`T extends Def<infer X> ? X : ...`) is read as a name's is
|
|
5969
|
+
* (`throughConditional`), through its branches as declared, because its
|
|
5970
|
+
* constraint drops the branch the inferred parameter stands in.
|
|
5971
|
+
*/
|
|
5972
|
+
isObjectConditional(type) {
|
|
5973
|
+
// A branch that names the conditional again (itself, or through a second
|
|
5974
|
+
// alias) is a fresh instantiation each time round, so identity does not end
|
|
5975
|
+
// the chain: a depth cap does. Past it, as for an unreadable branch, it is
|
|
5976
|
+
// not an object.
|
|
5977
|
+
if (this.conditionalDepth >= MAX_CONDITIONAL_DEPTH)
|
|
5978
|
+
return false;
|
|
5979
|
+
this.conditionalDepth++;
|
|
5980
|
+
try {
|
|
5981
|
+
return this.readObjectConditional(type);
|
|
5982
|
+
}
|
|
5983
|
+
finally {
|
|
5984
|
+
this.conditionalDepth--;
|
|
5985
|
+
}
|
|
5986
|
+
}
|
|
5987
|
+
readObjectConditional(type) {
|
|
5988
|
+
if ((type.root.inferTypeParameters?.length ?? 0) > 0) {
|
|
5989
|
+
const node = type.root.node;
|
|
5990
|
+
const branchSaysNothing = [node.trueType, node.falseType].some(branch => {
|
|
5991
|
+
const declared = this.checker.getTypeFromTypeNode(branch);
|
|
5992
|
+
return (declared.flags & ts.TypeFlags.Never) === 0 && this.returnSaysNothing(declared);
|
|
5993
|
+
});
|
|
5994
|
+
if (branchSaysNothing)
|
|
5995
|
+
return false;
|
|
5996
|
+
}
|
|
5997
|
+
const constraint = this.checker.getBaseConstraintOfType(type);
|
|
5998
|
+
if (constraint === undefined || constraint === type)
|
|
5999
|
+
return false;
|
|
6000
|
+
const parts = this.parts(constraint);
|
|
6001
|
+
return parts.length > 0 && parts.every(part => part !== type && this.isObjectLike(part));
|
|
6002
|
+
}
|
|
5673
6003
|
/**
|
|
5674
6004
|
* The verdict when a slot fails its predicate: `unchecked` (`member_untyped`)
|
|
5675
6005
|
* when its type says nothing, `failed` with `code` when it says something
|
|
@@ -5782,10 +6112,30 @@ const HANDLER_MEMBER_CAP = 500;
|
|
|
5782
6112
|
* listed 8.99 million of them (1.3 GB) before it.
|
|
5783
6113
|
*/
|
|
5784
6114
|
const HANDLER_LISTING_BUDGET = 500_000;
|
|
6115
|
+
/**
|
|
6116
|
+
* The most members the receivers a request's foreign values' members make may
|
|
6117
|
+
* be estimated at before none of them is listed (carrick#3745). A value typed
|
|
6118
|
+
* by another package's class (a package of schema values typed by a schema
|
|
6119
|
+
* library) makes that class's whole fluent surface again at every value's
|
|
6120
|
+
* type arguments: the checker keeps every instantiation, and a package of
|
|
6121
|
+
* about 170 such values passes the builder's heap in pass 1. Measured at the
|
|
6122
|
+
* builder's heap: an estimate of 144,016 listed in 63 s, 181,636 ran out of
|
|
6123
|
+
* heap. Over it, the listing stays whole otherwise.
|
|
6124
|
+
*/
|
|
6125
|
+
const FOREIGN_MAKER_BUDGET = 160_000;
|
|
5785
6126
|
const PRINT_FLAGS = ts.NodeBuilderFlags.AllowUniqueESSymbolType |
|
|
5786
6127
|
ts.NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope |
|
|
5787
6128
|
ts.NodeBuilderFlags.IgnoreErrors |
|
|
5788
6129
|
ts.NodeBuilderFlags.NoTruncation;
|
|
6130
|
+
/**
|
|
6131
|
+
* A deferred conditional with no alias, whose branches reach more such
|
|
6132
|
+
* conditionals, doubles its print at every level and runs the lister out of
|
|
6133
|
+
* heap. A print that reaches more symbol references than this stops and lists
|
|
6134
|
+
* as `NOT_PRINTED`. Counted, never timed, so the same print stops at the same
|
|
6135
|
+
* point on every run; no finished print in the packages measured came near it.
|
|
6136
|
+
*/
|
|
6137
|
+
const PRINT_SYMBOL_BUDGET = 100_000;
|
|
6138
|
+
const NOT_PRINTED = '<not printed: too large>';
|
|
5789
6139
|
const TYPE_PRINTER = ts.createPrinter({ removeComments: true });
|
|
5790
6140
|
/**
|
|
5791
6141
|
* A type node as `typeToString` prints it with no enclosing declaration: with
|