@forklaunch/core 0.2.37 → 0.3.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.
Files changed (222) hide show
  1. package/lib/{src/database/mikro/models/entities/base.entity.d.ts → base.entity-DNfmMOgd.d.mts} +3 -2
  2. package/lib/base.entity-DNfmMOgd.d.ts +27 -0
  3. package/lib/{src/cache/redisTtlCache.d.ts → cache/index.d.mts} +67 -4
  4. package/lib/cache/index.d.ts +130 -0
  5. package/lib/cache/index.js +133 -0
  6. package/lib/cache/index.mjs +105 -0
  7. package/lib/controllers/index.d.mts +5 -0
  8. package/lib/controllers/index.d.ts +5 -0
  9. package/lib/controllers/index.js +18 -0
  10. package/lib/controllers/index.mjs +0 -0
  11. package/lib/database/index.d.mts +37 -0
  12. package/lib/{src/database/mikro/models/entities/mongo.base.entity.d.ts → database/index.d.ts} +5 -2
  13. package/lib/database/index.js +78 -0
  14. package/lib/database/index.mjs +53 -0
  15. package/lib/dtoMapper/index.d.mts +215 -0
  16. package/lib/dtoMapper/index.d.ts +215 -0
  17. package/lib/dtoMapper/index.js +235 -0
  18. package/lib/dtoMapper/index.mjs +213 -0
  19. package/lib/http/index.d.mts +910 -0
  20. package/lib/http/index.d.ts +910 -0
  21. package/lib/http/index.js +2189 -0
  22. package/lib/http/index.mjs +2134 -0
  23. package/lib/services/index.d.mts +69 -0
  24. package/lib/services/index.d.ts +69 -0
  25. package/lib/services/index.js +244 -0
  26. package/lib/services/index.mjs +215 -0
  27. package/package.json +68 -55
  28. package/lib/src/cache/index.d.ts +0 -5
  29. package/lib/src/cache/index.d.ts.map +0 -1
  30. package/lib/src/cache/index.js +0 -4
  31. package/lib/src/cache/interfaces/ttlCache.interface.d.ts +0 -48
  32. package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +0 -1
  33. package/lib/src/cache/interfaces/ttlCache.interface.js +0 -1
  34. package/lib/src/cache/redisTtlCache.d.ts.map +0 -1
  35. package/lib/src/cache/redisTtlCache.js +0 -98
  36. package/lib/src/cache/types/ttlCacheRecord.types.d.ts +0 -14
  37. package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +0 -1
  38. package/lib/src/cache/types/ttlCacheRecord.types.js +0 -1
  39. package/lib/src/cache/utils/cacheKey.d.ts +0 -2
  40. package/lib/src/cache/utils/cacheKey.d.ts.map +0 -1
  41. package/lib/src/cache/utils/cacheKey.js +0 -3
  42. package/lib/src/controllers/index.d.ts +0 -2
  43. package/lib/src/controllers/index.d.ts.map +0 -1
  44. package/lib/src/controllers/index.js +0 -1
  45. package/lib/src/controllers/interfaces/controller.interface.d.ts +0 -4
  46. package/lib/src/controllers/interfaces/controller.interface.d.ts.map +0 -1
  47. package/lib/src/controllers/interfaces/controller.interface.js +0 -1
  48. package/lib/src/database/index.d.ts +0 -3
  49. package/lib/src/database/index.d.ts.map +0 -1
  50. package/lib/src/database/index.js +0 -2
  51. package/lib/src/database/mikro/models/entities/base.entity.d.ts.map +0 -1
  52. package/lib/src/database/mikro/models/entities/base.entity.js +0 -42
  53. package/lib/src/database/mikro/models/entities/mongo.base.entity.d.ts.map +0 -1
  54. package/lib/src/database/mikro/models/entities/mongo.base.entity.js +0 -51
  55. package/lib/src/dtoMapper/index.d.ts +0 -3
  56. package/lib/src/dtoMapper/index.d.ts.map +0 -1
  57. package/lib/src/dtoMapper/index.js +0 -2
  58. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts +0 -18
  59. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts.map +0 -1
  60. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.js +0 -1
  61. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts +0 -72
  62. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +0 -1
  63. package/lib/src/dtoMapper/models/baseDtoMapper.model.js +0 -76
  64. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +0 -68
  65. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +0 -1
  66. package/lib/src/dtoMapper/models/requestDtoMapper.model.js +0 -71
  67. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +0 -67
  68. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +0 -1
  69. package/lib/src/dtoMapper/models/responseDtoMapper.model.js +0 -68
  70. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts +0 -9
  71. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts.map +0 -1
  72. package/lib/src/dtoMapper/types/dtoMapper.types.js +0 -1
  73. package/lib/src/http/application/expressLikeApplication.d.ts +0 -21
  74. package/lib/src/http/application/expressLikeApplication.d.ts.map +0 -1
  75. package/lib/src/http/application/expressLikeApplication.js +0 -21
  76. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts +0 -4
  77. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts.map +0 -1
  78. package/lib/src/http/guards/isConstrainedForklaunchRouter.js +0 -5
  79. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts +0 -5
  80. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts.map +0 -1
  81. package/lib/src/http/guards/isExpressLikeSchemaHandler.js +0 -6
  82. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts +0 -5
  83. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts.map +0 -1
  84. package/lib/src/http/guards/isForklaunchExpressLikeRouter.js +0 -6
  85. package/lib/src/http/guards/isForklaunchRouter.d.ts +0 -4
  86. package/lib/src/http/guards/isForklaunchRouter.d.ts.map +0 -1
  87. package/lib/src/http/guards/isForklaunchRouter.js +0 -7
  88. package/lib/src/http/guards/isHttpContractDetails.d.ts +0 -7
  89. package/lib/src/http/guards/isHttpContractDetails.d.ts.map +0 -1
  90. package/lib/src/http/guards/isHttpContractDetails.js +0 -9
  91. package/lib/src/http/guards/isPathParamContractDetails.d.ts +0 -4
  92. package/lib/src/http/guards/isPathParamContractDetails.d.ts.map +0 -1
  93. package/lib/src/http/guards/isPathParamContractDetails.js +0 -10
  94. package/lib/src/http/guards/isResponseShape.d.ts +0 -3
  95. package/lib/src/http/guards/isResponseShape.d.ts.map +0 -1
  96. package/lib/src/http/guards/isResponseShape.js +0 -7
  97. package/lib/src/http/guards/isTypedHandler.d.ts +0 -5
  98. package/lib/src/http/guards/isTypedHandler.d.ts.map +0 -1
  99. package/lib/src/http/guards/isTypedHandler.js +0 -6
  100. package/lib/src/http/handlers/delete.d.ts +0 -9
  101. package/lib/src/http/handlers/delete.d.ts.map +0 -1
  102. package/lib/src/http/handlers/delete.js +0 -4
  103. package/lib/src/http/handlers/get.d.ts +0 -9
  104. package/lib/src/http/handlers/get.d.ts.map +0 -1
  105. package/lib/src/http/handlers/get.js +0 -4
  106. package/lib/src/http/handlers/head.d.ts +0 -9
  107. package/lib/src/http/handlers/head.d.ts.map +0 -1
  108. package/lib/src/http/handlers/head.js +0 -4
  109. package/lib/src/http/handlers/middleware.d.ts +0 -9
  110. package/lib/src/http/handlers/middleware.d.ts.map +0 -1
  111. package/lib/src/http/handlers/middleware.js +0 -4
  112. package/lib/src/http/handlers/options.d.ts +0 -9
  113. package/lib/src/http/handlers/options.d.ts.map +0 -1
  114. package/lib/src/http/handlers/options.js +0 -4
  115. package/lib/src/http/handlers/patch.d.ts +0 -9
  116. package/lib/src/http/handlers/patch.d.ts.map +0 -1
  117. package/lib/src/http/handlers/patch.js +0 -4
  118. package/lib/src/http/handlers/post.d.ts +0 -9
  119. package/lib/src/http/handlers/post.d.ts.map +0 -1
  120. package/lib/src/http/handlers/post.js +0 -4
  121. package/lib/src/http/handlers/put.d.ts +0 -9
  122. package/lib/src/http/handlers/put.d.ts.map +0 -1
  123. package/lib/src/http/handlers/put.js +0 -4
  124. package/lib/src/http/handlers/trace.d.ts +0 -9
  125. package/lib/src/http/handlers/trace.d.ts.map +0 -1
  126. package/lib/src/http/handlers/trace.js +0 -4
  127. package/lib/src/http/handlers/typedAuthHandler.d.ts +0 -5
  128. package/lib/src/http/handlers/typedAuthHandler.d.ts.map +0 -1
  129. package/lib/src/http/handlers/typedAuthHandler.js +0 -3
  130. package/lib/src/http/handlers/typedHandler.d.ts +0 -21
  131. package/lib/src/http/handlers/typedHandler.d.ts.map +0 -1
  132. package/lib/src/http/handlers/typedHandler.js +0 -30
  133. package/lib/src/http/index.d.ts +0 -23
  134. package/lib/src/http/index.d.ts.map +0 -1
  135. package/lib/src/http/index.js +0 -22
  136. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts +0 -24
  137. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts.map +0 -1
  138. package/lib/src/http/interfaces/expressLikeRouter.interface.js +0 -1
  139. package/lib/src/http/middleware/request/auth.middleware.d.ts +0 -16
  140. package/lib/src/http/middleware/request/auth.middleware.d.ts.map +0 -1
  141. package/lib/src/http/middleware/request/auth.middleware.js +0 -143
  142. package/lib/src/http/middleware/request/cors.middleware.d.ts +0 -13
  143. package/lib/src/http/middleware/request/cors.middleware.d.ts.map +0 -1
  144. package/lib/src/http/middleware/request/cors.middleware.js +0 -15
  145. package/lib/src/http/middleware/request/createContext.middleware.d.ts +0 -15
  146. package/lib/src/http/middleware/request/createContext.middleware.d.ts.map +0 -1
  147. package/lib/src/http/middleware/request/createContext.middleware.js +0 -26
  148. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts +0 -15
  149. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts.map +0 -1
  150. package/lib/src/http/middleware/request/enrichDetails.middleware.js +0 -19
  151. package/lib/src/http/middleware/request/parse.middleware.d.ts +0 -17
  152. package/lib/src/http/middleware/request/parse.middleware.d.ts.map +0 -1
  153. package/lib/src/http/middleware/request/parse.middleware.js +0 -43
  154. package/lib/src/http/middleware/response/parse.middleware.d.ts +0 -31
  155. package/lib/src/http/middleware/response/parse.middleware.d.ts.map +0 -1
  156. package/lib/src/http/middleware/response/parse.middleware.js +0 -52
  157. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts +0 -14
  158. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts.map +0 -1
  159. package/lib/src/http/openApiV3Generator/openApiV3Generator.js +0 -169
  160. package/lib/src/http/router/expressLikeRouter.d.ts +0 -138
  161. package/lib/src/http/router/expressLikeRouter.d.ts.map +0 -1
  162. package/lib/src/http/router/expressLikeRouter.js +0 -483
  163. package/lib/src/http/types/apiDefinition.types.d.ts +0 -260
  164. package/lib/src/http/types/apiDefinition.types.d.ts.map +0 -1
  165. package/lib/src/http/types/apiDefinition.types.js +0 -1
  166. package/lib/src/http/types/contractDetails.types.d.ts +0 -211
  167. package/lib/src/http/types/contractDetails.types.d.ts.map +0 -1
  168. package/lib/src/http/types/contractDetails.types.js +0 -1
  169. package/lib/src/http/types/expressLikeRouter.types.d.ts +0 -51
  170. package/lib/src/http/types/expressLikeRouter.types.d.ts.map +0 -1
  171. package/lib/src/http/types/expressLikeRouter.types.js +0 -1
  172. package/lib/src/http/types/router.types.d.ts +0 -32
  173. package/lib/src/http/types/router.types.d.ts.map +0 -1
  174. package/lib/src/http/types/router.types.js +0 -1
  175. package/lib/src/http/types/typedHandler.types.d.ts +0 -10
  176. package/lib/src/http/types/typedHandler.types.d.ts.map +0 -1
  177. package/lib/src/http/types/typedHandler.types.js +0 -1
  178. package/lib/src/http/utils/enrichExpressLikeSend.d.ts +0 -32
  179. package/lib/src/http/utils/enrichExpressLikeSend.d.ts.map +0 -1
  180. package/lib/src/http/utils/enrichExpressLikeSend.js +0 -50
  181. package/lib/src/http/utils/httpStatusCodes.d.ts +0 -75
  182. package/lib/src/http/utils/httpStatusCodes.d.ts.map +0 -1
  183. package/lib/src/http/utils/httpStatusCodes.js +0 -1039
  184. package/lib/src/services/configInjector.d.ts +0 -21
  185. package/lib/src/services/configInjector.d.ts.map +0 -1
  186. package/lib/src/services/configInjector.js +0 -90
  187. package/lib/src/services/index.d.ts +0 -5
  188. package/lib/src/services/index.d.ts.map +0 -1
  189. package/lib/src/services/index.js +0 -4
  190. package/lib/src/services/interfaces/baseService.d.ts +0 -15
  191. package/lib/src/services/interfaces/baseService.d.ts.map +0 -1
  192. package/lib/src/services/interfaces/baseService.js +0 -1
  193. package/lib/src/services/types/configInjector.types.d.ts +0 -25
  194. package/lib/src/services/types/configInjector.types.d.ts.map +0 -1
  195. package/lib/src/services/types/configInjector.types.js +0 -6
  196. package/lib/src/services/types/entityManager.types.d.ts +0 -4
  197. package/lib/src/services/types/entityManager.types.d.ts.map +0 -1
  198. package/lib/src/services/types/entityManager.types.js +0 -1
  199. package/lib/tests/configInjector.test.d.ts +0 -2
  200. package/lib/tests/configInjector.test.d.ts.map +0 -1
  201. package/lib/tests/configInjector.test.js +0 -105
  202. package/lib/tests/dtoMapper.test.d.ts +0 -2
  203. package/lib/tests/dtoMapper.test.d.ts.map +0 -1
  204. package/lib/tests/dtoMapper.test.js +0 -170
  205. package/lib/tests/expressLikeRouterInstantiation.test.d.ts +0 -2
  206. package/lib/tests/expressLikeRouterInstantiation.test.d.ts.map +0 -1
  207. package/lib/tests/expressLikeRouterInstantiation.test.js +0 -118
  208. package/lib/tests/http.middleware.test.d.ts +0 -2
  209. package/lib/tests/http.middleware.test.d.ts.map +0 -1
  210. package/lib/tests/http.middleware.test.js +0 -102
  211. package/lib/tests/openApiV3Generator.test.d.ts +0 -2
  212. package/lib/tests/openApiV3Generator.test.d.ts.map +0 -1
  213. package/lib/tests/openApiV3Generator.test.js +0 -66
  214. package/lib/tests/redisTtlCache.test.d.ts +0 -2
  215. package/lib/tests/redisTtlCache.test.d.ts.map +0 -1
  216. package/lib/tests/redisTtlCache.test.js +0 -49
  217. package/lib/tests/typedHandler.test.d.ts +0 -2
  218. package/lib/tests/typedHandler.test.d.ts.map +0 -1
  219. package/lib/tests/typedHandler.test.js +0 -3
  220. package/lib/vitest.config.d.ts +0 -3
  221. package/lib/vitest.config.d.ts.map +0 -1
  222. package/lib/vitest.config.js +0 -7
