@h4ad/serverless-adapter 4.0.0 → 4.1.0

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 (199) hide show
  1. package/lib/adapter.contract-EQE3rlgO.d.ts +278 -0
  2. package/lib/adapter.contract-y5xSjOjo.d.cts +278 -0
  3. package/lib/adapters/apollo-server/index.cjs +6 -0
  4. package/lib/adapters/apollo-server/index.cjs.map +1 -0
  5. package/lib/adapters/apollo-server/index.d.cts +61 -0
  6. package/lib/adapters/apollo-server/index.d.ts +61 -0
  7. package/lib/adapters/apollo-server/index.mjs +2 -0
  8. package/lib/adapters/apollo-server/index.mjs.map +1 -0
  9. package/lib/adapters/aws/index.cjs +6 -0
  10. package/lib/adapters/aws/index.cjs.map +1 -0
  11. package/lib/adapters/aws/index.d.cts +928 -0
  12. package/lib/adapters/aws/index.d.ts +928 -0
  13. package/lib/adapters/aws/index.mjs +2 -0
  14. package/lib/adapters/aws/index.mjs.map +1 -0
  15. package/lib/adapters/azure/index.cjs +6 -0
  16. package/lib/adapters/azure/index.cjs.map +1 -0
  17. package/lib/adapters/azure/index.d.cts +86 -0
  18. package/lib/adapters/azure/index.d.ts +86 -0
  19. package/lib/adapters/azure/index.mjs +2 -0
  20. package/lib/adapters/azure/index.mjs.map +1 -0
  21. package/lib/adapters/digital-ocean/index.cjs +6 -0
  22. package/lib/adapters/digital-ocean/index.cjs.map +1 -0
  23. package/lib/adapters/digital-ocean/index.d.cts +126 -0
  24. package/lib/adapters/digital-ocean/index.d.ts +126 -0
  25. package/lib/adapters/digital-ocean/index.mjs +2 -0
  26. package/lib/adapters/digital-ocean/index.mjs.map +1 -0
  27. package/lib/adapters/dummy/index.cjs +6 -0
  28. package/lib/adapters/dummy/index.cjs.map +1 -0
  29. package/lib/adapters/dummy/index.d.cts +37 -0
  30. package/lib/adapters/dummy/index.d.ts +37 -0
  31. package/lib/adapters/dummy/index.mjs +2 -0
  32. package/lib/adapters/dummy/index.mjs.map +1 -0
  33. package/lib/adapters/huawei/index.cjs +6 -0
  34. package/lib/adapters/huawei/index.cjs.map +1 -0
  35. package/lib/adapters/huawei/index.d.cts +365 -0
  36. package/lib/adapters/huawei/index.d.ts +365 -0
  37. package/lib/adapters/huawei/index.mjs +2 -0
  38. package/lib/adapters/huawei/index.mjs.map +1 -0
  39. package/lib/base-handler-fYEk59Xq.d.ts +35 -0
  40. package/lib/base-handler-peEBoKtZ.d.cts +35 -0
  41. package/lib/chunk-22SSVZU5.mjs +1 -0
  42. package/lib/chunk-22SSVZU5.mjs.map +1 -0
  43. package/lib/chunk-57ZKWTH4.mjs +2 -0
  44. package/lib/chunk-57ZKWTH4.mjs.map +1 -0
  45. package/lib/chunk-OYOJMOFP.mjs +2 -0
  46. package/lib/chunk-OYOJMOFP.mjs.map +1 -0
  47. package/lib/chunk-PQDB5AVF.mjs +12 -0
  48. package/lib/chunk-PQDB5AVF.mjs.map +1 -0
  49. package/lib/chunk-VPGUOREQ.mjs +2 -0
  50. package/lib/chunk-VPGUOREQ.mjs.map +1 -0
  51. package/lib/constants-0cgQlFSV.d.cts +32 -0
  52. package/lib/constants-0cgQlFSV.d.ts +32 -0
  53. package/lib/framework.contract-YnJ-fl1w.d.cts +20 -0
  54. package/lib/framework.contract-YnJ-fl1w.d.ts +20 -0
  55. package/lib/frameworks/apollo-server/index.cjs +6 -0
  56. package/lib/frameworks/apollo-server/index.cjs.map +1 -0
  57. package/lib/frameworks/apollo-server/index.d.cts +72 -0
  58. package/lib/frameworks/apollo-server/index.d.ts +72 -0
  59. package/lib/frameworks/apollo-server/index.mjs +2 -0
  60. package/lib/frameworks/apollo-server/index.mjs.map +1 -0
  61. package/lib/frameworks/body-parser/index.cjs +6 -0
  62. package/lib/frameworks/body-parser/index.cjs.map +1 -0
  63. package/lib/frameworks/body-parser/index.d.cts +159 -0
  64. package/lib/frameworks/body-parser/index.d.ts +159 -0
  65. package/lib/frameworks/body-parser/index.mjs +2 -0
  66. package/lib/frameworks/body-parser/index.mjs.map +1 -0
  67. package/lib/frameworks/cors/index.cjs +7 -0
  68. package/lib/frameworks/cors/index.cjs.map +1 -0
  69. package/lib/frameworks/cors/index.d.cts +79 -0
  70. package/lib/frameworks/cors/index.d.ts +79 -0
  71. package/lib/frameworks/cors/index.mjs +3 -0
  72. package/lib/frameworks/cors/index.mjs.map +1 -0
  73. package/lib/frameworks/deepkit/index.cjs +6 -0
  74. package/lib/frameworks/deepkit/index.cjs.map +1 -0
  75. package/lib/frameworks/deepkit/index.d.cts +21 -0
  76. package/lib/frameworks/deepkit/index.d.ts +21 -0
  77. package/lib/frameworks/deepkit/index.mjs +2 -0
  78. package/lib/frameworks/deepkit/index.mjs.map +1 -0
  79. package/lib/frameworks/express/index.cjs +2 -0
  80. package/lib/frameworks/express/index.cjs.map +1 -0
  81. package/lib/frameworks/express/index.d.cts +18 -0
  82. package/lib/frameworks/express/index.d.ts +18 -0
  83. package/lib/frameworks/express/index.mjs +2 -0
  84. package/lib/frameworks/express/index.mjs.map +1 -0
  85. package/lib/frameworks/fastify/index.cjs +2 -0
  86. package/lib/frameworks/fastify/index.cjs.map +1 -0
  87. package/lib/frameworks/fastify/index.d.cts +18 -0
  88. package/lib/frameworks/fastify/index.d.ts +18 -0
  89. package/lib/frameworks/fastify/index.mjs +2 -0
  90. package/lib/frameworks/fastify/index.mjs.map +1 -0
  91. package/lib/frameworks/hapi/index.cjs +2 -0
  92. package/lib/frameworks/hapi/index.cjs.map +1 -0
  93. package/lib/frameworks/hapi/index.d.cts +18 -0
  94. package/lib/frameworks/hapi/index.d.ts +18 -0
  95. package/lib/frameworks/hapi/index.mjs +2 -0
  96. package/lib/frameworks/hapi/index.mjs.map +1 -0
  97. package/lib/frameworks/koa/index.cjs +2 -0
  98. package/lib/frameworks/koa/index.cjs.map +1 -0
  99. package/lib/frameworks/koa/index.d.cts +18 -0
  100. package/lib/frameworks/koa/index.d.ts +18 -0
  101. package/lib/frameworks/koa/index.mjs +2 -0
  102. package/lib/frameworks/koa/index.mjs.map +1 -0
  103. package/lib/frameworks/lazy/index.cjs +6 -0
  104. package/lib/frameworks/lazy/index.cjs.map +1 -0
  105. package/lib/frameworks/lazy/index.d.cts +57 -0
  106. package/lib/frameworks/lazy/index.d.ts +57 -0
  107. package/lib/frameworks/lazy/index.mjs +2 -0
  108. package/lib/frameworks/lazy/index.mjs.map +1 -0
  109. package/lib/frameworks/trpc/index.cjs +6 -0
  110. package/lib/frameworks/trpc/index.cjs.map +1 -0
  111. package/lib/frameworks/trpc/index.d.cts +154 -0
  112. package/lib/frameworks/trpc/index.d.ts +154 -0
  113. package/lib/frameworks/trpc/index.mjs +2 -0
  114. package/lib/frameworks/trpc/index.mjs.map +1 -0
  115. package/lib/handler.contract-8Cb7qLSi.d.ts +66 -0
  116. package/lib/handler.contract-TQk8iM8f.d.cts +66 -0
  117. package/lib/handlers/aws/index.cjs +12 -0
  118. package/lib/handlers/aws/index.cjs.map +1 -0
  119. package/lib/handlers/aws/index.d.cts +96 -0
  120. package/lib/handlers/aws/index.d.ts +96 -0
  121. package/lib/handlers/aws/index.mjs +2 -0
  122. package/lib/handlers/aws/index.mjs.map +1 -0
  123. package/lib/handlers/azure/index.cjs +6 -0
  124. package/lib/handlers/azure/index.cjs.map +1 -0
  125. package/lib/handlers/azure/index.d.cts +53 -0
  126. package/lib/handlers/azure/index.d.ts +53 -0
  127. package/lib/handlers/azure/index.mjs +2 -0
  128. package/lib/handlers/azure/index.mjs.map +1 -0
  129. package/lib/handlers/default/index.cjs +6 -0
  130. package/lib/handlers/default/index.cjs.map +1 -0
  131. package/lib/handlers/default/index.d.cts +95 -0
  132. package/lib/handlers/default/index.d.ts +95 -0
  133. package/lib/handlers/default/index.mjs +2 -0
  134. package/lib/handlers/default/index.mjs.map +1 -0
  135. package/lib/handlers/digital-ocean/index.cjs +6 -0
  136. package/lib/handlers/digital-ocean/index.cjs.map +1 -0
  137. package/lib/handlers/digital-ocean/index.d.cts +25 -0
  138. package/lib/handlers/digital-ocean/index.d.ts +25 -0
  139. package/lib/handlers/digital-ocean/index.mjs +2 -0
  140. package/lib/handlers/digital-ocean/index.mjs.map +1 -0
  141. package/lib/handlers/firebase/index.cjs +6 -0
  142. package/lib/handlers/firebase/index.cjs.map +1 -0
  143. package/lib/handlers/firebase/index.d.cts +59 -0
  144. package/lib/handlers/firebase/index.d.ts +59 -0
  145. package/lib/handlers/firebase/index.mjs +2 -0
  146. package/lib/handlers/firebase/index.mjs.map +1 -0
  147. package/lib/handlers/gcp/index.cjs +6 -0
  148. package/lib/handlers/gcp/index.cjs.map +1 -0
  149. package/lib/handlers/gcp/index.d.cts +33 -0
  150. package/lib/handlers/gcp/index.d.ts +33 -0
  151. package/lib/handlers/gcp/index.mjs +2 -0
  152. package/lib/handlers/gcp/index.mjs.map +1 -0
  153. package/lib/handlers/huawei/index.cjs +6 -0
  154. package/lib/handlers/huawei/index.cjs.map +1 -0
  155. package/lib/handlers/huawei/index.d.cts +62 -0
  156. package/lib/handlers/huawei/index.d.ts +62 -0
  157. package/lib/handlers/huawei/index.mjs +2 -0
  158. package/lib/handlers/huawei/index.mjs.map +1 -0
  159. package/lib/headers-K2qbcurv.d.cts +38 -0
  160. package/lib/headers-K2qbcurv.d.ts +38 -0
  161. package/lib/index.cjs +12 -0
  162. package/lib/index.cjs.map +1 -0
  163. package/lib/index.d.cts +439 -0
  164. package/lib/index.d.ts +439 -0
  165. package/lib/index.mjs +2 -0
  166. package/lib/index.mjs.map +1 -0
  167. package/lib/logger-9me5n48P.d.cts +65 -0
  168. package/lib/logger-9me5n48P.d.ts +65 -0
  169. package/lib/path-yBwCb8C1.d.cts +64 -0
  170. package/lib/path-yBwCb8C1.d.ts +64 -0
  171. package/lib/raw-request-B2vPjAfE.d.cts +32 -0
  172. package/lib/raw-request-b6AYnkxd.d.ts +32 -0
  173. package/lib/request-DNNIV9ub.d.cts +44 -0
  174. package/lib/request-sVa4pxmx.d.ts +44 -0
  175. package/lib/resolvers/aws-context/index.cjs +2 -0
  176. package/lib/resolvers/aws-context/index.cjs.map +1 -0
  177. package/lib/resolvers/aws-context/index.d.cts +25 -0
  178. package/lib/resolvers/aws-context/index.d.ts +25 -0
  179. package/lib/resolvers/aws-context/index.mjs +2 -0
  180. package/lib/resolvers/aws-context/index.mjs.map +1 -0
  181. package/lib/resolvers/callback/index.cjs +2 -0
  182. package/lib/resolvers/callback/index.cjs.map +1 -0
  183. package/lib/resolvers/callback/index.d.cts +29 -0
  184. package/lib/resolvers/callback/index.d.ts +29 -0
  185. package/lib/resolvers/callback/index.mjs +2 -0
  186. package/lib/resolvers/callback/index.mjs.map +1 -0
  187. package/lib/resolvers/dummy/index.cjs +2 -0
  188. package/lib/resolvers/dummy/index.cjs.map +1 -0
  189. package/lib/resolvers/dummy/index.d.cts +20 -0
  190. package/lib/resolvers/dummy/index.d.ts +20 -0
  191. package/lib/resolvers/dummy/index.mjs +2 -0
  192. package/lib/resolvers/dummy/index.mjs.map +1 -0
  193. package/lib/resolvers/promise/index.cjs +2 -0
  194. package/lib/resolvers/promise/index.cjs.map +1 -0
  195. package/lib/resolvers/promise/index.d.cts +20 -0
  196. package/lib/resolvers/promise/index.d.ts +20 -0
  197. package/lib/resolvers/promise/index.mjs +2 -0
  198. package/lib/resolvers/promise/index.mjs.map +1 -0
  199. package/package.json +1 -1
