@xylabs/express 5.0.80 → 5.0.82

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.
Files changed (65) hide show
  1. package/README.md +229 -55
  2. package/package.json +10 -14
  3. package/src/Handler/RouteDefinition/RouteDefinition.ts +0 -18
  4. package/src/Handler/RouteDefinition/addRouteDefinitions.ts +0 -9
  5. package/src/Handler/RouteDefinition/index.ts +0 -2
  6. package/src/Handler/StatusCodeHandlers/index.ts +0 -1
  7. package/src/Handler/StatusCodeHandlers/notImplemented.ts +0 -6
  8. package/src/Handler/asyncHandler.ts +0 -21
  9. package/src/Handler/errorToJsonHandler.ts +0 -16
  10. package/src/Handler/index.ts +0 -4
  11. package/src/HttpUtil/getHttpHeader.ts +0 -27
  12. package/src/HttpUtil/index.ts +0 -1
  13. package/src/Logger/LogFormats/LocalDev/index.ts +0 -1
  14. package/src/Logger/LogFormats/LocalDev/logFormatLocalDev.ts +0 -11
  15. package/src/Logger/LogFormats/Rollbar/index.ts +0 -1
  16. package/src/Logger/LogFormats/Rollbar/logFormatRollbar.ts +0 -5
  17. package/src/Logger/LogFormats/Structured/index.ts +0 -1
  18. package/src/Logger/LogFormats/Structured/logFormatStructured.ts +0 -7
  19. package/src/Logger/LogFormats/index.ts +0 -3
  20. package/src/Logger/LoggerMeta.ts +0 -1
  21. package/src/Logger/LoggerOptions.ts +0 -7
  22. package/src/Logger/LoggerVerbosity.ts +0 -1
  23. package/src/Logger/Transports/Rollbar/RollbarTransport.ts +0 -24
  24. package/src/Logger/Transports/Rollbar/canGetDefaultRollbarTransport.ts +0 -3
  25. package/src/Logger/Transports/Rollbar/getDefaultRollbarTransport.ts +0 -10
  26. package/src/Logger/Transports/Rollbar/index.ts +0 -3
  27. package/src/Logger/Transports/index.ts +0 -1
  28. package/src/Logger/WinstonVerbosity.ts +0 -5
  29. package/src/Logger/WrappedWinstonLogger.ts +0 -20
  30. package/src/Logger/getDefaultLogger.ts +0 -21
  31. package/src/Logger/getLogger.ts +0 -55
  32. package/src/Logger/index.ts +0 -13
  33. package/src/Logger/toWinstonVerbosity.ts +0 -6
  34. package/src/Model/ExpressError.ts +0 -3
  35. package/src/Model/index.ts +0 -1
  36. package/src/Performance/Counters.ts +0 -36
  37. package/src/Performance/Profiler.ts +0 -10
  38. package/src/Performance/index.ts +0 -2
  39. package/src/Util/compactObject.ts +0 -9
  40. package/src/Util/index.ts +0 -2
  41. package/src/Util/tryParse.ts +0 -17
  42. package/src/Validation/index.ts +0 -1
  43. package/src/Validation/requestHandlerValidator.ts +0 -120
  44. package/src/index.ts +0 -8
  45. package/src/middleware/caseInsensitiveRouting/caseInsensitiveRouting.ts +0 -21
  46. package/src/middleware/caseInsensitiveRouting/index.ts +0 -1
  47. package/src/middleware/customPoweredByHeader/customPoweredByHeader.ts +0 -29
  48. package/src/middleware/customPoweredByHeader/index.ts +0 -1
  49. package/src/middleware/index.ts +0 -5
  50. package/src/middleware/jsonBodyParser/index.ts +0 -1
  51. package/src/middleware/jsonBodyParser/jsonBodyParser.ts +0 -59
  52. package/src/middleware/metrics/counters.ts +0 -25
  53. package/src/middleware/metrics/index.ts +0 -2
  54. package/src/middleware/metrics/responseProfiler.ts +0 -23
  55. package/src/middleware/standardResponses/getResponseMetadata.ts +0 -18
  56. package/src/middleware/standardResponses/index.ts +0 -4
  57. package/src/middleware/standardResponses/jsonApi/README.md +0 -4
  58. package/src/middleware/standardResponses/jsonApi/error.ts +0 -52
  59. package/src/middleware/standardResponses/jsonApi/index.ts +0 -5
  60. package/src/middleware/standardResponses/jsonApi/links.ts +0 -6
  61. package/src/middleware/standardResponses/jsonApi/relationship.ts +0 -43
  62. package/src/middleware/standardResponses/jsonApi/resourceIdentifier.ts +0 -15
  63. package/src/middleware/standardResponses/jsonApi/response.ts +0 -49
  64. package/src/middleware/standardResponses/standardErrors.ts +0 -27
  65. package/src/middleware/standardResponses/standardResponses.ts +0 -61
