carrick 0.3.161 → 0.3.162
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/contract.d.ts +8 -0
- package/dist/contract.js.map +1 -1
- package/dist/facts/store.d.ts +12 -0
- package/dist/facts/store.js +15 -0
- package/dist/facts/store.js.map +1 -1
- package/dist/held/daemon.d.ts +8 -0
- package/dist/held/daemon.js.map +1 -1
- package/dist/held/early.d.ts +1 -1
- package/dist/held/early.js +29 -10
- package/dist/held/early.js.map +1 -1
- package/dist/held/message-rows.d.ts +3 -0
- package/dist/held/message-rows.js +41 -0
- package/dist/held/message-rows.js.map +1 -0
- package/dist/held/place.d.ts +11 -2
- package/dist/held/place.js +4 -1
- package/dist/held/place.js.map +1 -1
- package/dist/held/runtime.d.ts +1 -1
- package/dist/held/runtime.js +47 -17
- package/dist/held/runtime.js.map +1 -1
- package/dist/held/shadow.d.ts +2 -0
- package/dist/held/shadow.js.map +1 -1
- package/dist/hook/confirm.js +40 -21
- package/dist/hook/confirm.js.map +1 -1
- package/dist/init/codex.d.ts +1 -1
- package/dist/init/codex.js +8 -4
- package/dist/init/codex.js.map +1 -1
- package/dist/init/doctor.d.ts +10 -13
- package/dist/init/doctor.js +26 -92
- package/dist/init/doctor.js.map +1 -1
- package/dist/init/launcher.d.ts +35 -0
- package/dist/init/launcher.js +85 -0
- package/dist/init/launcher.js.map +1 -0
- package/dist/init/outdated.d.ts +3 -4
- package/dist/init/outdated.js +19 -8
- package/dist/init/outdated.js.map +1 -1
- package/dist/init/remove.js +4 -0
- package/dist/init/remove.js.map +1 -1
- package/dist/init/repo-copies.d.ts +1 -1
- package/dist/init/repo-copies.js +13 -4
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/run.js +17 -26
- package/dist/init/run.js.map +1 -1
- package/dist/init/self-update.js +7 -4
- package/dist/init/self-update.js.map +1 -1
- package/dist/init/settings.d.ts +0 -34
- package/dist/init/settings.js +11 -45
- package/dist/init/settings.js.map +1 -1
- package/dist/render.d.ts +6 -0
- package/dist/render.js +27 -7
- package/dist/render.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/carrick-hook.sh +122 -0
- package/plugin/hooks/hooks.json +8 -8
- package/sidecar/dist/src/capture/anchors.d.ts +2 -2
- package/sidecar/dist/src/capture/anchors.js +25 -10
- package/sidecar/dist/src/capture/api.d.ts +10 -0
- package/sidecar/dist/src/capture/check-classify.d.ts +11 -4
- package/sidecar/dist/src/capture/check-classify.js +65 -25
- package/sidecar/dist/src/capture/check-fields.d.ts +2 -1
- package/sidecar/dist/src/capture/check-fields.js +10 -2
- package/sidecar/dist/src/capture/check-probe.d.ts +77 -25
- package/sidecar/dist/src/capture/check-probe.js +100 -37
- package/sidecar/dist/src/capture/index.d.ts +3 -2
- package/sidecar/dist/src/capture/index.js +14 -2
- package/sidecar/dist/src/capture/reply-status.d.ts +86 -0
- package/sidecar/dist/src/capture/reply-status.js +255 -0
- package/sidecar/dist/src/capture/site-node.d.ts +34 -0
- package/sidecar/dist/src/capture/site-node.js +258 -0
- package/sidecar/dist/src/engine-stamp.json +1 -1
- package/sidecar/dist/src/held-shadow.d.ts +23 -2
- package/sidecar/dist/src/held-shadow.js +42 -8
- package/sidecar/dist/src/stated-params.d.ts +3 -2
- package/sidecar/dist/src/type-inferrer.d.ts +15 -55
- package/sidecar/dist/src/type-inferrer.js +83 -213
- package/sidecar/dist/src/types.d.ts +10 -0
- package/sidecar/dist/src/validators.d.ts +150 -28
- package/sidecar/dist/src/validators.js +15 -1
- package/templates/carrick-hook.sh +122 -0
|
@@ -64,7 +64,8 @@ function assignabilityOf(checker) {
|
|
|
64
64
|
*
|
|
65
65
|
* The sent side is whatever that assignment actually sent: the GraphQL
|
|
66
66
|
* comparand where one exists, then the JSON wire form where serialising
|
|
67
|
-
* changes the type
|
|
67
|
+
* changes the type, then the GraphQL declared fill where the wire form does
|
|
68
|
+
* not assign. Reading `sent` there instead would describe a type the
|
|
68
69
|
* judge did not compare, which is the one way a reader of this pair could
|
|
69
70
|
* contradict it.
|
|
70
71
|
*/
|
|
@@ -97,8 +98,15 @@ export function comparedTypes(opened, plan) {
|
|
|
97
98
|
// optionality gap or the wire note (carrick#1341). Where serialisation did
|
|
98
99
|
// change the type the wire form is a mapped type with real members, and it
|
|
99
100
|
// stays the thing compared, because that is what the judge judged.
|
|
101
|
+
const sentForm = wireApplied ? wire.type : declared.type;
|
|
102
|
+
// A GraphQL wire form that does not assign is decided by the declared line
|
|
103
|
+
// (carrick#4726): the wire type with the fields the root record lacks or
|
|
104
|
+
// converts in the type the served schema declares. That is what the judge
|
|
105
|
+
// compared, so the report reads it, and never calls a filled field missing.
|
|
106
|
+
const filled = declaredConstType(source, checker, 'sentDeclared');
|
|
107
|
+
const compared = filled !== undefined && !isAssignableTo(sentForm, expected.type) ? filled.type : sentForm;
|
|
100
108
|
return {
|
|
101
|
-
compared
|
|
109
|
+
compared,
|
|
102
110
|
expected,
|
|
103
111
|
wireApplied,
|
|
104
112
|
checker,
|
|
@@ -79,7 +79,7 @@ export declare function fnv1a(input: string): string;
|
|
|
79
79
|
* path, so it is byte-stable across runs. */
|
|
80
80
|
export declare function pairId(spec: CheckPairSpec): string;
|
|
81
81
|
/** Names each gate line so a TS2344 can be attributed to a specific side+kind. */
|
|
82
|
-
export type GateName = 'sent:any' | 'sent:unknown' | 'sent:never' | 'sent:void' | 'sent:form' | 'sent:bytes' | 'sent:wire_form' | '
|
|
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';
|
|
83
83
|
export interface ProbePlan {
|
|
84
84
|
pairId: string;
|
|
85
85
|
spec: CheckPairSpec;
|
|
@@ -121,6 +121,23 @@ export interface ProbePlan {
|
|
|
121
121
|
* sends with no literal widened.
|
|
122
122
|
*/
|
|
123
123
|
unwidenedFromLine?: number;
|
|
124
|
+
/**
|
|
125
|
+
* The GraphQL declared block (carrick#4726), present on a scalar-form probe
|
|
126
|
+
* only: its first line, after the wire line, and its assignment, which sends
|
|
127
|
+
* the wire type with the fields the root record lacks or converts in the
|
|
128
|
+
* type the served schema declares. When the wire line fails this line
|
|
129
|
+
* decides; any other diagnostic from the line after `assignmentLine` (the
|
|
130
|
+
* wire alias the fill is built on) to it means the fill was never judged.
|
|
131
|
+
*/
|
|
132
|
+
declaredFromLine?: number;
|
|
133
|
+
declaredAssignmentLine?: number;
|
|
134
|
+
/**
|
|
135
|
+
* The same assignment with every consumer key the table could not answer
|
|
136
|
+
* (one the schema type does not declare: a fragment on a union member or an
|
|
137
|
+
* interface implementation, an alias) as a type that assigns to nothing.
|
|
138
|
+
* It fails where the declared line passed only through such a key.
|
|
139
|
+
*/
|
|
140
|
+
declaredReadLine?: number;
|
|
124
141
|
}
|
|
125
142
|
/**
|
|
126
143
|
* The surface export that carries a response alias's unwidened reading
|
|
@@ -180,6 +197,20 @@ export declare function voidReceiverDeclaration(prefix: string): string;
|
|
|
180
197
|
* `absent_body_tolerated`).
|
|
181
198
|
*/
|
|
182
199
|
export declare function absentBodyRule(sent: string, expected: string, toleratesAbsence: boolean): string;
|
|
200
|
+
/**
|
|
201
|
+
* The top and bottom type tests the probe's six gates read: `IsAny<T>`,
|
|
202
|
+
* `IsUnknown<T>` (`any` excluded first) and `IsNever<T>`. `prefix` namespaces
|
|
203
|
+
* the names, as for `jsonWireDeclarations`; `buildProbe` writes them with
|
|
204
|
+
* none. A held check that must stay silent on a top or bottom side reads them
|
|
205
|
+
* from here, never from a copy.
|
|
206
|
+
*/
|
|
207
|
+
export declare function topTypeDeclarations(prefix: string): string[];
|
|
208
|
+
/**
|
|
209
|
+
* Whether the absent-body tolerance (`absentBodyRule`) reads a pair: the
|
|
210
|
+
* request direction of HTTP, and socket and pub/sub payloads (the subscriber
|
|
211
|
+
* is `expected`). Never an HTTP response, and not a GraphQL request.
|
|
212
|
+
*/
|
|
213
|
+
export declare function absentBodyApplies(protocol: ProbeProtocol, typeKind: ProbeTypeKind): boolean;
|
|
183
214
|
/**
|
|
184
215
|
* The judge's three tolerances, as the texts the probe is built from: the
|
|
185
216
|
* literal-widened reading (`unwidened_alias_suffix`, the export suffix a stub
|
|
@@ -250,35 +281,56 @@ export declare function graphqlComparandLeafRule(sent: string, expected: string,
|
|
|
250
281
|
/** The scalar form's wire line over the comparand (carrick#4403): each leaf as its scalar sends it. */
|
|
251
282
|
export declare function graphqlScalarWireRule(comparand: string, relaxed: string, leaf: string, prefix: string): string;
|
|
252
283
|
/**
|
|
253
|
-
* The
|
|
254
|
-
* `<p>
|
|
255
|
-
* `<p>
|
|
256
|
-
*
|
|
284
|
+
* The declared fill's helpers (carrick#1875 option 1, carrick#4726), namespaced
|
|
285
|
+
* by `prefix`. They read `<p>GqlTypes`, `<p>GqlScalarSent`, `<p>GqlFieldOf`,
|
|
286
|
+
* `<p>GqlDepth` and `<p>GqlNames`, so they follow the leaf walk's lines.
|
|
287
|
+
*
|
|
288
|
+
* A root resolver's record often lacks fields the schema declares (relations,
|
|
289
|
+
* computed fields), or holds one as a generic JSON value or a primitive where
|
|
290
|
+
* the schema declares an object type. Field resolvers the check does not read
|
|
291
|
+
* supply or convert them. `GqlSdlFilled<C, F, E>` is the record `C` (declared
|
|
292
|
+
* as `F`) with each such field replaced by `GqlSdlDeclared`, the type the
|
|
293
|
+
* schema declares for it, read over the consumer's own reading `E`:
|
|
257
294
|
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
295
|
+
* - non-null strips `null`, a nullable field adds `| null`, a list maps its
|
|
296
|
+
* elements;
|
|
297
|
+
* - a built-in scalar is the type it sends (`GqlScalarSent`); a custom
|
|
298
|
+
* scalar, an enum and a type the table does not hold are `any`, since the
|
|
299
|
+
* table holds no enum values and no scalar's wire form. The leaf walk
|
|
300
|
+
* (`GqlLeafSent`) does the same for a field the record has: it keeps the
|
|
301
|
+
* record's own form and states no constraint of its own;
|
|
302
|
+
* - an object type maps each consumer key the schema type declares to its
|
|
303
|
+
* declared type. A key it does not declare (a union member's or an
|
|
304
|
+
* interface implementation's field read through a fragment, an alias) is
|
|
305
|
+
* `U`: `any` on the declared line, `GqlUnread` on the read line, so a pair
|
|
306
|
+
* that passes only through such a key is told apart from one the table
|
|
307
|
+
* answered. `__typename` is supplied by the server and is `any`. Whether a
|
|
308
|
+
* selection is declared at all is the selection reader's question
|
|
309
|
+
* (carrick#3201). A consumer that reads the field as a non-object gets
|
|
310
|
+
* `{}`, which assigns to no primitive and no array;
|
|
311
|
+
* - the depth bound gives `any`, and so does a field the consumer does not
|
|
312
|
+
* read, which it never compares.
|
|
263
313
|
*
|
|
264
|
-
* Rule G: a field the record HAS is
|
|
265
|
-
* object type (or a list of them, at any depth) and the
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
314
|
+
* Rule G decides conversion: a field the record HAS is converted when the
|
|
315
|
+
* schema types it as an object type (or a list of them, at any depth) and the
|
|
316
|
+
* record's own type for it is a primitive or a generic JSON value. The JSON
|
|
317
|
+
* value is read by its structure, on the whole field before any union splits:
|
|
318
|
+
* it holds every JSON primitive, and an array of itself and a string-keyed
|
|
319
|
+
* object of itself both assign to it. A field that is, or includes, an object
|
|
320
|
+
* shape is compared field by field. The root record is never a field, so it
|
|
321
|
+
* is never replaced whole. No branch yields `never`.
|
|
272
322
|
*/
|
|
273
|
-
export declare function
|
|
323
|
+
export declare function graphqlDeclaredDeclarations(prefix: string): string[];
|
|
274
324
|
/**
|
|
275
|
-
* The
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* the
|
|
325
|
+
* The declared line's sent type (carrick#4726): the scalar form's wire type
|
|
326
|
+
* whenever that already assigns, else the wire type with the fields the
|
|
327
|
+
* record lacks or converts in the type the schema declares
|
|
328
|
+
* (`graphqlDeclaredDeclarations`). The short-circuit keeps every pair the wire
|
|
329
|
+
* line passes exactly as it was. `wire` is the scalar form's wire type,
|
|
330
|
+
* `relaxed` the consumer's reading, `leaf` the comparand's SDL leaf. The probe
|
|
331
|
+
* and the held check write this one text.
|
|
280
332
|
*/
|
|
281
|
-
export declare function
|
|
333
|
+
export declare function graphqlDeclaredRule(wire: string, relaxed: string, leaf: string, prefix: string, unread?: 'any' | 'unread'): string;
|
|
282
334
|
export declare function decisiveAssignmentLine(plan: ProbePlan): number;
|
|
283
335
|
/**
|
|
284
336
|
* Build one probe, recording the exact line of every gate and the assignment so
|
|
@@ -191,6 +191,28 @@ export function absentBodyRule(sent, expected, toleratesAbsence) {
|
|
|
191
191
|
const byHandler = toleratesAbsence ? dropped : sent;
|
|
192
192
|
return `[Extract<${sent}, undefined | void>] extends [never] ? ${sent} : [{}] extends [${expected}] ? ([Extract<${expected}, undefined | void>] extends [never] ? ${byHandler} : ${dropped}) : ${sent}`;
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* The top and bottom type tests the probe's six gates read: `IsAny<T>`,
|
|
196
|
+
* `IsUnknown<T>` (`any` excluded first) and `IsNever<T>`. `prefix` namespaces
|
|
197
|
+
* the names, as for `jsonWireDeclarations`; `buildProbe` writes them with
|
|
198
|
+
* none. A held check that must stay silent on a top or bottom side reads them
|
|
199
|
+
* from here, never from a copy.
|
|
200
|
+
*/
|
|
201
|
+
export function topTypeDeclarations(prefix) {
|
|
202
|
+
return [
|
|
203
|
+
`type ${prefix}IsAny<T> = 0 extends 1 & T ? true : false;`,
|
|
204
|
+
`type ${prefix}IsUnknown<T> = unknown extends T ? (0 extends 1 & T ? false : true) : false;`,
|
|
205
|
+
`type ${prefix}IsNever<T> = [T] extends [never] ? true : false;`,
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Whether the absent-body tolerance (`absentBodyRule`) reads a pair: the
|
|
210
|
+
* request direction of HTTP, and socket and pub/sub payloads (the subscriber
|
|
211
|
+
* is `expected`). Never an HTTP response, and not a GraphQL request.
|
|
212
|
+
*/
|
|
213
|
+
export function absentBodyApplies(protocol, typeKind) {
|
|
214
|
+
return (protocol === 'http' && typeKind === 'request') || protocol === 'socket' || protocol === 'pubsub';
|
|
215
|
+
}
|
|
194
216
|
export function judgeTolerances(prefix) {
|
|
195
217
|
return {
|
|
196
218
|
unwidened_alias_suffix: unwidenedAliasOf(''),
|
|
@@ -300,45 +322,73 @@ export function graphqlScalarWireRule(comparand, relaxed, leaf, prefix) {
|
|
|
300
322
|
return `[${comparand}] extends [${relaxed}] ? ${comparand} : (${p}JsonWireSame<${p}GqlLeafSent<${comparand}, ${leaf}>, ${comparand}> extends true ? ${comparand} : ${p}GqlLeafSent<${comparand}, ${leaf}>)`;
|
|
301
323
|
}
|
|
302
324
|
/**
|
|
303
|
-
* The
|
|
304
|
-
* `<p>
|
|
305
|
-
* `<p>
|
|
306
|
-
*
|
|
325
|
+
* The declared fill's helpers (carrick#1875 option 1, carrick#4726), namespaced
|
|
326
|
+
* by `prefix`. They read `<p>GqlTypes`, `<p>GqlScalarSent`, `<p>GqlFieldOf`,
|
|
327
|
+
* `<p>GqlDepth` and `<p>GqlNames`, so they follow the leaf walk's lines.
|
|
328
|
+
*
|
|
329
|
+
* A root resolver's record often lacks fields the schema declares (relations,
|
|
330
|
+
* computed fields), or holds one as a generic JSON value or a primitive where
|
|
331
|
+
* the schema declares an object type. Field resolvers the check does not read
|
|
332
|
+
* supply or convert them. `GqlSdlFilled<C, F, E>` is the record `C` (declared
|
|
333
|
+
* as `F`) with each such field replaced by `GqlSdlDeclared`, the type the
|
|
334
|
+
* schema declares for it, read over the consumer's own reading `E`:
|
|
307
335
|
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
336
|
+
* - non-null strips `null`, a nullable field adds `| null`, a list maps its
|
|
337
|
+
* elements;
|
|
338
|
+
* - a built-in scalar is the type it sends (`GqlScalarSent`); a custom
|
|
339
|
+
* scalar, an enum and a type the table does not hold are `any`, since the
|
|
340
|
+
* table holds no enum values and no scalar's wire form. The leaf walk
|
|
341
|
+
* (`GqlLeafSent`) does the same for a field the record has: it keeps the
|
|
342
|
+
* record's own form and states no constraint of its own;
|
|
343
|
+
* - an object type maps each consumer key the schema type declares to its
|
|
344
|
+
* declared type. A key it does not declare (a union member's or an
|
|
345
|
+
* interface implementation's field read through a fragment, an alias) is
|
|
346
|
+
* `U`: `any` on the declared line, `GqlUnread` on the read line, so a pair
|
|
347
|
+
* that passes only through such a key is told apart from one the table
|
|
348
|
+
* answered. `__typename` is supplied by the server and is `any`. Whether a
|
|
349
|
+
* selection is declared at all is the selection reader's question
|
|
350
|
+
* (carrick#3201). A consumer that reads the field as a non-object gets
|
|
351
|
+
* `{}`, which assigns to no primitive and no array;
|
|
352
|
+
* - the depth bound gives `any`, and so does a field the consumer does not
|
|
353
|
+
* read, which it never compares.
|
|
313
354
|
*
|
|
314
|
-
* Rule G: a field the record HAS is
|
|
315
|
-
* object type (or a list of them, at any depth) and the
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
355
|
+
* Rule G decides conversion: a field the record HAS is converted when the
|
|
356
|
+
* schema types it as an object type (or a list of them, at any depth) and the
|
|
357
|
+
* record's own type for it is a primitive or a generic JSON value. The JSON
|
|
358
|
+
* value is read by its structure, on the whole field before any union splits:
|
|
359
|
+
* it holds every JSON primitive, and an array of itself and a string-keyed
|
|
360
|
+
* object of itself both assign to it. A field that is, or includes, an object
|
|
361
|
+
* shape is compared field by field. The root record is never a field, so it
|
|
362
|
+
* is never replaced whole. No branch yields `never`.
|
|
322
363
|
*/
|
|
323
|
-
export function
|
|
364
|
+
export function graphqlDeclaredDeclarations(prefix) {
|
|
324
365
|
const p = prefix;
|
|
325
366
|
return [
|
|
326
367
|
`type ${p}GqlObjectLeaf<F> = [F] extends [{ non_null: infer I }] ? ${p}GqlObjectLeaf<I> : [F] extends [{ list: infer I }] ? ${p}GqlObjectLeaf<I> : [F] extends [{ type: infer T }] ? ([T] extends [keyof ${p}GqlTypes] ? true : false) : false;`,
|
|
327
368
|
`type ${p}GqlJsonValueLike<X> = [string | number | boolean] extends [X] ? ([X[]] extends [X] ? ([{ [k: string]: X }] extends [X] ? true : false) : false) : false;`,
|
|
328
369
|
`type ${p}GqlNotShape<X> = [X] extends [never] ? false : [X] extends [string | number | boolean | bigint] ? true : ${p}GqlJsonValueLike<X>;`,
|
|
329
370
|
`type ${p}GqlConvertedField<C, F> = [unknown] extends [C] ? false : [${p}GqlObjectLeaf<F>] extends [true] ? ${p}GqlNotShape<Exclude<C, null | undefined>> : false;`,
|
|
330
|
-
`type ${p}
|
|
371
|
+
`type ${p}GqlAt<E, K> = E extends object ? (K extends keyof E ? E[K] : never) : never;`,
|
|
372
|
+
`type ${p}GqlElemOf<E> = E extends readonly (infer X)[] ? X : never;`,
|
|
373
|
+
`type ${p}GqlUnread = { readonly __carrick_unread: never };`,
|
|
374
|
+
`type ${p}GqlSdlObject<E, T extends keyof ${p}GqlTypes, D extends number, U> = [E] extends [never] ? {} : E extends readonly unknown[] ? {} : E extends (...args: any[]) => any ? {} : E extends object ? { [K in keyof E]: K extends keyof ${p}GqlTypes[T] ? ${p}GqlSdlDeclared<E[K], ${p}GqlFieldOf<T, K>, U, ${p}GqlDepth[D]> : K extends '__typename' ? any : U } : {};`,
|
|
375
|
+
`type ${p}GqlSdlInner<E, F, U, D extends number> = [F] extends [{ list: infer I }] ? ${p}GqlSdlDeclared<${p}GqlElemOf<E>, I, U, ${p}GqlDepth[D]>[] : [F] extends [{ scalar: infer N }] ? (N extends keyof ${p}GqlScalarSent ? ${p}GqlScalarSent[N] : any) : [F] extends [{ type: infer T }] ? ([T] extends [keyof ${p}GqlTypes] ? ${p}GqlSdlObject<Exclude<E, null | undefined>, T, D, U> : any) : any;`,
|
|
376
|
+
`type ${p}GqlSdlDeclared<E, F, U, D extends number = 15> = [D] extends [never] ? any : [E] extends [never] ? any : [unknown] extends [E] ? E : [F] extends [{ non_null: infer I }] ? ${p}GqlSdlInner<E, I, U, D> : ${p}GqlSdlInner<E, F, U, D> | null;`,
|
|
377
|
+
`type ${p}GqlSdlFilled<C, F, E, U, D extends number = 15> = [D] extends [never] ? C : [unknown] extends [C] ? C : [F] extends [{ non_null: infer I }] ? ${p}GqlSdlFilled<C, I, E, U, D> : C extends null | undefined ? C : [F] extends [{ list: infer I }] ? (C extends readonly unknown[] ? { [K in keyof C]: ${p}GqlSdlFilled<C[K], I, ${p}GqlElemOf<E>, U, ${p}GqlDepth[D]> } : C) : [F] extends [{ type: infer T }] ? ([T] extends [keyof ${p}GqlTypes] ? (C extends readonly unknown[] ? C : C extends (...args: any[]) => any ? C : C extends object ? { [K in keyof C]: [${p}GqlConvertedField<C[K], ${p}GqlFieldOf<T, K>>] extends [true] ? ${p}GqlSdlDeclared<${p}GqlAt<E, K>, ${p}GqlFieldOf<T, K>, U, ${p}GqlDepth[D]> : ${p}GqlSdlFilled<C[K], ${p}GqlFieldOf<T, K>, ${p}GqlAt<E, K>, U, ${p}GqlDepth[D]> } & { [K in Exclude<keyof ${p}GqlTypes[T], keyof C> & ${p}GqlNames<E>]: ${p}GqlSdlDeclared<${p}GqlAt<E, K>, ${p}GqlFieldOf<T, K>, U, ${p}GqlDepth[D]> } : C) : C) : C;`,
|
|
331
378
|
];
|
|
332
379
|
}
|
|
333
380
|
/**
|
|
334
|
-
* The
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* the
|
|
381
|
+
* The declared line's sent type (carrick#4726): the scalar form's wire type
|
|
382
|
+
* whenever that already assigns, else the wire type with the fields the
|
|
383
|
+
* record lacks or converts in the type the schema declares
|
|
384
|
+
* (`graphqlDeclaredDeclarations`). The short-circuit keeps every pair the wire
|
|
385
|
+
* line passes exactly as it was. `wire` is the scalar form's wire type,
|
|
386
|
+
* `relaxed` the consumer's reading, `leaf` the comparand's SDL leaf. The probe
|
|
387
|
+
* and the held check write this one text.
|
|
339
388
|
*/
|
|
340
|
-
export function
|
|
341
|
-
|
|
389
|
+
export function graphqlDeclaredRule(wire, relaxed, leaf, prefix, unread = 'any') {
|
|
390
|
+
const u = unread === 'any' ? 'any' : `${prefix}GqlUnread`;
|
|
391
|
+
return `[${wire}] extends [${relaxed}] ? ${wire} : ${prefix}GqlSdlFilled<${wire}, ${leaf}, ${relaxed}, ${u}>`;
|
|
342
392
|
}
|
|
343
393
|
export function decisiveAssignmentLine(plan) {
|
|
344
394
|
return plan.wireAssignmentLine ?? plan.assignmentLine;
|
|
@@ -375,9 +425,8 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
375
425
|
};
|
|
376
426
|
importLines.push(push(`import type { ${sentEndpoint.alias} as Sent } from '${sentPkg}';`));
|
|
377
427
|
importLines.push(push(`import type { ${expectedEndpoint.alias} as Expected } from '${expectedPkg}';`));
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
push(`type IsNever<T> = [T] extends [never] ? true : false;`);
|
|
428
|
+
for (const line of topTypeDeclarations(''))
|
|
429
|
+
push(line);
|
|
381
430
|
push(`type Not<T extends boolean> = T extends true ? false : true;`);
|
|
382
431
|
push(`type Assert<T extends true> = T;`);
|
|
383
432
|
gateLines.set(push(`type _G_sent_any = Assert<Not<IsAny<Sent>>>;`), 'sent:any');
|
|
@@ -449,9 +498,7 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
449
498
|
// remains is compared as before. The request direction of HTTP, and socket
|
|
450
499
|
// and pub/sub payloads (the subscriber is `expected`); a GraphQL request is
|
|
451
500
|
// not read this way.
|
|
452
|
-
const absentBodyAllowed = (spec.protocol
|
|
453
|
-
spec.protocol === 'socket' ||
|
|
454
|
-
spec.protocol === 'pubsub';
|
|
501
|
+
const absentBodyAllowed = absentBodyApplies(spec.protocol, spec.type_kind);
|
|
455
502
|
const toleratesAbsence = expectedToleratesAbsence?.(expectedEndpoint) === true;
|
|
456
503
|
const sentBodyType = (sent) => absentBodyRule(sent, 'Expected', toleratesAbsence);
|
|
457
504
|
if (absentBodyAllowed)
|
|
@@ -468,6 +515,9 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
468
515
|
});
|
|
469
516
|
let assignmentLine;
|
|
470
517
|
let wireAssignmentLine;
|
|
518
|
+
let declaredFromLine;
|
|
519
|
+
let declaredAssignmentLine;
|
|
520
|
+
let declaredReadLine;
|
|
471
521
|
if (spec.protocol === 'graphql') {
|
|
472
522
|
// GraphQL selection-set semantics (v1 `unwrapGraphqlPayload` parity): the
|
|
473
523
|
// producer side (always `sent` for graphql — see the direction table) is
|
|
@@ -558,12 +608,22 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
558
608
|
push(`type GqlWire = ${graphqlScalarWireRule('GqlComparand', 'GqlExpected', 'GqlComparandLeaf', '')};`);
|
|
559
609
|
push(`declare const sentWire: GqlWire;`);
|
|
560
610
|
wireAssignmentLine = push(`const expectedWire: GqlExpected = sentWire;`);
|
|
561
|
-
// carrick#
|
|
562
|
-
//
|
|
563
|
-
|
|
611
|
+
// carrick#4726: the declared line (`graphqlDeclaredRule`). Every line
|
|
612
|
+
// sits after the wire line, so no line above it moves. When the wire
|
|
613
|
+
// line fails, this line decides.
|
|
614
|
+
const [firstDeclared, ...restDeclared] = graphqlDeclaredDeclarations('');
|
|
615
|
+
declaredFromLine = push(firstDeclared);
|
|
616
|
+
for (const line of restDeclared)
|
|
564
617
|
push(line);
|
|
565
|
-
push(`type
|
|
566
|
-
|
|
618
|
+
push(`type GqlDeclared = ${graphqlDeclaredRule('GqlWire', 'GqlExpected', 'GqlComparandLeaf', '')};`);
|
|
619
|
+
push(`declare const sentDeclared: GqlDeclared;`);
|
|
620
|
+
declaredAssignmentLine = push(`const expectedDeclared: GqlExpected = sentDeclared;`);
|
|
621
|
+
// The same fill with every key the table could not answer as a type
|
|
622
|
+
// that assigns to nothing the consumer reads: it fails where the line
|
|
623
|
+
// above passed only through such a key.
|
|
624
|
+
push(`type GqlDeclaredRead = ${graphqlDeclaredRule('GqlWire', 'GqlExpected', 'GqlComparandLeaf', '', 'unread')};`);
|
|
625
|
+
push(`declare const sentDeclaredRead: GqlDeclaredRead;`);
|
|
626
|
+
declaredReadLine = push(`const expectedDeclaredRead: GqlExpected = sentDeclaredRead;`);
|
|
567
627
|
}
|
|
568
628
|
}
|
|
569
629
|
else {
|
|
@@ -655,6 +715,9 @@ export function buildProbe(spec, packageOf, unwidenedAliasFor, expectedTolerates
|
|
|
655
715
|
gateLines,
|
|
656
716
|
assignmentLine,
|
|
657
717
|
wireAssignmentLine,
|
|
718
|
+
...(declaredAssignmentLine === undefined
|
|
719
|
+
? {}
|
|
720
|
+
: { declaredFromLine, declaredAssignmentLine, declaredReadLine }),
|
|
658
721
|
...(unwidenedFromLine === undefined ? {} : { unwidenedFromLine }),
|
|
659
722
|
};
|
|
660
723
|
}
|
|
@@ -52,10 +52,10 @@ export type { InternalTypeChecker } from './node-builder.js';
|
|
|
52
52
|
export { toPosix } from './installed-package.js';
|
|
53
53
|
export { constituentsOf } from './result-label.js';
|
|
54
54
|
export { moduleExport } from './anchors.js';
|
|
55
|
-
export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, type DeclaredOutside, } from './site-node.js';
|
|
55
|
+
export { anchorInHandler, callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, type DeclaredOutside, type HandlerLines, } from './site-node.js';
|
|
56
56
|
export { runCheck, judgeTscPath } from './check.js';
|
|
57
57
|
export type { CheckProgress } from './check.js';
|
|
58
|
-
export { graphqlComparandLeafRule, graphqlComparandRule, graphqlExpectedRule,
|
|
58
|
+
export { absentBodyApplies, absentBodyRule, graphqlComparandLeafRule, graphqlComparandRule, graphqlExpectedRule, graphqlDeclaredDeclarations, graphqlDeclaredRule, graphqlGenericDeclarations, graphqlLeafWalkDeclarations, graphqlScalarWireRule, jsonWireDeclarations, jsonWireRule, judgeTolerances, topTypeDeclarations, wireFormFor, type JudgeTolerances, } from './check-probe.js';
|
|
59
59
|
export { fitOptionsOf, judgeFitOptions, type FitOptions } from './check-workspace.js';
|
|
60
60
|
export { nodeByExpressionText, isPreferredTarget } from './anchors.js';
|
|
61
61
|
export { graphqlDeclaresType, graphqlFieldLeaf, graphqlReachableFields, graphqlRootLeaf, graphqlScalarSent, withoutNonNull, } from './graphql-leaves.js';
|
|
@@ -100,3 +100,4 @@ export declare function removeStaleSurfaceEntries(dir: string, guard: WriteGuard
|
|
|
100
100
|
export declare function sanitizeServiceName(name: string): string;
|
|
101
101
|
export declare function captureStub(opts: CaptureStubOptions): CaptureStubResult;
|
|
102
102
|
export { classifyStatusCodes, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
|
|
103
|
+
export { STATUS_MEMBER_NAMES, chainStatus, isDroppedReplyStatus, replyStatus, resultTypeStatusCodes, statedStatusCodes, statusCodesOfType, valueStatus, type ReplyStatus, } from './reply-status.js';
|
|
@@ -75,11 +75,11 @@ export { constituentsOf } from './result-label.js';
|
|
|
75
75
|
export { moduleExport } from './anchors.js';
|
|
76
76
|
// One node locator and one machinery test for the inferrer and the capture
|
|
77
77
|
// (carrick#3500).
|
|
78
|
-
export { callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, } from './site-node.js';
|
|
78
|
+
export { anchorInHandler, callNamedBy, callResultNamesNoCall, isFrameworkMachinery, nodeByLocatorText, normalizeLocatorText, symbolDeclaredOutside, typeIsOrContainsMachinery, wrapsValueTransparently, } from './site-node.js';
|
|
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 { graphqlComparandLeafRule, graphqlComparandRule, graphqlExpectedRule,
|
|
82
|
+
export { absentBodyApplies, absentBodyRule, graphqlComparandLeafRule, graphqlComparandRule, graphqlExpectedRule, graphqlDeclaredDeclarations, graphqlDeclaredRule, graphqlGenericDeclarations, graphqlLeafWalkDeclarations, graphqlScalarWireRule, jsonWireDeclarations, jsonWireRule, judgeTolerances, topTypeDeclarations, wireFormFor, } from './check-probe.js';
|
|
83
83
|
export { fitOptionsOf, judgeFitOptions } from './check-workspace.js';
|
|
84
84
|
export { nodeByExpressionText, isPreferredTarget } from './anchors.js';
|
|
85
85
|
export { graphqlDeclaresType, graphqlFieldLeaf, graphqlReachableFields, graphqlRootLeaf, graphqlScalarSent, withoutNonNull, } from './graphql-leaves.js';
|
|
@@ -236,6 +236,15 @@ export function captureStub(opts) {
|
|
|
236
236
|
const packageName = `@carrick/${sanitizeServiceName(opts.serviceName)}`;
|
|
237
237
|
const stubDir = path.resolve(opts.outDir);
|
|
238
238
|
const errors = [];
|
|
239
|
+
// A cause the driver names is a word of the one list of reasons.
|
|
240
|
+
const unknownCause = opts.anchors.find((anchor) => anchor.kind === 'literal' &&
|
|
241
|
+
anchor.unread_cause !== undefined &&
|
|
242
|
+
!Object.hasOwn(typeReasons, anchor.unread_cause));
|
|
243
|
+
if (unknownCause?.kind === 'literal') {
|
|
244
|
+
return fail(stubDir, packageName, [
|
|
245
|
+
`unread_cause '${unknownCause.unread_cause}' on ${unknownCause.alias} is not a key of type-reasons.json`,
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
239
248
|
// Under CARRICK_UNTRUSTED_TREE every compiler read below is held to the
|
|
240
249
|
// checkout, the sidecar's own install, these stub dirs and a Deno graph's
|
|
241
250
|
// npm packages (`bound`, built once the Deno graph exists); otherwise
|
|
@@ -1346,3 +1355,6 @@ function resolveAnchors(opts, parsed, ctx, deno, owner) {
|
|
|
1346
1355
|
// carrick#1841: the response-table reading the inferrer and the v1 bundle
|
|
1347
1356
|
// share with the capture's symbol anchor.
|
|
1348
1357
|
export { classifyStatusCodes, httpStatus, statesNoBody, statesNoShape, statusKeyCode, statusTableBody, statusTableOf, successEntries, } from './status-table.js';
|
|
1358
|
+
// The one reader of a reply's HTTP status: the inferrer reads
|
|
1359
|
+
// a located reply with it; the capture reads the same module.
|
|
1360
|
+
export { STATUS_MEMBER_NAMES, chainStatus, isDroppedReplyStatus, replyStatus, resultTypeStatusCodes, statedStatusCodes, statusCodesOfType, valueStatus, } from './reply-status.js';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a reply's HTTP status says about its body (carrick#1161), read off the
|
|
3
|
+
* compiler's own API so every path that holds a located reply decides it the
|
|
4
|
+
* same way.
|
|
5
|
+
*
|
|
6
|
+
* `success` (below 300) and `undecided` (no status stated anywhere) send the
|
|
7
|
+
* route's contract; `error` (400 and up) and `redirect` (3xx) do not; and
|
|
8
|
+
* `variable` is a status the source computes, which fails open into the union
|
|
9
|
+
* so no success body is ever guessed away.
|
|
10
|
+
*
|
|
11
|
+
* Inputs are a checker and a node. Nothing here consults a method, a
|
|
12
|
+
* framework or a library name: the status is read from an argument past the
|
|
13
|
+
* body, from an earlier call of the same chain, or from the call's result
|
|
14
|
+
* type. Whether a call IS a reply stays with each caller.
|
|
15
|
+
*/
|
|
16
|
+
import ts from 'typescript';
|
|
17
|
+
export type ReplyStatus = 'success' | 'error' | 'redirect' | 'variable' | 'undecided';
|
|
18
|
+
/**
|
|
19
|
+
* Members an options object uses to state an HTTP status. A >= 400 status marks
|
|
20
|
+
* the branch an error path, whose shape is not the endpoint's contract.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STATUS_MEMBER_NAMES: readonly ["status", "statusCode"];
|
|
23
|
+
/** An error or redirect reply carries no body the route's contract describes. */
|
|
24
|
+
export declare function isDroppedReplyStatus(status: ReplyStatus): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The status codes a TYPE fixes: a numeric literal, or a union made only of
|
|
27
|
+
* them, every one in the HTTP range. `undefined` for anything else, including
|
|
28
|
+
* a plain `number`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function statusCodesOfType(type: ts.Type): number[] | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The HTTP status codes an argument states, `'variable'` when it is a
|
|
33
|
+
* status-shaped value the source does not fix, or `undefined` when it says
|
|
34
|
+
* nothing about a status.
|
|
35
|
+
*
|
|
36
|
+
* Read from the AST first: `{ status: 400 }` in an argument position widens
|
|
37
|
+
* to `{ status: number }`, so the literal only survives syntactically. The
|
|
38
|
+
* type read behind it catches `as const`, hoisted option objects and
|
|
39
|
+
* literal-typed variables. Only values in the HTTP range count: an
|
|
40
|
+
* arbitrary number named `status` on a domain object (`{ status: 2 }`)
|
|
41
|
+
* states nothing about transport.
|
|
42
|
+
*/
|
|
43
|
+
export declare function statedStatusCodes(checker: ts.TypeChecker, node: ts.Node): number[] | 'variable' | undefined;
|
|
44
|
+
/** The status a value states, classified as a send's status argument is. */
|
|
45
|
+
export declare function valueStatus(checker: ts.TypeChecker, value: ts.Node | undefined): ReplyStatus;
|
|
46
|
+
/**
|
|
47
|
+
* The status an earlier call of a send's own chain states: the receiver
|
|
48
|
+
* calls `call` is invoked on (`a.status(401).json(body)` has `a.status(401)`),
|
|
49
|
+
* innermost last. Each receiver call's first argument is read by the rule
|
|
50
|
+
* an argument past a body is, so a numeric literal or a literal-typed value
|
|
51
|
+
* counts and a plain `number` is `variable`. `undefined` when no receiver
|
|
52
|
+
* call states a status. No method name is consulted: a receiver call that
|
|
53
|
+
* is handed no status-shaped value says nothing.
|
|
54
|
+
*/
|
|
55
|
+
export declare function chainStatus(checker: ts.TypeChecker, call: ts.Node): ReplyStatus | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Status codes a send call's result type records: the members (of the result,
|
|
58
|
+
* or of each part of an intersection result) typed as a status literal or a
|
|
59
|
+
* union of them. `undefined` when none is.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resultTypeStatusCodes(checker: ts.TypeChecker, call: ts.Node): number[] | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* What a reply states about its HTTP status (carrick#1161).
|
|
64
|
+
*
|
|
65
|
+
* Read in order, and the first that states anything decides:
|
|
66
|
+
*
|
|
67
|
+
* 1. an argument past the body that carries a status: a numeric literal
|
|
68
|
+
* (`send(body, 404)`), an options object (`{ status: 401 }`), or any
|
|
69
|
+
* expression whose TYPE is a status literal or a union of them
|
|
70
|
+
* (`let code: 400 | 500`). A numeric argument whose type is a plain
|
|
71
|
+
* `number` states a status the source does not fix, which is
|
|
72
|
+
* `variable`: the branch fails open into the union and is logged.
|
|
73
|
+
* 2. the call's own chain, when `readChain` is set (carrick#2005):
|
|
74
|
+
* `reply.status(401).json(body)`.
|
|
75
|
+
* 3. the call's own RESULT type, when a member of it is typed as a status
|
|
76
|
+
* literal. A framework that types its sends records the status there, and
|
|
77
|
+
* a redirect helper's default `302` is only visible there. A result whose
|
|
78
|
+
* status member spans success and error codes (the default of a typed
|
|
79
|
+
* `json(body, status?)`) says nothing either way.
|
|
80
|
+
*
|
|
81
|
+
* A status in the FIRST argument is a field of the body and is never read.
|
|
82
|
+
* No method or framework name is consulted anywhere.
|
|
83
|
+
*/
|
|
84
|
+
export declare function replyStatus(checker: ts.TypeChecker, expression: ts.Node, opts: {
|
|
85
|
+
readChain: boolean;
|
|
86
|
+
}): ReplyStatus;
|