@3sixty/api-server-fastify 0.20.0-next.0 → 0.20.0-next.1

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.
@@ -2,10 +2,9 @@
2
2
 
3
3
  Implementation of the web server using Fastify.
4
4
 
5
- ## Implements
5
+ ## Extends
6
6
 
7
- - `IWebServer`\<`FastifyInstance`\>
8
- - `IHealthProviderComponent`
7
+ - `BaseServer`\<`FastifyInstance`\>
9
8
 
10
9
  ## Constructors
11
10
 
@@ -27,16 +26,607 @@ The options for the server.
27
26
 
28
27
  `FastifyWebServer`
29
28
 
29
+ #### Overrides
30
+
31
+ `BaseServer<FastifyInstance>.constructor`
32
+
30
33
  ## Properties
31
34
 
35
+ ### \_loggingComponentType? {#_loggingcomponenttype}
36
+
37
+ > `protected` `readonly` `optional` **\_loggingComponentType?**: `string`
38
+
39
+ The logging component type.
40
+
41
+ #### Inherited from
42
+
43
+ `BaseServer._loggingComponentType`
44
+
45
+ ***
46
+
47
+ ### \_logging? {#_logging}
48
+
49
+ > `protected` `readonly` `optional` **\_logging?**: `ILoggingComponent`
50
+
51
+ The logging component.
52
+
53
+ #### Inherited from
54
+
55
+ `BaseServer._logging`
56
+
57
+ ***
58
+
59
+ ### \_options? {#_options}
60
+
61
+ > `protected` `optional` **\_options?**: `IWebServerOptions`
62
+
63
+ The options for the server.
64
+
65
+ #### Inherited from
66
+
67
+ `BaseServer._options`
68
+
69
+ ***
70
+
71
+ ### \_started {#_started}
72
+
73
+ > `protected` **\_started**: `boolean`
74
+
75
+ Whether the server has been started.
76
+
77
+ #### Inherited from
78
+
79
+ `BaseServer._started`
80
+
81
+ ***
82
+
83
+ ### \_mimeTypeProcessors {#_mimetypeprocessors}
84
+
85
+ > `protected` `readonly` **\_mimeTypeProcessors**: `IMimeTypeProcessor`[]
86
+
87
+ The mime type processors.
88
+
89
+ #### Inherited from
90
+
91
+ `BaseServer._mimeTypeProcessors`
92
+
93
+ ***
94
+
95
+ ### \_includeErrorStack {#_includeerrorstack}
96
+
97
+ > `protected` `readonly` **\_includeErrorStack**: `boolean`
98
+
99
+ Include the stack with errors.
100
+
101
+ #### Inherited from
102
+
103
+ `BaseServer._includeErrorStack`
104
+
105
+ ***
106
+
107
+ ### \_publicOrigin? {#_publicorigin}
108
+
109
+ > `protected` `optional` **\_publicOrigin?**: `string`
110
+
111
+ The public origin of the server, used for constructing the request URL and for CORS.
112
+
113
+ #### Inherited from
114
+
115
+ `BaseServer._publicOrigin`
116
+
117
+ ***
118
+
119
+ ### \_localOrigin? {#_localorigin}
120
+
121
+ > `protected` `optional` **\_localOrigin?**: `string`
122
+
123
+ The local origin of the server, used for constructing the request URL and for CORS.
124
+
125
+ #### Inherited from
126
+
127
+ `BaseServer._localOrigin`
128
+
129
+ ***
130
+
131
+ ### \_restChains {#_restchains}
132
+
133
+ > `protected` **\_restChains**: `IRestProcessorChains`
134
+
135
+ The REST processor chains resolved when the server is built.
136
+
137
+ #### Inherited from
138
+
139
+ `BaseServer._restChains`
140
+
141
+ ***
142
+
143
+ ### \_socketChains {#_socketchains}
144
+
145
+ > `protected` **\_socketChains**: `ISocketProcessorChains`
146
+
147
+ The socket processor chains resolved when the server is built.
148
+
149
+ #### Inherited from
150
+
151
+ `BaseServer._socketChains`
152
+
153
+ ***
154
+
32
155
  ### CLASS\_NAME {#class_name}
33
156
 
34
157
  > `readonly` `static` **CLASS\_NAME**: `string`
35
158
 
36
159
  Runtime name for the class.
37
160
 
161
+ #### Overrides
162
+
163
+ `BaseServer.CLASS_NAME`
164
+
38
165
  ## Methods
