@creator.co/wapi 1.6.1 → 2.0.0-alpha.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.
- package/.github/workflows/npmpublish.yml +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +2 -4
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +12 -12
- package/dist/src/API/Request.js +53 -59
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.js +81 -156
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +54 -132
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.js +40 -98
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.js +122 -310
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Cache/Redis.js +55 -119
- package/dist/src/Cache/Redis.js.map +1 -1
- package/dist/src/Cache/types.js +1 -2
- package/dist/src/Config/Configuration.js +46 -86
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js +57 -119
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.js +35 -82
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.js +12 -27
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.js +3 -8
- package/dist/src/Database/Database.js.map +1 -1
- package/dist/src/Database/DatabaseManager.js +23 -28
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/DatabaseTransaction.js +50 -166
- package/dist/src/Database/DatabaseTransaction.js.map +1 -1
- package/dist/src/Database/index.js +11 -15
- package/dist/src/Database/index.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
- package/dist/src/Database/types.js +1 -2
- package/dist/src/Globals.js +93 -98
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +88 -222
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.js +83 -204
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.js +43 -107
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.js +22 -49
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.js +12 -16
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +21 -83
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.js +50 -99
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.js +32 -107
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.js +3 -35
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.js +64 -127
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.js +12 -55
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Util/AsyncSingleton.js +40 -164
- package/dist/src/Util/AsyncSingleton.js.map +1 -1
- package/dist/src/Util/Utils.js +18 -24
- package/dist/src/Util/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.js +10 -16
- package/dist/src/Validation/Validator.js.map +1 -1
- package/package.json +12 -12
- package/tests/Logger/Logger.test.ts +5 -3
- package/tsconfig.json +3 -1
package/dist/src/API/Response.js
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -34,35 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
8
|
});
|
|
36
9
|
};
|
|
37
|
-
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
var Globals_1 = require("../Globals");
|
|
10
|
+
import Globals from '../Globals';
|
|
66
11
|
/**
|
|
67
12
|
* CustomError class that extends the built-in Error class.
|
|
68
13
|
* @class
|
|
@@ -71,20 +16,17 @@ var Globals_1 = require("../Globals");
|
|
|
71
16
|
* @constructor
|
|
72
17
|
* @property {string} name - The name of the error.
|
|
73
18
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_this.name = body.error || 'UnknownError';
|
|
79
|
-
return _this;
|
|
19
|
+
class CustomError extends Error {
|
|
20
|
+
constructor(body) {
|
|
21
|
+
super(body.message || 'Unknown error!');
|
|
22
|
+
this.name = body.error || 'UnknownError';
|
|
80
23
|
}
|
|
81
|
-
|
|
82
|
-
}(Error));
|
|
24
|
+
}
|
|
83
25
|
/**
|
|
84
26
|
* Represents a response object with various methods for building and manipulating the response.
|
|
85
27
|
* @template BodyType - The type of the response body.
|
|
86
28
|
*/
|
|
87
|
-
|
|
29
|
+
export default class Response {
|
|
88
30
|
/**
|
|
89
31
|
* Constructs a new Response object with the given status code, body, and optional behavior.
|
|
90
32
|
* @param {number} statusCode - The HTTP status code of the response.
|
|
@@ -95,7 +37,7 @@ var Response = /** @class */ (function () {
|
|
|
95
37
|
* @param {boolean} [optBehaviour.throwOnErrors] - Indicates whether errors should be thrown for non-successful status codes.
|
|
96
38
|
* @param {boolean} [optBehaviour
|
|
97
39
|
*/
|
|
98
|
-
|
|
40
|
+
constructor(statusCode, body, optBehaviour) {
|
|
99
41
|
// response
|
|
100
42
|
this.statusCode = statusCode;
|
|
101
43
|
this.body = body;
|
|
@@ -116,34 +58,34 @@ var Response = /** @class */ (function () {
|
|
|
116
58
|
* Get the status code of the response.
|
|
117
59
|
* @returns {number} The status code.
|
|
118
60
|
*/
|
|
119
|
-
|
|
61
|
+
getCode() {
|
|
120
62
|
return this.statusCode;
|
|
121
|
-
}
|
|
63
|
+
}
|
|
122
64
|
/**
|
|
123
65
|
* Get the body of the object.
|
|
124
66
|
* @returns {BodyType} The body of the object.
|
|
125
67
|
*/
|
|
126
|
-
|
|
68
|
+
getBody() {
|
|
127
69
|
return this.body;
|
|
128
|
-
}
|
|
70
|
+
}
|
|
129
71
|
/**
|
|
130
72
|
* Appends a key-value pair into the body object.
|
|
131
73
|
* @param {string} key - The key to append.
|
|
132
74
|
* @param {any} value - The value to append.
|
|
133
75
|
* @returns None
|
|
134
76
|
*/
|
|
135
|
-
|
|
77
|
+
appendIntoBody(key, value) {
|
|
136
78
|
this.body[key] = value;
|
|
137
|
-
}
|
|
79
|
+
}
|
|
138
80
|
/**
|
|
139
81
|
* Appends a header to the existing headers object.
|
|
140
82
|
* @param {string} key - The key of the header.
|
|
141
83
|
* @param {any} value - The value of the header.
|
|
142
84
|
* @returns None
|
|
143
85
|
*/
|
|
144
|
-
|
|
86
|
+
appendHeader(key, value) {
|
|
145
87
|
this.headers[key] = value;
|
|
146
|
-
}
|
|
88
|
+
}
|
|
147
89
|
/**
|
|
148
90
|
* Builds the response for the given context and transaction.
|
|
149
91
|
* @param {Context} context - The context object.
|
|
@@ -151,70 +93,55 @@ var Response = /** @class */ (function () {
|
|
|
151
93
|
* @param {boolean} optDoNotCallContext - Optional flag to indicate whether to call the context or not.
|
|
152
94
|
* @returns {Promise<void>} - A promise that resolves when the response is built.
|
|
153
95
|
*/
|
|
154
|
-
|
|
155
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
transaction.logger.debug(b);
|
|
178
|
-
if (!transaction.responseProxy) return [3 /*break*/, 2];
|
|
179
|
-
return [4 /*yield*/, transaction.responseProxy(this)
|
|
180
|
-
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
181
|
-
];
|
|
182
|
-
case 1:
|
|
183
|
-
_a.sent();
|
|
184
|
-
_a.label = 2;
|
|
185
|
-
case 2:
|
|
186
|
-
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
187
|
-
if (!optDoNotCallContext)
|
|
188
|
-
context.succeed(b);
|
|
189
|
-
return [2 /*return*/];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
96
|
+
build(context, transaction, optDoNotCallContext) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
//Stream support
|
|
99
|
+
if (this.isPipingOut)
|
|
100
|
+
return;
|
|
101
|
+
if (this.shouldStream)
|
|
102
|
+
return this.pipe(context);
|
|
103
|
+
//append default fields
|
|
104
|
+
if (transaction.request.getRequestID() && this.body && !this.disableTransactionID)
|
|
105
|
+
this.appendIntoBody('transactionID', transaction.request.getRequestID()); //append transaction ID
|
|
106
|
+
//Raw response support
|
|
107
|
+
if (this.rawBody)
|
|
108
|
+
return this.rawContext(context, transaction);
|
|
109
|
+
//build response
|
|
110
|
+
const b = Object.assign({ statusCode: this.statusCode, headers: this.headers }, (this.body ? { body: JSON.stringify(this.body) } : {}));
|
|
111
|
+
//log response and respond to context
|
|
112
|
+
transaction.logger.debug(b);
|
|
113
|
+
//Check for transaction response proxy
|
|
114
|
+
if (transaction.responseProxy)
|
|
115
|
+
yield transaction.responseProxy(this);
|
|
116
|
+
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
117
|
+
if (!optDoNotCallContext)
|
|
118
|
+
context.succeed(b);
|
|
192
119
|
});
|
|
193
|
-
}
|
|
120
|
+
}
|
|
194
121
|
/**
|
|
195
122
|
* Private method that pipes the response to the given context.
|
|
196
123
|
* @param {Context} context - The context object provided by AWS Lambda.
|
|
197
124
|
* @returns None
|
|
198
125
|
*/
|
|
199
|
-
|
|
126
|
+
pipe(context) {
|
|
200
127
|
//Check if not streaming
|
|
201
128
|
this.isPipingOut = true;
|
|
202
129
|
//build response
|
|
203
|
-
|
|
130
|
+
const b = {
|
|
204
131
|
statusCode: this.statusCode,
|
|
205
132
|
body: this.body,
|
|
206
133
|
headers: this.headers,
|
|
207
134
|
};
|
|
208
135
|
//log response and respond to context
|
|
209
136
|
context.succeed(b);
|
|
210
|
-
}
|
|
137
|
+
}
|
|
211
138
|
/**
|
|
212
139
|
* Private method that handles the raw context of a transaction.
|
|
213
140
|
* @param {Context} context - The context object.
|
|
214
141
|
* @param {Transaction<null, BodyType>} transaction - The transaction object.
|
|
215
142
|
* @returns None
|
|
216
143
|
*/
|
|
217
|
-
|
|
144
|
+
rawContext(context, transaction) {
|
|
218
145
|
//log response and respond to context
|
|
219
146
|
transaction.logger.debug(this.body);
|
|
220
147
|
if (this.getCode() <= 200 && this.getCode() <= 299)
|
|
@@ -225,31 +152,31 @@ var Response = /** @class */ (function () {
|
|
|
225
152
|
else
|
|
226
153
|
throw new CustomError(this.body);
|
|
227
154
|
}
|
|
228
|
-
}
|
|
155
|
+
}
|
|
229
156
|
/**
|
|
230
157
|
* Generates a response object for a missing path parameter error.
|
|
231
158
|
* @param {string} paramName - The name of the missing path parameter.
|
|
232
159
|
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
233
160
|
*/
|
|
234
|
-
|
|
235
|
-
console.warn(
|
|
161
|
+
static MissingParamResponse(paramName) {
|
|
162
|
+
console.warn(`Invalid request - Path parameter ${paramName} is missing.`);
|
|
236
163
|
return new Response(400, {
|
|
237
|
-
err:
|
|
238
|
-
errCode:
|
|
164
|
+
err: `Invalid request. Path parameter ${paramName} is missing.`,
|
|
165
|
+
errCode: Globals.ErrorCode_MissingParam,
|
|
239
166
|
});
|
|
240
|
-
}
|
|
167
|
+
}
|
|
241
168
|
/**
|
|
242
169
|
* Creates a response object for a missing query parameter error.
|
|
243
170
|
* @param {string} paramName - The name of the missing query parameter.
|
|
244
171
|
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
245
172
|
*/
|
|
246
|
-
|
|
247
|
-
console.warn(
|
|
173
|
+
static MissingQueryResponse(paramName) {
|
|
174
|
+
console.warn(`Invalid request - Query parameter ${paramName} is missing.`);
|
|
248
175
|
return new Response(400, {
|
|
249
|
-
err:
|
|
250
|
-
errCode:
|
|
176
|
+
err: `Invalid request. Query parameter ${paramName} is missing.`,
|
|
177
|
+
errCode: Globals.ErrorCode_MissingParam,
|
|
251
178
|
});
|
|
252
|
-
}
|
|
179
|
+
}
|
|
253
180
|
/**
|
|
254
181
|
* Creates a BadRequestResponse object with the given parameters.
|
|
255
182
|
* @param {string} [msg] - The error message.
|
|
@@ -257,10 +184,10 @@ var Response = /** @class */ (function () {
|
|
|
257
184
|
* @param {any} [optBody] - Optional additional body data.
|
|
258
185
|
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
259
186
|
*/
|
|
260
|
-
|
|
261
|
-
console.warn(
|
|
262
|
-
return new Response(400,
|
|
263
|
-
}
|
|
187
|
+
static BadRequestResponse(msg, errCode, optBody) {
|
|
188
|
+
console.warn(`Bad request - ${msg}`);
|
|
189
|
+
return new Response(400, Object.assign(Object.assign({ err: msg }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
190
|
+
}
|
|
264
191
|
/**
|
|
265
192
|
* Creates a BadRequestResponse object with rollback option.
|
|
266
193
|
* @param {string} msg - The error message.
|
|
@@ -268,71 +195,69 @@ var Response = /** @class */ (function () {
|
|
|
268
195
|
* @param {any} [optBody] - Optional body to include in the response.
|
|
269
196
|
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
270
197
|
*/
|
|
271
|
-
|
|
272
|
-
console.warn(
|
|
273
|
-
return new Response(400,
|
|
274
|
-
}
|
|
198
|
+
static BadRequestResponseWithRollback(msg, errCode, optBody) {
|
|
199
|
+
console.warn(`Bad request - ${msg}`);
|
|
200
|
+
return new Response(400, Object.assign(Object.assign({ err: msg, rollback: true }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
201
|
+
}
|
|
275
202
|
/**
|
|
276
203
|
* Creates an unauthorized response with the given error message and error code.
|
|
277
204
|
* @param {string} msg - The error message.
|
|
278
205
|
* @param {string} [errCode] - The error code (optional).
|
|
279
206
|
* @returns {Response<ResponseErrorType>} - The unauthorized response.
|
|
280
207
|
*/
|
|
281
|
-
|
|
282
|
-
console.warn(
|
|
283
|
-
return new Response(401,
|
|
284
|
-
}
|
|
208
|
+
static UnauthorizedResponse(msg, errCode) {
|
|
209
|
+
console.warn(`Denying request - ${msg}`);
|
|
210
|
+
return new Response(401, Object.assign({ err: msg }, (errCode ? { errCode: errCode } : {})));
|
|
211
|
+
}
|
|
285
212
|
/**
|
|
286
213
|
* Creates a success response object with the given body.
|
|
287
214
|
* @param {BodyType} body - The body of the response.
|
|
288
215
|
* @returns {Response<BodyType>} - The success response object.
|
|
289
216
|
*/
|
|
290
|
-
|
|
217
|
+
static SuccessResponse(body) {
|
|
291
218
|
return new Response(200, (body ? body : {}));
|
|
292
|
-
}
|
|
219
|
+
}
|
|
293
220
|
/**
|
|
294
221
|
* Creates a redirect response with the specified URL.
|
|
295
222
|
* @param {string} url - The URL to redirect to.
|
|
296
223
|
* @returns {Response<null>} - The redirect response.
|
|
297
224
|
*/
|
|
298
|
-
|
|
299
|
-
|
|
225
|
+
static RedirectResponse(url) {
|
|
226
|
+
const resp = new Response(302, null);
|
|
300
227
|
resp.appendHeader('Location', url);
|
|
301
228
|
return resp;
|
|
302
|
-
}
|
|
229
|
+
}
|
|
303
230
|
/**
|
|
304
231
|
* Creates a success response with no content.
|
|
305
232
|
* @returns {Response<null>} A response object with a status code of 204 and no content.
|
|
306
233
|
*/
|
|
307
|
-
|
|
234
|
+
static SuccessNoContentResponse() {
|
|
308
235
|
return new Response(204, null);
|
|
309
|
-
}
|
|
236
|
+
}
|
|
310
237
|
/**
|
|
311
238
|
* Creates a success response object with a streaming body and specified content type.
|
|
312
239
|
* @param {any} stream - The stream object to be used as the response body.
|
|
313
240
|
* @param {string} contentType - The content type of the response.
|
|
314
241
|
* @returns {Response} - The success response object.
|
|
315
242
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
243
|
+
static SuccessStreamResponse(stream, contentType) {
|
|
244
|
+
const resp = new Response(200, stream, {
|
|
318
245
|
shouldStream: true,
|
|
319
246
|
});
|
|
320
247
|
resp.appendHeader('Connection', 'keep-alive');
|
|
321
248
|
if (contentType)
|
|
322
249
|
resp.appendHeader('Content-Type', contentType);
|
|
323
250
|
return resp;
|
|
324
|
-
}
|
|
251
|
+
}
|
|
325
252
|
/**
|
|
326
253
|
* Creates a simple HTTP response with the given body and optional status code.
|
|
327
254
|
* @param {BodyType} body - The body of the response.
|
|
328
255
|
* @param {number} [optionalCode] - The optional status code of the response. Defaults to 200.
|
|
329
256
|
* @returns {Response<BodyType>} - The created response object.
|
|
330
257
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
258
|
+
static SimpleResponse(body, optionalCode) {
|
|
259
|
+
const resp = new Response(optionalCode || 200, body);
|
|
333
260
|
return resp;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
}());
|
|
337
|
-
exports.default = Response;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
338
263
|
//# sourceMappingURL=Response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Response.js","sourceRoot":"","sources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