@@ -44,16 +44,23 @@ import {
4444/*
4545This file defines request step *definitions*, which includes everything necessary to define
4646and 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.
5151
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
5353requests according to the configuration, and adding a deserialize static method that takes
5454the serialized output from the serialize() methods defined here and creates a working step.
5555*/
5656
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+ */
5764export interface RequestStepDefinition extends Explainable , Serializable {
5865 type : keyof typeof StepDefinitionLookup ;
5966}
@@ -251,7 +258,7 @@ function validateCustomHeaders(
251258 }
252259}
253260
254- export class FixedResponseStepDefinition extends Serializable implements RequestStepDefinition {
261+ export class FixedResponseStep extends Serializable implements RequestStepDefinition {
255262
256263 readonly type = 'simple' ;
257264 static readonly isFinal = true ;
@@ -301,7 +308,7 @@ export interface CallbackRequestMessage {
301308 args : [ Replace < CompletedRequest , { body : SerializedBody } > ] ;
302309}
303310
304- export class CallbackStepDefinition extends Serializable implements RequestStepDefinition {
311+ export class CallbackStep extends Serializable implements RequestStepDefinition {
305312
306313 readonly type = 'callback' ;
307314 static readonly isFinal = true ;
@@ -359,7 +366,7 @@ type StreamStepEventMessage =
359366 { type : 'arraybuffer' , value : string } |
360367 { type : 'nil' } ;
361368
362- export class StreamStepDefinition extends Serializable implements RequestStepDefinition {
369+ export class StreamStep extends Serializable implements RequestStepDefinition {
363370
364371 readonly type = 'stream' ;
365372 static readonly isFinal = true ;
@@ -421,7 +428,7 @@ export class StreamStepDefinition extends Serializable implements RequestStepDef
421428 }
422429}
423430
424- export class FileStepDefinition extends Serializable implements RequestStepDefinition {
431+ export class FileStep extends Serializable implements RequestStepDefinition {
425432
426433 readonly type = 'file' ;
427434 static readonly isFinal = true ;
@@ -722,7 +729,7 @@ export interface BeforePassthroughResponseRequest {
722729 */
723730export const SERIALIZED_OMIT = "__mockttp__transform__omit__" ;
724731
725- export class PassThroughStepDefinition extends Serializable implements RequestStepDefinition {
732+ export class PassThroughStep extends Serializable implements RequestStepDefinition {
726733
727734 readonly type = 'passthrough' ;
728735 static readonly isFinal = true ;
@@ -988,7 +995,7 @@ export class PassThroughStepDefinition extends Serializable implements RequestSt
988995 }
989996}
990997
991- export class CloseConnectionStepDefinition extends Serializable implements RequestStepDefinition {
998+ export class CloseConnectionStep extends Serializable implements RequestStepDefinition {
992999 readonly type = 'close-connection' ;
9931000 static readonly isFinal = true ;
9941001
@@ -997,7 +1004,7 @@ export class CloseConnectionStepDefinition extends Serializable implements Reque
9971004 }
9981005}
9991006
1000- export class ResetConnectionStepDefinition extends Serializable implements RequestStepDefinition {
1007+ export class ResetConnectionStep extends Serializable implements RequestStepDefinition {
10011008 readonly type = 'reset-connection' ;
10021009 static readonly isFinal = true ;
10031010
@@ -1006,7 +1013,7 @@ export class ResetConnectionStepDefinition extends Serializable implements Reque
10061013 }
10071014}
10081015
1009- export class TimeoutStepDefinition extends Serializable implements RequestStepDefinition {
1016+ export class TimeoutStep extends Serializable implements RequestStepDefinition {
10101017 readonly type = 'timeout' ;
10111018 static readonly isFinal = true ;
10121019
@@ -1015,7 +1022,7 @@ export class TimeoutStepDefinition extends Serializable implements RequestStepDe
10151022 }
10161023}
10171024
1018- export class JsonRpcResponseStepDefinition extends Serializable implements RequestStepDefinition {
1025+ export class JsonRpcResponseStep extends Serializable implements RequestStepDefinition {
10191026 readonly type = 'json-rpc-response' ;
10201027 static readonly isFinal = true ;
10211028
@@ -1040,7 +1047,7 @@ export class JsonRpcResponseStepDefinition extends Serializable implements Reque
10401047 }
10411048}
10421049
1043- export class DelayStepDefinition extends Serializable implements RequestStepDefinition {
1050+ export class DelayStep extends Serializable implements RequestStepDefinition {
10441051
10451052 readonly type = 'delay' ;
10461053 static readonly isFinal = false ;
@@ -1058,14 +1065,14 @@ export class DelayStepDefinition extends Serializable implements RequestStepDefi
10581065}
10591066
10601067export 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
10711078}
0 commit comments