39
166
 
167
+ ### start() {#start}
168
+
169
+ > **start**(): `Promise`\<`void`\>
170
+
171
+ Start the server.
172
+
173
+ #### Returns
174
+
175
+ `Promise`\<`void`\>
176
+
177
+ A promise that resolves when the server is listening for connections.
178
+
179
+ #### Inherited from
180
+
181
+ `BaseServer.start`
182
+
183
+ ***
184
+
185
+ ### stop() {#stop}
186
+
187
+ > **stop**(): `Promise`\<`void`\>
188
+
189
+ Stop the server.
190
+
191
+ #### Returns
192
+
193
+ `Promise`\<`void`\>
194
+
195
+ A promise that resolves when the server has shut down all connections.
196
+
197
+ #### Inherited from
198
+
199
+ `BaseServer.stop`
200
+
201
+ ***
202
+
203
+ ### health() {#health}
204
+
205
+ > **health**(): `Promise`\<`IHealth`[]\>
206
+
207
+ Returns the health status of the component.
208
+
209
+ #### Returns
210
+
211
+ `Promise`\<`IHealth`[]\>
212
+
213
+ The health status of the component, can return multiple entries for elements within the component.
214
+
215
+ #### Inherited from
216
+
217
+ `BaseServer.health`
218
+
219
+ ***
220
+
221
+ ### healthApplication() {#healthapplication}
222
+
223
+ > **healthApplication**(`callback`): `Promise`\<`IHealth`[] \| `undefined`\>
224
+
225
+ Verify the root endpoint is reachable and returns a body by making a real HTTP request.
226
+ Skipped when GET / is not registered on this server instance.
227
+
228
+ #### Parameters
229
+
230
+ ##### callback
231
+
232
+ `HealthApplicationCallback`
233
+
234
+ The callback to invoke when a deferred health result is ready.
235
+
236
+ #### Returns
237
+
238
+ `Promise`\<`IHealth`[] \| `undefined`\>
239
+
240
+ The application health status of the component.
241
+
242
+ #### Inherited from
243
+
244
+ `BaseServer.healthApplication`
245
+
246
+ ***
247
+
248
+ ### requestLocalRoot() {#requestlocalroot}
249
+
250
+ > `protected` **requestLocalRoot**(`url`): `Promise`\<\{ `ok`: `boolean`; `body`: `string`; \}\>
251
+
252
+ Request the root endpoint of this server over the loopback address.
253
+
254
+ #### Parameters
255
+
256
+ ##### url
257
+
258
+ `string`
259
+
260
+ The url of the root endpoint.
261
+
262
+ #### Returns
263
+
264
+ `Promise`\<\{ `ok`: `boolean`; `body`: `string`; \}\>
265
+
266
+ Whether the response was successful and its body.
267
+
268
+ #### Inherited from
269
+
270
+ `BaseServer.requestLocalRoot`
271
+
272
+ ***
273
+
274
+ ### prepareBuild() {#preparebuild}
275
+
276
+ > `protected` **prepareBuild**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
277
+
278
+ Perform the transport agnostic part of building the server, validating the routes and
279
+ processors, resolving the origins and resolving the processor chains.
280
+
281
+ #### Parameters
282
+
283
+ ##### restRouteProcessors?
284
+
285
+ `IRestRouteProcessor`[]
286
+
287
+ The processors for incoming requests over REST.
288
+
289
+ ##### restRoutes?
290
+
291
+ `IRestRoute`\<`any`, `any`\>[]
292
+
293
+ The REST routes.
294
+
295
+ ##### socketRouteProcessors?
296
+
297
+ `ISocketRouteProcessor`[]
298
+
299
+ The processors for incoming requests over Sockets.
300
+
301
+ ##### socketRoutes?
302
+
303
+ `ISocketRoute`\<`any`, `any`\>[]
304
+
305
+ The socket routes.
306
+
307
+ ##### options?
308
+
309
+ `IWebServerOptions`
310
+
311
+ Options for building the server.
312
+
313
+ #### Returns
314
+
315
+ `Promise`\<`void`\>
316
+
317
+ A promise that resolves when the shared build steps are complete.
318
+
319
+ #### Inherited from
320
+
321
+ `BaseServer.prepareBuild`
322
+
323
+ ***
324
+
325
+ ### buildProcessorChains() {#buildprocessorchains}
326
+
327
+ > `protected` **buildProcessorChains**(`restRouteProcessors?`, `socketRouteProcessors?`): `void`
328
+
329
+ Resolve the route processors in to per phase chains, so that the lookups and bindings
330
+ are performed once when the server is built instead of on every request.
331
+
332
+ #### Parameters
333
+
334
+ ##### restRouteProcessors?
335
+
336
+ `IRestRouteProcessor`[]
337
+
338
+ The processors for the incoming REST requests.
339
+
340
+ ##### socketRouteProcessors?
341
+
342
+ `ISocketRouteProcessor`[]
343
+
344
+ The processors for the incoming socket requests.
345
+
346
+ #### Returns
347
+
348
+ `void`
349
+
350
+ #### Inherited from
351
+
352
+ `BaseServer.buildProcessorChains`
353
+
354
+ ***
355
+
356
+ ### resolveBodyLimits() {#resolvebodylimits}
357
+
358
+ > `protected` **resolveBodyLimits**(): `object`
359
+
360
+ Merge the configured body limits over the built-in ones and validate them.
361
+
362
+ #### Returns
363
+
364
+ `object`
365
+
366
+ The named body limits in bytes.
367
+
368
+ #### Throws
369
+
370
+ GeneralError If a limit is not a positive integer.
371
+
372
+ #### Inherited from
373
+
374
+ `BaseServer.resolveBodyLimits`
375
+
376
+ ***
377
+
378
+ ### resolveCorsOptions() {#resolvecorsoptions}
379
+
380
+ > `protected` **resolveCorsOptions**(`options?`): `IServerCorsOptions`
381
+
382
+ Resolve the CORS options from the web server options, merging in the defaults.
383
+
384
+ #### Parameters
385
+
386
+ ##### options?
387
+
388
+ `IWebServerOptions`
389
+
390
+ The web server options.
391
+
392
+ #### Returns
393
+
394
+ `IServerCorsOptions`
395
+
396
+ The resolved CORS options.
397
+
398
+ #### Inherited from
399
+
400
+ `BaseServer.resolveCorsOptions`
401
+
402
+ ***
403
+
404
+ ### buildServerRequest() {#buildserverrequest}
405
+
406
+ > `protected` **buildServerRequest**(`method`, `url`, `body`, `query?`, `pathParams?`, `headers?`): `IHttpServerRequest`
407
+
408
+ Build the server request from the transport values, the path params and query must already
409
+ have been decoded by the transport, as decoding them again corrupts values containing %.
410
+
411
+ #### Parameters
412
+
413
+ ##### method
414
+
415
+ `HttpMethod`
416
+
417
+ The request method.
418
+
419
+ ##### url
420
+
421
+ `string`
422
+
423
+ The full request url, including the origin.
424
+
425
+ ##### body
426
+
427
+ `unknown`
428
+
429
+ The request body.
430
+
431
+ ##### query?
432
+
433
+ `IHttpRequestQuery`
434
+
435
+ The request query params.
436
+
437
+ ##### pathParams?
438
+
439
+ `IHttpRequestPathParams`
440
+
441
+ The request path params.
442
+
443
+ ##### headers?
444
+
445
+ `IHttpHeaders`
446
+
447
+ The request headers.
448
+
449
+ #### Returns
450
+
451
+ `IHttpServerRequest`
452
+
453
+ The server request.
454
+
455
+ #### Inherited from
456
+
457
+ `BaseServer.buildServerRequest`
458
+
459
+ ***
460
+
461
+ ### validateResponse() {#validateresponse}
462
+
463
+ > `protected` **validateResponse**(`httpResponse`): `void`
464
+
465
+ Validate the processed response before it is sent, so that every transport fails an invalid
466
+ response in the same way rather than with its own transport specific error.
467
+
468
+ #### Parameters
469
+
470
+ ##### httpResponse
471
+
472
+ `IHttpResponse`
473
+
474
+ The processed response.
475
+
476
+ #### Returns
477
+
478
+ `void`
479
+
480
+ #### Throws
481
+
482
+ GeneralError If the status code or a header is invalid.
483
+
484
+ #### Inherited from
485
+
486
+ `BaseServer.validateResponse`
487
+
488
+ ***
489
+
490
+ ### buildContextIds() {#buildcontextids}
491
+
492
+ > `protected` **buildContextIds**(`requestOrigin`, `headers?`): `IContextIds`
493
+
494
+ Build the context ids for an incoming request.
495
+
496
+ #### Parameters
497
+
498
+ ##### requestOrigin
499
+
500
+ `string`
501
+
502
+ The origin the request was received on.
503
+
504
+ ##### headers?
505
+
506
+ `IHttpHeaders`
507
+
508
+ The request headers.
509
+
510
+ #### Returns
511
+
512
+ `IContextIds`
513
+
514
+ The context ids.
515
+
516
+ #### Inherited from
517
+
518
+ `BaseServer.buildContextIds`
519
+
520
+ ***
521
+
522
+ ### runProcessorsRest() {#runprocessorsrest}
523
+
524
+ > `protected` **runProcessorsRest**(`restRoute`, `httpServerRequest`, `httpResponse`, `contextIds`, `processorState`): `Promise`\<`void`\>
525
+
526
+ Run the REST processors for the route.
527
+
528
+ #### Parameters
529
+
530
+ ##### restRoute
531
+
532
+ `IRestRoute`\<`any`, `any`\> \| `undefined`
533
+
534
+ The route to process.
535
+
536
+ ##### httpServerRequest
537
+
538
+ `IHttpServerRequest`
539
+
540
+ The incoming request.
541
+
542
+ ##### httpResponse
543
+
544
+ `IHttpResponse`
545
+
546
+ The outgoing response.
547
+
548
+ ##### contextIds
549
+
550
+ `IContextIds`
551
+
552
+ The context IDs of the request.
553
+
554
+ ##### processorState
555
+
556
+ \{\[`id`: `string`\]: `unknown`; \}
557
+
558
+ The state handed through the processors.
559
+
560
+ #### Returns
561
+
562
+ `Promise`\<`void`\>
563
+
564
+ #### Inherited from
565
+
566
+ `BaseServer.runProcessorsRest`
567
+
568
+ ***
569
+
570
+ ### runProcessorsSocket() {#runprocessorssocket}
571
+
572
+ > `protected` **runProcessorsSocket**(`socketRoute`, `socketServerRequest`, `httpResponse`, `contextIds`, `processorState`, `requestTopic`, `responseEmitter`): `Promise`\<`void`\>
573
+
574
+ Run the socket processors for the route.
575
+
576
+ #### Parameters
577
+
578
+ ##### socketRoute
579
+
580
+ `ISocketRoute`
581
+
582
+ The route to process.
583
+
584
+ ##### socketServerRequest
585
+
586
+ `ISocketServerRequest`
587
+
588
+ The incoming request.
589
+
590
+ ##### httpResponse
591
+
592
+ `IHttpResponse`
593
+
594
+ The outgoing response.
595
+
596
+ ##### contextIds
597
+
598
+ `IContextIds`
599
+
600
+ The context IDs of the request.
601
+
602
+ ##### processorState
603
+
604
+ \{\[`id`: `string`\]: `unknown`; \}
605
+
606
+ The state handed through the processors.
607
+
608
+ ##### requestTopic
609
+
610
+ `string`
611
+
612
+ The topic of the request.
613
+
614
+ ##### responseEmitter
615
+
616
+ (`topic`, `response`) => `Promise`\<`void`\>
617
+
618
+ The emitter to send the response on.
619
+
620
+ #### Returns
621
+
622
+ `Promise`\<`void`\>
623
+
624
+ #### Inherited from
625
+
626
+ `BaseServer.runProcessorsSocket`
627
+
628
+ ***
629
+
40
630
  ### className() {#classname}
