carrick 0.3.145 → 0.3.147
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 +4 -4
- package/dist/cli.d.ts +8 -1
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +31 -0
- package/dist/contract.js +29 -3
- package/dist/contract.js.map +1 -1
- package/dist/diagnostics.js +1 -9
- package/dist/diagnostics.js.map +1 -1
- package/dist/fs-util.d.ts +6 -0
- package/dist/fs-util.js +29 -0
- package/dist/fs-util.js.map +1 -0
- package/dist/global-install.js +1 -8
- package/dist/global-install.js.map +1 -1
- package/dist/hook/apply-patch.js +3 -4
- package/dist/hook/apply-patch.js.map +1 -1
- package/dist/hook/checked.d.ts +3 -1
- package/dist/hook/checked.js +9 -2
- package/dist/hook/checked.js.map +1 -1
- package/dist/hook/late.js +9 -2
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-edit.js +33 -24
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +1 -6
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/rechecks.d.ts +45 -1
- package/dist/hook/rechecks.js +116 -10
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/reuse.d.ts +31 -58
- package/dist/hook/reuse.js +48 -112
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-start.d.ts +9 -0
- package/dist/hook/session-start.js +43 -16
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stdin.d.ts +2 -0
- package/dist/hook/stdin.js +8 -0
- package/dist/hook/stdin.js.map +1 -0
- package/dist/hook/stop-wait.d.ts +24 -1
- package/dist/hook/stop-wait.js +163 -28
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/stop.js +17 -36
- package/dist/hook/stop.js.map +1 -1
- package/dist/hook/user-prompt.js +13 -30
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hosted-snapshot.d.ts +37 -0
- package/dist/hosted-snapshot.js +49 -0
- package/dist/hosted-snapshot.js.map +1 -0
- package/dist/init/agents-section.d.ts +16 -2
- package/dist/init/agents-section.js +43 -7
- package/dist/init/agents-section.js.map +1 -1
- package/dist/init/codex.js +8 -7
- package/dist/init/codex.js.map +1 -1
- package/dist/init/mcp.js +1 -3
- package/dist/init/mcp.js.map +1 -1
- package/dist/init/remove.d.ts +2 -0
- package/dist/init/remove.js +18 -4
- package/dist/init/remove.js.map +1 -1
- package/dist/init/repo-copies.js +2 -10
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/repos.d.ts +0 -2
- package/dist/init/repos.js +1 -9
- package/dist/init/repos.js.map +1 -1
- package/dist/init/run.js +14 -4
- package/dist/init/run.js.map +1 -1
- package/dist/init/self-update.d.ts +2 -2
- package/dist/init/self-update.js +89 -3
- package/dist/init/self-update.js.map +1 -1
- package/dist/init/settings.js +5 -7
- package/dist/init/settings.js.map +1 -1
- package/dist/native.js +1 -9
- package/dist/native.js.map +1 -1
- package/dist/render.d.ts +54 -11
- package/dist/render.js +188 -34
- package/dist/render.js.map +1 -1
- package/dist/root.d.ts +1 -2
- package/dist/root.js +1 -9
- package/dist/root.js.map +1 -1
- package/dist/surfaces.js +1 -3
- package/dist/surfaces.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/bundler.js +30 -28
- package/sidecar/dist/src/capture/service-config.d.ts +6 -0
- package/sidecar/dist/src/capture/service-config.js +11 -1
- package/sidecar/dist/src/library-claims.js +14 -0
- package/sidecar/dist/src/platform-body-read.d.ts +46 -0
- package/sidecar/dist/src/platform-body-read.js +82 -0
- package/sidecar/dist/src/response-modes.d.ts +5 -4
- package/sidecar/dist/src/response-modes.js +21 -25
- package/sidecar/dist/src/retype.js +11 -16
- package/sidecar/dist/src/stated-params.d.ts +6 -0
- package/sidecar/dist/src/stated-params.js +13 -0
- package/sidecar/dist/src/type-inferrer.d.ts +47 -14
- package/sidecar/dist/src/type-inferrer.js +119 -62
- package/sidecar/dist/src/types.d.ts +20 -3
- package/templates/skills/carrick-census.md +24 -3
- package/templates/skills/carrick-drift.md +11 -3
- package/templates/skills/carrick-impact.md +8 -3
- package/dist/hook/edited.d.ts +0 -22
- package/dist/hook/edited.js +0 -84
- package/dist/hook/edited.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carrick",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.147",
|
|
4
4
|
"carrickCache": {
|
|
5
5
|
"cache_version": 22,
|
|
6
6
|
"intent_cache_version": 2
|
|
@@ -115,11 +115,11 @@
|
|
|
115
115
|
"zod": "^3.23.0"
|
|
116
116
|
},
|
|
117
117
|
"optionalDependencies": {
|
|
118
|
-
"@carrick-tools/cli-darwin-arm64": "0.3.
|
|
119
|
-
"@carrick-tools/cli-darwin-x64": "0.3.
|
|
120
|
-
"@carrick-tools/cli-linux-arm64": "0.3.
|
|
121
|
-
"@carrick-tools/cli-linux-x64": "0.3.
|
|
122
|
-
"@carrick-tools/cli-win32-x64": "0.3.
|
|
118
|
+
"@carrick-tools/cli-darwin-arm64": "0.3.147",
|
|
119
|
+
"@carrick-tools/cli-darwin-x64": "0.3.147",
|
|
120
|
+
"@carrick-tools/cli-linux-arm64": "0.3.147",
|
|
121
|
+
"@carrick-tools/cli-linux-x64": "0.3.147",
|
|
122
|
+
"@carrick-tools/cli-win32-x64": "0.3.147"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
125
|
"@types/node": "^24.13.3"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carrick",
|
|
3
3
|
"description": "Claude Code plugin for Carrick, which indexes TypeScript codebases across service and repository boundaries. After each edit it adds the file's routes, calls, and cross-service type mismatches to the session, and it registers Carrick's language server. It pairs with the Carrick MCP server, which lets agents search functions by intent rather than name.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.147",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Carrick",
|
|
7
7
|
"email": "hello@carrick.tools"
|
|
@@ -27,6 +27,16 @@ function declaresName(sourceFile, name) {
|
|
|
27
27
|
sourceFile.getVariableDeclaration(name) ??
|
|
28
28
|
sourceFile.getFunction(name));
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether `sourceFile` declares `name` as a type: an interface, a type alias,
|
|
32
|
+
* a class or an enum. A variable or a function is a value only.
|
|
33
|
+
*/
|
|
34
|
+
function declaresType(sourceFile, name) {
|
|
35
|
+
return Boolean(sourceFile.getInterface(name) ??
|
|
36
|
+
sourceFile.getTypeAlias(name) ??
|
|
37
|
+
sourceFile.getClass(name) ??
|
|
38
|
+
sourceFile.getEnum(name));
|
|
39
|
+
}
|
|
30
40
|
/**
|
|
31
41
|
* The declarations `name` resolves to when imported from `sourceFile`
|
|
32
42
|
* (carrick#1605), or `ambiguous`.
|
|
@@ -223,6 +233,7 @@ export class TypeBundler {
|
|
|
223
233
|
symbol_name: symbol.symbol_name,
|
|
224
234
|
source_file: symbol.source_file,
|
|
225
235
|
reason: result.reason || 'Unknown error',
|
|
236
|
+
...(result.kind ? { kind: result.kind } : {}),
|
|
226
237
|
});
|
|
227
238
|
}
|
|
228
239
|
}
|
|
@@ -263,7 +274,19 @@ export class TypeBundler {
|
|
|
263
274
|
};
|
|
264
275
|
}
|
|
265
276
|
const site = declarationSite(sourceFile, symbol.symbol_name, symbol.source_file, this.expandOrigin());
|
|
266
|
-
|
|
277
|
+
if ('reason' in site)
|
|
278
|
+
return { valid: false, reason: site.reason };
|
|
279
|
+
// A model may name the value a handler reads its payload from (a service
|
|
280
|
+
// object, a function) as the payload's type. A value is not a type: the
|
|
281
|
+
// inference asked for the same alias defines it (blueprint row N10c).
|
|
282
|
+
if (!declaresType(site.sourceFile, site.name)) {
|
|
283
|
+
return {
|
|
284
|
+
valid: false,
|
|
285
|
+
reason: `Symbol '${symbol.symbol_name}' in ${symbol.source_file} is a value, not a type`,
|
|
286
|
+
kind: 'not_a_type',
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return { valid: true };
|
|
267
290
|
}
|
|
268
291
|
/** Where a requested symbol is declared, or undefined when it cannot be found. */
|
|
269
292
|
siteOf(symbol) {
|
|
@@ -382,15 +405,15 @@ export class TypeBundler {
|
|
|
382
405
|
}
|
|
383
406
|
/// Whether the element type must be parenthesised before an `[]` suffix.
|
|
384
407
|
/// Interfaces/classes/enums are always object/nominal (never a top-level
|
|
385
|
-
/// union), so only type aliases
|
|
386
|
-
///
|
|
387
|
-
///
|
|
408
|
+
/// union), so only type aliases can carry a bare union/intersection/function
|
|
409
|
+
/// that would misparse; those are re-resolved from the source Type here
|
|
410
|
+
/// (this runs only on the rare array_depth path).
|
|
388
411
|
elementNeedsArrayParens(symbol) {
|
|
389
412
|
const site = this.siteOf(symbol);
|
|
390
413
|
if (!site)
|
|
391
414
|
return false;
|
|
392
415
|
const { sourceFile, name } = site;
|
|
393
|
-
const decl = sourceFile.getTypeAlias(name)
|
|
416
|
+
const decl = sourceFile.getTypeAlias(name);
|
|
394
417
|
if (!decl)
|
|
395
418
|
return false;
|
|
396
419
|
const t = decl.getType();
|
|
@@ -494,29 +517,8 @@ export class TypeBundler {
|
|
|
494
517
|
: `export ${text}`;
|
|
495
518
|
return { definition, typeString, typeStringIsExpression: false };
|
|
496
519
|
}
|
|
497
|
-
//
|
|
498
|
-
|
|
499
|
-
if (varDecl) {
|
|
500
|
-
const type = varDecl.getType();
|
|
501
|
-
const typeString = type.getText();
|
|
502
|
-
const definition = `export type ${alias} = ${typeString};`;
|
|
503
|
-
return { definition, typeString, typeStringIsExpression: true };
|
|
504
|
-
}
|
|
505
|
-
// Try function
|
|
506
|
-
const funcDecl = sourceFile.getFunction(symbolName);
|
|
507
|
-
if (funcDecl) {
|
|
508
|
-
const text = funcDecl.getText();
|
|
509
|
-
const typeString = text;
|
|
510
|
-
const alreadyExported = text.trimStart().startsWith('export');
|
|
511
|
-
const definition = alias !== symbolName
|
|
512
|
-
? (alreadyExported
|
|
513
|
-
? text.replace(`function ${symbolName}`, `declare function ${alias}`)
|
|
514
|
-
: text.replace(`function ${symbolName}`, `export declare function ${alias}`))
|
|
515
|
-
: alreadyExported
|
|
516
|
-
? text
|
|
517
|
-
: `export declare ${text}`;
|
|
518
|
-
return { definition, typeString, typeStringIsExpression: false };
|
|
519
|
-
}
|
|
520
|
+
// A variable or a function is a value, never bundled: `validateSymbol`
|
|
521
|
+
// fails it as `not_a_type` (blueprint row N10c).
|
|
520
522
|
return null;
|
|
521
523
|
}
|
|
522
524
|
isPathSource(sourceFile) {
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* `lib`) is typed under that config, as the repo's own `tsc` types it; without
|
|
12
12
|
* it, every import only that config resolves read `any`.
|
|
13
13
|
*
|
|
14
|
+
* A service-root `jsconfig.json` ranks after those names and before an
|
|
15
|
+
* ancestor `tsconfig.json` (carrick#3497): tsserver types a JavaScript file
|
|
16
|
+
* under the jsconfig beside it, not under a config above. Where no ancestor
|
|
17
|
+
* config exists the answer stays undefined, as before: the service is then
|
|
18
|
+
* typed per file by `fileConfigPath`, which reads the same jsconfig.
|
|
19
|
+
*
|
|
14
20
|
* The walk stops at the scan root, inclusive: a config outside the scanned
|
|
15
21
|
* tree is never read. With no scan root, or a service outside it, only the
|
|
16
22
|
* service root is searched.
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* `lib`) is typed under that config, as the repo's own `tsc` types it; without
|
|
12
12
|
* it, every import only that config resolves read `any`.
|
|
13
13
|
*
|
|
14
|
+
* A service-root `jsconfig.json` ranks after those names and before an
|
|
15
|
+
* ancestor `tsconfig.json` (carrick#3497): tsserver types a JavaScript file
|
|
16
|
+
* under the jsconfig beside it, not under a config above. Where no ancestor
|
|
17
|
+
* config exists the answer stays undefined, as before: the service is then
|
|
18
|
+
* typed per file by `fileConfigPath`, which reads the same jsconfig.
|
|
19
|
+
*
|
|
14
20
|
* The walk stops at the scan root, inclusive: a config outside the scanned
|
|
15
21
|
* tree is never read. With no scan root, or a service outside it, only the
|
|
16
22
|
* service root is searched.
|
|
@@ -19,6 +25,8 @@ import * as fs from 'node:fs';
|
|
|
19
25
|
import * as path from 'node:path';
|
|
20
26
|
/** The names a service root is searched for, in order. */
|
|
21
27
|
const SERVICE_ROOT_NAMES = ['tsconfig.json', 'tsconfig.build.json', 'tsconfig.app.json'];
|
|
28
|
+
/** The root config tsserver types a JavaScript service under, after the names above. */
|
|
29
|
+
const SERVICE_ROOT_JSCONFIG = 'jsconfig.json';
|
|
22
30
|
/** The name an ancestor directory is searched for, as `tsc` searches. */
|
|
23
31
|
const ANCESTOR_NAME = 'tsconfig.json';
|
|
24
32
|
/** Absolute path of the config that types the service, or undefined for none. */
|
|
@@ -29,6 +37,8 @@ export function findServiceTsconfig(serviceRoot, scanRoot) {
|
|
|
29
37
|
if (fs.existsSync(candidate))
|
|
30
38
|
return candidate;
|
|
31
39
|
}
|
|
40
|
+
const jsconfig = path.join(root, SERVICE_ROOT_JSCONFIG);
|
|
41
|
+
const ownJsconfig = fs.existsSync(jsconfig) ? jsconfig : undefined;
|
|
32
42
|
if (scanRoot === undefined)
|
|
33
43
|
return undefined;
|
|
34
44
|
// Containment is decided on real paths, so a symlink on either end cannot
|
|
@@ -42,7 +52,7 @@ export function findServiceTsconfig(serviceRoot, scanRoot) {
|
|
|
42
52
|
dir = path.dirname(dir);
|
|
43
53
|
const candidate = path.join(dir, ANCESTOR_NAME);
|
|
44
54
|
if (fs.existsSync(candidate))
|
|
45
|
-
return candidate;
|
|
55
|
+
return ownJsconfig ?? candidate;
|
|
46
56
|
}
|
|
47
57
|
return undefined;
|
|
48
58
|
}
|
|
@@ -1864,6 +1864,20 @@ class DeclarationReader {
|
|
|
1864
1864
|
if (claim.kind !== 'op' || claim.op !== 'request' || claim.handler || claim.ack || claim.path !== undefined) {
|
|
1865
1865
|
return unchecked('claim_invalid');
|
|
1866
1866
|
}
|
|
1867
|
+
const outcome = this.judgeHttpOp(receiver, claim);
|
|
1868
|
+
if (outcome.verdict !== 'verified')
|
|
1869
|
+
return outcome;
|
|
1870
|
+
// The member it judged (carrick#3044 S1): the position row of a call of
|
|
1871
|
+
// that member joins on it, whatever holds the call's receiver.
|
|
1872
|
+
const callable = claim.member === null ? this.callSignatures(receiver) : this.callableProperty(receiver, claim.member);
|
|
1873
|
+
if ('failure' in callable)
|
|
1874
|
+
return outcome;
|
|
1875
|
+
const property = claim.member === null ? undefined : this.declaredProperty(receiver, claim.member);
|
|
1876
|
+
const declarations = this.declarationsOf(property ? { ...callable, named: { property, holder: receiver } } : callable);
|
|
1877
|
+
return declarations.length > 0 ? { ...outcome, declarations } : outcome;
|
|
1878
|
+
}
|
|
1879
|
+
/** The #1564 request check of an `op` claim already known to be an HTTP request shape. */
|
|
1880
|
+
judgeHttpOp(receiver, claim) {
|
|
1867
1881
|
const name = claim.name;
|
|
1868
1882
|
if (name !== undefined && !('arg' in name))
|
|
1869
1883
|
return unchecked('claim_invalid');
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform's body reads (blueprint row N33).
|
|
3
|
+
*
|
|
4
|
+
* A zero-argument `json()`, `text()`, `arrayBuffer()`, `blob()`, `bytes()` or
|
|
5
|
+
* `formData()` takes the whole body out of the platform's `Request` or
|
|
6
|
+
* `Response`. The member's name picks which read it is; it never decides
|
|
7
|
+
* that it is one. That is decided by the value the member is called on: its
|
|
8
|
+
* type is a global the runtime declares, in the compiler's default library
|
|
9
|
+
* (`lib.dom.d.ts`) or an installed runtime typings package that declares it
|
|
10
|
+
* as a global (`declare global { interface Response ... }`). A repository's
|
|
11
|
+
* own class with a `json()` member reads its own value, and a client that
|
|
12
|
+
* copies the platform's shape from a package of its own is read through the
|
|
13
|
+
* library store's label for its result, never by this name.
|
|
14
|
+
*
|
|
15
|
+
* A receiver nothing declares (`any` or `unknown`: `fetch` on a checkout whose
|
|
16
|
+
* configuration loads neither the DOM library nor installed runtime typings)
|
|
17
|
+
* has no declaration to decide by, so there the name is all there is and the
|
|
18
|
+
* read is taken as it always was. A declaration that is not the runtime's
|
|
19
|
+
* always decides against it.
|
|
20
|
+
*/
|
|
21
|
+
import { Node, ts, type CallExpression } from 'ts-morph';
|
|
22
|
+
/** The reads that take the whole body as JSON or as raw text (carrick#1842). */
|
|
23
|
+
export declare const WHOLE_BODY_READS: ReadonlySet<string>;
|
|
24
|
+
/** The JSON read alone. */
|
|
25
|
+
export declare const JSON_READ: ReadonlySet<string>;
|
|
26
|
+
/** The whole-body reads that are neither JSON nor text (carrick#2112). */
|
|
27
|
+
export declare const BINARY_BODY_READS: ReadonlySet<string>;
|
|
28
|
+
/** The read, and the body format a caller names, for raw text (carrick#1842). */
|
|
29
|
+
export declare const RAW_TEXT_FORMAT = "text";
|
|
30
|
+
/** Whether a declaring file is the runtime's: the default library or an installed package. */
|
|
31
|
+
export type RuntimeFile = (file: ts.SourceFile) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* `call` is `<receiver>.<read>()` with no arguments, `read` is one of
|
|
34
|
+
* `reads`, and the receiver is a platform value (`isPlatformValue`) or, with
|
|
35
|
+
* `undeclared` set, a value nothing declares (`isUndeclaredValue`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function isPlatformBodyRead(call: CallExpression, reads: ReadonlySet<string>, runtimeFile: RuntimeFile, undeclared: 'undeclared_reads' | 'platform_only'): boolean;
|
|
38
|
+
/** The value's type is `any` or `unknown`: nothing declares it. */
|
|
39
|
+
export declare function isUndeclaredValue(value: Node): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The value's type, `null` and `undefined` aside, is a global the runtime
|
|
42
|
+
* declares: every part of it is named by a symbol with a global declaration
|
|
43
|
+
* in a runtime file. `any`, `unknown` and an anonymous type declare nothing,
|
|
44
|
+
* so they are not.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isPlatformValue(value: Node, runtimeFile: RuntimeFile): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform's body reads (blueprint row N33).
|
|
3
|
+
*
|
|
4
|
+
* A zero-argument `json()`, `text()`, `arrayBuffer()`, `blob()`, `bytes()` or
|
|
5
|
+
* `formData()` takes the whole body out of the platform's `Request` or
|
|
6
|
+
* `Response`. The member's name picks which read it is; it never decides
|
|
7
|
+
* that it is one. That is decided by the value the member is called on: its
|
|
8
|
+
* type is a global the runtime declares, in the compiler's default library
|
|
9
|
+
* (`lib.dom.d.ts`) or an installed runtime typings package that declares it
|
|
10
|
+
* as a global (`declare global { interface Response ... }`). A repository's
|
|
11
|
+
* own class with a `json()` member reads its own value, and a client that
|
|
12
|
+
* copies the platform's shape from a package of its own is read through the
|
|
13
|
+
* library store's label for its result, never by this name.
|
|
14
|
+
*
|
|
15
|
+
* A receiver nothing declares (`any` or `unknown`: `fetch` on a checkout whose
|
|
16
|
+
* configuration loads neither the DOM library nor installed runtime typings)
|
|
17
|
+
* has no declaration to decide by, so there the name is all there is and the
|
|
18
|
+
* read is taken as it always was. A declaration that is not the runtime's
|
|
19
|
+
* always decides against it.
|
|
20
|
+
*/
|
|
21
|
+
import { Node, ts } from 'ts-morph';
|
|
22
|
+
/** The reads that take the whole body as JSON or as raw text (carrick#1842). */
|
|
23
|
+
export const WHOLE_BODY_READS = new Set(['json', 'text']);
|
|
24
|
+
/** The JSON read alone. */
|
|
25
|
+
export const JSON_READ = new Set(['json']);
|
|
26
|
+
/** The whole-body reads that are neither JSON nor text (carrick#2112). */
|
|
27
|
+
export const BINARY_BODY_READS = new Set(['arrayBuffer', 'blob', 'bytes', 'formData']);
|
|
28
|
+
/** The read, and the body format a caller names, for raw text (carrick#1842). */
|
|
29
|
+
export const RAW_TEXT_FORMAT = 'text';
|
|
30
|
+
/**
|
|
31
|
+
* `call` is `<receiver>.<read>()` with no arguments, `read` is one of
|
|
32
|
+
* `reads`, and the receiver is a platform value (`isPlatformValue`) or, with
|
|
33
|
+
* `undeclared` set, a value nothing declares (`isUndeclaredValue`).
|
|
34
|
+
*/
|
|
35
|
+
export function isPlatformBodyRead(call, reads, runtimeFile, undeclared) {
|
|
36
|
+
const callee = call.getExpression();
|
|
37
|
+
if (!Node.isPropertyAccessExpression(callee) || !reads.has(callee.getName()) || call.getArguments().length > 0) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const receiver = callee.getExpression();
|
|
41
|
+
return (isPlatformValue(receiver, runtimeFile) ||
|
|
42
|
+
(undeclared === 'undeclared_reads' && isUndeclaredValue(receiver)));
|
|
43
|
+
}
|
|
44
|
+
/** The value's type is `any` or `unknown`: nothing declares it. */
|
|
45
|
+
export function isUndeclaredValue(value) {
|
|
46
|
+
try {
|
|
47
|
+
const type = value.getType();
|
|
48
|
+
return type.isAny() || type.isUnknown();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The value's type, `null` and `undefined` aside, is a global the runtime
|
|
56
|
+
* declares: every part of it is named by a symbol with a global declaration
|
|
57
|
+
* in a runtime file. `any`, `unknown` and an anonymous type declare nothing,
|
|
58
|
+
* so they are not.
|
|
59
|
+
*/
|
|
60
|
+
export function isPlatformValue(value, runtimeFile) {
|
|
61
|
+
let type;
|
|
62
|
+
try {
|
|
63
|
+
type = value.getType().getNonNullableType();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const parts = type.isUnion() ? type.getUnionTypes() : [type];
|
|
69
|
+
return (parts.length > 0 &&
|
|
70
|
+
parts.every((part) => (part.getSymbol()?.getDeclarations() ?? []).some((declaration) => isGlobalDeclaration(declaration.compilerNode) &&
|
|
71
|
+
runtimeFile(declaration.getSourceFile().compilerNode))));
|
|
72
|
+
}
|
|
73
|
+
/** Declared in the global scope: a script file's top level, or a `declare global` block. */
|
|
74
|
+
function isGlobalDeclaration(node) {
|
|
75
|
+
for (let at = node.parent; at; at = at.parent) {
|
|
76
|
+
if (ts.isModuleDeclaration(at))
|
|
77
|
+
return (at.flags & ts.NodeFlags.GlobalAugmentation) !== 0;
|
|
78
|
+
if (ts.isSourceFile(at))
|
|
79
|
+
return !ts.isExternalModule(at);
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
*
|
|
30
30
|
* The published union is not changed by any of this.
|
|
31
31
|
*/
|
|
32
|
-
import { Node, type
|
|
32
|
+
import { Node, type CallExpression } from 'ts-morph';
|
|
33
33
|
/**
|
|
34
34
|
* Where in the incoming message a field is read from. Only the HTTP sources
|
|
35
35
|
* are read so far; another protocol (a socket message, a pub/sub payload)
|
|
@@ -74,9 +74,10 @@ export interface JoinedBody {
|
|
|
74
74
|
/**
|
|
75
75
|
* The modes of the union joined from `bodies`, or `undefined` when no message
|
|
76
76
|
* read separates them. `join` builds a union text from member texts with the
|
|
77
|
-
* rules the published union is built with. `
|
|
78
|
-
*
|
|
77
|
+
* rules the published union is built with. `isBodyRead` says whether a call
|
|
78
|
+
* is the platform's `json()` body read (`platform-body-read.ts`, blueprint
|
|
79
|
+
* row N33).
|
|
79
80
|
*/
|
|
80
|
-
export declare function readResponseModes(bodies: JoinedBody[], join: (texts: string[]) => string,
|
|
81
|
+
export declare function readResponseModes(bodies: JoinedBody[], join: (texts: string[]) => string, isBodyRead: (call: CallExpression) => boolean): ResponseModes | undefined;
|
|
81
82
|
/** The text of a string literal, `undefined` for anything else. */
|
|
82
83
|
export declare function stringLiteral(node: Node | undefined): string | undefined;
|
|
@@ -35,10 +35,11 @@ const MAX_CHAIN = 32;
|
|
|
35
35
|
/**
|
|
36
36
|
* The modes of the union joined from `bodies`, or `undefined` when no message
|
|
37
37
|
* read separates them. `join` builds a union text from member texts with the
|
|
38
|
-
* rules the published union is built with. `
|
|
39
|
-
*
|
|
38
|
+
* rules the published union is built with. `isBodyRead` says whether a call
|
|
39
|
+
* is the platform's `json()` body read (`platform-body-read.ts`, blueprint
|
|
40
|
+
* row N33).
|
|
40
41
|
*/
|
|
41
|
-
export function readResponseModes(bodies, join,
|
|
42
|
+
export function readResponseModes(bodies, join, isBodyRead) {
|
|
42
43
|
if (bodies.length < 2)
|
|
43
44
|
return undefined;
|
|
44
45
|
const boundary = smallestEnclosingFunction(bodies.map((body) => body.node));
|
|
@@ -61,7 +62,7 @@ export function readResponseModes(bodies, join, isLibOrExternal) {
|
|
|
61
62
|
for (const { step, byBody } of sides.values()) {
|
|
62
63
|
if (new Set(byBody.values()).size < 2)
|
|
63
64
|
continue;
|
|
64
|
-
const reading = readStep(step,
|
|
65
|
+
const reading = readStep(step, isBodyRead);
|
|
65
66
|
if (!reading)
|
|
66
67
|
continue;
|
|
67
68
|
if (reading.kind === 'unread') {
|
|
@@ -163,13 +164,13 @@ function admitsValue(admits, value) {
|
|
|
163
164
|
return 'only' in admits ? admits.only.has(value) : !admits.except.has(value);
|
|
164
165
|
}
|
|
165
166
|
/** What `step`'s test reads of the incoming message, `undefined` when nothing. */
|
|
166
|
-
function readStep(step,
|
|
167
|
+
function readStep(step, isBodyRead) {
|
|
167
168
|
if (step.kind === 'branch')
|
|
168
|
-
return readCondition(step.condition,
|
|
169
|
+
return readCondition(step.condition, isBodyRead);
|
|
169
170
|
const subject = step.test.getExpression();
|
|
170
|
-
const read = messageRead(subject,
|
|
171
|
+
const read = messageRead(subject, isBodyRead);
|
|
171
172
|
if (!read) {
|
|
172
|
-
const inside = readsIn(subject,
|
|
173
|
+
const inside = readsIn(subject, isBodyRead);
|
|
173
174
|
return inside.length > 0 ? { kind: 'unread', reads: inside } : undefined;
|
|
174
175
|
}
|
|
175
176
|
// A body after the switch is reached by the values whose clauses run on
|
|
@@ -214,7 +215,7 @@ function readStep(step, isLibOrExternal) {
|
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
/** What an `if` or conditional condition reads of the incoming message. */
|
|
217
|
-
function readCondition(condition,
|
|
218
|
+
function readCondition(condition, isBodyRead) {
|
|
218
219
|
let test = condition;
|
|
219
220
|
let flipped = false;
|
|
220
221
|
for (;;) {
|
|
@@ -242,7 +243,7 @@ function readCondition(condition, isLibOrExternal) {
|
|
|
242
243
|
const leftLiteral = stringLiteral(left);
|
|
243
244
|
const value = rightLiteral ?? leftLiteral;
|
|
244
245
|
const operand = rightLiteral !== undefined ? left : right;
|
|
245
|
-
const read = value !== undefined ? messageRead(operand,
|
|
246
|
+
const read = value !== undefined ? messageRead(operand, isBodyRead) : undefined;
|
|
246
247
|
if (read && value !== undefined) {
|
|
247
248
|
// True side admits the value when the test is an equality.
|
|
248
249
|
const trueAdmitsValue = equal !== flipped;
|
|
@@ -257,7 +258,7 @@ function readCondition(condition, isLibOrExternal) {
|
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
|
-
const inside = readsIn(condition,
|
|
261
|
+
const inside = readsIn(condition, isBodyRead);
|
|
261
262
|
return inside.length > 0 ? { kind: 'unread', reads: inside } : undefined;
|
|
262
263
|
}
|
|
263
264
|
/** The text of a string literal, `undefined` for anything else. */
|
|
@@ -273,12 +274,12 @@ export function stringLiteral(node) {
|
|
|
273
274
|
return undefined;
|
|
274
275
|
}
|
|
275
276
|
/** Every message read inside `node`, outermost reads only. */
|
|
276
|
-
function readsIn(node,
|
|
277
|
+
function readsIn(node, isBodyRead) {
|
|
277
278
|
const found = [];
|
|
278
279
|
for (const candidate of [node, ...node.getDescendants()]) {
|
|
279
280
|
if (found.some((read) => read.node.containsRange(candidate.getPos(), candidate.getEnd())))
|
|
280
281
|
continue;
|
|
281
|
-
const read = messageRead(candidate,
|
|
282
|
+
const read = messageRead(candidate, isBodyRead);
|
|
282
283
|
if (read)
|
|
283
284
|
found.push(read);
|
|
284
285
|
}
|
|
@@ -293,14 +294,14 @@ function readsIn(node, isLibOrExternal) {
|
|
|
293
294
|
* `URL`. A `let`, a binding default, or a call that takes the message as an
|
|
294
295
|
* argument ends the chain, and it is not a read.
|
|
295
296
|
*/
|
|
296
|
-
function messageRead(node,
|
|
297
|
+
function messageRead(node, isBodyRead) {
|
|
297
298
|
const links = chainOf(node, enclosingParameters(node), 0);
|
|
298
299
|
if (!links || links.length === 0)
|
|
299
300
|
return undefined;
|
|
300
301
|
const field = fieldOf(links);
|
|
301
302
|
if (field === undefined)
|
|
302
303
|
return undefined;
|
|
303
|
-
return { location: locationOf(links,
|
|
304
|
+
return { location: locationOf(links, isBodyRead), field, node };
|
|
304
305
|
}
|
|
305
306
|
function enclosingParameters(node) {
|
|
306
307
|
const parameters = new Set();
|
|
@@ -353,9 +354,7 @@ function chainOf(node, roots, depth) {
|
|
|
353
354
|
if (Node.isNewExpression(node)) {
|
|
354
355
|
const callee = node.getExpression();
|
|
355
356
|
const [input] = node.getArguments();
|
|
356
|
-
if (!
|
|
357
|
-
return undefined;
|
|
358
|
-
if (!declaredByDefaultLib(callee.getSymbol()))
|
|
357
|
+
if (!input || !declaredByDefaultLib(callee.getSymbol(), 'URL'))
|
|
359
358
|
return undefined;
|
|
360
359
|
const base = next(input);
|
|
361
360
|
return base && [...base, { kind: 'url' }];
|
|
@@ -421,7 +420,7 @@ function fieldOf(links) {
|
|
|
421
420
|
}
|
|
422
421
|
return undefined;
|
|
423
422
|
}
|
|
424
|
-
function locationOf(links,
|
|
423
|
+
function locationOf(links, isBodyRead) {
|
|
425
424
|
const last = links[links.length - 1];
|
|
426
425
|
if (last.kind === 'call' &&
|
|
427
426
|
last.name === 'get' &&
|
|
@@ -435,12 +434,9 @@ function locationOf(links, isLibOrExternal) {
|
|
|
435
434
|
if (awaited.kind === 'await' &&
|
|
436
435
|
json.kind === 'call' &&
|
|
437
436
|
json.name === 'json' &&
|
|
438
|
-
json.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const symbol = Node.isPropertyAccessExpression(callee) ? callee.getNameNode().getSymbol() : undefined;
|
|
442
|
-
if (isLibOrExternal(symbol))
|
|
443
|
-
return 'body';
|
|
437
|
+
Node.isCallExpression(json.call) &&
|
|
438
|
+
isBodyRead(json.call)) {
|
|
439
|
+
return 'body';
|
|
444
440
|
}
|
|
445
441
|
}
|
|
446
442
|
return 'unplaced';
|
|
@@ -33,6 +33,7 @@ import { typeToStringAsDeclared } from './print-type.js';
|
|
|
33
33
|
import { deferredResultNeedsUndefined } from './retype-deferred.js';
|
|
34
34
|
import { resolvedDeclaration, typeArgumentOnlySelects } from './retype-selector.js';
|
|
35
35
|
import { fileDiagnostics } from './unwidened.js';
|
|
36
|
+
import { JSON_READ } from './platform-body-read.js';
|
|
36
37
|
/** Names appended to a file that is not ours carry this prefix. */
|
|
37
38
|
const PREFIX = '__carrick_';
|
|
38
39
|
const WIRE = `${PREFIX}Wire`;
|
|
@@ -278,7 +279,7 @@ export class Retyper {
|
|
|
278
279
|
// `.json()`: the payload is that read, so the cast goes there
|
|
279
280
|
// (carrick#1493). The call's own result is not the payload and is not
|
|
280
281
|
// touched.
|
|
281
|
-
const reads = bodyReadsOf(call);
|
|
282
|
+
const reads = bodyReadsOf(call, (read) => this.inferrer.isPlatformBodyRead(read, JSON_READ, 'undeclared_reads'));
|
|
282
283
|
if (typeof reads === 'string')
|
|
283
284
|
return reads;
|
|
284
285
|
if (reads.length > 0) {
|
|
@@ -644,7 +645,7 @@ function returnsUndeclared(node) {
|
|
|
644
645
|
* may have its body read out of view, so an agreement here would claim reads
|
|
645
646
|
* the diff cannot see.
|
|
646
647
|
*/
|
|
647
|
-
function bodyReadsOf(call) {
|
|
648
|
+
function bodyReadsOf(call, isBodyRead) {
|
|
648
649
|
if (isBodyRead(call))
|
|
649
650
|
return checkedBodyReads([call]);
|
|
650
651
|
let top = call;
|
|
@@ -652,7 +653,7 @@ function bodyReadsOf(call) {
|
|
|
652
653
|
Node.isParenthesizedExpression(top.getParentOrThrow())) {
|
|
653
654
|
top = top.getParentOrThrow();
|
|
654
655
|
}
|
|
655
|
-
const chained = bodyReadOn(top);
|
|
656
|
+
const chained = bodyReadOn(top, isBodyRead);
|
|
656
657
|
if (chained)
|
|
657
658
|
return checkedBodyReads([chained]);
|
|
658
659
|
const name = responseBinding(top);
|
|
@@ -661,7 +662,7 @@ function bodyReadsOf(call) {
|
|
|
661
662
|
const reads = [];
|
|
662
663
|
let handedOn = false;
|
|
663
664
|
for (const ref of name.findReferencesAsNodes()) {
|
|
664
|
-
const read = bodyReadOn(ref);
|
|
665
|
+
const read = bodyReadOn(ref, isBodyRead);
|
|
665
666
|
if (read) {
|
|
666
667
|
reads.push(read);
|
|
667
668
|
continue;
|
|
@@ -960,13 +961,13 @@ function carriesBody(status) {
|
|
|
960
961
|
* Content, 205 Reset Content).
|
|
961
962
|
*/
|
|
962
963
|
const NO_CONTENT_STATUSES = new Set([204, 205]);
|
|
963
|
-
/**
|
|
964
|
-
|
|
964
|
+
/**
|
|
965
|
+
* `node.json()` with no arguments, where `node` is the receiver and
|
|
966
|
+
* `isBodyRead` takes the call as the platform's body read (blueprint row N33).
|
|
967
|
+
*/
|
|
968
|
+
function bodyReadOn(node, isBodyRead) {
|
|
965
969
|
const access = node.getParent();
|
|
966
|
-
if (!access ||
|
|
967
|
-
!Node.isPropertyAccessExpression(access) ||
|
|
968
|
-
access.getExpression() !== node ||
|
|
969
|
-
access.getName() !== 'json') {
|
|
970
|
+
if (!access || !Node.isPropertyAccessExpression(access) || access.getExpression() !== node) {
|
|
970
971
|
return undefined;
|
|
971
972
|
}
|
|
972
973
|
const read = access.getParent();
|
|
@@ -974,12 +975,6 @@ function bodyReadOn(node) {
|
|
|
974
975
|
? read
|
|
975
976
|
: undefined;
|
|
976
977
|
}
|
|
977
|
-
function isBodyRead(call) {
|
|
978
|
-
const callee = call.getExpression();
|
|
979
|
-
return (Node.isPropertyAccessExpression(callee) &&
|
|
980
|
-
callee.getName() === 'json' &&
|
|
981
|
-
call.getArguments().length === 0);
|
|
982
|
-
}
|
|
983
978
|
function isAssignmentOperator(kind) {
|
|
984
979
|
return kind >= SyntaxKind.FirstAssignment && kind <= SyntaxKind.LastAssignment;
|
|
985
980
|
}
|
|
@@ -150,6 +150,12 @@ export declare class StatedParams {
|
|
|
150
150
|
private payloadTypeParameters;
|
|
151
151
|
/** The type the call signature takes at the payload slot, read at `at`. */
|
|
152
152
|
private payloadAt;
|
|
153
|
+
/**
|
|
154
|
+
* The called member's declaration is one the labels name a request body
|
|
155
|
+
* (blueprint row N33): a framework's own `json()` on its request, read as
|
|
156
|
+
* the body where the store says so. Matched by declaration, never by name.
|
|
157
|
+
*/
|
|
158
|
+
readsLabelledBody(call: Node): boolean;
|
|
153
159
|
/**
|
|
154
160
|
* What the labels say about one call (carrick#2472 C2): the payload slot
|
|
155
161
|
* when the called member's declaration is a labelled send; `'setter'` when
|
|
@@ -600,6 +600,19 @@ export class StatedParams {
|
|
|
600
600
|
}
|
|
601
601
|
return type;
|
|
602
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* The called member's declaration is one the labels name a request body
|
|
605
|
+
* (blueprint row N33): a framework's own `json()` on its request, read as
|
|
606
|
+
* the body where the store says so. Matched by declaration, never by name.
|
|
607
|
+
*/
|
|
608
|
+
readsLabelledBody(call) {
|
|
609
|
+
if (this.labels.bodies.size === 0 || !Node.isCallExpression(call))
|
|
610
|
+
return false;
|
|
611
|
+
const callee = call.getExpression();
|
|
612
|
+
if (!Node.isPropertyAccessExpression(callee))
|
|
613
|
+
return false;
|
|
614
|
+
return (callee.getNameNode().getSymbol()?.getDeclarations() ?? []).some((d) => this.labels.bodies.has(declarationKey(d.compilerNode)));
|
|
615
|
+
}
|
|
603
616
|
/**
|
|
604
617
|
* What the labels say about one call (carrick#2472 C2): the payload slot
|
|
605
618
|
* when the called member's declaration is a labelled send; `'setter'` when
|