carrick 0.3.157 → 0.3.158
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +8 -1
- package/dist/contract.js.map +1 -1
- package/dist/engine-ask.d.ts +21 -0
- package/dist/engine-ask.js +50 -0
- package/dist/engine-ask.js.map +1 -0
- package/dist/facts/diff.d.ts +14 -1
- package/dist/facts/diff.js +21 -8
- package/dist/facts/diff.js.map +1 -1
- package/dist/facts/fetch.d.ts +7 -0
- package/dist/facts/fetch.js +22 -1
- package/dist/facts/fetch.js.map +1 -1
- package/dist/facts/lines.d.ts +22 -4
- package/dist/facts/lines.js +31 -9
- package/dist/facts/lines.js.map +1 -1
- package/dist/facts/peers.d.ts +13 -4
- package/dist/facts/peers.js +17 -15
- package/dist/facts/peers.js.map +1 -1
- package/dist/facts/rules/packages.js +3 -1
- package/dist/facts/rules/packages.js.map +1 -1
- package/dist/facts/rules/same-name.js +1 -1
- package/dist/facts/rules/same-name.js.map +1 -1
- package/dist/facts/store.d.ts +15 -0
- package/dist/facts/store.js +30 -0
- package/dist/facts/store.js.map +1 -1
- package/dist/held/backoff.d.ts +8 -0
- package/dist/held/backoff.js +43 -0
- package/dist/held/backoff.js.map +1 -0
- package/dist/held/build.d.ts +17 -0
- package/dist/held/build.js +62 -0
- package/dist/held/build.js.map +1 -0
- package/dist/held/client.d.ts +12 -3
- package/dist/held/client.js +123 -8
- package/dist/held/client.js.map +1 -1
- package/dist/held/daemon.d.ts +47 -2
- package/dist/held/daemon.js +115 -23
- package/dist/held/daemon.js.map +1 -1
- package/dist/held/early.d.ts +28 -0
- package/dist/held/early.js +115 -0
- package/dist/held/early.js.map +1 -0
- package/dist/held/paths.d.ts +6 -0
- package/dist/held/paths.js +17 -0
- package/dist/held/paths.js.map +1 -1
- package/dist/held/place.d.ts +76 -30
- package/dist/held/place.js +121 -83
- package/dist/held/place.js.map +1 -1
- package/dist/held/run.js +24 -6
- package/dist/held/run.js.map +1 -1
- package/dist/held/runtime.d.ts +22 -0
- package/dist/held/runtime.js +612 -0
- package/dist/held/runtime.js.map +1 -0
- package/dist/held/shadow.d.ts +33 -0
- package/dist/held/shadow.js +68 -0
- package/dist/held/shadow.js.map +1 -0
- package/dist/held/steps.d.ts +11 -0
- package/dist/held/steps.js +29 -0
- package/dist/held/steps.js.map +1 -0
- package/dist/hook/confirm.d.ts +79 -0
- package/dist/hook/confirm.js +220 -0
- package/dist/hook/confirm.js.map +1 -0
- package/dist/hook/edit-flow.d.ts +14 -3
- package/dist/hook/edit-flow.js +113 -33
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/generation.d.ts +19 -0
- package/dist/hook/generation.js +75 -0
- package/dist/hook/generation.js.map +1 -0
- package/dist/hook/late.d.ts +50 -9
- package/dist/hook/late.js +104 -24
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/post-bash.js +3 -3
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.js +2 -2
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +25 -3
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.js +1 -1
- package/dist/hook/post-search.js.map +1 -1
- package/dist/hook/probe.js +1 -0
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/read-answer.d.ts +5 -0
- package/dist/hook/read-answer.js +8 -4
- package/dist/hook/read-answer.js.map +1 -1
- package/dist/hook/rechecks.d.ts +58 -2
- package/dist/hook/rechecks.js +132 -9
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/session-start.d.ts +1 -1
- package/dist/hook/session-start.js +19 -5
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/similar.d.ts +1 -1
- package/dist/hook/similar.js +21 -8
- package/dist/hook/similar.js.map +1 -1
- package/dist/hook/stop-wait.js +35 -16
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/timings.d.ts +29 -1
- package/dist/hook/timings.js +7 -1
- package/dist/hook/timings.js.map +1 -1
- package/dist/hook/user-prompt.js +2 -2
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hosted-snapshot.d.ts +27 -0
- package/dist/hosted-snapshot.js +32 -0
- package/dist/hosted-snapshot.js.map +1 -1
- package/dist/init/hosted.js +2 -9
- package/dist/init/hosted.js.map +1 -1
- package/dist/render.d.ts +15 -1
- package/dist/render.js +50 -4
- package/dist/render.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.d.ts +8 -0
- package/sidecar/dist/src/capture/anchors.js +3 -2
- package/sidecar/dist/src/capture/api.d.ts +70 -3
- package/sidecar/dist/src/capture/check-classify.d.ts +7 -0
- package/sidecar/dist/src/capture/check-classify.js +24 -0
- package/sidecar/dist/src/capture/check-probe.d.ts +76 -7
- package/sidecar/dist/src/capture/check-probe.js +147 -19
- package/sidecar/dist/src/capture/check.js +13 -1
- package/sidecar/dist/src/capture/graphql-leaves.d.ts +46 -0
- package/sidecar/dist/src/capture/graphql-leaves.js +142 -0
- package/sidecar/dist/src/capture/index.d.ts +4 -1
- package/sidecar/dist/src/capture/index.js +3 -1
- package/sidecar/dist/src/definition-resolver.d.ts +2 -1
- package/sidecar/dist/src/definition-resolver.js +15 -9
- package/sidecar/dist/src/engine-stamp.json +1 -1
- package/sidecar/dist/src/held-shadow.d.ts +12 -2
- package/sidecar/dist/src/held-shadow.js +9 -9
- package/sidecar/dist/src/index.js +18 -1
- package/sidecar/dist/src/library-claims.js +26 -3
- package/sidecar/dist/src/retype.d.ts +47 -0
- package/sidecar/dist/src/retype.js +274 -18
- package/sidecar/dist/src/site-find.d.ts +27 -0
- package/sidecar/dist/src/site-find.js +109 -0
- package/sidecar/dist/src/type-inferrer.d.ts +5 -0
- package/sidecar/dist/src/type-inferrer.js +8 -4
- package/sidecar/dist/src/type-structural-expander.d.ts +10 -0
- package/sidecar/dist/src/type-structural-expander.js +73 -4
- package/sidecar/dist/src/types.d.ts +50 -2
- package/sidecar/dist/src/validators.d.ts +328 -8
- package/sidecar/dist/src/validators.js +29 -0
|
@@ -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, WireFormat } from './api.js';
|
|
33
|
+
import type { CheckPairEndpoint, CheckPairSpec, GraphqlTypes, ProbeProtocol, ProbeTypeKind, WireFacts, 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 {
|
|
@@ -58,19 +58,28 @@ export declare function directionFor(protocol: ProbeProtocol, typeKind: ProbeTyp
|
|
|
58
58
|
* value's `toJSON()` result, so the producer of a response and the
|
|
59
59
|
* consumer of a request body send their JSON form;
|
|
60
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.
|
|
62
|
-
*
|
|
61
|
+
* `serialize`, so a resolver's `Date` reaches the client as a string. With
|
|
62
|
+
* the producer's SDL types and the root field the response answers
|
|
63
|
+
* (`facts.graphql`, carrick#4403) a built-in scalar leaf is compared in the
|
|
64
|
+
* type its scalar sends (`'graphql_scalars'`); without them, and for a
|
|
65
|
+
* custom scalar or an enum, in the JSON form. The request (variables) is
|
|
66
|
+
* read by the server as declared;
|
|
63
67
|
* - 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
|
|
68
|
+
* uses is a known fact: the codec belongs to the client, not the protocol;
|
|
69
|
+
* - an RPC procedure (tRPC and similar) travels in its router's
|
|
70
|
+
* transformer's form, either side: JSON with none, the declared `Date`
|
|
71
|
+
* with one that revives it (superjson). Until the transformer is a known
|
|
72
|
+
* fact the form is `'unknown'` (carrick#4402): the stored text prints it
|
|
73
|
+
* as declared, and the judge abstains where the two readings disagree.
|
|
65
74
|
*/
|
|
66
|
-
export declare function wireFormFor(protocol: ProbeProtocol, typeKind: ProbeTypeKind, side: Side): WireFormat;
|
|
75
|
+
export declare function wireFormFor(protocol: ProbeProtocol, typeKind: ProbeTypeKind, side: Side, facts?: WireFacts): WireFormat;
|
|
67
76
|
/** Deterministic FNV-1a (32-bit) over the pair's stable key. Never a path. */
|
|
68
77
|
export declare function fnv1a(input: string): string;
|
|
69
78
|
/** The pair ID is derived from the pair's semantic identity, not the workspace
|
|
70
79
|
* path, so it is byte-stable across runs. */
|
|
71
80
|
export declare function pairId(spec: CheckPairSpec): string;
|
|
72
81
|
/** Names each gate line so a TS2344 can be attributed to a specific side+kind. */
|
|
73
|
-
export type GateName = 'sent:any' | 'sent:unknown' | 'sent:never' | 'sent:void' | 'sent:form' | 'sent:bytes' | 'expected:any' | 'expected:unknown' | 'expected:never' | 'expected:void' | 'expected:bytes' | 'sent:envelope' | 'expected:envelope';
|
|
82
|
+
export type GateName = 'sent:any' | 'sent:unknown' | 'sent:never' | 'sent:void' | 'sent:form' | 'sent:bytes' | 'sent:wire_form' | 'expected:any' | 'expected:unknown' | 'expected:never' | 'expected:void' | 'expected:bytes' | 'sent:envelope' | 'expected:envelope';
|
|
74
83
|
export interface ProbePlan {
|
|
75
84
|
pairId: string;
|
|
76
85
|
spec: CheckPairSpec;
|
|
@@ -146,6 +155,66 @@ export declare const UNWIDENED_LOCAL_NAME = "SentUnwidened";
|
|
|
146
155
|
* (one that returns its own type), and which no depth of nesting reaches.
|
|
147
156
|
*/
|
|
148
157
|
export declare function jsonWireDeclarations(prefix: string): string[];
|
|
158
|
+
/**
|
|
159
|
+
* The judge's decisive wire rule as a type expression: keep the declared
|
|
160
|
+
* `sent` type whenever it already assigns to `expected` or serialising
|
|
161
|
+
* changes nothing observable, else the wire form. `buildProbe` writes it at
|
|
162
|
+
* every wire line, and the held check appends it, so the line and the PR
|
|
163
|
+
* check answer "what travels" from this one text. `prefix` is the one
|
|
164
|
+
* `jsonWireDeclarations` was given.
|
|
165
|
+
*/
|
|
166
|
+
export declare function jsonWireRule(sent: string, expected: string, prefix: string): string;
|
|
167
|
+
/**
|
|
168
|
+
* The receiver-declared-void gate's helper: `void` or `undefined` is what a
|
|
169
|
+
* call site that reads no body types its response as, and states no contract
|
|
170
|
+
* (carrick#1162). `any` is excluded first, so an `any` side keeps its own
|
|
171
|
+
* top-type reason. `prefix` namespaces the name, as for `jsonWireDeclarations`.
|
|
172
|
+
*/
|
|
173
|
+
export declare function voidReceiverDeclaration(prefix: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* The absent-body tolerance as a type expression over `sent` (carrick#2814):
|
|
176
|
+
* a body the sender may omit (`T | undefined`, `T | void`) is compatible with
|
|
177
|
+
* a receiver that requires none, which is one with no required member
|
|
178
|
+
* (`{} extends expected`) that either admits absence itself or whose handler
|
|
179
|
+
* works with nothing sent (`toleratesAbsence`, the capture record's
|
|
180
|
+
* `absent_body_tolerated`).
|
|
181
|
+
*/
|
|
182
|
+
export declare function absentBodyRule(sent: string, expected: string, toleratesAbsence: boolean): string;
|
|
183
|
+
/**
|
|
184
|
+
* The judge's three tolerances, as the texts the probe is built from: the
|
|
185
|
+
* literal-widened reading (`unwidened_alias_suffix`, the export suffix a stub
|
|
186
|
+
* ships its unwidened response under, `unwidenedAliasOf`), and the other two
|
|
187
|
+
* as declarations to append beside `jsonWireDeclarations` (same `prefix`):
|
|
188
|
+
* `<p>IsVoid<T>` (a receiver declared void), `<p>AbsentBody<S, E>` (the absent
|
|
189
|
+
* body dropped when the receiver admits absence) and `<p>AbsentBodyByHandler<S,
|
|
190
|
+
* E>` (the same when the receiver's handler is marked to tolerate it). A
|
|
191
|
+
* caller that checks a value against a declared type reads them from here,
|
|
192
|
+
* never from a copy.
|
|
193
|
+
*/
|
|
194
|
+
export interface JudgeTolerances {
|
|
195
|
+
unwidened_alias_suffix: string;
|
|
196
|
+
declarations: string[];
|
|
197
|
+
}
|
|
198
|
+
export declare function judgeTolerances(prefix: string): JudgeTolerances;
|
|
199
|
+
/**
|
|
200
|
+
* The probe's GraphQL leaf walk (carrick#4403), over the SDL types reachable
|
|
201
|
+
* from the root field (`graphqlReachableFields`, which reads the table only
|
|
202
|
+
* through `graphqlFieldLeaf`). `GqlLeafSent<C, F>` is the type the server
|
|
203
|
+
* sends for a value `C` declared as `F`:
|
|
204
|
+
*
|
|
205
|
+
* - `any` and `unknown` stay what they are, so a top type is never laundered
|
|
206
|
+
* into a scalar; non-null is read through; `null` and `undefined` stay;
|
|
207
|
+
* - a list maps its elements; a non-array under a list keeps the JSON form;
|
|
208
|
+
* - a built-in scalar is the type it sends (`GRAPHQL_SCALAR_SENT`); any
|
|
209
|
+
* other scalar, an enum and a field the table does not name are JSON;
|
|
210
|
+
* - an object type the table holds maps each field through its own leaf;
|
|
211
|
+
* a type reference it does not hold (an undeclared scalar) is JSON.
|
|
212
|
+
*
|
|
213
|
+
* Every test on `F` is wrapped (`[F] extends [...]`) so a missing leaf never
|
|
214
|
+
* distributes to `never`. Needs `JsonWire`, `GqlDepth` and the comparand's
|
|
215
|
+
* helpers declared before it.
|
|
216
|
+
*/
|
|
217
|
+
export declare function graphqlScalarDeclarations(reachable: Record<string, Record<string, unknown>>, rootLeaf: unknown): string[];
|
|
149
218
|
export declare function decisiveAssignmentLine(plan: ProbePlan): number;
|
|
150
219
|
/**
|
|
151
220
|
* Build one probe, recording the exact line of every gate and the assignment so
|
|
@@ -163,4 +232,4 @@ export declare function decisiveAssignmentLine(plan: ProbePlan): number;
|
|
|
163
232
|
* capture record marks a handler that works when no body is sent
|
|
164
233
|
* (carrick#2814).
|
|
165
234
|
*/
|
|
166
|
-
export declare function buildProbe(spec: CheckPairSpec, packageOf: (serviceName: string) => string, unwidenedAliasFor?: (sent: CheckPairEndpoint) => string | undefined, expectedToleratesAbsence?: (expected: CheckPairEndpoint) => boolean): ProbePlan;
|
|
235
|
+
export declare function buildProbe(spec: CheckPairSpec, packageOf: (serviceName: string) => string, unwidenedAliasFor?: (sent: CheckPairEndpoint) => string | undefined, expectedToleratesAbsence?: (expected: CheckPairEndpoint) => boolean, graphqlTypesOf?: (serviceName: string) => GraphqlTypes | undefined): ProbePlan;
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
*
|
|
31
31
|
* Seam: node builtins + `typescript` + this bundle only. No imports needed here.
|
|
32
32
|
*/
|
|
33
|
+
import { GRAPHQL_SCALAR_SENT, graphqlReachableFields, graphqlRootLeaf, } from './graphql-leaves.js';
|
|
33
34
|
/**
|
|
34
35
|
* The direction table, keyed on (protocol, type_kind) — one place. Structurally
|
|
35
36
|
* fixes the confirmed HTTP request-body inversion (data flows consumer ->
|
|
@@ -60,18 +61,33 @@ export function directionFor(protocol, typeKind) {
|
|
|
60
61
|
* value's `toJSON()` result, so the producer of a response and the
|
|
61
62
|
* consumer of a request body send their JSON form;
|
|
62
63
|
* - `graphql` response: the server sends each leaf through its scalar's
|
|
63
|
-
* `serialize`, so a resolver's `Date` reaches the client as a string.
|
|
64
|
-
*
|
|
64
|
+
* `serialize`, so a resolver's `Date` reaches the client as a string. With
|
|
65
|
+
* the producer's SDL types and the root field the response answers
|
|
66
|
+
* (`facts.graphql`, carrick#4403) a built-in scalar leaf is compared in the
|
|
67
|
+
* type its scalar sends (`'graphql_scalars'`); without them, and for a
|
|
68
|
+
* custom scalar or an enum, in the JSON form. The request (variables) is
|
|
69
|
+
* read by the server as declared;
|
|
65
70
|
* - 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
|
|
71
|
+
* uses is a known fact: the codec belongs to the client, not the protocol;
|
|
72
|
+
* - an RPC procedure (tRPC and similar) travels in its router's
|
|
73
|
+
* transformer's form, either side: JSON with none, the declared `Date`
|
|
74
|
+
* with one that revives it (superjson). Until the transformer is a known
|
|
75
|
+
* fact the form is `'unknown'` (carrick#4402): the stored text prints it
|
|
76
|
+
* as declared, and the judge abstains where the two readings disagree.
|
|
67
77
|
*/
|
|
68
|
-
export function wireFormFor(protocol, typeKind, side) {
|
|
78
|
+
export function wireFormFor(protocol, typeKind, side, facts = {}) {
|
|
69
79
|
if (directionFor(protocol, typeKind).sent !== side)
|
|
70
80
|
return 'declared';
|
|
81
|
+
if (facts.procedure)
|
|
82
|
+
return 'unknown';
|
|
71
83
|
if (protocol === 'http')
|
|
72
84
|
return 'json';
|
|
73
|
-
if (protocol === 'graphql' && typeKind === 'response')
|
|
74
|
-
|
|
85
|
+
if (protocol === 'graphql' && typeKind === 'response') {
|
|
86
|
+
const graphql = facts.graphql;
|
|
87
|
+
return graphql !== undefined && graphqlRootLeaf(graphql.types, graphql.root) !== undefined
|
|
88
|
+
? 'graphql_scalars'
|
|
89
|
+
: 'json';
|
|
90
|
+
}
|
|
75
91
|
return 'declared';
|
|
76
92
|
}
|
|
77
93
|
/** Deterministic FNV-1a (32-bit) over the pair's stable key. Never a path. */
|
|
@@ -142,6 +158,80 @@ export function jsonWireDeclarations(prefix) {
|
|
|
142
158
|
`type ${same}<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;`,
|
|
143
159
|
];
|
|
144
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* The judge's decisive wire rule as a type expression: keep the declared
|
|
163
|
+
* `sent` type whenever it already assigns to `expected` or serialising
|
|
164
|
+
* changes nothing observable, else the wire form. `buildProbe` writes it at
|
|
165
|
+
* every wire line, and the held check appends it, so the line and the PR
|
|
166
|
+
* check answer "what travels" from this one text. `prefix` is the one
|
|
167
|
+
* `jsonWireDeclarations` was given.
|
|
168
|
+
*/
|
|
169
|
+
export function jsonWireRule(sent, expected, prefix) {
|
|
170
|
+
return `[${sent}] extends [${expected}] ? ${sent} : (${prefix}JsonWireSame<${prefix}JsonWire<${sent}>, ${sent}> extends true ? ${sent} : ${prefix}JsonWire<${sent}>)`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The receiver-declared-void gate's helper: `void` or `undefined` is what a
|
|
174
|
+
* call site that reads no body types its response as, and states no contract
|
|
175
|
+
* (carrick#1162). `any` is excluded first, so an `any` side keeps its own
|
|
176
|
+
* top-type reason. `prefix` namespaces the name, as for `jsonWireDeclarations`.
|
|
177
|
+
*/
|
|
178
|
+
export function voidReceiverDeclaration(prefix) {
|
|
179
|
+
return `type ${prefix}IsVoid<T> = 0 extends 1 & T ? false : [T] extends [never] ? false : [T] extends [void] ? true : false;`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The absent-body tolerance as a type expression over `sent` (carrick#2814):
|
|
183
|
+
* a body the sender may omit (`T | undefined`, `T | void`) is compatible with
|
|
184
|
+
* a receiver that requires none, which is one with no required member
|
|
185
|
+
* (`{} extends expected`) that either admits absence itself or whose handler
|
|
186
|
+
* works with nothing sent (`toleratesAbsence`, the capture record's
|
|
187
|
+
* `absent_body_tolerated`).
|
|
188
|
+
*/
|
|
189
|
+
export function absentBodyRule(sent, expected, toleratesAbsence) {
|
|
190
|
+
const dropped = `Exclude<${sent}, undefined | void>`;
|
|
191
|
+
const byHandler = toleratesAbsence ? dropped : sent;
|
|
192
|
+
return `[Extract<${sent}, undefined | void>] extends [never] ? ${sent} : [{}] extends [${expected}] ? ([Extract<${expected}, undefined | void>] extends [never] ? ${byHandler} : ${dropped}) : ${sent}`;
|
|
193
|
+
}
|
|
194
|
+
export function judgeTolerances(prefix) {
|
|
195
|
+
return {
|
|
196
|
+
unwidened_alias_suffix: unwidenedAliasOf(''),
|
|
197
|
+
declarations: [
|
|
198
|
+
voidReceiverDeclaration(prefix),
|
|
199
|
+
`type ${prefix}AbsentBody<S, E> = ${absentBodyRule('S', 'E', false)};`,
|
|
200
|
+
`type ${prefix}AbsentBodyByHandler<S, E> = ${absentBodyRule('S', 'E', true)};`,
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The probe's GraphQL leaf walk (carrick#4403), over the SDL types reachable
|
|
206
|
+
* from the root field (`graphqlReachableFields`, which reads the table only
|
|
207
|
+
* through `graphqlFieldLeaf`). `GqlLeafSent<C, F>` is the type the server
|
|
208
|
+
* sends for a value `C` declared as `F`:
|
|
209
|
+
*
|
|
210
|
+
* - `any` and `unknown` stay what they are, so a top type is never laundered
|
|
211
|
+
* into a scalar; non-null is read through; `null` and `undefined` stay;
|
|
212
|
+
* - a list maps its elements; a non-array under a list keeps the JSON form;
|
|
213
|
+
* - a built-in scalar is the type it sends (`GRAPHQL_SCALAR_SENT`); any
|
|
214
|
+
* other scalar, an enum and a field the table does not name are JSON;
|
|
215
|
+
* - an object type the table holds maps each field through its own leaf;
|
|
216
|
+
* a type reference it does not hold (an undeclared scalar) is JSON.
|
|
217
|
+
*
|
|
218
|
+
* Every test on `F` is wrapped (`[F] extends [...]`) so a missing leaf never
|
|
219
|
+
* distributes to `never`. Needs `JsonWire`, `GqlDepth` and the comparand's
|
|
220
|
+
* helpers declared before it.
|
|
221
|
+
*/
|
|
222
|
+
export function graphqlScalarDeclarations(reachable, rootLeaf) {
|
|
223
|
+
const sent = Object.entries(GRAPHQL_SCALAR_SENT)
|
|
224
|
+
.map(([name, type]) => `${name}: ${type}`)
|
|
225
|
+
.join('; ');
|
|
226
|
+
return [
|
|
227
|
+
`type GqlScalarSent = { ${sent} };`,
|
|
228
|
+
`type GqlTypes = ${JSON.stringify(reachable)};`,
|
|
229
|
+
`type GqlRootLeaf = ${JSON.stringify(rootLeaf)};`,
|
|
230
|
+
`type GqlTypeOf<F> = [F] extends [{ non_null: infer I }] ? GqlTypeOf<I> : [F] extends [{ type: infer T }] ? T : never;`,
|
|
231
|
+
`type GqlFieldOf<T, K> = [T] extends [never] ? unknown : [T] extends [keyof GqlTypes] ? ([K] extends [keyof GqlTypes[T]] ? GqlTypes[T][K] : unknown) : unknown;`,
|
|
232
|
+
`type GqlLeafSent<C, F, D extends number = 15> = [D] extends [never] ? JsonWire<C> : [unknown] extends [C] ? C : [F] extends [{ non_null: infer I }] ? GqlLeafSent<C, I, D> : C extends null | undefined ? C : [F] extends [{ list: infer I }] ? (C extends readonly unknown[] ? { [K in keyof C]: GqlLeafSent<C[K], I, GqlDepth[D]> } : JsonWire<C>) : [F] extends [{ scalar: infer N }] ? (N extends keyof GqlScalarSent ? GqlScalarSent[N] : JsonWire<C>) : [F] extends [{ type: infer T }] ? ([T] extends [keyof GqlTypes] ? (C extends readonly unknown[] ? JsonWire<C> : C extends (...args: any[]) => any ? C : C extends object ? { [K in keyof C]: GqlLeafSent<C[K], GqlFieldOf<T, K>, GqlDepth[D]> } : JsonWire<C>) : JsonWire<C>) : JsonWire<C>;`,
|
|
233
|
+
];
|
|
234
|
+
}
|
|
145
235
|
export function decisiveAssignmentLine(plan) {
|
|
146
236
|
return plan.wireAssignmentLine ?? plan.assignmentLine;
|
|
147
237
|
}
|
|
@@ -161,7 +251,7 @@ export function decisiveAssignmentLine(plan) {
|
|
|
161
251
|
* capture record marks a handler that works when no body is sent
|
|
162
252
|
* (carrick#2814).
|
|
163
253
|
*/
|
|
164
|
-
export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedToleratesAbsence) {
|
|
254
|
+
export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedToleratesAbsence, graphqlTypesOf) {
|
|
165
255
|
const id = pairId(spec);
|
|
166
256
|
const direction = directionFor(spec.protocol, spec.type_kind);
|
|
167
257
|
const sentEndpoint = direction.sent === 'producer' ? spec.producer : spec.consumer;
|
|
@@ -193,7 +283,7 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
193
283
|
// contract, so no counterparty shape can be judged against it.
|
|
194
284
|
// `any` is excluded first: `[any] extends [void]` holds, and an `any` side
|
|
195
285
|
// must keep its own top-type reason, never read as "reads no body".
|
|
196
|
-
push(
|
|
286
|
+
push(voidReceiverDeclaration(''));
|
|
197
287
|
gateLines.set(push(`type _G_sent_void = Assert<Not<IsVoid<Sent>>>;`), 'sent:void');
|
|
198
288
|
gateLines.set(push(`type _G_expected_void = Assert<Not<IsVoid<Expected>>>;`), 'expected:void');
|
|
199
289
|
// carrick#1162: a form-encoded request body (the platform `FormData` or
|
|
@@ -255,16 +345,19 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
255
345
|
spec.protocol === 'socket' ||
|
|
256
346
|
spec.protocol === 'pubsub';
|
|
257
347
|
const toleratesAbsence = expectedToleratesAbsence?.(expectedEndpoint) === true;
|
|
258
|
-
const sentBodyType = (sent) =>
|
|
259
|
-
const dropped = `Exclude<${sent}, undefined | void>`;
|
|
260
|
-
const byHandler = toleratesAbsence ? dropped : sent;
|
|
261
|
-
return `[Extract<${sent}, undefined | void>] extends [never] ? ${sent} : [{}] extends [Expected] ? ([Extract<Expected, undefined | void>] extends [never] ? ${byHandler} : ${dropped}) : ${sent}`;
|
|
262
|
-
};
|
|
348
|
+
const sentBodyType = (sent) => absentBodyRule(sent, 'Expected', toleratesAbsence);
|
|
263
349
|
if (absentBodyAllowed)
|
|
264
350
|
push(`type SentBody = ${sentBodyType('Sent')};`);
|
|
265
351
|
const sentBody = absentBodyAllowed ? 'SentBody' : 'Sent';
|
|
266
352
|
push(`declare const sent: ${sentBody};`);
|
|
267
|
-
const
|
|
353
|
+
const graphqlTypes = graphqlTypesOf?.(spec.producer.service_name);
|
|
354
|
+
const graphqlFacts = graphqlTypes !== undefined && spec.graphql_root !== undefined
|
|
355
|
+
? { graphql: { types: graphqlTypes, root: spec.graphql_root } }
|
|
356
|
+
: {};
|
|
357
|
+
const wire = wireFormFor(spec.protocol, spec.type_kind, direction.sent, {
|
|
358
|
+
procedure: spec.procedure,
|
|
359
|
+
...graphqlFacts,
|
|
360
|
+
});
|
|
268
361
|
let assignmentLine;
|
|
269
362
|
let wireAssignmentLine;
|
|
270
363
|
if (spec.protocol === 'graphql') {
|
|
@@ -340,7 +433,28 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
340
433
|
if (wire === 'json') {
|
|
341
434
|
for (const line of jsonWireDeclarations(''))
|
|
342
435
|
push(line);
|
|
343
|
-
push(`type GqlWire =
|
|
436
|
+
push(`type GqlWire = ${jsonWireRule('GqlComparand', 'GqlExpected', '')};`);
|
|
437
|
+
push(`declare const sentWire: GqlWire;`);
|
|
438
|
+
wireAssignmentLine = push(`const expectedWire: GqlExpected = sentWire;`);
|
|
439
|
+
}
|
|
440
|
+
else if (wire === 'graphql_scalars') {
|
|
441
|
+
// carrick#4403: each leaf in the type its scalar sends, read from the
|
|
442
|
+
// SDL from the root field down. The walk follows the producer's own
|
|
443
|
+
// type, so it ends where that type ends; the depth bound backs it up.
|
|
444
|
+
// A field the SDL does not name, a custom scalar and an enum keep the
|
|
445
|
+
// JSON form; a leaf keeps the producer's own null and undefined.
|
|
446
|
+
const { graphql } = graphqlFacts;
|
|
447
|
+
const rootLeaf = graphqlRootLeaf(graphql.types, graphql.root);
|
|
448
|
+
for (const line of jsonWireDeclarations(''))
|
|
449
|
+
push(line);
|
|
450
|
+
for (const line of graphqlScalarDeclarations(graphqlReachableFields(graphql.types, rootLeaf), rootLeaf)) {
|
|
451
|
+
push(line);
|
|
452
|
+
}
|
|
453
|
+
// After a single-payload unwrap the comparand is the payload: its leaf
|
|
454
|
+
// is the envelope field's, when the SDL declares the envelope. When it
|
|
455
|
+
// does not, the root leaf already describes the payload.
|
|
456
|
+
push(`type GqlComparandLeaf = [Sent] extends [GqlExpected] ? GqlRootLeaf : ([GqlPayloadOf<Sent>] extends [never] ? GqlRootLeaf : [GqlReadsOuter<Sent, Expected>] extends [true] ? GqlRootLeaf : ([unknown] extends [GqlFieldOf<GqlTypeOf<GqlRootLeaf>, GqlSingleKey<GqlPayloadKeys<Sent>>>] ? GqlRootLeaf : GqlFieldOf<GqlTypeOf<GqlRootLeaf>, GqlSingleKey<GqlPayloadKeys<Sent>>>));`);
|
|
457
|
+
push(`type GqlWire = [GqlComparand] extends [GqlExpected] ? GqlComparand : (JsonWireSame<GqlLeafSent<GqlComparand, GqlComparandLeaf>, GqlComparand> extends true ? GqlComparand : GqlLeafSent<GqlComparand, GqlComparandLeaf>);`);
|
|
344
458
|
push(`declare const sentWire: GqlWire;`);
|
|
345
459
|
wireAssignmentLine = push(`const expectedWire: GqlExpected = sentWire;`);
|
|
346
460
|
}
|
|
@@ -370,10 +484,23 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
370
484
|
// that name — and there the declared name no longer describes what travels.
|
|
371
485
|
for (const line of jsonWireDeclarations(''))
|
|
372
486
|
push(line);
|
|
373
|
-
push(`type WireSent =
|
|
487
|
+
push(`type WireSent = ${jsonWireRule(sentBody, 'Expected', '')};`);
|
|
374
488
|
push(`declare const sentWire: WireSent;`);
|
|
375
489
|
wireAssignmentLine = push(`const expectedWire: Expected = sentWire;`);
|
|
376
490
|
}
|
|
491
|
+
// The wire form is unknown (carrick#4402): an RPC procedure, whose router's
|
|
492
|
+
// transformer decides what travels. The declared line stays decisive, and
|
|
493
|
+
// the gate fires where the two readings disagree: the declared form fails
|
|
494
|
+
// and the JSON form passes, so the verdict hangs on the transformer. Where
|
|
495
|
+
// both pass or both fail, the declared line decides alone. No `sentWire`
|
|
496
|
+
// const is declared, so the field report reads no wire form and the pair
|
|
497
|
+
// carries no wire note.
|
|
498
|
+
if (wire === 'unknown') {
|
|
499
|
+
for (const line of jsonWireDeclarations(''))
|
|
500
|
+
push(line);
|
|
501
|
+
push(`type WireDecides = [${sentBody}] extends [Expected] ? false : [JsonWire<${sentBody}>] extends [Expected] ? true : false;`);
|
|
502
|
+
gateLines.set(push(`type _G_sent_wire_form = Assert<Not<WireDecides>>;`), 'sent:wire_form');
|
|
503
|
+
}
|
|
377
504
|
// The unwidened reading (carrick#1538). A handler that returns
|
|
378
505
|
// `cond ? 'a' : 'b'` publishes `string`, because a literal widens where it
|
|
379
506
|
// is inferred, and a consumer that declares `'a' | 'b'` then mismatches a
|
|
@@ -390,9 +517,10 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
390
517
|
// assignment the second reading mirrors, here in the wire form. A GraphQL
|
|
391
518
|
// pair compares an unwrapped comparand (above), which a plain assignment of
|
|
392
519
|
// the reading would not mirror. Socket and pub/sub payloads are not read
|
|
393
|
-
// again
|
|
520
|
+
// again, and neither is a sending side whose wire form is unknown
|
|
521
|
+
// (carrick#4402): it is judged in JSON form, which could clear the pair.
|
|
394
522
|
let unwidenedFromLine;
|
|
395
|
-
const sentUnwidenedAlias = spec.protocol === 'http' ? unwidenedAliasFor?.(sentEndpoint) : undefined;
|
|
523
|
+
const sentUnwidenedAlias = spec.protocol === 'http' && wire === 'json' ? unwidenedAliasFor?.(sentEndpoint) : undefined;
|
|
396
524
|
if (sentUnwidenedAlias !== undefined) {
|
|
397
525
|
const local = UNWIDENED_LOCAL_NAME;
|
|
398
526
|
unwidenedFromLine = push(`import type { ${sentUnwidenedAlias} as ${local} } from '${sentPkg}';`);
|
|
@@ -404,7 +532,7 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
404
532
|
push(`type SentUnwidenedBody = ${sentBodyType(local)};`);
|
|
405
533
|
unwidenedBody = 'SentUnwidenedBody';
|
|
406
534
|
}
|
|
407
|
-
push(`type WireSentUnwidened =
|
|
535
|
+
push(`type WireSentUnwidened = ${jsonWireRule(unwidenedBody, 'Expected', '')};`);
|
|
408
536
|
push(`declare const sentWireUnwidened: WireSentUnwidened;`);
|
|
409
537
|
push(`const expectedWireUnwidened: Expected = sentWireUnwidened;`);
|
|
410
538
|
}
|
|
@@ -372,7 +372,7 @@ export async function runCheck(opts, onProgress) {
|
|
|
372
372
|
const unresolved = [];
|
|
373
373
|
for (const spec of opts.pairs) {
|
|
374
374
|
try {
|
|
375
|
-
plans.push(buildProbe(spec, ws.packageOf, unwidenedAliasIn(aliasRecords), absenceToleratedIn(aliasRecords)));
|
|
375
|
+
plans.push(buildProbe(spec, ws.packageOf, unwidenedAliasIn(aliasRecords), absenceToleratedIn(aliasRecords), graphqlTypesIn(opts.stubs)));
|
|
376
376
|
}
|
|
377
377
|
catch {
|
|
378
378
|
unresolved.push({
|
|
@@ -787,6 +787,18 @@ function dedupeDegraded(list) {
|
|
|
787
787
|
seen.set(d.service_name, d);
|
|
788
788
|
return [...seen.values()].sort((a, b) => a.service_name < b.service_name ? -1 : a.service_name > b.service_name ? 1 : 0);
|
|
789
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* Each service's SDL output types (carrick#4403), as its stub input carries
|
|
792
|
+
* them. A service id named twice answers nothing: which stub the judge reads
|
|
793
|
+
* is not known.
|
|
794
|
+
*/
|
|
795
|
+
function graphqlTypesIn(stubs) {
|
|
796
|
+
const byService = new Map();
|
|
797
|
+
for (const stub of stubs) {
|
|
798
|
+
byService.set(stub.service_name, byService.has(stub.service_name) ? undefined : stub.graphql_types);
|
|
799
|
+
}
|
|
800
|
+
return (serviceName) => byService.get(serviceName);
|
|
801
|
+
}
|
|
790
802
|
/** Plan pairs without a workspace (for the isolation-unavailable early exit). */
|
|
791
803
|
function planPairs(opts, packageOf) {
|
|
792
804
|
const plans = [];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDL side of a GraphQL producer response (carrick#4403): what type each
|
|
3
|
+
* field of the response is declared as, read from the service's one type
|
|
4
|
+
* table (`GraphqlTypes`) from the root field down.
|
|
5
|
+
*
|
|
6
|
+
* A GraphQL server sends each leaf through its scalar's `serialize`. The
|
|
7
|
+
* built-in scalars are fixed by the spec (`GRAPHQL_SCALAR_SENT`); a custom
|
|
8
|
+
* scalar's `serialize` is not read, so it keeps the JSON form, and so does an
|
|
9
|
+
* enum. Both the judge's probe and the stored type text read the table only
|
|
10
|
+
* through `graphqlFieldLeaf`, the one lookup.
|
|
11
|
+
*
|
|
12
|
+
* Seam: this bundle only.
|
|
13
|
+
*/
|
|
14
|
+
import type { GraphqlLeaf, GraphqlRoot, GraphqlTypes } from './api.js';
|
|
15
|
+
/**
|
|
16
|
+
* The type each built-in scalar sends, by the GraphQL spec: `String` and `ID`
|
|
17
|
+
* serialise to a string, `Int` and `Float` to a number, `Boolean` to a
|
|
18
|
+
* boolean. Every other scalar keeps the JSON form.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GRAPHQL_SCALAR_SENT: Readonly<Record<string, 'string' | 'number' | 'boolean'>>;
|
|
21
|
+
/** The type a built-in scalar sends, or `undefined` for any other scalar. */
|
|
22
|
+
export declare function graphqlScalarSent(name: string): 'string' | 'number' | 'boolean' | undefined;
|
|
23
|
+
/** `leaf` with its non-null wrappers removed; a list is kept. */
|
|
24
|
+
export declare function withoutNonNull(leaf: GraphqlLeaf): GraphqlLeaf;
|
|
25
|
+
/**
|
|
26
|
+
* The declared output type of `field` on `typeName`, or `undefined` when the
|
|
27
|
+
* table does not say. An object or interface answers from its fields. A union
|
|
28
|
+
* answers only for a field every member declares with the same type; a
|
|
29
|
+
* member that is itself a union is read the same way, and a union met again
|
|
30
|
+
* on the way answers nothing, so a cyclic table ends.
|
|
31
|
+
*/
|
|
32
|
+
export declare function graphqlFieldLeaf(types: GraphqlTypes, typeName: string, field: string, visiting?: ReadonlySet<string>): GraphqlLeaf | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the table holds `typeName`. A type no schema file of the service
|
|
35
|
+
* declares (an undeclared custom scalar) is a reference with no entry: a
|
|
36
|
+
* leaf that names it is read as unknown, in the JSON form.
|
|
37
|
+
*/
|
|
38
|
+
export declare function graphqlDeclaresType(types: GraphqlTypes, typeName: string): boolean;
|
|
39
|
+
/** The leaf the root field is declared as, or `undefined` when the table has none. */
|
|
40
|
+
export declare function graphqlRootLeaf(types: GraphqlTypes, root: GraphqlRoot): GraphqlLeaf | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The table a probe needs for one response: every type reachable from
|
|
43
|
+
* `leaf`, each as the fields `graphqlFieldLeaf` answers for it (a union's
|
|
44
|
+
* shared fields), keyed and ordered by name so the probe text is stable.
|
|
45
|
+
*/
|
|
46
|
+
export declare function graphqlReachableFields(types: GraphqlTypes, leaf: GraphqlLeaf): Record<string, Record<string, GraphqlLeaf>>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDL side of a GraphQL producer response (carrick#4403): what type each
|
|
3
|
+
* field of the response is declared as, read from the service's one type
|
|
4
|
+
* table (`GraphqlTypes`) from the root field down.
|
|
5
|
+
*
|
|
6
|
+
* A GraphQL server sends each leaf through its scalar's `serialize`. The
|
|
7
|
+
* built-in scalars are fixed by the spec (`GRAPHQL_SCALAR_SENT`); a custom
|
|
8
|
+
* scalar's `serialize` is not read, so it keeps the JSON form, and so does an
|
|
9
|
+
* enum. Both the judge's probe and the stored type text read the table only
|
|
10
|
+
* through `graphqlFieldLeaf`, the one lookup.
|
|
11
|
+
*
|
|
12
|
+
* Seam: this bundle only.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The type each built-in scalar sends, by the GraphQL spec: `String` and `ID`
|
|
16
|
+
* serialise to a string, `Int` and `Float` to a number, `Boolean` to a
|
|
17
|
+
* boolean. Every other scalar keeps the JSON form.
|
|
18
|
+
*/
|
|
19
|
+
export const GRAPHQL_SCALAR_SENT = Object.freeze({
|
|
20
|
+
String: 'string',
|
|
21
|
+
ID: 'string',
|
|
22
|
+
Int: 'number',
|
|
23
|
+
Float: 'number',
|
|
24
|
+
Boolean: 'boolean',
|
|
25
|
+
});
|
|
26
|
+
/** The type a built-in scalar sends, or `undefined` for any other scalar. */
|
|
27
|
+
export function graphqlScalarSent(name) {
|
|
28
|
+
return Object.prototype.hasOwnProperty.call(GRAPHQL_SCALAR_SENT, name)
|
|
29
|
+
? GRAPHQL_SCALAR_SENT[name]
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
/** `leaf` with its non-null wrappers removed; a list is kept. */
|
|
33
|
+
export function withoutNonNull(leaf) {
|
|
34
|
+
let current = leaf;
|
|
35
|
+
while ('non_null' in current)
|
|
36
|
+
current = current.non_null;
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
function leavesEqual(a, b) {
|
|
40
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The declared output type of `field` on `typeName`, or `undefined` when the
|
|
44
|
+
* table does not say. An object or interface answers from its fields. A union
|
|
45
|
+
* answers only for a field every member declares with the same type; a
|
|
46
|
+
* member that is itself a union is read the same way, and a union met again
|
|
47
|
+
* on the way answers nothing, so a cyclic table ends.
|
|
48
|
+
*/
|
|
49
|
+
export function graphqlFieldLeaf(types, typeName, field, visiting = new Set()) {
|
|
50
|
+
if (visiting.has(typeName))
|
|
51
|
+
return undefined;
|
|
52
|
+
if (!Object.prototype.hasOwnProperty.call(types, typeName))
|
|
53
|
+
return undefined;
|
|
54
|
+
const def = types[typeName];
|
|
55
|
+
if ('fields' in def) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(def.fields, field)
|
|
57
|
+
? def.fields[field]
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
if (def.members.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
const inner = new Set(visiting).add(typeName);
|
|
63
|
+
let shared;
|
|
64
|
+
for (const member of def.members) {
|
|
65
|
+
const leaf = graphqlFieldLeaf(types, member, field, inner);
|
|
66
|
+
if (leaf === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (shared === undefined)
|
|
69
|
+
shared = leaf;
|
|
70
|
+
else if (!leavesEqual(shared, leaf))
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return shared;
|
|
74
|
+
}
|
|
75
|
+
/** The fields `typeName` answers for, as `graphqlFieldLeaf` reads them. */
|
|
76
|
+
function graphqlFieldsOf(types, typeName, visiting = new Set()) {
|
|
77
|
+
if (visiting.has(typeName))
|
|
78
|
+
return [];
|
|
79
|
+
if (!Object.prototype.hasOwnProperty.call(types, typeName))
|
|
80
|
+
return [];
|
|
81
|
+
const def = types[typeName];
|
|
82
|
+
if ('fields' in def)
|
|
83
|
+
return Object.keys(def.fields);
|
|
84
|
+
const inner = new Set(visiting).add(typeName);
|
|
85
|
+
const names = new Set();
|
|
86
|
+
for (const member of def.members) {
|
|
87
|
+
for (const name of graphqlFieldsOf(types, member, inner))
|
|
88
|
+
names.add(name);
|
|
89
|
+
}
|
|
90
|
+
return [...names].filter((name) => graphqlFieldLeaf(types, typeName, name) !== undefined);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Whether the table holds `typeName`. A type no schema file of the service
|
|
94
|
+
* declares (an undeclared custom scalar) is a reference with no entry: a
|
|
95
|
+
* leaf that names it is read as unknown, in the JSON form.
|
|
96
|
+
*/
|
|
97
|
+
export function graphqlDeclaresType(types, typeName) {
|
|
98
|
+
return Object.prototype.hasOwnProperty.call(types, typeName);
|
|
99
|
+
}
|
|
100
|
+
/** The leaf the root field is declared as, or `undefined` when the table has none. */
|
|
101
|
+
export function graphqlRootLeaf(types, root) {
|
|
102
|
+
return graphqlFieldLeaf(types, root.type, root.field);
|
|
103
|
+
}
|
|
104
|
+
/** The named type a leaf refers to through its wrappers, if it refers to one. */
|
|
105
|
+
function referencedType(leaf) {
|
|
106
|
+
let current = leaf;
|
|
107
|
+
while ('non_null' in current || 'list' in current) {
|
|
108
|
+
current = 'non_null' in current ? current.non_null : current.list;
|
|
109
|
+
}
|
|
110
|
+
return 'type' in current ? current.type : undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The table a probe needs for one response: every type reachable from
|
|
114
|
+
* `leaf`, each as the fields `graphqlFieldLeaf` answers for it (a union's
|
|
115
|
+
* shared fields), keyed and ordered by name so the probe text is stable.
|
|
116
|
+
*/
|
|
117
|
+
export function graphqlReachableFields(types, leaf) {
|
|
118
|
+
const out = {};
|
|
119
|
+
const pending = [];
|
|
120
|
+
const first = referencedType(leaf);
|
|
121
|
+
if (first !== undefined)
|
|
122
|
+
pending.push(first);
|
|
123
|
+
const seen = new Set();
|
|
124
|
+
while (pending.length > 0) {
|
|
125
|
+
const name = pending.pop();
|
|
126
|
+
if (seen.has(name))
|
|
127
|
+
continue;
|
|
128
|
+
seen.add(name);
|
|
129
|
+
if (!graphqlDeclaresType(types, name))
|
|
130
|
+
continue;
|
|
131
|
+
const fields = {};
|
|
132
|
+
for (const field of graphqlFieldsOf(types, name).sort()) {
|
|
133
|
+
const fieldLeaf = graphqlFieldLeaf(types, name, field);
|
|
134
|
+
fields[field] = fieldLeaf;
|
|
135
|
+
const next = referencedType(fieldLeaf);
|
|
136
|
+
if (next !== undefined && !seen.has(next))
|
|
137
|
+
pending.push(next);
|
|
138
|
+
}
|
|
139
|
+
out[name] = fields;
|
|
140
|
+
}
|
|
141
|
+
return Object.fromEntries(Object.keys(out).sort().map((name) => [name, out[name]]));
|
|
142
|
+
}
|
|
@@ -36,6 +36,7 @@ export type { CaptureStubOptions, CaptureStubResult } from './api.js';
|
|
|
36
36
|
* row's `decided` is one of the three values the cast states.
|
|
37
37
|
*/
|
|
38
38
|
export declare const TYPE_REASONS: Readonly<Record<TypeProvenanceReason, TypeReason>>;
|
|
39
|
+
export type { GraphqlLeaf, GraphqlRoot, GraphqlTypes } from './api.js';
|
|
39
40
|
export { DenoProject, findDenoConfig } from './deno-project.js';
|
|
40
41
|
export { sidecarCompilerOptions } from './compiler-options.js';
|
|
41
42
|
export { withStubResolution, type StubModuleResolver } from './stub-resolution.js';
|
|
@@ -54,7 +55,9 @@ export { moduleExport } from './anchors.js';
|
|
|
54
55
|
export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, type DeclaredOutside, } from './site-node.js';
|
|
55
56
|
export { runCheck, judgeTscPath } from './check.js';
|
|
56
57
|
export type { CheckProgress } from './check.js';
|
|
57
|
-
export { jsonWireDeclarations, wireFormFor } from './check-probe.js';
|
|
58
|
+
export { jsonWireDeclarations, jsonWireRule, judgeTolerances, wireFormFor, type JudgeTolerances } from './check-probe.js';
|
|
59
|
+
export { nodeByExpressionText, isPreferredTarget } from './anchors.js';
|
|
60
|
+
export { graphqlDeclaresType, graphqlFieldLeaf, graphqlRootLeaf, graphqlScalarSent, withoutNonNull, } from './graphql-leaves.js';
|
|
58
61
|
export { findDisqualifyingTopTypes } from './deep-walk.js';
|
|
59
62
|
/**
|
|
60
63
|
* The name of THIS capture's surface entry, without an extension
|
|
@@ -79,7 +79,9 @@ export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocator
|
|
|
79
79
|
// v2 check core ("tsc as the judge"). Same bundle, same seam: the sidecar
|
|
80
80
|
// reaches it only through this door (index.js).
|
|
81
81
|
export { runCheck, judgeTscPath } from './check.js';
|
|
82
|
-
export { jsonWireDeclarations, wireFormFor } from './check-probe.js';
|
|
82
|
+
export { jsonWireDeclarations, jsonWireRule, judgeTolerances, wireFormFor } from './check-probe.js';
|
|
83
|
+
export { nodeByExpressionText, isPreferredTarget } from './anchors.js';
|
|
84
|
+
export { graphqlDeclaresType, graphqlFieldLeaf, graphqlRootLeaf, graphqlScalarSent, withoutNonNull, } from './graphql-leaves.js';
|
|
83
85
|
export { findDisqualifyingTopTypes } from './deep-walk.js';
|
|
84
86
|
const SURFACE_ENTRY_BASENAME = '__carrick_surface__';
|
|
85
87
|
/** Captures made by this process, so each one's entry file has a name of its
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
* (carrick#3995 T5).
|
|
42
42
|
*/
|
|
43
43
|
import type { DefinitionAlias } from './types.js';
|
|
44
|
+
import type { GraphqlTypes } from './capture/index.js';
|
|
44
45
|
export interface ResolvedDefinition {
|
|
45
46
|
type_alias: string;
|
|
46
47
|
/** Original declaration text as written (preserves named types) */
|
|
@@ -60,7 +61,7 @@ export declare class DefinitionResolver {
|
|
|
60
61
|
* both extensionless and `.js`-suffixed specifiers — the same policy the
|
|
61
62
|
* check-phase workspace uses.
|
|
62
63
|
*/
|
|
63
|
-
resolveFromStub(stubDir: string, aliases: DefinitionAlias[]): ResolvedDefinition[];
|
|
64
|
+
resolveFromStub(stubDir: string, aliases: DefinitionAlias[], graphqlTypes?: GraphqlTypes): ResolvedDefinition[];
|
|
64
65
|
/**
|
|
65
66
|
* Resolve a single alias: the original text and the structural form.
|
|
66
67
|
*/
|