package/README.md CHANGED
@@ -29,6 +29,7 @@ SDK for base code for Api repos that use express and deploy on AWS ECS
29
29
 
30
30
  ## Interfaces
31
31
 
32
+ - [RouteDefinition](#interfaces/RouteDefinition)
32
33
  - [Empty](#interfaces/Empty)
33
34
  - [LoggerOptions](#interfaces/LoggerOptions)
34
35
  - [ExpressError](#interfaces/ExpressError)
@@ -48,6 +49,7 @@ SDK for base code for Api repos that use express and deploy on AWS ECS
48
49
 
49
50
  ## Type Aliases
50
51
 
52
+ - [HttpMethod](#type-aliases/HttpMethod)
51
53
  - [NoReqParams](#type-aliases/NoReqParams)
52
54
  - [NoResBody](#type-aliases/NoResBody)
53
55
  - [NoReqBody](#type-aliases/NoReqBody)
@@ -68,6 +70,9 @@ SDK for base code for Api repos that use express and deploy on AWS ECS
68
70
  ## Variables
69
71
 
70
72
  - [notImplemented](#variables/notImplemented)
73
+ - [EmptyParamsZod](#variables/EmptyParamsZod)
74
+ - [EmptyQueryParamsZod](#variables/EmptyQueryParamsZod)
75
+ - [ValidateRequestDefaults](#variables/ValidateRequestDefaults)
71
76
  - [DefaultJsonBodyParserOptionsLimit](#variables/DefaultJsonBodyParserOptionsLimit)
72
77
  - [DefaultJsonBodyParserOptionsTypes](#variables/DefaultJsonBodyParserOptionsTypes)
73
78
  - [DefaultJsonBodyParserOptions](#variables/DefaultJsonBodyParserOptions)
@@ -76,15 +81,15 @@ SDK for base code for Api repos that use express and deploy on AWS ECS
76
81
 
77
82
  ## Functions
78
83
 
84
+ - [addRouteDefinitions](#functions/addRouteDefinitions)
79
85
  - [asyncHandler](#functions/asyncHandler)
80
86
  - [errorToJsonHandler](#functions/errorToJsonHandler)
81
87
  - [getHttpHeader](#functions/getHttpHeader)
82
88
  - [getDefaultLogger](#functions/getDefaultLogger)
83
89
  - [getLogger](#functions/getLogger)
84
90
  - [compactObject](#functions/compactObject)
85
- - [tryParse](#functions/tryParse)
86
- - [tryParseFloat](#functions/tryParseFloat)
87
- - [tryParseInt](#functions/tryParseInt)
91
+ - [~~tryParse~~](#functions/tryParse)
92
+ - [requestHandlerValidator](#functions/requestHandlerValidator)
88
93
  - [enableCaseSensitiveRouting](#functions/enableCaseSensitiveRouting)
89
94
  - [disableCaseSensitiveRouting](#functions/disableCaseSensitiveRouting)
90
95
  - [enableExpressDefaultPoweredByHeader](#functions/enableExpressDefaultPoweredByHeader)
@@ -133,7 +138,7 @@ static counters: Record<string, number> = {};
133
138
  ### inc()
134
139
 
135
140
  ```ts
136
- static inc(name, count): void;
141
+ static inc(name, count?): void;
137
142
  ```
138
143
 
139
144
  ### Parameters
@@ -142,7 +147,7 @@ static inc(name, count): void;
142
147
 
143
148
  `string`
144
149
 
145
- #### count
150
+ #### count?
146
151
 
147
152
  `number` = `1`
148
153
 
@@ -373,6 +378,30 @@ Logger.warn
373
378
 
374
379
  ### functions
375
380
 
381
+ ### <a id="addRouteDefinitions"></a>addRouteDefinitions
382
+
383
+ [**@xylabs/express**](#../README)
384
+
385
+ ***
386
+
387
+ ```ts
388
+ function addRouteDefinitions(app, routeDefinitions): void;
389
+ ```
390
+
391
+ ## Parameters
392
+
393
+ ### app
394
+
395
+ `Express`
396
+
397
+ ### routeDefinitions
398
+
399
+ [`RouteDefinition`](#../interfaces/RouteDefinition)\<`RequestHandler`\<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`\<`string`, `any`\>\>\>[]
400
+
401
+ ## Returns
402
+
403
+ `void`
404
+
376
405
  ### <a id="asyncHandler"></a>asyncHandler
377
406
 
378
407
  [**@xylabs/express**](#../README)
@@ -380,7 +409,7 @@ Logger.warn
380
409
  ***
381
410
 
382
411
  ```ts
383
- function asyncHandler<P, ResBody, ReqBody, ReqQuery, Locals>(fn): (req, res, next) => Promise<void>;
412
+ function asyncHandler<P, ResBody, ReqBody, ReqQuery, Locals>(fn): (req, res, next) => Promise<unknown>;
384
413
  ```
385
414
 
386
415
  ## Type Parameters
@@ -417,7 +446,7 @@ function asyncHandler<P, ResBody, ReqBody, ReqQuery, Locals>(fn): (req, res, nex
417
446
  (
418
447
  req,
419
448
  res,
420
- next): Promise<void>;
449
+ next): Promise<unknown>;
421
450
  ```
422
451
 
423
452
  ### Parameters
@@ -436,7 +465,7 @@ next): Promise<void>;
436
465
 
437
466
  ### Returns
438
467
 
439
- `Promise`\<`void`\>
468
+ `Promise`\<`unknown`\>
440
469
 
441
470
  ### <a id="clearRawResponseFormat"></a>clearRawResponseFormat
442
471
 
@@ -677,7 +706,7 @@ function getDefaultLogger(): Logger;
677
706
  ***
678
707
 
679
708
  ```ts
680
- function getHttpHeader(header, req): undefined | string;
709
+ function getHttpHeader(header, req): string | undefined;
681
710
  ```
682
711
 
683
712
  Since there can be multiple of certain HTTP headers or
@@ -701,7 +730,7 @@ The received HTTP request (with headers)
701
730
 
702
731
  ## Returns
703
732
 
704
- `undefined` \| `string`
733
+ `string` \| `undefined`
705
734
 
706
735
  The first or only occurrence of the specified HTTP header
707
736
 
@@ -712,14 +741,14 @@ The first or only occurrence of the specified HTTP header
712
741
  ***
713
742
 
714
743
  ```ts
715
- function getJsonBodyParser(options): NextHandleFunction;
744
+ function getJsonBodyParser(options?): NextHandleFunction;
716
745
  ```
717
746
 
718
747
  Get a JSON Body Parser connect middleware handler
719
748
 
720
749
  ## Parameters
721
750
 
722
- ### options
751
+ ### options?
723
752
 
724
753
  `OptionsJson` = `DefaultJsonBodyParserOptions`
725
754
 
@@ -766,12 +795,12 @@ precedence over the default
766
795
  ***
767
796
 
768
797
  ```ts
769
- function getLogger(minVerbosity): Logger;
798
+ function getLogger(minVerbosity?): Logger;
770
799
  ```
771
800
 
772
801
  ## Parameters
773
802
 
774
- ### minVerbosity
803
+ ### minVerbosity?
775
804
 
776
805
  [`LoggerVerbosity`](#../type-aliases/LoggerVerbosity) = `'info'`
777
806
 
@@ -825,6 +854,75 @@ body to the client
825
854
 
826
855
  True if there are any flags on the response, false otherwise
827
856
 
857
+ ### <a id="requestHandlerValidator"></a>requestHandlerValidator
858
+
859
+ [**@xylabs/express**](#../README)
860
+
861
+ ***
862
+
863
+ ```ts
864
+ function requestHandlerValidator<TParams, TQuery, TBody, TResponse>(schemas?): (handler) => RequestHandler;
865
+ ```
866
+
867
+ Factory for Express middleware that validates request and response objects using Zod schemas.
868
+
869
+ ## Type Parameters
870
+
871
+ ### TParams
872
+
873
+ `TParams` *extends*
874
+ \| `ZodObject`\<\{
875
+ \}, `$catchall`\<`ZodUnion`\<readonly \[`ZodString`, `ZodArray`\<`ZodString`\>\]\>\>\>
876
+ \| `ZodType`\<`Record`\<`string`, `string`\>, `unknown`, `$ZodTypeInternals`\<`Record`\<`string`, `string`\>, `unknown`\>\> = `ZodObject`\<\{
877
+ \}, `$catchall`\<`ZodUnion`\<readonly \[`ZodString`, `ZodArray`\<`ZodString`\>\]\>\>\>
878
+
879
+ ### TQuery
880
+
881
+ `TQuery` *extends*
882
+ \| `ZodObject`\<\{
883
+ \}, `$catchall`\<`ZodUnion`\<readonly \[`ZodString`, `ZodArray`\<`ZodString`\>\]\>\>\>
884
+ \| `ZodType`\<`Record`\<`string`, `string` \| `string`[]\>, `unknown`, `$ZodTypeInternals`\<`Record`\<`string`, `string` \| `string`[]\>, `unknown`\>\> = `ZodObject`\<\{
885
+ \}, `$catchall`\<`ZodUnion`\<readonly \[`ZodString`, `ZodArray`\<`ZodString`\>\]\>\>\>
886
+
887
+ ### TBody
888
+
889
+ `TBody` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>
890
+
891
+ ### TResponse
892
+
893
+ `TResponse` *extends* `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\> = `ZodType`\<`unknown`, `unknown`, `$ZodTypeInternals`\<`unknown`, `unknown`\>\>
894
+
895
+ ## Parameters
896
+
897
+ ### schemas?
898
+
899
+ `Partial`\<\{
900
+ `body`: `TBody`;
901
+ `params`: `TParams`;
902
+ `query`: `TQuery`;
903
+ `response`: `TResponse`;
904
+ \}\>
905
+
906
+ The Zod schemas to use for validation.
907
+
908
+ ## Returns
909
+
910
+ A middleware function for validating requests and responses.
911
+
912
+ ```ts
913
+ (handler): RequestHandler;
914
+ ```
915
+
916
+ ### Parameters
917
+
918
+ ### handler
919
+
920
+ (`req`, `res`, `next`) => `unknown`
921
+
922
+ ### Returns
923
+
924
+ `RequestHandler`
925
+
828
926
  ### <a id="responseProfiler"></a>responseProfiler
829
927
 
830
928
  [**@xylabs/express**](#../README)
@@ -917,7 +1015,7 @@ function standardErrors(
917
1015
 
918
1016
  ### err
919
1017
 
920
- `undefined` | [`ExpressError`](#../interfaces/ExpressError)
1018
+ [`ExpressError`](#../interfaces/ExpressError) | `undefined`
921
1019
 
922
1020
  ### req
923
1021
 
@@ -942,7 +1040,7 @@ function standardErrors(
942
1040
  ***
943
1041
 
944
1042
  ```ts
945
- function tryParse<T>(func, value?): undefined | T & object;
1043
+ function tryParse<T>(func, value?): T & object | undefined;
946
1044
  ```
947
1045
 
948
1046
  ## Type Parameters
@@ -963,47 +1061,11 @@ function tryParse<T>(func, value?): undefined | T & object;
963
1061
 
964
1062
  ## Returns
965
1063
 
966
- `undefined` \| `T` & `object`
967
-
968
- ### <a id="tryParseFloat"></a>tryParseFloat
969
-
970
- [**@xylabs/express**](#../README)
971
-
972
- ***
973
-
974
- ```ts
975
- function tryParseFloat(value?): undefined | number;
976
- ```
977
-
978
- ## Parameters
979
-
980
- ### value?
981
-
982
- `string`
983
-
984
- ## Returns
985
-
986
- `undefined` \| `number`
987
-
988
- ### <a id="tryParseInt"></a>tryParseInt
989
-
990
- [**@xylabs/express**](#../README)
991
-
992
- ***
993
-
994
- ```ts
995
- function tryParseInt(value?): undefined | number;
996
- ```
997
-
998
- ## Parameters
1064
+ `T` & `object` \| `undefined`
999
1065
 
1000
- ### value?
1001
-
1002
- `string`
1003
-
1004
- ## Returns
1066
+ ## Deprecated
1005
1067
 
1006
- `undefined` \| `number`
1068
+ use zod instead
1007
1069
 
1008
1070
  ### <a id="useRequestCounters"></a>useRequestCounters
1009
1071
 
@@ -1539,6 +1601,42 @@ optional defaultMeta: LoggerMeta;
1539
1601
 
1540
1602
  ```ts
1541
1603
  optional level: LoggerVerbosity;
1604
+ ```
1605
+
1606
+ ### <a id="RouteDefinition"></a>RouteDefinition
1607
+
1608
+ [**@xylabs/express**](#../README)
1609
+
1610
+ ***
1611
+
1612
+ ## Type Parameters
1613
+
1614
+ ### H
1615
+
1616
+ `H` *extends* `RequestHandler` = `RequestHandler`
1617
+
1618
+ ## Properties
1619
+
1620
+ ### handlers
1621
+
1622
+ ```ts
1623
+ handlers: H | H[];
1624
+ ```
1625
+
1626
+ ***
1627
+
1628
+ ### method
1629
+
1630
+ ```ts
1631
+ method: HttpMethod;
1632
+ ```
1633
+
1634
+ ***
1635
+
1636
+ ### path
1637
+
1638
+ ```ts
1639
+ path: string | RegExp;
1542
1640
  ```
1543
1641
 
1544
1642
  ### <a id="Source"></a>Source
@@ -1610,6 +1708,16 @@ type ApiResponse<T> =
1610
1708
 
1611
1709
  `T` *extends* [`ApiResourceIdentifierObject`](#../interfaces/ApiResourceIdentifierObject)
1612
1710
 
1711
+ ### <a id="HttpMethod"></a>HttpMethod
1712
+
1713
+ [**@xylabs/express**](#../README)
1714
+
1715
+ ***
1716
+
1717
+ ```ts
1718
+ type HttpMethod = "get" | "post" | "put" | "patch" | "delete" | "options" | "head";
1719
+ ```
1720
+
1613
1721
  ### <a id="LogFunction"></a>LogFunction
1614
1722
 
1615
1723
  [**@xylabs/express**](#../README)
@@ -1820,6 +1928,72 @@ const DefaultJsonBodyParserOptionsTypes: string[];
1820
1928
 
1821
1929
  The default MIME types for the JSON Body Parser
1822
1930
 
1931
+ ### <a id="EmptyParamsZod"></a>EmptyParamsZod
1932
+
1933
+ [**@xylabs/express**](#../README)
1934
+
1935
+ ***
1936
+
1937
+ ```ts
1938
+ const EmptyParamsZod: ZodObject<{
1939
+ }, $catchall<ZodString>>;
1940
+ ```
1941
+
1942
+ Empty Zod schema for requests with no parameters.
1943
+
1944
+ ### <a id="EmptyQueryParamsZod"></a>EmptyQueryParamsZod
1945
+
1946
+ [**@xylabs/express**](#../README)
1947
+
1948
+ ***
1949
+
1950
+ ```ts
1951
+ const EmptyQueryParamsZod: ZodObject<{
1952
+ }, $catchall<ZodUnion<readonly [ZodString, ZodArray<ZodString>]>>>;
1953
+ ```
1954
+
1955
+ Empty Zod schema for requests with no query parameters.
1956
+
1957
+ ### <a id="ValidateRequestDefaults"></a>ValidateRequestDefaults
1958
+
1959
+ [**@xylabs/express**](#../README)
1960
+
1961
+ ***
1962
+
1963
+ ```ts
1964
+ const ValidateRequestDefaults: object;
1965
+ ```
1966
+
1967
+ Default validation schemas for request handler validator.
1968
+
1969
+ ## Type Declaration
1970
+
1971
+ ### params
1972
+
1973
+ ```ts
1974
+ params: ZodObject<{
1975
+ }, $catchall<ZodString>> = EmptyParamsZod;
1976
+ ```
1977
+
1978
+ ### query
1979
+
1980
+ ```ts
1981
+ query: ZodObject<{
1982
+ }, $catchall<ZodUnion<readonly [ZodString, ZodArray<ZodString>]>>> = EmptyQueryParamsZod;
1983
+ ```
1984
+
1985
+ ### body
1986
+
1987
+ ```ts
1988
+ body: ZodOptional<ZodJSONSchema>;
1989
+ ```
1990
+
1991
+ ### response
1992
+
1993
+ ```ts
1994
+ response: ZodOptional<ZodJSONSchema>;
1995
+ ```
1996
+
1823
1997
  ### <a id="jsonBodyParser"></a>jsonBodyParser
1824
1998
 
1825
1999
  [**@xylabs/express**](#../README)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/express",
3
- "version": "5.0.80",
3
+ "version": "5.0.82",
4
4
  "description": "SDK for base code for Api repos that use express and deploy on AWS ECS",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -32,7 +32,6 @@
32
32
  ".": {
33
33
  "node": {
34
34
  "types": "./dist/node/index.d.ts",
35
- "source": "./src/index.ts",
36
35
  "default": "./dist/node/index.mjs"
37
36
  }
38
37
  },
@@ -40,11 +39,9 @@
40
39
  "./README.md": "./README.md"
41
40
  },
42
41
  "module": "./dist/node/index.mjs",
43
- "source": "./src/index.ts",
44
42
  "types": "./dist/node/index.d.ts",
45
43
  "files": [
46
44
  "dist",
47
- "src",
48
45
  "!**/*.bench.*",
49
46
  "!**/*.spec.*",
50
47
  "!**/*.test.*"
@@ -55,13 +52,14 @@
55
52
  "dependencies": {
56
53
  "@types/connect": "~3.4.38",
57
54
  "@types/express-serve-static-core": "~5.1.1",
58
- "@xylabs/assert": "~5.0.80",
59
- "@xylabs/logger": "~5.0.80",
60
- "@xylabs/typeof": "~5.0.80",
55
+ "@xylabs/assert": "~5.0.82",
56
+ "@xylabs/logger": "~5.0.82",
57
+ "@xylabs/typeof": "~5.0.82",
58
+ "@xylabs/vitest-extended": "~5.0.82",
61
59
  "body-parser": "~2.2.2",
62
60
  "express-mung": "~0.5.1",
63
61
  "http-status-codes": "~2.3.0",
64
- "rollbar": "~2.26.5",
62
+ "rollbar": "~3.0.0",
65
63
  "winston": "~3.19.0",
66
64
  "winston-transport": "~4.9.0"
67
65
  },
@@ -69,16 +67,14 @@
69
67
  "@types/body-parser": "~1.19.6",
70
68
  "@types/express": "~5.0.6",
71
69
  "@types/express-mung": "~0.5.5",
72
- "@types/node": "~25.2.3",
73
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
74
- "@xylabs/tsconfig": "~7.3.2",
75
- "@xylabs/vitest-extended": "~5.0.80",
70
+ "@types/node": "~25.4.0",
71
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
72
+ "@xylabs/tsconfig": "~7.4.11",
76
73
  "body-parser": "~2.2.2",
77
74
  "express": "~5.2.1",
78
75
  "express-mung": "~0.5.1",
79
76
  "http-status-codes": "~2.3.0",
80
- "node-cache": "~5.1.2",
81
- "rollbar": "~2.26.5",
77
+ "rollbar": "~3.0.0",
82
78
  "typescript": "~5.9.3",
83
79
  "vitest": "~4.0.18",
84
80
  "vitest-mock-extended": "~3.1.0",
@@ -1,18 +0,0 @@
1
- import type { RequestHandler } from 'express'
2
-
3
- export type HttpMethod
4
- = | 'get'
5
- | 'post'
6
- | 'put'
7
- | 'patch'
8
- | 'delete'
9
- | 'options'
10
- | 'head'
11
-
12
- export interface RouteDefinition<
13
- H extends RequestHandler = RequestHandler,
14
- > {
15
- handlers: H[] | H
16
- method: HttpMethod
17
- path: string | RegExp
18
- }
@@ -1,9 +0,0 @@
1
- import type { Express } from 'express'
2
-
3
- import type { RouteDefinition } from './RouteDefinition.ts'
4
-
5
- export const addRouteDefinitions = (app: Express, routeDefinitions: RouteDefinition[]) => {
6
- for (const definition of routeDefinitions) {
7
- app[definition.method](definition.path, definition.handlers)
8
- }
9
- }
@@ -1,2 +0,0 @@
1
- export * from './addRouteDefinitions.ts'
2
- export * from './RouteDefinition.ts'
@@ -1 +0,0 @@
1
- export * from './notImplemented.ts'
@@ -1,6 +0,0 @@
1
- import type { RequestHandler } from 'express'
2
- import { ReasonPhrases, StatusCodes } from 'http-status-codes'
3
-
4
- export const notImplemented: RequestHandler = (_req, _res, next) => {
5
- next({ message: ReasonPhrases.NOT_IMPLEMENTED, statusCode: StatusCodes.NOT_IMPLEMENTED })
6
- }
@@ -1,21 +0,0 @@
1
- import type {
2
- NextFunction, Request, RequestHandler, Response,
3
- } from 'express'
4
- import type { ParamsDictionary, Query } from 'express-serve-static-core'
5
-
6
- export function asyncHandler<P = NoReqParams, ResBody = NoResBody, ReqBody = NoReqBody, ReqQuery = NoReqQuery, Locals extends NoLocals = NoLocals>(
7
- fn: RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals>,
8
- ) {
9
- return (req: Request<P, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, next: NextFunction) => {
10
- return Promise.resolve(fn(req, res, next)).catch(next)
11
- }
12
- }
13
-
14
- export interface Empty {}
15
-
16
- export type NoReqParams = ParamsDictionary
17
- export type NoResBody = Empty
18
- export type NoReqBody = Empty
19
- export type NoReqQuery = Query
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- export type NoLocals = Record<string, any>
@@ -1,16 +0,0 @@
1
- import { isError, isNumber } from '@xylabs/typeof'
2
- import type {
3
- NextFunction, Request, Response,
4
- } from 'express'
5
-
6
- import { getDefaultLogger } from '../Logger/index.ts'
7
- import type { ExpressError } from '../Model/index.ts'
8
-
9
- export const errorToJsonHandler = (error: ExpressError, req: Request, res: Response, next: NextFunction) => {
10
- if (isError(error)) {
11
- getDefaultLogger().error(error.message)
12
- if (!isNumber(error.statusCode)) error.statusCode = 500
13
- res.status(error.statusCode).send({ error: error.message })
14
- }
15
- next(error)
16
- }
@@ -1,4 +0,0 @@
1
- export * from './asyncHandler.ts'
2
- export * from './errorToJsonHandler.ts'
3
- export * from './RouteDefinition/index.ts'
4
- export * from './StatusCodeHandlers/index.ts'
@@ -1,27 +0,0 @@
1
- import { isDefined } from '@xylabs/typeof'
2
- import type { Request } from 'express-serve-static-core'
3
-
4
- /**
5
- * Since there can be multiple of certain HTTP headers or
6
- * to prevent ugliness if someone did send us multiple
7
- * instances of a header we only expect one of, this
8
- * method grabs the 1st/only one of the desired header
9
- * @param header The header to find
10
- * @param req The received HTTP request (with headers)
11
- * @returns The first or only occurrence of the specified HTTP header
12
- */
13
- export const getHttpHeader = (header: string, req: Request): string | undefined => {
14
- const headerValue = req.headers[header]
15
- const value
16
- // If the header exists
17
- = isDefined(headerValue)
18
- // If there's multiple of the same header
19
- ? Array.isArray(headerValue)
20
- // Grab the first one
21
- ? (headerValue as string[]).shift()
22
- // Otherwise grab the only one
23
- : (headerValue as string)
24
- // Otherwise undefined
25
- : undefined
26
- return value
27
- }
@@ -1 +0,0 @@
1
- export * from './getHttpHeader.ts'
@@ -1 +0,0 @@
1
- export * from './logFormatLocalDev.ts'
@@ -1,11 +0,0 @@
1
- import { format } from 'winston'
2
-
3
- const {
4
- colorize, combine, timestamp, printf,
5
- } = format
6
-
7
- export const logFormatLocalDev = combine(
8
- colorize(),
9
- timestamp(),
10
- printf(info => `[${info.timestamp} ${info.level}] ${info.message}`),
11
- )
@@ -1 +0,0 @@
1
- export * from './logFormatRollbar.ts'
@@ -1,5 +0,0 @@
1
- import { format } from 'winston'
2
-
3
- const { simple } = format
4
-
5
- export const logFormatRollbar = simple()
@@ -1 +0,0 @@
1
- export * from './logFormatStructured.ts'
@@ -1,7 +0,0 @@
1
- import { format } from 'winston'
2
-
3
- const {
4
- combine, timestamp, json,
5
- } = format
6
-
7
- export const logFormatStructured = combine(timestamp(), json())
@@ -1,3 +0,0 @@
1
- export * from './LocalDev/index.ts'
2
- export * from './Rollbar/index.ts'
3
- export * from './Structured/index.ts'
@@ -1 +0,0 @@
1
- export type LoggerMeta = Record<string, string | number>
@@ -1,7 +0,0 @@
1
- import type { LoggerMeta } from './LoggerMeta.ts'
2
- import type { LoggerVerbosity } from './LoggerVerbosity.ts'
3
-
4
- export interface LoggerOptions {
5
- defaultMeta?: LoggerMeta
6
- level?: LoggerVerbosity
7
- }
@@ -1 +0,0 @@
1
- export type LoggerVerbosity = 'error' | 'warn' | 'info' | 'debug' | 'all'