carrick 0.3.126 → 0.3.128
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/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.js +5 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +8 -1
- package/sidecar/dist/src/capture/check-classify.js +21 -1
- package/sidecar/dist/src/capture/check-probe.d.ts +7 -7
- package/sidecar/dist/src/capture/check-probe.js +13 -14
- package/sidecar/dist/src/capture/check.js +5 -5
- package/sidecar/dist/src/index.js +56 -4
- package/sidecar/dist/src/library-claims.d.ts +63 -3
- package/sidecar/dist/src/library-claims.js +435 -44
- package/sidecar/dist/src/retype.js +124 -8
- package/sidecar/dist/src/server-labels.d.ts +29 -0
- package/sidecar/dist/src/server-labels.js +45 -0
- package/sidecar/dist/src/stated-params.d.ts +138 -0
- package/sidecar/dist/src/stated-params.js +547 -0
- package/sidecar/dist/src/type-inferrer.d.ts +144 -8
- package/sidecar/dist/src/type-inferrer.js +635 -35
- package/sidecar/dist/src/types.d.ts +84 -3
- package/sidecar/dist/src/unwidened.d.ts +11 -2
- package/sidecar/dist/src/unwidened.js +50 -3
- package/sidecar/dist/src/validators.d.ts +228 -59
- package/sidecar/dist/src/validators.js +45 -2
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { Project, SourceFile, type CallExpression } from 'ts-morph';
|
|
21
21
|
import type { InferRequestItem, InferResult, ModelSymbol, ExtractionConfig } from './types.js';
|
|
22
|
+
import type { LabelledMembers } from './library-claims.js';
|
|
22
23
|
/**
|
|
23
24
|
* Strongly-discriminating member names of HTTP transport machinery — the
|
|
24
25
|
* fetch/DOM `Response` & `Request`, a Node `http.ServerResponse`, a framework
|
|
@@ -123,9 +124,15 @@ export declare class TypeInferrer {
|
|
|
123
124
|
* @param onRequestDone - Called once per request, as the batch is done with it
|
|
124
125
|
* @returns InferResult with inferred types or errors
|
|
125
126
|
*/
|
|
126
|
-
infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[]): InferResult;
|
|
127
|
+
infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[], labels?: LabelledMembers): InferResult;
|
|
127
128
|
/** The types the model named, by the alias of the row each is for (carrick#2111). */
|
|
128
129
|
private modelSymbols;
|
|
130
|
+
/**
|
|
131
|
+
* carrick#2674: what route handlers' parameters state, through the
|
|
132
|
+
* members the batch's verified server-framework labels name. Empty when
|
|
133
|
+
* the batch carries no labels, and then it reads nothing.
|
|
134
|
+
*/
|
|
135
|
+
private statedParams;
|
|
129
136
|
/**
|
|
130
137
|
* carrick#2111: where the model named a type for the response this request
|
|
131
138
|
* reads, record on `inferred` how that type relates to the compiler's type
|
|
@@ -161,13 +168,20 @@ export declare class TypeInferrer {
|
|
|
161
168
|
* really returns beside the published one (`unwidened_type_string`). See
|
|
162
169
|
* `unwidened.ts` for what is marked and why the reading is sound.
|
|
163
170
|
*
|
|
171
|
+
* carrick#2011: a request body (`read` is `'request_body'`) is read the same
|
|
172
|
+
* way, the call that sends it in place of the handler, except that a literal
|
|
173
|
+
* handed to any call other than the send is never marked.
|
|
174
|
+
*
|
|
164
175
|
* One rewrite for the whole batch: every file on any request's path is
|
|
165
176
|
* rewritten once, type-checked before and after, the requests re-inferred,
|
|
166
177
|
* and every file restored before returning, so the project other requests
|
|
167
178
|
* read is the project the scan loaded.
|
|
168
179
|
*
|
|
169
180
|
* Nothing is read past `deadline`: a batch that runs out keeps the readings
|
|
170
|
-
* it made and publishes none for the rest
|
|
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.
|
|
171
185
|
*/
|
|
172
186
|
private addUnwidenedReadings;
|
|
173
187
|
/**
|
|
@@ -295,6 +309,17 @@ export declare class TypeInferrer {
|
|
|
295
309
|
* when the located expression is not part of what the handler returns.
|
|
296
310
|
*/
|
|
297
311
|
private returnedSendHolding;
|
|
312
|
+
/**
|
|
313
|
+
* True when `node` is a bare reference to a parameter of the handler the
|
|
314
|
+
* route registration on the request's line hands in (found as
|
|
315
|
+
* `registrationAtLine` finds it, wrappers included): the request, the reply
|
|
316
|
+
* or the context the framework passes, never a body the route sends
|
|
317
|
+
* (carrick-cloud#2576). Where the parameter's type is declared is not read:
|
|
318
|
+
* a parameter of any other function is data, whether the repo or an
|
|
319
|
+
* installed package types it (`.then((account) => reply.send(account))`, a
|
|
320
|
+
* helper's `account: Account`).
|
|
321
|
+
*/
|
|
322
|
+
private isRouteHandlerParameter;
|
|
298
323
|
/**
|
|
299
324
|
* True when a located call's own result is the route's payload, so the
|
|
300
325
|
* transitional drill into its first argument must not run (carrick#1732).
|
|
@@ -629,6 +654,72 @@ export declare class TypeInferrer {
|
|
|
629
654
|
private resultCarrierArguments;
|
|
630
655
|
/** The member names every branch holds, each with one and the same type. */
|
|
631
656
|
private membersCommonToEveryBranch;
|
|
657
|
+
/**
|
|
658
|
+
* What the source narrows a call's value to, where the type stated at the
|
|
659
|
+
* walk's terminal is a placeholder that leaves a position open
|
|
660
|
+
* (carrick#2714, `as { data: Item[] } | { error: unknown }`): the one type
|
|
661
|
+
* stated for the value later in the function, on its success path
|
|
662
|
+
* (`return json as { data: Item[] }`). A closed statement at the terminal
|
|
663
|
+
* keeps the answer it had.
|
|
664
|
+
*/
|
|
665
|
+
private narrowedBodyStatement;
|
|
666
|
+
/**
|
|
667
|
+
* The rule that verifies a call's result as a request library's response
|
|
668
|
+
* object, or undefined (carrick#2714). The result is that object when its
|
|
669
|
+
* awaited type is one a rule recognises. It is that object too when the
|
|
670
|
+
* call states no type arguments and its declared result, with its free
|
|
671
|
+
* type parameters at their defaults (`freeResultAtDefaults`), is a type a
|
|
672
|
+
* rule recognises (`get<T, R = Response<T>>(): Promise<R>`).
|
|
673
|
+
* The compiler then takes the parameter from where the value goes
|
|
674
|
+
* (`return client.post(…)` in a function declared `Promise<void>` types the
|
|
675
|
+
* call `Promise<void>`), and that is the caller's claim about the object,
|
|
676
|
+
* not what the call returns.
|
|
677
|
+
*/
|
|
678
|
+
private transportRuleOfCall;
|
|
679
|
+
/**
|
|
680
|
+
* The first rule that matches `type` as a wrapper whose body is a member
|
|
681
|
+
* (`payloadPropertyPath`) the type has, whether or not it reads a payload
|
|
682
|
+
* out of it. A
|
|
683
|
+
* wrapper with no such member (the platform's `Response`) is read by its
|
|
684
|
+
* body reads (`res.json()`), which the def-use walk follows.
|
|
685
|
+
*/
|
|
686
|
+
private ruleRecognising;
|
|
687
|
+
/**
|
|
688
|
+
* What a call's declared result is when its free type parameters take
|
|
689
|
+
* their defaults, or undefined. A parameter is free when the declaration's
|
|
690
|
+
* result mentions it and none of its parameters do, so only a type
|
|
691
|
+
* argument, the default or the call's return position can fix it. The
|
|
692
|
+
* result is read through `Promise`, a free parameter (its default), and a
|
|
693
|
+
* conditional alias whose check type is a free parameter tested against
|
|
694
|
+
* exactly that parameter's default (`R extends Default ? Response<T> : R`:
|
|
695
|
+
* the true branch). Anything else is the type as written.
|
|
696
|
+
*/
|
|
697
|
+
private freeResultAtDefaults;
|
|
698
|
+
/**
|
|
699
|
+
* The call states the body itself: the rules read a payload out of its
|
|
700
|
+
* result (`client.get<Widget>(url)`). An untyped payload is no payload to
|
|
701
|
+
* the rules (they verify the object and read nothing), and a result its
|
|
702
|
+
* return position chose is no response object to them.
|
|
703
|
+
*/
|
|
704
|
+
private callStatesTypedPayload;
|
|
705
|
+
/**
|
|
706
|
+
* The body of a call that returns a response object (carrick#2714): the
|
|
707
|
+
* one type the source states, in the function the call is made in, for the
|
|
708
|
+
* reads of the object's payload member (`res.data as Widget`, `const w:
|
|
709
|
+
* Widget = res.data`, `return res.data` from a function that declares its
|
|
710
|
+
* return type), through a binding or in place. Where no read states one,
|
|
711
|
+
* or two state different types, or the object is handed on whole, the
|
|
712
|
+
* site states no response contract, and the abstain is decided so the
|
|
713
|
+
* capture does not re-read the call and publish the object.
|
|
714
|
+
*/
|
|
715
|
+
private transportCallBody;
|
|
716
|
+
/**
|
|
717
|
+
* The reads of a response object's payload member (`path`, e.g. `data`)
|
|
718
|
+
* that take it off the call's value: in place (`(await call).data`),
|
|
719
|
+
* through the name the value is bound to (`res.data`), or as a name
|
|
720
|
+
* destructured out of it (`const { data } = await call`).
|
|
721
|
+
*/
|
|
722
|
+
private payloadMemberReads;
|
|
632
723
|
/**
|
|
633
724
|
* The decided abstain of a call whose result carries transport the
|
|
634
725
|
* service's wrapper rules verify and read no payload out of (carrick#1841,
|
|
@@ -1703,11 +1794,14 @@ export declare class TypeInferrer {
|
|
|
1703
1794
|
*/
|
|
1704
1795
|
private registrationHandlerAt;
|
|
1705
1796
|
/**
|
|
1706
|
-
* The handler function referenced by a route-registration call: the
|
|
1797
|
+
* The handler function referenced by a route-registration call: the LAST
|
|
1707
1798
|
* argument that is an inline function, or an identifier bound to a function
|
|
1708
|
-
* (
|
|
1709
|
-
*
|
|
1710
|
-
*
|
|
1799
|
+
* (carrick#2472 P3-2b). The functions before it are middleware
|
|
1800
|
+
* (`route(path).post(auth, audit, handler)`), which runs first and hands on;
|
|
1801
|
+
* reading the first function read a middleware as the route. The path
|
|
1802
|
+
* literal is not function-valued, so it is skipped naturally. No callee-name
|
|
1803
|
+
* check: a call whose argument resolves to a function is structurally a
|
|
1804
|
+
* registration regardless of the framework.
|
|
1711
1805
|
*/
|
|
1712
1806
|
private handlerFromRegistrationCall;
|
|
1713
1807
|
/**
|
|
@@ -1722,16 +1816,32 @@ export declare class TypeInferrer {
|
|
|
1722
1816
|
* declaration (via the compiler's definition nodes) and returned when that
|
|
1723
1817
|
* declaration is — or initializes to — a function. Anything else (a path
|
|
1724
1818
|
* literal, an object, a non-function binding) yields undefined.
|
|
1819
|
+
* `followWrapperCalls` false reads a binding to a wrapper call as no
|
|
1820
|
+
* function, so a name the wrapper walk meets is never walked again.
|
|
1725
1821
|
*/
|
|
1726
1822
|
private asHandlerFunction;
|
|
1727
1823
|
/**
|
|
1728
1824
|
* Extract a `FunctionLike` from a declaration node the compiler resolved an
|
|
1729
1825
|
* identifier to: a function declaration is itself the function; a variable
|
|
1730
1826
|
* declaration / binding whose initializer is an inline function yields that
|
|
1731
|
-
* function (`const h = async () => { … }`)
|
|
1732
|
-
*
|
|
1827
|
+
* function (`const h = async () => { … }`), and one whose initializer is a
|
|
1828
|
+
* wrapper call yields the function the call wraps
|
|
1829
|
+
* (`const h = wrap<Contract>(async (req, res) => { … })`, carrick#2472
|
|
1830
|
+
* P3-2b; `functionWrappedBy`). Import/re-export shims are walked by
|
|
1831
|
+
* ts-morph's `getDefinitionNodes`, so no manual import chasing is needed.
|
|
1733
1832
|
*/
|
|
1734
1833
|
private functionFromDeclaration;
|
|
1834
|
+
/**
|
|
1835
|
+
* The function a call wraps, for a name bound to that call and used as a
|
|
1836
|
+
* handler (carrick#2472 P3-2b): the call's one argument that is a function
|
|
1837
|
+
* literal, a name bound to one, or another such call, a few calls deep.
|
|
1838
|
+
*
|
|
1839
|
+
* Two conditions keep this to wrappers. The call's own value has to be
|
|
1840
|
+
* callable, because the name is used as a function: `rows.map((row) => …)`
|
|
1841
|
+
* is handed a function and yields a list. And exactly one argument may be a
|
|
1842
|
+
* function: with two there is no saying which of them is wrapped.
|
|
1843
|
+
*/
|
|
1844
|
+
private functionWrappedBy;
|
|
1735
1845
|
/**
|
|
1736
1846
|
* True when `handler` reads nothing from the incoming message (carrick#827):
|
|
1737
1847
|
* every use of one of its parameters, named or destructured, is the receiver
|
|
@@ -1952,6 +2062,12 @@ export declare class TypeInferrer {
|
|
|
1952
2062
|
* below reads it.
|
|
1953
2063
|
*/
|
|
1954
2064
|
private bodyBuiltByCallee;
|
|
2065
|
+
/**
|
|
2066
|
+
* `bodyBuiltByCallee`, telling apart a callee that sends the argument
|
|
2067
|
+
* unchanged (`passes`) from one that states nothing about it (`none`).
|
|
2068
|
+
* `depth` counts the forwarded locals followed (carrick#2671).
|
|
2069
|
+
*/
|
|
2070
|
+
private calleeBodyRead;
|
|
1955
2071
|
/**
|
|
1956
2072
|
* The request body value `use` is part of, inside `scope`: the value of a
|
|
1957
2073
|
* body-named object member, or the argument at a body slot of a call,
|
|
@@ -1959,6 +2075,15 @@ export declare class TypeInferrer {
|
|
|
1959
2075
|
* around it. `use` itself when it is that value whole.
|
|
1960
2076
|
*/
|
|
1961
2077
|
private bodyValueAround;
|
|
2078
|
+
/**
|
|
2079
|
+
* carrick#2671: the `const` local whose initializer holds `use`, inside
|
|
2080
|
+
* `scope`, when `scope` sends that local unchanged as the body: whole in a
|
|
2081
|
+
* body slot, or as an argument into a function that passes it on as its
|
|
2082
|
+
* body. The local's name, so its declared type is read. Undefined when the
|
|
2083
|
+
* local is never sent, when a further body is built from it, or when a
|
|
2084
|
+
* function lies between `use` and the declaration.
|
|
2085
|
+
*/
|
|
2086
|
+
private forwardedLocalHolding;
|
|
1962
2087
|
/** `value` is `use` behind what `sentValue` sees through. */
|
|
1963
2088
|
private isSameValue;
|
|
1964
2089
|
/**
|
|
@@ -2042,6 +2167,17 @@ export declare class TypeInferrer {
|
|
|
2042
2167
|
* own locator authoritative when a route declares nothing.
|
|
2043
2168
|
*/
|
|
2044
2169
|
private declaredRequestContract;
|
|
2170
|
+
/** The stated-parameter reader over `labels`, judging files and statuses as this inferrer does. */
|
|
2171
|
+
private statedParamsFor;
|
|
2172
|
+
/**
|
|
2173
|
+
* carrick#2674: where today's reading of a route's response is empty
|
|
2174
|
+
* (nothing, `void`, or an `unknown` the inferrer did not decide), the reply
|
|
2175
|
+
* its handler's parameter states, cut to its success variants. A typed
|
|
2176
|
+
* reading, or a decided abstain, stands as it is.
|
|
2177
|
+
*/
|
|
2178
|
+
private withStatedReply;
|
|
2179
|
+
/** Nothing read: `void`, or an `unknown` with no decided reason at its root. */
|
|
2180
|
+
private isEmptyResponseReading;
|
|
2045
2181
|
/**
|
|
2046
2182
|
* Anchor (a): the request contract declared on the handler's own signature.
|
|
2047
2183
|
*
|