carrick 0.3.154 → 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 +10 -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 +31 -122
- 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/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 +2 -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/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/library-claims.js +211 -20
- 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 +39 -4
- package/sidecar/dist/src/position-rows.js +233 -16
- package/sidecar/dist/src/project-loader.js +13 -5
- 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 +33 -145
- package/sidecar/dist/src/type-inferrer.js +68 -524
- package/sidecar/dist/src/types.d.ts +55 -2
- package/sidecar/dist/src/validators.d.ts +800 -142
- package/sidecar/dist/src/validators.js +11 -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))
|
|
@@ -1260,6 +1290,45 @@ function placementInvalid(claim) {
|
|
|
1260
1290
|
const of = parseReceiver(claim.of);
|
|
1261
1291
|
return of === undefined || (of.maker === undefined && of.scope === undefined && of.type === undefined);
|
|
1262
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
|
+
}
|
|
1263
1332
|
/**
|
|
1264
1333
|
* Where a handler's request holds its path, method and body (#2474 R0,
|
|
1265
1334
|
* carrick#2674) is read on a receive op with a handler, and names `path`,
|
|
@@ -1441,6 +1510,10 @@ function readLocalRanges(fromDir) {
|
|
|
1441
1510
|
dir = parent;
|
|
1442
1511
|
}
|
|
1443
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
|
+
}
|
|
1444
1517
|
/**
|
|
1445
1518
|
* Reads the declarations the probe imported, with the program's own checker.
|
|
1446
1519
|
* Every predicate is the contract's (carrick#1564, section 3), stated on the
|
|
@@ -2207,8 +2280,11 @@ class DeclarationReader {
|
|
|
2207
2280
|
const holding = [];
|
|
2208
2281
|
let best;
|
|
2209
2282
|
for (const signature of callee.signatures) {
|
|
2210
|
-
let result = this.messageSignatureOutcome(signature, layout.value, labels);
|
|
2211
|
-
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) {
|
|
2212
2288
|
const collected = collections();
|
|
2213
2289
|
if (collected !== undefined) {
|
|
2214
2290
|
result = this.messageSignatureOutcome(signature, layout.value, labels, declared => this.runsCollectionOutcome(signature, declared, collected));
|
|
@@ -2254,17 +2330,36 @@ class DeclarationReader {
|
|
|
2254
2330
|
* `arg`, read through a rest (`parameterAt`), takes what a verified
|
|
2255
2331
|
* `collects` scope of the request returns (`collectionSlotOutcome`), and
|
|
2256
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.
|
|
2257
2341
|
*/
|
|
2258
2342
|
judgeScope(receiver, claim, built, collections) {
|
|
2259
|
-
|
|
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') };
|
|
2260
2347
|
return { outcome: this.decorateScopeOutcome(receiver, claim) };
|
|
2348
|
+
}
|
|
2261
2349
|
if ((claim.runs === undefined) !== (claim.yields === undefined))
|
|
2262
2350
|
return { outcome: unchecked('claim_invalid') };
|
|
2263
2351
|
if (claim.mounts !== undefined && claim.runs !== undefined)
|
|
2264
2352
|
return { outcome: unchecked('claim_invalid') };
|
|
2265
|
-
const
|
|
2266
|
-
|
|
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))
|
|
2267
2361
|
return { outcome: unchecked('claim_invalid') };
|
|
2362
|
+
const namelessMount = carried === 0 && claim.mounts !== undefined;
|
|
2268
2363
|
if ((claim.collects !== undefined || claim.merges !== undefined) &&
|
|
2269
2364
|
(claim.runs !== undefined || claim.mounts !== undefined)) {
|
|
2270
2365
|
return { outcome: unchecked('claim_invalid') };
|
|
@@ -2275,7 +2370,6 @@ class DeclarationReader {
|
|
|
2275
2370
|
return { outcome: unchecked('claim_invalid') };
|
|
2276
2371
|
}
|
|
2277
2372
|
const collected = merges === undefined ? undefined : collections?.();
|
|
2278
|
-
const binds = claim.runs !== undefined || claim.mounts !== undefined;
|
|
2279
2373
|
const layout = this.layout({ name: claim.name, runs: claim.runs, mounts: claim.mounts });
|
|
2280
2374
|
if ('failure' in layout)
|
|
2281
2375
|
return { outcome: layout.failure };
|
|
@@ -2288,14 +2382,24 @@ class DeclarationReader {
|
|
|
2288
2382
|
const holding = [];
|
|
2289
2383
|
let best;
|
|
2290
2384
|
for (const signature of callee.signatures) {
|
|
2291
|
-
|
|
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
|
+
}
|
|
2292
2393
|
if (result.rank === Infinity && claim.yields !== undefined) {
|
|
2293
2394
|
const given = this.yieldsOutcome(signature, claim.runs, claim.yields, receiver);
|
|
2294
2395
|
if (given)
|
|
2295
2396
|
result = { rank: 5, outcome: given };
|
|
2296
2397
|
}
|
|
2297
2398
|
if (result.rank === Infinity && claim.mounts !== undefined) {
|
|
2298
|
-
|
|
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);
|
|
2299
2403
|
if (mounted)
|
|
2300
2404
|
result = { rank: 5, outcome: mounted };
|
|
2301
2405
|
}
|
|
@@ -2322,7 +2426,8 @@ class DeclarationReader {
|
|
|
2322
2426
|
// The member's own declarations, as a verified op carries them (#2636).
|
|
2323
2427
|
const declarations = this.declarationsOf({ signatures: holding, named: callee.named });
|
|
2324
2428
|
const outcome = declarations.length > 0 ? { verdict: 'verified', declarations } : VERIFIED;
|
|
2325
|
-
|
|
2429
|
+
// A binding scope and a pass-through open no `>scope:` receiver.
|
|
2430
|
+
return binds || passes ? { outcome } : { outcome, holding };
|
|
2326
2431
|
}
|
|
2327
2432
|
return { outcome: best.outcome };
|
|
2328
2433
|
}
|
|
@@ -2337,11 +2442,7 @@ class DeclarationReader {
|
|
|
2337
2442
|
* Undefined when it holds.
|
|
2338
2443
|
*/
|
|
2339
2444
|
mountsOutcome(signature, mounts, receiver) {
|
|
2340
|
-
|
|
2341
|
-
if (declared !== undefined && mounts.key !== undefined) {
|
|
2342
|
-
const property = this.declaredProperty(declared, mounts.key);
|
|
2343
|
-
declared = property ? this.checker.getTypeOfSymbol(property) : undefined;
|
|
2344
|
-
}
|
|
2445
|
+
const declared = this.mountedSlot(signature, mounts);
|
|
2345
2446
|
if (declared === undefined)
|
|
2346
2447
|
return failed('param_missing');
|
|
2347
2448
|
const slot = this.throughConstraint(declared);
|
|
@@ -2358,6 +2459,14 @@ class DeclarationReader {
|
|
|
2358
2459
|
return erased ? undefined : failed('mounts_not_instance');
|
|
2359
2460
|
return this.checker.isTypeAssignableTo(receiver.type, slot) ? undefined : failed('mounts_not_instance');
|
|
2360
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
|
+
}
|
|
2361
2470
|
/**
|
|
2362
2471
|
* `collects: { arg, key?, join }` on a scope (#2474 R6a): the parameter
|
|
2363
2472
|
* there is an object type that is not a function, whose keys name the
|
|
@@ -3256,6 +3365,30 @@ class DeclarationReader {
|
|
|
3256
3365
|
}
|
|
3257
3366
|
return best?.outcome ?? failed('param_missing');
|
|
3258
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
|
+
}
|
|
3259
3392
|
/** A `runs` slot: a function with a declared signature, as a handler is, under its own reasons. */
|
|
3260
3393
|
runsFailure(declared) {
|
|
3261
3394
|
const failure = this.handlerFailure(declared);
|
|
@@ -3429,9 +3562,12 @@ class DeclarationReader {
|
|
|
3429
3562
|
layout(parts) {
|
|
3430
3563
|
const positional = new Map();
|
|
3431
3564
|
const keyed = new Map();
|
|
3565
|
+
const orFile = new Set();
|
|
3432
3566
|
for (const [part, slot] of Object.entries(parts)) {
|
|
3433
3567
|
if (slot === undefined)
|
|
3434
3568
|
continue;
|
|
3569
|
+
if (part === 'handler' && slot.or_file === true)
|
|
3570
|
+
orFile.add(slotKey(slot.arg, slot.key));
|
|
3435
3571
|
if (slot.key === undefined) {
|
|
3436
3572
|
if (positional.has(slot.arg) || keyed.has(slot.arg))
|
|
3437
3573
|
return { failure: failed('slots_overlap') };
|
|
@@ -3446,7 +3582,7 @@ class DeclarationReader {
|
|
|
3446
3582
|
keys.set(slot.key, part);
|
|
3447
3583
|
keyed.set(slot.arg, keys);
|
|
3448
3584
|
}
|
|
3449
|
-
return { value: { positional, keyed } };
|
|
3585
|
+
return { value: orFile.size > 0 ? { positional, keyed, orFile } : { positional, keyed } };
|
|
3450
3586
|
}
|
|
3451
3587
|
/**
|
|
3452
3588
|
* One overload against a message claim's layout; rank `Infinity` holds.
|
|
@@ -3512,7 +3648,11 @@ class DeclarationReader {
|
|
|
3512
3648
|
if (part !== 'handler' && part !== 'ack' && part !== 'runs')
|
|
3513
3649
|
continue;
|
|
3514
3650
|
const declared = this.keyParameterAt(signature, arg);
|
|
3515
|
-
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);
|
|
3516
3656
|
if (failure)
|
|
3517
3657
|
return { rank: 3, outcome: failure };
|
|
3518
3658
|
}
|
|
@@ -3521,7 +3661,7 @@ class DeclarationReader {
|
|
|
3521
3661
|
const slot = this.keyParameterAt(signature, arg);
|
|
3522
3662
|
if (slot === undefined)
|
|
3523
3663
|
return { rank: 1, outcome: failed('param_missing') };
|
|
3524
|
-
const view = this.viewFor(slot, keys, runsFailure);
|
|
3664
|
+
const view = this.viewFor(slot, keys, runsFailure, key => layout.orFile?.has(slotKey(arg, key)) === true);
|
|
3525
3665
|
if ('rank' in view)
|
|
3526
3666
|
return view;
|
|
3527
3667
|
views.set(arg, view.view);
|
|
@@ -3536,7 +3676,7 @@ class DeclarationReader {
|
|
|
3536
3676
|
* union member that is an object type and not a function type, declaring
|
|
3537
3677
|
* every claimed key with the type its part needs.
|
|
3538
3678
|
*/
|
|
3539
|
-
viewFor(slot, keys, runsFailure) {
|
|
3679
|
+
viewFor(slot, keys, runsFailure, orFile = () => false) {
|
|
3540
3680
|
if (slot === VARIADIC || !this.isObjectType(slot)) {
|
|
3541
3681
|
return { rank: 1, outcome: this.slotFailure(slot, 'param_missing') };
|
|
3542
3682
|
}
|
|
@@ -3581,7 +3721,7 @@ class DeclarationReader {
|
|
|
3581
3721
|
}
|
|
3582
3722
|
}
|
|
3583
3723
|
if (part === 'handler' || part === 'ack') {
|
|
3584
|
-
const bad = this.handlerFailure(type);
|
|
3724
|
+
const bad = part === 'handler' && orFile(key) ? this.functionOrFileFailure(type) : this.handlerFailure(type);
|
|
3585
3725
|
if (bad) {
|
|
3586
3726
|
failure = { rank: 3, outcome: bad };
|
|
3587
3727
|
break;
|
|
@@ -3847,6 +3987,55 @@ class DeclarationReader {
|
|
|
3847
3987
|
}
|
|
3848
3988
|
return undefined;
|
|
3849
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
|
+
}
|
|
3850
4039
|
/**
|
|
3851
4040
|
* A name typed by a conditional (`IdOf<T> = T extends Def<infer Id> ? Id
|
|
3852
4041
|
* : never`) is read through what its branches allow. When a branch says
|
|
@@ -5279,6 +5468,8 @@ class DeclarationReader {
|
|
|
5279
5468
|
accepts_string: slot !== undefined && this.acceptsString(this.throughConditional(slot)),
|
|
5280
5469
|
function: this.handlerFailure(slot) === undefined,
|
|
5281
5470
|
};
|
|
5471
|
+
if (this.isFunctionOrFile(slot))
|
|
5472
|
+
param.function_or_file = true;
|
|
5282
5473
|
if (slot !== undefined && slot !== VARIADIC && this.isObjectType(slot) && this.handlerFailure(slot) !== undefined) {
|
|
5283
5474
|
const keys = this.listKeys(slot, take);
|
|
5284
5475
|
if (keys.length > 0)
|
|
@@ -35,6 +35,8 @@ export interface IndexedNode {
|
|
|
35
35
|
export declare function nodeIndexBuilds(): number;
|
|
36
36
|
/** The ts-morph node for an indexed one. */
|
|
37
37
|
export declare function wrap<T extends Node = Node>(sourceFile: SourceFile, entry: IndexedNode): T;
|
|
38
|
+
/** The ts-morph node for one of the file's compiler nodes. */
|
|
39
|
+
export declare function wrapCompilerNode<T extends Node = Node>(sourceFile: SourceFile, node: ts.Node): T;
|
|
38
40
|
/** Every descendant, in `getDescendants()` order. */
|
|
39
41
|
export declare function descendantsOf(sourceFile: SourceFile): readonly IndexedNode[];
|
|
40
42
|
/**
|
|
@@ -65,7 +65,11 @@ function buildIndex(sourceFile) {
|
|
|
65
65
|
}
|
|
66
66
|
/** The ts-morph node for an indexed one. */
|
|
67
67
|
export function wrap(sourceFile, entry) {
|
|
68
|
-
return
|
|
68
|
+
return wrapCompilerNode(sourceFile, entry.node);
|
|
69
|
+
}
|
|
70
|
+
/** The ts-morph node for one of the file's compiler nodes. */
|
|
71
|
+
export function wrapCompilerNode(sourceFile, node) {
|
|
72
|
+
return internals(sourceFile)._getNodeFromCompilerNode(node);
|
|
69
73
|
}
|
|
70
74
|
/** Every descendant, in `getDescendants()` order. */
|
|
71
75
|
export function descendantsOf(sourceFile) {
|
|
@@ -56,7 +56,7 @@ import { ts } from 'ts-morph';
|
|
|
56
56
|
import type { ProjectLoader } from './project-loader.js';
|
|
57
57
|
import type { PositionRowsCounts } from './types.js';
|
|
58
58
|
/** The format's version, written in the header. */
|
|
59
|
-
export declare const POSITION_ROWS_VERSION =
|
|
59
|
+
export declare const POSITION_ROWS_VERSION = 7;
|
|
60
60
|
/** The type is `any`, declared or inferred. Never set with the error type. */
|
|
61
61
|
export declare const FLAG_ANY = 1;
|
|
62
62
|
/** The type is the compiler's error type: something did not resolve. */
|
|
@@ -82,11 +82,21 @@ export declare const FLAG_MODULE_DEFAULT = 64;
|
|
|
82
82
|
* function returns, or an awaitable of one), so the library runs it and
|
|
83
83
|
* hands its result back (carrick#2634). Set when the call passes at least
|
|
84
84
|
* one argument at a function-typed parameter and every such parameter
|
|
85
|
-
* meets that return. The last
|
|
86
|
-
*
|
|
87
|
-
* `src/position_rows.rs` by
|
|
85
|
+
* meets that return. The last bit of the first byte: the flags widened to
|
|
86
|
+
* sixteen bits with {@link FLAG_DECLARED_TYPE} (format 7). Pinned to
|
|
87
|
+
* `FLAG_RUNS_HANDED` in `src/position_rows.rs` by
|
|
88
|
+
* `position-rows-runs-handed.test.ts`.
|
|
88
89
|
*/
|
|
89
90
|
export declare const FLAG_RUNS_HANDED = 128;
|
|
91
|
+
/**
|
|
92
|
+
* A `receiver_type` row only: the row names the type alias a package
|
|
93
|
+
* declares that the receiver was *declared* as, not a type the value holds
|
|
94
|
+
* ("declared, not held"). The compiler's printed type of a proxy is what the
|
|
95
|
+
* alias expands to (an alias of an alias, an intersection), so a reader cannot
|
|
96
|
+
* get the alias from the value. Pinned to `FLAG_DECLARED_TYPE` in
|
|
97
|
+
* `src/position_rows.rs` by `position-rows-declared-type.test.ts`.
|
|
98
|
+
*/
|
|
99
|
+
export declare const FLAG_DECLARED_TYPE = 256;
|
|
90
100
|
/** The most `decl` rows one position lists. */
|
|
91
101
|
export declare const DECL_CAP = 16;
|
|
92
102
|
/** The kinds {@link kindOf} gives a node; `decl` and `jsx` rows are written beside them. */
|
|
@@ -267,6 +277,31 @@ export declare class PositionWalker {
|
|
|
267
277
|
* type text. A throw writes none: the `member` row carries the flag.
|
|
268
278
|
*/
|
|
269
279
|
private receiverTypeRows;
|
|
280
|
+
/**
|
|
281
|
+
* The {@link FLAG_DECLARED_TYPE} row of a member read's receiver: the type
|
|
282
|
+
* alias a package declares that the receiver was declared as. Read from
|
|
283
|
+
* the declaration, never the value: the receiver symbol's annotation, else
|
|
284
|
+
* the declared return of the make its initializer calls (or the call the
|
|
285
|
+
* receiver is), walked through the checkout's own aliases to the first
|
|
286
|
+
* package alias (the first constituent of a union or intersection that has
|
|
287
|
+
* one). Only aliases: an interface or class is what the class rows are for.
|
|
288
|
+
* Only where the member read sits on a call's callee chain
|
|
289
|
+
* (`a.b.c()`); a plain property read gives none. At most one row per
|
|
290
|
+
* receiver span, outside {@link DECL_CAP}, and not subject to the
|
|
291
|
+
* same-package skip of the class rows. A throw writes none.
|
|
292
|
+
*/
|
|
293
|
+
private declaredTypeRow;
|
|
294
|
+
/** The type node a receiver is declared by: its symbol's annotation, or the declared return of the call it is made by. */
|
|
295
|
+
private declaredTypeNode;
|
|
296
|
+
/** The declared return type node of the signature a call resolves to. */
|
|
297
|
+
private returnTypeNode;
|
|
298
|
+
/**
|
|
299
|
+
* The first type alias a package declares that `typeNode` names, through
|
|
300
|
+
* the checkout's own aliases (`type Runner = Inner`), a union or an
|
|
301
|
+
* intersection, in order. An alias, interface or class of the checkout
|
|
302
|
+
* that is not an alias is a stop; so is the default library.
|
|
303
|
+
*/
|
|
304
|
+
private packageAlias;
|
|
270
305
|
/**
|
|
271
306
|
* The name a `receiver_type` row gives a class. A class written
|
|
272
307
|
* `export default class Cursor` has the symbol name `default`, which is
|