carrick 0.3.149 → 0.3.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global-install.d.ts +2 -2
- package/dist/global-install.js +1 -1
- package/dist/global-install.js.map +1 -1
- package/dist/hook/post-edit.js +4 -0
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/rechecks.d.ts +6 -0
- package/dist/hook/rechecks.js +19 -0
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/reuse.d.ts +1 -0
- package/dist/hook/reuse.js +10 -1
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-start.js +15 -13
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stop-wait.js +17 -3
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/upgrade.d.ts +11 -0
- package/dist/hook/upgrade.js +81 -0
- package/dist/hook/upgrade.js.map +1 -0
- package/dist/hook/worktree.d.ts +10 -0
- package/dist/hook/worktree.js +45 -0
- package/dist/hook/worktree.js.map +1 -0
- package/dist/init/repo-copies.d.ts +2 -0
- package/dist/init/repo-copies.js +1 -1
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/self-update.d.ts +2 -2
- package/dist/init/self-update.js +56 -12
- package/dist/init/self-update.js.map +1 -1
- package/dist/self-upgrade.d.ts +1 -0
- package/dist/self-upgrade.js +10 -0
- package/dist/self-upgrade.js.map +1 -0
- package/dist/upgrade.d.ts +26 -0
- package/dist/upgrade.js +86 -0
- package/dist/upgrade.js.map +1 -0
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.d.ts +7 -0
- package/sidecar/dist/src/capture/anchors.js +13 -4
- package/sidecar/dist/src/capture/check-classify.js +4 -2
- package/sidecar/dist/src/capture/check.js +8 -4
- package/sidecar/dist/src/capture/deep-walk.d.ts +14 -8
- package/sidecar/dist/src/capture/deep-walk.js +26 -9
- package/sidecar/dist/src/capture/index.js +4 -2
- package/sidecar/dist/src/capture/self-check.d.ts +7 -0
- package/sidecar/dist/src/capture/self-check.js +19 -1
- package/sidecar/dist/src/capture/service-config.d.ts +5 -4
- package/sidecar/dist/src/capture/service-config.js +15 -12
- package/sidecar/dist/src/library-claims.js +244 -30
- package/sidecar/dist/src/position-rows.js +25 -3
- package/sidecar/dist/src/types.d.ts +27 -4
- package/sidecar/dist/src/validators.d.ts +284 -34
- package/sidecar/dist/src/validators.js +19 -3
|
@@ -727,7 +727,10 @@ export class LibraryClaimsVerifier {
|
|
|
727
727
|
const builtAtDefaults = built === undefined ? undefined : atDefaults(check, built);
|
|
728
728
|
// An adapter's `runs` is read against the request's collections only
|
|
729
729
|
// when today's reading refuses it (#2474 R6a): `judgeMake` asks.
|
|
730
|
-
const collectionsOf = check.claim.kind === 'make' && check.claim.runs !== undefined
|
|
730
|
+
const collectionsOf = (check.claim.kind === 'make' && check.claim.runs !== undefined) ||
|
|
731
|
+
(check.claim.kind === 'scope' && check.claim.merges !== undefined)
|
|
732
|
+
? collections
|
|
733
|
+
: undefined;
|
|
731
734
|
const holding = [];
|
|
732
735
|
const declarations = [];
|
|
733
736
|
const members = [];
|
|
@@ -1203,6 +1206,9 @@ function unbuiltPart(claim) {
|
|
|
1203
1206
|
else if ('parts' in name) {
|
|
1204
1207
|
return 'name.parts';
|
|
1205
1208
|
}
|
|
1209
|
+
else if ('first' in name) {
|
|
1210
|
+
// Judged in `firstNameOutcome`: its entries are plain slots or the decorated name.
|
|
1211
|
+
}
|
|
1206
1212
|
else if (!('literal' in name)) {
|
|
1207
1213
|
// A literal is judged in `judgeOp`, a document or reference slot too; a make's or scope's still is not.
|
|
1208
1214
|
slots.push({ ...name, document: undefined, ref: undefined });
|
|
@@ -2115,7 +2121,7 @@ class DeclarationReader {
|
|
|
2115
2121
|
case 'make':
|
|
2116
2122
|
return this.judgeMake(receiver, claim, built, collections);
|
|
2117
2123
|
case 'scope':
|
|
2118
|
-
return this.judgeScope(receiver, claim, built);
|
|
2124
|
+
return this.judgeScope(receiver, claim, built, collections);
|
|
2119
2125
|
case 'op':
|
|
2120
2126
|
return { outcome: this.judgeOp(receiver, claim, rules) };
|
|
2121
2127
|
case 'reserved':
|
|
@@ -2227,19 +2233,33 @@ class DeclarationReader {
|
|
|
2227
2233
|
* beside `runs`, `yields` or `mounts` (`claim_invalid`). With `collects`
|
|
2228
2234
|
* the member takes an object of procedures there (`collectsOutcome`), and
|
|
2229
2235
|
* its return, the collection, is read as a plain scope's is.
|
|
2236
|
+
*
|
|
2237
|
+
* Merged collections (amendment 9): `merges` is a third way to carry the
|
|
2238
|
+
* scope, alone and as `{ arg, each: true }`. The member's parameter at
|
|
2239
|
+
* `arg`, read through a rest (`parameterAt`), takes what a verified
|
|
2240
|
+
* `collects` scope of the request returns (`collectionSlotOutcome`), and
|
|
2241
|
+
* the return is read as a plain scope's is.
|
|
2230
2242
|
*/
|
|
2231
|
-
judgeScope(receiver, claim, built) {
|
|
2243
|
+
judgeScope(receiver, claim, built, collections) {
|
|
2232
2244
|
if (claim.form === 'decorate')
|
|
2233
2245
|
return { outcome: this.decorateScopeOutcome(receiver, claim) };
|
|
2234
2246
|
if ((claim.runs === undefined) !== (claim.yields === undefined))
|
|
2235
2247
|
return { outcome: unchecked('claim_invalid') };
|
|
2236
2248
|
if (claim.mounts !== undefined && claim.runs !== undefined)
|
|
2237
2249
|
return { outcome: unchecked('claim_invalid') };
|
|
2238
|
-
|
|
2250
|
+
const carried = [claim.name, claim.collects, claim.merges].filter(part => part !== undefined).length;
|
|
2251
|
+
if (carried !== 1)
|
|
2239
2252
|
return { outcome: unchecked('claim_invalid') };
|
|
2240
|
-
if (claim.collects !== undefined
|
|
2253
|
+
if ((claim.collects !== undefined || claim.merges !== undefined) &&
|
|
2254
|
+
(claim.runs !== undefined || claim.mounts !== undefined)) {
|
|
2255
|
+
return { outcome: unchecked('claim_invalid') };
|
|
2256
|
+
}
|
|
2257
|
+
const merges = claim.merges;
|
|
2258
|
+
if (merges !== undefined &&
|
|
2259
|
+
(merges.each !== true || merges.key !== undefined || merges.at !== undefined)) {
|
|
2241
2260
|
return { outcome: unchecked('claim_invalid') };
|
|
2242
2261
|
}
|
|
2262
|
+
const collected = merges === undefined ? undefined : collections?.();
|
|
2243
2263
|
const binds = claim.runs !== undefined || claim.mounts !== undefined;
|
|
2244
2264
|
const layout = this.layout({ name: claim.name, runs: claim.runs, mounts: claim.mounts });
|
|
2245
2265
|
if ('failure' in layout)
|
|
@@ -2247,6 +2267,8 @@ class DeclarationReader {
|
|
|
2247
2267
|
const callee = this.ownCallee(receiver, claim.path ?? [], claim.member, 'call');
|
|
2248
2268
|
if ('failure' in callee)
|
|
2249
2269
|
return { outcome: callee.failure };
|
|
2270
|
+
if (merges !== undefined && collected === undefined)
|
|
2271
|
+
return { outcome: failed('merges_unbound') };
|
|
2250
2272
|
const labels = claim.key_labels ?? {};
|
|
2251
2273
|
const holding = [];
|
|
2252
2274
|
let best;
|
|
@@ -2267,6 +2289,12 @@ class DeclarationReader {
|
|
|
2267
2289
|
if (collected)
|
|
2268
2290
|
result = { rank: 5, outcome: collected };
|
|
2269
2291
|
}
|
|
2292
|
+
if (result.rank === Infinity && merges !== undefined && collected !== undefined) {
|
|
2293
|
+
const merged = this.mergesNotRest(signature, merges.arg) ??
|
|
2294
|
+
this.collectionSlotOutcome(signature, this.mergedSlotAt(signature, merges.arg), collected, 'merges');
|
|
2295
|
+
if (merged)
|
|
2296
|
+
result = { rank: 5, outcome: merged };
|
|
2297
|
+
}
|
|
2270
2298
|
if (result.rank === Infinity && !binds && this.returnSaysNothing(this.returnOf(signature, built))) {
|
|
2271
2299
|
result = { rank: 6, outcome: unchecked('scope_unresolved') };
|
|
2272
2300
|
}
|
|
@@ -2345,22 +2373,57 @@ class DeclarationReader {
|
|
|
2345
2373
|
}
|
|
2346
2374
|
/**
|
|
2347
2375
|
* An adapter's `runs` slot (#2474 R6a) takes one of `collections`, the
|
|
2348
|
-
* types the request's verified `collects` scopes return
|
|
2349
|
-
* instance is (`fitsErased`, then assignability). A slot typed `any`,
|
|
2350
|
-
* `unknown`, `{}` or by an unconstrained type parameter says nothing
|
|
2351
|
-
* (`runs_untyped`). Undefined when it holds.
|
|
2376
|
+
* types the request's verified `collects` scopes return.
|
|
2352
2377
|
*/
|
|
2353
2378
|
runsCollectionOutcome(signature, declared, collections) {
|
|
2379
|
+
return this.collectionSlotOutcome(signature, declared, collections, 'runs');
|
|
2380
|
+
}
|
|
2381
|
+
/** A merge's slot at `index` must be a rest parameter (or an element of one): a plain parameter fails `merges_not_rest`. */
|
|
2382
|
+
mergesNotRest(signature, index) {
|
|
2383
|
+
const restIndex = this.restIndexOf(signature);
|
|
2384
|
+
const plain = restIndex === -1 || index < restIndex;
|
|
2385
|
+
return plain && index < signature.getParameters().length ? failed('merges_not_rest') : undefined;
|
|
2386
|
+
}
|
|
2387
|
+
/**
|
|
2388
|
+
* What a merge's rest slot takes at `index` (amendment 9): the element
|
|
2389
|
+
* `parameterAt` reads, and when that is itself a type parameter spread into
|
|
2390
|
+
* the rest (`...routers: [...R]` with `R extends Router[]`), its
|
|
2391
|
+
* constraint's element. Only that spread is unwrapped: a parameter that
|
|
2392
|
+
* takes an array of routers (`routers: Router[]`, `...lists: Router[][]`)
|
|
2393
|
+
* is a merge over an array, which amendment 9 leaves out.
|
|
2394
|
+
*/
|
|
2395
|
+
mergedSlotAt(signature, index) {
|
|
2396
|
+
const slot = this.parameterAt(signature, index, true);
|
|
2397
|
+
if (slot === undefined || slot === VARIADIC)
|
|
2398
|
+
return slot;
|
|
2399
|
+
const restIndex = this.restIndexOf(signature);
|
|
2400
|
+
if (restIndex === -1 || index < restIndex || !(slot.flags & ts.TypeFlags.TypeParameter))
|
|
2401
|
+
return slot;
|
|
2402
|
+
const through = this.throughConstraint(slot);
|
|
2403
|
+
if (through !== VARIADIC && this.checker.isArrayType(through)) {
|
|
2404
|
+
return this.checker.getTypeArguments(through)[0];
|
|
2405
|
+
}
|
|
2406
|
+
return slot;
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* A slot that takes one of `collections`, read as a mounted instance is
|
|
2410
|
+
* (`fitsErased`, then assignability): an adapter's `runs` slot and a merge's
|
|
2411
|
+
* rest slot (amendment 9). A slot typed `any`, `unknown`, `{}` or by an
|
|
2412
|
+
* unconstrained type parameter says nothing (`<reason>_untyped`); one that
|
|
2413
|
+
* takes none of them fails (`<reason>_not_collection`). Undefined when it
|
|
2414
|
+
* holds.
|
|
2415
|
+
*/
|
|
2416
|
+
collectionSlotOutcome(signature, declared, collections, reason) {
|
|
2354
2417
|
if (declared === undefined)
|
|
2355
2418
|
return failed('param_missing');
|
|
2356
2419
|
const slot = this.throughConstraint(declared);
|
|
2357
2420
|
if (slot === VARIADIC)
|
|
2358
|
-
return unchecked(
|
|
2421
|
+
return unchecked(`${reason}_untyped`);
|
|
2359
2422
|
const parts = this.parts(slot);
|
|
2360
2423
|
if (parts.length === 0)
|
|
2361
|
-
return failed(
|
|
2424
|
+
return failed(`${reason}_not_collection`);
|
|
2362
2425
|
if (parts.some(part => this.isOpenTop(part) || this.isUnconstrained(part) || this.isEmptyObject(part))) {
|
|
2363
|
-
return unchecked(
|
|
2426
|
+
return unchecked(`${reason}_untyped`);
|
|
2364
2427
|
}
|
|
2365
2428
|
const own = signature.typeParameters ?? [];
|
|
2366
2429
|
for (const collection of collections) {
|
|
@@ -2370,7 +2433,7 @@ class DeclarationReader {
|
|
|
2370
2433
|
if (erased === undefined && this.checker.isTypeAssignableTo(collection, slot))
|
|
2371
2434
|
return undefined;
|
|
2372
2435
|
}
|
|
2373
|
-
return failed(
|
|
2436
|
+
return failed(`${reason}_not_collection`);
|
|
2374
2437
|
}
|
|
2375
2438
|
/**
|
|
2376
2439
|
* `receiver` fits `slot` with the signature's own type parameters
|
|
@@ -2495,6 +2558,10 @@ class DeclarationReader {
|
|
|
2495
2558
|
}
|
|
2496
2559
|
if (form === 'decorate' && claim.op !== 'receive')
|
|
2497
2560
|
return unchecked('claim_invalid');
|
|
2561
|
+
// A name the decorated method gives (amendment 8) is read on a decorate receive only.
|
|
2562
|
+
const decorated = claim.name !== undefined && ('first' in claim.name || ('bound' in claim.name && claim.name.bound === 'decorated'));
|
|
2563
|
+
if (decorated && form !== 'decorate')
|
|
2564
|
+
return unchecked('claim_invalid');
|
|
2498
2565
|
// `returns` judges the handler a receive op registers.
|
|
2499
2566
|
if (claim.returns !== undefined && (claim.op !== 'receive' || claim.handler === undefined)) {
|
|
2500
2567
|
return unchecked('claim_invalid');
|
|
@@ -2518,6 +2585,11 @@ class DeclarationReader {
|
|
|
2518
2585
|
if (claim.request !== undefined && !requestAtValid(claim))
|
|
2519
2586
|
return unchecked('claim_invalid');
|
|
2520
2587
|
const name = claim.name;
|
|
2588
|
+
if (decorated && name !== undefined) {
|
|
2589
|
+
if ('first' in name && (name.first.length < 2 || name.first.length > 4))
|
|
2590
|
+
return unchecked('claim_invalid');
|
|
2591
|
+
return this.decoratedNameOutcome(receiver, claim, 'first' in name ? name.first : [{ bound: 'decorated' }]);
|
|
2592
|
+
}
|
|
2521
2593
|
// A send carries a payload: a name alone on `send(data)` is the data. An
|
|
2522
2594
|
// op that runs a function or client it is handed takes its name from
|
|
2523
2595
|
// what it runs, and one that hands its handler a receiver (a server's
|
|
@@ -2646,6 +2718,10 @@ class DeclarationReader {
|
|
|
2646
2718
|
const ran = this.boundRunsOutcome(receiver.makerHolding, boundRuns);
|
|
2647
2719
|
return ran.verdict === 'verified' && requestDropped !== undefined ? { ...ran, requestDropped } : ran;
|
|
2648
2720
|
}
|
|
2721
|
+
return this.opVerified(callee, bodyMembers, requestDropped);
|
|
2722
|
+
}
|
|
2723
|
+
/** A verified op: the callee's declarations and members, for `labelledMembers`. */
|
|
2724
|
+
opVerified(callee, bodyMembers = [], requestDropped) {
|
|
2649
2725
|
const declarations = this.declarationsOf(callee);
|
|
2650
2726
|
const members = callee.named
|
|
2651
2727
|
? (callee.named.property.declarations ?? [])
|
|
@@ -2658,6 +2734,113 @@ class DeclarationReader {
|
|
|
2658
2734
|
...(requestDropped === undefined ? {} : { requestDropped }),
|
|
2659
2735
|
};
|
|
2660
2736
|
}
|
|
2737
|
+
/**
|
|
2738
|
+
* A name read from the first entry the call fills, in order, or from the
|
|
2739
|
+
* decorated method alone (amendment 8 of carrick#2434): a GraphQL root field
|
|
2740
|
+
* written as a method decorator. The op is a decorate receive whose
|
|
2741
|
+
* decorated method is the handler, so it holds no other part. `first` has
|
|
2742
|
+
* two to four entries, none twice, `{ bound: 'decorated' }` only last.
|
|
2743
|
+
*
|
|
2744
|
+
* Strict D2 holds on EVERY overload that returns a method decorator, never
|
|
2745
|
+
* on one: a reader that falls back to the method on `@Query()` would also
|
|
2746
|
+
* write the method's name on `@Query('x')` unless every overload taking a
|
|
2747
|
+
* string there is a `first` entry. Per overload, D2 runs once for each
|
|
2748
|
+
* entry that takes a string there, that entry as the name and the others
|
|
2749
|
+
* accounted for; with none, it runs with no name, and any string slot
|
|
2750
|
+
* competes. Each slot entry takes a string on at least one such overload,
|
|
2751
|
+
* else the reason a name slot that takes none answers.
|
|
2752
|
+
*/
|
|
2753
|
+
decoratedNameOutcome(receiver, claim, entries) {
|
|
2754
|
+
if (claim.form !== 'decorate' || claim.op !== 'receive')
|
|
2755
|
+
return unchecked('claim_invalid');
|
|
2756
|
+
const parts = [
|
|
2757
|
+
claim.payload, claim.handler, claim.ack, claim.runs, claim.yields, claim.request, claim.returns,
|
|
2758
|
+
claim.method_key, claim.method_default, claim.options, claim.base,
|
|
2759
|
+
];
|
|
2760
|
+
if (parts.some(part => part !== undefined))
|
|
2761
|
+
return unchecked('claim_invalid');
|
|
2762
|
+
const slots = [];
|
|
2763
|
+
const seen = new Set();
|
|
2764
|
+
for (const [index, entry] of entries.entries()) {
|
|
2765
|
+
if ('bound' in entry) {
|
|
2766
|
+
if (index !== entries.length - 1)
|
|
2767
|
+
return unchecked('claim_invalid');
|
|
2768
|
+
continue;
|
|
2769
|
+
}
|
|
2770
|
+
const slot = { arg: entry.arg, ...(entry.key === undefined ? {} : { key: entry.key }) };
|
|
2771
|
+
const id = `${slot.arg}.${slot.key ?? ''}`;
|
|
2772
|
+
if (seen.has(id))
|
|
2773
|
+
return unchecked('claim_invalid');
|
|
2774
|
+
seen.add(id);
|
|
2775
|
+
slots.push(slot);
|
|
2776
|
+
}
|
|
2777
|
+
const callee = this.ownCallee(receiver, claim.path ?? [], claim.member, 'call');
|
|
2778
|
+
if ('failure' in callee)
|
|
2779
|
+
return callee.failure;
|
|
2780
|
+
const labels = claim.key_labels ?? {};
|
|
2781
|
+
let best;
|
|
2782
|
+
let decorators = 0;
|
|
2783
|
+
// Per slot entry, why it takes no string on an overload, until one where it does.
|
|
2784
|
+
const unread = new Map(slots.map(slot => [slot, undefined]));
|
|
2785
|
+
const takes = new Set();
|
|
2786
|
+
for (const signature of callee.signatures) {
|
|
2787
|
+
const given = this.decoratorOutcome(signature, 'method');
|
|
2788
|
+
if (given) {
|
|
2789
|
+
best = furthest(best, 1, given);
|
|
2790
|
+
continue;
|
|
2791
|
+
}
|
|
2792
|
+
decorators += 1;
|
|
2793
|
+
const here = [];
|
|
2794
|
+
for (const slot of slots) {
|
|
2795
|
+
const failure = this.nameEntryFailure(signature, slot);
|
|
2796
|
+
if (failure === undefined) {
|
|
2797
|
+
here.push(slot);
|
|
2798
|
+
takes.add(slot);
|
|
2799
|
+
}
|
|
2800
|
+
else {
|
|
2801
|
+
unread.set(slot, furthest(unread.get(slot), failure.rank, failure.outcome));
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
if (here.length === 0) {
|
|
2805
|
+
const ambiguity = this.nameSiblings(signature, { positional: new Map(), keyed: new Map() }, new Map(), labels, []);
|
|
2806
|
+
if (ambiguity)
|
|
2807
|
+
return ambiguity;
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
for (const slot of here) {
|
|
2811
|
+
const layout = this.layout({ name: slot });
|
|
2812
|
+
if ('failure' in layout)
|
|
2813
|
+
return layout.failure;
|
|
2814
|
+
const others = here.filter(other => other !== slot);
|
|
2815
|
+
const result = this.messageSignatureOutcome(signature, layout.value, labels, undefined, others);
|
|
2816
|
+
if (result.rank !== Infinity)
|
|
2817
|
+
return result.outcome;
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
if (decorators === 0)
|
|
2821
|
+
return best.outcome;
|
|
2822
|
+
for (const [slot, failure] of unread) {
|
|
2823
|
+
if (!takes.has(slot))
|
|
2824
|
+
return failure.outcome;
|
|
2825
|
+
}
|
|
2826
|
+
return this.opVerified(callee);
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Why a `first` slot takes no name string on one overload, or undefined
|
|
2830
|
+
* when it does: as a name slot is read (`messageSignatureOutcome`, steps 1
|
|
2831
|
+
* and 3).
|
|
2832
|
+
*/
|
|
2833
|
+
nameEntryFailure(signature, slot) {
|
|
2834
|
+
const declared = this.keyParameterAt(signature, slot.arg);
|
|
2835
|
+
if (declared === undefined)
|
|
2836
|
+
return { rank: 1, outcome: failed('param_missing') };
|
|
2837
|
+
if (slot.key === undefined) {
|
|
2838
|
+
const read = this.throughConditional(declared);
|
|
2839
|
+
return this.acceptsString(read) ? undefined : { rank: 1, outcome: this.slotFailure(read, 'name_not_string') };
|
|
2840
|
+
}
|
|
2841
|
+
const view = this.viewFor(declared, new Map([[slot.key, 'name']]), given => this.runsFailure(given));
|
|
2842
|
+
return 'rank' in view ? view : undefined;
|
|
2843
|
+
}
|
|
2661
2844
|
/**
|
|
2662
2845
|
* `form: set` on a send (amendment 7 part 3, carrick#3047): the service
|
|
2663
2846
|
* assigns the reply (`ctx.body = x`). `member` is a property that `path`
|
|
@@ -2741,6 +2924,7 @@ class DeclarationReader {
|
|
|
2741
2924
|
decorateScopeOutcome(receiver, claim) {
|
|
2742
2925
|
if (claim.name === undefined ||
|
|
2743
2926
|
claim.collects !== undefined ||
|
|
2927
|
+
claim.merges !== undefined ||
|
|
2744
2928
|
claim.runs !== undefined ||
|
|
2745
2929
|
claim.yields !== undefined ||
|
|
2746
2930
|
claim.mounts !== undefined) {
|
|
@@ -2901,6 +3085,10 @@ class DeclarationReader {
|
|
|
2901
3085
|
* call's other parts.
|
|
2902
3086
|
*/
|
|
2903
3087
|
methodOutcome(claim, rules, receiver) {
|
|
3088
|
+
// A GraphQL root field written as a decorator states its root word (amendment 8).
|
|
3089
|
+
if (claim.protocol === 'graphql' && claim.form === 'decorate' && claim.method === undefined) {
|
|
3090
|
+
return unchecked('claim_invalid');
|
|
3091
|
+
}
|
|
2904
3092
|
const words = methodWords(claim, rules);
|
|
2905
3093
|
// A procedure named by its key (#2474 R6a): a receive op with a handler.
|
|
2906
3094
|
// On http the label states its method, a route word, and the member names
|
|
@@ -3259,9 +3447,10 @@ class DeclarationReader {
|
|
|
3259
3447
|
* (design D2, `nameSiblings`).
|
|
3260
3448
|
*
|
|
3261
3449
|
* `runsAs` replaces the `runs` predicate (an adapter's collection, #2474
|
|
3262
|
-
* R6a); absent, a `runs` slot is a declared function.
|
|
3450
|
+
* R6a); absent, a `runs` slot is a declared function. `others` are a
|
|
3451
|
+
* `first` name's other entries (amendment 8), see `nameSiblings`.
|
|
3263
3452
|
*/
|
|
3264
|
-
messageSignatureOutcome(signature, layout, labels, runsAs) {
|
|
3453
|
+
messageSignatureOutcome(signature, layout, labels, runsAs, others) {
|
|
3265
3454
|
const runsFailure = runsAs ?? ((declared) => this.runsFailure(declared));
|
|
3266
3455
|
for (const [arg, part] of layout.positional) {
|
|
3267
3456
|
if (part === 'method') {
|
|
@@ -3322,7 +3511,7 @@ class DeclarationReader {
|
|
|
3322
3511
|
return view;
|
|
3323
3512
|
views.set(arg, view.view);
|
|
3324
3513
|
}
|
|
3325
|
-
const ambiguity = this.nameSiblings(signature, layout, views, labels);
|
|
3514
|
+
const ambiguity = this.nameSiblings(signature, layout, views, labels, others);
|
|
3326
3515
|
if (ambiguity)
|
|
3327
3516
|
return { rank: 4, outcome: ambiguity };
|
|
3328
3517
|
return { rank: Infinity, outcome: VERIFIED };
|
|
@@ -3413,7 +3602,10 @@ class DeclarationReader {
|
|
|
3413
3602
|
* The labels must agree with the claim: at most one key is labelled `name`,
|
|
3414
3603
|
* and only the claim's own name key; that key is never labelled `not_name`.
|
|
3415
3604
|
* A `not_name` label for a key an overload does not declare is ignored
|
|
3416
|
-
* (one label map serves every overload). No name, no rule
|
|
3605
|
+
* (one label map serves every overload). No name, no rule, except for a
|
|
3606
|
+
* `first` name (amendment 8): `others` are its other entries that take a
|
|
3607
|
+
* string on this overload, accounted for as the name is, and the rule holds
|
|
3608
|
+
* with no name in the run at all.
|
|
3417
3609
|
*
|
|
3418
3610
|
* Rest parameters: a rest the claim puts a payload or handler in belongs
|
|
3419
3611
|
* wholly to that part; one that holds the name holds other names too; from
|
|
@@ -3423,7 +3615,7 @@ class DeclarationReader {
|
|
|
3423
3615
|
* cannot be read at all (`...args: Rest<B>`, a conditional on a type
|
|
3424
3616
|
* parameter), since it could hold a string slot.
|
|
3425
3617
|
*/
|
|
3426
|
-
nameSiblings(signature, layout, views, labels) {
|
|
3618
|
+
nameSiblings(signature, layout, views, labels, others) {
|
|
3427
3619
|
const namedAt = [...layout.positional].find(([, part]) => part === 'name')?.[0];
|
|
3428
3620
|
let nameKey;
|
|
3429
3621
|
for (const keys of layout.keyed.values()) {
|
|
@@ -3431,15 +3623,28 @@ class DeclarationReader {
|
|
|
3431
3623
|
if (part === 'name')
|
|
3432
3624
|
nameKey = key;
|
|
3433
3625
|
}
|
|
3434
|
-
|
|
3626
|
+
// A `first` name (amendment 8) is judged with no name of its own too: a
|
|
3627
|
+
// string slot there is one a fallback name would be written over.
|
|
3628
|
+
if (namedAt === undefined && nameKey === undefined && others === undefined)
|
|
3435
3629
|
return undefined;
|
|
3436
3630
|
const ambiguous = failed('name_ambiguous');
|
|
3631
|
+
// The `first` entries beside this run's name, which name the op on another
|
|
3632
|
+
// call: a position, or a key of the object at one.
|
|
3633
|
+
const otherAt = new Set((others ?? []).filter(slot => slot.key === undefined).map(slot => slot.arg));
|
|
3634
|
+
const otherKeys = new Map();
|
|
3635
|
+
for (const slot of others ?? []) {
|
|
3636
|
+
if (slot.key !== undefined)
|
|
3637
|
+
otherKeys.set(slot.arg, (otherKeys.get(slot.arg) ?? new Set()).add(slot.key));
|
|
3638
|
+
}
|
|
3639
|
+
const nameKeys = new Set([...otherKeys.values()].flatMap(keys => [...keys]));
|
|
3640
|
+
if (nameKey !== undefined)
|
|
3641
|
+
nameKeys.add(nameKey);
|
|
3437
3642
|
const nameLabels = Object.keys(labels).filter(key => labels[key] === 'name');
|
|
3438
3643
|
if (nameLabels.length > 1)
|
|
3439
3644
|
return ambiguous;
|
|
3440
|
-
if (nameLabels.length === 1 && nameLabels[0]
|
|
3645
|
+
if (nameLabels.length === 1 && !nameKeys.has(nameLabels[0]))
|
|
3441
3646
|
return ambiguous;
|
|
3442
|
-
if (
|
|
3647
|
+
if ([...nameKeys].some(key => labels[key] === 'not_name'))
|
|
3443
3648
|
return ambiguous;
|
|
3444
3649
|
// A string key at the call the claim neither assigns nor labels.
|
|
3445
3650
|
const unaccountedKey = (keys, assigned) => keys.some(key => !assigned.has(key) && labels[key] !== 'not_name');
|
|
@@ -3448,11 +3653,14 @@ class DeclarationReader {
|
|
|
3448
3653
|
// An argument the claim gives no part: a string, an object with a string
|
|
3449
3654
|
// key nobody accounts for, or a rest the verifier cannot read, which could
|
|
3450
3655
|
// hold either and no label can account for (fail closed, carrick#1687).
|
|
3451
|
-
const competes = (slot) => slot === VARIADIC ||
|
|
3656
|
+
const competes = (slot, i) => slot === VARIADIC ||
|
|
3657
|
+
takesString(slot) ||
|
|
3658
|
+
unaccountedKey(this.stringKeys(slot), (i === undefined ? undefined : otherKeys.get(i)) ?? none);
|
|
3452
3659
|
// Every object the claim reads keys of: its other string keys.
|
|
3453
3660
|
for (const [arg, keys] of layout.keyed) {
|
|
3454
3661
|
const view = views.get(arg);
|
|
3455
|
-
|
|
3662
|
+
const accounted = new Set([...keys.keys(), ...(otherKeys.get(arg) ?? [])]);
|
|
3663
|
+
if (view && unaccountedKey(this.stringKeys(view), accounted))
|
|
3456
3664
|
return ambiguous;
|
|
3457
3665
|
}
|
|
3458
3666
|
const parameters = signature.getParameters();
|
|
@@ -3460,11 +3668,14 @@ class DeclarationReader {
|
|
|
3460
3668
|
const lastDeclaration = last?.valueDeclaration;
|
|
3461
3669
|
const restIndex = lastDeclaration && ts.isParameter(lastDeclaration) && lastDeclaration.dotDotDotToken ? parameters.length - 1 : -1;
|
|
3462
3670
|
const fixed = restIndex === -1 ? parameters.length : restIndex;
|
|
3463
|
-
const assigned = (i) => layout.positional.has(i) || layout.keyed.has(i);
|
|
3671
|
+
const assigned = (i) => layout.positional.has(i) || layout.keyed.has(i) || otherAt.has(i);
|
|
3672
|
+
// A rest never holds a `first` position: it would hold other names too.
|
|
3673
|
+
if (restIndex !== -1 && [...otherAt].some(arg => arg >= restIndex))
|
|
3674
|
+
return ambiguous;
|
|
3464
3675
|
for (let i = 0; i < fixed; i++) {
|
|
3465
3676
|
if (assigned(i))
|
|
3466
3677
|
continue;
|
|
3467
|
-
if (competes(this.keyParameterAt(signature, i)))
|
|
3678
|
+
if (competes(this.keyParameterAt(signature, i), i))
|
|
3468
3679
|
return ambiguous;
|
|
3469
3680
|
}
|
|
3470
3681
|
if (restIndex === -1)
|
|
@@ -3478,7 +3689,7 @@ class DeclarationReader {
|
|
|
3478
3689
|
for (let i = restIndex; i < restIndex + fixedLength; i++) {
|
|
3479
3690
|
if (assigned(i))
|
|
3480
3691
|
continue;
|
|
3481
|
-
if (competes(this.keyParameterAt(signature, i)))
|
|
3692
|
+
if (competes(this.keyParameterAt(signature, i), i))
|
|
3482
3693
|
return ambiguous;
|
|
3483
3694
|
}
|
|
3484
3695
|
if (variable !== -1) {
|
|
@@ -5450,6 +5661,12 @@ class DeclarationReader {
|
|
|
5450
5661
|
parts(type) {
|
|
5451
5662
|
return (type.isUnion() ? type.types : [type]).filter(part => !isNullish(part));
|
|
5452
5663
|
}
|
|
5664
|
+
/** The index of the signature's rest parameter, or -1 when it has none. */
|
|
5665
|
+
restIndexOf(signature) {
|
|
5666
|
+
const parameters = signature.getParameters();
|
|
5667
|
+
const declaration = parameters[parameters.length - 1]?.valueDeclaration;
|
|
5668
|
+
return declaration && ts.isParameter(declaration) && declaration.dotDotDotToken ? parameters.length - 1 : -1;
|
|
5669
|
+
}
|
|
5453
5670
|
/**
|
|
5454
5671
|
* What the signature has at parameter `index`, reading through a rest
|
|
5455
5672
|
* parameter; `undefined` when it has none there. A rest typed by a type
|
|
@@ -5459,10 +5676,7 @@ class DeclarationReader {
|
|
|
5459
5676
|
parameterAt(signature, index, readConstraint = false) {
|
|
5460
5677
|
const parameters = signature.getParameters();
|
|
5461
5678
|
const last = parameters[parameters.length - 1];
|
|
5462
|
-
const
|
|
5463
|
-
const restIndex = declaration && ts.isParameter(declaration) && declaration.dotDotDotToken
|
|
5464
|
-
? parameters.length - 1
|
|
5465
|
-
: -1;
|
|
5679
|
+
const restIndex = this.restIndexOf(signature);
|
|
5466
5680
|
if (restIndex === -1 || index < restIndex) {
|
|
5467
5681
|
return index < parameters.length ? this.checker.getTypeOfSymbol(parameters[index]) : undefined;
|
|
5468
5682
|
}
|
|
@@ -876,11 +876,29 @@ export class PositionWalker {
|
|
|
876
876
|
exportName = key ? key.text : declaration.name.text;
|
|
877
877
|
initializer = declaration.parent.parent.initializer;
|
|
878
878
|
}
|
|
879
|
+
let castSpecifier;
|
|
880
|
+
while (initializer &&
|
|
881
|
+
(ts.isParenthesizedExpression(initializer) ||
|
|
882
|
+
ts.isAsExpression(initializer) ||
|
|
883
|
+
ts.isSatisfiesExpression(initializer) ||
|
|
884
|
+
ts.isTypeAssertionExpression(initializer) ||
|
|
885
|
+
ts.isNonNullExpression(initializer))) {
|
|
886
|
+
const type = ts.isNonNullExpression(initializer) || ts.isParenthesizedExpression(initializer) ? undefined : initializer.type;
|
|
887
|
+
if (castSpecifier === undefined && type && ts.isImportTypeNode(type) && type.isTypeOf) {
|
|
888
|
+
const arg = type.argument;
|
|
889
|
+
if (ts.isLiteralTypeNode(arg) && ts.isStringLiteral(arg.literal))
|
|
890
|
+
castSpecifier = arg.literal.text;
|
|
891
|
+
}
|
|
892
|
+
initializer = initializer.expression;
|
|
893
|
+
}
|
|
879
894
|
const specifier = initializer ? this.requireSpecifier(initializer) : undefined;
|
|
880
895
|
if (specifier === undefined)
|
|
881
896
|
return undefined;
|
|
882
897
|
const from = declaration.getSourceFile();
|
|
883
|
-
|
|
898
|
+
const binding = exportName === undefined ? { specifier, from } : { specifier, from, exportName };
|
|
899
|
+
if (castSpecifier !== undefined)
|
|
900
|
+
binding.castSpecifier = castSpecifier;
|
|
901
|
+
return binding;
|
|
884
902
|
}
|
|
885
903
|
/** `"m"` of a call `require("m")` to the global `require`, else `undefined`. */
|
|
886
904
|
requireSpecifier(expression) {
|
|
@@ -896,8 +914,12 @@ export class PositionWalker {
|
|
|
896
914
|
return own ? undefined : argument.text;
|
|
897
915
|
}
|
|
898
916
|
exportOfRequired(binding) {
|
|
899
|
-
const
|
|
900
|
-
|
|
917
|
+
const sourceOf = (specifier) => {
|
|
918
|
+
const resolved = ts.resolveModuleName(specifier, binding.from.fileName, this.program.getCompilerOptions(), this.resolutionHost(), undefined, undefined, ts.ModuleKind.CommonJS).resolvedModule;
|
|
919
|
+
return resolved ? this.program.getSourceFile(resolved.resolvedFileName) : undefined;
|
|
920
|
+
};
|
|
921
|
+
// The require that runs wins; the cast is read only when it names no file.
|
|
922
|
+
const target = sourceOf(binding.specifier) ?? (binding.castSpecifier !== undefined ? sourceOf(binding.castSpecifier) : undefined);
|
|
901
923
|
if (!target)
|
|
902
924
|
return undefined;
|
|
903
925
|
if (binding.exportName === undefined)
|
|
@@ -566,16 +566,32 @@ export interface NameParts {
|
|
|
566
566
|
export interface NameLiteral {
|
|
567
567
|
literal: string;
|
|
568
568
|
}
|
|
569
|
+
/** A `first` entry (amendment 8): a plain slot, or the decorated method's name. */
|
|
570
|
+
export type NameEntry = {
|
|
571
|
+
arg: number;
|
|
572
|
+
key?: string;
|
|
573
|
+
} | {
|
|
574
|
+
bound: 'decorated';
|
|
575
|
+
};
|
|
576
|
+
/**
|
|
577
|
+
* The first entry the call fills names the op, read in order (amendment 8):
|
|
578
|
+
* two to four entries, `{ bound: 'decorated' }` only last, on a decorate
|
|
579
|
+
* receive.
|
|
580
|
+
*/
|
|
581
|
+
export interface NameFirst {
|
|
582
|
+
first: NameEntry[];
|
|
583
|
+
}
|
|
569
584
|
/** Where an op's name comes from. */
|
|
570
|
-
export type OpNameSource = BoundName | NameParts | NameLiteral | NameSlot;
|
|
585
|
+
export type OpNameSource = BoundName | NameParts | NameLiteral | NameFirst | NameSlot;
|
|
571
586
|
/**
|
|
572
587
|
* A name the call does not carry: the one the maker's `name` slot bound to
|
|
573
588
|
* the instance (`maker`), the one the scope member bound (`scope`), or the
|
|
574
589
|
* key path the op's value sits under in a `collects` object (`key`, #2474
|
|
575
|
-
* R6a)
|
|
590
|
+
* R6a), or the name of the class member a decorator is applied to
|
|
591
|
+
* (`decorated`, amendment 8).
|
|
576
592
|
*/
|
|
577
593
|
export interface BoundName {
|
|
578
|
-
bound: 'maker' | 'scope' | 'key' | 'path' | 'export' | 'subscribed';
|
|
594
|
+
bound: 'maker' | 'scope' | 'key' | 'path' | 'export' | 'subscribed' | 'decorated';
|
|
579
595
|
/** `path`: the property names walked on the receiver are joined by this (amendment 7). */
|
|
580
596
|
join?: string;
|
|
581
597
|
/** `subscribed`: the handler parameter that is handed the name. */
|
|
@@ -681,7 +697,7 @@ export type LibraryClaim = {
|
|
|
681
697
|
member: string;
|
|
682
698
|
/** Amendment 7: absent is `call`; `decorate` is a class decorator whose name prefixes its methods' ops. */
|
|
683
699
|
form?: 'call' | 'decorate';
|
|
684
|
-
/** Exactly one of `name` and `
|
|
700
|
+
/** Exactly one of `name`, `collects` and `merges` (#2474 R6a). */
|
|
685
701
|
name?: NameSlot;
|
|
686
702
|
path?: string[];
|
|
687
703
|
on?: ClaimOn;
|
|
@@ -700,6 +716,13 @@ export type LibraryClaim = {
|
|
|
700
716
|
mounts?: ClaimSlot;
|
|
701
717
|
/** Procedure routers (#2474 R6a): the member collects procedures by key and returns the collection. */
|
|
702
718
|
collects?: Collects;
|
|
719
|
+
/**
|
|
720
|
+
* Merged collections (amendment 9 on carrick#2434): the member takes
|
|
721
|
+
* the collections a verified `collects` member returns at `arg` and at
|
|
722
|
+
* every argument after it (`each: true`), and returns one collection
|
|
723
|
+
* serving all their procedures at the same level.
|
|
724
|
+
*/
|
|
725
|
+
merges?: ClaimSlot;
|
|
703
726
|
} | {
|
|
704
727
|
kind: 'op';
|
|
705
728
|
op: LibraryOp;
|