carrick 0.3.135 → 0.3.137

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.
@@ -74,16 +74,40 @@ export interface TypeInferrerOptions {
74
74
  */
75
75
  repoRoot: string;
76
76
  /**
77
- * How long the unwidened reading of one `infer` batch may take
78
- * (carrick#1516). Defaults to `UNWIDENED_BUDGET_MS`.
77
+ * How much work the unwidened reading of one `infer` batch may do
78
+ * (carrick#2629). Each field defaults to its `UNWIDENED_*` constant.
79
79
  */
80
- unwidenedBudgetMs?: number;
80
+ unwidenedLimits?: Partial<UnwidenedLimits>;
81
+ /**
82
+ * The clock the unwidened reading's last-resort time limit reads, in
83
+ * milliseconds. Defaults to `performance.now`; a test passes a slow one.
84
+ */
85
+ now?: () => number;
86
+ }
87
+ /**
88
+ * The bounds on one batch's unwidened reading (carrick#2629). The first two
89
+ * count work, so a batch reads the same on a quiet machine and a loaded one;
90
+ * the third is a wall-clock backstop for a reading that runs away.
91
+ */
92
+ export interface UnwidenedLimits {
93
+ /** Readings (requests re-read in the rewrite) one batch may make. */
94
+ readings: number;
95
+ /** Files one batch may type-check before and after its rewrite. */
96
+ files: number;
97
+ /** The longest the reading may run, from its start, before it stops. */
98
+ backstopMs: number;
81
99
  }
82
100
  /**
83
101
  * Called each time an `infer` batch is done with one of its requests,
84
102
  * whatever that request answered: skipped, refused, failed or inferred.
85
103
  */
86
104
  export type InferRequestDone = () => void;
105
+ /**
106
+ * Called each time the unwidened reading finishes a unit of its work: a file
107
+ * type-checked or a request re-read (carrick#2629). The reading runs after
108
+ * every request is done, so this is what keeps a long one from going silent.
109
+ */
110
+ export type UnwidenedStepDone = () => void;
87
111
  /**
88
112
  * TypeInferrer - Extracts types from source code, both explicit and inferred
89
113
  *
@@ -101,7 +125,8 @@ export declare class TypeInferrer {
101
125
  * unwidened reading re-reads from here (carrick#1516).
102
126
  */
103
127
  private readonly readNodes;
104
- private readonly unwidenedBudgetMs;
128
+ private readonly unwidenedLimits;
129
+ private readonly now;
105
130
  /**
106
131
  * The files a request has named to this inferrer, as the requests named
107
132
  * them (carrick#1985). It lives as long as the project does, so the first
@@ -122,9 +147,10 @@ export declare class TypeInferrer {
122
147
  * @param requests - Array of inference requests
123
148
  * @param extractionConfig - Agent-generated extraction config for payload unwrapping
124
149
  * @param onRequestDone - Called once per request, as the batch is done with it
150
+ * @param onUnwidenedStep - Called once per unit of the unwidened reading's work
125
151
  * @returns InferResult with inferred types or errors
126
152
  */
127
- infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[], labels?: LabelledMembers): InferResult;
153
+ infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[], labels?: LabelledMembers, onUnwidenedStep?: UnwidenedStepDone): InferResult;
128
154
  /** The types the model named, by the alias of the row each is for (carrick#2111). */
129
155
  private modelSymbols;
