@xylabs/express 4.13.4 → 4.13.5

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 (2) hide show
  1. package/dist/node/index.d.ts +354 -382
  2. package/package.json +7 -7
@@ -1,382 +1,354 @@
1
- import type { Application } from 'express';
2
- import type { Express as Express_2 } from 'express';
3
- import type { LogFunction as LogFunction_2 } from '@xylabs/logger';
4
- import type { Logger as Logger_2 } from '@xylabs/logger';
5
- import type { Logger as Logger_3 } from 'winston';
6
- import type { NextFunction } from 'express';
7
- import type { NextHandleFunction } from 'connect';
8
- import type { OptionsJson } from 'body-parser';
9
- import type { ParamsDictionary } from 'express-serve-static-core';
10
- import type { Query } from 'express-serve-static-core';
11
- import type { Request as Request_2 } from 'express';
12
- import type { Request as Request_3 } from 'express-serve-static-core';
13
- import type { RequestHandler } from 'express';
14
- import type { Response as Response_2 } from 'express';
15
-
16
- export declare interface ApiDataResponse<T extends ApiResourceIdentifierObject> extends ApiResponseBase {
17
- data: T;
18
- included?: ApiResourceObject[];
19
- }
20
-
21
- export declare interface ApiError {
22
- /**
23
- * An application-specific error code, expressed as a string value.
24
- */
25
- code?: string;
26
- /**
27
- * A human-readable explanation specific to this occurrence of the problem. Like title, this field's value can be localized.
28
- */
29
- detail?: string;
30
- /**
31
- * A unique identifier for this particular occurrence of the problem.
32
- */
33
- id?: string;
34
- /**
35
- * A links object containing the following members:
36
- * about: a link that leads to further details about this particular occurrence of the problem
37
- */
38
- links?: ApiLinks;
39
- /**
40
- * A meta object containing non-standard meta-information about the error.
41
- */
42
- meta?: Record<string, unknown>;
43
- /**
44
- * An object containing references to the source of the error, optionally including any of the following members:
45
- */
46
- source?: Source;
47
- /**
48
- * The HTTP status code applicable to this problem, expressed as a string value.
49
- */
50
- status?: string;
51
- /**
52
- * A short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
53
- */
54
- title?: string;
55
- }
56
-
57
- export declare interface ApiErrorResponse extends ApiResponseBase {
58
- errors: ApiError[];
59
- }
60
-
61
- export declare type ApiLink = string | HrefWithMeta;
62
-
63
- export declare type ApiLinks = Record<string, ApiLink>;
64
-
65
- /**
66
- * Within a given API, each resource object's type and id pair MUST identify a single, unique resource.
67
- * (The set of URIs controlled by a server, or multiple servers acting as one, constitute an API.)
68
- */
69
- export declare interface ApiResourceIdentifierObject {
70
- /**
71
- * The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.
72
- */
73
- id: string;
74
- /**
75
- * The type member is used to describe resource objects that share common attributes and relationships.
76
- * The values of type members MUST adhere to the same constraints as member names.
77
- */
78
- type: string;
79
- }
80
-
81
- export declare interface ApiResourceObject extends ApiResourceIdentifierObject {
82
- /**
83
- * An attributes object representing some of the resource's data.
84
- */
85
- attributes?: Record<string, unknown>;
86
- /**
87
- * A links object containing links related to the resource.
88
- */
89
- links?: ApiLinks;
90
- /**
91
- * A meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
92
- */
93
- meta?: Record<string, unknown>;
94
- /**
95
- * A relationships object describing relationships between the resource and other JSON:API resources.
96
- */
97
- relationships?: Record<string, Relationship>;
98
- }
99
-
100
- export declare type ApiResponse<T extends ApiResourceIdentifierObject> = ApiDataResponse<T> | ApiErrorResponse;
101
-
102
- export declare interface ApiResponseBase {
103
- jsonapi?: JsonApi;
104
- links?: ApiLinks;
105
- meta?: Record<string, unknown>;
106
- }
107
-
108
- export declare function asyncHandler<P = NoReqParams, ResBody = NoResBody, ReqBody = NoReqBody, ReqQuery = NoReqQuery, Locals extends NoLocals = NoLocals>(fn: RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals>): (req: Request_2<P, ResBody, ReqBody, ReqQuery, Locals>, res: Response_2<ResBody, Locals>, next: NextFunction) => Promise<void>;
109
-
110
- /**
111
- * Clears any flags on the response, allowing the response to
112
- * use the default standard response envelope
113
- * @param res The response to set to the standard response format
114
- */
115
- export declare const clearRawResponseFormat: (res: Response_2) => void;
116
-
117
- export declare const compactObject: <T extends Record<string, unknown>>(obj: T) => T;
118
-
119
- export declare class Counters {
120
- static counters: Record<string, number>;
121
- static inc(name: string, count?: number): void;
122
- static max(name: string, count: number): void;
123
- static min(name: string, count: number): void;
124
- private static catchError;
125
- }
126
-
127
- export declare const customPoweredByHeader: (req: Request_2, res: Response_2, next: NextFunction) => void;
128
-
129
- /**
130
- * The default options for the JSON Body Parser
131
- */
132
- export declare const DefaultJsonBodyParserOptions: OptionsJson;
133
-
134
- /**
135
- * The default maximum request body size for the JSON Body Parser
136
- */
137
- export declare const DefaultJsonBodyParserOptionsLimit = "100kb";
138
-
139
- /**
140
- * The default MIME types for the JSON Body Parser
141
- */
142
- export declare const DefaultJsonBodyParserOptionsTypes: string[];
143
-
144
- /**
145
- * Disable case sensitivity. When enabled, "/Foo" and "/foo" are different
146
- * routes. When disabled, "/Foo" and "/foo" are treated the same.
147
- * @param app The Express app to disable the header on.
148
- */
149
- export declare const disableCaseSensitiveRouting: (app: Express_2) => void;
150
-
151
- /**
152
- * By default Express appends the `X-Powered-By: Express` header to
153
- * all responses. Calling this method disables that behavior.
154
- * @param app The Express app to disable the header on.
155
- */
156
- export declare const disableExpressDefaultPoweredByHeader: (app: Express_2) => void;
157
-
158
- export declare interface Empty {
159
- }
160
-
161
- /**
162
- * Enable case sensitivity. When enabled, "/Foo" and "/foo" are different
163
- * routes. When disabled, "/Foo" and "/foo" are treated the same.
164
- * @param app The Express app to disable the header on.
165
- */
166
- export declare const enableCaseSensitiveRouting: (app: Express_2) => void;
167
-
168
- /**
169
- * By default Express appends the `X-Powered-By: Express` header to
170
- * all responses. Calling this method enables that behavior.
171
- * @param app The Express app to disable the header on.
172
- */
173
- export declare const enableExpressDefaultPoweredByHeader: (app: Express_2) => void;
174
-
175
- export declare const errorToJsonHandler: (error: ExpressError, req: Request_2, res: Response_2, next: NextFunction) => void;
176
-
177
- export declare interface ExpressError extends Error {
178
- statusCode?: number;
179
- }
180
-
181
- export declare const getDefaultLogger: () => Logger_2;
182
-
183
- /**
184
- * Since there can be multiple of certain HTTP headers or
185
- * to prevent ugliness if someone did send us multiple
186
- * instances of a header we only expect one of, this
187
- * method grabs the 1st/only one of the desired header
188
- * @param header The header to find
189
- * @param req The received HTTP request (with headers)
190
- * @returns The first or only occurrence of the specified HTTP header
191
- */
192
- export declare const getHttpHeader: (header: string, req: Request_3) => string | undefined;
193
-
194
- /**
195
- * Get a JSON Body Parser connect middleware handler
196
- * @param options The options for the JSON Body Parser
197
- * @returns A middleware function that parses JSON bodies
198
- */
199
- export declare const getJsonBodyParser: (options?: OptionsJson) => NextHandleFunction;
200
-
201
- /**
202
- * Gets the default JSON Body Parser options merged with the supplied options
203
- * with the supplied options taking precedence
204
- * @param options The options to override the default JSON Body Parser options with
205
- * @returns The combined JSON Body Parser options with the supplied values taking
206
- * precedence over the default
207
- */
208
- export declare const getJsonBodyParserOptions: (options?: Partial<OptionsJson>) => OptionsJson;
209
-
210
- export declare const getLogger: (minVerbosity?: LoggerVerbosity) => Logger_2;
211
-
212
- export declare const getResponseMetadata: (res: Response_2) => Record<string, unknown>;
213
-
214
- export declare interface HrefWithMeta {
215
- href: string;
216
- meta: Record<string, unknown>;
217
- }
218
-
219
- export declare interface IRelationshipData {
220
- data: ResourceLinkage;
221
- }
222
-
223
- export declare interface IRelationshipLinks {
224
- links: IRelationshipRelatedLink | IRelationshipSelfLink;
225
- }
226
-
227
- export declare interface IRelationshipRelatedLink {
228
- /**
229
- * A related resource link
230
- */
231
- related: string;
232
- }
233
-
234
- export declare interface IRelationshipSelfLink {
235
- /**
236
- * A link for the relationship itself (a "relationship link"). This link allows the client to directly manipulate the relationship.
237
- * For example, removing an author through an article’s relationship URL would disconnect the person from the article without
238
- * deleting the people resource itself. When fetched successfully, this link returns the linkage for the related resources as its primary data.
239
- */
240
- self: string;
241
- }
242
-
243
- /**
244
- * Checks if there are any flags on the response that would cause it
245
- * to forgo the standard response envelope and return the raw response
246
- * body to the client
247
- * @param res
248
- * @returns True if there are any flags on the response, false otherwise
249
- */
250
- export declare const isRawResponseFormatSet: (res: Response_2) => boolean;
251
-
252
- export declare interface JsonApi {
253
- meta?: Record<string, unknown>;
254
- version?: '1.0' | '1.1';
255
- }
256
-
257
- /**
258
- * A JSON Body Parser middleware handler initialized with the default options
259
- */
260
- export declare const jsonBodyParser: NextHandleFunction;
261
-
262
- /** @deprecated use from @xylabs/logger instead */
263
- export declare type LogFunction = LogFunction_2;
264
-
265
- /** @deprecated use from @xylabs/logger instead */
266
- export declare type Logger = Logger_2;
267
-
268
- export declare type LoggerMeta = Record<string, string | number>;
269
-
270
- export declare interface LoggerOptions {
271
- defaultMeta?: LoggerMeta;
272
- level?: LoggerVerbosity;
273
- }
274
-
275
- export declare type LoggerVerbosity = 'error' | 'warn' | 'info' | 'debug' | 'all';
276
-
277
- export declare type NoLocals = Record<string, any>;
278
-
279
- export declare type NoReqBody = Empty;
280
-
281
- export declare type NoReqParams = ParamsDictionary;
282
-
283
- export declare type NoReqQuery = Query;
284
-
285
- export declare type NoResBody = Empty;
286
-
287
- export declare const notImplemented: RequestHandler;
288
-
289
- export declare type ParseFunc<T = number> = (value: string) => T;
290
-
291
- export declare class Profiler {
292
- stats: Record<string, number>;
293
- profile<T>(name: string, promise: Promise<T>): Promise<T>;
294
- }
295
-
296
- /**
297
- * The value of the relationships key MUST be an object (a "relationships object"). Members of the relationships object ("relationships")
298
- * represent references from the resource object in which it’s defined to other resource objects.
299
- * Relationships may be to-one or to-many.
300
- */
301
- export declare type Relationship = IRelationshipLinks | IRelationshipData | RelationshipMeta;
302
-
303
- export declare type RelationshipMeta = Record<string, unknown>;
304
-
305
- /**
306
- * Resource linkage in a compound document allows a client to link together all of the included resource objects without having to GET any URLs via links.
307
- * Resource linkage MUST be represented as one of the following:
308
- * null for empty to-one relationships.
309
- * an empty array ([]) for empty to-many relationships.
310
- * a single resource identifier object for non-empty to-one relationships.
311
- * • an array of resource identifier objects for non-empty to-many relationships.
312
- */
313
- export declare type ResourceLinkage = null | [] | ApiResourceIdentifierObject | ApiResourceIdentifierObject[];
314
-
315
- /**
316
- * Connect middleware to enable profiling of response lifecycle timing. To effectively profile
317
- * the response timing, this middleware needs to be called first when initializing your Express
318
- * App
319
- * @example
320
- * const app = express()
321
- * app.use(responseProfiler)
322
- * // other initialization ...
323
- * @param _req The request
324
- * @param res The response
325
- * @param next The next function
326
- */
327
- export declare const responseProfiler: (_req: Request_2, res: Response_2, next: NextFunction) => void;
328
-
329
- /**
330
- * Flags the response to forgo the standard response envelope
331
- * and return the raw response body to the client
332
- * @param res The response to disable the standard response format on
333
- */
334
- export declare const setRawResponseFormat: (res: Response_2) => void;
335
-
336
- /**
337
- * An object containing references to the source of the error
338
- */
339
- export declare interface Source {
340
- /**
341
- * A string indicating which URI query parameter caused the error.
342
- */
343
- parameter?: string;
344
- /**
345
- * A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object,
346
- * or "/data/attributes/title" for a specific attribute].
347
- */
348
- pointer?: string;
349
- }
350
-
351
- export declare const standardErrors: (err: ExpressError | undefined, req: Request_2, res: Response_2, next: NextFunction) => void;
352
-
353
- /**
354
- * Connect middleware to enable the transform of all responses to match
355
- * the standard response format (compatible with JSON API)
356
- */
357
- export declare const standardResponses: RequestHandler;
358
-
359
- export declare const tryParse: <T = number>(func: ParseFunc<T>, value?: string) => (T & {}) | undefined;
360
-
361
- export declare const tryParseFloat: (value?: string) => number | undefined;
362
-
363
- export declare const tryParseInt: (value?: string) => number | undefined;
364
-
365
- export declare const useRequestCounters: (app: Application) => void;
366
-
367
- /**
368
- * Wrap Winston logger methods to adapt to familiar
369
- * console logging methods
370
- */
371
- export declare class WrappedWinstonLogger implements Logger_2 {
372
- protected readonly winston: Logger_3;
373
- constructor(winston: Logger_3);
374
- debug: LogFunction_2;
375
- error: LogFunction_2;
376
- info: LogFunction_2;
377
- log: LogFunction_2;
378
- trace: LogFunction_2;
379
- warn: LogFunction_2;
380
- }
381
-
382
- export { }
1
+ import { RequestHandler, Request, Response, NextFunction, Express, Application } from 'express';
2
+ import { ParamsDictionary, Query, Request as Request$1 } from 'express-serve-static-core';
3
+ import { Logger as Logger$1, LogFunction as LogFunction$1 } from '@xylabs/logger';
4
+ import { Logger as Logger$2 } from 'winston';
5
+ import { OptionsJson } from 'body-parser';
6
+ import { NextHandleFunction } from 'connect';
7
+
8
+ declare function asyncHandler<P = NoReqParams, ResBody = NoResBody, ReqBody = NoReqBody, ReqQuery = NoReqQuery, Locals extends NoLocals = NoLocals>(fn: RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals>): (req: Request<P, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, next: NextFunction) => Promise<unknown>;
9
+ interface Empty {
10
+ }
11
+ type NoReqParams = ParamsDictionary;
12
+ type NoResBody = Empty;
13
+ type NoReqBody = Empty;
14
+ type NoReqQuery = Query;
15
+ type NoLocals = Record<string, any>;
16
+
17
+ interface ExpressError extends Error {
18
+ statusCode?: number;
19
+ }
20
+
21
+ declare const errorToJsonHandler: (error: ExpressError, req: Request, res: Response, next: NextFunction) => void;
22
+
23
+ declare const notImplemented: RequestHandler;
24
+
25
+ /**
26
+ * Since there can be multiple of certain HTTP headers or
27
+ * to prevent ugliness if someone did send us multiple
28
+ * instances of a header we only expect one of, this
29
+ * method grabs the 1st/only one of the desired header
30
+ * @param header The header to find
31
+ * @param req The received HTTP request (with headers)
32
+ * @returns The first or only occurrence of the specified HTTP header
33
+ */
34
+ declare const getHttpHeader: (header: string, req: Request$1) => string | undefined;
35
+
36
+ /**
37
+ * Wrap Winston logger methods to adapt to familiar
38
+ * console logging methods
39
+ */
40
+ declare class WrappedWinstonLogger implements Logger$1 {
41
+ protected readonly winston: Logger$2;
42
+ constructor(winston: Logger$2);
43
+ debug: LogFunction$1;
44
+ error: LogFunction$1;
45
+ info: LogFunction$1;
46
+ log: LogFunction$1;
47
+ trace: LogFunction$1;
48
+ warn: LogFunction$1;
49
+ }
50
+
51
+ /**
52
+ * Static instance to prevent multiple instances of the same logger
53
+ * with the same config
54
+ */
55
+ declare global {
56
+ var xy: {
57
+ defaultLogger?: WrappedWinstonLogger;
58
+ };
59
+ }
60
+ declare const getDefaultLogger: () => Logger$1;
61
+
62
+ type LoggerVerbosity = 'error' | 'warn' | 'info' | 'debug' | 'all';
63
+
64
+ declare const getLogger: (minVerbosity?: LoggerVerbosity) => Logger$1;
65
+
66
+ type LoggerMeta = Record<string, string | number>;
67
+
68
+ interface LoggerOptions {
69
+ defaultMeta?: LoggerMeta;
70
+ level?: LoggerVerbosity;
71
+ }
72
+
73
+ /** @deprecated use from @xylabs/logger instead */
74
+ type LogFunction = LogFunction$1;
75
+ /** @deprecated use from @xylabs/logger instead */
76
+ type Logger = Logger$1;
77
+
78
+ /**
79
+ * Enable case sensitivity. When enabled, "/Foo" and "/foo" are different
80
+ * routes. When disabled, "/Foo" and "/foo" are treated the same.
81
+ * @param app The Express app to disable the header on.
82
+ */
83
+ declare const enableCaseSensitiveRouting: (app: Express) => void;
84
+ /**
85
+ * Disable case sensitivity. When enabled, "/Foo" and "/foo" are different
86
+ * routes. When disabled, "/Foo" and "/foo" are treated the same.
87
+ * @param app The Express app to disable the header on.
88
+ */
89
+ declare const disableCaseSensitiveRouting: (app: Express) => void;
90
+
91
+ /**
92
+ * By default Express appends the `X-Powered-By: Express` header to
93
+ * all responses. Calling this method enables that behavior.
94
+ * @param app The Express app to disable the header on.
95
+ */
96
+ declare const enableExpressDefaultPoweredByHeader: (app: Express) => void;
97
+ /**
98
+ * By default Express appends the `X-Powered-By: Express` header to
99
+ * all responses. Calling this method disables that behavior.
100
+ * @param app The Express app to disable the header on.
101
+ */
102
+ declare const disableExpressDefaultPoweredByHeader: (app: Express) => void;
103
+ declare const customPoweredByHeader: (req: Request, res: Response, next: NextFunction) => void;
104
+
105
+ /**
106
+ * The default maximum request body size for the JSON Body Parser
107
+ */
108
+ declare const DefaultJsonBodyParserOptionsLimit = "100kb";
109
+ /**
110
+ * The default MIME types for the JSON Body Parser
111
+ */
112
+ declare const DefaultJsonBodyParserOptionsTypes: string[];
113
+ /**
114
+ * The default options for the JSON Body Parser
115
+ */
116
+ declare const DefaultJsonBodyParserOptions: OptionsJson;
117
+ /**
118
+ * Gets the default JSON Body Parser options merged with the supplied options
119
+ * with the supplied options taking precedence
120
+ * @param options The options to override the default JSON Body Parser options with
121
+ * @returns The combined JSON Body Parser options with the supplied values taking
122
+ * precedence over the default
123
+ */
124
+ declare const getJsonBodyParserOptions: (options?: Partial<OptionsJson>) => OptionsJson;
125
+ /**
126
+ * Get a JSON Body Parser connect middleware handler
127
+ * @param options The options for the JSON Body Parser
128
+ * @returns A middleware function that parses JSON bodies
129
+ */
130
+ declare const getJsonBodyParser: (options?: OptionsJson) => NextHandleFunction;
131
+ /**
132
+ * A JSON Body Parser middleware handler initialized with the default options
133
+ */
134
+ declare const jsonBodyParser: NextHandleFunction;
135
+
136
+ declare const useRequestCounters: (app: Application) => void;
137
+
138
+ /**
139
+ * Connect middleware to enable profiling of response lifecycle timing. To effectively profile
140
+ * the response timing, this middleware needs to be called first when initializing your Express
141
+ * App
142
+ * @example
143
+ * const app = express()
144
+ * app.use(responseProfiler)
145
+ * // other initialization ...
146
+ * @param _req The request
147
+ * @param res The response
148
+ * @param next The next function
149
+ */
150
+ declare const responseProfiler: (_req: Request, res: Response, next: NextFunction) => void;
151
+
152
+ declare const getResponseMetadata: (res: Response) => Record<string, unknown>;
153
+
154
+ interface HrefWithMeta {
155
+ href: string;
156
+ meta: Record<string, unknown>;
157
+ }
158
+ type ApiLink = string | HrefWithMeta;
159
+ type ApiLinks = Record<string, ApiLink>;
160
+
161
+ /**
162
+ * An object containing references to the source of the error
163
+ */
164
+ interface Source {
165
+ /**
166
+ * A string indicating which URI query parameter caused the error.
167
+ */
168
+ parameter?: string;
169
+ /**
170
+ * A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object,
171
+ * or "/data/attributes/title" for a specific attribute].
172
+ */
173
+ pointer?: string;
174
+ }
175
+ interface ApiError {
176
+ /**
177
+ * An application-specific error code, expressed as a string value.
178
+ */
179
+ code?: string;
180
+ /**
181
+ * A human-readable explanation specific to this occurrence of the problem. Like title, this field's value can be localized.
182
+ */
183
+ detail?: string;
184
+ /**
185
+ * A unique identifier for this particular occurrence of the problem.
186
+ */
187
+ id?: string;
188
+ /**
189
+ * A links object containing the following members:
190
+ * about: a link that leads to further details about this particular occurrence of the problem
191
+ */
192
+ links?: ApiLinks;
193
+ /**
194
+ * A meta object containing non-standard meta-information about the error.
195
+ */
196
+ meta?: Record<string, unknown>;
197
+ /**
198
+ * An object containing references to the source of the error, optionally including any of the following members:
199
+ */
200
+ source?: Source;
201
+ /**
202
+ * The HTTP status code applicable to this problem, expressed as a string value.
203
+ */
204
+ status?: string;
205
+ /**
206
+ * A short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
207
+ */
208
+ title?: string;
209
+ }
210
+
211
+ /**
212
+ * Within a given API, each resource object's type and id pair MUST identify a single, unique resource.
213
+ * (The set of URIs controlled by a server, or multiple servers acting as one, constitute an API.)
214
+ */
215
+ interface ApiResourceIdentifierObject {
216
+ /**
217
+ * The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.
218
+ */
219
+ id: string;
220
+ /**
221
+ * The type member is used to describe resource objects that share common attributes and relationships.
222
+ * The values of type members MUST adhere to the same constraints as member names.
223
+ */
224
+ type: string;
225
+ }
226
+
227
+ interface IRelationshipSelfLink {
228
+ /**
229
+ * A link for the relationship itself (a "relationship link"). This link allows the client to directly manipulate the relationship.
230
+ * For example, removing an author through an article’s relationship URL would disconnect the person from the article without
231
+ * deleting the people resource itself. When fetched successfully, this link returns the linkage for the related resources as its primary data.
232
+ */
233
+ self: string;
234
+ }
235
+ interface IRelationshipRelatedLink {
236
+ /**
237
+ * A related resource link
238
+ */
239
+ related: string;
240
+ }
241
+ interface IRelationshipLinks {
242
+ links: IRelationshipRelatedLink | IRelationshipSelfLink;
243
+ }
244
+ /**
245
+ * Resource linkage in a compound document allows a client to link together all of the included resource objects without having to GET any URLs via links.
246
+ * Resource linkage MUST be represented as one of the following:
247
+ * null for empty to-one relationships.
248
+ * an empty array ([]) for empty to-many relationships.
249
+ * • a single resource identifier object for non-empty to-one relationships.
250
+ * • an array of resource identifier objects for non-empty to-many relationships.
251
+ */
252
+ type ResourceLinkage = null | [] | ApiResourceIdentifierObject | ApiResourceIdentifierObject[];
253
+ interface IRelationshipData {
254
+ data: ResourceLinkage;
255
+ }
256
+ type RelationshipMeta = Record<string, unknown>;
257
+ /**
258
+ * The value of the relationships key MUST be an object (a "relationships object"). Members of the relationships object ("relationships")
259
+ * represent references from the resource object in which it’s defined to other resource objects.
260
+ * Relationships may be to-one or to-many.
261
+ */
262
+ type Relationship = IRelationshipLinks | IRelationshipData | RelationshipMeta;
263
+
264
+ /**
265
+ * Loosely following the JSON API 1.0 formats and conventions
266
+ * https://jsonapi.org/format/
267
+ */
268
+
269
+ interface ApiResourceObject extends ApiResourceIdentifierObject {
270
+ /**
271
+ * An attributes object representing some of the resource's data.
272
+ */
273
+ attributes?: Record<string, unknown>;
274
+ /**
275
+ * A links object containing links related to the resource.
276
+ */
277
+ links?: ApiLinks;
278
+ /**
279
+ * A meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
280
+ */
281
+ meta?: Record<string, unknown>;
282
+ /**
283
+ * A relationships object describing relationships between the resource and other JSON:API resources.
284
+ */
285
+ relationships?: Record<string, Relationship>;
286
+ }
287
+ interface JsonApi {
288
+ meta?: Record<string, unknown>;
289
+ version?: '1.0' | '1.1';
290
+ }
291
+ interface ApiResponseBase {
292
+ jsonapi?: JsonApi;
293
+ links?: ApiLinks;
294
+ meta?: Record<string, unknown>;
295
+ }
296
+ interface ApiDataResponse<T extends ApiResourceIdentifierObject> extends ApiResponseBase {
297
+ data: T;
298
+ included?: ApiResourceObject[];
299
+ }
300
+ interface ApiErrorResponse extends ApiResponseBase {
301
+ errors: ApiError[];
302
+ }
303
+ type ApiResponse<T extends ApiResourceIdentifierObject> = ApiDataResponse<T> | ApiErrorResponse;
304
+
305
+ declare const standardErrors: (err: ExpressError | undefined, req: Request, res: Response, next: NextFunction) => void;
306
+
307
+ /**
308
+ * Flags the response to forgo the standard response envelope
309
+ * and return the raw response body to the client
310
+ * @param res The response to disable the standard response format on
311
+ */
312
+ declare const setRawResponseFormat: (res: Response) => void;
313
+ /**
314
+ * Clears any flags on the response, allowing the response to
315
+ * use the default standard response envelope
316
+ * @param res The response to set to the standard response format
317
+ */
318
+ declare const clearRawResponseFormat: (res: Response) => void;
319
+ /**
320
+ * Checks if there are any flags on the response that would cause it
321
+ * to forgo the standard response envelope and return the raw response
322
+ * body to the client
323
+ * @param res
324
+ * @returns True if there are any flags on the response, false otherwise
325
+ */
326
+ declare const isRawResponseFormatSet: (res: Response) => boolean;
327
+ /**
328
+ * Connect middleware to enable the transform of all responses to match
329
+ * the standard response format (compatible with JSON API)
330
+ */
331
+ declare const standardResponses: RequestHandler;
332
+
333
+ declare class Counters {
334
+ static counters: Record<string, number>;
335
+ static inc(name: string, count?: number): void;
336
+ static max(name: string, count: number): void;
337
+ static min(name: string, count: number): void;
338
+ private static catchError;
339
+ }
340
+
341
+ declare class Profiler {
342
+ stats: Record<string, number>;
343
+ profile<T>(name: string, promise: Promise<T>): Promise<T>;
344
+ }
345
+
346
+ declare const compactObject: <T extends Record<string, unknown>>(obj: T) => T;
347
+
348
+ type ParseFunc<T = number> = (value: string) => T;
349
+ declare const tryParse: <T = number>(func: ParseFunc<T>, value?: string) => (T & {}) | undefined;
350
+ declare const tryParseFloat: (value?: string) => number | undefined;
351
+ declare const tryParseInt: (value?: string) => number | undefined;
352
+
353
+ export { Counters, DefaultJsonBodyParserOptions, DefaultJsonBodyParserOptionsLimit, DefaultJsonBodyParserOptionsTypes, Profiler, WrappedWinstonLogger, asyncHandler, clearRawResponseFormat, compactObject, customPoweredByHeader, disableCaseSensitiveRouting, disableExpressDefaultPoweredByHeader, enableCaseSensitiveRouting, enableExpressDefaultPoweredByHeader, errorToJsonHandler, getDefaultLogger, getHttpHeader, getJsonBodyParser, getJsonBodyParserOptions, getLogger, getResponseMetadata, isRawResponseFormatSet, jsonBodyParser, notImplemented, responseProfiler, setRawResponseFormat, standardErrors, standardResponses, tryParse, tryParseFloat, tryParseInt, useRequestCounters };
354
+ export type { ApiDataResponse, ApiError, ApiErrorResponse, ApiLink, ApiLinks, ApiResourceIdentifierObject, ApiResourceObject, ApiResponse, ApiResponseBase, Empty, ExpressError, HrefWithMeta, IRelationshipData, IRelationshipLinks, IRelationshipRelatedLink, IRelationshipSelfLink, JsonApi, LogFunction, Logger, LoggerMeta, LoggerOptions, LoggerVerbosity, NoLocals, NoReqBody, NoReqParams, NoReqQuery, NoResBody, ParseFunc, Relationship, RelationshipMeta, ResourceLinkage, Source };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/express",
3
- "version": "4.13.4",
3
+ "version": "4.13.5",
4
4
  "description": "SDK for base code for Api repos that use express and deploy on AWS ECS",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -47,9 +47,9 @@
