carrick 0.3.155 → 0.3.157

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.
Files changed (125) hide show
  1. package/dist/contract.d.ts +22 -23
  2. package/dist/contract.js.map +1 -1
  3. package/dist/facts/enabled.d.ts +28 -0
  4. package/dist/facts/enabled.js +36 -0
  5. package/dist/facts/enabled.js.map +1 -1
  6. package/dist/facts/fetch.js +20 -8
  7. package/dist/facts/fetch.js.map +1 -1
  8. package/dist/facts/lines.d.ts +75 -2
  9. package/dist/facts/lines.js +302 -46
  10. package/dist/facts/lines.js.map +1 -1
  11. package/dist/facts/match.d.ts +2 -0
  12. package/dist/facts/match.js +189 -28
  13. package/dist/facts/match.js.map +1 -1
  14. package/dist/facts/peers.d.ts +2 -0
  15. package/dist/facts/peers.js +7 -2
  16. package/dist/facts/peers.js.map +1 -1
  17. package/dist/facts/store.d.ts +98 -2
  18. package/dist/facts/store.js +110 -12
  19. package/dist/facts/store.js.map +1 -1
  20. package/dist/held/client.d.ts +34 -0
  21. package/dist/held/client.js +85 -0
  22. package/dist/held/client.js.map +1 -0
  23. package/dist/held/daemon.d.ts +106 -0
  24. package/dist/held/daemon.js +307 -0
  25. package/dist/held/daemon.js.map +1 -0
  26. package/dist/held/engine.d.ts +50 -0
  27. package/dist/held/engine.js +166 -0
  28. package/dist/held/engine.js.map +1 -0
  29. package/dist/held/paths.d.ts +9 -0
  30. package/dist/held/paths.js +27 -0
  31. package/dist/held/paths.js.map +1 -0
  32. package/dist/held/place.d.ts +84 -0
  33. package/dist/held/place.js +198 -0
  34. package/dist/held/place.js.map +1 -0
  35. package/dist/held/registry.d.ts +22 -0
  36. package/dist/held/registry.js +72 -0
  37. package/dist/held/registry.js.map +1 -0
  38. package/dist/held/run.d.ts +2 -0
  39. package/dist/held/run.js +60 -0
  40. package/dist/held/run.js.map +1 -0
  41. package/dist/hook/bash-targets.d.ts +7 -2
  42. package/dist/hook/bash-targets.js +82 -27
  43. package/dist/hook/bash-targets.js.map +1 -1
  44. package/dist/hook/edit-flow.js +11 -7
  45. package/dist/hook/edit-flow.js.map +1 -1
  46. package/dist/hook/late.d.ts +1 -1
  47. package/dist/hook/late.js +3 -3
  48. package/dist/hook/late.js.map +1 -1
  49. package/dist/hook/lock.d.ts +26 -0
  50. package/dist/hook/lock.js +122 -0
  51. package/dist/hook/lock.js.map +1 -0
  52. package/dist/hook/post-bash.js +22 -7
  53. package/dist/hook/post-bash.js.map +1 -1
  54. package/dist/hook/post-read.js +9 -4
  55. package/dist/hook/post-read.js.map +1 -1
  56. package/dist/hook/probe.js +4 -2
  57. package/dist/hook/probe.js.map +1 -1
  58. package/dist/hook/read-answer.d.ts +23 -4
  59. package/dist/hook/read-answer.js +74 -19
  60. package/dist/hook/read-answer.js.map +1 -1
  61. package/dist/hook/rechecks.d.ts +2 -5
  62. package/dist/hook/rechecks.js +23 -130
  63. package/dist/hook/rechecks.js.map +1 -1
  64. package/dist/hook/similar.d.ts +13 -0
  65. package/dist/hook/similar.js +60 -0
  66. package/dist/hook/similar.js.map +1 -0
  67. package/dist/hook/stop-wait.d.ts +1 -0
  68. package/dist/hook/stop-wait.js +19 -24
  69. package/dist/hook/stop-wait.js.map +1 -1
  70. package/dist/hook/timings.d.ts +17 -3
  71. package/dist/hook/timings.js +10 -2
  72. package/dist/hook/timings.js.map +1 -1
  73. package/dist/lsp-frame.d.ts +20 -0
  74. package/dist/lsp-frame.js +47 -0
  75. package/dist/lsp-frame.js.map +1 -0
  76. package/dist/render.js +9 -3
  77. package/dist/render.js.map +1 -1
  78. package/dist/scan.d.ts +9 -0
  79. package/dist/scan.js +39 -8
  80. package/dist/scan.js.map +1 -1
  81. package/dist/server.js +4 -28
  82. package/dist/server.js.map +1 -1
  83. package/package.json +6 -6
  84. package/plugin/.claude-plugin/plugin.json +1 -1
  85. package/sidecar/dist/src/bundler.d.ts +5 -0
  86. package/sidecar/dist/src/bundler.js +20 -0
  87. package/sidecar/dist/src/capture/anchors.js +19 -4
  88. package/sidecar/dist/src/capture/api.d.ts +52 -4
  89. package/sidecar/dist/src/capture/check-probe.d.ts +17 -1
  90. package/sidecar/dist/src/capture/check-probe.js +39 -2
  91. package/sidecar/dist/src/capture/index.d.ts +12 -4
  92. package/sidecar/dist/src/capture/index.js +19 -3
  93. package/sidecar/dist/src/capture/result-label.js +3 -1
  94. package/sidecar/dist/src/capture/self-check.js +12 -31
  95. package/sidecar/dist/src/capture/serialised-arms.d.ts +27 -0
  96. package/sidecar/dist/src/capture/serialised-arms.js +76 -0
  97. package/sidecar/dist/src/capture/site-node.d.ts +17 -0
  98. package/sidecar/dist/src/capture/site-node.js +36 -0
  99. package/sidecar/dist/src/capture/stub-resolution.d.ts +63 -0
  100. package/sidecar/dist/src/capture/stub-resolution.js +102 -0
  101. package/sidecar/dist/src/capture/type-reasons.json +78 -0
  102. package/sidecar/dist/src/capture/unresolved.js +8 -1
  103. package/sidecar/dist/src/definition-resolver.d.ts +18 -9
  104. package/sidecar/dist/src/definition-resolver.js +66 -42
  105. package/sidecar/dist/src/engine-stamp.json +1 -0
  106. package/sidecar/dist/src/held-shadow.d.ts +60 -0
  107. package/sidecar/dist/src/held-shadow.js +222 -0
  108. package/sidecar/dist/src/index.js +47 -1
  109. package/sidecar/dist/src/library-claims.d.ts +3 -1
  110. package/sidecar/dist/src/library-claims.js +79 -3
  111. package/sidecar/dist/src/retype.js +1 -61
  112. package/sidecar/dist/src/type-home.d.ts +42 -0
  113. package/sidecar/dist/src/type-home.js +94 -0
  114. package/sidecar/dist/src/type-inferrer.d.ts +245 -28
  115. package/sidecar/dist/src/type-inferrer.js +938 -192
  116. package/sidecar/dist/src/type-parameters.d.ts +41 -0
  117. package/sidecar/dist/src/type-parameters.js +126 -0
  118. package/sidecar/dist/src/type-structural-expander.d.ts +1 -11
  119. package/sidecar/dist/src/type-structural-expander.js +9 -1
  120. package/sidecar/dist/src/types.d.ts +132 -20
  121. package/sidecar/dist/src/validators.d.ts +450 -244
  122. package/sidecar/dist/src/validators.js +27 -1
  123. package/dist/hook/lead.d.ts +0 -13
  124. package/dist/hook/lead.js +0 -39
  125. package/dist/hook/lead.js.map +0 -1