130
156
  /**
@@ -177,11 +203,15 @@ export declare class TypeInferrer {
177
203
  * and every file restored before returning, so the project other requests
178
204
  * read is the project the scan loaded.
179
205
  *
180
- * Nothing is read past `deadline`: a batch that runs out keeps the readings
181
- * it made and publishes none for the rest, and marks each of the rest
182
- * `unwidened_out_of_budget` (carrick#2100). A request that never needed a
183
- * reading (a declared return, nothing to mark) or lost it for a reason of
184
- * its own (a marking that added a diagnostic) is never marked.
206
+ * The reading is bounded by work, not time (carrick#2629): a batch makes at
207
+ * most `UnwidenedLimits.readings` readings over at most `.files` files,
208
+ * taken in request order, the responses first. The first request past
209
+ * either cap and every request after it are marked
210
+ * `unwidened_out_of_budget` (carrick#2100) and publish no reading, on any
211
+ * machine. A reading still running at the wall-clock backstop stops the
212
+ * same way and says so in the log. A request that never needed a reading
213
+ * (a declared return, nothing to mark) or lost it for a reason of its own
214
+ * (a marking that added a diagnostic) is never marked.
185
215
  */
186
216
  private addUnwidenedReadings;
187
217
  /**
@@ -440,11 +470,17 @@ export declare class TypeInferrer {
440
470
  * success body.
441
471
  */
442
472
  private statementEndsFunctionPath;
473
+ /**
474
+ * The handler returns a send the service's labels name (carrick#3053): a
475
+ * `new` construction or a static call whose declaration a verified label
476
+ * keys. Its result is transport whatever its type looks like, so the body
477
+ * is read from the send's argument.
478
+ */
479
+ private returnsLabelledSend;
443
480
  /**
444
481
  * True when `candidate` is a response send: a call or `new` whose result is
445
482
  * transport machinery (by the extraction config's verified rule or the
446
- * structural check), or whose callee this handler's own returns prove is a
447
- * serialiser (`calleesProvenSerialiser`, which holds on a bare checkout).
483
+ * structural check).
448
484
  */
449
485
  private isResponseSend;
450
486
  /**
@@ -893,20 +929,34 @@ export declare class TypeInferrer {
893
929
  * the chain ends in is what the caller computed from it, and publishing
894
930
  * that as the body is the false mismatch this rule exists for.
895
931
  *
896
- * Exactly one such cast across the whole chain answers. None, or more than
932
+ * A call that narrows that parameter (a schema validates it, or a function
933
+ * returns it unchanged) states it the same way (carrick#3004).
934
+ *
935
+ * Exactly one such read across the whole chain answers. None, or more than
897
936
  * one (a callback on the failure side can be handed an `unknown` too), and
898
- * the walk carries on as before. A parameter typed `any` is not read: an
899
- * unresolved library types every callback that way, success and failure
900
- * alike, so it says nothing about which one is the body.
937
+ * `handedUnread` says a callback was handed the body all the same: what it
938
+ * returns is a value built from the body (`.mapOk`, `.then`, `.andThen`,
939
+ * whatever the name), so the value the chain ends in is never the body
940
+ * (carrick#3004). A parameter typed `any` is not read: an unresolved
941
+ * library types every callback that way, success and failure alike, so it
942
+ * says nothing about which one is the body.
901
943
  */
902
944
  private bodyReadInCallbackChain;
903
945
  /**
904
- * The casts of a callback's first parameter, when the compiler types that
905
- * parameter `unknown`: `response as T` and `<T>response`, the operand being
906
- * the parameter itself. A cast that leaves a position open states nothing
907
- * about the body and is skipped.
946
+ * `type`, or a type argument it is instantiated with at any depth, is
947
+ * `any` or `unknown`: `Chain<unknown>`, `Task<Outcome<unknown, E>>`. The
948
+ * value such a carrier hands its callbacks is untyped (carrick#3004).
908
949
  */