package/lib/index.d.ts ADDED
@@ -0,0 +1,439 @@
1
+ import { B as BinarySettings, H as HandlerContract, S as ServerlessHandler } from './handler.contract-8Cb7qLSi.js';
2
+ export { b as BinarySettingsContentHeaders, a as BinarySettingsFunction } from './handler.contract-8Cb7qLSi.js';
3
+ import { B as BothValueHeaders } from './headers-K2qbcurv.js';
4
+ export { M as MultiValueHeaders, S as SingleValueHeaders } from './headers-K2qbcurv.js';
5
+ export { C as Concrete, S as StripBasePathFn, b as buildStripBasePath, g as getPathWithQueryStringParams, a as getQueryParamsStringFromRecord } from './path-yBwCb8C1.js';
6
+ import { A as AdapterContract, R as ResolverContract } from './adapter.contract-EQE3rlgO.js';
7
+ export { a as AdapterRequest, D as DelegatedResolver, G as GetResponseAdapterProps, O as OnErrorProps, c as Resolver, b as ResolverProps, S as ServerlessResponse, d as ServerlessResponseProps } from './adapter.contract-EQE3rlgO.js';
8
+ import { F as FrameworkContract } from './framework.contract-YnJ-fl1w.js';
9
+ export { B as BaseHandler } from './base-handler-fYEk59Xq.js';
10
+ export { a as DEFAULT_BINARY_CONTENT_TYPES, D as DEFAULT_BINARY_ENCODINGS, E as EmptyResponse, I as IEmptyResponse } from './constants-0cgQlFSV.js';
11
+ import { I as ILogger } from './logger-9me5n48P.js';
12
+ export { L as LogLevels, b as LoggerFN, a as LoggerOptions, c as createDefaultLogger, i as isInternalLogger } from './logger-9me5n48P.js';
13
+ import { Writable, Readable } from 'node:stream';
14
+ export { S as ServerlessRequest, a as ServerlessRequestProps } from './request-sVa4pxmx.js';
15
+ import { ServerResponse } from 'node:http';
16
+ import 'http';
17
+
18
+ /**
19
+ * The properties to create a {@link ServerlessStreamResponse}.
20
+ *
21
+ * @breadcrumb Network / ServerlessStreamResponse
22
+ * @public
23
+ */
24
+ interface ServerlessStreamResponseProps {
25
+ /**
26
+ * The HTTP Method from request
27
+ */
28
+ method?: string;
29
+ /**
30
+ * The callback to receive the headers when they are written to the stream
31
+ * You need to return a writable stream be able to continue writing the response
32
+ *
33
+ * @param statusCode - The status code of the response
34
+ * @param headers - The headers of the response
35
+ */
36
+ onReceiveHeaders: (statusCode: number, headers: BothValueHeaders) => Writable;
37
+ /**
38
+ * Instance of the logger
39
+ */
40
+ log: ILogger;
41
+ }
42
+ /**
43
+ * The class that represents a response instance used to send to the framework and wait until the framework finishes processing the request.
44
+ * This response is specially built to deal with transfer-encoding: chunked
45
+ *
46
+ * @breadcrumb Network / ServerlessStreamResponse
47
+ * @public
48
+ */
49
+ declare class ServerlessStreamResponse extends ServerResponse {
50
+ constructor({ method, onReceiveHeaders, log, }: ServerlessStreamResponseProps);
51
+ }
52
+
53
+ /**
54
+ * Get the data from a buffer, string, or Uint8Array
55
+ *
56
+ * @breadcrumb Network
57
+ * @param data - The data that was written inside the stream
58
+ */
59
+ declare function getString(data: Buffer | string | unknown): string;
60
+
61
+ /**
62
+ * The type that represents the object that handles the references to the event created by the serverless trigger or context created by the serverless environment.
63
+ *
64
+ * @breadcrumb Core / Current Invoke
65
+ * @public
66
+ */
67
+ type CurrentInvoke<TEvent, TContext> = {
68
+ /**
69
+ * The event created by the serverless trigger
70
+ *
71
+ * @remarks It's only null when you call {@link getCurrentInvoke} outside this library's pipeline.
72
+ */
73
+ event: TEvent | null;
74
+ /**
75
+ * The context created by the serverless environment
76
+ *
77
+ * @remarks It's only null when you call {@link getCurrentInvoke} outside this library's pipeline.
78
+ */
79
+ context: TContext | null;
80
+ };
81
+ /**
82
+ * Get the reference to the event created by the serverless trigger or context created by the serverless environment.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import type { ALBEvent, Context } from 'aws-lambda';
87
+ *
88
+ * // inside the method that handles the aws alb request.
89
+ * const { event, context } = getCurrentInvoke<ALBEvent, Context>();
90
+ * ```
91
+ *
92
+ * @breadcrumb Core / Current Invoke
93
+ * @public
94
+ */
95
+ declare function getCurrentInvoke<TEvent = any, TContext = any>(): CurrentInvoke<TEvent, TContext>;
96
+ /**
97
+ * Method that saves to the event created by the serverless trigger or context created by the serverless environment.
98
+ *
99
+ * @remarks This method MUST NOT be called by you, this method MUST only be used internally in this library.
100
+ *
101
+ * @param event - The event created by the serverless trigger
102
+ * @param context - The context created by the serverless environment
103
+ *
104
+ * @breadcrumb Core / Current Invoke
105
+ * @public
106
+ */
107
+ declare function setCurrentInvoke<TEvent = any, TContext = any>({ event, context, }: CurrentInvoke<TEvent, TContext>): void;
108
+
109
+ /**
110
+ * Get the event body as buffer from body string with content length
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const body = '{}';
115
+ * const [buffer, contentLength] = getEventBodyAsBuffer(body, false);
116
+ * console.log(buffer);
117
+ * // <Buffer 7b 7d>
118
+ * console.log(contentLength);
119
+ * // 2
120
+ * ```
121
+ *
122
+ * @param body - The body string that can be encoded or not
123
+ * @param isBase64Encoded - Tells if body string is encoded in base64
124
+ *
125
+ * @breadcrumb Core
126
+ * @public
127
+ */
128
+ declare function getEventBodyAsBuffer(body: string, isBase64Encoded: boolean): [body: Buffer, contentLength: number];
129
+
130
+ /**
131
+ * Transform a header map and make sure the value is not an array
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const headers = { 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };
136
+ * const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);
137
+ * console.log(flattenedHeaders);
138
+ * // { 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }
139
+ * ```
140
+ *
141
+ * @param headersMap - The initial headers
142
+ * @param separator - The separator used when we join the array of header's value
143
+ * @param lowerCaseKey - Should put all keys in lowercase
144
+ *
145
+ * @breadcrumb Core / Headers
146
+ * @public
147
+ */
148
+ declare function getFlattenedHeadersMap(headersMap: BothValueHeaders, separator?: string, lowerCaseKey?: boolean): Record<string, string>;
149
+ /**
150
+ * Transforms a header map into a multi-value map header.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const headers = { 'accept-encoding': 'gzip', 'connection': ['keep-alive'] };
155
+ * const multiValueHeaders = getMultiValueHeadersMap(headers);
156
+ * console.log(multiValueHeaders);
157
+ * // { 'accept-encoding': ['gzip'], 'connection': ['keep-alive'] }
158
+ * ```
159
+ *
160
+ * @param headersMap - The initial headers
161
+ *
162
+ * @breadcrumb Core / Headers
163
+ * @public
164
+ */
165
+ declare function getMultiValueHeadersMap(headersMap: BothValueHeaders): Record<string, string[]>;
166
+ /**
167
+ * The wrapper that holds the information about single value headers and cookies
168
+ *
169
+ * @breadcrumb Core / Headers
170
+ * @public
171
+ */
172
+ type FlattenedHeadersAndCookies = {
173
+ /**
174
+ * Just the single value headers
175
+ */
176
+ headers: Record<string, string>;
177
+ /**
178
+ * The list of cookies
179
+ */
180
+ cookies: string[];
181
+ };
182
+ /**
183
+ * Transforms a header map into a single value headers and cookies
184
+ *
185
+ * @param headersMap - The initial headers
186
+ *
187
+ * @breadcrumb Core / Headers
188
+ * @public
189
+ */
190
+ declare function getFlattenedHeadersMapAndCookies(headersMap: BothValueHeaders): FlattenedHeadersAndCookies;
191
+ /**
192
+ * Parse HTTP Raw Headers
193
+ * Attribution to {@link https://github.com/kesla/parse-headers/blob/master/parse-headers.js}
194
+ *
195
+ * @param headers - The raw headers
196
+ *
197
+ * @breadcrumb Core / Headers
198
+ * @public
199
+ */
200
+ declare function parseHeaders(headers: string): Record<string, string | string[]>;
201
+
202
+ /**
203
+ * The function that determines by the content encoding whether the response should be treated as binary
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const headers = { 'content-encoding': 'gzip' };
208
+ * const isBinary = isContentEncodingBinary(headers, ['gzip']);
209
+ * console.log(isBinary);
210
+ * // true
211
+ * ```
212
+ *
213
+ * @param headers - The headers of the response
214
+ * @param binaryEncodingTypes - The list of content encodings that will be treated as binary
215
+ *
216
+ * @breadcrumb Core / isBinary
217
+ * @public
218
+ */
219
+ declare function isContentEncodingBinary(headers: BothValueHeaders, binaryEncodingTypes: string[]): boolean;
220
+ /**
221
+ * The function that returns the content type of headers
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const headers = { 'content-type': 'application/json' };
226
+ * const contentType = getContentType(headers);
227
+ * console.log(contentType);
228
+ * // application/json
229
+ * ```
230
+ *
231
+ * @param headers - The headers of the response
232
+ *
233
+ * @breadcrumb Core / isBinary
234
+ * @public
235
+ */
236
+ declare function getContentType(headers: BothValueHeaders): string;
237
+ /**
238
+ * The function that determines by the content type whether the response should be treated as binary
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const headers = { 'content-type': 'image/png' };
243
+ * const isBinary = isContentTypeBinary(headers, new Map([['image/png', true]]));
244
+ * console.log(isBinary);
245
+ * // true
246
+ * ```
247
+ *
248
+ * @param headers - The headers of the response
249
+ * @param binaryContentTypes - The list of content types that will be treated as binary
250
+ *
251
+ * @breadcrumb Core / isBinary
252
+ * @public
253
+ */
254
+ declare function isContentTypeBinary(headers: BothValueHeaders, binaryContentTypes: string[]): boolean;
255
+ /**
256
+ * The function used to determine from the headers and the binary settings if a response should be encoded or not
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const headers = { 'content-type': 'image/png', 'content-encoding': 'gzip' };
261
+ * const isContentBinary = isBinary(headers, { contentEncodings: ['gzip'], contentTypes: ['image/png'] });
262
+ * console.log(isContentBinary);
263
+ * // true
264
+ * ```
265
+ *
266
+ * @param headers - The headers of the response
267
+ * @param binarySettings - The settings for the validation
268
+ *
269
+ * @breadcrumb Core / isBinary
270
+ * @public
271
+ */
272
+ declare function isBinary(headers: BothValueHeaders, binarySettings: BinarySettings): boolean;
273
+
274
+ /**
275
+ * No operation function is used when we need to pass a function, but we don't want to specify any behavior.
276
+ *
277
+ * @breadcrumb Core
278
+ * @public
279
+ */
280
+ declare const NO_OP: (...args: any[]) => any;
281
+
282
+ /**
283
+ * Return the defaultValue whether the value is undefined, otherwise, return the value.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * const value1 = getDefaultIfUndefined(undefined, true);
288
+ * const value2 = getDefaultIfUndefined(false, true);
289
+ *
290
+ * console.log(value1);
291
+ * // true
292
+ * console.log(value2);
293
+ * // false
294
+ * ```
295
+ *
296
+ * @param value - The value to be checked
297
+ * @param defaultValue - The default value when value is undefined
298
+ *
299
+ * @breadcrumb Core
300
+ * @public
301
+ */
302
+ declare function getDefaultIfUndefined<T>(value: T | undefined, defaultValue: T): T;
303
+
304
+ /**
305
+ * Check if stream already ended
306
+ *
307
+ * @param stream - The stream
308
+ *
309
+ * @breadcrumb Core / Stream
310
+ * @public
311
+ */
312
+ declare function isStreamEnded(stream: Readable | Writable): boolean;
313
+ /**
314
+ * Wait asynchronous the stream to complete
315
+ *
316
+ * @param stream - The stream
317
+ *
318
+ * @breadcrumb Core / Stream
319
+ * @public
320
+ */
321
+ declare function waitForStreamComplete<TStream extends Readable | Writable>(stream: TStream): Promise<TStream>;
322
+
323
+ /**
324
+ * The class used to build the serverless handler.
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const app = express();
329
+ * export const handler = ServerlessAdapter.new(app)
330
+ * .setFramework(new ExpressFramework())
331
+ * .setHandler(new DefaultHandler())
332
+ * .setResolver(new PromiseResolver())
333
+ * .setRespondWithErrors(true)
334
+ * .addAdapter(new AlbAdapter())
335
+ * .addAdapter(new SQSAdapter())
336
+ * .addAdapter(new SNSAdapter())
337
+ * .build();
338
+ * ```
339
+ *
340
+ * @breadcrumb ServerlessAdapter
341
+ * @public
342
+ */
343
+ declare class ServerlessAdapter<TApp, TEvent, TContext, TCallback, TResponse, TReturn> {
344
+ /**
345
+ * Default constructor
346
+ */
347
+ private constructor();
348
+ /**
349
+ * The instance of the app (express, hapi, koa, etc...)
350
+ */
351
+ protected app: TApp;
352
+ /**
353
+ * Settings for whether the response should be treated as binary or not
354
+ *
355
+ * @defaultValue `contentEncodings` and `contentTypes` are set with {@link DEFAULT_BINARY_ENCODINGS} and {@link DEFAULT_BINARY_CONTENT_TYPES}, respectively.
356
+ */
357
+ protected binarySettings: BinarySettings;
358
+ /**
359
+ * Indicates whether the error stack should be included in the response or not
360
+ *
361
+ * @remarks These errors will only be included when an error occurs while forwarding the event to the framework
362
+ * @defaultValue True when NODE_ENV is equal to `development`
363
+ */
364
+ protected respondWithErrors: boolean;
365
+ /**
366
+ * The instance of the logger service
367
+ */
368
+ protected log: ILogger;
369
+ /**
370
+ * The list of adapters used to handle an event's request and response
371
+ */
372
+ protected adapters: AdapterContract<TEvent, TContext, TResponse>[];
373
+ /**
374
+ * The framework that will process requests
375
+ */
376
+ protected framework?: FrameworkContract<TApp>;
377
+ /**
378
+ * The resolver that aims to resolve the response to serverless and stop its execution when the request ends
379
+ */
380
+ protected resolver?: ResolverContract<TEvent, TContext, TCallback, TResponse, TReturn>;
381
+ /**
382
+ * The handler that will get the event, context and callback and pass it to the adapter and framework
383
+ */
384
+ protected handler?: HandlerContract<TApp, TEvent, TContext, TCallback, TResponse, TReturn>;
385
+ /**
386
+ * Creates a new instance of the builder with app (express, hapi, koa, etc...)
387
+ *
388
+ * @param app - The instance of the app
389
+ */
390
+ static new<TApp, TEvent, TContext = any, TCallback = any, TResponse = any, TReturn = any>(app: TApp): ServerlessAdapter<TApp, TEvent, TContext, TCallback, TResponse, TReturn>;
391
+ /**
392
+ * Defines the handler that will get the event, context and callback and pass it to the adapter and framework
393
+ *
394
+ * @param handler - The implementation of the handler contract
395
+ */
396
+ setHandler(handler: HandlerContract<TApp, TEvent, TContext, TCallback, TResponse, TReturn>): Omit<this, 'setHandler'>;
397
+ /**
398
+ * Defines the resolver that aims to resolve the response to serverless and stop its execution when the request ends
399
+ *
400
+ * @param resolver - The implementation of the resolver contract
401
+ */
402
+ setResolver(resolver: ResolverContract<TEvent, TContext, TCallback, TResponse, TReturn>): Omit<this, 'setResolver'>;
403
+ /**
404
+ * Defines the framework that will process requests
405
+ *
406
+ * @param framework - The implementation of the framework contract
407
+ */
408
+ setFramework(framework: FrameworkContract<TApp>): Omit<this, 'setFramework'>;
409
+ /**
410
+ * Defines the logger service used during the execution of the handler
411
+ *
412
+ * @param logger - The implementation of the logger
413
+ */
414
+ setLogger(logger: ILogger): Omit<this, 'setLogger'>;
415
+ /**
416
+ * Defines the binary settings for whether the response should be treated as binary or not
417
+ *
418
+ * @param binarySettings - The binary settings
419
+ */
420
+ setBinarySettings(binarySettings: BinarySettings): Omit<this, 'setBinarySettings'>;
421
+ /**
422
+ * Defines the responseWithErrors, a property that indicates whether the error stack should be included in the response or not
423
+ *
424
+ * @param respondWithErrors - Should include or not the errors in response
425
+ */
426
+ setRespondWithErrors(respondWithErrors: boolean): Omit<this, 'setRespondWithErrors'>;
427
+ /**
428
+ * Add an adapter to the adapters list to handle the event coming from any serverless event source
429
+ *
430
+ * @param adapter - The implementation of the adapter contract
431
+ */
432
+ addAdapter(adapter: AdapterContract<TEvent, TContext, TResponse>): Pick<this, 'addAdapter' | 'build'>;
433
+ /**
434
+ * The builder method that returns the handler function to be exported for serverless consumption
435
+ */
436
+ build(): ServerlessHandler<TReturn>;
437
+ }
438
+
439
+ export { AdapterContract, BinarySettings, BothValueHeaders, type CurrentInvoke, type FlattenedHeadersAndCookies, FrameworkContract, HandlerContract, ILogger, NO_OP, ResolverContract, ServerlessAdapter, ServerlessHandler, ServerlessStreamResponse, type ServerlessStreamResponseProps, getContentType, getCurrentInvoke, getDefaultIfUndefined, getEventBodyAsBuffer, getFlattenedHeadersMap, getFlattenedHeadersMapAndCookies, getMultiValueHeadersMap, getString, isBinary, isContentEncodingBinary, isContentTypeBinary, isStreamEnded, parseHeaders, setCurrentInvoke, waitForStreamComplete };
package/lib/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import"./chunk-22SSVZU5.mjs";import{A as D,B as _,a,b as r,c as o,d as p,e as l,f as T,g as h,h as E,i as d,j as c,k as R,l as u,m as S,n as m,o as A,p as w,q as s,r as b,s as C,t as f,u as g,v,w as k,x,y,z as L}from"./chunk-PQDB5AVF.mjs";import{a as t}from"./chunk-OYOJMOFP.mjs";var n=class i{static{t(this,"ServerlessAdapter")}constructor(e){this.app=e}app;binarySettings={contentEncodings:r,contentTypes:o};respondWithErrors=process.env.NODE_ENV==="development";log=s();adapters=[];framework;resolver;handler;static new(e){return new i(e)}setHandler(e){if(this.handler)throw new Error("SERVERLESS_ADAPTER: The handler should not set twice.");return this.handler=e,this}setResolver(e){if(this.resolver)throw new Error("SERVERLESS_ADAPTER: The resolver should not set twice.");return this.resolver=e,this}setFramework(e){if(this.framework)throw new Error("SERVERLESS_ADAPTER: The framework should not set twice.");return this.framework=e,this}setLogger(e){return this.log=e,this}setBinarySettings(e){return this.binarySettings={...this.binarySettings,...e},this}setRespondWithErrors(e){return this.respondWithErrors=e,this}addAdapter(e){return this.adapters.push(e),this}build(){if(!this.resolver)throw new Error("SERVERLESS_ADAPTER: Is required to set a resolver before build.");if(!this.framework)throw new Error("SERVERLESS_ADAPTER: Is required to set a framework before build.");if(!this.handler)throw new Error("SERVERLESS_ADAPTER: Is required to set a handler before build.");if(this.adapters.length===0)throw new Error("SERVERLESS_ADAPTER: Is required to set at least one adapter.");return this.handler.getHandler(this.app,this.framework,this.adapters,this.resolver,this.binarySettings,this.respondWithErrors,this.log)}};export{a as BaseHandler,o as DEFAULT_BINARY_CONTENT_TYPES,r as DEFAULT_BINARY_ENCODINGS,p as EmptyResponse,w as NO_OP,n as ServerlessAdapter,y as ServerlessRequest,D as ServerlessResponse,_ as ServerlessStreamResponse,v as buildStripBasePath,s as createDefaultLogger,S as getContentType,l as getCurrentInvoke,C as getDefaultIfUndefined,h as getEventBodyAsBuffer,E as getFlattenedHeadersMap,c as getFlattenedHeadersMapAndCookies,d as getMultiValueHeadersMap,f as getPathWithQueryStringParams,g as getQueryParamsStringFromRecord,L as getString,A as isBinary,u as isContentEncodingBinary,m as isContentTypeBinary,b as isInternalLogger,k as isStreamEnded,R as parseHeaders,T as setCurrentInvoke,x as waitForStreamComplete};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/serverless-adapter.ts"],"sourcesContent":["//#region Imports\n\nimport type { BinarySettings } from './@types';\nimport type {\n AdapterContract,\n FrameworkContract,\n HandlerContract,\n ResolverContract,\n ServerlessHandler,\n} from './contracts';\nimport {\n DEFAULT_BINARY_CONTENT_TYPES,\n DEFAULT_BINARY_ENCODINGS,\n type ILogger,\n createDefaultLogger,\n} from './core';\n\n//#endregion\n\n/**\n * The class used to build the serverless handler.\n *\n * @example\n * ```typescript\n * const app = express();\n * export const handler = ServerlessAdapter.new(app)\n * .setFramework(new ExpressFramework())\n * .setHandler(new DefaultHandler())\n * .setResolver(new PromiseResolver())\n * .setRespondWithErrors(true)\n * .addAdapter(new AlbAdapter())\n * .addAdapter(new SQSAdapter())\n * .addAdapter(new SNSAdapter())\n * .build();\n * ```\n *\n * @breadcrumb ServerlessAdapter\n * @public\n */\nexport class ServerlessAdapter<\n TApp,\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn,\n> {\n //#region Constructor\n\n /**\n * Default constructor\n */\n private constructor(app: TApp) {\n this.app = app;\n }\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * The instance of the app (express, hapi, koa, etc...)\n */\n protected app: TApp;\n\n //#endregion\n\n //#region Protected Properties\n\n /**\n * Settings for whether the response should be treated as binary or not\n *\n * @defaultValue `contentEncodings` and `contentTypes` are set with {@link DEFAULT_BINARY_ENCODINGS} and {@link DEFAULT_BINARY_CONTENT_TYPES}, respectively.\n */\n protected binarySettings: BinarySettings = {\n contentEncodings: DEFAULT_BINARY_ENCODINGS,\n contentTypes: DEFAULT_BINARY_CONTENT_TYPES,\n };\n\n /**\n * Indicates whether the error stack should be included in the response or not\n *\n * @remarks These errors will only be included when an error occurs while forwarding the event to the framework\n * @defaultValue True when NODE_ENV is equal to `development`\n */\n protected respondWithErrors: boolean = process.env.NODE_ENV === 'development';\n\n /**\n * The instance of the logger service\n */\n protected log: ILogger = createDefaultLogger();\n\n /**\n * The list of adapters used to handle an event's request and response\n */\n protected adapters: AdapterContract<TEvent, TContext, TResponse>[] = [];\n\n /**\n * The framework that will process requests\n */\n protected framework?: FrameworkContract<TApp>;\n\n /**\n * The resolver that aims to resolve the response to serverless and stop its execution when the request ends\n */\n protected resolver?: ResolverContract<\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn\n >;\n\n /**\n * The handler that will get the event, context and callback and pass it to the adapter and framework\n */\n protected handler?: HandlerContract<\n TApp,\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn\n >;\n\n //#endregion\n\n //#region Static Methods\n\n /**\n * Creates a new instance of the builder with app (express, hapi, koa, etc...)\n *\n * @param app - The instance of the app\n */\n public static new<\n TApp,\n TEvent,\n TContext = any,\n TCallback = any,\n TResponse = any,\n TReturn = any,\n >(\n app: TApp,\n ): ServerlessAdapter<TApp, TEvent, TContext, TCallback, TResponse, TReturn> {\n return new ServerlessAdapter(app);\n }\n\n //#endregion\n\n //#region Builder Methods\n\n /**\n * Defines the handler that will get the event, context and callback and pass it to the adapter and framework\n *\n * @param handler - The implementation of the handler contract\n */\n public setHandler(\n handler: HandlerContract<\n TApp,\n TEvent,\n TContext,\n TCallback,\n TResponse,\n TReturn\n >,\n ): Omit<this, 'setHandler'> {\n if (this.handler)\n throw new Error('SERVERLESS_ADAPTER: The handler should not set twice.');\n\n this.handler = handler;\n\n return this;\n }\n\n /**\n * Defines the resolver that aims to resolve the response to serverless and stop its execution when the request ends\n *\n * @param resolver - The implementation of the resolver contract\n */\n public setResolver(\n resolver: ResolverContract<TEvent, TContext, TCallback, TResponse, TReturn>,\n ): Omit<this, 'setResolver'> {\n if (this.resolver)\n throw new Error('SERVERLESS_ADAPTER: The resolver should not set twice.');\n\n this.resolver = resolver;\n\n return this;\n }\n\n /**\n * Defines the framework that will process requests\n *\n * @param framework - The implementation of the framework contract\n */\n public setFramework(\n framework: FrameworkContract<TApp>,\n ): Omit<this, 'setFramework'> {\n if (this.framework) {\n throw new Error(\n 'SERVERLESS_ADAPTER: The framework should not set twice.',\n );\n }\n\n this.framework = framework;\n\n return this;\n }\n\n /**\n * Defines the logger service used during the execution of the handler\n *\n * @param logger - The implementation of the logger\n */\n public setLogger(logger: ILogger): Omit<this, 'setLogger'> {\n this.log = logger;\n\n return this;\n }\n\n /**\n * Defines the binary settings for whether the response should be treated as binary or not\n *\n * @param binarySettings - The binary settings\n */\n public setBinarySettings(\n binarySettings: BinarySettings,\n ): Omit<this, 'setBinarySettings'> {\n this.binarySettings = {\n ...this.binarySettings,\n ...binarySettings,\n };\n\n return this;\n }\n\n /**\n * Defines the responseWithErrors, a property that indicates whether the error stack should be included in the response or not\n *\n * @param respondWithErrors - Should include or not the errors in response\n */\n public setRespondWithErrors(\n respondWithErrors: boolean,\n ): Omit<this, 'setRespondWithErrors'> {\n this.respondWithErrors = respondWithErrors;\n\n return this;\n }\n\n /**\n * Add an adapter to the adapters list to handle the event coming from any serverless event source\n *\n * @param adapter - The implementation of the adapter contract\n */\n public addAdapter(\n adapter: AdapterContract<TEvent, TContext, TResponse>,\n ): Pick<this, 'addAdapter' | 'build'> {\n this.adapters.push(adapter);\n\n return this;\n }\n\n /**\n * The builder method that returns the handler function to be exported for serverless consumption\n */\n public build(): ServerlessHandler<TReturn> {\n if (!this.resolver) {\n throw new Error(\n 'SERVERLESS_ADAPTER: Is required to set a resolver before build.',\n );\n }\n\n if (!this.framework) {\n throw new Error(\n 'SERVERLESS_ADAPTER: Is required to set a framework before build.',\n );\n }\n\n if (!this.handler) {\n throw new Error(\n 'SERVERLESS_ADAPTER: Is required to set a handler before build.',\n );\n }\n\n if (this.adapters.length === 0) {\n throw new Error(\n 'SERVERLESS_ADAPTER: Is required to set at least one adapter.',\n );\n }\n\n return this.handler.getHandler(\n this.app,\n this.framework,\n this.adapters,\n this.resolver,\n this.binarySettings,\n this.respondWithErrors,\n this.log,\n );\n }\n\n //#endregion\n}\n"],"mappings":"wRAuCO,IAAMA,EAAN,MAAMC,CAOX,CA9CF,MA8CE,CAAAC,EAAA,0BAMQ,YAAYC,EAAW,CAC7B,KAAK,IAAMA,CACb,CASU,IAWA,eAAiC,CACzC,iBAAkBC,EAClB,aAAcC,CAChB,EAQU,kBAA6B,QAAQ,IAAI,WAAa,cAKtD,IAAeC,EAAoB,EAKnC,SAA2D,CAAC,EAK5D,UAKA,SAWA,QAkBV,OAAc,IAQZH,EAC0E,CAC1E,OAAO,IAAIF,EAAkBE,CAAG,CAClC,CAWO,WACLI,EAQ0B,CAC1B,GAAI,KAAK,QACP,MAAM,IAAI,MAAM,uDAAuD,EAEzE,YAAK,QAAUA,EAER,IACT,CAOO,YACLC,EAC2B,CAC3B,GAAI,KAAK,SACP,MAAM,IAAI,MAAM,wDAAwD,EAE1E,YAAK,SAAWA,EAET,IACT,CAOO,aACLC,EAC4B,CAC5B,GAAI,KAAK,UACP,MAAM,IAAI,MACR,yDACF,EAGF,YAAK,UAAYA,EAEV,IACT,CAOO,UAAUC,EAA0C,CACzD,YAAK,IAAMA,EAEJ,IACT,CAOO,kBACLC,EACiC,CACjC,YAAK,eAAiB,CACpB,GAAG,KAAK,eACR,GAAGA,CACL,EAEO,IACT,CAOO,qBACLC,EACoC,CACpC,YAAK,kBAAoBA,EAElB,IACT,CAOO,WACLC,EACoC,CACpC,YAAK,SAAS,KAAKA,CAAO,EAEnB,IACT,CAKO,OAAoC,CACzC,GAAI,CAAC,KAAK,SACR,MAAM,IAAI,MACR,iEACF,EAGF,GAAI,CAAC,KAAK,UACR,MAAM,IAAI,MACR,kEACF,EAGF,GAAI,CAAC,KAAK,QACR,MAAM,IAAI,MACR,gEACF,EAGF,GAAI,KAAK,SAAS,SAAW,EAC3B,MAAM,IAAI,MACR,8DACF,EAGF,OAAO,KAAK,QAAQ,WAClB,KAAK,IACL,KAAK,UACL,KAAK,SACL,KAAK,SACL,KAAK,eACL,KAAK,kBACL,KAAK,GACP,CACF,CAGF","names":["ServerlessAdapter","_ServerlessAdapter","__name","app","DEFAULT_BINARY_ENCODINGS","DEFAULT_BINARY_CONTENT_TYPES","createDefaultLogger","handler","resolver","framework","logger","binarySettings","respondWithErrors","adapter"]}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The type representing the possible log levels to choose from.
3
+ *
4
+ * @breadcrumb Core / Logger
5
+ * @public
6
+ */
7
+ type LogLevels = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'none';
8
+ /**
9
+ * The options to customize {@link ILogger}
10
+ *
11
+ * @breadcrumb Core / Logger
12
+ * @public
13
+ */
14
+ type LoggerOptions = {
15
+ /**
16
+ * Select the log level, {@link LogLevels | see more}.
17
+ *
18
+ * @defaultValue error
19
+ */
20
+ level: LogLevels;
21
+ };
22
+ /**
23
+ * The log function used in any level.
24
+ *
25
+ * @breadcrumb Core / Logger
26
+ * @public
27
+ */
28
+ type LoggerFN = (message: any, ...additional: any[]) => void;
29
+ /**
30
+ * The interface representing the logger, you can provide a custom logger by implementing this interface.
31
+ *
32
+ * @breadcrumb Core / Logger
33
+ * @public
34
+ */
35
+ type ILogger = Record<Exclude<LogLevels, 'none'>, LoggerFN>;
36
+ /**
37
+ * The method used to create a simple logger instance to use in this library.
38
+ *
39
+ * @remarks Behind the scenes, this simple logger sends the message to the `console` methods.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const logger = createDefaultLogger();
44
+ *
45
+ * logger.error('An error happens.');
46
+ * // An error happens.
47
+ * ```
48
+ *
49
+ * @param level - Select the level of the log
50
+ *
51
+ * @breadcrumb Core / Logger
52
+ * @public
53
+ */
54
+ declare function createDefaultLogger({ level }?: LoggerOptions): ILogger;
55
+ /**
56
+ * The method used to chck if logger was created by this library, or it was defined by the user.
57
+ *
58
+ * @param logger - The instance of the logger to check
59
+ *
60
+ * @breadcrumb Core / Logger
61
+ * @public
62
+ */
63
+ declare function isInternalLogger(logger: ILogger): boolean;
64
+
65
+ export { type ILogger as I, type LogLevels as L, type LoggerOptions as a, type LoggerFN as b, createDefaultLogger as c, isInternalLogger as i };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The type representing the possible log levels to choose from.
3
+ *
4
+ * @breadcrumb Core / Logger
5
+ * @public
6
+ */
7
+ type LogLevels = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'none';
8
+ /**
9
+ * The options to customize {@link ILogger}
10
+ *
11
+ * @breadcrumb Core / Logger
12
+ * @public
13
+ */
14
+ type LoggerOptions = {
15
+ /**
16
+ * Select the log level, {@link LogLevels | see more}.
17
+ *
18
+ * @defaultValue error
19
+ */
20
+ level: LogLevels;
21
+ };
22
+ /**
23
+ * The log function used in any level.
24
+ *
25
+ * @breadcrumb Core / Logger
26
+ * @public
27
+ */
28
+ type LoggerFN = (message: any, ...additional: any[]) => void;
29
+ /**
30
+ * The interface representing the logger, you can provide a custom logger by implementing this interface.
31
+ *
32
+ * @breadcrumb Core / Logger
33
+ * @public
34
+ */
35
+ type ILogger = Record<Exclude<LogLevels, 'none'>, LoggerFN>;
36
+ /**
37
+ * The method used to create a simple logger instance to use in this library.
38
+ *
39
+ * @remarks Behind the scenes, this simple logger sends the message to the `console` methods.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const logger = createDefaultLogger();
44
+ *
45
+ * logger.error('An error happens.');
46
+ * // An error happens.
47
+ * ```
48
+ *
49
+ * @param level - Select the level of the log
50
+ *
51
+ * @breadcrumb Core / Logger
52
+ * @public
53
+ */
54
+ declare function createDefaultLogger({ level }?: LoggerOptions): ILogger;
55
+ /**
56
+ * The method used to chck if logger was created by this library, or it was defined by the user.
57
+ *
58
+ * @param logger - The instance of the logger to check
59
+ *
60
+ * @breadcrumb Core / Logger
61
+ * @public
62
+ */
63
+ declare function isInternalLogger(logger: ILogger): boolean;
64
+
65
+ export { type ILogger as I, type LogLevels as L, type LoggerOptions as a, type LoggerFN as b, createDefaultLogger as c, isInternalLogger as i };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Removes 'optional' attributes from a type's properties
3
+ *
4
+ * @breadcrumb Types
5
+ * @public
6
+ */
7
+ type Concrete<Type> = {
8
+ [Property in keyof Type]-?: Type[Property];
9
+ };
10
+
11
+ /**
12
+ * Transform the path and a map of query params to a string with formatted query params
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const path = '/pets/search';
17
+ * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };
18
+ * const result = getPathWithQueryStringParams(path, queryParams);
19
+ * console.log(result);
20
+ * // /pets/search?batata=&petType=dog&petType=fish
21
+ * ```
22
+ *
23
+ * @param path - The path
24
+ * @param queryParams - The query params
25
+ *
26
+ * @breadcrumb Core / Path
27
+ * @public
28
+ */
29
+ declare function getPathWithQueryStringParams(path: string, queryParams: string | Record<string, string | string[] | undefined> | undefined | null): string;
30
+ /**
31
+ * Map query params to a string with formatted query params
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const queryParams = { batata: undefined, petType: [ 'dog', 'fish' ] };
36
+ * const result = getQueryParamsStringFromRecord(queryParams);
37
+ * console.log(result);
38
+ * // batata=&petType=dog&petType=fish
39
+ * ```
40
+ *
41
+ * @param queryParamsRecord - The query params record
42
+ *
43
+ * @breadcrumb Core / Path
44
+ * @public
45
+ */
46
+ declare function getQueryParamsStringFromRecord(queryParamsRecord: Record<string, string | string[] | undefined> | undefined | null): string;
47
+ /**
48
+ * Type of the function to strip base path
49
+ *
50
+ * @breadcrumb Core / Path
51
+ * @public
52
+ */
53
+ type StripBasePathFn = (path: string) => string;
54
+ /**
55
+ * Get the strip base path function
56
+ *
57
+ * @param basePath - The base path
58
+ *
59
+ * @breadcrumb Core / Path
60
+ * @public
61
+ */
62
+ declare function buildStripBasePath(basePath: string | undefined): StripBasePathFn;
63
+
64
+ export { type Concrete as C, type StripBasePathFn as S, getQueryParamsStringFromRecord as a, buildStripBasePath as b, getPathWithQueryStringParams as g };