@@ -8,6 +8,7 @@
8
8
  * stdio `capture_v2` action is the only surface the Rust client sees.
9
9
  */
10
10
  import type { ResultLabel } from './result-label.js';
11
+ import type TypeReasons from './type-reasons.json';
11
12
  export type { ResultLabel };
12
13
  /**
13
14
  * How the anchor was produced upstream (design-doc amendment 2). Recorded so
@@ -181,6 +182,14 @@ export interface InferAnchorRequest {
181
182
  * after the awaited unwrap; absent means the type is taken as it stands.
182
183
  */
183
184
  result?: ResultLabel;
185
+ /**
186
+ * carrick#4232: the kind of the inference request this anchor carries. A
187
+ * `call_result` anchor reads a call's result, so a locator that lands on no
188
+ * call abstains (`callNamedBy`, the rule the inferrer applies too). The
189
+ * value is the request's `InferKind` (validated in `validators.ts`); it is
190
+ * typed as a string here because the capture bundle imports only itself.
191
+ */
192
+ infer_kind?: string;
184
193
  }
185
194
  export type CaptureAnchorRequest = SymbolAnchorRequest | HandlerReturnAnchorRequest | InferAnchorRequest | LiteralAnchorRequest;
186
195
  export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal';
@@ -194,8 +203,8 @@ export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal
194
203
  * honest value is `not_recorded` — never a guess.
195
204
  *
196
205
  * - `declared`: the captured declaration states `any`/`unknown` at this
197
- * position, and the producer's own program had a type there too: an author
198
- * annotation, not a failed resolution.
206
+ * position, and the producer's own program had a type there too: stated by
207
+ * the code or a library it uses, not a failed resolution.
199
208
  * - `unresolved_import`: the position is `any` in the emitted text because the
200
209
  * producer's program could not resolve the type there — an import of a
201
210
  * dependency that is not installed, or of a generated module that was never
@@ -246,17 +255,44 @@ export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal
246
255
  * name) that builds a new value from it, and nothing in the chain states
247
256
  * the body, so the value the chain ends in is not the response the call