909
- private castsOfUnreadParameter;
950
+ private holdsTopTypeArgument;
951
+ /**
952
+ * What a callback states about its first parameter, when the compiler types
953
+ * that parameter `unknown`, or `undefined` when it is not handed one. A
954
+ * statement is a cast whose operand is the parameter itself (`response as
955
+ * T`, `<T>response`), or a call that narrows it (`callStatesItsArgument`:
956
+ * a schema validates it, or a function returns it unchanged). A cast that
957
+ * leaves a position open states nothing about the body and is skipped.
958
+ */
959
+ private statementsOfUnreadParameter;
910
960
  /**
911
961
  * The zero-argument whole-body read taken in place on the value `callExpr`
912
962
  * yields, or `undefined` (carrick#1851): `(await fetch(url)).text()`. The
@@ -1428,36 +1478,6 @@ export declare class TypeInferrer {
1428
1478
  * bare object literal does.
1429
1479
  */
1430
1480
  private responseReturnedExpressions;
1431
- /**
1432
- * The callees these returned expressions PROVE are response serialisers.
1433
- *
1434
- * A return type of `any` says the callee could not be resolved, not that it
1435
- * was a serialiser — the reason the unresolvable-callee case is otherwise
1436
- * restricted to arguments the source annotates. But a handler that writes
1437
- *
1438
- * return f(problem, { status: 401 });
1439
- * return f(payload);
1440
- *
1441
- * has stated what `f` is in its own source: a call that takes a body and,
1442
- * beside it, an HTTP status is a response serialiser, and nothing else is
1443
- * written that way. That is evidence the compiler does not need to resolve
1444
- * anything to see, so it survives the bare checkout CI scans, and it makes
1445
- * the second call's unannotated argument a payload rather than a guess.
1446
- *
1447
- * Three deliberate limits, each a negative test:
1448
- * - only RETURNED expressions count. A handler may well call a logger with
1449
- * `{ status: 500 }`; what it returns is what it serialises.
1450
- * - the status-stating argument must sit at index >= 1. A status in FIRST
1451
- * position is a field of the body (`{ status: 503, note }`), and reading
1452
- * it as evidence would promote every callee that takes a status field.
1453
- * - the evidence is per HANDLER, never cached across files. It says what
1454
- * this handler does, and that is all it is used for.
1455
- *
1456
- * Callees are keyed by resolved symbol where one exists — an import alias
1457
- * resolves locally even when its module does not — and by callee text
1458
- * otherwise.
1459
- */
1460
- private calleesProvenSerialiser;
1461
1481
  /**
1462
1482
  * Stable identity for a call's callee within one file: its resolved symbol
1463
1483
  * when the compiler has one, else the callee's source text.
@@ -1477,9 +1497,7 @@ export declare class TypeInferrer {
1477
1497
  *
1478
1498
  * `statedOnly` narrows what counts as a payload to an argument the source
1479
1499
  * annotates; see `recoverPayloadFromReturnStatements`. It is lifted for a
1480
- * callee the handler's own returned calls PROVE is a serialiser
1481
- * (`calleesProvenSerialiser`): there the source has stated what the callee
1482
- * is, so its argument is the payload even unannotated.
1500
+ * callee a caller has its own evidence for (`serialisers`).
1483
1501
  */
1484
1502
  private responseHelperPayloadNode;
1485
1503
  /**
@@ -2254,8 +2272,16 @@ export declare class TypeInferrer {
2254
2272
  * (nothing, `void`, or an `unknown` the inferrer did not decide), the reply
2255
2273
  * its handler's parameter states, cut to its success variants. A typed
2256
2274
  * reading, or a decided abstain, stands as it is.
2275
+ *
2276
+ * carrick#3054: a route whose receive op carries a `returns` label replies
2277
+ * with what its handler returns. A labelled send the handler's parameters
2278
+ * state wins over the return. The returned reply replaces a typed reading
2279
+ * only where it prints differently (the label names a part of the return,
2280
+ * or a nothing part is dropped); where it prints the same, today's reading
2281
+ * stands with everything it carries.
2257
2282
  */
2258
2283
  private withStatedReply;
2284
+ private publishStatedReply;
2259
2285
  /** Nothing read: `void`, or an `unknown` with no decided reason at its root. */
2260
2286
  private isEmptyResponseReading;
2261
2287
  /**