41
631
 
42
632
  > **className**(): `string`
@@ -49,9 +639,9 @@ Returns the class name of the component.
49
639
 
50
640
  The class name of the component.
51
641
 
52
- #### Implementation of
642
+ #### Overrides
53
643
 
54
- `IWebServer.className`
644
+ `BaseServer.className`
55
645
 
56
646
  ***
57
647
 
@@ -67,9 +657,9 @@ Get the web server instance.
67
657
 
68
658
  The web server instance.
69
659
 
70
- #### Implementation of
660
+ #### Overrides
71
661
 
72
- `IWebServer.getInstance`
662
+ `BaseServer.getInstance`
73
663
 
74
664
  ***
75
665
 
@@ -117,87 +707,128 @@ Options for building the server.
117
707
 
118
708
  A promise that resolves when the server is fully built and ready to start.
119
709
 
120
- #### Implementation of
710
+ #### Overrides
121
711
 
122
- `IWebServer.build`
712
+ `BaseServer.build`
123
713
 
124
714
  ***
125
715
 
126
- ### start() {#start}
716
+ ### serverListen() {#serverlisten}
127
717
 
128
- > **start**(): `Promise`\<`void`\>
718
+ > `protected` **serverListen**(`host`, `port`): `Promise`\<`void`\>
129
719
 
