@@ -44,16 +44,23 @@ import {
44
44
/*
45
45
This file defines request step *definitions*, which includes everything necessary to define
46
46
and serialize their behaviour, but doesn't include the actual handling logic (which
47
- lives in ./request-steps instead). This is intended to allow tree-shaking in browser usage
48
- or remote clients to import only the necessary code, with no need to include all the real
49
- request-processing and handling code that is only used at HTTP-runtime, so isn't relevant when
50
- defining rules.
47
+ lives in the Impl classes in ./request-steps instead). This is intended to allow tree-shaking
48
+ in browser usage or remote clients, importing only the necessary code, with no need to include
49
+ all the real request-processing and handling code that is only used at HTTP-runtime, so isn't
50
+ relevant when defining rules.
51
51
52
- Every RequestStep extends its definition, simply adding a handle() method, which handles
52
+ Every RequestStepImpl extends its definition, simply adding a handle() method, which handles
53
53
requests according to the configuration, and adding a deserialize static method that takes
54
54
the serialized output from the serialize() methods defined here and creates a working step.
55
55
*/
56
56
57
+ /**
58
+ * The definition of a request rule step, which can be passed to Mockttp to define
59
+ * a rule.
60
+ *
61
+ * Implementation of the step is not included in the definition classes, but
62
+ * instead exists in an *Impl class defined separately and used internally.
63
+ */
57
64
export interface RequestStepDefinition extends Explainable , Serializable {
58
65
type : keyof typeof StepDefinitionLookup ;
59
66
}
@@ -251,7 +258,7 @@ function validateCustomHeaders(
251
258
}
252
259
}
253
260
254
- export class FixedResponseStepDefinition extends Serializable implements RequestStepDefinition {
261
+ export class FixedResponseStep extends Serializable implements RequestStepDefinition {
255
262
256
263
readonly type = 'simple' ;
257
264
static readonly isFinal = true ;
@@ -301,7 +308,7 @@ export interface CallbackRequestMessage {
301
308
args : [ Replace < CompletedRequest , { body : SerializedBody } > ] ;
302
309
}
303
310
304
- export class CallbackStepDefinition extends Serializable implements RequestStepDefinition {
311
+ export class CallbackStep extends Serializable implements RequestStepDefinition {
305
312
306
313
readonly type = 'callback' ;
307
314
static readonly isFinal = true ;
@@ -359,7 +366,7 @@ type StreamStepEventMessage =
359
366
{ type : 'arraybuffer' , value : string } |
360
367
{ type : 'nil' } ;
361
368
362
- export class StreamStepDefinition extends Serializable implements RequestStepDefinition {
369
+ export class StreamStep extends Serializable implements RequestStepDefinition {
363
370
364
371
readonly type = 'stream' ;
365
372
static readonly isFinal = true ;
@@ -421,7 +428,7 @@ export class StreamStepDefinition extends Serializable implements RequestStepDef
421
428
}
422
429
}
423
430
424
- export class FileStepDefinition extends Serializable implements RequestStepDefinition {
431
+ export class FileStep extends Serializable implements RequestStepDefinition {
425
432
426
433
readonly type = 'file' ;
427
434
static readonly isFinal = true ;
@@ -722,7 +729,7 @@ export interface BeforePassthroughResponseRequest {
722
729
*/
723
730
export const SERIALIZED_OMIT = "__mockttp__transform__omit__" ;
724
731
725
- export class PassThroughStepDefinition extends Serializable implements RequestStepDefinition {
732
+ export class PassThroughStep extends Serializable implements RequestStepDefinition {
726
733
727
734
readonly type = 'passthrough' ;
728
735
static readonly isFinal = true ;
@@ -988,7 +995,7 @@ export class PassThroughStepDefinition extends Serializable implements RequestSt
988
995
}
989
996
}
990
997
991
- export class CloseConnectionStepDefinition extends Serializable implements RequestStepDefinition {
998
+ export class CloseConnectionStep extends Serializable implements RequestStepDefinition {
992
999
readonly type = 'close-connection' ;
993
1000
static readonly isFinal = true ;
994
1001
@@ -997,7 +1004,7 @@ export class CloseConnectionStepDefinition extends Serializable implements Reque
997
1004
}
998
1005
}
999
1006
1000
- export class ResetConnectionStepDefinition extends Serializable implements RequestStepDefinition {
1007
+ export class ResetConnectionStep extends Serializable implements RequestStepDefinition {
1001
1008
readonly type = 'reset-connection' ;
1002
1009
static readonly isFinal = true ;
1003
1010
@@ -1006,7 +1013,7 @@ export class ResetConnectionStepDefinition extends Serializable implements Reque
1006
1013
}
1007
1014
}
1008
1015
1009
- export class TimeoutStepDefinition extends Serializable implements RequestStepDefinition {
1016
+ export class TimeoutStep extends Serializable implements RequestStepDefinition {
1010
1017
readonly type = 'timeout' ;
1011
1018
static readonly isFinal = true ;
1012
1019
@@ -1015,7 +1022,7 @@ export class TimeoutStepDefinition extends Serializable implements RequestStepDe
1015
1022
}
1016
1023
}
1017
1024
1018
- export class JsonRpcResponseStepDefinition extends Serializable implements RequestStepDefinition {
1025
+ export class JsonRpcResponseStep extends Serializable implements RequestStepDefinition {
1019
1026
readonly type = 'json-rpc-response' ;
1020
1027
static readonly isFinal = true ;
1021
1028
@@ -1040,7 +1047,7 @@ export class JsonRpcResponseStepDefinition extends Serializable implements Reque
1040
1047
}
1041
1048
}
1042
1049
1043
- export class DelayStepDefinition extends Serializable implements RequestStepDefinition {
1050
+ export class DelayStep extends Serializable implements RequestStepDefinition {
1044
1051
1045
1052
readonly type = 'delay' ;
1046
1053
static readonly isFinal = false ;
@@ -1058,14 +1065,14 @@ export class DelayStepDefinition extends Serializable implements RequestStepDefi
1058
1065
}
1059
1066
1060
1067
export const StepDefinitionLookup = {
1061
- 'simple' : FixedResponseStepDefinition ,
1062
- 'callback' : CallbackStepDefinition ,
1063
- 'stream' : StreamStepDefinition ,
1064
- 'file' : FileStepDefinition ,
1065
- 'passthrough' : PassThroughStepDefinition ,
1066
- 'close-connection' : CloseConnectionStepDefinition ,
1067
- 'reset-connection' : ResetConnectionStepDefinition ,
1068
- 'timeout' : TimeoutStepDefinition ,
1069
- 'json-rpc-response' : JsonRpcResponseStepDefinition ,
1070
- 'delay' : DelayStepDefinition
1068
+ 'simple' : FixedResponseStep ,
1069
+ 'callback' : CallbackStep ,
1070
+ 'stream' : StreamStep ,
1071
+ 'file' : FileStep ,
1072
+ 'passthrough' : PassThroughStep ,
1073
+ 'close-connection' : CloseConnectionStep ,
1074
+ 'reset-connection' : ResetConnectionStep ,
1075
+ 'timeout' : TimeoutStep ,
1076
+ 'json-rpc-response' : JsonRpcResponseStep ,
1077
+ 'delay' : DelayStep
1071
1078
}
0 commit comments