@@ -0,0 +1,2189 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/http/index.ts
31
+ var http_exports = {};
32
+ __export(http_exports, {
33
+ ForklaunchExpressLikeApplication: () => ForklaunchExpressLikeApplication,
34
+ ForklaunchExpressLikeRouter: () => ForklaunchExpressLikeRouter,
35
+ HTTPStatuses: () => HTTPStatuses,
36
+ delete_: () => delete_,
37
+ enrichExpressLikeSend: () => enrichExpressLikeSend,
38
+ generateSwaggerDocument: () => generateSwaggerDocument,
39
+ get: () => get,
40
+ getCodeForStatus: () => getCodeForStatus,
41
+ head: () => head,
42
+ isClientError: () => isClientError,
43
+ isForklaunchRouter: () => isForklaunchRouter,
44
+ isInformational: () => isInformational,
45
+ isRedirection: () => isRedirection,
46
+ isServerError: () => isServerError,
47
+ isSuccessful: () => isSuccessful,
48
+ isValidStatusCode: () => isValidStatusCode,
49
+ middleware: () => middleware,
50
+ options: () => options,
51
+ patch: () => patch,
52
+ post: () => post,
53
+ put: () => put,
54
+ trace: () => trace,
55
+ typedHandler: () => typedHandler
56
+ });
57
+ module.exports = __toCommonJS(http_exports);
58
+
59
+ // src/http/guards/isForklaunchRouter.ts
60
+ function isForklaunchRouter(maybeForklaunchRouter) {
61
+ return maybeForklaunchRouter != null && typeof maybeForklaunchRouter === "object" && "basePath" in maybeForklaunchRouter && "routes" in maybeForklaunchRouter && Array.isArray(maybeForklaunchRouter.routes);
62
+ }
63
+
64
+ // src/http/guards/isConstrainedForklaunchRouter.ts
65
+ function isConstrainedForklaunchRouter(maybeForklaunchExpressLikeRouter) {
66
+ return isForklaunchRouter(maybeForklaunchExpressLikeRouter) && "requestHandler" in maybeForklaunchExpressLikeRouter;
67
+ }
68
+
69
+ // src/http/guards/isExpressLikeSchemaHandler.ts
70
+ var import_common = require("@forklaunch/common");
71
+ function isExpressLikeSchemaHandler(middleware2) {
72
+ const extractedArgumentNames = typeof middleware2 === "function" && new Set(
73
+ (0, import_common.extractArgumentNames)(middleware2).map(
74
+ (argumentName) => argumentName.toLowerCase()
75
+ )
76
+ );
77
+ return extractedArgumentNames && extractedArgumentNames.size <= 3;
78
+ }
79
+
80
+ // src/http/guards/isForklaunchExpressLikeRouter.ts
81
+ function isForklaunchExpressLikeRouter(maybeForklaunchExpressLikeRouter) {
82
+ return isConstrainedForklaunchRouter(
83
+ maybeForklaunchExpressLikeRouter
84
+ ) && "basePath" in maybeForklaunchExpressLikeRouter && "internal" in maybeForklaunchExpressLikeRouter;
85
+ }
86
+
87
+ // src/http/guards/isPathParamContractDetails.ts
88
+ function isPathParamHttpContractDetails(maybePathParamHttpContractDetails) {
89
+ return maybePathParamHttpContractDetails != null && typeof maybePathParamHttpContractDetails === "object" && "name" in maybePathParamHttpContractDetails && "summary" in maybePathParamHttpContractDetails && "responses" in maybePathParamHttpContractDetails && maybePathParamHttpContractDetails.name != null && maybePathParamHttpContractDetails.summary != null && maybePathParamHttpContractDetails.responses != null;
90
+ }
91
+
92
+ // src/http/guards/isHttpContractDetails.ts
93
+ function isHttpContractDetails(maybeContractDetails) {
94
+ return isPathParamHttpContractDetails(maybeContractDetails) && "body" in maybeContractDetails && maybeContractDetails.body != null;
95
+ }
96
+
97
+ // src/http/guards/isTypedHandler.ts
98
+ function isTypedHandler(maybeTypedHandler) {
99
+ return maybeTypedHandler != null && typeof maybeTypedHandler === "object" && "_typedHandler" in maybeTypedHandler && maybeTypedHandler._typedHandler === true;
100
+ }
101
+
102
+ // src/http/middleware/request/auth.middleware.ts
103
+ var import_jose = require("jose");
104
+ var invalidAuthorizationTokenFormat = [
105
+ 401,
106
+ "Invalid Authorization token format."
107
+ ];
108
+ var invalidAuthorizationSubject = [
109
+ 403,
110
+ "Invalid Authorization subject."
111
+ ];
112
+ var invalidAuthorizationTokenPermissions = [
113
+ 403,
114
+ "Invalid Authorization permissions."
115
+ ];
116
+ var invalidAuthorizationTokenRoles = [
117
+ 403,
118
+ "Invalid Authorization roles."
119
+ ];
120
+ var invalidAuthorizationToken = [
121
+ 403,
122
+ "Invalid Authorization token."
123
+ ];
124
+ var invalidAuthorizationLogin = [
125
+ 403,
126
+ "Invalid Authorization login."
127
+ ];
128
+ async function checkAuthorizationToken(authorizationMethod, authorizationToken, req) {
129
+ if (authorizationToken == null) {
130
+ return [401, "No Authorization token provided."];
131
+ }
132
+ const [tokenPrefix, token] = authorizationToken.split(" ");
133
+ let resourceId;
134
+ switch (authorizationMethod.method) {
135
+ case "jwt": {
136
+ if (tokenPrefix !== "Bearer") {
137
+ return invalidAuthorizationTokenFormat;
138
+ }
139
+ try {
140
+ const decodedJwt = await (0, import_jose.jwtVerify)(
141
+ token,
142
+ new TextEncoder().encode(
143
+ // TODO: Check this at application startup if there is any route with jwt checking
144
+ process.env.JWT_SECRET
145
+ )
146
+ );
147
+ if (!decodedJwt.payload.sub) {
148
+ return invalidAuthorizationSubject;
149
+ }
150
+ resourceId = decodedJwt.payload.sub;
151
+ } catch (error) {
152
+ console.error(error);
153
+ return invalidAuthorizationToken;
154
+ }
155
+ break;
156
+ }
157
+ case "basic": {
158
+ if (authorizationToken !== "Basic") {
159
+ return invalidAuthorizationTokenFormat;
160
+ }
161
+ const [username, password] = Buffer.from(token, "base64").toString("utf-8").split(":");
162
+ if (!username || !password) {
163
+ return invalidAuthorizationTokenFormat;
164
+ }
165
+ if (!authorizationMethod.login(username, password)) {
166
+ return invalidAuthorizationLogin;
167
+ }
168
+ resourceId = username;
169
+ break;
170
+ }
171
+ case "other":
172
+ if (tokenPrefix !== authorizationMethod.tokenPrefix) {
173
+ return invalidAuthorizationTokenFormat;
174
+ }
175
+ resourceId = authorizationMethod.decodeResource(token);
176
+ break;
177
+ }
178
+ if (authorizationMethod.allowedPermissions || authorizationMethod.forbiddenPermissions) {
179
+ if (!authorizationMethod.mapPermissions) {
180
+ return [500, "No permission mapping function provided."];
181
+ }
182
+ const resourcePermissions = await authorizationMethod.mapPermissions(
183
+ resourceId,
184
+ req
185
+ );
186
+ if (authorizationMethod.allowedPermissions) {
187
+ if (resourcePermissions.intersection(authorizationMethod.allowedPermissions).size === 0) {
188
+ return invalidAuthorizationTokenPermissions;
189
+ }
190
+ }
191
+ if (authorizationMethod.forbiddenPermissions) {
192
+ if (resourcePermissions.intersection(
193
+ authorizationMethod.forbiddenPermissions
194
+ ).size !== 0) {
195
+ return invalidAuthorizationTokenPermissions;
196
+ }
197
+ }
198
+ }
199
+ if (authorizationMethod.allowedRoles || authorizationMethod.forbiddenRoles) {
200
+ if (!authorizationMethod.mapRoles) {
201
+ return [500, "No role mapping function provided."];
202
+ }
203
+ const resourceRoles = await authorizationMethod.mapRoles(resourceId, req);
204
+ if (authorizationMethod.allowedRoles) {
205
+ if (resourceRoles.intersection(authorizationMethod.allowedRoles).size === 0) {
206
+ return invalidAuthorizationTokenRoles;
207
+ }
208
+ }
209
+ if (authorizationMethod.forbiddenRoles) {
210
+ if (resourceRoles.intersection(authorizationMethod.forbiddenRoles).size !== 0) {
211
+ return invalidAuthorizationTokenRoles;
212
+ }
213
+ }
214
+ }
215
+ return [401, "Invalid Authorization method."];
216
+ }
217
+ async function parseRequestAuth(req, res, next) {
218
+ console.debug("[MIDDLEWARE] parseRequest started");
219
+ const auth = req.contractDetails.auth;
220
+ if (auth) {
221
+ const errorAndMessage = await checkAuthorizationToken(
222
+ auth,
223
+ req.headers[(auth.method === "other" ? auth.headerName : void 0) ?? "Authorization"],
224
+ req
225
+ );
226
+ if (Array.isArray(errorAndMessage)) {
227
+ res.status(errorAndMessage[0]).send(errorAndMessage[1]);
228
+ next?.(new Error(errorAndMessage[1]));
229
+ }
230
+ }
231
+ next?.();
232
+ }
233
+
234
+ // src/http/middleware/request/cors.middleware.ts
235
+ var import_cors = __toESM(require("cors"));
236
+ function cors(req, res, next) {
237
+ console.debug("[MIDDLEWARE] cors started");
238
+ if (req.method === "OPTIONS") {
239
+ res.cors = true;
240
+ }
241
+ (0, import_cors.default)()(req, res, next ?? (() => {
242
+ }));
243
+ }
244
+
245
+ // src/http/middleware/request/createContext.middleware.ts
246
+ var import_uuid = require("uuid");
247
+ function createContext(schemaValidator) {
248
+ return (req, res, next) => {
249
+ console.debug("[MIDDLEWARE] createRequestContext started");
250
+ req.schemaValidator = schemaValidator;
251
+ let correlationId = (0, import_uuid.v4)();
252
+ if (req.headers["x-correlation-id"]) {
253
+ correlationId = req.headers["x-correlation-id"];
254
+ }
255
+ res.setHeader("x-correlation-id", correlationId);
256
+ req.context = {
257
+ correlationId
258
+ };
259
+ next?.();
260
+ };
261
+ }
262
+
263
+ // src/http/middleware/request/enrichDetails.middleware.ts
264
+ function enrichDetails(contractDetails, requestSchema, responseSchemas) {
265
+ return (req, res, next) => {
266
+ console.debug("[MIDDLEWARE] enrichRequestDetails started");
267
+ req.contractDetails = contractDetails;
268
+ req.requestSchema = requestSchema;
269
+ res.responseSchemas = responseSchemas;
270
+ next?.();
271
+ };
272
+ }
273
+
274
+ // src/http/middleware/request/parse.middleware.ts
275
+ var import_validator = require("@forklaunch/validator");
276
+
277
+ // src/http/guards/isResponseShape.ts
278
+ function isResponseShape(maybeResponseShape) {
279
+ return maybeResponseShape != null && "body" in maybeResponseShape && "query" in maybeResponseShape && "params" in maybeResponseShape && "headers" in maybeResponseShape;
280
+ }
281
+
282
+ // src/http/middleware/request/parse.middleware.ts
283
+ function parse(req, _res, next) {
284
+ console.debug("[MIDDLEWARE] parseRequest started");
285
+ const request = {
286
+ params: req.params,
287
+ query: req.query,
288
+ headers: req.headers,
289
+ body: req.body
290
+ };
291
+ const parsedRequest = req.schemaValidator.parse(req.requestSchema, request);
292
+ if (parsedRequest.ok && isResponseShape(parsedRequest.value)) {
293
+ req.body = parsedRequest.value.body;
294
+ req.params = parsedRequest.value.params;
295
+ req.query = parsedRequest.value.query;
296
+ req.headers = parsedRequest.value.headers;
297
+ }
298
+ if (!parsedRequest.ok) {
299
+ switch (req.contractDetails.options?.requestValidation) {
300
+ default:
301
+ case "error":
302
+ next?.(
303
+ new Error((0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request"))
304
+ );
305
+ break;
306
+ case "warning":
307
+ console.warn((0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request"));
308
+ break;
309
+ case "none":
310
+ break;
311
+ }
312
+ }
313
+ next?.();
314
+ }
315
+
316
+ // src/http/router/expressLikeRouter.ts
317
+ var ForklaunchExpressLikeRouter = class {
318
+ constructor(basePath, schemaValidator, internal) {
319
+ this.schemaValidator = schemaValidator;
320
+ this.internal = internal;
321
+ this.basePath = basePath;
322
+ this.internal.use(createContext(this.schemaValidator));
323
+ this.internal.use(cors);
324
+ }
325
+ requestHandler;
326
+ routers = [];
327
+ routes = [];
328
+ basePath;
329
+ /**
330
+ * Resolves middlewares based on the contract details.
331
+ *
332
+ * @param {PathParamHttpContractDetails<SV> | HttpContractDetails<SV>} contractDetails - The contract details.
333
+ * @returns {MiddlewareHandler<SV>[]} - The resolved middlewares.
334
+ */
335
+ #resolveMiddlewares(contractDetails, requestSchema, responseSchemas) {
336
+ return [
337
+ enrichDetails(contractDetails, requestSchema, responseSchemas),
338
+ parse,
339
+ parseRequestAuth
340
+ ];
341
+ }
342
+ /**
343
+ * Parses and runs the controller handler with error handling.
344
+ *
345
+ * @template P - The type of request parameters.
346
+ * @template ResBodyMap - The type of response body.
347
+ * @template ReqBody - The type of request body.
348
+ * @template ReqQuery - The type of request query.
349
+ * @template LocalsObj - The type of local variables.
350
+ * @template StatusCode - The type of status code.
351
+ * @param {MiddlewareHandler<SV, P, ResBodyMap | string, ReqBody, ReqQuery, LocalsObj, StatusCode>} requestHandler - The request handler.
352
+ * @returns {ExpressMiddlewareHandler} - The Express request handler.
353
+ */
354
+ #parseAndRunControllerHandler(requestHandler) {
355
+ return async (req, res, next) => {
356
+ if (!requestHandler) {
357
+ throw new Error("Controller handler is not defined");
358
+ }
359
+ try {
360
+ await requestHandler(req, res, next);
361
+ } catch (error) {
362
+ next?.(error);
363
+ console.error(error);
364
+ if (!res.headersSent) {
365
+ res.status(500).send("Internal Server Error");
366
+ }
367
+ }
368
+ };
369
+ }
370
+ /**
371
+ * Extracts the controller handler from the provided handlers.
372
+ *
373
+ * @template P - The type of request parameters.
374
+ * @template ResBodyMap - The type of response body.
375
+ * @template ReqBody - The type of request body.
376
+ * @template ReqQuery - The type of request query.
377
+ * @template LocalsObj - The type of local variables.
378
+ * @param {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The provided handlers.
379
+ * @returns {MiddlewareHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>} - The extracted controller handler.
380
+ * @throws {Error} - Throws an error if the last argument is not a handler.
381
+ */
382
+ #extractControllerHandler(handlers) {
383
+ const controllerHandler = handlers.pop();
384
+ if (typeof controllerHandler !== "function") {
385
+ throw new Error(
386
+ `Last argument must be a handler, received: ${controllerHandler}`
387
+ );
388
+ }
389
+ return controllerHandler;
390
+ }
391
+ #compile(contractDetails) {
392
+ const schemaValidator = this.schemaValidator;
393
+ const requestSchema = schemaValidator.compile(
394
+ schemaValidator.schemify({
395
+ ...contractDetails.params ? { params: contractDetails.params } : {},
396
+ ...contractDetails.requestHeaders ? { headers: contractDetails.requestHeaders } : {},
397
+ ...contractDetails.query ? { query: contractDetails.query } : {},
398
+ ...isHttpContractDetails(contractDetails) && contractDetails.body ? { body: contractDetails.body } : {}
399
+ })
400
+ );
401
+ const responseEntries = {
402
+ 400: schemaValidator.string,
403
+ 401: schemaValidator.string,
404
+ 403: schemaValidator.string,
405
+ 404: schemaValidator.string,
406
+ 500: schemaValidator.string,
407
+ ...isPathParamHttpContractDetails(contractDetails) || isHttpContractDetails(contractDetails) ? { ...contractDetails.responses } : {}
408
+ };
409
+ const responseSchemas = {
410
+ responses: {},
411
+ ...contractDetails.responseHeaders ? {
412
+ headers: schemaValidator.compile(
413
+ schemaValidator.schemify(contractDetails.responseHeaders)
414
+ )
415
+ } : {}
416
+ };
417
+ Object.entries(responseEntries).forEach(([code, responseShape]) => {
418
+ responseSchemas.responses[Number(code)] = schemaValidator.compile(
419
+ schemaValidator.schemify(responseShape)
420
+ );
421
+ });
422
+ return {
423
+ requestSchema,
424
+ responseSchemas
425
+ };
426
+ }
427
+ /**
428
+ * Executes request locally, applying parameters
429
+ *
430
+ * @param handlers {ExpressLikeHandler<SV>}
431
+ * @param controllerHandler
432
+ * @returns
433
+ */
434
+ #localParamRequest(handlers, controllerHandler) {
435
+ return async (route, request) => {
436
+ let statusCode;
437
+ let responseMessage;
438
+ const responseHeaders = {};
439
+ const req = {
440
+ params: request?.params ?? {},
441
+ query: request?.query ?? {},
442
+ headers: request?.headers ?? {},
443
+ body: request?.body ?? {},
444
+ path: route
445
+ };
446
+ const res = {
447
+ status: (code) => {
448
+ statusCode = code;
449
+ return res;
450
+ },
451
+ send: (message) => {
452
+ responseMessage = message;
453
+ },
454
+ json: (body) => {
455
+ responseMessage = body;
456
+ },
457
+ jsonp: (body) => {
458
+ responseMessage = body;
459
+ },
460
+ setHeader: (key, value) => {
461
+ responseHeaders[key] = value;
462
+ }
463
+ };
464
+ let cursor = handlers.shift();
465
+ if (cursor) {
466
+ for (const fn of handlers) {
467
+ await cursor(req, res, (err) => {
468
+ if (err) {
469
+ throw err;
470
+ }
471
+ cursor = fn;
472
+ });
473
+ }
474
+ await cursor(req, res, async (err) => {
475
+ if (err) {
476
+ throw err;
477
+ }
478
+ });
479
+ }
480
+ const cHandler = controllerHandler;
481
+ await cHandler(req, res, (err) => {
482
+ if (err) {
483
+ throw err;
484
+ }
485
+ });
486
+ return {
487
+ code: statusCode,
488
+ response: responseMessage,
489
+ headers: responseHeaders
490
+ };
491
+ };
492
+ }
493
+ registerRoute(method, path, registrationMethod, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareAndTypedHandler) {
494
+ if (isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler)) {
495
+ const { contractDetails, handlers } = contractDetailsOrMiddlewareOrTypedHandler;
496
+ return this.registerRoute(
497
+ method,
498
+ path,
499
+ registrationMethod,
500
+ contractDetails,
501
+ ...handlers
502
+ );
503
+ } else {
504
+ const maybeTypedHandler = middlewareOrMiddlewareAndTypedHandler[middlewareOrMiddlewareAndTypedHandler.length - 1];
505
+ if (isTypedHandler(maybeTypedHandler)) {
506
+ const { contractDetails, handlers } = maybeTypedHandler;
507
+ return this.registerRoute(
508
+ method,
509
+ path,
510
+ registrationMethod,
511
+ contractDetails,
512
+ ...middlewareOrMiddlewareAndTypedHandler.concat(handlers)
513
+ );
514
+ } else {
515
+ if (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler)) {
516
+ throw new Error("Contract details are not defined");
517
+ }
518
+ const contractDetails = contractDetailsOrMiddlewareOrTypedHandler;
519
+ const handlers = middlewareOrMiddlewareAndTypedHandler.filter(
520
+ (handler) => isExpressLikeSchemaHandler(handler)
521
+ );
522
+ if (!isHttpContractDetails(contractDetails) && !isPathParamHttpContractDetails(contractDetails)) {
523
+ throw new Error(
524
+ "Contract details are malformed for route definition"
525
+ );
526
+ }
527
+ this.routes.push({
528
+ basePath: this.basePath,
529
+ path,
530
+ method,
531
+ contractDetails
532
+ });
533
+ const { requestSchema, responseSchemas } = this.#compile(contractDetails);
534
+ const controllerHandler = this.#extractControllerHandler(handlers);
535
+ registrationMethod.bind(this.internal)(
536
+ path,
537
+ ...this.#resolveMiddlewares(contractDetails, requestSchema, responseSchemas).concat(
538
+ handlers
539
+ ),
540
+ this.#parseAndRunControllerHandler(controllerHandler)
541
+ );
542
+ return this.#localParamRequest(
543
+ handlers,
544
+ controllerHandler
545
+ );
546
+ }
547
+ }
548
+ }
549
+ #extractHandlers(handlers, processMiddleware) {
550
+ const last = handlers.pop();
551
+ let finalHandlers = last ? [last] : [];
552
+ if (isTypedHandler(last)) {
553
+ finalHandlers = last.handlers;
554
+ }
555
+ handlers.forEach((handler) => {
556
+ if (isTypedHandler(handler)) {
557
+ throw new Error(
558
+ "Only the last argument supplied to this function can be a typed handler. Please use only middleware."
559
+ );
560
+ }
561
+ });
562
+ const middleware2 = processMiddleware ? handlers.map(processMiddleware) : handlers;
563
+ return [...middleware2, ...finalHandlers];
564
+ }
565
+ #extractMiddlewareFromEnrichedTypedHandlerArray(handlers) {
566
+ return this.#extractHandlers(handlers);
567
+ }
568
+ #extractNestableMiddlewareFromEnrichedTypedHandlerArray(handlers) {
569
+ return this.#extractHandlers(
570
+ handlers,
571
+ (handler) => isForklaunchExpressLikeRouter(handler) ? handler.internal : handler
572
+ );
573
+ }
574
+ #processTypedHandlerOrMiddleware(handler, middleware2) {
575
+ if (isTypedHandler(handler)) {
576
+ middleware2.push(...handler.handlers);
577
+ } else if (isExpressLikeSchemaHandler(handler)) {
578
+ middleware2.push(handler);
579
+ }
580
+ }
581
+ #extractMiddlewareAsRouterHandlers(contractDetailsOrMiddlewareOrTypedHandler, middlewareOrMiddlewareWithTypedHandler) {
582
+ const middleware2 = [];
583
+ this.#processTypedHandlerOrMiddleware(contractDetailsOrMiddlewareOrTypedHandler, middleware2);
584
+ middleware2.push(
585
+ ...this.#extractMiddlewareFromEnrichedTypedHandlerArray(middlewareOrMiddlewareWithTypedHandler)
586
+ );
587
+ return middleware2;
588
+ }
589
+ #extractNestableMiddlewareAsRouterHandlers(contractDetailsOrMiddlewareOrTypedHandler, middlewareOrMiddlewareWithTypedHandler) {
590
+ const middleware2 = [];
591
+ this.#processTypedHandlerOrMiddleware(
592
+ contractDetailsOrMiddlewareOrTypedHandler,
593
+ middleware2
594
+ );
595
+ if (isForklaunchExpressLikeRouter(
596
+ contractDetailsOrMiddlewareOrTypedHandler
597
+ )) {
598
+ middleware2.push(contractDetailsOrMiddlewareOrTypedHandler.internal);
599
+ }
600
+ middleware2.push(
601
+ ...this.#extractNestableMiddlewareFromEnrichedTypedHandlerArray(middlewareOrMiddlewareWithTypedHandler)
602
+ );
603
+ return middleware2;
604
+ }
605
+ registerMiddlewareHandler(registrationMethod, pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) {
606
+ const middleware2 = [];
607
+ if (typeof pathOrContractDetailsOrMiddlewareOrTypedHandler === "string") {
608
+ middleware2.push(
609
+ ...this.#extractMiddlewareAsRouterHandlers(
610
+ contractDetailsOrMiddlewareOrTypedHandler,
611
+ middlewareOrMiddlewareWithTypedHandler
612
+ )
613
+ );
614
+ const path = pathOrContractDetailsOrMiddlewareOrTypedHandler;
615
+ registrationMethod.bind(this.internal)(path, ...middleware2);
616
+ } else {
617
+ middleware2.push(
618
+ ...this.#extractMiddlewareAsRouterHandlers(
619
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
620
+ (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler) ? [contractDetailsOrMiddlewareOrTypedHandler] : []).concat(middlewareOrMiddlewareWithTypedHandler)
621
+ )
622
+ );
623
+ registrationMethod.bind(this.internal)(...middleware2);
624
+ }
625
+ return this;
626
+ }
627
+ registerNestableMiddlewareHandler(registrationMethod, pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) {
628
+ const middleware2 = [];
629
+ let path;
630
+ if (typeof pathOrContractDetailsOrMiddlewareOrTypedHandler === "string") {
631
+ middleware2.push(
632
+ ...this.#extractNestableMiddlewareAsRouterHandlers(
633
+ contractDetailsOrMiddlewareOrTypedHandler,
634
+ middlewareOrMiddlewareWithTypedHandler
635
+ )
636
+ );
637
+ path = pathOrContractDetailsOrMiddlewareOrTypedHandler;
638
+ } else {
639
+ if (isConstrainedForklaunchRouter(
640
+ pathOrContractDetailsOrMiddlewareOrTypedHandler
641
+ )) {
642
+ path = pathOrContractDetailsOrMiddlewareOrTypedHandler.basePath;
643
+ }
644
+ middleware2.push(
645
+ ...this.#extractNestableMiddlewareAsRouterHandlers(
646
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
647
+ (isExpressLikeSchemaHandler(contractDetailsOrMiddlewareOrTypedHandler) || isTypedHandler(contractDetailsOrMiddlewareOrTypedHandler) || isConstrainedForklaunchRouter(
648
+ contractDetailsOrMiddlewareOrTypedHandler
649
+ ) ? [contractDetailsOrMiddlewareOrTypedHandler] : []).concat(middlewareOrMiddlewareWithTypedHandler)
650
+ )
651
+ );
652
+ }
653
+ if (path) {
654
+ registrationMethod.bind(this.internal)(path, ...middleware2);
655
+ } else {
656
+ registrationMethod.bind(this.internal)(...middleware2);
657
+ }
658
+ return this;
659
+ }
660
+ use = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
661
+ [
662
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
663
+ contractDetailsOrMiddlewareOrTypedHandler,
664
+ ...middlewareOrMiddlewareWithTypedHandler
665
+ ].forEach((arg) => {
666
+ if (isForklaunchRouter(arg)) {
667
+ this.routers.push(arg);
668
+ }
669
+ });
670
+ return this.registerNestableMiddlewareHandler(
671
+ this.internal.use,
672
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
673
+ contractDetailsOrMiddlewareOrTypedHandler,
674
+ ...middlewareOrMiddlewareWithTypedHandler
675
+ );
676
+ };
677
+ all = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
678
+ return this.registerMiddlewareHandler(
679
+ this.internal.all,
680
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
681
+ contractDetailsOrMiddlewareOrTypedHandler,
682
+ ...middlewareOrMiddlewareWithTypedHandler
683
+ );
684
+ };
685
+ connect = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
686
+ return this.registerMiddlewareHandler(
687
+ this.internal.connect,
688
+ pathOrContractDetailsOrMiddlewareOrTypedHandler,
689
+ contractDetailsOrMiddlewareOrTypedHandler,
690
+ ...middlewareOrMiddlewareWithTypedHandler
691
+ );
692
+ };
693
+ /**
694
+ * Registers a GET route with the specified contract details and handler handlers.
695
+ *
696
+ * @template P - The type of request parameters.
697
+ * @template ResBodyMap - The type of response body.
698
+ * @template ReqBody - The type of request body.
699
+ * @template ReqQuery - The type of request query.
700
+ * @template LocalsObj - The type of local variables.
701
+ * @param {string} path - The path for the route.
702
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
703
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
704
+ * @returns {ExpressRouter} - The Express router.
705
+ */
706
+ get = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
707
+ return {
708
+ get: this.registerRoute(
709
+ "get",
710
+ path,
711
+ this.internal.get,
712
+ contractDetailsOrMiddlewareOrTypedHandler,
713
+ ...middlewareOrMiddlewareWithTypedHandler
714
+ )
715
+ };
716
+ };
717
+ /**
718
+ * Registers a POST route with the specified contract details and handler handlers.
719
+ *
720
+ * @template P - The type of request parameters.
721
+ * @template ResBodyMap - The type of response body.
722
+ * @template ReqBody - The type of request body.
723
+ * @template ReqQuery - The type of request query.
724
+ * @template LocalsObj - The type of local variables.
725
+ * @param {string} path - The path for the route.
726
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
727
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
728
+ * @returns {ExpressRouter} - The Expxwress router.
729
+ */
730
+ post = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
731
+ return {
732
+ post: this.registerRoute(
733
+ "post",
734
+ path,
735
+ this.internal.post,
736
+ contractDetailsOrMiddlewareOrTypedHandler,
737
+ ...middlewareOrMiddlewareWithTypedHandler
738
+ )
739
+ };
740
+ };
741
+ /**
742
+ * Registers a PUT route with the specified contract details and handler handlers.
743
+ *
744
+ * @template P - The type of request parameters.
745
+ * @template ResBodyMap - The type of response body.
746
+ * @template ReqBody - The type of request body.
747
+ * @template ReqQuery - The type of request query.
748
+ * @template LocalsObj - The type of local variables.
749
+ * @param {string} path - The path for the route.
750
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
751
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
752
+ * @returns {ExpressRouter} - The Express router.
753
+ */
754
+ put = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
755
+ return {
756
+ put: this.registerRoute(
757
+ "put",
758
+ path,
759
+ this.internal.put,
760
+ contractDetailsOrMiddlewareOrTypedHandler,
761
+ ...middlewareOrMiddlewareWithTypedHandler
762
+ )
763
+ };
764
+ };
765
+ /**
766
+ * Registers a PATCH route with the specified contract details and handler handlers.
767
+ *
768
+ * @template P - The type of request parameters.
769
+ * @template ResBodyMap - The type of response body.
770
+ * @template ReqBody - The type of request body.
771
+ * @template ReqQuery - The type of request query.
772
+ * @template LocalsObj - The type of local variables.
773
+ * @param {string} path - The path for the route.
774
+ * @param {HttpContractDetails<SV, P, ResBodyMap, ReqBody, ReqQuery>} contractDetails - The contract details.
775
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
776
+ * @returns {ExpressRouter} - The Express router.
777
+ */
778
+ patch = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
779
+ return {
780
+ patch: this.registerRoute(
781
+ "patch",
782
+ path,
783
+ this.internal.patch,
784
+ contractDetailsOrMiddlewareOrTypedHandler,
785
+ ...middlewareOrMiddlewareWithTypedHandler
786
+ )
787
+ };
788
+ };
789
+ /**
790
+ * Registers a DELETE route with the specified contract details and handler handlers.
791
+ *
792
+ * @template P - The type of request parameters.
793
+ * @template ResBodyMap - The type of response body.
794
+ * @template ReqBody - The type of request body.
795
+ * @template ReqQuery - The type of request query.
796
+ * @template LocalsObj - The type of local variables.
797
+ * @param {string} path - The path for the route.
798
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
799
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
800
+ * @returns {ExpressRouter} - The Express router.
801
+ */
802
+ delete = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
803
+ return {
804
+ delete: this.registerRoute(
805
+ "delete",
806
+ path,
807
+ this.internal.delete,
808
+ contractDetailsOrMiddlewareOrTypedHandler,
809
+ ...middlewareOrMiddlewareWithTypedHandler
810
+ )
811
+ };
812
+ };
813
+ /**
814
+ * Registers a OPTIONS route with the specified contract details and handler handlers.
815
+ *
816
+ * @template P - The type of request parameters.
817
+ * @template ResBodyMap - The type of response body.
818
+ * @template ReqBody - The type of request body.
819
+ * @template ReqQuery - The type of request query.
820
+ * @template LocalsObj - The type of local variables.
821
+ * @param {string} path - The path for the route.
822
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
823
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
824
+ * @returns {ExpressRouter} - The Express router.
825
+ */
826
+ options = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
827
+ return {
828
+ options: this.registerRoute(
829
+ "options",
830
+ path,
831
+ this.internal.options,
832
+ contractDetailsOrMiddlewareOrTypedHandler,
833
+ ...middlewareOrMiddlewareWithTypedHandler
834
+ )
835
+ };
836
+ };
837
+ /**
838
+ * Registers a HEAD route with the specified contract details and handler handlers.
839
+ *
840
+ * @template P - The type of request parameters.
841
+ * @template ResBodyMap - The type of response body.
842
+ * @template ReqBody - The type of request body.
843
+ * @template ReqQuery - The type of request query.
844
+ * @template LocalsObj - The type of local variables.
845
+ * @param {string} path - The path for the route.
846
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
847
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
848
+ * @returns {ExpressRouter} - The Express router.
849
+ */
850
+ head = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
851
+ return {
852
+ head: this.registerRoute(
853
+ "head",
854
+ path,
855
+ this.internal.head,
856
+ contractDetailsOrMiddlewareOrTypedHandler,
857
+ ...middlewareOrMiddlewareWithTypedHandler
858
+ )
859
+ };
860
+ };
861
+ /**
862
+ * Registers a TRACE route with the specified contract details and handler handlers.
863
+ *
864
+ * @template P - The type of request parameters.
865
+ * @template ResBodyMap - The type of response body.
866
+ * @template ReqBody - The type of request body.
867
+ * @template ReqQuery - The type of request query.
868
+ * @template LocalsObj - The type of local variables.
869
+ * @param {string} path - The path for the route.
870
+ * @param {PathParamHttpContractDetails<SV, P, ResBodyMap, ReqQuery>} contractDetails - The contract details.
871
+ * @param {...SchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, LocalsObj>[]} handlers - The handler handlers.
872
+ * @returns {ExpressRouter} - The Express router.
873
+ */
874
+ trace = (path, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
875
+ return {
876
+ trace: this.registerRoute(
877
+ "trace",
878
+ path,
879
+ this.internal.trace,
880
+ contractDetailsOrMiddlewareOrTypedHandler,
881
+ ...middlewareOrMiddlewareWithTypedHandler
882
+ )
883
+ };
884
+ };
885
+ };
886
+
887
+ // src/http/application/expressLikeApplication.ts
888
+ var ForklaunchExpressLikeApplication = class extends ForklaunchExpressLikeRouter {
889
+ /**
890
+ * Creates an instance of the Application class.
891
+ *
892
+ * @param {SV} schemaValidator - The schema validator.
893
+ */
894
+ constructor(schemaValidator, internal) {
895
+ super("/", schemaValidator, internal);
896
+ this.schemaValidator = schemaValidator;
897
+ this.internal = internal;
898
+ }
899
+ };
900
+
901
+ // src/http/handlers/typedHandler.ts
902
+ function typedHandler(_schemaValidator, _pathOrContractDetails, contractMethodOrContractDetails, contractDetailsOrHandler, ...handlerArray) {
903
+ let contractDetails;
904
+ let handlers;
905
+ if (typeof contractMethodOrContractDetails === "string") {
906
+ if (typeof contractDetailsOrHandler !== "function") {
907
+ contractDetails = contractDetailsOrHandler;
908
+ } else {
909
+ throw new Error("Invalid definition for contract details");
910
+ }
911
+ handlers = handlerArray;
912
+ } else {
913
+ contractDetails = contractMethodOrContractDetails;
914
+ if (typeof contractDetailsOrHandler === "function") {
915
+ handlers = [contractDetailsOrHandler, ...handlerArray];
916
+ } else {
917
+ throw new Error("Invalid definition for handler");
918
+ }
919
+ }
920
+ return {
921
+ _typedHandler: true,
922
+ contractDetails,
923
+ handlers
924
+ };
925
+ }
926
+
927
+ // src/http/handlers/delete.ts
928
+ var delete_ = (_schemaValidator, path, contractDetails, ...handlers) => {
929
+ return typedHandler(_schemaValidator, path, "delete", contractDetails, ...handlers);
930
+ };
931
+
932
+ // src/http/handlers/get.ts
933
+ var get = (_schemaValidator, path, contractDetails, ...handlers) => {
934
+ return typedHandler(_schemaValidator, path, "get", contractDetails, ...handlers);
935
+ };
936
+
937
+ // src/http/handlers/head.ts
938
+ var head = (_schemaValidator, path, contractDetails, ...handlers) => {
939
+ return typedHandler(_schemaValidator, path, "head", contractDetails, ...handlers);
940
+ };
941
+
942
+ // src/http/handlers/middleware.ts
943
+ var middleware = (_schemaValidator, path, contractDetails, ...handlers) => {
944
+ return typedHandler(_schemaValidator, path, "middleware", contractDetails, ...handlers);
945
+ };
946
+
947
+ // src/http/handlers/options.ts
948
+ var options = (_schemaValidator, path, contractDetails, ...handlers) => {
949
+ return typedHandler(_schemaValidator, path, "options", contractDetails, ...handlers);
950
+ };
951
+
952
+ // src/http/handlers/patch.ts
953
+ var patch = (_schemaValidator, path, contractDetails, ...handlers) => {
954
+ return typedHandler(_schemaValidator, path, "patch", contractDetails, ...handlers);
955
+ };
956
+
957
+ // src/http/handlers/post.ts
958
+ var post = (_schemaValidator, path, contractDetails, ...handlers) => {
959
+ return typedHandler(_schemaValidator, path, "post", contractDetails, ...handlers);
960
+ };
961
+
962
+ // src/http/handlers/put.ts
963
+ var put = (_schemaValidator, path, contractDetails, ...handlers) => {
964
+ return typedHandler(_schemaValidator, path, "put", contractDetails, ...handlers);
965
+ };
966
+
967
+ // src/http/handlers/trace.ts
968
+ var trace = (_schemaValidator, path, contractDetails, ...handlers) => {
969
+ return typedHandler(_schemaValidator, path, "trace", contractDetails, ...handlers);
970
+ };
971
+
972
+ // src/http/utils/httpStatusCodes.ts
973
+ var HTTPStatuses = {
974
+ /**
975
+ * The initial part of a request has been received and has not yet been
976
+ * rejected by the server. The server intends to send a final response after
977
+ * the request has been fully received and acted upon.
978
+ *
979
+ * When the request contains an Expect header field that includes a
980
+ * 100-continue expectation, the 100 response indicates that the server
981
+ * wishes to receive the request payload body. The client ought to continue
982
+ * sending the request and discard the 100 response.
983
+ *
984
+ * If the request did not contain an Expect header field containing the
985
+ * 100-continue expectation, the client can simply discard this interim
986
+ * response.
987
+ */
988
+ 100: "Continue",
989
+ /**
990
+ * The server understands and is willing to comply with the client's request,
991
+ * via the Upgrade header field, for a change in the application protocol
992
+ * being used on this connection.
993
+ *
994
+ * The server MUST generate an Upgrade header field in the response that
995
+ * indicates which protocol(s) will be switched to immediately after the
996
+ * empty line that terminates the 101 response.
997
+ *
998
+ * It is assumed that the server will only agree to switch protocols when it
999
+ * is advantageous to do so. For example, switching to a newer version of
1000
+ * HTTP might be advantageous over older versions, and switching to a
1001
+ * real-time, synchronous protocol might be advantageous when delivering
1002
+ * resources that use such features.
1003
+ */
1004
+ 101: "Switching Protocols",
1005
+ /**
1006
+ * An interim response used to inform the client that the server has accepted
1007
+ * the complete request, but has not yet completed it.
1008
+ *
1009
+ * This status code SHOULD only be sent when the server has a reasonable
1010
+ * expectation that the request will take significant time to complete. As
1011
+ * guidance, if a method is taking longer than 20 seconds (a reasonable, but
1012
+ * arbitrary value) to process the server SHOULD return a 102 (Processing)
1013
+ * response. The server MUST send a final response after the request has been
1014
+ * completed.
1015
+ *
1016
+ * Methods can potentially take a long period of time to process, especially
1017
+ * methods that support the Depth header. In such cases the client may
1018
+ * time-out the connection while waiting for a response. To prevent this the
1019
+ * server may return a 102 Processing status code to indicate to the client
1020
+ * that the server is still processing the method.
1021
+ */
1022
+ 102: "Processing",
1023
+ /**
1024
+ * The request has succeeded.
1025
+ *
1026
+ * Aside from responses to CONNECT, a 200 response always has a payload,
1027
+ * though an origin server MAY generate a payload body of zero length. If no
1028
+ * payload is desired, an origin server ought to send 204 No Content instead.
1029
+ * For CONNECT, no payload is allowed because the successful result is a
1030
+ * tunnel, which begins immediately after the 200 response header section.
1031
+ *
1032
+ * A 200 response is cacheable by default; i.e., unless otherwise indicated
1033
+ * by the method definition or explicit cache controls.
1034
+ */
1035
+ 200: "OK",
1036
+ /**
1037
+ * The request has been fulfilled and has resulted in one or more new
1038
+ * resources being created.
1039
+ *
1040
+ * The primary resource created by the request is identified by either a
1041
+ * Location header field in the response or, if no Location field is
1042
+ * received, by the effective request URI.
1043
+ *
1044
+ * The 201 response payload typically describes and links to the resource(s)
1045
+ * created. See Section 7.2 of RFC7231 for a discussion of the meaning and
1046
+ * purpose of validator header fields, such as ETag and Last-Modified, in a
1047
+ * 201 response.
1048
+ */
1049
+ 201: "Created",
1050
+ /**
1051
+ * The request has been accepted for processing, but the processing has not
1052
+ * been completed. The request might or might not eventually be acted upon,
1053
+ * as it might be disallowed when processing actually takes place.
1054
+ *
1055
+ * There is no facility in HTTP for re-sending a status code from an
1056
+ * asynchronous operation.
1057
+ *
1058
+ * The 202 response is intentionally noncommittal. Its purpose is to allow a
1059
+ * server to accept a request for some other process (perhaps a
1060
+ * batch-oriented process that is only run once per day) without requiring
1061
+ * that the user agent's connection to the server persist until the process
1062
+ * is completed. The representation sent with this response ought to describe
1063
+ * the request's current status and point to (or embed) a status monitor that
1064
+ * can provide the user with an estimate of when the request will be
1065
+ * fulfilled.
1066
+ */
1067
+ 202: "Accepted",
1068
+ /**
1069
+ * The request was successful but the enclosed payload has been modified from
1070
+ * that of the origin server's 200 OK response by a transforming proxy.
1071
+ *
1072
+ * This status code allows the proxy to notify recipients when a
1073
+ * transformation has been applied, since that knowledge might impact later
1074
+ * decisions regarding the content. For example, future cache validation
1075
+ * requests for the content might only be applicable along the same request
1076
+ * path (through the same proxies).
1077
+ *
1078
+ * The 203 response is similar to the Warning code of 214 Transformation
1079
+ * Applied, which has the advantage of being applicable to responses with any
1080
+ * status code.
1081
+ *
1082
+ * A 203 response is cacheable by default; i.e., unless otherwise indicated
1083
+ * by the method definition or explicit cache controls.
1084
+ */
1085
+ 203: "Non-authoritative Information",
1086
+ /**
1087
+ * The server has successfully fulfilled the request and that there is no
1088
+ * additional content to send in the response payload body.
1089
+ *
1090
+ * Metadata in the response header fields refer to the target resource and
1091
+ * its selected representation after the requested action was applied.
1092
+ *
1093
+ * A 204 response is terminated by the first empty line after the header
1094
+ * fields because it cannot contain a message body.
1095
+ *
1096
+ * A 204 response is cacheable by default; i.e., unless otherwise indicated
1097
+ * by the method definition or explicit cache controls.
1098
+ */
1099
+ 204: "No Content",
1100
+ /**
1101
+ * He server has fulfilled the request and desires that the user agent reset
1102
+ * the "document view", which caused the request to be sent, to its original
1103
+ * state as received from the origin server.
1104
+ *
1105
+ * This response is intended to support a common data entry use case where
1106
+ * the user receives content that supports data entry (a form, notepad,
1107
+ * canvas, etc.), enters or manipulates data in that space, causes the
1108
+ * entered data to be submitted in a request, and then the data entry
1109
+ * mechanism is reset for the next entry so that the user can easily
1110
+ * initiate another input action.
1111
+ *
1112
+ * Since the 205 status code implies that no additional content will be
1113
+ * provided, a server MUST NOT generate a payload in a 205 response. In
1114
+ * other words, a server MUST do one of the following for a 205 response: a)
1115
+ * indicate a zero-length body for the response by including a
1116
+ * Content-Length header field with a value of 0; b) indicate a zero-length
1117
+ * payload for the response by including a Transfer-Encoding header field
1118
+ * with a value of chunked and a message body consisting of a single chunk
1119
+ * of zero-length; or, c) close the connection immediately after sending the
1120
+ * blank line terminating the header section.
1121
+ */
1122
+ 205: "Reset Content",
1123
+ /**
1124
+ * The server is successfully fulfilling a range request for the target
1125
+ * resource by transferring one or more parts of the selected representation
1126
+ * that correspond to the satisfiable ranges found in the request's Range
1127
+ * header field.
1128
+ *
1129
+ * If a single part is being transferred, the server generating the 206
1130
+ * response MUST generate a Content-Range header field, describing what range
1131
+ * of the selected representation is enclosed, and a payload consisting of
1132
+ * the range.
1133
+ *
1134
+ * If multiple parts are being transferred, the server generating the 206
1135
+ * response MUST generate a "multipart/byteranges" payload2, and a
1136
+ * Content-Type header field containing the multipart/byteranges media type
1137
+ * and its required boundary parameter. To avoid confusion with single-part
1138
+ * responses, a server MUST NOT generate a Content-Range header field in the
1139
+ * HTTP header section of a multiple part response (this field will be sent
1140
+ * in each part instead).
1141
+ *
1142
+ * Within the header area of each body part in the multipart payload, the
1143
+ * server MUST generate a Content-Range header field corresponding to the
1144
+ * range being enclosed in that body part. If the selected representation
1145
+ * would have had a Content-Type header field in a 200 OK response, the
1146
+ * server SHOULD generate that same Content-Type field in the header area of
1147
+ * each body part.
1148
+ *
1149
+ * When multiple ranges are requested, a server MAY coalesce any of the
1150
+ * ranges that overlap, or that are separated by a gap that is smaller than
1151
+ * the overhead of sending multiple parts, regardless of the order in which
1152
+ * the corresponding byte-range-spec appeared in the received Range header
1153
+ * field. Since the typical overhead between parts of a multipart/byteranges
1154
+ * payload is around 80 bytes, depending on the selected representation's
1155
+ * media type and the chosen boundary parameter length, it can be less
1156
+ * efficient to transfer many small disjoint parts than it is to transfer the
1157
+ * entire selected representation.
1158
+ *
1159
+ * A server MUST NOT generate a multipart response to a request for a single
1160
+ * range, since a client that does not request multiple parts might not
1161
+ * support multipart responses. However, a server MAY generate a
1162
+ * multipart/byteranges payload with only a single body part if multiple
1163
+ * ranges were requested and only one range was found to be satisfiable or
1164
+ * only one range remained after coalescing. A client that cannot process a
1165
+ * multipart/byteranges response MUST NOT generate a request that asks for
1166
+ * multiple ranges.
1167
+ *
1168
+ * When a multipart response payload is generated, the server SHOULD send the
1169
+ * parts in the same order that the corresponding byte-range-spec appeared in
1170
+ * the received Range header field, excluding those ranges that were deemed
1171
+ * unsatisfiable or that were coalesced into other ranges. A client that
1172
+ * receives a multipart response MUST inspect the Content-Range header field
1173
+ * present in each body part in order to determine which range is contained
1174
+ * in that body part; a client cannot rely on receiving the same ranges that
1175
+ * it requested, nor the same order that it requested.
1176
+ *
1177
+ * When a 206 response is generated, the server MUST generate the following
1178
+ * header fields, in addition to those required above, if the field would
1179
+ * have been sent in a 200 OK response to the same request: Date,
1180
+ * Cache-Control, ETag, Expires, Content-Location, and Vary.
1181
+ *
1182
+ * If a 206 is generated in response to a request with an If-Range header
1183
+ * field, the sender SHOULD NOT generate other representation header fields
1184
+ * beyond those required above, because the client is understood to already
1185
+ * have a prior response containing those header fields. Otherwise, the
1186
+ * sender MUST generate all of the representation header fields that would
1187
+ * have been sent in a 200 OK response to the same request.
1188
+ *
1189
+ * A 206 response is cacheable by default; i.e., unless otherwise indicated
1190
+ * by explicit cache controls.
1191
+ */
1192
+ 206: "Partial Content",
1193
+ /**
1194
+ * A Multi-Status response conveys information about multiple resources in
1195
+ * situations where multiple status codes might be appropriate.
1196
+ *
1197
+ * The default Multi-Status response body is a text/xml or application/xml
1198
+ * HTTP entity with a 'multistatus' root element. Further elements contain
1199
+ * 200, 300, 400, and 500 series status codes generated during the method
1200
+ * invocation. 100 series status codes SHOULD NOT be recorded in a 'response'
1201
+ * XML element.
1202
+ *
1203
+ * Although '207' is used as the overall response status code, the recipient
1204
+ * needs to consult the contents of the multistatus response body for further
1205
+ * information about the success or failure of the method execution. The
1206
+ * response MAY be used in success, partial success and also in failure
1207
+ * situations.
1208
+ *
1209
+ * The 'multistatus' root element holds zero or more 'response' elements in
1210
+ * any order, each with information about an individual resource. Each
1211
+ * 'response' element MUST have an 'href' element to identify the resource.
1212
+ *
1213
+ * A Multi-Status response uses one out of two distinct formats for
1214
+ * representing the status:
1215
+ *
1216
+ * 1. A 'status' element as child of the 'response' element indicates the
1217
+ * status of the message execution for the identified resource as a whole.
1218
+ * Some method definitions provide information about specific status codes
1219
+ * clients should be prepared to see in a response. However, clients MUST be
1220
+ * able to handle other status codes, using the generic rules defined in
1221
+ * RFC2616 Section 10.
1222
+ *
1223
+ * 2. For PROPFIND and PROPPATCH, the format has been extended using the
1224
+ * 'propstat' element instead of 'status', providing information about
1225
+ * individual properties of a resource. This format is specific to PROPFIND
1226
+ * and PROPPATCH, and is described in detail in RFC4918 Section 9.1 and
1227
+ * RFC4918 Section 9.2.
1228
+ */
1229
+ 207: "Multi-Status",
1230
+ /**
1231
+ * Used inside a DAV: propstat response element to avoid enumerating the
1232
+ * internal members of multiple bindings to the same collection repeatedly.
1233
+ *
1234
+ * For each binding to a collection inside the request's scope, only one will
1235
+ * be reported with a 200 status, while subsequent DAV:response elements for
1236
+ * all other bindings will use the 208 status, and no DAV:response elements
1237
+ * for their descendants are included.
1238
+ *
1239
+ * Note that the 208 status will only occur for "Depth: infinity" requests,
1240
+ * and that it is of particular importance when the multiple collection
1241
+ * bindings cause a bind loop.
1242
+ *
1243
+ * A client can request the DAV:resource-id property in a PROPFIND request to
1244
+ * guarantee that they can accurately reconstruct the binding structure of a
1245
+ * collection with multiple bindings to a single resource.
1246
+ *
1247
+ * For backward compatibility with clients not aware of the 208 status code
1248
+ * appearing in multistatus response bodies, it SHOULD NOT be used unless the
1249
+ * client has signaled support for this specification using the "DAV" request
1250
+ * header. Instead, a 508 Loop Detected status should be returned when a
1251
+ * binding loop is discovered. This allows the server to return the 508 as
1252
+ * the top-level return status, if it discovers it before it started the
1253
+ * response, or in the middle of a multistatus, if it discovers it in the
1254
+ * middle of streaming out a multistatus response.
1255
+ */
1256
+ 208: "Already Reported",
1257
+ /**
1258
+ * The server has fulfilled a GET request for the resource, and the response
1259
+ * is a representation of the result of one or more instance-manipulations
1260
+ * applied to the current instance.
1261
+ *
1262
+ * The actual current instance might not be available except by combining
1263
+ * this response with other previous or future responses, as appropriate for
1264
+ * the specific instance-manipulation(s). If so, the headers of the resulting
1265
+ * instance are the result of combining the headers from the 226 response and
1266
+ * the other instances, following the rules in section 13.5.3 of the HTTP/1.1
1267
+ * specification.
1268
+ *
1269
+ * The request MUST have included an A-IM header field listing at least one
1270
+ * instance-manipulation. The response MUST include an Etag header field
1271
+ * giving the entity tag of the current instance.
1272
+ *
1273
+ * A response received with a status code of 226 MAY be stored by a cache and
1274
+ * used in reply to a subsequent request, subject to the HTTP expiration
1275
+ * mechanism and any Cache-Control headers, and to the requirements in
1276
+ * section 10.6.
1277
+ *
1278
+ * A response received with a status code of 226 MAY be used by a cache, in
1279
+ * conjunction with a cache entry for the base instance, to create a cache
1280
+ * entry for the current instance.
1281
+ */
1282
+ 226: "IM Used",
1283
+ /**
1284
+ * The target resource has more than one representation, each with its own
1285
+ * more specific identifier, and information about the alternatives is being
1286
+ * provided so that the user (or user agent) can select a preferred
1287
+ * representation by redirecting its request to one or more of those
1288
+ * identifiers.
1289
+ *
1290
+ * In other words, the server desires that the user agent engage in reactive
1291
+ * negotiation to select the most appropriate representation(s) for its
1292
+ * needs.
1293
+ *
1294
+ * If the server has a preferred choice, the server SHOULD generate a
1295
+ * Location header field containing a preferred choice's URI reference. The
1296
+ * user agent MAY use the Location field value for automatic redirection.
1297
+ *
1298
+ * For request methods other than HEAD, the server SHOULD generate a payload
1299
+ * in the 300 response containing a list of representation metadata and URI
1300
+ * reference(s) from which the user or user agent can choose the one most
1301
+ * preferred. The user agent MAY make a selection from that list
1302
+ * automatically if it understands the provided media type. A specific format
1303
+ * for automatic selection is not defined by this specification because HTTP
1304
+ * tries to remain orthogonal to the definition of its payloads. In practice,
1305
+ * the representation is provided in some easily parsed format believed to be
1306
+ * acceptable to the user agent, as determined by shared design or content
1307
+ * negotiation, or in some commonly accepted hypertext format.
1308
+ *
1309
+ * A 300 response is cacheable by default; i.e., unless otherwise indicated
1310
+ * by the method definition or explicit cache controls.
1311
+ *
1312
+ * Note: The original proposal for the 300 status code defined the URI header
1313
+ * field as providing a list of alternative representations, such that it
1314
+ * would be usable for 200, 300, and 406 responses and be transferred in
1315
+ * responses to the HEAD method. However, lack of deployment and disagreement
1316
+ * over syntax led to both URI and Alternates (a subsequent proposal) being
1317
+ * dropped from this specification. It is possible to communicate the list
1318
+ * using a set of Link header fields3, each with a relationship of
1319
+ * "alternate", though deployment is a chicken-and-egg problem.
1320
+ */
1321
+ 300: "Multiple Choices",
1322
+ /**
1323
+ * The target resource has been assigned a new permanent URI and any future
1324
+ * references to this resource ought to use one of the enclosed URIs.
1325
+ *
1326
+ * Clients with link-editing capabilities ought to automatically re-link
1327
+ * references to the effective request URI to one or more of the new
1328
+ * references sent by the server, where possible.
1329
+ *
1330
+ * The server SHOULD generate a Location header field in the response
1331
+ * containing a preferred URI reference for the new permanent URI. The user
1332
+ * agent MAY use the Location field value for automatic redirection. The
1333
+ * server's response payload usually contains a short hypertext note with a
1334
+ * hyperlink to the new URI(s).
1335
+ *
1336
+ * Note: For historical reasons, a user agent MAY change the request method
1337
+ * from POST to GET for the subsequent request. If this behavior is
1338
+ * undesired, the 307 Temporary Redirect status code can be used instead.
1339
+ *
1340
+ * A 301 response is cacheable by default; i.e., unless otherwise indicated
1341
+ * by the method definition or explicit cache controls.
1342
+ */
1343
+ 301: "Moved Permanently",
1344
+ /**
1345
+ * The target resource resides temporarily under a different URI. Since the
1346
+ * redirection might be altered on occasion, the client ought to continue to
1347
+ * use the effective request URI for future requests.
1348
+ *
1349
+ * The server SHOULD generate a Location header field in the response
1350
+ * containing a URI reference for the different URI. The user agent MAY use
1351
+ * the Location field value for automatic redirection. The server's response
1352
+ * payload usually contains a short hypertext note with a hyperlink to the
1353
+ * different URI(s).
1354
+ *
1355
+ * Note: For historical reasons, a user agent MAY change the request method
1356
+ * from POST to GET for the subsequent request. If this behavior is
1357
+ * undesired, the 307 Temporary Redirect status code can be used instead.
1358
+ */
1359
+ 302: "Found",
1360
+ /**
1361
+ * The server is redirecting the user agent to a different resource, as
1362
+ * indicated by a URI in the Location header field, which is intended to
1363
+ * provide an indirect response to the original request.
1364
+ *
1365
+ * A user agent can perform a retrieval request targeting that URI (a GET or
1366
+ * HEAD request if using HTTP), which might also be redirected, and present
1367
+ * the eventual result as an answer to the original request. Note that the
1368
+ * new URI in the Location header field is not considered equivalent to the
1369
+ * effective request URI.
1370
+ *
1371
+ * This status code is applicable to any HTTP method. It is primarily used
1372
+ * to allow the output of a POST action to redirect the user agent to a
1373
+ * selected resource, since doing so provides the information corresponding
1374
+ * to the POST response in a form that can be separately identified,
1375
+ * bookmarked, and cached, independent of the original request.
1376
+ *
1377
+ * A 303 response to a GET request indicates that the origin server does not
1378
+ * have a representation of the target resource that can be transferred by
1379
+ * the server over HTTP. However, the Location field value refers to a
1380
+ * resource that is descriptive of the target resource, such that making a
1381
+ * retrieval request on that other resource might result in a representation
1382
+ * that is useful to recipients without implying that it represents the
1383
+ * original target resource. Note that answers to the questions of what can
1384
+ * be represented, what representations are adequate, and what might be a
1385
+ * useful description are outside the scope of HTTP.
1386
+ *
1387
+ * Except for responses to a HEAD request, the representation of a 303
1388
+ * response ought to contain a short hypertext note with a hyperlink to the
1389
+ * same URI reference provided in the Location header field.
1390
+ */
1391
+ 303: "See Other",
1392
+ /**
1393
+ * A conditional GET or HEAD request has been received and would have
1394
+ * resulted in a 200 OK response if it were not for the fact that the
1395
+ * condition evaluated to false.
1396
+ *
1397
+ * In other words, there is no need for the server to transfer a
1398
+ * representation of the target resource because the request indicates that
1399
+ * the client, which made the request conditional, already has a valid
1400
+ * representation; the server is therefore redirecting the client to make
1401
+ * use of that stored representation as if it were the payload of a 200 OK
1402
+ * response.
1403
+ *
1404
+ * The server generating a 304 response MUST generate any of the following
1405
+ * header fields that would have been sent in a 200 OK response to the same
1406
+ * request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.
1407
+ *
1408
+ * Since the goal of a 304 response is to minimize information transfer when
1409
+ * the recipient already has one or more cached representations, a sender
1410
+ * SHOULD NOT generate representation metadata other than the above listed
1411
+ * fields unless said metadata exists for the purpose of guiding cache
1412
+ * updates (e.g., Last-Modified might be useful if the response does not have
1413
+ * an ETag field).
1414
+ *
1415
+ * Requirements on a cache that receives a 304 response are defined in
1416
+ * Section 4.3.4 of RFC7234. If the conditional request originated with an
1417
+ * outbound client, such as a user agent with its own cache sending a
1418
+ * conditional GET to a shared proxy, then the proxy SHOULD forward the
1419
+ * 304 response to that client.
1420
+ *
1421
+ * A 304 response cannot contain a message-body; it is always terminated by
1422
+ * the first empty line after the header fields.
1423
+ */
1424
+ 304: "Not Modified",
1425
+ /**
1426
+ * Defined in a previous version of this specification and is now deprecated,
1427
+ * due to security concerns regarding in-band configuration of a proxy.
1428
+ */
1429
+ 305: "Use Proxy",
1430
+ /**
1431
+ * The target resource resides temporarily under a different URI and the user
1432
+ * agent MUST NOT change the request method if it performs an automatic
1433
+ * redirection to that URI.
1434
+ *
1435
+ * Since the redirection can change over time, the client ought to continue
1436
+ * using the original effective request URI for future requests.
1437
+ *
1438
+ * The server SHOULD generate a Location header field in the response
1439
+ * containing a URI reference for the different URI. The user agent MAY use
1440
+ * the Location field value for automatic redirection. The server's response
1441
+ * payload usually contains a short hypertext note with a hyperlink to the
1442
+ * different URI(s).
1443
+ *
1444
+ * Note: This status code is similar to 302 Found, except that it does not
1445
+ * allow changing the request method from POST to GET. This specification
1446
+ * defines no equivalent counterpart for 301 Moved Permanently (RFC7238,
1447
+ * however, proposes defining the status code 308 Permanent Redirect for
1448
+ * this purpose).
1449
+ */
1450
+ 307: "Temporary Redirect",
1451
+ /**
1452
+ * The target resource has been assigned a new permanent URI and any future
1453
+ * references to this resource ought to use one of the enclosed URIs.
1454
+ *
1455
+ * Clients with link editing capabilities ought to automatically re-link
1456
+ * references to the effective request URI to one or more of the new
1457
+ * references sent by the server, where possible.
1458
+ *
1459
+ * The server SHOULD generate a Location header field in the response
1460
+ * containing a preferred URI reference for the new permanent URI. The user
1461
+ * agent MAY use the Location field value for automatic redirection. The
1462
+ * server's response payload usually contains a short hypertext note with a
1463
+ * hyperlink to the new URI(s).
1464
+ *
1465
+ * A 308 response is cacheable by default; i.e., unless otherwise indicated
1466
+ * by the method definition or explicit cache controls.
1467
+ *
1468
+ * Note: This status code is similar to 301 Moved Permanently, except that it
1469
+ * does not allow changing the request method from POST to GET.
1470
+ */
1471
+ 308: "Permanent Redirect",
1472
+ /**
1473
+ * The 400 (Bad Request) status code indicates that the server cannot or
1474
+ * will not process the request due to something that is perceived to be
1475
+ * a client error (e.g., malformed request syntax, invalid request
1476
+ * message framing, or deceptive request routing).
1477
+ */
1478
+ 400: "Bad Request",
1479
+ /**
1480
+ * The request has not been applied because it lacks valid authentication
1481
+ * credentials for the target resource.
1482
+ *
1483
+ * The server generating a 401 response MUST send a WWW-Authenticate header
1484
+ * field containing at least one challenge applicable to the target resource.
1485
+ *
1486
+ * If the request included authentication credentials, then the 401 response
1487
+ * indicates that authorization has been refused for those credentials. The
1488
+ * user agent MAY repeat the request with a new or replaced Authorization
1489
+ * header field. If the 401 response contains the same challenge as the
1490
+ * prior response, and the user agent has already attempted authentication at
1491
+ * least once, then the user agent SHOULD present the enclosed representation
1492
+ * to the user, since it usually contains relevant diagnostic information.
1493
+ */
1494
+ 401: "Unauthorized",
1495
+ /**
1496
+ * The 402 (Payment Required) status code is reserved for future use.
1497
+ */
1498
+ 402: "Payment Required",
1499
+ /**
1500
+ * The 403 (Forbidden) status code indicates that the server understood
1501
+ * the request but refuses to authorize it. A server that wishes to
1502
+ * make public why the request has been forbidden can describe that
1503
+ * reason in the response payload (if any).
1504
+ *
1505
+ * If authentication credentials were provided in the request, the
1506
+ * server considers them insufficient to grant access. The client
1507
+ * SHOULD NOT automatically repeat the request with the same
1508
+ * credentials. The client MAY repeat the request with new or different
1509
+ * credentials. However, a request might be forbidden for reasons
1510
+ * unrelated to the credentials.
1511
+ *
1512
+ * An origin server that wishes to "hide" the current existence of a
1513
+ * forbidden target resource MAY instead respond with a status code of
1514
+ * 404 (Not Found).
1515
+ */
1516
+ 403: "Forbidden",
1517
+ /**
1518
+ * The 404 (Not Found) status code indicates that the origin server did
1519
+ * not find a current representation for the target resource or is not
1520
+ * willing to disclose that one exists. A 404 status code does not
1521
+ * indicate whether this lack of representation is temporary or
1522
+ * permanent; the 410 (Gone) status code is preferred over 404 if the
1523
+ * origin server knows, presumably through some configurable means, that
1524
+ * the condition is likely to be permanent.
1525
+ *
1526
+ * A 404 response is cacheable by default; i.e., unless otherwise
1527
+ * indicated by the method definition or explicit cache controls (see
1528
+ * Section 4.2.2 of [RFC7234]).
1529
+ */
1530
+ 404: "Not Found",
1531
+ /**
1532
+ * The 405 (Method Not Allowed) status code indicates that the method
1533
+ * received in the request-line is known by the origin server but not
1534
+ * supported by the target resource. The origin server MUST generate an
1535
+ * Allow header field in a 405 response containing a list of the target
1536
+ * resource's currently supported methods.
1537
+ *
1538
+ * A 405 response is cacheable by default; i.e., unless otherwise
1539
+ * indicated by the method definition or explicit cache controls (see
1540
+ * Section 4.2.2 of [RFC7234]).
1541
+ */
1542
+ 405: "Method Not Allowed",
1543
+ /**
1544
+ * The 406 (Not Acceptable) status code indicates that the target
1545
+ * resource does not have a current representation that would be
1546
+ * acceptable to the user agent, according to the proactive negotiation
1547
+ * header fields received in the request (Section 5.3), and the server
1548
+ * is unwilling to supply a default representation.
1549
+ *
1550
+ * The server SHOULD generate a payload containing a list of available
1551
+ * representation characteristics and corresponding resource identifiers
1552
+ * from which the user or user agent can choose the one most
1553
+ * appropriate. A user agent MAY automatically select the most
1554
+ * appropriate choice from that list. However, this specification does
1555
+ * not define any standard for such automatic selection, as described in
1556
+ * Section 6.4.1 of [RFC7231]
1557
+ */
1558
+ 406: "Not Acceptable",
1559
+ /**
1560
+ * Similar to 401 Unauthorized, but it indicates that the client needs to
1561
+ * authenticate itself in order to use a proxy.
1562
+ *
1563
+ * The proxy MUST send a Proxy-Authenticate header field containing a
1564
+ * challenge applicable to that proxy for the target resource. The client MAY
1565
+ * repeat the request with a new or replaced Proxy-Authorization header field.
1566
+ */
1567
+ 407: "Proxy Authentication Required",
1568
+ /**
1569
+ * The 408 (Request Timeout) status code indicates that the server did
1570
+ * not receive a complete request message within the time that it was
1571
+ * prepared to wait. A server SHOULD send the "close" connection option
1572
+ * (Section 6.1 of [RFC7230]) in the response, since 408 implies that
1573
+ * the server has decided to close the connection rather than continue
1574
+ * waiting. If the client has an outstanding request in transit, the
1575
+ * client MAY repeat that request on a new connection.
1576
+ */
1577
+ 408: "Request Timeout",
1578
+ /**
1579
+ * The 409 (Conflict) status code indicates that the request could not
1580
+ * be completed due to a conflict with the current state of the target
1581
+ * resource. This code is used in situations where the user might be
1582
+ * able to resolve the conflict and resubmit the request. The server
1583
+ * SHOULD generate a payload that includes enough information for a user
1584
+ * to recognize the source of the conflict.
1585
+ *
1586
+ * Conflicts are most likely to occur in response to a PUT request. For
1587
+ * example, if versioning were being used and the representation being
1588
+ * PUT included changes to a resource that conflict with those made by
1589
+ * an earlier (third-party) request, the origin server might use a 409
1590
+ * response to indicate that it can't complete the request. In this
1591
+ * case, the response representation would likely contain information
1592
+ * useful for merging the differences based on the revision history.
1593
+ */
1594
+ 409: "Conflict",
1595
+ /**
1596
+ * The 410 (Gone) status code indicates that access to the target
1597
+ * resource is no longer available at the origin server and that this
1598
+ * condition is likely to be permanent. If the origin server does not
1599
+ * know, or has no facility to determine, whether or not the condition
1600
+ * is permanent, the status code 404 (Not Found) ought to be used
1601
+ * instead.
1602
+ *
1603
+ * The 410 response is primarily intended to assist the task of web
1604
+ * maintenance by notifying the recipient that the resource is
1605
+ * intentionally unavailable and that the server owners desire that
1606
+ * remote links to that resource be removed. Such an event is common
1607
+ * for limited-time, promotional services and for resources belonging to
1608
+ * individuals no longer associated with the origin server's site. It
1609
+ * is not necessary to mark all permanently unavailable resources as
1610
+ * "gone" or to keep the mark for any length of time -- that is left to
1611
+ * the discretion of the server owner.
1612
+ *
1613
+ * A 410 response is cacheable by default; i.e., unless otherwise
1614
+ * indicated by the method definition or explicit cache controls (see
1615
+ * Section 4.2.2 of [RFC7234]).
1616
+ */
1617
+ 410: "Gone",
1618
+ /**
1619
+ * The 411 (Length Required) status code indicates that the server
1620
+ * refuses to accept the request without a defined Content-Length
1621
+ * (Section 3.3.2 of [RFC7230]). The client MAY repeat the request if
1622
+ * it adds a valid Content-Length header field containing the length of
1623
+ * the message body in the request message.
1624
+ */
1625
+ 411: "Length Required",
1626
+ /**
1627
+ * One or more conditions given in the request header fields evaluated to
1628
+ * false when tested on the server.
1629
+ *
1630
+ * This response code allows the client to place preconditions on the current
1631
+ * resource state (its current representations and metadata) and, thus,
1632
+ * prevent the request method from being applied if the target resource is in
1633
+ * an unexpected state.
1634
+ */
1635
+ 412: "Precondition Failed",
1636
+ /**
1637
+ * The 413 (Payload Too Large) status code indicates that the server is
1638
+ * refusing to process a request because the request payload is larger
1639
+ * than the server is willing or able to process. The server MAY close
1640
+ * the connection to prevent the client from continuing the request.
1641
+ *
1642
+ * If the condition is temporary, the server SHOULD generate a
1643
+ * Retry-After header field to indicate that it is temporary and after
1644
+ * what time the client MAY try again.
1645
+ */
1646
+ 413: "Payload Too Large",
1647
+ /**
1648
+ * The 414 (URI Too Long) status code indicates that the server is
1649
+ * refusing to service the request because the request-target (Section
1650
+ * 5.3 of [RFC7230]) is longer than the server is willing to interpret.
1651
+ * This rare condition is only likely to occur when a client has
1652
+ * improperly converted a POST request to a GET request with long query
1653
+ * information, when the client has descended into a "black hole" of
1654
+ * redirection (e.g., a redirected URI prefix that points to a suffix of
1655
+ * itself) or when the server is under attack by a client attempting to
1656
+ * exploit potential security holes.
1657
+ *
1658
+ * A 414 response is cacheable by default; i.e., unless otherwise
1659
+ * indicated by the method definition or explicit cache controls (see
1660
+ * Section 4.2.2 of [RFC7234]).
1661
+ */
1662
+ 414: "Request-URI Too Long",
1663
+ /**
1664
+ * The 415 (Unsupported Media Type) status code indicates that the
1665
+ * origin server is refusing to service the request because the payload
1666
+ * is in a format not supported by this method on the target resource.
1667
+ * The format problem might be due to the request's indicated
1668
+ * Content-Type or Content-Encoding, or as a result of inspecting the
1669
+ * data directly.
1670
+ */
1671
+ 415: "Unsupported Media Type",
1672
+ /**
1673
+ * None of the ranges in the request's Range header field overlap the
1674
+ * current extent of the selected resource or that the set of ranges
1675
+ * requested has been rejected due to invalid ranges or an excessive request
1676
+ * of small or overlapping ranges.
1677
+ *
1678
+ * For byte ranges, failing to overlap the current extent means that the
1679
+ * first-byte-pos of all of the byte-range-spec values were greater than the
1680
+ * current length of the selected representation. When this status code is
1681
+ * generated in response to a byte-range request, the sender SHOULD generate
1682
+ * a Content-Range header field specifying the current length of the selected
1683
+ * representation
1684
+ */
1685
+ 416: "Requested Range Not Satisfiable",
1686
+ /**
1687
+ * The 417 (Expectation Failed) status code indicates that the
1688
+ * expectation given in the request's Expect header field
1689
+ * (Section 5.1.1 of [RFC7231]) could not be met by at least one of the
1690
+ * inbound servers.
1691
+ */
1692
+ 417: "Expectation Failed",
1693
+ /**
1694
+ * Any attempt to brew coffee with a teapot should result in the error code
1695
+ * "418 I'm a teapot". The resulting entity body MAY be short and stout.
1696
+ */
1697
+ 418: "I'm a Teapot",
1698
+ /**
1699
+ * The request was directed at a server that is not able to produce a
1700
+ * response. This can be sent by a server that is not configured to produce
1701
+ * responses for the combination of scheme and authority that are included
1702
+ * in the request URI.
1703
+ *
1704
+ * Clients receiving a 421 Misdirected Request response from a server MAY
1705
+ * retry the request -- whether the request method is idempotent or
1706
+ * not -- over a different connection. This is possible if a connection is
1707
+ * reused or if an alternative service is selected ALT-SVC.
1708
+ *
1709
+ * This status code MUST NOT be generated by proxies.
1710
+ *
1711
+ * A 421 response is cacheable by default, i.e., unless otherwise indicated by
1712
+ * the method definition or explicit cache controls
1713
+ */
1714
+ 421: "Misdirected Request",
1715
+ /**
1716
+ * The server understands the content type of the request entity (hence a
1717
+ * 415 Unsupported Media Type status code is inappropriate), and the syntax
1718
+ * of the request entity is correct (thus a 400 Bad Request status code is
1719
+ * inappropriate) but was unable to process the contained instructions.
1720
+ *
1721
+ * For example, this error condition may occur if an XML request body contains
1722
+ * well-formed (i.e., syntactically correct), but semantically erroneous, XML
1723
+ * instructions.
1724
+ */
1725
+ 422: "Unprocessable Entity",
1726
+ /**
1727
+ * The source or destination resource of a method is locked.
1728
+ *
1729
+ * This response SHOULD contain an appropriate precondition or postcondition
1730
+ * code, such as 'lock-token-submitted' or 'no-conflicting-lock'.
1731
+ */
1732
+ 423: "Locked",
1733
+ /**
1734
+ * The method could not be performed on the resource because the requested
1735
+ * action depended on another action and that action failed.
1736
+ *
1737
+ * For example, if a command in a PROPPATCH method fails, then, at minimum,
1738
+ * the rest of the commands will also fail with 424 Failed Dependency.
1739
+ */
1740
+ 424: "Failed Dependency",
1741
+ /**
1742
+ * The 426 (Upgrade Required) status code indicates that the server
1743
+ * refuses to perform the request using the current protocol but might
1744
+ * be willing to do so after the client upgrades to a different
1745
+ * protocol. The server MUST send an Upgrade header field in a 426
1746
+ * response to indicate the required protocol(s) (Section 6.7 of
1747
+ * [RFC7230]).
1748
+ */
1749
+ 426: "Upgrade Required",
1750
+ /**
1751
+ * The origin server requires the request to be conditional.
1752
+ *
1753
+ * Its typical use is to avoid the "lost update" problem, where a client GETs
1754
+ * a resource's state, modifies it, and PUTs it back to the server, when
1755
+ * meanwhile a third party has modified the state on the server, leading
1756
+ * to a conflict. By requiring requests to be conditional, the server can
1757
+ * assure that clients are working with the correct copies.
1758
+ *
1759
+ * Responses using this status code SHOULD explain how to resubmit the request
1760
+ * successfully.
1761
+ *
1762
+ * Responses with the 428 status code MUST NOT be stored by a cache.
1763
+ */
1764
+ 428: "Precondition Required",
1765
+ /**
1766
+ * The user has sent too many requests in a given amount of time
1767
+ * ("rate limiting").
1768
+ *
1769
+ * The response representations SHOULD include details explaining the
1770
+ * condition, and MAY include a Retry-After header indicating how long to
1771
+ * wait before making a new request.
1772
+ *
1773
+ * Responses with the 429 status code MUST NOT be stored by a cache.
1774
+ */
1775
+ 429: "Too Many Requests",
1776
+ /**
1777
+ * The server is unwilling to process the request because its header fields
1778
+ * are too large. The request MAY be resubmitted after reducing the size of
1779
+ * the request header fields.
1780
+ *
1781
+ * It can be used both when the set of request header fields in total is too
1782
+ * large, and when a single header field is at fault. In the latter case, the
1783
+ * response representation SHOULD specify which header field was too large.
1784
+ */
1785
+ 431: "Request Header Fields Too Large",
1786
+ /**
1787
+ * A non-standard status code used to instruct nginx to close the connection
1788
+ * without sending a response to the client, most commonly used to deny
1789
+ * malicious or malformed requests.
1790
+ *
1791
+ * This status code is not seen by the client, it only appears in nginx log
1792
+ * files.
1793
+ */
1794
+ 444: "Connection Closed Without Response",
1795
+ /**
1796
+ * The server is denying access to the resource as a consequence of a legal
1797
+ * demand.
1798
+ *
1799
+ * The server in question might not be an origin server. This type of legal
1800
+ * demand typically most directly affects the operations of ISPs and search
1801
+ * engines.
1802
+ *
1803
+ * Responses using this status code SHOULD include an explanation, in the
1804
+ * response body, of the details of the legal demand: the party making it,
1805
+ * the applicable legislation or regulation, and what classes of person and
1806
+ * resource it applies to.
1807
+ *
1808
+ * The use of the 451 status code implies neither the existence nor
1809
+ * non-existence of the resource named in the request. That is to say, it is
1810
+ * possible that if the legal demands were removed, a request for the
1811
+ * resource still might not succeed.
1812
+ *
1813
+ * Note that in many cases clients can still access the denied resource by
1814
+ * using technical countermeasures such as a VPN or the Tor network.
1815
+ *
1816
+ * A 451 response is cacheable by default; i.e., unless otherwise indicated
1817
+ * by the method definition or explicit cache controls; see RFC7234.
1818
+ */
1819
+ 451: "Unavailable For Legal Reasons",
1820
+ /**
1821
+ * A non-standard status code introduced by nginx for the case when a client
1822
+ * closes the connection while nginx is processing the request.
1823
+ */
1824
+ 499: "Client Closed Request",
1825
+ /**
1826
+ * The 500 (Internal Server Error) status code indicates that the server
1827
+ * encountered an unexpected condition that prevented it from fulfilling
1828
+ * the request.
1829
+ */
1830
+ 500: "Internal Server Error",
1831
+ /**
1832
+ * The 501 (Not Implemented) status code indicates that the server does
1833
+ * not support the functionality required to fulfill the request. This
1834
+ * is the appropriate response when the server does not recognize the
1835
+ * request method and is not capable of supporting it for any resource.
1836
+ *
1837
+ * A 501 response is cacheable by default; i.e., unless otherwise
1838
+ * indicated by the method definition or explicit cache controls (see
1839
+ * Section 4.2.2 of [RFC7234]).
1840
+ */
1841
+ 501: "Not Implemented",
1842
+ /**
1843
+ * The 502 (Bad Gateway) status code indicates that the server, while
1844
+ * acting as a gateway or proxy, received an invalid response from an
1845
+ * inbound server it accessed while attempting to fulfill the request.
1846
+ */
1847
+ 502: "Bad Gateway",
1848
+ /**
1849
+ * The 503 (Service Unavailable) status code indicates that the server
1850
+ * is currently unable to handle the request due to a temporary overload
1851
+ * or scheduled maintenance, which will likely be alleviated after some
1852
+ * delay. The server MAY send a Retry-After header field
1853
+ * (Section 7.1.3 of [RFC7231]) to suggest an appropriate amount of time for
1854
+ * the client to wait before retrying the request.
1855
+ */
1856
+ 503: "Service Unavailable",
1857
+ /**
1858
+ * The 504 (Gateway Timeout) status code indicates that the server,
1859
+ *while acting as a gateway or proxy, did not receive a timely response
1860
+ *from an upstream server it needed to access in order to complete the
1861
+ *request.
1862
+ */
1863
+ 504: "Gateway Timeout",
1864
+ /**
1865
+ * The 505 (HTTP Version Not Supported) status code indicates that the
1866
+ *server does not support, or refuses to support, the major version of
1867
+ *HTTP that was used in the request message. The server is indicating
1868
+ *that it is unable or unwilling to complete the request using the same
1869
+ *major version as the client, as described in Section 2.6 of
1870
+ *[RFC7230], other than with this error message. The server SHOULD
1871
+ *generate a representation for the 505 response that describes why
1872
+ *that version is not supported and what other protocols are supported
1873
+ *by that server.
1874
+ */
1875
+ 505: "HTTP Version Not Supported",
1876
+ /**
1877
+ * The server has an internal configuration error: the chosen variant
1878
+ * resource is configured to engage in transparent content negotiation
1879
+ * itself, and is therefore not a proper end point in the negotiation
1880
+ * process.
1881
+ */
1882
+ 506: "Variant Also Negotiates",
1883
+ /**
1884
+ * The method could not be performed on the resource because the server is
1885
+ * unable to store the representation needed to successfully complete the
1886
+ * request.
1887
+ *
1888
+ * This condition is considered to be temporary. If the request that received
1889
+ * this status code was the result of a user action, the request MUST NOT be
1890
+ * repeated until it is requested by a separate user action.
1891
+ */
1892
+ 507: "Insufficient Storage",
1893
+ /**
1894
+ * The server terminated an operation because it encountered an infinite loop
1895
+ * while processing a request with "Depth: infinity". This status indicates
1896
+ * that the entire operation failed.
1897
+ */
1898
+ 508: "Loop Detected",
1899
+ /**
1900
+ * The policy for accessing the resource has not been met in the request. The
1901
+ * server should send back all the information necessary for the client to
1902
+ * issue an extended request.
1903
+ *
1904
+ * It is outside the scope of this specification to specify how the
1905
+ * extensions inform the client.
1906
+ *
1907
+ * If the 510 response contains information about extensions that were not
1908
+ * present in the initial request then the client MAY repeat the request if
1909
+ * it has reason to believe it can fulfill the extension policy by modifying
1910
+ * the request according to the information provided in the 510 response.
1911
+ * Otherwise the client MAY present any entity included in the 510 response
1912
+ * to the user, since that entity may include relevant diagnostic information.
1913
+ */
1914
+ 510: "Not Extended",
1915
+ /**
1916
+ * The client needs to authenticate to gain network access.
1917
+ *
1918
+ * The response representation SHOULD contain a link to a resource that
1919
+ * allows the user to submit credentials (e.g., with an HTML form).
1920
+ *
1921
+ * Note that the 511 response SHOULD NOT contain a challenge or the login
1922
+ * interface itself, because browsers would show the login interface as being
1923
+ * associated with the originally requested URL, which may cause confusion.
1924
+ *
1925
+ * The 511 status SHOULD NOT be generated by origin servers; it is intended
1926
+ * for use by intercepting proxies that are interposed as a means of
1927
+ * controlling access to the network.
1928
+ *
1929
+ * Responses with the 511 status code MUST NOT be stored by a cache.
1930
+ */
1931
+ 511: "Network Authentication Required",
1932
+ /**
1933
+ * This status code is not specified in any RFCs, but is used by some HTTP
1934
+ * proxies to signal a network connect timeout behind the proxy to a client
1935
+ * in front of the proxy.
1936
+ */
1937
+ 599: "Network Connect Timeout Error"
1938
+ };
1939
+ var isValidStatusCode = (code) => !!HTTPStatuses[code];
1940
+ var isInformational = (code) => code >= 100 && code < 200;
1941
+ var isSuccessful = (code) => code >= 200 && code < 300;
1942
+ var isRedirection = (code) => code >= 300 && code < 400;
1943
+ var isClientError = (code) => code >= 400 && code < 500;
1944
+ var isServerError = (code) => code >= 500;
1945
+ var getCodeForStatus = (status) => {
1946
+ const clnStr = status.toLocaleLowerCase().trim();
1947
+ const entry = Object.entries(HTTPStatuses).find(
1948
+ (ent) => ent[1].toLowerCase() === clnStr
1949
+ );
1950
+ if (entry) return parseInt(entry[0]);
1951
+ return null;
1952
+ };
1953
+ var httpStatusCodes_default = HTTPStatuses;
1954
+
1955
+ // src/http/openApiV3Generator/openApiV3Generator.ts
1956
+ function toUpperCase(str) {
1957
+ return str.charAt(0).toUpperCase() + str.slice(1);
1958
+ }
1959
+ function transformBasePath(basePath) {
1960
+ if (basePath.startsWith("/")) {
1961
+ return toUpperCase(basePath.slice(1));
1962
+ }
1963
+ return `/${basePath}`;
1964
+ }
1965
+ function swaggerDocument(port, tags, paths) {
1966
+ return {
1967
+ openapi: "3.1.0",
1968
+ info: {
1969
+ title: process.env.API_TITLE || "",
1970
+ version: process.env.VERSION || "1.0.0"
1971
+ },
1972
+ components: {
1973
+ securitySchemes: {
1974
+ bearer: {
1975
+ type: "http",
1976
+ scheme: "bearer",
1977
+ bearerFormat: "JWT"
1978
+ }
1979
+ }
1980
+ },
1981
+ tags,
1982
+ servers: [
1983
+ {
1984
+ url: `http://localhost:${port}`
1985
+ }
1986
+ ],
1987
+ paths
1988
+ };
1989
+ }
1990
+ function contentResolver(schemaValidator, body) {
1991
+ const bodySpec = schemaValidator.openapi(body);
1992
+ return body === schemaValidator.string ? {
1993
+ "plain/text": {
1994
+ schema: bodySpec
1995
+ }
1996
+ } : {
1997
+ "application/json": {
1998
+ schema: bodySpec
1999
+ }
2000
+ };
2001
+ }
2002
+ function generateSwaggerDocument(schemaValidator, port, routers) {
2003
+ const tags = [];
2004
+ const paths = {};
2005
+ routers.flat(Infinity).forEach((router) => {
2006
+ const controllerName = transformBasePath(router.basePath);
2007
+ tags.push({
2008
+ name: controllerName,
2009
+ description: `${controllerName} Operations`
2010
+ });
2011
+ router.routes.forEach((route) => {
2012
+ const fullPath = `${router.basePath}${route.path === "/" ? "" : route.path}`.replace(/:(\w+)/g, "{$1}");
2013
+ if (!paths[fullPath]) {
2014
+ paths[fullPath] = {};
2015
+ }
2016
+ const { name, summary, query, requestHeaders } = route.contractDetails;
2017
+ const responses = {};
2018
+ for (const key in route.contractDetails.responses) {
2019
+ responses[key] = {
2020
+ description: httpStatusCodes_default[key],
2021
+ content: contentResolver(
2022
+ schemaValidator,
2023
+ route.contractDetails.responses[key]
2024
+ )
2025
+ };
2026
+ }
2027
+ const pathItemObject = {
2028
+ tags: [controllerName],
2029
+ summary: `${name}: ${summary}`,
2030
+ parameters: [],
2031
+ responses
2032
+ };
2033
+ if (route.contractDetails.params) {
2034
+ for (const key in route.contractDetails.params) {
2035
+ pathItemObject.parameters?.push({
2036
+ name: key,
2037
+ in: "path"
2038
+ });
2039
+ }
2040
+ }
2041
+ const body = route.contractDetails.body;
2042
+ if (body) {
2043
+ pathItemObject.requestBody = {
2044
+ required: true,
2045
+ content: contentResolver(schemaValidator, body)
2046
+ };
2047
+ }
2048
+ if (requestHeaders) {
2049
+ for (const key in requestHeaders) {
2050
+ pathItemObject.parameters?.push({
2051
+ name: key,
2052
+ in: "header"
2053
+ });
2054
+ }
2055
+ }
2056
+ if (query) {
2057
+ for (const key in query) {
2058
+ pathItemObject.parameters?.push({
2059
+ name: key,
2060
+ in: "query"
2061
+ });
2062
+ }
2063
+ }
2064
+ if (route.contractDetails.auth) {
2065
+ responses[401] = {
2066
+ description: httpStatusCodes_default[401],
2067
+ content: contentResolver(schemaValidator, schemaValidator.string)
2068
+ };
2069
+ responses[403] = {
2070
+ description: httpStatusCodes_default[403],
2071
+ content: contentResolver(schemaValidator, schemaValidator.string)
2072
+ };
2073
+ if (route.contractDetails.auth.method === "jwt") {
2074
+ pathItemObject.security = [
2075
+ {
2076
+ bearer: Array.from(
2077
+ route.contractDetails.auth.allowedPermissions?.values() || []
2078
+ )
2079
+ }
2080
+ ];
2081
+ }
2082
+ }
2083
+ if (route.method !== "middleware") {
2084
+ paths[fullPath][route.method] = pathItemObject;
2085
+ }
2086
+ });
2087
+ });
2088
+ return swaggerDocument(port, tags, paths);
2089
+ }
2090
+
2091
+ // src/http/middleware/response/parse.middleware.ts
2092
+ var import_validator2 = require("@forklaunch/validator");
2093
+ function parse2(req, res, next) {
2094
+ console.debug("[MIDDLEWARE] parseResponse started");
2095
+ const { headers, responses } = res.responseSchemas;
2096
+ const parsedResponse = req.schemaValidator.parse(
2097
+ responses?.[res.statusCode],
2098
+ res.bodyData
2099
+ );
2100
+ const parsedHeaders = req.schemaValidator.parse(
2101
+ headers ?? req.schemaValidator.unknown,
2102
+ res.getHeaders()
2103
+ );
2104
+ const parseErrors = [];
2105
+ if (!parsedHeaders.ok) {
2106
+ const headerErrors = (0, import_validator2.prettyPrintParseErrors)(parsedHeaders.errors, "Header");
2107
+ if (headerErrors) {
2108
+ parseErrors.push(headerErrors);
2109
+ }
2110
+ }
2111
+ if (!parsedResponse.ok) {
2112
+ const responseErrors = (0, import_validator2.prettyPrintParseErrors)(
2113
+ parsedResponse.errors,
2114
+ "Response"
2115
+ );
2116
+ if (responseErrors) {
2117
+ parseErrors.push(responseErrors);
2118
+ }
2119
+ }
2120
+ if (parseErrors.length > 0) {
2121
+ switch (req.contractDetails.options?.responseValidation) {
2122
+ default:
2123
+ case "error":
2124
+ next?.(new Error(`Invalid response:
2125
+ ${parseErrors.join("\n\n")}`));
2126
+ break;
2127
+ case "warning":
2128
+ console.warn(`Invalid response:
2129
+ ${parseErrors.join("\n\n")}`);
2130
+ break;
2131
+ case "none":
2132
+ break;
2133
+ }
2134
+ }
2135
+ next?.();
2136
+ }
2137
+
2138
+ // src/http/utils/enrichExpressLikeSend.ts
2139
+ function enrichExpressLikeSend(instance, req, res, originalSend, data, shouldEnrich) {
2140
+ let parseErrorSent;
2141
+ if (shouldEnrich) {
2142
+ if (res.statusCode === 404) {
2143
+ res.status(404);
2144
+ originalSend.call(instance, "Not Found");
2145
+ }
2146
+ parse2(req, res, (err) => {
2147
+ if (err) {
2148
+ let errorString = err.message;
2149
+ if (res.locals.errorMessage) {
2150
+ errorString += `
2151
+ ------------------
2152
+ ${res.locals.errorMessage}`;
2153
+ }
2154
+ res.status(500);
2155
+ originalSend.call(instance, errorString);
2156
+ parseErrorSent = true;
2157
+ }
2158
+ });
2159
+ }
2160
+ if (!parseErrorSent) {
2161
+ originalSend.call(instance, data);
2162
+ }
2163
+ }
2164
+ // Annotate the CommonJS export names for ESM import in node:
2165
+ 0 && (module.exports = {
2166
+ ForklaunchExpressLikeApplication,
2167
+ ForklaunchExpressLikeRouter,
2168
+ HTTPStatuses,
2169
+ delete_,
2170
+ enrichExpressLikeSend,
2171
+ generateSwaggerDocument,
2172
+ get,
2173
+ getCodeForStatus,
2174
+ head,
2175
+ isClientError,
2176
+ isForklaunchRouter,
2177
+ isInformational,
2178
+ isRedirection,
2179
+ isServerError,
2180
+ isSuccessful,
2181
+ isValidStatusCode,
2182
+ middleware,
2183
+ options,
2184
+ patch,
2185
+ post,
2186
+ put,
2187
+ trace,
2188
+ typedHandler
2189
+ });