47
47
  "dependencies": {
48
48
  "@types/connect": "^3.4.38",
49
49
  "@types/express-serve-static-core": "^5.0.7",
50
- "@xylabs/assert": "^4.13.4",
51
- "@xylabs/logger": "^4.13.4",
52
- "@xylabs/typeof": "^4.13.4",
50
+ "@xylabs/assert": "^4.13.5",
51
+ "@xylabs/logger": "^4.13.5",
52
+ "@xylabs/typeof": "^4.13.5",
53
53
  "body-parser": "^2.2.0",
54
54
  "express-mung": "^0.5.1",
55
55
  "http-status-codes": "^2.3.0",
@@ -62,9 +62,9 @@
62
62
  "@types/express": "^5.0.3",
63
63
  "@types/express-mung": "^0.5.5",
64
64
  "@types/node": "^24.0.13",
65
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
66
- "@xylabs/tsconfig": "^7.0.0-rc.7",
67
- "@xylabs/vitest-extended": "^4.13.4",
65
+ "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.8",
66
+ "@xylabs/tsconfig": "^7.0.0-rc.8",
67
+ "@xylabs/vitest-extended": "^4.13.5",
68
68
  "body-parser": "^2.2.0",
69
69
  "express": "^5.1.0",
70
70
  "express-mung": "^0.5.1",