130
- Start the server.
720
+ Start listening for connections on the transport.
721
+
722
+ #### Parameters
723
+
724
+ ##### host
725
+
726
+ `string`
727
+
728
+ The host to bind to.
729
+
730
+ ##### port
731
+
732
+ `number`
733
+
734
+ The port to bind to.
131
735
 
132
736
  #### Returns
133
737
 
134
738
  `Promise`\<`void`\>
135
739
 
136
- A promise that resolves when the server is listening for connections.
740
+ A promise that resolves when the transport is listening.
137
741
 
138
- #### Implementation of
742
+ #### Overrides
139
743
 
140
- `IWebServer.start`
744
+ `BaseServer.serverListen`
141
745
 
142
746
  ***
143
747
 
144
- ### stop() {#stop}
748
+ ### serverClose() {#serverclose}
145
749
 
146
- > **stop**(): `Promise`\<`void`\>
750
+ > `protected` **serverClose**(): `Promise`\<`void`\>
147
751
 
148
- Stop the server.
752
+ Close the transport and all of its connections.
149
753
 
150
754
  #### Returns
151
755
 
152
756
  `Promise`\<`void`\>
153
757
 
154
- A promise that resolves when the server has shut down all connections.
758
+ A promise that resolves when the transport has closed.
155
759
 