248
257
  * receives and no contract is published (carrick#3004).
258
+ * - `bound_by_callers`: the type here is still an open type parameter of a
259
+ * generic function, which only that function's callers set, so the site
260
+ * states no type of its own: a body or payload read with no call that binds
261
+ * the parameter, or at a call that leaves it open (carrick#4128,
262
+ * carrick#4164), and a response, call result, return or variable read
263
+ * inside the generic function itself (carrick#4201).
264
+ * - `body_member_undecided`: the call's result is an object that holds the
265
+ * transport response beside other members, and the called function's code
266
+ * does not settle which member holds the parsed body.
249
267
  * - `not_located`: the scan found no value in the code for this payload, so
250
268
  * no type was read for it: no request located one, or the only locator was
251
- * a line (carrick#3995).
269
+ * a line (carrick#3995) or a route's registration call that the handler
270
+ * gave no body read for (carrick#4079, carrick#4204).
252
271
  * - `site_unreadable`: the scan located the site, but the compiler could not
253
272
  * read a type at it (carrick#3995).
254
273
  * - `unplaced_top_type`: the printed shape holds a top type at a member no
255
274
  * layer placed (carrick#3995). Stamped at the entry's root.
256
275
  * - `not_recorded`: the position carries a top type and this layer has no
257
276
  * cause for it.
277
+ *
278
+ * The words are the keys of `./type-reasons.json`, the one list of reasons
279
+ * (carrick#4231): each word's reader sentence and whether it means the scan
280
+ * DECIDED there is no contract (`always`, `at_call_result`, `never`). The
281
+ * engine's decided set and the Rust driver's `reason_decided` both read that
282
+ * file. A word stays in it while any stored index can still carry it.
258
283
  */
259
- export type TypeProvenanceReason = 'declared' | 'unresolved_import' | 'budget_exhausted' | 'no_payload_evidence' | 'machinery_envelope' | 'coerced_input' | 'no_success_payload' | 'no_request_body' | 'projected_value_only' | 'serialised_body_unread' | 'body_built_by_callee' | 'reshaped_by_callback' | 'result_member_missing' | 'not_located' | 'site_unreadable' | 'unplaced_top_type' | 'not_recorded';
284
+ export type TypeProvenanceReason = keyof typeof TypeReasons;
285
+ /**
286
+ * When a root `unknown` with this reason is a decision rather than a failed
287
+ * read: at every site, only at a consumer call's result, or never.
288
+ */
289
+ export type ReasonDecided = 'always' | 'at_call_result' | 'never';
290
+ /** One word's row in `./type-reasons.json`. */
291
+ export interface TypeReason {
292
+ /** What a reader is told the word means. */
293
+ sentence: string;
294
+ decided: ReasonDecided;
295
+ }
260
296
  /**
261
297
  * One `any`/`unknown` finding inside a captured or inferred type, with its
262
298
  * position and its cause. Sorted by `path` wherever a list is emitted, so the
@@ -488,6 +524,18 @@ export type ProbeProtocol = 'http' | 'graphql' | 'socket' | 'pubsub';
488
524
  * pairs are `both`.
489
525
  */
490
526
  export type ProbeTypeKind = 'request' | 'response' | 'both';
527
+ /**
528
+ * The representation a type is printed in.
529
+ *
530
+ * `'declared'` prints the type the source declares. `'json'` prints what a
531
+ * JSON serialiser puts on the wire for a value of that type (carrick#1163):
532
+ * `JSON.stringify` calls a value's `toJSON()` and serialises its RESULT, so a
533
+ * `Date` travels as the string its `toJSON` returns, and so does any other
534
+ * type that declares one. The mapping is read from the compiler's own
535
+ * signature, never from a list of type names. Which payloads travel in which
536
+ * form is `wireFormFor` (check-probe.ts), the one rule.
537
+ */
538
+ export type WireFormat = 'declared' | 'json';
491
539
  /** One capture stub package to assemble into the check workspace. */
492
540
  export interface CheckStubInput {
493
541
  /** Service name (used for scrub labels + pair endpoints). */
@@ -30,7 +30,7 @@
30
30
  *
31
31
  * Seam: node builtins + `typescript` + this bundle only. No imports needed here.
32
32
  */
33
- import type { CheckPairEndpoint, CheckPairSpec, ProbeProtocol, ProbeTypeKind } from './api.js';
33
+ import type { CheckPairEndpoint, CheckPairSpec, ProbeProtocol, ProbeTypeKind, WireFormat } from './api.js';
34
34
  /** Which pair endpoint supplies the `sent` value / the `expected` binding. */
35
35
  export type Side = 'producer' | 'consumer';
36
36
  export interface Direction {
@@ -48,6 +48,22 @@ export interface Direction {
48
48
  * | socket, pubsub | both | consumer | producer |
49
49
  */
50
50
  export declare function directionFor(protocol: ProbeProtocol, typeKind: ProbeTypeKind): Direction;
51
+ /**
52
+ * The form a payload travels in: the one rule the judge and the stored type
53
+ * text both read (carrick-cloud#3503, carrick#4275). Only the SENDING side
54
+ * (`directionFor`'s `sent`) is ever transformed, because that is where
55
+ * serialisation happens:
56
+ *
57
+ * - `http`: a body is serialised with `JSON.stringify`, which writes a
58
+ * value's `toJSON()` result, so the producer of a response and the
59
+ * consumer of a request body send their JSON form;
60
+ * - `graphql` response: the server sends each leaf through its scalar's
61
+ * `serialize`, so a resolver's `Date` reaches the client as a string. The
62
+ * request (variables) is read by the server as declared;
63
+ * - socket and pub/sub payloads stay declared until the codec each library
64
+ * uses is a known fact: the codec belongs to the client, not the protocol.
65
+ */
66
+ export declare function wireFormFor(protocol: ProbeProtocol, typeKind: ProbeTypeKind, side: Side): WireFormat;
51
67
  /** Deterministic FNV-1a (32-bit) over the pair's stable key. Never a path. */
52
68
  export declare function fnv1a(input: string): string;
53
69
  /** The pair ID is derived from the pair's semantic identity, not the workspace
@@ -50,6 +50,30 @@ export function directionFor(protocol, typeKind) {
50
50
  // http/graphql response, and any other (http, graphql) shape.
51
51
  return { sent: 'producer', expected: 'consumer' };
52
52
  }
53
+ /**
54
+ * The form a payload travels in: the one rule the judge and the stored type
55
+ * text both read (carrick-cloud#3503, carrick#4275). Only the SENDING side
56
+ * (`directionFor`'s `sent`) is ever transformed, because that is where
57
+ * serialisation happens:
58
+ *
59
+ * - `http`: a body is serialised with `JSON.stringify`, which writes a
60
+ * value's `toJSON()` result, so the producer of a response and the
61
+ * consumer of a request body send their JSON form;
62
+ * - `graphql` response: the server sends each leaf through its scalar's
63
+ * `serialize`, so a resolver's `Date` reaches the client as a string. The
64
+ * request (variables) is read by the server as declared;
65
+ * - socket and pub/sub payloads stay declared until the codec each library
66
+ * uses is a known fact: the codec belongs to the client, not the protocol.
67
+ */
68
+ export function wireFormFor(protocol, typeKind, side) {
69
+ if (directionFor(protocol, typeKind).sent !== side)
70
+ return 'declared';
71
+ if (protocol === 'http')
72
+ return 'json';
73
+ if (protocol === 'graphql' && typeKind === 'response')
74
+ return 'json';
75
+ return 'declared';
76
+ }
53
77
  /** Deterministic FNV-1a (32-bit) over the pair's stable key. Never a path. */
54
78
  export function fnv1a(input) {
55
79
  let hash = 0x811c9dc5;
@@ -240,7 +264,9 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
240
264
  push(`type SentBody = ${sentBodyType('Sent')};`);
241
265
  const sentBody = absentBodyAllowed ? 'SentBody' : 'Sent';
242
266
  push(`declare const sent: ${sentBody};`);
267
+ const wire = wireFormFor(spec.protocol, spec.type_kind, direction.sent);
243
268
  let assignmentLine;
269
+ let wireAssignmentLine;
244
270
  if (spec.protocol === 'graphql') {
245
271
  // GraphQL selection-set semantics (v1 `unwrapGraphqlPayload` parity): the
246
272
  // producer side (always `sent` for graphql — see the direction table) is
@@ -306,6 +332,18 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
306
332
  gateLines.set(push(`type _G_comparand_never = Assert<Not<IsNever<GqlComparand>>>;`), 'sent:never');
307
333
  push(`declare const sentComparand: GqlComparand;`);
308
334
  assignmentLine = push(`const expected: GqlExpected = sentComparand;`);
335
+ // The wire line over the comparand (carrick#4275): JSON applies after the
336
+ // envelope unwrap, so the unwrap reads the declared shape and never meets
337
+ // the transform. It mirrors `WireSent` below and keeps the comparand
338
+ // whenever that already assigns. The const is `sentWire`, the name the
339
+ // field report reads (`comparedTypes`).
340
+ if (wire === 'json') {
341
+ for (const line of jsonWireDeclarations(''))
342
+ push(line);
343
+ push(`type GqlWire = [GqlComparand] extends [GqlExpected] ? GqlComparand : (JsonWireSame<JsonWire<GqlComparand>, GqlComparand> extends true ? GqlComparand : JsonWire<GqlComparand>);`);
344
+ push(`declare const sentWire: GqlWire;`);
345
+ wireAssignmentLine = push(`const expectedWire: GqlExpected = sentWire;`);
346
+ }
309
347
  }
310
348
  else {
311
349
  assignmentLine = push(`const expected: Expected = sent;`);
@@ -324,8 +362,7 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
324
362
  // so a pair that agrees as declared never instantiates the mapped type (no
325
363
  // cost, and no way for the transform to turn an agreeing pair into a
326
364
  // disagreeing one). tsc stays the judge of both forms.
327
- let wireAssignmentLine;
328
- if (spec.protocol === 'http') {
365
+ if (spec.protocol !== 'graphql' && wire === 'json') {
329
366
  // Keep the DECLARED type whenever serialising changes nothing observable,
330
367
  // so the compiler's headline still names the real surface alias (the probe
331
368
  // prints `Sent`, which the scrub rewrites) instead of expanding a mapped
@@ -27,12 +27,20 @@
27
27
  * node builtins and `typescript`; the rest of the sidecar reaches it only
28
28
  * through ./api.js types and this file's `captureStub`.
29
29
  */
30
- import type { CaptureStubOptions, CaptureStubResult } from './api.js';
30
+ import type { CaptureStubOptions, CaptureStubResult, TypeProvenanceReason, TypeReason } from './api.js';
31
31
  import { WriteGuard } from './guarded-fs.js';
32
32
  export type { CaptureStubOptions, CaptureStubResult } from './api.js';
33
+ /**
34
+ * The one list of type reasons (carrick#4231), keyed by word. The Rust driver
35
+ * embeds the same file; `test/type-reasons-one-source.test.ts` checks every
36
+ * row's `decided` is one of the three values the cast states.
37
+ */
38
+ export declare const TYPE_REASONS: Readonly<Record<TypeProvenanceReason, TypeReason>>;
33
39
  export { DenoProject, findDenoConfig } from './deno-project.js';
34
40
  export { sidecarCompilerOptions } from './compiler-options.js';
41
+ export { withStubResolution, type StubModuleResolver } from './stub-resolution.js';
35
42
  export { isInsideCheckout, untrustedReadBound, UNTRUSTED_TREE_ENV, type ReadBound } from './checkout.js';
43
+ export { serialisedConditionalType } from './serialised-arms.js';
36
44
  export { serviceConfigPath } from './project-references.js';
37
45
  export { referenceRedirectOf, workspaceSourceRedirectOf } from './reference-redirect.js';
38
46
  export { findServiceTsconfig, GoverningConfigs } from './service-config.js';
@@ -43,10 +51,10 @@ export type { InternalTypeChecker } from './node-builder.js';
43
51
  export { toPosix } from './installed-package.js';
44
52
  export { constituentsOf } from './result-label.js';
45
53
  export { moduleExport } from './anchors.js';
46
- export { isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, type DeclaredOutside, } from './site-node.js';
47
- export { runCheck } from './check.js';
54
+ export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, type DeclaredOutside, } from './site-node.js';
55
+ export { runCheck, judgeTscPath } from './check.js';
48
56
  export type { CheckProgress } from './check.js';
49
- export { jsonWireDeclarations } from './check-probe.js';
57
+ export { jsonWireDeclarations, wireFormFor } from './check-probe.js';
50
58
  export { findDisqualifyingTopTypes } from './deep-walk.js';
51
59
  /**
52
60
  * The name of THIS capture's surface entry, without an extension
@@ -36,6 +36,7 @@ import { installedVersions, lockfileVersions } from './lockfile.js';
36
36
  import { installedResolutionEdges, RESOLUTION_FILE } from './resolution-edges.js';
37
37
  import { rewriteEmittedSpecifiers } from './paths-rewrite.js';
38
38
  import { substituteMachinePathImports } from './machine-paths.js';
39
+ import { forgetStubResolutions, rememberStubResolution } from './stub-resolution.js';
39
40
  import { installedPackageSpecifier, typesPackageOf, withInstalledPackages } from './installed-package.js';
40
41
  import { selfCheckStub } from './self-check.js';
41
42
  import { backfillRerun, sharingHost } from './backfill.js';
@@ -48,10 +49,19 @@ import { findServiceTsconfig } from './service-config.js';
48
49
  import { placeEmittedTree, surfaceModuleInTree } from './outside-root.js';
49
50
  import { WriteGuard } from './guarded-fs.js';
50
51
  import { sidecarCompilerOptions } from './compiler-options.js';
52
+ import typeReasons from './type-reasons.json' with { type: 'json' };
51
53
  import { boundedCompilerHost, boundedSys, isInsideCheckout, untrustedReadBound } from './checkout.js';
54
+ /**
55
+ * The one list of type reasons (carrick#4231), keyed by word. The Rust driver
56
+ * embeds the same file; `test/type-reasons-one-source.test.ts` checks every
57
+ * row's `decided` is one of the three values the cast states.
58
+ */
59
+ export const TYPE_REASONS = typeReasons;
52
60
  export { DenoProject, findDenoConfig } from './deno-project.js';
53
61
  export { sidecarCompilerOptions } from './compiler-options.js';
62
+ export { withStubResolution } from './stub-resolution.js';
54
63
  export { isInsideCheckout, untrustedReadBound, UNTRUSTED_TREE_ENV } from './checkout.js';
64
+ export { serialisedConditionalType } from './serialised-arms.js';
55
65
  export { serviceConfigPath } from './project-references.js';
56
66
  export { referenceRedirectOf, workspaceSourceRedirectOf } from './reference-redirect.js';
57
67
  export { findServiceTsconfig, GoverningConfigs } from './service-config.js';
@@ -65,11 +75,11 @@ export { constituentsOf } from './result-label.js';
65
75
  export { moduleExport } from './anchors.js';
66
76
  // One node locator and one machinery test for the inferrer and the capture
67
77
  // (carrick#3500).
68
- export { isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, } from './site-node.js';
78
+ export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, } from './site-node.js';
69
79
  // v2 check core ("tsc as the judge"). Same bundle, same seam: the sidecar
70
80
  // reaches it only through this door (index.js).
71
- export { runCheck } from './check.js';
72
- export { jsonWireDeclarations } from './check-probe.js';
81
+ export { runCheck, judgeTscPath } from './check.js';
82
+ export { jsonWireDeclarations, wireFormFor } from './check-probe.js';
73
83
  export { findDisqualifyingTopTypes } from './deep-walk.js';
74
84
  const SURFACE_ENTRY_BASENAME = '__carrick_surface__';
75
85
  /** Captures made by this process, so each one's entry file has a name of its
@@ -218,6 +228,7 @@ function computeFidelity(records) {
218
228
  return fidelity;
219
229
  }
220
230
  export function captureStub(opts) {
231
+ forgetStubResolutions();
221
232
  const repoRoot = path.resolve(opts.repoRoot);
222
233
  const packageName = `@carrick/${sanitizeServiceName(opts.serviceName)}`;
223
234
  const stubDir = path.resolve(opts.outDir);
@@ -531,6 +542,11 @@ export function captureStub(opts) {
531
542
  else {
532
543
  ({ first: aliases, second: secondAliases } = selfCheckBoth(stub, second, checkArgs, hostFor));
533
544
  }
545
+ // The definition resolver reads each stub next, in this process, and must
546
+ // resolve it as its self-check did (carrick#3995 T5).
547
+ for (const written of second ? [stub, second] : [stub]) {
548
+ rememberStubResolution(checkArgs(written, hostFor(written.installs)));
549
+ }
534
550
  const result = finishStub(stub, aliases, {
535
551
  packageName,
536
552
  bareCheckout,
@@ -24,8 +24,10 @@ const NULLISH = ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Void;
24
24
  export function constituentsOf(type) {
25
25
  return type.isUnion() ? type.types : [type];
26
26
  }
27
+ /** The abstain's word, checked against the one list of reasons. */
28
+ const RESULT_MEMBER_MISSING = 'result_member_missing';
27
29
  function missing(what) {
28
- return { abstain: `result_member_missing: ${what}` };
30
+ return { abstain: `${RESULT_MEMBER_MISSING}: ${what}` };
29
31
  }
30
32
  /**
31
33
  * Read `label` off a call's type. `raw` is the type as the call returns it and
@@ -40,6 +40,7 @@ import { sidecarCompilerOptions } from './compiler-options.js';
40
40
  import { collectSpecifiers, declarationCandidates, isDeclarationFileName, isRelative, packageNameOf, } from './specifiers.js';
41
41
  import { repairDanglingImports } from './repair-dangling.js';
42
42
  import { RESOLUTION_FILE } from './resolution-edges.js';
43
+ import { linkInstalledPackages, stubResolutionHost } from './stub-resolution.js';
43
44
  import { findDisqualifyingTopTypes, findUnresolvedPlaceholders, isErrorPlaceholder, provenanceOf, unemittedModuleProvenance, unresolvedInTreeProvenance, } from './deep-walk.js';
44
45
  /** The records of each surface, in `args.surfaces` order. */
45
46
  export function selfCheckStub(args) {
@@ -56,13 +57,7 @@ export function selfCheckStub(args) {
56
57
  };
57
58
  walk(typesDir);
58
59
  // Point resolution at the producer repo's installed deps when present.
59
- const repoNodeModules = path.join(args.repoRoot, 'node_modules');
60
- const linkPath = path.join(args.stubDir, 'node_modules');
61
- let linked = false;
62
- if (!args.bareCheckout && fs.existsSync(repoNodeModules) && !fs.existsSync(linkPath)) {
63
- args.guard.symlink(repoNodeModules, linkPath, 'dir');
64
- linked = true;
65
- }
60
+ const unlink = linkInstalledPackages(args);
66
61
  try {
67
62
  const first = runSelfCheck(args, treeFiles);
68
63
  // carrick#1397: an emitted declaration that imports a module the checkout
@@ -78,10 +73,7 @@ export function selfCheckStub(args) {
78
73
  return runSelfCheck(args, treeFiles, repaired).records;
79
74
  }
80
75
  finally {
81
- // unlinkSync, not rmSync: the link target is a directory and rmSync
82
- // refuses symlinks-to-directories with EISDIR.
83
- if (linked)
84
- args.guard.unlink(linkPath);
76
+ unlink();
85
77
  }
86
78
  }
87
79
  /**
@@ -110,26 +102,8 @@ export const SELF_CHECK_OPTIONS = sidecarCompilerOptions({
110
102
  moduleResolution: ts.ModuleResolutionKind.Bundler,
111
103
  types: [],
112
104
  });
113
- /** The host of a self-check program, with outside declarations resolving from their source. */
114
- function selfCheckHost(args) {
115
- const outside = args.outsideSources;
116
- if (!outside || Object.keys(outside).length === 0)
117
- return args.compilerHost?.(SELF_CHECK_OPTIONS);
118
- const host = args.compilerHost?.(SELF_CHECK_OPTIONS) ?? ts.createCompilerHost(SELF_CHECK_OPTIONS);
119
- const fallback = host.resolveModuleNames?.bind(host);
120
- host.resolveModuleNames = (names, containingFile, reused, redirected, options, containingSourceFile) => names.map((name, index) => {
121
- const resolved = fallback
122
- ? fallback([name], containingFile, reused?.slice(index, index + 1), redirected, options, containingSourceFile)[0]
123
- : ts.resolveModuleName(name, containingFile, options, host).resolvedModule;
124
- const source = outside[path.resolve(containingFile)];
125
- if (resolved || !source || name.startsWith('.') || path.isAbsolute(name))
126
- return resolved;
127
- return ts.resolveModuleName(name, source, options, host).resolvedModule;
128
- });
129
- return host;
130
- }
131
105
  function runSelfCheck(args, treeFiles, repaired) {
132
- const program = ts.createProgram(treeFiles, SELF_CHECK_OPTIONS, selfCheckHost(args));
106
+ const program = ts.createProgram(treeFiles, SELF_CHECK_OPTIONS, stubResolutionHost(args, SELF_CHECK_OPTIONS));
133
107
  const checker = program.getTypeChecker();
134
108
  const diagnostics = ts.getPreEmitDiagnostics(program);
135
109
  // A surface holds EVERY alias, and every alias's closure starts there, so
@@ -580,7 +554,14 @@ function checkedRecord(anchor, ctx) {
580
554
  !anchor.abstainReason &&
581
555
  !(anchor.request.kind === 'literal' && anchor.request.type_text.trim() === 'unknown') &&
582
556
  !unreadCause(anchor).unread_cause
583
- ? { unread_cause: 'declared' }
557
+ ? {
558
+ // The anchor's source program read this top type through a
559
+ // reference that did not resolve (carrick#3995): the root twin of
560
+ // `provenanceOf`.
561
+ unread_cause: anchor.unresolved?.paths.includes('')
562
+ ? 'unresolved_import'
563
+ : 'declared',
564
+ }
584
565
  : {}),
585
566
  ...unreadCause(anchor),
586
567
  };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A request body written as a conditional over the serialiser
3
+ * (`body: x ? JSON.stringify(x) : null`), carrick#4285.
4
+ *
5
+ * A direct `JSON.stringify(x)` body reads as the type of `x`: the call's own
6
+ * `string` is the wire text, never a contract. A conditional body reads each
7
+ * arm the same way: a serialised arm as its argument's type, any other arm as
8
+ * its own, and the body is the union of the arms. A conditional with no
9
+ * serialised arm is none of this module's business and reads as it always did.
10
+ *
11
+ * Lives in the capture bundle; the v1 inferrer (ts-morph) reaches it through
12
+ * capture/index.js, and the capture anchor
13
+ * resolver (raw program) answer it with the same rule.
14
+ */
15
+ import ts from 'typescript';
16
+ /**
17
+ * The nodes whose types make up a conditional serialised body: for each arm,
18
+ * the serialiser's argument or the arm itself (a nested conditional is
19
+ * flattened). Undefined when `node` is not a conditional, or when none of its
20
+ * arms is a `JSON.stringify` call. A property assignment reads as its value.
21
+ */
22
+ export declare function serialisedConditionalArms(node: ts.Node): ts.Node[] | undefined;
23
+ /**
24
+ * The union of the arms' own types, or undefined when the checker cannot join
25
+ * them (the caller then keeps its existing reading).
26
+ */
27
+ export declare function serialisedConditionalType(checker: ts.TypeChecker, node: ts.Node): ts.Type | undefined;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * A request body written as a conditional over the serialiser
3
+ * (`body: x ? JSON.stringify(x) : null`), carrick#4285.
4
+ *
5
+ * A direct `JSON.stringify(x)` body reads as the type of `x`: the call's own
6
+ * `string` is the wire text, never a contract. A conditional body reads each
7
+ * arm the same way: a serialised arm as its argument's type, any other arm as
8
+ * its own, and the body is the union of the arms. A conditional with no
9
+ * serialised arm is none of this module's business and reads as it always did.
10
+ *
11
+ * Lives in the capture bundle; the v1 inferrer (ts-morph) reaches it through
12
+ * capture/index.js, and the capture anchor
13
+ * resolver (raw program) answer it with the same rule.
14
+ */
15
+ import ts from 'typescript';
16
+ const MAX_DEPTH = 8;
17
+ function peel(node) {
18
+ let current = node;
19
+ while (ts.isParenthesizedExpression(current))
20
+ current = current.expression;
21
+ return current;
22
+ }
23
+ /** The argument of a `JSON.stringify(arg)` call, else undefined. */
24
+ function stringifiedArgument(node) {
25
+ if (ts.isCallExpression(node) &&
26
+ node.arguments.length > 0 &&
27
+ ts.isPropertyAccessExpression(node.expression) &&
28
+ ts.isIdentifier(node.expression.expression) &&
29
+ node.expression.expression.text === 'JSON' &&
30
+ node.expression.name.text === 'stringify') {
31
+ return node.arguments[0];
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * The nodes whose types make up a conditional serialised body: for each arm,
37
+ * the serialiser's argument or the arm itself (a nested conditional is
38
+ * flattened). Undefined when `node` is not a conditional, or when none of its
39
+ * arms is a `JSON.stringify` call. A property assignment reads as its value.
40
+ */
41
+ export function serialisedConditionalArms(node) {
42
+ const start = peel(ts.isPropertyAssignment(node) ? node.initializer : node);
43
+ if (!ts.isConditionalExpression(start))
44
+ return undefined;
45
+ const arms = [];
46
+ let serialised = false;
47
+ const walk = (expression, depth) => {
48
+ const arm = peel(expression);
49
+ if (ts.isConditionalExpression(arm) && depth < MAX_DEPTH) {
50
+ walk(arm.whenTrue, depth + 1);
51
+ walk(arm.whenFalse, depth + 1);
52
+ return;
53
+ }
54
+ const argument = stringifiedArgument(arm);
55
+ if (argument)
56
+ serialised = true;
57
+ arms.push(argument ? peel(argument) : arm);
58
+ };
59
+ walk(start.whenTrue, 0);
60
+ walk(start.whenFalse, 0);
61
+ return serialised ? arms : undefined;
62
+ }
63
+ /**
64
+ * The union of the arms' own types, or undefined when the checker cannot join
65
+ * them (the caller then keeps its existing reading).
66
+ */
67
+ export function serialisedConditionalType(checker, node) {
68
+ const arms = serialisedConditionalArms(node);
69
+ if (!arms)
70
+ return undefined;
71
+ const types = arms.map((arm) => checker.getTypeAtLocation(arm));
72
+ if (types.length === 1)
73
+ return types[0];
74
+ const union = checker.getUnionType;
75
+ return union ? union.call(checker, types, 1 /* UnionReduction.Literal */) : undefined;
76
+ }
@@ -13,6 +13,23 @@
13
13
  * reaches it through `capture/index.js` and hands it compiler nodes.
14
14
  */
15
15
  import ts from 'typescript';
16
+ /**
17
+ * The call a `call_result` locator's node names, or undefined when it names
18
+ * none (carrick#2056, carrick#4232): one rule for the inferrer and the capture.
19
+ *
20
+ * A call's result is read off the call. The node may wrap the call in what
21
+ * leaves its value as it is (`await`, parentheses, `as`, `<T>`, `!`,
22
+ * `satisfies`) or be the variable the call initialises. Anything else, a JSX
23
+ * element whose attribute holds a call included, is not the call's result.
24
+ */
25
+ export declare function callNamedBy(node: ts.Node | undefined): ts.CallExpression | undefined;
26
+ /**
27
+ * A wrapper that leaves its operand's value as it is: `await`, parentheses,
28
+ * `!`, a cast, `satisfies`.
29
+ */
30
+ export declare function wrapsValueTransparently(node: ts.Node): node is ts.AwaitExpression | ts.ParenthesizedExpression | ts.NonNullExpression | ts.AsExpression | ts.TypeAssertion | ts.SatisfiesExpression;
31
+ /** Why a call-result locator is refused, worded once for both readers. */
32
+ export declare function callResultNamesNoCall(where: string): string;
16
33
  /**
17
34
  * Strongly-discriminating member names of HTTP transport machinery: a
18
35
  * fetch/DOM `Response` & `Request`, a Node `http.ServerResponse`, a framework
@@ -14,6 +14,42 @@
14
14
  */
15
15
  import ts from 'typescript';
16
16
  // ===========================================================================
17
+ // Call-result locators
18
+ // ===========================================================================
19
+ /**
20
+ * The call a `call_result` locator's node names, or undefined when it names
21
+ * none (carrick#2056, carrick#4232): one rule for the inferrer and the capture.
22
+ *
23
+ * A call's result is read off the call. The node may wrap the call in what
24
+ * leaves its value as it is (`await`, parentheses, `as`, `<T>`, `!`,
25
+ * `satisfies`) or be the variable the call initialises. Anything else, a JSX
26
+ * element whose attribute holds a call included, is not the call's result.
27
+ */
28
+ export function callNamedBy(node) {
29
+ let current = node;
30
+ if (current && ts.isVariableDeclaration(current))
31
+ current = current.initializer;
32
+ while (current && wrapsValueTransparently(current))
33
+ current = current.expression;
34
+ return current && ts.isCallExpression(current) ? current : undefined;
35
+ }
36
+ /**
37
+ * A wrapper that leaves its operand's value as it is: `await`, parentheses,
38
+ * `!`, a cast, `satisfies`.
39
+ */
40
+ export function wrapsValueTransparently(node) {
41
+ return (ts.isAwaitExpression(node) ||
42
+ ts.isParenthesizedExpression(node) ||
43
+ ts.isNonNullExpression(node) ||
44
+ ts.isAsExpression(node) ||
45
+ ts.isTypeAssertionExpression(node) ||
46
+ ts.isSatisfiesExpression(node));
47
+ }
48
+ /** Why a call-result locator is refused, worded once for both readers. */
49
+ export function callResultNamesNoCall(where) {
50
+ return `the call-result locator at ${where} names no call; a call's result is read off the call, so the anchor abstains`;
51
+ }
52
+ // ===========================================================================
17
53
  // Framework machinery
18
54
  // ===========================================================================
19
55
  /**
@@ -0,0 +1,63 @@
1
+ /**
2
+ * How a stub's module specifiers resolve: one answer for the capture's
3
+ * self-check and for the definition resolver that reads the stub after it
4
+ * (carrick#3995 T5).
5
+ *
6
+ * The stub is written outside the checkout, so a bare specifier in it
7
+ * (`import("pkg").Thing`) reaches nothing by itself. The self-check reaches the
8
+ * producer's installed packages three ways: a `node_modules` link inside the
9
+ * stub to the producer's own, the capture's compiler host (installed-package
10
+ * rewrites, a Deno graph, the untrusted-tree read bound), and, for a
11
+ * declaration emitted from a source outside the service's rootDir, that
12
+ * source's own place in the checkout. The resolver used to read the stub with
13
+ * none of them, so an alias the self-check called clean answered `any`.
14
+ *
15
+ * The capture remembers each stub's resolution in this process; the resolver
16
+ * asks for it by stub directory. The compiler engine runs a capture in a
17
+ * process of its own and resolves its stub in the same process, right after.
18
+ * A stub this process did not capture reads with nothing installed, as before.
19
+ */
20
+ import ts from 'typescript';
21
+ import type { WriteGuard } from './guarded-fs.js';
22
+ /** What a stub's resolution is built from: the capture's, per stub. */
23
+ export interface StubResolution {
24
+ /** Writes held to this stub. */
25
+ guard: WriteGuard;
26
+ stubDir: string;
27
+ bareCheckout: boolean;
28
+ /** Producer repo root; its node_modules (if any) backs resolution. */
29
+ repoRoot: string;
30
+ compilerHost?: (options: ts.CompilerOptions) => ts.CompilerHost;
31
+ /**
32
+ * Absolute stub path of each declaration emitted for a source outside the
33
+ * service's rootDir -> that source's own path. A bare specifier such a
34
+ * declaration names that the stub's links do not reach is resolved from the
35
+ * source's place in the checkout, as the compiler resolved it at emit.
36
+ */
37
+ outsideSources?: Readonly<Record<string, string>>;
38
+ }
39
+ /**
40
+ * Point the stub at the producer's installed packages: a `node_modules` link
41
+ * in the stub to the producer's own, unless the checkout is bare or the stub
42
+ * already has one. Returns what removes the link again.
43
+ */
44
+ export declare function linkInstalledPackages(resolution: StubResolution): () => void;
45
+ /**
46
+ * The compiler host of a program over the stub: the capture's, with outside
47
+ * declarations resolving from their source. `undefined` means the compiler's
48
+ * default host.
49
+ */
50
+ export declare function stubResolutionHost(resolution: StubResolution, options: ts.CompilerOptions): ts.CompilerHost | undefined;
51
+ /** Forget every stub of an earlier capture: only the latest is resolved. */
52
+ export declare function forgetStubResolutions(): void;
53
+ /** Remember how a captured stub resolves, for the resolver that reads it next. */
54
+ export declare function rememberStubResolution(resolution: StubResolution): void;
55
+ /** Resolves module names in a program over a stub. */
56
+ export type StubModuleResolver = (moduleNames: string[], containingFile: string, options: ts.CompilerOptions) => (ts.ResolvedModuleFull | undefined)[];
57
+ /**
58
+ * Run `use` with the stub resolving as its self-check did: the installed
59
+ * packages linked in, and module names resolved through the self-check's host.
60
+ * `use` gets `undefined` when this process did not capture the stub; the stub
61
+ * then reads with nothing installed.
62
+ */
63
+ export declare function withStubResolution<T>(stubDir: string, use: (resolve: StubModuleResolver | undefined) => T): T;