156
- #### Implementation of
760
+ #### Overrides
157
761
 
158
- `IWebServer.stop`
762
+ `BaseServer.serverClose`
159
763
 
160
764
  ***
161
765
 
162
- ### health() {#health}
766
+ ### serverAddresses() {#serveraddresses}
163
767
 
164
- > **health**(): `Promise`\<`IHealth`[]\>
768
+ > `protected` **serverAddresses**(): `object`[]
165
769
 
166
- Returns the health status of the component.
770
+ Get the addresses the transport is bound to.
167
771
 
168
772
  #### Returns
169
773
 
170
- `Promise`\<`IHealth`[]\>
774
+ `object`[]
171
775
 
172
- The health status of the component, can return multiple entries for elements within the component.
776
+ The bound addresses.
173
777
 
174
- #### Implementation of
778
+ #### Overrides
175
779
 
176
- `IHealthProviderComponent.health`
780
+ `BaseServer.serverAddresses`
177
781
 
178
782
  ***
179
783
 
180
- ### healthApplication() {#healthapplication}
784
+ ### serverIsSecure() {#serverissecure}
181
785
 
182
- > **healthApplication**(`callback`): `Promise`\<`IHealth`[] \| `undefined`\>
786
+ > `protected` **serverIsSecure**(): `boolean`
183
787
 
184
- Verify the root endpoint is reachable and returns a body by making a real HTTP request.
185
- Skipped when GET / is not registered on this server instance.
788
+ Whether the transport is serving over TLS.
186
789
 
187
- #### Parameters
790
+ #### Returns
188
791
 
189
- ##### callback
792
+ `boolean`
190
793
 
191
- `HealthApplicationCallback`
794
+ True if the transport is secure.
192
795
 
193
- The callback to invoke when a deferred health result is ready.
796
+ #### Overrides
797
+
798
+ `BaseServer.serverIsSecure`
799
+
800
+ ***
801
+
802
+ ### serverIsListening() {#serverislistening}
803
+
804
+ > `protected` **serverIsListening**(): `boolean`
805
+
806
+ Whether the transport is currently listening for connections.
194
807
 
195
808
  #### Returns
196
809
 
197
- `Promise`\<`IHealth`[] \| `undefined`\>
810
+ `boolean`
198
811
 
199
- The application health status of the component.
812
+ True if the transport is listening.
813
+
814
+ #### Overrides
815
+
816
+ `BaseServer.serverIsListening`
817
+
818
+ ***
819
+
820
+ ### serverHasRootRoute() {#serverhasrootroute}
821
+
822
+ > `protected` **serverHasRootRoute**(): `boolean`
823
+
824
+ Whether a GET route is registered for the root path.
825
+
826
+ #### Returns
827
+
828
+ `boolean`
829
+
830
+ True if the root route is registered.
200
831
 
201
- #### Implementation of
832
+ #### Overrides
202
833
 
203
- `IHealthProviderComponent.healthApplication`
834
+ `BaseServer.serverHasRootRoute`